Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add more customization options #8

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions src/main/java/com/vlsolutions/swing/docking/AutoHideButton.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,10 @@
package com.vlsolutions.swing.docking;

import javax.swing.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.Color;
import java.awt.Insets;
import java.awt.Dimension;
import java.beans.*;
Expand Down Expand Up @@ -54,6 +56,9 @@ public class AutoHideButton extends JLabel {
private int blinkCount = 0;
private int MAX_BLINKS = UIManager.getInt("DockingDesktop.notificationBlinkCount");

private Color highlightColor = UIManager.getColor("VLDocking.highlight");
private Color bgColor = UIManager.getColor("AutoHideButton.background");

private PropertyChangeListener keyListener = new PropertyChangeListener() {

// this is a DockKey listener, not a KeyEvent listener...
Expand Down Expand Up @@ -107,7 +112,7 @@ private void setNotification(boolean notification) {
setBackground(UIManager.getColor("DockingDesktop.notificationColor"));
setOpaque(true);
} else {
setOpaque(false);
setHighlighted(false);
}
repaint();
}
Expand Down Expand Up @@ -142,7 +147,8 @@ public void init(Dockable dockable, int zone) {

setFocusable(true);

setOpaque(false);
setBackground(bgColor);
setOpaque(bgColor != null);

setIconTextGap(4);
setAlignmentY(1);
Expand Down Expand Up @@ -191,12 +197,23 @@ public boolean isSelected() {
/** Selects or unselects the button */
public void setSelected(boolean selected) {
this.selected = selected;
setOpaque(selected);
repaint();
setHighlighted(selected);
if(selected) {
key.setNotification(false); // in case we were in notification mode
}
}

/** Sets the button highlight (on rollover, etc.) */
public void setHighlighted(boolean highlighted) {
if (highlighted) {
setBackground(highlightColor);
setOpaque(true);
} else {
setBackground(bgColor);
setOpaque(bgColor != null);
}
repaint();
}

public String getUIClassID() {
return uiClassID;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,22 +101,17 @@ public void remove(AutoHideButton btn) {

private class ButtonHighlighter extends MouseAdapter {

Color highlight = UIManager.getColor("VLDocking.highlight");

public void mouseEntered(MouseEvent e) {
AutoHideButton btn = (AutoHideButton) e.getSource();
if(! btn.isSelected()) { // selected buttons have their own pain style
btn.setBackground(highlight);
btn.setOpaque(true);
btn.repaint();
btn.setHighlighted(true);
}
}

public void mouseExited(MouseEvent e) {
AutoHideButton btn = (AutoHideButton) e.getSource();
if(! btn.isSelected()) { // selected buttons have their own pain style
btn.setOpaque(false);
btn.repaint();
btn.setHighlighted(false);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
import com.vlsolutions.swing.docking.AutoHideButtonPanel;
import com.vlsolutions.swing.docking.DockingConstants;

import java.awt.Color;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;

Expand Down Expand Up @@ -59,12 +60,14 @@ public AutoHideButtonPanelUI() {}
public void installUI(JComponent comp) {
super.installUI(comp);
installBorder((AutoHideButtonPanel) comp);
installBackground(comp);
comp.addPropertyChangeListener(AutoHideButtonPanel.PROPERTY_BORDERZONE, this);
}

public void uninstallUI(JComponent comp) {
super.uninstallUI(comp);
comp.setBorder(null);
comp.setBackground(null);
comp.removePropertyChangeListener(this);
}

Expand All @@ -85,6 +88,13 @@ protected void installBorder(AutoHideButtonPanel btnPanel) {
}
}

protected void installBackground(JComponent comp) {
Color color = UIManager.getColor("AutoHideButtonPanel.background");
if (color != null) {
comp.setBackground(color);
}
}

public void propertyChange(PropertyChangeEvent e) {
installBorder((AutoHideButtonPanel) e.getSource());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ protected void installBorder(AutoHideButton btn) {
public void paint(Graphics g, JComponent comp) {
AutoHideButton btn = (AutoHideButton) comp;
int zone = btn.getZone();
if(zone == DockingConstants.INT_HIDE_TOP || zone == DockingConstants.INT_SPLIT_BOTTOM) {
if(zone == DockingConstants.INT_HIDE_TOP || zone == DockingConstants.INT_HIDE_BOTTOM) {
super.paint(g, comp);
} else {
// vertical button : we have to rely on a custom paint
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,8 @@
public class DockViewTitleBarUI extends PanelUI implements PropertyChangeListener {

/* hack to use custom painting except on mac os (ugly opacity effects) */
private static boolean useCustomPaint = System.getProperty("os.name").toLowerCase().indexOf("mac os") < 0;
private static boolean useCustomPaint = !System.getProperty("os.name").contains("OS X")
&& !UIManager.getBoolean("DockViewTitleBar.disableCustomPaint");

private static Color panelColor = UIManager.getColor("Panel.background");
@SuppressWarnings("unused")
Expand Down