001: package test.check.statusbar;
002:
003: import javax.swing.*;
004: import javax.swing.border.EmptyBorder;
005: import javax.swing.event.ChangeEvent;
006: import javax.swing.event.ChangeListener;
007: import javax.swing.plaf.FontUIResource;
008:
009: import org.jvnet.substance.SubstanceLookAndFeel;
010: import org.jvnet.substance.fonts.FontPolicy;
011: import org.jvnet.substance.fonts.FontSet;
012:
013: import com.jgoodies.forms.builder.DefaultFormBuilder;
014: import com.jgoodies.forms.layout.FormLayout;
015:
016: public class FontSizePanel {
017: private static class WrapperFontSet implements FontSet {
018: private int extra;
019:
020: private FontSet delegate;
021:
022: public WrapperFontSet(FontSet delegate, int extra) {
023: super ();
024: this .delegate = delegate;
025: this .extra = extra;
026: }
027:
028: private FontUIResource getWrappedFont(FontUIResource systemFont) {
029: return new FontUIResource(systemFont.getFontName(),
030: systemFont.getStyle(), systemFont.getSize() + extra);
031: }
032:
033: public FontUIResource getControlFont() {
034: return getWrappedFont(delegate.getControlFont());
035: }
036:
037: public FontUIResource getMenuFont() {
038: return getWrappedFont(delegate.getMenuFont());
039: }
040:
041: public FontUIResource getMessageFont() {
042: return getWrappedFont(delegate.getMessageFont());
043: }
044:
045: public FontUIResource getSmallFont() {
046: return getWrappedFont(delegate.getSmallFont());
047: }
048:
049: public FontUIResource getTitleFont() {
050: return getWrappedFont(delegate.getTitleFont());
051: }
052:
053: public FontUIResource getWindowTitleFont() {
054: // FontUIResource f = this.getWrappedFont(this.delegate
055: // .getWindowTitleFont());
056: // return new FontUIResource(f.deriveFont(Font.BOLD, f.getSize() +
057: // 1));
058: return getWrappedFont(delegate.getWindowTitleFont());
059: }
060: }
061:
062: public static JPanel getPanel() {
063: FormLayout lm = new FormLayout(
064: "fill:pref, 2dlu, fill:pref, 0dlu, fill:min:grow, 0dlu, fill:pref",
065: "");
066: DefaultFormBuilder builder = new DefaultFormBuilder(lm);
067: builder.setBorder(new EmptyBorder(0, 0, 0, 0));
068:
069: final JLabel fontSizeLabel = new JLabel();
070: fontSizeLabel.setText(SubstanceLookAndFeel.getFontPolicy()
071: .getFontSet("Substance", null).getControlFont()
072: .getSize()
073: + " pt.");
074: builder.append(fontSizeLabel);
075: // fontSizeLabel.add(Box.createHorizontalStrut(5));
076:
077: Icon zoomOutIcon = new ImageIcon(Thread.currentThread()
078: .getContextClassLoader().getResource(
079: "test/check/icons/16/zoom_out.png"));
080: JLabel zoomOutLabel = new JLabel(zoomOutIcon);
081: zoomOutLabel.putClientProperty(
082: SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,
083: Boolean.TRUE);
084: builder.append(zoomOutLabel);
085:
086: final JSlider fontSizeSlider = new JSlider(0, 10, 0);
087: fontSizeSlider.setFocusable(false);
088: //fontSizeSlider.setOpaque(false);
089: fontSizeSlider
090: .setToolTipText("Controls the global font set size. Resets Substance as the current LAF.");
091: fontSizeSlider.addChangeListener(new ChangeListener() {
092: public void stateChanged(ChangeEvent e) {
093: // if the value is adjusting - ignore. This is done
094: // to make CPU usage better.
095: if (!fontSizeSlider.getModel().getValueIsAdjusting()) {
096: final int newValue = fontSizeSlider.getValue();
097: SwingUtilities.invokeLater(new Runnable() {
098: public void run() {
099: SubstanceLookAndFeel.setFontPolicy(null);
100: final FontSet substanceCoreFontSet = SubstanceLookAndFeel
101: .getFontPolicy().getFontSet(
102: "Substance", null);
103: FontPolicy newFontPolicy = new FontPolicy() {
104: public FontSet getFontSet(
105: String lafName, UIDefaults table) {
106: return new WrapperFontSet(
107: substanceCoreFontSet,
108: newValue);
109: }
110: };
111:
112: try {
113: SubstanceLookAndFeel
114: .setFontPolicy(newFontPolicy);
115: UIManager
116: .setLookAndFeel(new SubstanceLookAndFeel());
117: SwingUtilities
118: .updateComponentTreeUI(SwingUtilities
119: .getWindowAncestor(fontSizeLabel));
120: } catch (Exception exc) {
121: exc.printStackTrace();
122: }
123:
124: fontSizeLabel.setText(SubstanceLookAndFeel
125: .getFontPolicy().getFontSet(
126: "Substance", null)
127: .getControlFont().getSize()
128: + " pt.");
129: }
130: });
131: }
132: }
133: });
134: builder.append(fontSizeSlider);
135:
136: Icon zoomInIcon = new ImageIcon(Thread.currentThread()
137: .getContextClassLoader().getResource(
138: "test/check/icons/16/zoom_in.png"));
139: JLabel zoomInLabel = new JLabel(zoomInIcon);
140: zoomInLabel.putClientProperty(
141: SubstanceLookAndFeel.USE_THEMED_DEFAULT_ICONS,
142: Boolean.TRUE);
143: builder.append(zoomInLabel);
144:
145: JPanel result = builder.getPanel();
146: //result.setOpaque(false);
147: return result;
148: }
149: }
|