KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > ComponentControls


1 /*
2  * $Id: ComponentControls.java,v 1.10 2005/05/27 15:11:12 blueshift Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package wingset;
15
16 import org.wings.*;
17 import org.wings.style.CSSProperty;
18
19 import java.awt.event.ActionEvent JavaDoc;
20 import java.awt.event.ActionListener JavaDoc;
21 import java.util.Iterator JavaDoc;
22 import java.util.LinkedList JavaDoc;
23 import java.util.List JavaDoc;
24
25 /**
26  * @author hengels
27  * @version $Revision: 1.10 $
28  */

29 public class ComponentControls
30         extends SToolbar {
31     protected final List JavaDoc components = new LinkedList JavaDoc();
32     protected final STextField widthTextField;
33     protected final STextField heightTextField;
34     protected final SButton applyButton;
35
36     public ComponentControls() {
37         setAttribute(CSSProperty.BORDER_BOTTOM,"1px solid #cccccc");
38         applyButton = new SButton("apply");
39         applyButton.setActionCommand("apply");
40         widthTextField = new STextField();
41         heightTextField = new STextField();
42
43         add(applyButton);
44         add(new SLabel("<html>&nbsp;&nbsp;&nbsp;width&nbsp;"));
45         add(widthTextField);
46         add(new SLabel("<html>&nbsp;&nbsp;&nbsp;height&nbsp;"));
47         add(heightTextField);
48
49         addActionListener(new ActionListener JavaDoc() {
50             public void actionPerformed(ActionEvent JavaDoc e) {
51                 SDimension preferredSize = new SDimension();
52                 String JavaDoc width = widthTextField.getText();
53                 if (width != null && width.length() > 0) {
54                     int widthInt;
55                     try {
56                         widthInt = Integer.parseInt(width);
57                     } catch (NumberFormatException JavaDoc nfe) {
58                         widthInt = Integer.MIN_VALUE;
59                     }
60                     if (widthInt == Integer.MIN_VALUE) {
61                         preferredSize.setWidth(width);
62                     } else {
63                         preferredSize.setWidth(widthInt);
64                     }
65                 }
66                 String JavaDoc height = heightTextField.getText();
67                 if (height != null && height.length() > 0) {
68                     int heightInt;
69                     try {
70                         heightInt = Integer.parseInt(height);
71                     } catch (NumberFormatException JavaDoc nfe) {
72                         heightInt = Integer.MIN_VALUE;
73                     }
74                     if (heightInt == Integer.MIN_VALUE) {
75                         preferredSize.setHeight(height);
76                     } else {
77                         preferredSize.setHeight(heightInt);
78                     }
79                 }
80                 for (Iterator JavaDoc iterator = components.iterator(); iterator.hasNext();) {
81                     SComponent component = (SComponent) iterator.next();
82                     component.setPreferredSize(preferredSize);
83                 }
84             }
85         });
86     }
87
88     public void addSizable(SComponent component) {
89         components.add(component);
90     }
91
92     protected void addActionListener(ActionListener JavaDoc actionListener) {
93         applyButton.addActionListener(actionListener);
94     }
95 }
96
Popular Tags