0001: /*
0002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
0003: *
0004: * Redistribution and use in source and binary forms, with or without
0005: * modification, are permitted provided that the following conditions are met:
0006: *
0007: * o Redistributions of source code must retain the above copyright notice,
0008: * this list of conditions and the following disclaimer.
0009: *
0010: * o Redistributions in binary form must reproduce the above copyright notice,
0011: * this list of conditions and the following disclaimer in the documentation
0012: * and/or other materials provided with the distribution.
0013: *
0014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
0015: * its contributors may be used to endorse or promote products derived
0016: * from this software without specific prior written permission.
0017: *
0018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
0020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
0021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
0022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
0023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
0024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
0025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
0026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
0027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
0028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
0029: */
0030: package test;
0031:
0032: import java.awt.*;
0033: import java.awt.event.*;
0034: import java.io.*;
0035: import java.net.URL;
0036: import java.util.*;
0037:
0038: import javax.swing.*;
0039: import javax.swing.event.ChangeEvent;
0040: import javax.swing.event.ChangeListener;
0041: import javax.swing.plaf.FontUIResource;
0042:
0043: import org.jdesktop.swingx.*;
0044: import org.jvnet.lafwidget.LafWidget;
0045: import org.jvnet.lafwidget.tabbed.DefaultTabPreviewPainter;
0046: import org.jvnet.lafwidget.utils.LafConstants.TabOverviewKind;
0047: import org.jvnet.substance.*;
0048: import org.jvnet.substance.button.*;
0049: import org.jvnet.substance.fonts.FontSet;
0050: import org.jvnet.substance.painter.*;
0051: import org.jvnet.substance.painter.decoration.DecorationAreaType;
0052: import org.jvnet.substance.tabbed.*;
0053: import org.jvnet.substance.theme.*;
0054: import org.jvnet.substance.utils.SubstanceConstants;
0055: import org.jvnet.substance.utils.SubstanceConstants.Side;
0056: import org.jvnet.substance.utils.SubstanceConstants.TabCloseKind;
0057: import org.jvnet.substance.watermark.*;
0058:
0059: import test.check.*;
0060: import test.check.statusbar.FontSizePanel;
0061:
0062: public class Check extends JFrame {
0063: private JTabbedPane jtp;
0064:
0065: private MyMainTabPreviewPainter mainTabPreviewPainter;
0066:
0067: private static class WrapperFontSet implements FontSet {
0068: private int extra;
0069:
0070: private FontSet delegate;
0071:
0072: public WrapperFontSet(FontSet delegate, int extra) {
0073: super ();
0074: this .delegate = delegate;
0075: this .extra = extra;
0076: }
0077:
0078: private FontUIResource getWrappedFont(FontUIResource systemFont) {
0079: return new FontUIResource(systemFont.getFontName(),
0080: systemFont.getStyle(), systemFont.getSize() + extra);
0081: }
0082:
0083: public FontUIResource getControlFont() {
0084: return getWrappedFont(delegate.getControlFont());
0085: }
0086:
0087: public FontUIResource getMenuFont() {
0088: return getWrappedFont(delegate.getMenuFont());
0089: }
0090:
0091: public FontUIResource getMessageFont() {
0092: return getWrappedFont(delegate.getMessageFont());
0093: }
0094:
0095: public FontUIResource getSmallFont() {
0096: return getWrappedFont(delegate.getSmallFont());
0097: }
0098:
0099: public FontUIResource getTitleFont() {
0100: return getWrappedFont(delegate.getTitleFont());
0101: }
0102:
0103: public FontUIResource getWindowTitleFont() {
0104: // FontUIResource f = this.getWrappedFont(this.delegate
0105: // .getWindowTitleFont());
0106: // return new FontUIResource(f.deriveFont(Font.BOLD, f.getSize() +
0107: // 1));
0108: return getWrappedFont(delegate.getWindowTitleFont());
0109: }
0110: }
0111:
0112: private class MyThemeChangeListener implements ThemeChangeListener {
0113: public void themeChanged() {
0114: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0115: out("Substance theme is '"
0116: + SubstanceLookAndFeel.getCurrentThemeName()
0117: + "'");
0118:
0119: ClassLoader cl = Thread.currentThread()
0120: .getContextClassLoader();
0121: setIconImage(SubstanceImageCreator
0122: .getThemeImage(
0123: null,
0124: new ImageIcon(
0125: cl
0126: .getResource("test/resource/image-x-generic.png")),
0127: SubstanceLookAndFeel.getTheme(), false));
0128:
0129: }
0130: }
0131: }
0132:
0133: private class MyWatermarkChangeListener implements
0134: WatermarkChangeListener {
0135: public void watermarkChanged() {
0136: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0137: out("Substance watermark is '"
0138: + SubstanceLookAndFeel
0139: .getCurrentWatermarkName() + "'");
0140: }
0141: }
0142: }
0143:
0144: private class MyButtonShaperChangeListener implements
0145: ButtonShaperChangeListener {
0146: public void buttonShaperChanged() {
0147: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0148: out("Substance button shaper is '"
0149: + SubstanceLookAndFeel
0150: .getCurrentButtonShaperName() + "'");
0151: }
0152: }
0153: }
0154:
0155: private class MyGradientPainterChangeListener implements
0156: GradientPainterChangeListener {
0157: public void gradientPainterChanged() {
0158: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0159: out("Substance gradient painter is '"
0160: + SubstanceLookAndFeel
0161: .getCurrentGradientPainterName() + "'");
0162: }
0163: }
0164: }
0165:
0166: private boolean toUseThemeObjs;
0167:
0168: private boolean toUseWatermarksObjs;
0169:
0170: private boolean toUseButtonShapersObjs;
0171:
0172: private boolean toUseGradientPaintersObjs;
0173:
0174: private JXTaskPaneContainer taskPaneContainer;
0175:
0176: private JXTaskPane currentSpecificTaskPane;
0177:
0178: private JXTaskPane mainTaskPane;
0179:
0180: private JToolBar toolbar;
0181:
0182: public Check() {
0183: super (
0184: "Substance test with very very very very very very very very very very very very very very long title");
0185:
0186: ClassLoader cl = Thread.currentThread().getContextClassLoader();
0187: setIconImage(SubstanceImageCreator
0188: .getThemeImage(
0189: null,
0190: new ImageIcon(
0191: cl
0192: .getResource("test/resource/image-x-generic.png")),
0193: SubstanceLookAndFeel.getTheme(), false));
0194: setLayout(new BorderLayout());
0195:
0196: jtp = new JTabbedPane();
0197: try {
0198: mainTabPreviewPainter = new MyMainTabPreviewPainter();
0199: jtp.putClientProperty(
0200: LafWidget.TABBED_PANE_PREVIEW_PAINTER,
0201: mainTabPreviewPainter);
0202: } catch (Throwable e) {
0203: }
0204: jtp.getModel().addChangeListener(new TabSwitchListener());
0205:
0206: // TransitionLayoutManager.getInstance().track(this.jtp, true);
0207: // UIManager.addPropertyChangeListener(new PropertyChangeListener() {
0208: // public void propertyChange(PropertyChangeEvent evt) {
0209: // if ("lookAndFeel".equals(evt.getPropertyName())) {
0210: // LookAndFeel newLaf = (LookAndFeel) evt.getNewValue();
0211: // if (newLaf.getID().contains("Substance")) {
0212: // if (!(jtp.getLayout() instanceof TransitionLayout)) {
0213: // TransitionLayoutManager.getInstance().track(jtp,
0214: // true);
0215: // }
0216: // } else {
0217: // TransitionLayoutManager.getInstance().untrack(jtp);
0218: // }
0219: // }
0220: // }
0221: // });
0222:
0223: final JXPanel jxPanel = new JXPanel(new BorderLayout());
0224: toolbar = getToolbar("", 22, true);
0225: jxPanel.add(toolbar, BorderLayout.NORTH);
0226:
0227: JXStatusBar statusBar = getStatusBar(jxPanel, jtp);
0228: this .add(statusBar, BorderLayout.SOUTH);
0229:
0230: // JPanel buttons = new JPanel(new FlowLayout());
0231:
0232: taskPaneContainer = new JXTaskPaneContainer() {
0233: @Override
0234: public boolean getScrollableTracksViewportWidth() {
0235: return false;
0236: }
0237: };
0238: taskPaneContainer.setScrollableTracksViewportHeight(false);
0239: taskPaneContainer.setScrollableTracksViewportWidth(false);
0240: taskPaneContainer.putClientProperty(
0241: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
0242: new ClassicButtonShaper());
0243: // this.taskPaneContainer.setOpaque(false);
0244:
0245: mainTaskPane = new JXTaskPane();
0246: mainTaskPane.setLayout(new BorderLayout());
0247: JPanel mainControlPanel = ControlPanelFactory
0248: .getMainControlPanel(this , jtp, mainTabPreviewPainter,
0249: toolbar);
0250: // mainControlPanel.setOpaque(false);
0251: mainTaskPane.add(mainControlPanel, BorderLayout.CENTER);
0252: mainTaskPane.setTitle("General settings");
0253: mainTaskPane.setIcon(getIcon("JFrameColor16"));
0254: mainTaskPane.setExpanded(false);
0255: taskPaneContainer.add(mainTaskPane);
0256:
0257: JPanel dialogControlPanel = ControlPanelFactory
0258: .getDialogControlPanel(this );
0259: JXTaskPane dialogTaskPane = new JXTaskPane();
0260: dialogTaskPane.setLayout(new BorderLayout());
0261: dialogTaskPane.add(dialogControlPanel, BorderLayout.CENTER);
0262: dialogTaskPane.setTitle("Dialogs");
0263: dialogTaskPane.setIcon(getIcon("JDialogColor16"));
0264: dialogTaskPane.setExpanded(false);
0265: // dialogTaskPane.setOpaque(false);
0266: taskPaneContainer.add(dialogTaskPane);
0267:
0268: currentSpecificTaskPane = null;
0269:
0270: final JScrollPane scrollPane = new JScrollPane(
0271: taskPaneContainer,
0272: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
0273: JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
0274: SubstanceLookAndFeel.setDecorationType(scrollPane,
0275: DecorationAreaType.GENERAL);
0276: scrollPane.setOpaque(false);
0277: scrollPane.getViewport().setOpaque(false);
0278:
0279: JPanel mainPanel = new JPanel();
0280: mainPanel.add(scrollPane);
0281: mainPanel.add(jtp);
0282: mainPanel.setLayout(new LayoutManager() {
0283: public void addLayoutComponent(String name, Component comp) {
0284: }
0285:
0286: public Dimension minimumLayoutSize(Container parent) {
0287: Dimension min1 = scrollPane.getMinimumSize();
0288: Dimension min2 = jtp.getMinimumSize();
0289: return new Dimension(min1.width + min2.width,
0290: min1.height + min2.height);
0291: }
0292:
0293: public void layoutContainer(Container parent) {
0294: // give 30% width to task pane container and
0295: // 70% width to the tabbed pane with controls.
0296: int width = parent.getWidth();
0297: int height = parent.getHeight();
0298: scrollPane.setBounds(0, 0, (int) (0.3 * width), height);
0299: jtp.setBounds((int) (0.3 * width), 0, width
0300: - (int) (0.3 * width), height);
0301: }
0302:
0303: public Dimension preferredLayoutSize(Container parent) {
0304: Dimension pref1 = scrollPane.getPreferredSize();
0305: Dimension pref2 = jtp.getPreferredSize();
0306: return new Dimension(pref1.width + pref2.width,
0307: pref1.height + pref2.height);
0308: }
0309:
0310: public void removeLayoutComponent(Component comp) {
0311: }
0312: });
0313: jxPanel.add(mainPanel, BorderLayout.CENTER);
0314:
0315: this .add(jxPanel, BorderLayout.CENTER);
0316:
0317: setPreferredSize(new Dimension(400, 400));
0318: this .setSize(getPreferredSize());
0319: setMinimumSize(getPreferredSize());
0320:
0321: ButtonsPanel buttonsPanel = new ButtonsPanel();
0322: jtp.addTab("Buttons", getIcon("JButtonColor16"), buttonsPanel);
0323: getRootPane().setDefaultButton(buttonsPanel.defaultButton);
0324:
0325: jtp.addTab("Combo box", getIcon("JComboBoxColor16"),
0326: new CombosPanel());
0327:
0328: jtp.addTab("Scroll pane", getIcon("JScrollPaneColor16"),
0329: new ScrollPanel());
0330:
0331: TabCloseCallback closeCallback = new TabCloseCallback() {
0332: public TabCloseKind onAreaClick(JTabbedPane tabbedPane,
0333: int tabIndex, MouseEvent mouseEvent) {
0334: if (mouseEvent.getButton() != MouseEvent.BUTTON3)
0335: return TabCloseKind.NONE;
0336: if (mouseEvent.isShiftDown()) {
0337: return TabCloseKind.ALL;
0338: }
0339: return TabCloseKind.THIS;
0340: }
0341:
0342: public TabCloseKind onCloseButtonClick(
0343: JTabbedPane tabbedPane, int tabIndex,
0344: MouseEvent mouseEvent) {
0345: if (mouseEvent.isAltDown()) {
0346: return TabCloseKind.ALL_BUT_THIS;
0347: }
0348: if (mouseEvent.isShiftDown()) {
0349: return TabCloseKind.ALL;
0350: }
0351: return TabCloseKind.THIS;
0352: }
0353:
0354: public String getAreaTooltip(JTabbedPane tabbedPane,
0355: int tabIndex) {
0356: return null;
0357: }
0358:
0359: public String getCloseButtonTooltip(JTabbedPane tabbedPane,
0360: int tabIndex) {
0361: StringBuffer result = new StringBuffer();
0362: result.append("<html><body>");
0363: result.append("Mouse click closes <b>"
0364: + tabbedPane.getTitleAt(tabIndex) + "</b> tab");
0365: result
0366: .append("<br><b>Alt</b>-Mouse click closes all tabs but <b>"
0367: + tabbedPane.getTitleAt(tabIndex)
0368: + "</b> tab");
0369: result
0370: .append("<br><b>Shift</b>-Mouse click closes all tabs");
0371: result.append("</body></html>");
0372: return result.toString();
0373: }
0374: };
0375:
0376: try {
0377: TabPanel tp = new TabPanel();
0378: tp.jtp.putClientProperty(
0379: SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK,
0380: closeCallback);
0381: jtp
0382: .addTab("Tabbed pane",
0383: getIcon("JTabbedPaneColor16"), tp);
0384:
0385: TabPanel tp2 = new TabPanel();
0386: tp2.jtp
0387: .putClientProperty(
0388: SubstanceLookAndFeel.TABBED_PANE_VERTICAL_ORIENTATION,
0389: true);
0390:
0391: tp2.jtp.putClientProperty(
0392: SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK,
0393: closeCallback);
0394: tp2.jtp.setTabPlacement(JTabbedPane.RIGHT);
0395: SubstanceLookAndFeel.registerTabCloseChangeListener(
0396: tp2.jtp, new MultipleTabCloseListener() {
0397: public void tabsClosed(JTabbedPane tabbedPane,
0398: Set<Component> tabComponents) {
0399: out("Closed " + tabComponents.size()
0400: + " vertical tabs - specific");
0401: }
0402:
0403: public void tabsClosing(JTabbedPane tabbedPane,
0404: Set<Component> tabComponents) {
0405: out("Closing " + tabComponents.size()
0406: + " vertical tabs - specific");
0407: }
0408: });
0409: SubstanceLookAndFeel.registerTabCloseChangeListener(
0410: tp2.jtp, new TabCloseListener() {
0411: public void tabClosed(JTabbedPane tabbedPane,
0412: Component tabComponent) {
0413: out("Closed vertical tab - specific");
0414: }
0415:
0416: public void tabClosing(JTabbedPane tabbedPane,
0417: Component tabComponent) {
0418: out("Closing vertical tab - specific");
0419: }
0420: });
0421:
0422: jtp.addTab("Tabbed pane vertical", tp2);
0423: } catch (NoClassDefFoundError ncdfe) {
0424: }
0425:
0426: jtp.addTab("Split", new SplitPanel());
0427:
0428: jtp.addTab("Desktop", getIcon("JDesktopPaneColor16"),
0429: new DesktopPanel());
0430:
0431: jtp.addTab("Text fields", getIcon("JTextPaneColor16"),
0432: new TextFieldsPanel());
0433:
0434: jtp.addTab("Table", getIcon("JTableColor16"), new TablePanel());
0435:
0436: try {
0437: jtp
0438: .addTab("List", getIcon("JListColor16"),
0439: new ListPanel());
0440: } catch (NoClassDefFoundError ncdfe) {
0441: }
0442:
0443: jtp.addTab("Slider", getIcon("JSliderColor16"),
0444: new SliderPanel());
0445:
0446: jtp.addTab("Progress bar", getIcon("JProgressBarColor16"),
0447: new ProgressBarPanel());
0448:
0449: jtp.addTab("Spinner", getIcon("JSpinnerColor16"),
0450: new SpinnerPanel());
0451:
0452: jtp.addTab("Tree", getIcon("JTreeColor16"), new TreePanel());
0453:
0454: jtp.addTab("File tree", getIcon("JTreeColor16"),
0455: new FileTreePanel());
0456:
0457: jtp.addTab("Cards", new CardPanel());
0458:
0459: JPanel bigButtonPanel = new JPanel();
0460: bigButtonPanel.setLayout(new BorderLayout());
0461: bigButtonPanel.add(new JButton("One big button"));
0462: jtp.addTab("Big button", bigButtonPanel);
0463:
0464: JPanel verticalButtonPanel = new JPanel();
0465: verticalButtonPanel.setLayout(new GridLayout(1, 3));
0466: verticalButtonPanel.add(new JButton("Vert button 1"));
0467: verticalButtonPanel.add(new JButton("Vert button 2"));
0468: JPanel smallVerticalButtonPanel = new JPanel();
0469: smallVerticalButtonPanel.setLayout(new GridLayout(4, 4));
0470: for (int row = 0; row < 4; row++) {
0471: for (int col = 0; col < 4; col++) {
0472: JButton vertButton = new JButton("vert");
0473: vertButton.setToolTipText("Vertical button " + row
0474: + ":" + col);
0475: smallVerticalButtonPanel.add(vertButton);
0476: }
0477: }
0478: verticalButtonPanel.add(smallVerticalButtonPanel);
0479: jtp.addTab("Vertical buttons", verticalButtonPanel);
0480:
0481: jtp.addTab("Colored", new ColoredControlsPanel());
0482:
0483: jtp.addTab("Colorized", new ColorizedControlsPanel());
0484:
0485: JPanel buttonStripPanel = new JPanel();
0486: buttonStripPanel.setLayout(new FlowLayout());
0487:
0488: jtp.addTab("Sizes", new SizesPanel());
0489:
0490: jtp.addTab("Alignment", AlignmentPanel.getAlignmentPanel());
0491:
0492: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0493: jtp.addTab("Mixed Buttons",
0494: getIcon("JColorChooserColor16"),
0495: new MixedButtonsPanel());
0496: }
0497:
0498: // sample menu bar
0499: JMenuBar jmb = new JMenuBar();
0500:
0501: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0502:
0503: jmb.add(SampleMenuFactory.getThemeMenu());
0504: jmb.add(SampleMenuFactory.getSkinMenu());
0505:
0506: JMenu jmWatermark = new JMenu("Watermark");
0507: JCheckBoxMenuItem jmiWatermarkObjs = new JCheckBoxMenuItem(
0508: "Use objects");
0509: jmiWatermarkObjs.setSelected(true);
0510: jmiWatermarkObjs.addActionListener(new ActionListener() {
0511: public void actionPerformed(ActionEvent e) {
0512: JCheckBoxMenuItem src = (JCheckBoxMenuItem) e
0513: .getSource();
0514: toUseWatermarksObjs = src.isSelected();
0515: }
0516: });
0517: jmWatermark.add(jmiWatermarkObjs);
0518: toUseWatermarksObjs = jmiWatermarkObjs.isSelected();
0519:
0520: Map<String, WatermarkInfo> allWatermarks = SubstanceLookAndFeel
0521: .getAllWatermarks();
0522: for (Map.Entry<String, WatermarkInfo> watermarkEntry : allWatermarks
0523: .entrySet()) {
0524: String watermarkName = watermarkEntry.getKey();
0525: final String watermarkClassName = watermarkEntry
0526: .getValue().getClassName();
0527:
0528: JMenuItem jmiWatermark = new JMenuItem(watermarkName);
0529: try {
0530: Class watermarkClass = Class
0531: .forName(watermarkClassName);
0532: SubstanceWatermark watermark = (SubstanceWatermark) watermarkClass
0533: .newInstance();
0534: jmiWatermark.setIcon(SubstanceImageCreator
0535: .getWatermarkIcon(watermark));
0536: } catch (Exception exc) {
0537: continue;
0538: }
0539: jmiWatermark.addActionListener(new ActionListener() {
0540: public void actionPerformed(ActionEvent e) {
0541: SwingUtilities.invokeLater(new Runnable() {
0542: public void run() {
0543: if (toUseWatermarksObjs) {
0544: try {
0545: SubstanceLookAndFeel
0546: .setCurrentWatermark((SubstanceWatermark) Class
0547: .forName(
0548: watermarkClassName)
0549: .newInstance());
0550: } catch (Exception exc) {
0551: exc.printStackTrace();
0552: }
0553: } else {
0554: SubstanceLookAndFeel
0555: .setCurrentWatermark(watermarkClassName);
0556: }
0557: SwingUtilities
0558: .updateComponentTreeUI(Check.this );
0559: }
0560: });
0561: }
0562: });
0563: if (watermarkName.equals(SubstanceLookAndFeel
0564: .getCurrentWatermarkName())) {
0565: jmiWatermark.setSelected(true);
0566: }
0567: jmWatermark.add(jmiWatermark);
0568: }
0569:
0570: jmWatermark.addSeparator();
0571:
0572: JMenuItem jmiCoffeeBeansWatermark = new JMenuItem(
0573: "Coffee Beans");
0574: jmiCoffeeBeansWatermark
0575: .addActionListener(new ActionListener() {
0576: public void actionPerformed(ActionEvent e) {
0577: SwingUtilities.invokeLater(new Runnable() {
0578: public void run() {
0579: try {
0580: SubstanceLookAndFeel
0581: .setCurrentWatermark(new SubstanceCoffeeBeansWatermark());
0582: } catch (Exception exc) {
0583: exc.printStackTrace();
0584: }
0585: SwingUtilities
0586: .updateComponentTreeUI(Check.this );
0587: }
0588: });
0589: }
0590: });
0591: if ("Coffee Beans".equals(SubstanceLookAndFeel
0592: .getCurrentWatermarkName())) {
0593: jmiCoffeeBeansWatermark.setSelected(true);
0594: }
0595: jmWatermark.add(jmiCoffeeBeansWatermark);
0596:
0597: JMenuItem jmiVerticalGradientWatermark = new JMenuItem(
0598: "Vertical Gradient");
0599: jmiVerticalGradientWatermark
0600: .addActionListener(new ActionListener() {
0601: public void actionPerformed(ActionEvent e) {
0602: SwingUtilities.invokeLater(new Runnable() {
0603: public void run() {
0604: try {
0605: SubstanceLookAndFeel
0606: .setCurrentWatermark(new SubstanceVerticalGradientWatermark());
0607: } catch (Exception exc) {
0608: exc.printStackTrace();
0609: }
0610: SwingUtilities
0611: .updateComponentTreeUI(Check.this );
0612: }
0613: });
0614: }
0615: });
0616: if ("Vertical Gradient".equals(SubstanceLookAndFeel
0617: .getCurrentWatermarkName())) {
0618: jmiVerticalGradientWatermark.setSelected(true);
0619: }
0620: jmWatermark.add(jmiVerticalGradientWatermark);
0621:
0622: JMenuItem jmiDiagonalGradientWatermark = new JMenuItem(
0623: "Diagonal Gradient");
0624: jmiDiagonalGradientWatermark
0625: .addActionListener(new ActionListener() {
0626: public void actionPerformed(ActionEvent e) {
0627: SwingUtilities.invokeLater(new Runnable() {
0628: public void run() {
0629: try {
0630: SubstanceLookAndFeel
0631: .setCurrentWatermark(new SubstanceDiagonalGradientWatermark());
0632: } catch (Exception exc) {
0633: exc.printStackTrace();
0634: }
0635: SwingUtilities
0636: .updateComponentTreeUI(Check.this );
0637: }
0638: });
0639: }
0640: });
0641: if ("Diagonal Gradient".equals(SubstanceLookAndFeel
0642: .getCurrentWatermarkName())) {
0643: jmiDiagonalGradientWatermark.setSelected(true);
0644: }
0645: jmWatermark.add(jmiDiagonalGradientWatermark);
0646:
0647: jmb.add(jmWatermark);
0648:
0649: JMenu jmButtonShaper = new JMenu("Shapers");
0650: JCheckBoxMenuItem jmiButtonShaperObjs = new JCheckBoxMenuItem(
0651: "Use objects");
0652: jmiButtonShaperObjs.setSelected(true);
0653: jmiButtonShaperObjs.addActionListener(new ActionListener() {
0654: public void actionPerformed(ActionEvent e) {
0655: JCheckBoxMenuItem src = (JCheckBoxMenuItem) e
0656: .getSource();
0657: toUseButtonShapersObjs = src.isSelected();
0658: }
0659: });
0660: jmButtonShaper.add(jmiButtonShaperObjs);
0661: toUseButtonShapersObjs = jmiButtonShaperObjs.isSelected();
0662:
0663: ButtonGroup bgButtonShaper = new ButtonGroup();
0664: Map<String, ButtonShaperInfo> allButtonShapers = SubstanceLookAndFeel
0665: .getAllButtonShapers();
0666: for (Map.Entry<String, ButtonShaperInfo> ButtonShaperEntry : allButtonShapers
0667: .entrySet()) {
0668: String buttonShaperName = ButtonShaperEntry.getKey();
0669: final String buttonShaperClassName = ButtonShaperEntry
0670: .getValue().getClassName();
0671:
0672: JRadioButtonMenuItem jmiButtonShaper = new JRadioButtonMenuItem(
0673: buttonShaperName);
0674: jmiButtonShaper.addActionListener(new ActionListener() {
0675: public void actionPerformed(ActionEvent e) {
0676: SwingUtilities.invokeLater(new Runnable() {
0677: public void run() {
0678: if (toUseButtonShapersObjs) {
0679: try {
0680: SubstanceLookAndFeel
0681: .setCurrentButtonShaper((SubstanceButtonShaper) Class
0682: .forName(
0683: buttonShaperClassName)
0684: .newInstance());
0685: } catch (Exception exc) {
0686: exc.printStackTrace();
0687: }
0688: } else {
0689: SubstanceLookAndFeel
0690: .setCurrentButtonShaper(buttonShaperClassName);
0691: }
0692: SwingUtilities
0693: .updateComponentTreeUI(Check.this );
0694: }
0695: });
0696: }
0697: });
0698: if (buttonShaperName.equals(SubstanceLookAndFeel
0699: .getCurrentButtonShaperName())) {
0700: jmiButtonShaper.setSelected(true);
0701: }
0702: bgButtonShaper.add(jmiButtonShaper);
0703: jmButtonShaper.add(jmiButtonShaper);
0704: }
0705:
0706: jmb.add(jmButtonShaper);
0707:
0708: JMenu jmGradientPainter = new JMenu("Painters");
0709: JCheckBoxMenuItem jmiGradientPainterObjs = new JCheckBoxMenuItem(
0710: "Use objects");
0711: jmiGradientPainterObjs.setSelected(true);
0712: jmiGradientPainterObjs
0713: .addActionListener(new ActionListener() {
0714: public void actionPerformed(ActionEvent e) {
0715: JCheckBoxMenuItem src = (JCheckBoxMenuItem) e
0716: .getSource();
0717: toUseGradientPaintersObjs = src
0718: .isSelected();
0719: }
0720: });
0721: jmGradientPainter.add(jmiGradientPainterObjs);
0722: toUseGradientPaintersObjs = jmiGradientPainterObjs
0723: .isSelected();
0724:
0725: ButtonGroup bgGradientPainter = new ButtonGroup();
0726: Map<String, GradientPainterInfo> allGradientPainters = SubstanceLookAndFeel
0727: .getAllGradientPainters();
0728: for (Map.Entry<String, GradientPainterInfo> GradientPainterEntry : allGradientPainters
0729: .entrySet()) {
0730: String gradientPainterName = GradientPainterEntry
0731: .getKey();
0732: final String gradientPainterClassName = GradientPainterEntry
0733: .getValue().getClassName();
0734:
0735: JRadioButtonMenuItem jmiGradientPainter = new JRadioButtonMenuItem(
0736: gradientPainterName);
0737: jmiGradientPainter
0738: .addActionListener(new ActionListener() {
0739: public void actionPerformed(ActionEvent e) {
0740: SwingUtilities
0741: .invokeLater(new Runnable() {
0742: public void run() {
0743: if (toUseGradientPaintersObjs) {
0744: try {
0745: SubstanceLookAndFeel
0746: .setCurrentGradientPainter((SubstanceGradientPainter) Class
0747: .forName(
0748: gradientPainterClassName)
0749: .newInstance());
0750: } catch (Exception exc) {
0751: exc
0752: .printStackTrace();
0753: }
0754: } else {
0755: SubstanceLookAndFeel
0756: .setCurrentGradientPainter(gradientPainterClassName);
0757: }
0758: SwingUtilities
0759: .updateComponentTreeUI(Check.this );
0760: }
0761: });
0762: }
0763: });
0764: if (gradientPainterName.equals(SubstanceLookAndFeel
0765: .getCurrentGradientPainterName())) {
0766: jmiGradientPainter.setSelected(true);
0767: }
0768: bgGradientPainter.add(jmiGradientPainter);
0769: jmGradientPainter.add(jmiGradientPainter);
0770: }
0771:
0772: jmb.add(jmGradientPainter);
0773: }
0774: JMenu coloredMenu = new JMenu("Colors");
0775: coloredMenu.setMnemonic('0');
0776: final JMenuItem coloredMI = new JMenuItem("Italic red");
0777: // coloredMI.addPropertyChangeListener(new PropertyChangeListener() {
0778: // public void propertyChange(PropertyChangeEvent evt) {
0779: // if ("font".equals(evt.getPropertyName()))
0780: // System.out
0781: // .println("Font changed to " + coloredMI.getFont());
0782: // }
0783: // });
0784: coloredMI.setFont(coloredMI.getFont().deriveFont(Font.ITALIC));
0785: coloredMI.setForeground(Color.red);
0786: coloredMenu.add(coloredMI);
0787: JRadioButtonMenuItem coloredRBMI = new JRadioButtonMenuItem(
0788: "Bold green");
0789: coloredRBMI
0790: .setFont(coloredRBMI.getFont().deriveFont(Font.BOLD));
0791: coloredRBMI.setForeground(Color.green);
0792: coloredMenu.add(coloredRBMI);
0793: JCheckBoxMenuItem coloredCBMI = new JCheckBoxMenuItem(
0794: "Big blue");
0795: coloredCBMI.setFont(coloredCBMI.getFont().deriveFont(32f));
0796: coloredCBMI.setForeground(Color.blue);
0797: coloredMenu.add(coloredCBMI);
0798: JMenu coloredM = new JMenu("Always big magenta");
0799: coloredM.setForeground(Color.magenta);
0800: coloredM.setFont(coloredM.getFont().deriveFont(24f));
0801: coloredMenu.add(coloredM);
0802: jmb.add(coloredMenu);
0803:
0804: JMenu testMenu = SampleMenuFactory.getTestMenu();
0805: jmb.add(testMenu);
0806:
0807: JMenu jm4 = new JMenu("Disabled");
0808: jm4.add(new JMenuItem("dummy4"));
0809: jm4.setMnemonic('4');
0810: jmb.add(jm4);
0811: jm4.setEnabled(false);
0812:
0813: // if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
0814: // JMenu fontSizeMenu = new JMenu("Font size");
0815: // JMenuItem sizeM2 = new JMenuItem("Minus 2 points");
0816: // sizeM2.addActionListener(new FontPolicyChanger(this, -2));
0817: // fontSizeMenu.add(sizeM2);
0818: //
0819: // JMenuItem sizeM1 = new JMenuItem("Minus 1 point");
0820: // sizeM1.addActionListener(new FontPolicyChanger(this, -1));
0821: // fontSizeMenu.add(sizeM1);
0822: //
0823: // JMenuItem sizeB = new JMenuItem("Base");
0824: // sizeB.addActionListener(new FontPolicyChanger(this, 0));
0825: // fontSizeMenu.add(sizeB);
0826: //
0827: // JMenuItem sizeP1 = new JMenuItem("Plus 1 point");
0828: // sizeP1.addActionListener(new FontPolicyChanger(this, 1));
0829: // fontSizeMenu.add(sizeP1);
0830: //
0831: // JMenuItem sizeP2 = new JMenuItem("Plus 2 points");
0832: // sizeP2.addActionListener(new FontPolicyChanger(this, 2));
0833: // fontSizeMenu.add(sizeP2);
0834: //
0835: // jmb.add(fontSizeMenu);
0836: // }
0837:
0838: // LAF changing
0839: jmb.add(SampleMenuFactory.getLookAndFeelMenu(this ));
0840: setJMenuBar(jmb);
0841:
0842: // sample flat toolbar (does nothing)
0843: // JToolBar toolBar = getToolbar("Flat ");
0844: // this.add(toolBar, AKDockLayout.NORTH);
0845:
0846: // // sample non-flat toolbar (does nothing)
0847: // JToolBar toolBar2 = getToolbar("Non-flat ");
0848: // toolBar2.putClientProperty(SubstanceLookAndFeel.TOOLBAR_BUTTON_FLAT,
0849: // Boolean.FALSE);
0850: // this.add(toolBar2, AKDockLayout.NORTH);
0851: //
0852: // final JToolBar toolBar3 = getToolbar("Translucent ");
0853: // toolBar3.putClientProperty(SubstanceLookAndFeel.TOOLBAR_BUTTON_FLAT,
0854: // Boolean.FALSE);
0855: // toolBar3.putClientProperty(SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
0856: // new AlphaControlBackgroundComposite(0.5f));
0857: // final JSlider translucencySlider = new JSlider(0, 100, 50);
0858: // translucencySlider.addChangeListener(new ChangeListener() {
0859: // public void stateChanged(ChangeEvent e) {
0860: // toolBar3.putClientProperty(
0861: // SubstanceLookAndFeel.BACKGROUND_COMPOSITE,
0862: // new AlphaControlBackgroundComposite(translucencySlider
0863: // .getValue() / 100.f));
0864: // toolBar3.repaint();
0865: // }
0866: // });
0867: // toolBar3.add(translucencySlider);
0868: // this.add(toolBar3, AKDockLayout.NORTH);
0869:
0870: // register sample listeners
0871: SubstanceLookAndFeel
0872: .registerThemeChangeListener(new MyThemeChangeListener());
0873: SubstanceLookAndFeel
0874: .registerWatermarkChangeListener(new MyWatermarkChangeListener());
0875: SubstanceLookAndFeel
0876: .registerButtonShaperChangeListener(new MyButtonShaperChangeListener());
0877: SubstanceLookAndFeel
0878: .registerGradientPainterChangeListener(new MyGradientPainterChangeListener());
0879: // SubstanceLookAndFeel
0880: // .registerSkinChangeListener(new SkinChangeListener() {
0881: // public void skinChanged() {
0882: // TransitionLayoutManager.getInstance().track(jtp, true);
0883: // }
0884: // });
0885:
0886: TabCloseCallback closeCallbackMain = new TabCloseCallback() {
0887: public TabCloseKind onAreaClick(JTabbedPane tabbedPane,
0888: int tabIndex, MouseEvent mouseEvent) {
0889: if (mouseEvent.getButton() != MouseEvent.BUTTON2)
0890: return TabCloseKind.NONE;
0891: if (mouseEvent.isShiftDown()) {
0892: return TabCloseKind.ALL;
0893: }
0894: return TabCloseKind.THIS;
0895: }
0896:
0897: public TabCloseKind onCloseButtonClick(
0898: JTabbedPane tabbedPane, int tabIndex,
0899: MouseEvent mouseEvent) {
0900: if (mouseEvent.isAltDown()) {
0901: return TabCloseKind.ALL_BUT_THIS;
0902: }
0903: if (mouseEvent.isShiftDown()) {
0904: return TabCloseKind.ALL;
0905: }
0906: return TabCloseKind.THIS;
0907: }
0908:
0909: public String getAreaTooltip(JTabbedPane tabbedPane,
0910: int tabIndex) {
0911: return null;
0912: }
0913:
0914: public String getCloseButtonTooltip(JTabbedPane tabbedPane,
0915: int tabIndex) {
0916: StringBuffer result = new StringBuffer();
0917: result.append("<html><body>");
0918: result.append("Mouse click closes <b>"
0919: + tabbedPane.getTitleAt(tabIndex) + "</b> tab");
0920: result
0921: .append("<br><b>Alt</b>-Mouse click closes all tabs but <b>"
0922: + tabbedPane.getTitleAt(tabIndex)
0923: + "</b> tab");
0924: result
0925: .append("<br><b>Shift</b>-Mouse click closes all tabs");
0926: result.append("</body></html>");
0927: return result.toString();
0928: }
0929: };
0930:
0931: jtp.putClientProperty(
0932: SubstanceLookAndFeel.TABBED_PANE_CLOSE_CALLBACK,
0933: closeCallbackMain);
0934: SubstanceLookAndFeel
0935: .registerTabCloseChangeListener(new TabCloseListener() {
0936: public void tabClosed(JTabbedPane tabbedPane,
0937: Component tabComponent) {
0938: out("Closed tab");
0939: }
0940:
0941: public void tabClosing(JTabbedPane tabbedPane,
0942: Component tabComponent) {
0943: out("Closing tab");
0944: }
0945: });
0946:
0947: SubstanceLookAndFeel.registerTabCloseChangeListener(jtp,
0948: new VetoableTabCloseListener() {
0949: public void tabClosed(JTabbedPane tabbedPane,
0950: Component tabComponent) {
0951: out("Closed tab - specific");
0952: }
0953:
0954: public void tabClosing(JTabbedPane tabbedPane,
0955: Component tabComponent) {
0956: out("Closing tab - specific");
0957: }
0958:
0959: public boolean vetoTabClosing(
0960: JTabbedPane tabbedPane,
0961: Component tabComponent) {
0962: int userCloseAnswer = JOptionPane
0963: .showConfirmDialog(
0964: Check.this ,
0965: "Are you sure you want to close '"
0966: + tabbedPane
0967: .getTitleAt(tabbedPane
0968: .indexOfComponent(tabComponent))
0969: + "' tab?",
0970: "Confirm dialog",
0971: JOptionPane.YES_NO_OPTION);
0972: return (userCloseAnswer == JOptionPane.NO_OPTION);
0973: }
0974: });
0975:
0976: SubstanceLookAndFeel.registerTabCloseChangeListener(jtp,
0977: new VetoableMultipleTabCloseListener() {
0978: public void tabsClosed(JTabbedPane tabbedPane,
0979: Set<Component> tabComponents) {
0980: out("Closed " + tabComponents.size()
0981: + " tabs - specific");
0982: }
0983:
0984: public void tabsClosing(JTabbedPane tabbedPane,
0985: Set<Component> tabComponents) {
0986: out("Closing " + tabComponents.size()
0987: + " tabs - specific");
0988: }
0989:
0990: public boolean vetoTabsClosing(
0991: JTabbedPane tabbedPane,
0992: Set<Component> tabComponents) {
0993: int userCloseAnswer = JOptionPane
0994: .showConfirmDialog(Check.this ,
0995: "Are you sure you want to close "
0996: + tabComponents.size()
0997: + " tabs?",
0998: "Confirm dialog",
0999: JOptionPane.YES_NO_OPTION);
1000: return (userCloseAnswer == JOptionPane.NO_OPTION);
1001: }
1002: });
1003:
1004: addComponentListener(new ComponentAdapter() {
1005: @Override
1006: public void componentResized(ComponentEvent e) {
1007: System.out.println("Size " + getSize());
1008: }
1009: });
1010:
1011: }
1012:
1013: protected static JXStatusBar getStatusBar(final JXPanel jxPanel,
1014: final JTabbedPane mainTabbedPane) {
1015: JXStatusBar statusBar = new JXStatusBar();
1016:
1017: try {
1018: ClassLoader cl = Thread.currentThread()
1019: .getContextClassLoader();
1020: Enumeration<URL> urls = cl
1021: .getResources("META-INF/MANIFEST.MF");
1022: String substanceVer = null;
1023: String substanceBuildStamp = null;
1024: while (urls.hasMoreElements()) {
1025: InputStream is = urls.nextElement().openStream();
1026: BufferedReader br = new BufferedReader(
1027: new InputStreamReader(is));
1028: while (true) {
1029: String line = br.readLine();
1030: if (line == null)
1031: break;
1032: int firstColonIndex = line.indexOf(":");
1033: if (firstColonIndex < 0)
1034: continue;
1035: String name = line.substring(0, firstColonIndex)
1036: .trim();
1037: String val = line.substring(firstColonIndex + 1)
1038: .trim();
1039: if (name.compareTo("Substance-Version") == 0)
1040: substanceVer = val;
1041: if (name.compareTo("Substance-BuildStamp") == 0)
1042: substanceBuildStamp = val;
1043: }
1044: try {
1045: br.close();
1046: } catch (IOException ioe) {
1047: }
1048: }
1049: if (substanceVer != null) {
1050: JLabel statusLabel = new JLabel(substanceVer
1051: + " [built on " + substanceBuildStamp + "]");
1052: JXStatusBar.Constraint cStatusLabel = new JXStatusBar.Constraint();
1053: cStatusLabel.setFixedWidth(300);
1054: statusBar.add(statusLabel, cStatusLabel);
1055: }
1056: } catch (IOException ioe) {
1057: }
1058:
1059: // final JLabel statusLabel = new JLabel("");
1060: // JXStatusBar.Constraint cStatusLabel = new JXStatusBar.Constraint();
1061: // cStatusLabel.setFixedWidth(100);
1062: // statusBar.add(statusLabel, cStatusLabel);
1063: // try {
1064: // Toolkit.getDefaultToolkit().addAWTEventListener(
1065: // new AWTEventListener() {
1066: // public void eventDispatched(AWTEvent event) {
1067: // if (event instanceof MouseEvent) {
1068: // MouseEvent me = (MouseEvent) event;
1069: // if (me.getID() == MouseEvent.MOUSE_MOVED) {
1070: // Point p = me.getPoint();
1071: // statusLabel.setText(p.x + ":" + p.y);
1072: // }
1073: // }
1074: // }
1075: // }, AWTEvent.MOUSE_MOTION_EVENT_MASK);
1076: // } catch (AccessControlException ace) {
1077: // // running in JNLP - ignore
1078: // }
1079:
1080: JXStatusBar.Constraint c2 = new JXStatusBar.Constraint(
1081: JXStatusBar.Constraint.ResizeBehavior.FILL);
1082: final JLabel tabLabel = new JLabel("");
1083: statusBar.add(tabLabel, c2);
1084: mainTabbedPane.getModel().addChangeListener(
1085: new ChangeListener() {
1086: public void stateChanged(ChangeEvent e) {
1087: int selectedIndex = mainTabbedPane
1088: .getSelectedIndex();
1089: if (selectedIndex < 0)
1090: tabLabel.setText("No selected tab");
1091: else
1092: tabLabel.setText("Tab "
1093: + mainTabbedPane
1094: .getTitleAt(selectedIndex)
1095: + " selected");
1096: }
1097: });
1098:
1099: JPanel fontSizePanel = FontSizePanel.getPanel();
1100: JXStatusBar.Constraint fontSizePanelConstraints = new JXStatusBar.Constraint();
1101: fontSizePanelConstraints.setFixedWidth(190);
1102: statusBar.add(fontSizePanel, fontSizePanelConstraints);
1103:
1104: JPanel alphaPanel = new JPanel(new FlowLayout(
1105: FlowLayout.LEADING, 0, 0));
1106: // alphaPanel.setOpaque(false);
1107:
1108: final JLabel alphaLabel = new JLabel("100%");
1109: final JSlider alphaSlider = new JSlider(0, 100, 100);
1110: alphaSlider.setFocusable(false);
1111: // alphaSlider.setOpaque(false);
1112: alphaSlider.addChangeListener(new ChangeListener() {
1113: public void stateChanged(ChangeEvent e) {
1114: int currValue = alphaSlider.getValue();
1115: alphaLabel.setText(currValue + "%");
1116: jxPanel.setAlpha(currValue / 100.0f);
1117: }
1118: });
1119: alphaSlider
1120: .setToolTipText("Changes the global opacity. Is not Substance-specific");
1121: alphaSlider.setPreferredSize(new Dimension(120, alphaSlider
1122: .getPreferredSize().height));
1123:
1124: alphaPanel.add(alphaLabel);
1125: alphaPanel.add(alphaSlider);
1126:
1127: JXStatusBar.Constraint alphaPanelConstraints = new JXStatusBar.Constraint();
1128: alphaPanelConstraints.setFixedWidth(160);
1129: statusBar.add(alphaPanel, alphaPanelConstraints);
1130: return statusBar;
1131: }
1132:
1133: public static JButton getPill(SubstanceTheme theme1,
1134: SubstanceTheme theme2) {
1135: JButton result = new JButton("Pill");
1136: result.putClientProperty(
1137: SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY,
1138: SpecularGradientPainter.class.getName());
1139: result.putClientProperty(
1140: SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
1141: Boolean.TRUE);
1142: result.putClientProperty(SubstanceLookAndFeel.THEME_PROPERTY,
1143: new SubstanceMixTheme(theme1, theme2));
1144: result.putClientProperty(
1145: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
1146: StandardButtonShaper.class.getName());
1147: return result;
1148: }
1149:
1150: public static JButton getMultiPill(SubstanceTheme... themes) {
1151: JButton result = new JButton(themes.length + "Pill");
1152: result.putClientProperty(
1153: SubstanceLookAndFeel.GRADIENT_PAINTER_PROPERTY,
1154: SpecularGradientPainter.class.getName());
1155: result.putClientProperty(
1156: SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
1157: Boolean.TRUE);
1158: result.putClientProperty(SubstanceLookAndFeel.THEME_PROPERTY,
1159: new SubstanceMixTheme(themes));
1160: result.putClientProperty(
1161: SubstanceLookAndFeel.BUTTON_SHAPER_PROPERTY,
1162: StandardButtonShaper.class.getName());
1163: return result;
1164: }
1165:
1166: public static void main(String[] args) {
1167: boolean hasLafSpecified = false;
1168: try {
1169: hasLafSpecified = (System.getProperty("swing.defaultlaf") != null);
1170: } catch (Throwable t) {
1171: // JNLP sandbox
1172: }
1173:
1174: try {
1175: if (!hasLafSpecified) {
1176: out(" CREATING LAF ");
1177: long time0 = System.currentTimeMillis();
1178: LookAndFeel laf = (LookAndFeel) Class
1179: .forName(
1180: "org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel")
1181: .newInstance();
1182: long time1 = System.currentTimeMillis();
1183: out(" LAF CREATED " + (time1 - time0));
1184: out(" SETTING LAF ");
1185: long time2 = System.currentTimeMillis();
1186: UIManager.setLookAndFeel(laf);
1187: long time3 = System.currentTimeMillis();
1188: out(" LAF SET " + (time3 - time2));
1189: }
1190: } catch (Exception e) {
1191: e.printStackTrace();
1192: }
1193:
1194: SubstanceLookAndFeel.setToUseConstantThemesOnDialogs(true);
1195:
1196: UIManager
1197: .put(
1198: SubstanceLookAndFeel.TABBED_PANE_CLOSE_BUTTONS_PROPERTY,
1199: Boolean.TRUE);
1200: // try {
1201: // if (System.getProperty("substancelaf.useDecorations") == null) {
1202: JFrame.setDefaultLookAndFeelDecorated(true);
1203: JDialog.setDefaultLookAndFeelDecorated(true);
1204: // }
1205: // } catch (AccessControlException ace) {
1206: // JFrame.setDefaultLookAndFeelDecorated(true);
1207: // JDialog.setDefaultLookAndFeelDecorated(true);
1208: // }
1209: // System.setProperty("sun.awt.noerasebackground", "false");
1210:
1211: SwingUtilities.invokeLater(new Runnable() {
1212: public void run() {
1213: long time2 = System.currentTimeMillis();
1214: Check c = new Check();
1215: c.addComponentListener(new ComponentAdapter() {
1216: @Override
1217: public void componentResized(ComponentEvent e) {
1218: super .componentResized(e);
1219: ((JFrame) e.getComponent()).getRootPane()
1220: .repaint();
1221: }
1222: });
1223: c.setPreferredSize(new Dimension(820, 560));
1224: c.setMinimumSize(new Dimension(150, 100));
1225: c.pack();
1226: Dimension d = Toolkit.getDefaultToolkit()
1227: .getScreenSize();
1228: // center the frame in the physical screen
1229: c.setLocation((d.width - c.getWidth()) / 2,
1230: (d.height - c.getHeight()) / 2);
1231:
1232: c.setVisible(true);
1233: c
1234: .setDefaultCloseOperation(System
1235: .getProperty("javawebstart.version") != null ? JFrame.EXIT_ON_CLOSE
1236: : JFrame.DISPOSE_ON_CLOSE);
1237: long time3 = System.currentTimeMillis();
1238: out("App " + (time3 - time2));
1239: }
1240: });
1241: }
1242:
1243: public static void out(Object obj) {
1244: try {
1245: System.out.println(obj);
1246: } catch (Exception exc) {
1247: // ignore - is thrown on Mac in WebStart (security access)
1248: }
1249: }
1250:
1251: public static void setTheme(final SubstanceTheme theme) {
1252: SwingUtilities.invokeLater(new Runnable() {
1253: public void run() {
1254: try {
1255: SubstanceLookAndFeel.setCurrentTheme(theme);
1256: UIManager
1257: .setLookAndFeel(new SubstanceLookAndFeel());
1258: } catch (Exception exc) {
1259: exc.printStackTrace();
1260: }
1261: for (Frame frame : Frame.getFrames())
1262: SwingUtilities.updateComponentTreeUI(frame);
1263: out(UIManager.getColor("TabbedPane.selectHighlight"));
1264: }
1265: });
1266: }
1267:
1268: public static Icon getIcon(String iconName) {
1269: ClassLoader cl = Thread.currentThread().getContextClassLoader();
1270: URL url = cl.getResource("test/check/icons/" + iconName
1271: + ".gif");
1272: if (url != null)
1273: return new ImageIcon(url);
1274: url = cl.getResource("test/check/icons/" + iconName + ".png");
1275: if (url != null)
1276: return new ImageIcon(url);
1277: return null;
1278: }
1279:
1280: public static JToolBar getToolbar(String label, int size,
1281: boolean hasStrings) {
1282: JToolBar toolBar = new JToolBar();
1283: // toolBar.setLayout(new BoxLayout(toolBar,BoxLayout.LINE_AXIS));
1284: // toolBar.setFloatable(false);
1285:
1286: JButton buttonCut = new JButton(hasStrings ? "cut" : null,
1287: getIcon(size + "/edit-cut"));
1288: buttonCut.putClientProperty(
1289: SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY,
1290: Boolean.TRUE);
1291: toolBar.add(buttonCut);
1292: JButton buttonCopy = new JButton(hasStrings ? "copy" : null,
1293: getIcon(size + "/edit-copy"));
1294: buttonCopy.putClientProperty(
1295: SubstanceLookAndFeel.BUTTON_NO_MIN_SIZE_PROPERTY,
1296: Boolean.TRUE);
1297: buttonCopy.setEnabled(false);
1298: toolBar.add(buttonCopy);
1299: JButton buttonPaste = new JButton(getIcon(size + "/edit-paste"));
1300: toolBar.add(buttonPaste);
1301: JButton buttonSelectAll = new JButton(getIcon(size
1302: + "/edit-select-all"));
1303: toolBar.add(buttonSelectAll);
1304: JButton buttonDelete = new JButton(getIcon(size
1305: + "/edit-delete"));
1306: toolBar.add(buttonDelete);
1307: toolBar.addSeparator();
1308:
1309: // add an inner toolbar to check the painting of toolbar
1310: // gradient and drop shadows under different skins.
1311: JToolBar innerToolbar = new JToolBar(JToolBar.HORIZONTAL);
1312: innerToolbar.setFloatable(false);
1313: JToggleButton buttonFormatCenter = new JToggleButton(
1314: getIcon(size + "/format-justify-center"));
1315: buttonFormatCenter
1316: .putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS,
1317: Float.valueOf(5.0f));
1318: innerToolbar.add(buttonFormatCenter);
1319: JToggleButton buttonFormatLeft = new JToggleButton(getIcon(size
1320: + "/format-justify-left"));
1321: innerToolbar.add(buttonFormatLeft);
1322: JToggleButton buttonFormatRight = new JToggleButton(
1323: getIcon(size + "/format-justify-right"));
1324: innerToolbar.add(buttonFormatRight);
1325: JToggleButton buttonFormatFill = new JToggleButton(getIcon(size
1326: + "/format-justify-fill"));
1327: buttonFormatFill
1328: .putClientProperty(SubstanceLookAndFeel.CORNER_RADIUS,
1329: Float.valueOf(0.0f));
1330: innerToolbar.add(buttonFormatFill);
1331:
1332: toolBar.add(innerToolbar);
1333: toolBar.addSeparator();
1334:
1335: if (size > 20) {
1336: // JPanel groupPanel = new JPanel();
1337: // BoxLayout groupLayout = new BoxLayout(groupPanel,
1338: // BoxLayout.LINE_AXIS);
1339: // groupPanel.setLayout(groupLayout);
1340: JToolBar innerToolbar2 = new JToolBar(JToolBar.HORIZONTAL);
1341: innerToolbar2.setFloatable(false);
1342:
1343: JPanel innerPanel = new JPanel(new FlowLayout(
1344: FlowLayout.LEFT, 0, 0));// new
1345: // BorderLayout());
1346: innerToolbar2.add(innerPanel, BorderLayout.CENTER);
1347:
1348: final JToggleButton buttonStyleBold = new JToggleButton(
1349: getIcon(size + "/format-text-bold"));
1350: Set<Side> rightSide = new HashSet<Side>();
1351: rightSide.add(Side.RIGHT);
1352: buttonStyleBold.putClientProperty(
1353: SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY,
1354: rightSide);
1355: buttonStyleBold.putClientProperty(
1356: SubstanceLookAndFeel.CORNER_RADIUS, Float
1357: .valueOf(3.0f));
1358:
1359: final JToggleButton buttonStyleItalic = new JToggleButton(
1360: getIcon(size + "/format-text-italic"));
1361: buttonStyleItalic.putClientProperty(
1362: SubstanceLookAndFeel.CORNER_RADIUS, Float
1363: .valueOf(0.0f));
1364: buttonStyleItalic.putClientProperty(
1365: SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY,
1366: rightSide);
1367:
1368: final JToggleButton buttonStyleUnderline = new JToggleButton(
1369: getIcon(size + "/format-text-underline"));
1370: buttonStyleUnderline.putClientProperty(
1371: SubstanceLookAndFeel.CORNER_RADIUS, Float
1372: .valueOf(0.0f));
1373: buttonStyleUnderline.putClientProperty(
1374: SubstanceLookAndFeel.BUTTON_OPEN_SIDE_PROPERTY,
1375: rightSide);
1376:
1377: final JToggleButton buttonStyleStrikethrough = new JToggleButton(
1378: getIcon(size + "/format-text-strikethrough"));
1379: buttonStyleStrikethrough.putClientProperty(
1380: SubstanceLookAndFeel.BUTTON_SIDE_PROPERTY,
1381: SubstanceConstants.Side.LEFT.name());
1382: buttonStyleStrikethrough.putClientProperty(
1383: SubstanceLookAndFeel.CORNER_RADIUS, Float
1384: .valueOf(3.0f));
1385: buttonStyleBold.setSelected(true);
1386:
1387: innerPanel.add(buttonStyleBold);
1388: innerPanel.add(buttonStyleItalic);
1389: innerPanel.add(buttonStyleUnderline);
1390: innerPanel.add(buttonStyleStrikethrough);
1391:
1392: toolBar.add(innerToolbar2);
1393: }
1394: // toolBar.add(groupPanel);
1395:
1396: toolBar.add(Box.createGlue());
1397: JButton buttonExit = new JButton(
1398: getIcon(size + "/process-stop"));
1399: buttonExit.setToolTipText("Closes the test application");
1400: buttonExit.addActionListener(new ActionListener() {
1401: public void actionPerformed(ActionEvent e) {
1402: System.exit(0);
1403: }
1404: });
1405: toolBar.add(buttonExit);
1406:
1407: return toolBar;
1408: }
1409:
1410: public static void setTheme(final ThemeInfo themeInfo,
1411: final boolean useInstance) {
1412: SwingUtilities.invokeLater(new Runnable() {
1413: public void run() {
1414: try {
1415: if (useInstance)
1416: SubstanceLookAndFeel
1417: .setCurrentTheme(SubstanceTheme
1418: .createInstance(themeInfo));
1419: else
1420: SubstanceLookAndFeel.setCurrentTheme(themeInfo
1421: .getClassName());
1422: // UIManager.setLookAndFeel(new SubstanceLookAndFeel());
1423: } catch (Exception exc) {
1424: exc.printStackTrace();
1425: }
1426: for (Frame frame : Frame.getFrames())
1427: SwingUtilities.updateComponentTreeUI(frame);
1428: }
1429: });
1430: }
1431:
1432: public void setSpecificTaskPane(JPanel contents, String title,
1433: Icon icon) {
1434: if (currentSpecificTaskPane != null) {
1435: taskPaneContainer.remove(currentSpecificTaskPane);
1436: }
1437: currentSpecificTaskPane = new JXTaskPane();
1438: currentSpecificTaskPane.setLayout(new BorderLayout());
1439: currentSpecificTaskPane.setTitle(title);
1440: currentSpecificTaskPane.setIcon(icon);
1441: // contents.setOpaque(false);
1442: SwingUtilities.updateComponentTreeUI(contents);
1443: // currentSpecificTaskPane.setOpaque(false);
1444: currentSpecificTaskPane.add(contents, BorderLayout.CENTER);
1445:
1446: // this.mainTaskPane.setExpanded(false);
1447: taskPaneContainer.add(currentSpecificTaskPane);
1448: }
1449:
1450: public void clearSpecificTaskPane() {
1451: if (currentSpecificTaskPane != null) {
1452: taskPaneContainer.remove(currentSpecificTaskPane);
1453: }
1454: currentSpecificTaskPane = null;
1455: // this.mainTaskPane.setExpanded(true);
1456: }
1457:
1458: public class TabSwitchListener implements ChangeListener {
1459: public void stateChanged(ChangeEvent e) {
1460: Component selected = jtp.getSelectedComponent();
1461: if (selected instanceof Controllable) {
1462: JPanel controlPanel = ((Controllable) selected)
1463: .getControlPanel();
1464: if (controlPanel == null)
1465: clearSpecificTaskPane();
1466: else
1467: setSpecificTaskPane(controlPanel, jtp
1468: .getTitleAt(jtp.getSelectedIndex()), jtp
1469: .getIconAt(jtp.getSelectedIndex()));
1470: } else {
1471: clearSpecificTaskPane();
1472: }
1473: }
1474: }
1475:
1476: public static class MyMainTabPreviewPainter extends
1477: DefaultTabPreviewPainter {
1478: protected TabOverviewKind tabOverviewKind;
1479:
1480: public void setTabOverviewKind(TabOverviewKind tabOverviewKind) {
1481: this .tabOverviewKind = tabOverviewKind;
1482: }
1483:
1484: @Override
1485: public TabOverviewKind getOverviewKind(JTabbedPane tabPane) {
1486: if (tabOverviewKind == null)
1487: return super .getOverviewKind(tabPane);
1488: return tabOverviewKind;
1489: }
1490:
1491: @Override
1492: public void previewTab(JTabbedPane tabPane, int tabIndex,
1493: Graphics g, int x, int y, int w, int h) {
1494: if (tabPane.getComponentAt(tabIndex) instanceof MixedButtonsPanel) {
1495: Graphics2D graphics = (Graphics2D) g.create();
1496: int fontSize = Math.min(w, h) / 6;
1497: Font font = new Font("Arial", Font.PLAIN, fontSize);
1498: graphics.setFont(font);
1499: graphics.setColor(Color.black);
1500: graphics.setRenderingHint(
1501: RenderingHints.KEY_TEXT_ANTIALIASING,
1502: RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
1503: graphics.drawString("Mixed buttons", x + 5, y + w / 2
1504: - fontSize);
1505: graphics.drawRect(x, y, w - 1, h - 1);
1506: graphics.dispose();
1507: } else {
1508: super.previewTab(tabPane, tabIndex, g, x, y, w, h);
1509: }
1510: }
1511: }
1512: }
|