KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > swing > gridsplit > Test


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Code is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19 /*
20  * Test.java
21  *
22  * Created on May 2, 2004, 4:01 PM
23  */

24
25 package org.netbeans.swing.gridsplit;
26
27 import java.awt.BorderLayout JavaDoc;
28 import java.awt.Component JavaDoc;
29 import java.awt.Dimension JavaDoc;
30 import java.awt.GridBagConstraints JavaDoc;
31 import java.awt.GridBagLayout JavaDoc;
32 import java.awt.Insets JavaDoc;
33 import java.awt.event.ActionEvent JavaDoc;
34 import java.awt.event.ActionListener JavaDoc;
35 import java.awt.event.WindowListener JavaDoc;
36 import java.util.Collection JavaDoc;
37 import java.util.Iterator JavaDoc;
38 import javax.swing.AbstractAction JavaDoc;
39 import javax.swing.JButton JavaDoc;
40 import javax.swing.JCheckBoxMenuItem JavaDoc;
41 import javax.swing.JComponent JavaDoc;
42 import javax.swing.JFrame JavaDoc;
43 import javax.swing.JMenu JavaDoc;
44 import javax.swing.JMenuItem JavaDoc;
45 import javax.swing.JPanel JavaDoc;
46 import javax.swing.JPopupMenu JavaDoc;
47 import javax.swing.JScrollPane JavaDoc;
48 import javax.swing.JTree JavaDoc;
49
50
51 /**
52  *
53  * @author Tim Boudreau
54  */

55 public class Test {
56     
57     public GridSplitModel model;
58     private Component JavaDoc c1;
59     
60     public static int index = 0;
61     
62     /** Creates a new instance of Test */
63     public Test() {
64         model = buildModel();
65     }
66     
67     public String JavaDoc toString() {
68         return "\33\n\"'\\\ue161"; // FULL OF BUGS IN TOOLTIP
69
}
70     
71     public Component JavaDoc getFirstComponent(){
72         return c1;
73     }
74     
75     public void display(){
76         TestFrame jf = new TestFrame();
77         jf.getContentPane().setLayout(new BorderLayout JavaDoc());
78         jf.addWindowListener(new WA());
79         jf.setSplitter( new GridSplitPane( model ) );
80         jf.setBounds(20, 20, 800, 600);
81         jf.show();
82     }
83     
84     public Component JavaDoc addComponent(Component JavaDoc c,String JavaDoc orientation,double proportion){
85         TestComponent in=(TestComponent)c;
86         
87         Component JavaDoc out=buildComponent();
88         if(orientation.equals((Object JavaDoc)"horizontal")){
89             model.addToSide(in,out,GridSplitCell.WEST,proportion);
90         } else{
91             model.addToSide(in,out,GridSplitCell.NORTH,proportion);
92             
93         }
94         return out;
95     }
96   
97     GridSplitModel buildModel() {
98         c1 = new TestComponent(this);
99         GridSplitModel model = new GridSplitModel( c1, new Dimension JavaDoc( 800,600 ), 0.3 );
100         return model;
101     }
102     
103     public Component JavaDoc buildComponent() {
104         return new TestComponent(this);
105     }
106     
107     private static class WA implements WindowListener JavaDoc {
108         
109         public void windowActivated(java.awt.event.WindowEvent JavaDoc windowEvent) {
110         }
111         
112         public void windowClosed(java.awt.event.WindowEvent JavaDoc windowEvent) {
113         }
114         
115         public void windowClosing(java.awt.event.WindowEvent JavaDoc windowEvent) {
116             System.exit(0);
117         }
118         
119         public void windowDeactivated(java.awt.event.WindowEvent JavaDoc windowEvent) {
120         }
121         
122         public void windowDeiconified(java.awt.event.WindowEvent JavaDoc windowEvent) {
123         }
124         
125         public void windowIconified(java.awt.event.WindowEvent JavaDoc windowEvent) {
126         }
127         
128         public void windowOpened(java.awt.event.WindowEvent JavaDoc windowEvent) {
129         }
130         
131     }
132     private static class TestFrame extends JFrame JavaDoc {
133         JComponent JavaDoc splitPane;
134         
135         public void setSplitter( JComponent JavaDoc splitter ) {
136             this.splitPane = splitter;
137             getContentPane().add( splitter, BorderLayout.CENTER );
138             invalidate();
139         }
140         
141         public java.awt.Dimension JavaDoc getMinimumSize() {
142             
143             if( null != splitPane )
144                 return splitPane.getMinimumSize();
145             
146             java.awt.Dimension JavaDoc retValue;
147             
148             retValue = super.getMinimumSize();
149             return retValue;
150         }
151     }
152     
153 }
154
155
156
Popular Tags