View Javadoc

1   /*
2   
3       dsh-disclosure-triangle-examples  Examples for the disclosure-triangle library.
4       Copyright (c) 2007-2012 held jointly by the individual authors.
5   
6       This library is free software; you can redistribute it and/or modify it
7       under the terms of the GNU Lesser General Public License as published
8       by the Free Software Foundation; either version 3 of the License, or (at
9       your option) any later version.
10  
11      This library is distributed in the hope that it will be useful, but WITHOUT
12      ANY WARRANTY; with out even the implied warranty of MERCHANTABILITY or
13      FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public
14      License for more details.
15  
16      You should have received a copy of the GNU Lesser General Public License
17      along with this library;  if not, write to the Free Software Foundation,
18      Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA.
19  
20      > http://www.fsf.org/licensing/licenses/lgpl.html
21      > http://www.opensource.org/licenses/lgpl-license.php
22  
23  */
24  package org.dishevelled.disclosuretriangle.examples;
25  
26  import java.awt.BorderLayout;
27  
28  import javax.swing.Box;
29  import javax.swing.JDesktopPane;
30  import javax.swing.JDialog;
31  import javax.swing.JFrame;
32  import javax.swing.JInternalFrame;
33  import javax.swing.JLabel;
34  import javax.swing.JPanel;
35  import javax.swing.JTextField;
36  import javax.swing.SwingUtilities;
37  import javax.swing.UIManager;
38  
39  import javax.swing.border.EmptyBorder;
40  
41  import org.dishevelled.layout.LabelFieldLayout;
42  
43  import org.dishevelled.disclosuretriangle.DisclosureTriangle;
44  
45  /**
46   * DisclosureTriangle example.
47   *
48   * @author  Michael Heuer
49   * @version $Revision$ $Date$
50   */
51  public final class DisclosureTriangleExample
52      implements Runnable
53  {
54  
55      /** {@inheritDoc} */
56      public void run()
57      {
58          try
59          {
60              UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
61          }
62          catch (Exception e)
63          {
64              // ignore
65          }
66  
67          final JFrame f = new JFrame("JFrame example");
68          f.setContentPane(createContentPane());
69          f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
70          f.setBounds(120, 120, 400, 200);
71  
72          final JDialog d = new JDialog(f, "JDialog example");
73          d.setContentPane(createContentPane());
74          d.setBounds(140, 140, 400, 200);
75  
76          final JDialog desktop = new JDialog(f, "JInternalFrame example");
77          JDesktopPane desktopPane = new JDesktopPane();
78          JInternalFrame internalFrame = new JInternalFrame("JInternalFrame example");
79          internalFrame.setContentPane(createContentPane());
80          internalFrame.setBounds(50, 20, 400, 200);
81          internalFrame.setVisible(true);
82          desktopPane.add(internalFrame);
83          desktop.setContentPane(desktopPane);
84          desktop.setBounds(160, 160, 500, 300);
85  
86          f.setVisible(true);
87          d.setVisible(true);
88          desktop.setVisible(true);
89      }
90  
91      /**
92       * Create and return a new content pane.
93       *
94       * @return a new content pane
95       */
96      private JPanel createContentPane()
97      {
98          JPanel contentPane = new JPanel();
99          contentPane.setLayout(new BorderLayout());
100         contentPane.setBorder(new EmptyBorder(11, 11, 11, 11));
101         contentPane.add("North", new JLabel("North"));
102         contentPane.add("Center", new JLabel("Center"));
103         JPanel detailsPane = new JPanel();
104         LabelFieldLayout l = new LabelFieldLayout();
105         detailsPane.setLayout(l);
106         detailsPane.setBorder(new EmptyBorder(11, 11, 0, 0));
107         detailsPane.add(new JLabel("Foo:"), l.label());
108         detailsPane.add(new JTextField(), l.field());
109         l.nextLine();
110         detailsPane.add(new JLabel("Bar:"), l.label());
111         detailsPane.add(new JTextField(), l.field());
112         l.nextLine();
113         detailsPane.add(new JLabel("Baz:"), l.label());
114         detailsPane.add(new JTextField(), l.field());
115         l.nextLine();
116         detailsPane.add(Box.createGlue(), l.finalSpacing());
117         contentPane.add("South", new DisclosureTriangle(detailsPane));
118         return contentPane;
119     }
120 
121 
122     /**
123      * Main.
124      *
125      * @param args command line arguments, ignored
126      */
127     public static void main(final String[] args)
128     {
129         SwingUtilities.invokeLater(new DisclosureTriangleExample());
130     }
131 }