KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > nextapp > echo2 > testapp > interactive > testscreen > SplitPaneTest


1 /*
2  * This file is part of the Echo Web Application Framework (hereinafter "Echo").
3  * Copyright (C) 2002-2005 NextApp, Inc.
4  *
5  * Version: MPL 1.1/GPL 2.0/LGPL 2.1
6  *
7  * The contents of this file are subject to the Mozilla Public License Version
8  * 1.1 (the "License"); you may not use this file except in compliance with
9  * the License. You may obtain a copy of the License at
10  * http://www.mozilla.org/MPL/
11  *
12  * Software distributed under the License is distributed on an "AS IS" basis,
13  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
14  * for the specific language governing rights and limitations under the
15  * License.
16  *
17  * Alternatively, the contents of this file may be used under the terms of
18  * either the GNU General Public License Version 2 or later (the "GPL"), or
19  * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
20  * in which case the provisions of the GPL or the LGPL are applicable instead
21  * of those above. If you wish to allow use of your version of this file only
22  * under the terms of either the GPL or the LGPL, and not to allow others to
23  * use your version of this file under the terms of the MPL, indicate your
24  * decision by deleting the provisions above and replace them with the notice
25  * and other provisions required by the GPL or the LGPL. If you do not delete
26  * the provisions above, a recipient may use your version of this file under
27  * the terms of any one of the MPL, the GPL or the LGPL.
28  */

29
30 package nextapp.echo2.testapp.interactive.testscreen;
31
32 import nextapp.echo2.app.Alignment;
33 import nextapp.echo2.app.Border;
34 import nextapp.echo2.app.Color;
35 import nextapp.echo2.app.FillImage;
36 import nextapp.echo2.app.Button;
37 import nextapp.echo2.app.Extent;
38 import nextapp.echo2.app.Insets;
39 import nextapp.echo2.app.Label;
40 import nextapp.echo2.app.Column;
41 import nextapp.echo2.app.Row;
42 import nextapp.echo2.app.SplitPane;
43 import nextapp.echo2.app.event.ActionEvent;
44 import nextapp.echo2.app.event.ActionListener;
45 import nextapp.echo2.app.layout.SplitPaneLayoutData;
46 import nextapp.echo2.testapp.interactive.ButtonColumn;
47 import nextapp.echo2.testapp.interactive.StyleUtil;
48 import nextapp.echo2.testapp.interactive.Styles;
49
50 /**
51  * Interactive test module for <code>SplitPane</code>s.
52  */

