001: package test;
002:
003: import java.awt.*;
004: import java.awt.event.ActionEvent;
005: import java.awt.event.ActionListener;
006:
007: import javax.swing.*;
008: import javax.swing.plaf.FontUIResource;
009:
010: import org.jvnet.lafwidget.LafWidget;
011: import org.jvnet.lafwidget.LafWidgetUtilities;
012: import org.jvnet.lafwidget.animation.FadeConfigurationManager;
013: import org.jvnet.lafwidget.animation.FadeKind;
014: import org.jvnet.lafwidget.utils.LafConstants.AnimationKind;
015: import org.jvnet.substance.SubstanceDefaultComboBoxRenderer;
016: import org.jvnet.substance.SubstanceLookAndFeel;
017: import org.jvnet.substance.fonts.FontPolicy;
018: import org.jvnet.substance.fonts.FontSet;
019: import org.jvnet.substance.skin.SubstanceModerateLookAndFeel;
020:
021: public class ButtonRolloverDemo extends JFrame {
022: /**
023: * Wrapper around the base Substance font set. Is used to create larger /
024: * smaller font sets.
025: *
026: * @author Kirill Grouchnikov
027: */
028: private static class WrapperFontSet implements FontSet {
029: /**
030: * Extra size in pixels. Can be positive or negative.
031: */
032: private int extra;
033:
034: /**
035: * The base Substance font set.
036: */
037: private FontSet delegate;
038:
039: /**
040: * Creates a wrapper font set.
041: *
042: * @param delegate
043: * The base Substance font set.
044: * @param extra
045: * Extra size in pixels. Can be positive or negative.
046: */
047: public WrapperFontSet(FontSet delegate, int extra) {
048: super ();
049: this .delegate = delegate;
050: this .extra = extra;
051: }
052:
053: /**
054: * Returns the wrapped font.
055: *
056: * @param systemFont
057: * Original font.
058: * @return Wrapped font.
059: */
060: private FontUIResource getWrappedFont(FontUIResource systemFont) {
061: return new FontUIResource(systemFont.getFontName(),
062: systemFont.getStyle(), systemFont.getSize() + extra);
063: }
064:
065: public FontUIResource getControlFont() {
066: return getWrappedFont(delegate.getControlFont());
067: }
068:
069: public FontUIResource getMenuFont() {
070: return getWrappedFont(delegate.getMenuFont());
071: }
072:
073: public FontUIResource getMessageFont() {
074: return getWrappedFont(delegate.getMessageFont());
075: }
076:
077: public FontUIResource getSmallFont() {
078: return getWrappedFont(delegate.getSmallFont());
079: }
080:
081: public FontUIResource getTitleFont() {
082: return getWrappedFont(delegate.getTitleFont());
083: }
084:
085: public FontUIResource getWindowTitleFont() {
086: return getWrappedFont(delegate.getWindowTitleFont());
087: }
088: }
089:
090: public ButtonRolloverDemo() {
091: super ("Ghost effects");
092:
093: setLayout(new BorderLayout());
094: final JPanel buttons = new JPanel(new FlowLayout());
095: JButton cutButton = new JButton("Cut", new ImageIcon(
096: ButtonRolloverDemo.class
097: .getResource("/test/icons/edit-cut.png")));
098: cutButton.setFocusPainted(false);
099: buttons.add(cutButton);
100: // buttons.add(new JButton("Copy", new ImageIcon(ButtonRolloverDemo.class
101: // .getResource("/test/icons/edit-copy.png"))));
102: JButton copyButton = new JButton("Paste", new ImageIcon(
103: ButtonRolloverDemo.class
104: .getResource("/test/icons/edit-paste.png")));
105: copyButton.setFocusPainted(false);
106: buttons.add(copyButton);
107: JButton deleteButton = new JButton("Delete", new ImageIcon(
108: ButtonRolloverDemo.class
109: .getResource("/test/icons/edit-delete.png")));
110: deleteButton.setFocusPainted(false);
111: buttons.add(deleteButton);
112: // buttons.add(new JButton("Paste", new ImageIcon(ButtonRolloverDemo.class
113: // .getResource("/test/icons/edit-paste.png"))));
114: // buttons.add(new JButton("Delete", new ImageIcon(
115: // ButtonRolloverDemo.class
116: // .getResource("/test/icons/edit-delete.png"))));
117: // buttons.add(new JButton("Select All", new ImageIcon(
118: // ButtonRolloverDemo.class
119: // .getResource("/test/icons/edit-select-all.png"))));
120:
121: this .add(buttons, BorderLayout.CENTER);
122:
123: JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
124: controls.setBackground(new Color(255, 240, 150));
125: final JComboBox animKindCombo = new JComboBox(new Object[] {
126: AnimationKind.NONE, AnimationKind.FAST,
127: AnimationKind.REGULAR, AnimationKind.SLOW });
128: animKindCombo.setRenderer(new SubstanceDefaultComboBoxRenderer(
129: animKindCombo) {
130: @Override
131: public Component getListCellRendererComponent(JList list,
132: Object value, int index, boolean isSelected,
133: boolean cellHasFocus) {
134: AnimationKind ak = (AnimationKind) value;
135: return super .getListCellRendererComponent(list, ak
136: .getName(), index, isSelected, cellHasFocus);
137: }
138: });
139: animKindCombo.setSelectedItem(LafWidgetUtilities
140: .getAnimationKind(buttons));
141: controls.add(animKindCombo);
142: animKindCombo.addActionListener(new ActionListener() {
143: public void actionPerformed(ActionEvent e) {
144: buttons.putClientProperty(LafWidget.ANIMATION_KIND,
145: animKindCombo.getSelectedItem());
146: }
147: });
148: this .add(controls, BorderLayout.SOUTH);
149:
150: setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
151: this .setSize(400, 150);
152: setLocationRelativeTo(null);
153: }
154:
155: public static void main(String[] args) throws Exception {
156: JFrame.setDefaultLookAndFeelDecorated(true);
157: UIManager.setLookAndFeel(new SubstanceModerateLookAndFeel());
158:
159: final FontSet substanceCoreFontSet = SubstanceLookAndFeel
160: .getFontPolicy().getFontSet("Substance", null);
161: // Create the wrapper font set
162: FontPolicy newFontPolicy = new FontPolicy() {
163: public FontSet getFontSet(String lafName, UIDefaults table) {
164: return new WrapperFontSet(substanceCoreFontSet, 6);
165: }
166: };
167:
168: // set the new font policy
169: SubstanceLookAndFeel.setFontPolicy(newFontPolicy);
170: // reset the LAF to have the changes
171: UIManager.setLookAndFeel(new SubstanceLookAndFeel());
172:
173: FadeConfigurationManager.getInstance().allowFades(
174: FadeKind.GHOSTING_ICON_ROLLOVER);
175: FadeConfigurationManager.getInstance().allowFades(
176: FadeKind.GHOSTING_BUTTON_PRESS);
177: FadeConfigurationManager.getInstance().allowFades(
178: FadeKind.ICON_GLOW);
179: SwingUtilities.invokeLater(new Runnable() {
180: public void run() {
181: new ButtonRolloverDemo().setVisible(true);
182: }
183: });
184:
185: }
186: }
|