001: /*
002: * Copyright (c) 2005-2008 Substance Kirill Grouchnikov. All Rights Reserved.
003: *
004: * Redistribution and use in source and binary forms, with or without
005: * modification, are permitted provided that the following conditions are met:
006: *
007: * o Redistributions of source code must retain the above copyright notice,
008: * this list of conditions and the following disclaimer.
009: *
010: * o Redistributions in binary form must reproduce the above copyright notice,
011: * this list of conditions and the following disclaimer in the documentation
012: * and/or other materials provided with the distribution.
013: *
014: * o Neither the name of Substance Kirill Grouchnikov nor the names of
015: * its contributors may be used to endorse or promote products derived
016: * from this software without specific prior written permission.
017: *
018: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
019: * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
020: * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
021: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
022: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
023: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
024: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
025: * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
026: * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE
027: * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
028: * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
029: */
030: package test.samples.substance.api;
031:
032: import java.awt.*;
033: import java.awt.event.ActionEvent;
034: import java.awt.event.ActionListener;
035:
036: import javax.swing.*;
037:
038: import org.jvnet.substance.SubstanceLookAndFeel;
039: import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
040:
041: import test.Check;
042:
043: /**
044: * Test application that shows the use of the
045: * {@link SubstanceLookAndFeel#setToUseConstantThemesOnDialogs(boolean)} API.
046: *
047: * @author Kirill Grouchnikov
048: * @see SubstanceLookAndFeel#setToUseConstantThemesOnDialogs(boolean)
049: */
050: public class SetUseConstantThemesOnDialogs extends JFrame {
051: /**
052: * Creates the main frame for <code>this</code> sample.
053: */
054: public SetUseConstantThemesOnDialogs() {
055: super ("Use constant themes on dialogs");
056:
057: this .setLayout(new BorderLayout());
058:
059: JPanel buttonPanel = new JPanel(new FlowLayout());
060: JButton bopi = new JButton("Info", Check
061: .getIcon("22/dialog-information"));
062: bopi.addActionListener(new ActionListener() {
063: public void actionPerformed(ActionEvent e) {
064: JOptionPane.showMessageDialog(
065: SetUseConstantThemesOnDialogs.this ,
066: "Sample info message", "Sample title",
067: JOptionPane.INFORMATION_MESSAGE);
068: }
069: });
070: buttonPanel.add(bopi);
071:
072: JButton bope = new JButton("Show", Check
073: .getIcon("22/dialog-error"));
074: bope.addActionListener(new ActionListener() {
075: public void actionPerformed(ActionEvent e) {
076: JOptionPane.showMessageDialog(
077: SetUseConstantThemesOnDialogs.this ,
078: "Sample error message", "Sample title",
079: JOptionPane.ERROR_MESSAGE);
080: }
081: });
082: buttonPanel.add(bope);
083:
084: JButton bopw = new JButton("Show", Check
085: .getIcon("22/dialog-warning"));
086: bopw.addActionListener(new ActionListener() {
087: public void actionPerformed(ActionEvent e) {
088: JOptionPane.showMessageDialog(
089: SetUseConstantThemesOnDialogs.this ,
090: "Sample warning message", "Sample title",
091: JOptionPane.WARNING_MESSAGE);
092: }
093: });
094: buttonPanel.add(bopw);
095:
096: JButton bopq = new JButton("Show", Check
097: .getIcon("22/help-browser"));
098: bopq.addActionListener(new ActionListener() {
099: public void actionPerformed(ActionEvent e) {
100: JOptionPane.showMessageDialog(
101: SetUseConstantThemesOnDialogs.this ,
102: "Sample question message", "Sample title",
103: JOptionPane.QUESTION_MESSAGE);
104: }
105: });
106: buttonPanel.add(bopq);
107:
108: this .add(buttonPanel, BorderLayout.CENTER);
109:
110: JPanel controls = new JPanel(new FlowLayout(FlowLayout.RIGHT));
111: final JCheckBox useConstantThemesOnDialogs = new JCheckBox(
112: "Use constant themes on dialogs");
113: useConstantThemesOnDialogs.setSelected(SubstanceLookAndFeel
114: .isToUseConstantThemesOnDialogs());
115: useConstantThemesOnDialogs
116: .addActionListener(new ActionListener() {
117: public void actionPerformed(ActionEvent e) {
118: SwingUtilities.invokeLater(new Runnable() {
119: public void run() {
120: SubstanceLookAndFeel
121: .setToUseConstantThemesOnDialogs(useConstantThemesOnDialogs
122: .isSelected());
123: try {
124: UIManager
125: .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
126: for (Frame frame : Frame
127: .getFrames())
128: SwingUtilities
129: .updateComponentTreeUI(frame);
130: } catch (Throwable t) {
131: }
132: }
133: });
134: }
135: });
136: controls.add(useConstantThemesOnDialogs);
137: this .add(controls, BorderLayout.SOUTH);
138:
139: this .setSize(400, 200);
140: this .setLocationRelativeTo(null);
141: this .setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
142: }
143:
144: /**
145: * The main method for <code>this</code> sample. The arguments are
146: * ignored.
147: *
148: * @param args
149: * Ignored.
150: * @throws Exception
151: * If some exception occured. Note that there is no special
152: * treatment of exception conditions in <code>this</code>
153: * sample code.
154: */
155: public static void main(String[] args) throws Exception {
156: UIManager
157: .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
158: JDialog.setDefaultLookAndFeelDecorated(true);
159: JFrame.setDefaultLookAndFeelDecorated(true);
160: SwingUtilities.invokeLater(new Runnable() {
161: public void run() {
162: new SetUseConstantThemesOnDialogs().setVisible(true);
163: }
164: });
165: }
166: }
|