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.check;
031:
032: import java.awt.*;
033: import java.awt.event.*;
034: import java.security.AccessControlException;
035: import java.util.ArrayList;
036: import java.util.List;
037:
038: import javax.swing.*;
039: import javax.swing.border.EmptyBorder;
040: import javax.swing.tree.DefaultMutableTreeNode;
041:
042: import org.jvnet.lafwidget.LafWidget;
043: import org.jvnet.lafwidget.layout.TransitionLayout;
044: import org.jvnet.lafwidget.layout.TransitionLayoutManager;
045: import org.jvnet.lafwidget.tabbed.DefaultTabPreviewPainter;
046: import org.jvnet.lafwidget.utils.LafConstants.AnimationKind;
047: import org.jvnet.substance.SubstanceImageCreator;
048: import org.jvnet.substance.SubstanceLookAndFeel;
049: import org.jvnet.substance.button.ButtonShaperChangeListener;
050: import org.jvnet.substance.painter.GradientPainterChangeListener;
051: import org.jvnet.substance.skin.SkinChangeListener;
052: import org.jvnet.substance.skin.SubstanceBusinessBlackSteelLookAndFeel;
053: import org.jvnet.substance.theme.*;
054: import org.jvnet.substance.watermark.WatermarkChangeListener;
055:
056: import test.Check;
057:
058: import com.jgoodies.forms.builder.PanelBuilder;
059: import com.jgoodies.forms.layout.CellConstraints;
060: import com.jgoodies.forms.layout.FormLayout;
061:
062: public class SampleFrame extends JFrame {
063: protected JButton prev;
064: private JTabbedPane tabbed;
065: private JTree tree;
066: private JList list;
067:
068: private static class MyListModel extends AbstractListModel {
069: protected List<String> model;
070:
071: public MyListModel() {
072: super ();
073: this .model = new ArrayList<String>();
074: this .model.add("Ohio State [Buckeyes]");
075: this .model.add("Auburn [Tigers]");
076: this .model.add("University of South California [Trojans]");
077: this .model.add("West Virginia [Mountaineers]");
078: this .model.add("Florida [Gators]");
079: this .model.add("Michigan [Wolverines]");
080: this .model.add("Texas [Longhorns]");
081: this .model.add("Louisville [Cardinals]");
082: this .model.add("Louisiana State University [Tigers]");
083: this .model.add("Georgia [Bulldogs]");
084: this .model.add("Virginia Tech [Hokies]");
085: this .model.add("Notre Dame [Fighting Irish]");
086: this .model.add("Iowa [Hawkeyes]");
087: this .model.add("Oregon [Ducks]");
088: this .model.add("Tennessee [Volunteers]");
089: this .model.add("Oklahoma [Sooners]");
090: this .model.add("Texas Christian University [Horned Frogs]");
091: }
092:
093: public Object getElementAt(int index) {
094: return this .model.get(index);
095: }
096:
097: public int getSize() {
098: return this .model.size();
099: }
100: }
101:
102: protected static class TraitChangeListener implements
103: ThemeChangeListener, WatermarkChangeListener,
104: GradientPainterChangeListener, ButtonShaperChangeListener,
105: SkinChangeListener {
106: protected JTabbedPane jtp;
107:
108: protected boolean installTransitionLayout;
109:
110: public TraitChangeListener(JTabbedPane jtp,
111: boolean installTransitionLayout) {
112: this .jtp = jtp;
113: this .installTransitionLayout = installTransitionLayout;
114: }
115:
116: protected void update() {
117: if (this .jtp.getLayout() instanceof TransitionLayout)
118: return;
119: if (!this .installTransitionLayout)
120: return;
121: TransitionLayoutManager.getInstance().track(this .jtp, true);
122: }
123:
124: public void buttonShaperChanged() {
125: this .update();
126: }
127:
128: public void gradientPainterChanged() {
129: this .update();
130: }
131:
132: public void skinChanged() {
133: this .update();
134: }
135:
136: public void themeChanged() {
137: this .update();
138: }
139:
140: public void titlePainterChanged() {
141: this .update();
142: }
143:
144: public void watermarkChanged() {
145: this .update();
146: }
147: }
148:
149: public SampleFrame(boolean installTransitionLayout) {
150: super ("Test application");
151: this .setLayout(new BorderLayout());
152: this .tabbed = new JTabbedPane();
153: if (installTransitionLayout)
154: TransitionLayoutManager.getInstance().track(this .tabbed,
155: true);
156: TraitChangeListener tcl = new TraitChangeListener(this .tabbed,
157: installTransitionLayout);
158: SubstanceLookAndFeel.registerThemeChangeListener(tcl);
159: SubstanceLookAndFeel.registerButtonShaperChangeListener(tcl);
160: SubstanceLookAndFeel.registerGradientPainterChangeListener(tcl);
161: SubstanceLookAndFeel.registerSkinChangeListener(tcl);
162: SubstanceLookAndFeel.registerWatermarkChangeListener(tcl);
163:
164: this .add(Check.getToolbar("", 16, false), BorderLayout.NORTH);
165: this .add(this .tabbed, BorderLayout.CENTER);
166: this .tabbed.putClientProperty(
167: LafWidget.TABBED_PANE_PREVIEW_PAINTER,
168: new DefaultTabPreviewPainter());
169:
170: JPanel transPanel = new JPanel();
171: transPanel.setLayout(new BorderLayout());
172:
173: JPanel buttons = new JPanel(new FlowLayout(FlowLayout.CENTER,
174: 1, 0));
175: transPanel.add(buttons, BorderLayout.SOUTH);
176:
177: // for the first movie, change the following line to
178: // use the BorderLayout
179: final JPanel mainPanel = new JPanel(new FlowLayout());
180: final JPanel mainPanel2 = new JPanel(new FlowLayout());
181:
182: final JPanel centerPanel = new JPanel(new GridLayout(2, 1));
183: centerPanel.add(mainPanel);
184: centerPanel.add(mainPanel2);
185:
186: // bring the magic in one single line
187: if (installTransitionLayout) {
188: TransitionLayoutManager.getInstance()
189: .track(mainPanel, true);
190: TransitionLayoutManager.getInstance().track(mainPanel2,
191: true);
192: }
193: final JButton b1 = new JButton("1");
194: final JButton b2 = new JButton("2");
195: final JButton b3 = new JButton("3");
196:
197: final JButton b4 = new JButton("4");
198: final JButton b5 = new JButton("5");
199: final JButton b6 = new JButton("6");
200:
201: final JButton add1 = new JButton("add");
202: final JButton add2 = new JButton("add");
203: add1.addActionListener(new ActionListener() {
204: public void actionPerformed(ActionEvent e) {
205: SwingUtilities.invokeLater(new Runnable() {
206: public void run() {
207: mainPanel.add(b1);
208: mainPanel.add(b2);
209: mainPanel.add(b3);
210: mainPanel.revalidate();
211: add1.setVisible(false);
212: }
213: });
214: }
215: });
216: add2.addActionListener(new ActionListener() {
217: public void actionPerformed(ActionEvent e) {
218: SwingUtilities.invokeLater(new Runnable() {
219: public void run() {
220: mainPanel2.add(b4);
221: mainPanel2.add(b5);
222: mainPanel2.add(b6);
223: mainPanel2.revalidate();
224: add2.setVisible(false);
225: }
226: });
227: }
228: });
229: mainPanel.add(add1);
230: mainPanel2.add(add2);
231:
232: final JCheckBox cb = new JCheckBox("border layout");
233: cb.addActionListener(new ActionListener() {
234: public void actionPerformed(ActionEvent e) {
235: TransitionLayoutManager.getInstance()
236: .untrack(mainPanel);
237: TransitionLayoutManager.getInstance().untrack(
238: mainPanel2);
239: if (cb.isSelected()) {
240: mainPanel.setLayout(new BorderLayout());
241: mainPanel2.setLayout(new BorderLayout());
242: } else {
243: mainPanel.setLayout(new FlowLayout());
244: mainPanel2.setLayout(new FlowLayout());
245: }
246: TransitionLayoutManager.getInstance().track(mainPanel,
247: true);
248: TransitionLayoutManager.getInstance().track(mainPanel2,
249: true);
250: mainPanel.revalidate();
251: mainPanel.doLayout();
252: mainPanel.repaint();
253: mainPanel2.revalidate();
254: }
255: });
256: // buttons.add(cb);
257:
258: transPanel.add(centerPanel, BorderLayout.CENTER);
259:
260: final JCheckBox cb1 = new JCheckBox("1");
261: cb1.setSelected(true);
262: final JCheckBox cb2 = new JCheckBox("2");
263: cb2.setSelected(true);
264: final JCheckBox cb3 = new JCheckBox("3");
265: cb3.setSelected(true);
266: final JCheckBox cb4 = new JCheckBox("4");
267: cb4.setSelected(true);
268: final JCheckBox cb5 = new JCheckBox("5");
269: cb5.setSelected(true);
270: final JCheckBox cb6 = new JCheckBox("6");
271: cb6.setSelected(true);
272: buttons.add(cb1);
273: buttons.add(cb2);
274: buttons.add(cb3);
275: buttons.add(cb4);
276: buttons.add(cb5);
277: buttons.add(cb6);
278:
279: JButton showHide = new JButton("Toggle");
280: showHide.addActionListener(new ActionListener() {
281: public void actionPerformed(ActionEvent e) {
282: b1.setVisible(cb1.isSelected());
283: b2.setVisible(cb2.isSelected());
284: b3.setVisible(cb3.isSelected());
285: b4.setVisible(cb4.isSelected());
286: b5.setVisible(cb5.isSelected());
287: b6.setVisible(cb6.isSelected());
288: mainPanel.doLayout();
289: mainPanel2.doLayout();
290: }
291: });
292: buttons.add(showHide);
293:
294: this .tabbed.addTab("Regular", transPanel);
295:
296: JPanel samplePanel = new JPanel(new BorderLayout());
297: FormLayout lm = new FormLayout("fill:default:grow(1), 2dlu,"
298: + "fill:default:grow(1)",
299: "pref, 0dlu, pref, 0dlu, pref, 0dlu, pref");
300: PanelBuilder builder = new PanelBuilder(lm);
301: builder.setBorder(new EmptyBorder(0, 2, 0, 2));
302: CellConstraints cc = new CellConstraints();
303:
304: JCheckBox cbes = new JCheckBox("Enabled selected");
305: cbes.setSelected(true);
306: JCheckBox cbds = new JCheckBox("Disabled selected");
307: cbds.setSelected(true);
308: cbds.setEnabled(false);
309: JCheckBox cbeu = new JCheckBox("Enabled unselected");
310: JRadioButton rb1 = new JRadioButton("Enabled selected");
311: rb1.setSelected(true);
312: JRadioButton rb2 = new JRadioButton("Disabled selected");
313: rb2.setSelected(true);
314: rb2.setEnabled(false);
315: JRadioButton rb3 = new JRadioButton("Enabled unselected");
316:
317: builder.add(cbes, cc.xy(1, 1));
318: builder.add(rb1, cc.xy(3, 1));
319: builder.add(cbds, cc.xy(1, 3));
320: builder.add(rb2, cc.xy(3, 3));
321: builder.add(cbeu, cc.xy(1, 5));
322: builder.add(rb3, cc.xy(3, 5));
323:
324: JComboBox combo = new JComboBox(new Object[] { "item1" });
325: combo.setSelectedIndex(0);
326: combo.setEditable(true);
327: combo.putClientProperty(LafWidget.COMBO_BOX_USE_MODEL_ONLY,
328: Boolean.TRUE);
329: JTextField text = new JTextField("Text field");
330: text.setEditable(false);
331: text.putClientProperty(LafWidget.ANIMATION_KIND,
332: AnimationKind.SLOW);
333:
334: builder.add(combo, cc.xy(1, 7));
335: builder.add(text, cc.xy(3, 7));
336:
337: JPanel contentPanel = builder.getPanel();
338: contentPanel.setPreferredSize(new Dimension(contentPanel
339: .getPreferredSize().width, contentPanel
340: .getPreferredSize().height + 100));
341: // contentPanel.setBorder(null);
342:
343: contentPanel.setOpaque(false);
344: final JScrollPane scroll = new JScrollPane(contentPanel,
345: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
346: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
347:
348: scroll.setBorder(new EmptyBorder(0, 0, 0, 0));
349: scroll.setOpaque(false);
350: scroll.getViewport().setOpaque(false);
351:
352: final JPanel buttons2 = new JPanel(new FlowLayout(
353: FlowLayout.RIGHT, 5, 2));
354: this .prev = new JButton("prev");
355: JButton cancel = new JButton("cancel");
356: cancel.setEnabled(false);
357: final JButton ok = new JButton("OK");
358: // ok.putClientProperty(SubstanceLookAndFeel.PAINT_ACTIVE_PROPERTY,
359: // Boolean.TRUE);
360: buttons2.add(this .prev);
361: buttons2.add(cancel);
362: buttons2.add(ok);
363: this .getRootPane().setDefaultButton(ok);
364: // ok.requestFocusInWindow();
365: this .addWindowListener(new WindowAdapter() {
366: @Override
367: public void windowActivated(WindowEvent e) {
368: ok.requestFocusInWindow();
369: }
370: });
371:
372: samplePanel.add(scroll, BorderLayout.CENTER);
373: samplePanel.add(buttons2, BorderLayout.SOUTH);
374:
375: this .tabbed.addTab("Sample", samplePanel);
376:
377: JPanel samplePanel2 = new JPanel(new BorderLayout());
378: DefaultMutableTreeNode root = new DefaultMutableTreeNode("root");
379: DefaultMutableTreeNode son1 = new DefaultMutableTreeNode("son1");
380: DefaultMutableTreeNode son2 = new DefaultMutableTreeNode("son2");
381: DefaultMutableTreeNode son3 = new DefaultMutableTreeNode("son3");
382: DefaultMutableTreeNode gson11 = new DefaultMutableTreeNode(
383: "gson11");
384: DefaultMutableTreeNode gson12 = new DefaultMutableTreeNode(
385: "gson12");
386: DefaultMutableTreeNode gson21 = new DefaultMutableTreeNode(
387: "gson21");
388: DefaultMutableTreeNode gson22 = new DefaultMutableTreeNode(
389: "gson22");
390: DefaultMutableTreeNode gson31 = new DefaultMutableTreeNode(
391: "gson31");
392: DefaultMutableTreeNode gson32 = new DefaultMutableTreeNode(
393: "gson32");
394: DefaultMutableTreeNode ggson111 = new DefaultMutableTreeNode(
395: "ggson111");
396: DefaultMutableTreeNode ggson112 = new DefaultMutableTreeNode(
397: "ggson112");
398: DefaultMutableTreeNode ggson113 = new DefaultMutableTreeNode(
399: "ggson113");
400:
401: gson11.add(ggson111);
402: gson11.add(ggson112);
403: gson11.add(ggson113);
404: son1.add(gson11);
405: son1.add(gson12);
406: son2.add(gson21);
407: son2.add(gson22);
408: son3.add(gson31);
409: son3.add(gson32);
410: root.add(son1);
411: root.add(son2);
412: root.add(son3);
413:
414: this .tree = new JTree(root);
415: this .tree.setBorder(new EmptyBorder(0, 0, 0, 0));
416: JScrollPane jspTree = new JScrollPane(this .tree);
417: // TransitionLayoutManager.getInstance().track(jspTree, true);
418: // jspTree.setBorder(new EmptyBorder(0, 0, 0, 0));
419:
420: this .list = new JList(new MyListModel());
421: this .list.setBorder(new EmptyBorder(0, 0, 0, 0));
422: this .list
423: .setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
424: JScrollPane jspList = new JScrollPane(this .list);
425: // jspList.setBorder(new EmptyBorder(0, 0, 0, 0));
426:
427: JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT,
428: jspTree, jspList);
429: split.setDividerLocation(130);
430: samplePanel2.add(split, BorderLayout.CENTER);
431: this .tabbed.add("Renderers", samplePanel2);
432:
433: this .tabbed.setSelectedComponent(samplePanel);
434: this .tabbed.setOpaque(false);
435: this .tabbed.setBorder(new EmptyBorder(0, 2, 2, 2));
436: JMenuBar jmb = new JMenuBar();
437:
438: if (UIManager.getLookAndFeel() instanceof SubstanceLookAndFeel) {
439: jmb.add(SampleMenuFactory.getThemeMenu());
440: jmb.add(SampleMenuFactory.getSkinMenu());
441: }
442:
443: JMenu testMenu = SampleMenuFactory.getTestMenu();
444: jmb.add(testMenu);
445: testMenu.putClientProperty(LafWidget.ANIMATION_KIND,
446: AnimationKind.SLOW);
447: this .setJMenuBar(jmb);
448:
449: this .setResizable(true);
450:
451: this .synchronize();
452: SubstanceLookAndFeel
453: .registerThemeChangeListener(new ThemeChangeListener() {
454: public void themeChanged() {
455: SampleFrame.this .synchronize();
456: }
457: });
458: SubstanceLookAndFeel
459: .registerWatermarkChangeListener(new WatermarkChangeListener() {
460: public void watermarkChanged() {
461: SampleFrame.this .synchronize();
462: }
463: });
464: this .getRootPane().setDefaultButton(ok);
465: }
466:
467: protected void synchronize() {
468: SwingUtilities.invokeLater(new Runnable() {
469: public void run() {
470: SampleFrame.this
471: .setIconImage(SubstanceImageCreator
472: .getThemeImage(
473: null,
474: new ImageIcon(
475: Check.class
476: .getClassLoader()
477: .getResource(
478: "test/resource/image-x-generic.png")),
479: SubstanceLookAndFeel.getTheme(),
480: false));
481: }
482: });
483: }
484:
485: public static void main(String... args) throws Exception {
486: try {
487: if (System.getProperty("swing.defaultlaf") == null)
488: UIManager
489: .setLookAndFeel(new SubstanceBusinessBlackSteelLookAndFeel());
490: } catch (AccessControlException ace) {
491: UIManager.setLookAndFeel(new SubstanceLookAndFeel());
492: }
493: SubstanceLookAndFeel.addMixedTheme(new SubstanceMixTheme(
494: new SubstanceAquaTheme(),
495: new SubstanceBottleGreenTheme()));
496: SubstanceLookAndFeel.addMixedTheme(new SubstanceAquaTheme(),
497: new SubstanceLightAquaTheme());
498: SubstanceLookAndFeel.addMixedTheme(new SubstanceAquaTheme(),
499: new SubstanceBottleGreenTheme());
500: SubstanceLookAndFeel.addMixedTheme(
501: new SubstanceBarbyPinkTheme(),
502: new SubstanceRaspberryTheme());
503: SubstanceLookAndFeel.addMixedTheme(
504: new SubstanceBottleGreenTheme(),
505: new SubstanceLimeGreenTheme());
506: SubstanceLookAndFeel.addMixedTheme(new SubstanceBrownTheme(),
507: new SubstanceSunGlareTheme());
508: SubstanceLookAndFeel.addMixedTheme(new SubstanceSunsetTheme(),
509: new SubstanceOrangeTheme());
510:
511: SubstanceLookAndFeel.addMixedTheme(
512: new SubstanceBottleGreenTheme(),
513: new SubstanceLimeGreenTheme(),
514: new SubstanceBottleGreenTheme());
515: SubstanceLookAndFeel.addMixedTheme(new SubstanceAquaTheme(),
516: new SubstanceLimeGreenTheme(),
517: new SubstanceBottleGreenTheme());
518: SubstanceLookAndFeel.addMixedTheme(
519: new SubstanceBarbyPinkTheme(),
520: new SubstancePurpleTheme(),
521: new SubstanceRaspberryTheme());
522: SubstanceLookAndFeel.addMixedTheme(
523: new SubstanceRaspberryTheme(),
524: new SubstanceSunsetTheme(), new SubstanceOrangeTheme());
525: SubstanceLookAndFeel.addMixedTheme(new SubstanceBrownTheme(),
526: new SubstanceSunGlareTheme(),
527: new SubstanceOrangeTheme());
528: SubstanceLookAndFeel.addMixedTheme(new SubstanceAquaTheme(),
529: new SubstanceLightAquaTheme(),
530: new SubstancePurpleTheme(),
531: new SubstanceBarbyPinkTheme());
532: SubstanceLookAndFeel.addMixedTheme(new SubstanceBrownTheme(),
533: new SubstanceTerracottaTheme(),
534: new SubstanceSunGlareTheme(),
535: new SubstanceOrangeTheme(), new SubstanceSunsetTheme());
536:
537: SwingUtilities.invokeLater(new Runnable() {
538: public void run() {
539: JFrame.setDefaultLookAndFeelDecorated(true);
540: SampleFrame sf = new SampleFrame(true);
541: sf.setSize(315, 245);
542: sf.setLocationRelativeTo(null);
543: sf.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
544: sf.setVisible(true);
545: }
546: });
547:
548: // h(sf, 0);
549: }
550:
551: public static void h(Component comp, int depth) {
552: for (int i = 0; i < depth; i++)
553: System.out.print(" ");
554: Rectangle r = comp.getBounds();
555: System.out.println(comp.getClass().getSimpleName() + " [" + r.x
556: + "," + r.y + " : " + (r.x + r.width) + ","
557: + (r.y + r.height) + "]");
558: if (comp instanceof Container) {
559: Container cont = (Container) comp;
560: for (int i = 0; i < cont.getComponentCount(); i++) {
561: h(cont.getComponent(i), depth + 1);
562: }
563: }
564: }
565:
566: public void switchToLastTab() {
567: this .tabbed.setSelectedIndex(2);
568: this .list.setSelectedIndices(new int[] { 1, 4 });
569: this .tree.setSelectionRow(1);
570: }
571: }
|