01: package org.jvnet.substance.netbeans;
02:
03: import java.awt.Component;
04: import java.awt.Dimension;
05: import java.awt.Graphics;
06: import javax.swing.AbstractButton;
07: import javax.swing.JComponent;
08: import javax.swing.plaf.ComponentUI;
09: import javax.swing.plaf.basic.BasicGraphicsUtils;
10: import org.jvnet.substance.SubstanceLookAndFeel;
11: import org.jvnet.substance.SubstanceToggleButtonUI;
12: import org.jvnet.substance.button.ClassicButtonShaper;
13: import org.jvnet.substance.button.SubstanceButtonShaper;
14: import org.jvnet.substance.painter.ClassicGradientPainter;
15: import org.jvnet.substance.utils.SubstanceCoreUtilities;
16:
17: public class NetbeansSubstanceToggleButtonUI extends
18: SubstanceToggleButtonUI {
19: protected ClassicButtonShaper classicShaper = new ClassicButtonShaper();
20:
21: public static ComponentUI createUI(JComponent b) {
22: ((AbstractButton) b).setRolloverEnabled(true);
23: return new NetbeansSubstanceToggleButtonUI();
24: }
25:
26: protected boolean isInMatissePalette(AbstractButton button) {
27: Component c = button;
28: while (c != null) {
29: if (c.getClass().getSimpleName().equals("PalettePanel"))
30: return true;
31: c = c.getParent();
32: }
33: return false;
34: }
35:
36: public Dimension getPreferredSize(JComponent c) {
37: AbstractButton button = (AbstractButton) c;
38: SubstanceButtonShaper shaper = SubstanceCoreUtilities
39: .getButtonShaper(button);
40: if (isInMatissePalette(button)) {
41: shaper = classicShaper;
42: Object currentShaper = button
43: .getClientProperty(SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY);
44: if (!(currentShaper instanceof ClassicButtonShaper)) {
45: button.putClientProperty(
46: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
47: new ClassicButtonShaper());
48: }
49: button.putClientProperty(
50: SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE);
51: Object currentPainter = button
52: .getClientProperty(SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY);
53: if (!(currentPainter instanceof ClassicGradientPainter))
54: button.putClientProperty(
55: SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY,
56: new ClassicGradientPainter());
57: }
58: // MemoryAnalyzer.enqueueUsage("Button size '" + button.getText() + "' -> "
59: // + shaper.getDisplayName() + " [" + isInMatissePalette(button) + "] " +
60: // button.getBorder());
61:
62: return shaper.getPreferredSize(button,
63: BasicGraphicsUtils.getPreferredButtonSize(button,
64: button.getIconTextGap()));
65: }
66:
67: public void update(Graphics g, JComponent c) {
68: AbstractButton button = (AbstractButton) c;
69: if (isInMatissePalette(button)) {
70: Object currentShaper = button
71: .getClientProperty(SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY);
72: if (!(currentShaper instanceof ClassicButtonShaper)) {
73: button.putClientProperty(
74: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
75: new ClassicButtonShaper());
76: button.setBorder(((ClassicButtonShaper) currentShaper)
77: .getButtonBorder(button));
78: }
79: button.putClientProperty(
80: SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE);
81: Object currentPainter = button
82: .getClientProperty(SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY);
83: if (!(currentPainter instanceof ClassicGradientPainter))
84: button.putClientProperty(
85: SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY,
86: new ClassicGradientPainter());
87: }
88: // MemoryAnalyzer.enqueueUsage("Button paint '" + button.getText() + "' -> "
89: // + SubstanceCoreUtilities.getButtonShaper(button).getDisplayName() +
90: // " [" + isInMatissePalette(button) + "] " +
91: // button.getBorder());
92: super.update(g, c);
93: }
94: }
|