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.SubstanceButtonUI;
11: import org.jvnet.substance.SubstanceLookAndFeel;
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 NetbeansSubstanceButtonUI extends SubstanceButtonUI {
18: protected ClassicButtonShaper classicShaper = new ClassicButtonShaper();
19:
20: public static ComponentUI createUI(JComponent b) {
21: ((AbstractButton) b).setRolloverEnabled(true);
22: return new NetbeansSubstanceButtonUI();
23: }
24:
25: protected boolean isInMatissePalette(AbstractButton button) {
26: Component c = button;
27: while (c != null) {
28: if (c.getClass().getSimpleName().equals("PalettePanel"))
29: return true;
30: c = c.getParent();
31: }
32: return false;
33: }
34:
35: public Dimension getPreferredSize(JComponent c) {
36: AbstractButton button = (AbstractButton) c;
37: SubstanceButtonShaper shaper = SubstanceCoreUtilities
38: .getButtonShaper(button);
39: if (isInMatissePalette(button)) {
40: shaper = classicShaper;
41: Object currentShaper = button
42: .getClientProperty(SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY);
43: if (!(currentShaper instanceof ClassicButtonShaper)) {
44: button.putClientProperty(
45: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
46: new ClassicButtonShaper());
47: }
48: button.putClientProperty(
49: SubstanceLookAndFeel.FLAT_PROPERTY, Boolean.TRUE);
50: Object currentPainter = button
51: .getClientProperty(SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY);
52: if (!(currentPainter instanceof ClassicGradientPainter))
53: button.putClientProperty(
54: SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY,
55: new ClassicGradientPainter());
56: button.setBorder(shaper.getButtonBorder(button));
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:
95: }
|