53 public class SplitPaneTest extends SplitPane {
54     
55     private class PaneControlsColumn extends ButtonColumn {
56         
57         private PaneControlsColumn(final int paneNumber) {
58             add(new Label("Configure Pane #" + paneNumber));
59     
60             addButton("Fill With Text", new ActionListener() {
61                 public void actionPerformed(ActionEvent e) {
62                     if (testPane.getComponentCount() < paneNumber + 1) {
63                         return;
64                     }
65                     if (testPane.getComponent(paneNumber) instanceof Label) {
66                         Label label = (Label) testPane.getComponent(paneNumber);
67                         label.setText(StyleUtil.QUASI_LATIN_TEXT_1);
68                     }
69                 }
70             });
71             addButton("Change Background Color", new ActionListener() {
72                 public void actionPerformed(ActionEvent e) {
73                     if (testPane.getComponentCount() < paneNumber + 1) {
74                         return;
75                     }
76                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
77                     splitPaneLayoutData.setBackground(StyleUtil.randomBrightColor());
78                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
79                 }
80             });
81             addButton("MIN Size = Default", new ActionListener() {
82                 public void actionPerformed(ActionEvent e) {
83                     if (testPane.getComponentCount() < paneNumber + 1) {
84                         return;
85                     }
86                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
87                     splitPaneLayoutData.setMinimumSize(null);
88                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
89                 }
90             });
91             addButton("MIN Size = 30", new ActionListener() {
92                 public void actionPerformed(ActionEvent e) {
93                     if (testPane.getComponentCount() < paneNumber + 1) {
94                         return;
95                     }
96                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
97                     splitPaneLayoutData.setMinimumSize(new Extent(30));
98                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
99                 }
100             });
101             addButton("MAX Size = Default", new ActionListener() {
102                 public void actionPerformed(ActionEvent e) {
103                     if (testPane.getComponentCount() < paneNumber + 1) {
104                         return;
105                     }
106                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
107                     splitPaneLayoutData.setMaximumSize(null);
108                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
109                 }
110             });
111             addButton("MAX Size = 120", new ActionListener() {
112                 public void actionPerformed(ActionEvent e) {
113                     if (testPane.getComponentCount() < paneNumber + 1) {
114                         return;
115                     }
116                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
117                     splitPaneLayoutData.setMaximumSize(new Extent(120));
118                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
119                 }
120             });
121             addButton("Toggle Background Image", new ActionListener() {
122                 public void actionPerformed(ActionEvent e) {
123                     if (testPane.getComponentCount() < paneNumber + 1) {
124                         return;
125                     }
126                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
127                     FillImage backgroundImage = splitPaneLayoutData.getBackgroundImage();
128                     if (backgroundImage == null) {
129                         splitPaneLayoutData.setBackgroundImage(Styles.BG_SHADOW_LIGHT_BLUE);
130                     } else {
131                         splitPaneLayoutData.setBackgroundImage(null);
132                     }
133                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
134                 }
135             });
136             addButton("Insets = null", new ActionListener() {
137                 public void actionPerformed(ActionEvent e) {
138                     if (testPane.getComponentCount() < paneNumber + 1) {
139                         return;
140                     }
141                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
142                     splitPaneLayoutData.setInsets(null);
143                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
144                 }
145             });
146             addButton("Insets = 0px", new ActionListener() {
147                 public void actionPerformed(ActionEvent e) {
148                     if (testPane.getComponentCount() < paneNumber + 1) {
149                         return;
150                     }
151                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
152                     splitPaneLayoutData.setInsets(new Insets(0));
153                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
154                 }
155             });
156             addButton("Insets = 5px", new ActionListener() {
157                 public void actionPerformed(ActionEvent e) {
158                     if (testPane.getComponentCount() < paneNumber + 1) {
159                         return;
160                     }
161                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
162                     splitPaneLayoutData.setInsets(new Insets(5));
163                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
164                 }
165             });
166             addButton("Insets = 10/20/30/40px", new ActionListener() {
167                 public void actionPerformed(ActionEvent e) {
168                     if (testPane.getComponentCount() < paneNumber + 1) {
169                         return;
170                     }
171                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
172                     splitPaneLayoutData.setInsets(new Insets(10, 20, 30, 40));
173                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
174                 }
175             });
176             addButton("Overflow = Auto", new ActionListener() {
177                 public void actionPerformed(ActionEvent e) {
178                     if (testPane.getComponentCount() < paneNumber + 1) {
179                         return;
180                     }
181                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
182                     splitPaneLayoutData.setOverflow(SplitPaneLayoutData.OVERFLOW_AUTO);
183                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
184                 }
185             });
186             addButton("Overflow = Hidden", new ActionListener() {
187                 public void actionPerformed(ActionEvent e) {
188                     if (testPane.getComponentCount() < paneNumber + 1) {
189                         return;
190                     }
191                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
192                     splitPaneLayoutData.setOverflow(SplitPaneLayoutData.OVERFLOW_HIDDEN);
193                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
194                 }
195             });
196             addButton("Overflow = Scroll", new ActionListener() {
197                 public void actionPerformed(ActionEvent e) {
198                     if (testPane.getComponentCount() < paneNumber + 1) {
199                         return;
200                     }
201                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
202                     splitPaneLayoutData.setOverflow(SplitPaneLayoutData.OVERFLOW_SCROLL);
203                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
204                 }
205             });
206             addButton("Alignment = Left", new ActionListener() {
207                 public void actionPerformed(ActionEvent e) {
208                     if (testPane.getComponentCount() < paneNumber + 1) {
209                         return;
210                     }
211                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
212                     splitPaneLayoutData.setAlignment(new Alignment(Alignment.LEFT, Alignment.DEFAULT));
213                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
214                 }
215             });
216             addButton("Alignment = Center", new ActionListener() {
217                 public void actionPerformed(ActionEvent e) {
218                     if (testPane.getComponentCount() < paneNumber + 1) {
219                         return;
220                     }
221                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
222                     splitPaneLayoutData.setAlignment(new Alignment(Alignment.CENTER, Alignment.DEFAULT));
223                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
224                 }
225             });
226             addButton("Alignment = Right", new ActionListener() {
227                 public void actionPerformed(ActionEvent e) {
228                     if (testPane.getComponentCount() < paneNumber + 1) {
229                         return;
230                     }
231                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
232                     splitPaneLayoutData.setAlignment(new Alignment(Alignment.RIGHT, Alignment.DEFAULT));
233                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
234                 }
235             });
236             addButton("Alignment = Default", new ActionListener() {
237                 public void actionPerformed(ActionEvent e) {
238                     if (testPane.getComponentCount() < paneNumber + 1) {
239                         return;
240                     }
241                     SplitPaneLayoutData splitPaneLayoutData = getLayoutData(paneNumber);
242                     splitPaneLayoutData.setAlignment(new Alignment(Alignment.DEFAULT, Alignment.DEFAULT));
243                     testPane.getComponent(paneNumber).setLayoutData(splitPaneLayoutData);
244                 }
245             });
246         }
247         
248         private SplitPaneLayoutData getLayoutData(int paneNumber) {
249             SplitPaneLayoutData splitPaneLayoutData = (SplitPaneLayoutData) testPane.getComponent(paneNumber).getLayoutData();
250             if (splitPaneLayoutData == null) {
251                 splitPaneLayoutData = new SplitPaneLayoutData();
252             }
253             return splitPaneLayoutData;
254         }
255     }
256
257     private SplitPane testPane;
258     
259     public SplitPaneTest() {
260         super(SplitPane.ORIENTATION_HORIZONTAL, new Extent(250, Extent.PX));
261         setStyleName("DefaultResizable");
262         
263         Column groupContainerColumn = new Column();
264         groupContainerColumn.setCellSpacing(new Extent(5));
265         groupContainerColumn.setStyleName("TestControlsColumn");
266         add(groupContainerColumn);
267
268         ButtonColumn controlsColumn;
269         
270         controlsColumn = new ButtonColumn();
271         controlsColumn.add(new Label("Add / Remove Panes"));
272         groupContainerColumn.add(controlsColumn);
273         
274         controlsColumn.addButton("Remove Pane 0", new ActionListener() {
275             public void actionPerformed(ActionEvent e) {
276                 if (testPane.getComponentCount() >= 1) {
277                     testPane.remove(0);
278                 }
279             }
280         });
281         controlsColumn.addButton("Remove Pane 1", new ActionListener() {
282             public void actionPerformed(ActionEvent e) {
283                 if (testPane.getComponentCount() >= 2) {
284                     testPane.remove(1);
285                 }
286             }
287         });
288         controlsColumn.addButton("Replace Pane 0", new ActionListener() {
289             public void actionPerformed(ActionEvent e) {
290                 if (testPane.getComponentCount() >= 1) {
291                     testPane.remove(0);
292                 }
293                 testPane.add(createPaneLabel("Replacement for Pane 0"), 0);
294             }
295         });
296         controlsColumn.addButton("Replace Pane 1", new ActionListener() {
297             public void actionPerformed(ActionEvent e) {
298                 if (testPane.getComponentCount() >= 2) {
299                     testPane.remove(1);
300                 }
301                 testPane.add(createPaneLabel("Replacement for Pane 1"));
302             }
303         });
304         controlsColumn.addButton("Add at Beginning", new ActionListener() {
305             public void actionPerformed(ActionEvent e) {
306                 if (testPane.getComponentCount() < 2) {
307                     testPane.add(createPaneLabel("Added at Beginning"), 0);
308                 }
309             }
310         });
311         controlsColumn.addButton("Add at End", new ActionListener() {
312             public void actionPerformed(ActionEvent e) {
313                 if (testPane.getComponentCount() < 2) {
314                     testPane.add(createPaneLabel("Added at End"));
315                 }
316             }
317         });
318         controlsColumn.addButton("Add Row", new ActionListener() {
319             public void actionPerformed(ActionEvent e) {
320                 if (testPane.getComponentCount() < 2) {
321                     Row row = new Row();
322                     row.setBorder(new Border(new Extent(1), Color.BLACK, Border.STYLE_SOLID));
323                     row.setCellSpacing(new Extent(5));
324                     row.setInsets(new Insets(10, 5));
325                     row.add(new Label("Alpha"));
326                     row.add(new Label("Bravo"));
327                     row.add(new Label("Charlie"));
328                     testPane.add(row);
329                 }
330             }
331         });
332         controlsColumn.addButton("Add-Remove-Add", new ActionListener() {
333             public void actionPerformed(ActionEvent e) {
334                 if (testPane.getComponentCount() < 2) {
335                     Label label = createPaneLabel("Added at End, Removed, Re-Added");
336                     testPane.add(label);
337                     testPane.remove(label);
338                     testPane.add(label);
339                 }
340             }
341         });
342         controlsColumn.addButton("Add Button", new ActionListener() {
343             public void actionPerformed(ActionEvent e) {
344                 if (testPane.getComponentCount() < 2) {
345                     Button testButton = new Button("Test Button");
346                     SplitPaneLayoutData layoutData = new SplitPaneLayoutData();
347                     layoutData.setInsets(new Insets(10));
348                     testButton.setLayoutData(layoutData);
349                     testButton.setStyleName("Default");
350                     testPane.add(testButton);
351                 }
352             }
353         });
354         
355         controlsColumn = new ButtonColumn();
356         controlsColumn.add(new Label("Configure SplitPane"));
357         groupContainerColumn.add(controlsColumn);
358         
359         controlsColumn.addButton("Set Separator Position = null", new ActionListener() {
360             public void actionPerformed(ActionEvent e) {
361                 testPane.setSeparatorPosition(null);
362             }
363         });
364         controlsColumn.addButton("Set Separator Position = 300px", new ActionListener() {
365             public void actionPerformed(ActionEvent e) {
366                 testPane.setSeparatorPosition(new Extent(300));
367             }
368         });
369         controlsColumn.addButton("Set Orientation = Leading/Trailing", new ActionListener() {
370             public void actionPerformed(ActionEvent e) {
371                 testPane.setOrientation(SplitPane.ORIENTATION_HORIZONTAL_LEADING_TRAILING);
372             }
373         });
374         controlsColumn.addButton("Set Orientation = Trailing/Leading", new ActionListener() {
375             public void actionPerformed(ActionEvent e) {
376                 testPane.setOrientation(SplitPane.ORIENTATION_HORIZONTAL_TRAILING_LEADING);
377             }
378         });
379         controlsColumn.addButton("Set Orientation = Left/Right", new ActionListener() {
380             public void actionPerformed(ActionEvent e) {
381                 testPane.setOrientation(SplitPane.ORIENTATION_HORIZONTAL_LEFT_RIGHT);
382             }
383         });
384         controlsColumn.addButton("Set Orientation = Right/Left", new ActionListener() {
385             public void actionPerformed(ActionEvent e) {
386                 testPane.setOrientation(SplitPane.ORIENTATION_HORIZONTAL_RIGHT_LEFT);
387             }
388         });
389         controlsColumn.addButton("Set Orientation = Top/Bottom", new ActionListener() {
390             public void actionPerformed(ActionEvent e) {
391                 testPane.setOrientation(SplitPane.ORIENTATION_VERTICAL_TOP_BOTTOM);
392             }
393         });
394         controlsColumn.addButton("Set Orientation = Bottom/Top", new ActionListener() {
395             public void actionPerformed(ActionEvent e) {
396                 testPane.setOrientation(SplitPane.ORIENTATION_VERTICAL_BOTTOM_TOP);
397             }
398         });
399         controlsColumn.addButton("Disable Resize", new ActionListener() {
400             public void actionPerformed(ActionEvent e) {
401                 testPane.setResizable(!testPane.isResizable());
402                 ((Button) e.getSource()).setText(testPane.isResizable() ? "Disable Resize" : "Enable Resize");
403             }
404         });
405         
406         groupContainerColumn.add(new PaneControlsColumn(0));
407         groupContainerColumn.add(new PaneControlsColumn(1));
408
409         testPane = new SplitPane(ORIENTATION_VERTICAL, new Extent(200, Extent.PX));
410         testPane.setStyleName("DefaultResizable");
411         add(testPane);
412     }
413     
414     private Label createPaneLabel(String JavaDoc text) {
415         Label label = new Label(text);
416         SplitPaneLayoutData splitPaneLayoutData = new SplitPaneLayoutData();
417         splitPaneLayoutData.setBackground(StyleUtil.randomBrightColor());
418         label.setLayoutData(splitPaneLayoutData);
419         return label;
420     }
421 }
422
Popular Tags