KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > wingset > BorderExample


1 /*
2  * $Id: BorderExample.java,v 1.8 2005/03/01 15:04:45 neurolabs 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.border.*;
18
19 import java.awt.*;
20 import java.awt.event.ActionEvent JavaDoc;
21 import java.awt.event.ActionListener JavaDoc;
22
23 /**
24  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
25  * @version $Revision: 1.8 $
26  */

27 public class BorderExample
28         extends WingSetPane {
29     private static final SIcon WAIT_ICON = new SResourceIcon("org/wings/icons/Wait.gif");
30
31     final SBorder raised = new SBevelBorder(SBevelBorder.RAISED, new Insets(5, 5, 5, 5));
32     final SBorder lowered = new SBevelBorder(SBevelBorder.LOWERED, new Insets(5, 5, 5, 5));
33     final SBorder line = new SLineBorder(2, new Insets(5, 5, 5, 5));
34     final SBorder titled = new STitledBorder(new SEtchedBorder(SEtchedBorder.LOWERED, new Insets(5, 5, 5, 5)), "This is a title");
35
36     private SLabel borderLabel;
37     private BorderControls controls;
38     private int thickness = 2;
39
40     public SComponent createExample() {
41         controls = new BorderControls();
42
43         borderLabel = new SLabel(WAIT_ICON);
44         borderLabel.setBackground(new Color(222, 222, 222));
45
46         SPanel buttons = new SPanel();
47         buttons.setLayout(new SGridLayout(1));
48         SButtonGroup group = new SButtonGroup();
49         final SRadioButton rb = new SRadioButton("Raised");
50         group.add(rb);
51         buttons.add(rb);
52         final SRadioButton lb = new SRadioButton("Lowered");
53         group.add(lb);
54         buttons.add(lb);
55         final SRadioButton lineb = new SRadioButton("Line");
56         group.add(lineb);
57         buttons.add(lineb);
58         final SRadioButton eb = new SRadioButton("Title");
59         group.add(eb);
60         buttons.add(eb);
61
62         group.addActionListener(new ActionListener JavaDoc() {
63             public void actionPerformed(ActionEvent JavaDoc e) {
64                 SButtonGroup g = (SButtonGroup) e.getSource();
65                 Object JavaDoc button = g.getSelection();
66                 if (button == rb) {
67                     borderLabel.setText("Raised Border");
68                     borderLabel.setBorder(raised);
69                 } else if (button == lb) {
70                     borderLabel.setText("Lowered Border");
71                     borderLabel.setBorder(lowered);
72                 } else if (button == lineb) {
73                     borderLabel.setText("Line Border");
74                     borderLabel.setBorder(line);
75                 } else if (button == eb) {
76                     borderLabel.setText("Titled Border");
77                     borderLabel.setBorder(titled);
78                 }
79                 borderLabel.getBorder().setThickness(thickness);
80             }
81         });
82
83         rb.setSelected(true);
84
85         controls.addSizable(borderLabel);
86
87         SForm panel = new SForm(new SBorderLayout());
88         panel.add(controls, SBorderLayout.NORTH);
89         panel.add(buttons, SBorderLayout.WEST);
90         panel.add(borderLabel, SBorderLayout.CENTER);
91         return panel;
92     }
93
94     class BorderControls extends ComponentControls {
95
96         public BorderControls() {
97             final STextField thicknessTextField = new STextField();
98             addActionListener(new ActionListener JavaDoc() {
99                 public void actionPerformed(ActionEvent JavaDoc event) {
100                     try {
101                         thickness = Integer.parseInt(thicknessTextField.getText());
102                         borderLabel.getBorder().setThickness(thickness);
103                     }
104                     catch (NumberFormatException JavaDoc e) {}
105                 }
106             });
107
108             add(new SLabel(" thicknessTextField "));
109             add(thicknessTextField);
110         }
111     }
112 }
113
Popular Tags