summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorWe-unite <3205135446@qq.com>2025-02-19 13:45:27 +0800
committerWe-unite <3205135446@qq.com>2025-02-19 13:45:27 +0800
commiteaba1ffa193104f90751371bfa9814552a2a6243 (patch)
tree07fbb22993b79dcbf8e1dd4521918e50523e1315 /lib
downloadproject-eaba1ffa193104f90751371bfa9814552a2a6243.tar.gz
project-eaba1ffa193104f90751371bfa9814552a2a6243.zip
Init
Diffstat (limited to 'lib')
-rw-r--r--lib/TableLayout.jarbin0 -> 112151 bytes
-rw-r--r--lib/dom4j-2.0.3.jarbin0 -> 313916 bytes
-rw-r--r--lib/example/GridBagVersusTable$1.classbin0 -> 551 bytes
-rw-r--r--lib/example/GridBagVersusTable.classbin0 -> 3490 bytes
-rw-r--r--lib/example/GridBagVersusTable.java140
-rw-r--r--lib/example/GridVersusTable$1.classbin0 -> 542 bytes
-rw-r--r--lib/example/GridVersusTable.classbin0 -> 2252 bytes
-rw-r--r--lib/example/GridVersusTable.java112
-rw-r--r--lib/example/MyClass$1.classbin0 -> 518 bytes
-rw-r--r--lib/example/MyClass.classbin0 -> 1425 bytes
-rw-r--r--lib/example/MyClass.java49
-rw-r--r--lib/example/Preferred$1.classbin0 -> 631 bytes
-rw-r--r--lib/example/Preferred.classbin0 -> 2744 bytes
-rw-r--r--lib/example/Preferred.java106
-rw-r--r--lib/example/RadTool$1.classbin0 -> 621 bytes
-rw-r--r--lib/example/RadTool$Box.classbin0 -> 2183 bytes
-rw-r--r--lib/example/RadTool$Smiley.classbin0 -> 6148 bytes
-rw-r--r--lib/example/RadTool.classbin0 -> 9194 bytes
-rw-r--r--lib/example/RadTool.java647
-rw-r--r--lib/example/Simple$1.classbin0 -> 515 bytes
-rw-r--r--lib/example/Simple.classbin0 -> 1648 bytes
-rw-r--r--lib/example/Simple.java62
-rw-r--r--lib/example/TypicalGui$1.classbin0 -> 636 bytes
-rw-r--r--lib/example/TypicalGui$ColorBox.classbin0 -> 1255 bytes
-rw-r--r--lib/example/TypicalGui.classbin0 -> 4240 bytes
-rw-r--r--lib/example/TypicalGui.java179
-rw-r--r--lib/hamcrest-core-1.3.jarbin0 -> 45024 bytes
-rw-r--r--lib/jcommon-1.0.16.jarbin0 -> 309293 bytes
-rw-r--r--lib/jfreechart-1.0.13.jarbin0 -> 1425744 bytes
-rw-r--r--lib/junit-4.13.jarbin0 -> 381765 bytes
-rw-r--r--lib/looks-2.1.4.jarbin0 -> 409708 bytes
31 files changed, 1295 insertions, 0 deletions
diff --git a/lib/TableLayout.jar b/lib/TableLayout.jar
new file mode 100644
index 0000000..23519b0
--- /dev/null
+++ b/lib/TableLayout.jar
Binary files differ
diff --git a/lib/dom4j-2.0.3.jar b/lib/dom4j-2.0.3.jar
new file mode 100644
index 0000000..1ef5c52
--- /dev/null
+++ b/lib/dom4j-2.0.3.jar
Binary files differ
diff --git a/lib/example/GridBagVersusTable$1.class b/lib/example/GridBagVersusTable$1.class
new file mode 100644
index 0000000..78bc1c2
--- /dev/null
+++ b/lib/example/GridBagVersusTable$1.class
Binary files differ
diff --git a/lib/example/GridBagVersusTable.class b/lib/example/GridBagVersusTable.class
new file mode 100644
index 0000000..52ee8f7
--- /dev/null
+++ b/lib/example/GridBagVersusTable.class
Binary files differ
diff --git a/lib/example/GridBagVersusTable.java b/lib/example/GridBagVersusTable.java
new file mode 100644
index 0000000..53e45d6
--- /dev/null
+++ b/lib/example/GridBagVersusTable.java
@@ -0,0 +1,140 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import javax.swing.JButton;
8import layout.TableLayout;
9import layout.TableLayoutConstraints;
10
11
12
13public class GridBagVersusTable
14{
15
16
17
18 protected static void makeButton
19 (Frame frame, String name, GridBagLayout gridbag, GridBagConstraints c)
20 {
21 JButton button = new JButton(name);
22 gridbag.setConstraints(button, c);
23 frame.add(button);
24 }
25
26
27
28 protected static Frame showGridBagWindow ()
29 {
30 // Create layout and contraints object
31 GridBagLayout gridbag = new GridBagLayout();
32 GridBagConstraints c = new GridBagConstraints();
33
34 // Create frame
35 Frame frame = new Frame("GridBagLayout");
36 frame.setFont (new Font("Helvetica", Font.PLAIN, 14));
37 frame.setLayout (gridbag);
38
39 // Create buttons, add buttons, and apply constraints
40 c.fill = GridBagConstraints.BOTH;
41 c.weightx = 1.0;
42 makeButton (frame, "Button1", gridbag, c);
43 makeButton (frame, "Button2", gridbag, c);
44 makeButton (frame, "Button3", gridbag, c);
45
46 c.gridwidth = GridBagConstraints.REMAINDER; //end of row
47 makeButton (frame, "Button4", gridbag, c);
48
49 c.weightx = 0.0; //reset to the default
50 makeButton (frame, "Button5", gridbag, c); //another row
51
52 c.gridwidth = GridBagConstraints.RELATIVE; //next-to-last in row
53 makeButton (frame, "Button6", gridbag, c);
54
55 c.gridwidth = GridBagConstraints.REMAINDER; //end of row
56 makeButton (frame, "Button7", gridbag, c);
57
58 c.gridwidth = 1; //reset to the default
59 c.gridheight = 2;
60 c.weighty = 1.0;
61 makeButton (frame, "Button8", gridbag, c);
62
63 c.weighty = 0.0; //reset to the default
64 c.gridwidth = GridBagConstraints.REMAINDER; //end of row
65 c.gridheight = 1; //reset to the default
66 makeButton (frame, "Button9", gridbag, c);
67 makeButton (frame, "Button10", gridbag, c);
68
69 // Show frame
70 frame.pack();
71 frame.setLocation (0, 10);
72 frame.show();
73
74 return frame;
75 }
76
77
78
79 protected static Frame showTableWindow ()
80 {
81 // Create frame
82 Frame frame = new Frame("TableLayout");
83 frame.setFont(new Font("Helvetica", Font.PLAIN, 14));
84
85 // Set layout
86 double f = TableLayout.FILL;
87 double p = TableLayout.PREFERRED;
88 double size[][] = {{f, f, f, f}, {p, p, p, p, f}};
89
90 TableLayout layout = new TableLayout(size);
91 frame.setLayout (layout);
92
93 // Create buttons labeled Button1 to Button10
94 int numButton = 10;
95 JButton button[] = new JButton[numButton + 1];
96
97 for (int i = 1; i <= numButton; i++)
98 button[i] = new JButton("Button" + i);
99
100 // Add buttons
101 frame.add (button[1], "0, 0");
102 frame.add (button[2], "1, 0");
103 frame.add (button[3], "2, 0");
104 frame.add (button[4], "3, 0");
105 frame.add (button[5], "0, 1, 3, 1");
106 frame.add (button[6], "0, 2, 2, 2");
107 frame.add (button[7], "3, 2, 3, 2");
108 frame.add (button[8], "0, 3, 0, 4");
109 frame.add (button[9], "1, 3, 3, 3");
110 frame.add (button[10], "1, 4, 3, 4");
111
112 // Show frame
113 frame.pack();
114 frame.setLocation (400, 10);
115 frame.show();
116
117 return frame;
118 }
119
120
121
122 public static void main (String args[])
123 {
124 WindowListener listener =
125 (new WindowAdapter()
126 {
127 public void windowClosing (WindowEvent e)
128 {
129 System.exit (0);
130 }
131 }
132 );
133
134 Frame frame = showGridBagWindow();
135 frame.addWindowListener (listener);
136
137 frame = showTableWindow();
138 frame.addWindowListener (listener);
139 }
140}
diff --git a/lib/example/GridVersusTable$1.class b/lib/example/GridVersusTable$1.class
new file mode 100644
index 0000000..0acce1a
--- /dev/null
+++ b/lib/example/GridVersusTable$1.class
Binary files differ
diff --git a/lib/example/GridVersusTable.class b/lib/example/GridVersusTable.class
new file mode 100644
index 0000000..ea2dbbe
--- /dev/null
+++ b/lib/example/GridVersusTable.class
Binary files differ
diff --git a/lib/example/GridVersusTable.java b/lib/example/GridVersusTable.java
new file mode 100644
index 0000000..c5746c4
--- /dev/null
+++ b/lib/example/GridVersusTable.java
@@ -0,0 +1,112 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import javax.swing.JButton;
8import layout.TableLayout;
9
10
11
12public class GridVersusTable {
13
14
15
16 protected static Frame showGridWindow ()
17 {
18 // Create frame
19 Frame frame = new Frame("GridLayout");
20 frame.setFont (new Font("Helvetica", Font.PLAIN, 14));
21 frame.setLayout (new GridLayout(2, 0));
22
23 // Create and add buttons
24 frame.add (new JButton("One"));
25 frame.add (new JButton("Two"));
26 frame.add (new JButton("Three"));
27 frame.add (new JButton("Four"));
28
29 // Show frame
30 frame.pack();
31 frame.setLocation (0, 10);
32 frame.show();
33
34 return frame;
35 }
36
37
38
39 protected static Frame showTableWindow ()
40 {
41 // Create frame
42 Frame frame = new Frame("TableLayout");
43 frame.setFont (new Font("Helvetica", Font.PLAIN, 14));
44
45 // Set layout
46 double f = TableLayout.FILL;
47 double size[][] = {{f, f}, {f, f}};
48 frame.setLayout (new TableLayout(size));
49
50 // Create and add buttons
51 frame.add (new JButton("One"), "0, 0");
52 frame.add (new JButton("Two"), "1, 0");
53 frame.add (new JButton("Three"), "0, 1");
54 frame.add (new JButton("Four"), "1, 1");
55
56 // Show frame
57 frame.pack();
58 frame.setLocation (200, 10);
59 frame.show();
60
61 return frame;
62 }
63
64
65
66 protected static Frame showTableWindow2 ()
67 {
68 // Create frame
69 Frame frame = new Frame("TableLayout");
70 frame.setFont (new Font("Helvetica", Font.PLAIN, 14));
71
72 // Set layout
73 double f = TableLayout.FILL;
74 double size[][] = {{f, f}, {f, f}};
75 frame.setLayout (new TableLayout(size));
76
77 // Create and add buttons
78 frame.add (new JButton("One"), "0, 0");
79 frame.add (new JButton("Two"), "1, 1");
80
81 // Show frame
82 frame.pack();
83 frame.setLocation (400, 10);
84 frame.show();
85
86 return frame;
87 }
88
89
90
91 public static void main (String args[])
92 {
93 WindowListener listener =
94 (new WindowAdapter()
95 {
96 public void windowClosing (WindowEvent e)
97 {
98 System.exit (0);
99 }
100 }
101 );
102
103 Frame frame = showGridWindow();
104 frame.addWindowListener(listener);
105
106 frame = showTableWindow();
107 frame.addWindowListener(listener);
108
109 frame = showTableWindow2();
110 frame.addWindowListener(listener);
111 }
112}
diff --git a/lib/example/MyClass$1.class b/lib/example/MyClass$1.class
new file mode 100644
index 0000000..d221d3f
--- /dev/null
+++ b/lib/example/MyClass$1.class
Binary files differ
diff --git a/lib/example/MyClass.class b/lib/example/MyClass.class
new file mode 100644
index 0000000..0ff16c4
--- /dev/null
+++ b/lib/example/MyClass.class
Binary files differ
diff --git a/lib/example/MyClass.java b/lib/example/MyClass.java
new file mode 100644
index 0000000..632e99a
--- /dev/null
+++ b/lib/example/MyClass.java
@@ -0,0 +1,49 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import layout.TableLayout;
8
9public class MyClass
10{
11
12 public static void main (String args[])
13 {
14 Frame frame = new Frame("MyTitle");
15 frame.setBounds (100, 100, 300, 300);
16
17 double size[][] =
18 {{-2.0, 10.0, 50.0, -1.0, 10.0}, // Columns
19 {-2.0, 10.0, 0.25, -1.0, 10.0}}; // Rows
20
21 frame.setLayout (new TableLayout(size));
22
23 Button button;
24 button = new Button("3, 3, R, C");
25 frame.add (button, "3, 3, R, C");
26 button = new Button("3, 3, L, T");
27 frame.add (button, "3, 3, L, T");
28 button = new Button("2, 3, C, T");
29 frame.add (button, "2, 3, C, T");
30 button = new Button("3, 2, L, C");
31 frame.add (button, "3, 2, L, C");
32 button = new Button("2, 2, F, F");
33 frame.add (button, "2, 2, F, F");
34 button = new Button("3, 3, C, C");
35 frame.add (button, "3, 3, C, C");
36
37 frame.addWindowListener
38 (new WindowAdapter()
39 {
40 public void windowClosing (WindowEvent e)
41 {
42 System.exit (0);
43 }
44 }
45 );
46
47 frame.show();
48 }
49}
diff --git a/lib/example/Preferred$1.class b/lib/example/Preferred$1.class
new file mode 100644
index 0000000..2501341
--- /dev/null
+++ b/lib/example/Preferred$1.class
Binary files differ
diff --git a/lib/example/Preferred.class b/lib/example/Preferred.class
new file mode 100644
index 0000000..221d384
--- /dev/null
+++ b/lib/example/Preferred.class
Binary files differ
diff --git a/lib/example/Preferred.java b/lib/example/Preferred.java
new file mode 100644
index 0000000..aa1e8a6
--- /dev/null
+++ b/lib/example/Preferred.java
@@ -0,0 +1,106 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import javax.swing.*;
8import layout.TableLayout;
9
10
11
12public class Preferred extends JFrame
13{
14
15
16
17 public static void main (String args[])
18 {
19 new Preferred();
20 }
21
22
23
24 public Preferred ()
25 {
26 super ("The Power of Preferred Sizes");
27
28 Container pane = getContentPane();
29
30 // b - border
31 // f - FILL
32 // p - PREFERRED
33 // vs - vertical space between labels and text fields
34 // vg - vertical gap between form elements
35 // hg - horizontal gap between form elements
36
37 double b = 10;
38 double f = TableLayout.FILL;
39 double p = TableLayout.PREFERRED;
40 double vs = 5;
41 double vg = 10;
42 double hg = 10;
43
44 double size[][] =
45 {{b, f, hg, p, hg, p, b},
46 {b, p, vs, p, vg, p, vs, p, vg, p, vs, p, vg, p, b}};
47
48 TableLayout layout = new TableLayout(size);
49 pane.setLayout (layout);
50
51 // Create all controls
52 JLabel labelName = new JLabel("Name");
53 JLabel labelAddress = new JLabel("Address");
54 JLabel labelCity = new JLabel("City");
55 JLabel labelState = new JLabel("State");
56 JLabel labelZip = new JLabel("Zip");
57
58 JTextField textfieldName = new JTextField(10);
59 JTextField textfieldAddress = new JTextField(20);
60 JTextField textfieldCity = new JTextField(10);
61 JTextField textfieldState = new JTextField(2);
62 JTextField textfieldZip = new JTextField(5);
63
64 JButton buttonOk = new JButton("OK");
65 JButton buttonCancel = new JButton("Cancel");
66 JPanel panelButton = new JPanel();
67 panelButton.add (buttonOk);
68 panelButton.add (buttonCancel);
69
70 // Add all controls
71 pane.add (labelName, "1, 1, 5, 1");
72 pane.add (textfieldName, "1, 3, 5, 3");
73 pane.add (labelAddress, "1, 5, 5, 5");
74 pane.add (textfieldAddress, "1, 7, 5, 7");
75 pane.add (labelCity, "1, 9");
76 pane.add (textfieldCity, "1, 11");
77 pane.add (labelState, "3, 9");
78 pane.add (textfieldState, "3, 11");
79 pane.add (labelZip, "5, 9");
80 pane.add (textfieldZip, "5, 11");
81 pane.add (panelButton, "1, 13, 5, 13");
82
83 allowClosing();
84 pack();
85 setResizable (false);
86 show();
87 }
88
89
90
91 public void allowClosing ()
92 {
93 addWindowListener
94 (new WindowAdapter()
95 {
96 public void windowClosing (WindowEvent e)
97 {
98 System.exit (0);
99 }
100 }
101 );
102 }
103
104
105
106}
diff --git a/lib/example/RadTool$1.class b/lib/example/RadTool$1.class
new file mode 100644
index 0000000..5701874
--- /dev/null
+++ b/lib/example/RadTool$1.class
Binary files differ
diff --git a/lib/example/RadTool$Box.class b/lib/example/RadTool$Box.class
new file mode 100644
index 0000000..4ca3197
--- /dev/null
+++ b/lib/example/RadTool$Box.class
Binary files differ
diff --git a/lib/example/RadTool$Smiley.class b/lib/example/RadTool$Smiley.class
new file mode 100644
index 0000000..2796ed6
--- /dev/null
+++ b/lib/example/RadTool$Smiley.class
Binary files differ
diff --git a/lib/example/RadTool.class b/lib/example/RadTool.class
new file mode 100644
index 0000000..cc59d1f
--- /dev/null
+++ b/lib/example/RadTool.class
Binary files differ
diff --git a/lib/example/RadTool.java b/lib/example/RadTool.java
new file mode 100644
index 0000000..8ef0c55
--- /dev/null
+++ b/lib/example/RadTool.java
@@ -0,0 +1,647 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import java.util.*;
8import javax.swing.*;
9import layout.TableLayout;
10import layout.TableLayoutConstraints;
11import support.GeneralDialog;
12
13
14
15public class RadTool extends Frame implements ActionListener
16{
17
18
19
20 private JTextField textfieldColumnNumber;
21 private JTextField textfieldColumnSize;
22 private JTextField textfieldRowNumber;
23 private JTextField textfieldRowSize;
24 private JButton buttonAddColumn;
25 private JButton buttonRemoveColumn;
26 private JButton buttonResizeColumn;
27 private JButton buttonAddRow;
28 private JButton buttonRemoveRow;
29 private JButton buttonResizeRow;
30 private JButton buttonShowLayout;
31 private JButton buttonGenerateCode;
32 private TextArea textArea;
33 private JPanel panel;
34 private TableLayout layout;
35 private ArrayList columnHeader;
36 private ArrayList rowHeader;
37 private ArrayList boxList;
38
39
40
41 public static void main (String args[])
42 {
43 new RadTool();
44 }
45
46
47
48 /**
49 * Constructs the user interface.
50 */
51
52 public RadTool()
53 {
54 // Create frame
55 super("Example of Dynamic Rows and Columns");
56
57 // Create a TableLayout for the frame
58 double b = 10;
59 double s = 5;
60 double f = TableLayout.FILL;
61 double p = TableLayout.PREFERRED;
62 double size[][] =
63 {{b, p, s, p, s, p, s, p, s, p, s, p, s, p, f, b},
64 {f, s, p, s, p, s, 100, s, p, b}};
65
66 setLayout (new TableLayout(size));
67
68 // Create static controls
69 JLabel labelColumn = new JLabel("Column");
70 JLabel labelColumnSize = new JLabel("Size");
71 textfieldColumnNumber = new JTextField(2);
72 textfieldColumnSize = new JTextField(2);
73 buttonAddColumn = new JButton("Add");
74 buttonRemoveColumn = new JButton("Remove");
75 buttonResizeColumn = new JButton("Resize");
76
77 JLabel labelRow = new JLabel("Row");
78 JLabel labelRowSize = new JLabel("Size");
79 textfieldRowNumber = new JTextField(2);
80 textfieldRowSize = new JTextField(5);
81 buttonAddRow = new JButton("Add");
82 buttonRemoveRow = new JButton("Remove");
83 buttonResizeRow = new JButton("Resize");
84
85 textArea = new TextArea();
86 columnHeader = new ArrayList();
87 rowHeader = new ArrayList();
88 boxList = new ArrayList();
89 buttonShowLayout = new JButton("Show Layout");
90 buttonGenerateCode = new JButton("Generate Code");
91
92 // Add static controls
93 add (labelColumn, " 1, 2");
94 add (textfieldColumnNumber, " 3, 2");
95 add (labelColumnSize, " 5, 2");
96 add (textfieldColumnSize, " 7, 2");
97 add (buttonAddColumn, " 9, 2");
98 add (buttonRemoveColumn, "11, 2");
99 add (buttonResizeColumn, "13, 2");
100
101 add (labelRow, " 1, 4");
102 add (textfieldRowNumber, " 3, 4");
103 add (labelRowSize, " 5, 4");
104 add (textfieldRowSize, " 7, 4");
105 add (buttonAddRow, " 9, 4");
106 add (buttonRemoveRow, "11, 4");
107 add (buttonResizeRow, "13, 4");
108
109 add (textArea, "1, 6, 14, 6");
110 add (buttonShowLayout, "1, 8, 7, 6");
111 add (buttonGenerateCode, "9, 8, 12, 8");
112
113 // Listen for button events
114 buttonAddColumn.addActionListener (this);
115 buttonRemoveColumn.addActionListener (this);
116 buttonResizeColumn.addActionListener (this);
117 buttonAddRow.addActionListener (this);
118 buttonRemoveRow.addActionListener (this);
119 buttonResizeRow.addActionListener (this);
120 buttonShowLayout.addActionListener (this);
121 buttonGenerateCode.addActionListener (this);
122
123 // Add a panel for RadTool controls
124 panel = new JPanel();
125 panel.setBackground (Color.white);
126 add (panel, "0, 0, 15, 0");
127
128 // Create the layout manager for the panel
129 double size2[][] = {{p, -1}, {p, -1}};
130 layout = new TableLayout(size2);
131 panel.setLayout (layout);
132 updateHeader();
133 updateBox();
134
135 // Allow user to close the window to terminate the program
136 addWindowListener
137 (new WindowAdapter()
138 {
139 public void windowClosing (WindowEvent e)
140 {
141 System.exit (0);
142 }
143 }
144 );
145
146 // Show frame
147 setBackground (Color.lightGray);
148 setBounds (100, 100, 500, 400);
149 show();
150 }
151
152
153
154 /**
155 * Handles all action events.
156 */
157
158 public void actionPerformed (ActionEvent e)
159 {
160 // Get row and column information from text fields
161 int row = getInt(textfieldRowNumber);
162 int col = getInt(textfieldColumnNumber);
163 double rowSize = getDouble(textfieldRowSize);
164 double colSize = getDouble(textfieldColumnSize);
165
166 // Get source of the event
167 Object source = e.getSource();
168
169 try
170 {
171 // Update layout
172 if (source == buttonAddColumn)
173 layout.insertColumn (col, colSize);
174 else if (source == buttonRemoveColumn)
175 layout.deleteColumn (col);
176 else if (source == buttonResizeColumn)
177 layout.setColumn (col, colSize);
178 else if (source == buttonAddRow)
179 layout.insertRow (row, rowSize);
180 else if (source == buttonRemoveRow)
181 layout.deleteRow (row);
182 else if (source == buttonResizeRow)
183 layout.setRow (row, rowSize);
184
185 // Update headers, etc. to reflect layout's change
186 updateHeader();
187 updateBox();
188
189 // Layout and repaint panel since the layout has changed
190 panel.doLayout();
191 panel.repaint();
192
193 // Update layout's description
194 textArea.setText(layout.toString());
195
196 // Generate code if desired
197 if (source == buttonGenerateCode)
198 generateCode();
199 }
200 catch (Throwable error)
201 {
202 error.printStackTrace();
203 textArea.setText (error.toString());
204 }
205 }
206
207
208
209 /**
210 * Converts the text in a text field to an integer.
211 */
212
213 private int getInt (JTextField field)
214 {
215 int value = 0;
216
217 try
218 {
219 value = Integer.parseInt(field.getText());
220 }
221 catch (NumberFormatException e) {}
222
223 return value;
224 }
225
226
227
228 /**
229 * Converts the text in a text field to a double.
230 */
231
232 private double getDouble (JTextField field)
233 {
234 double value = -1.0;
235
236 try
237 {
238 value = Double.parseDouble(field.getText());
239 }
240 catch (NumberFormatException e) {}
241
242 return value;
243 }
244
245
246
247 /**
248 * Updates all the row and columns headers by bruce force. The headers
249 * are removed and then recreated based on the current layout configuration.
250 */
251
252 private void updateHeader ()
253 {
254 TableLayoutConstraints c = new TableLayoutConstraints
255 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL);
256
257 double size[] = layout.getColumn();
258
259 for (int i = columnHeader.size() - 1; i >= 0; i--)
260 {
261 JButton header = (JButton) columnHeader.remove(i);
262 panel.remove(header);
263 }
264
265 for (int i = 0; i < size.length; i++)
266 {
267 c.col1 = c.col2 = i;
268 JButton header = new JButton("" + i + ": " + size[i]);
269 columnHeader.add(i, header);
270 panel.add (header, c);
271 }
272
273 c.col1 = c.col2 = 0;
274 size = layout.getRow();
275
276 for (int i = rowHeader.size() - 1; i >= 0; i--)
277 {
278 JButton header = (JButton) rowHeader.remove(i);
279 panel.remove(header);
280 }
281
282 for (int i = 0; i < size.length; i++)
283 {
284 c.row1 = c.row2 = i;
285 JButton header = new JButton("" + i + ": " + size[i]);
286 rowHeader.add(i, header);
287 panel.add (header, c);
288 }
289 }
290
291
292
293 /**
294 * Updates the boxes used to illustrate cells. This is a brute force,
295 * unoptimized method.
296 */
297
298 private void updateBox ()
299 {
300 for (int i = boxList.size() - 1; i >= 0; i--)
301 {
302 Box box = (Box) boxList.remove(i);
303 panel.remove(box);
304 }
305
306 TableLayoutConstraints constraint = new TableLayoutConstraints
307 (0, 0, 0, 0, TableLayout.FULL, TableLayout.FULL);
308
309 double col[] = layout.getColumn();
310 double row[] = layout.getRow();
311
312 for (int c = 1; c < col.length; c++)
313 for (int r = 1; r < row.length; r++)
314 {
315 constraint.col1 = constraint.col2 = c;
316 constraint.row1 = constraint.row2 = r;
317 Box box = new Box();
318 panel.add (box, constraint);
319 }
320 }
321
322
323
324 /**
325 * Generates code based on the current layout and Smiley controls.
326 */
327
328 private void generateCode ()
329 {
330 String code =
331 "import java.awt.*;\n" +
332 "import java.awt.event.*;\n" +
333 "import layout.TableLayout;\n\n" +
334
335 "public class MyClass\n" +
336 "{\n\n" +
337
338 " public static void main (String args[])\n" +
339 " {\n" +
340 " Frame frame = new Frame(\"MyTitle\");\n" +
341 " frame.setBounds (100, 100, 300, 300);\n\n" +
342
343 " double size[][] =\n" +
344 " {{";
345
346 double size[] = layout.getColumn();
347
348 if (size.length > 0)
349 code += size[0];
350
351 for (int i = 1; i < size.length; i++)
352 code += ", " + size[i];
353
354 code += "}, // Columns\n" +
355 " {";
356
357 size = layout.getRow();
358
359 if (size.length > 0)
360 code += size[0];
361
362 for (int i = 1; i < size.length; i++)
363 code += ", " + size[i];
364
365 code += "}}; // Rows\n\n" +
366 " frame.setLayout (new TableLayout(size));\n\n" +
367 " Button button;\n";
368
369 Component component[] = panel.getComponents();
370
371 for (int i = 0; i < component.length; i++)
372 {
373 if (component[i] instanceof Smiley)
374 {
375 TableLayoutConstraints c = layout.getConstraints(component[i]);
376 String constraint = "" + c.col1 + ", " + c.row1 + ", ";
377
378 if ((c.col1 == c.col2) && (c.row1 == c.row2))
379 {
380 String h[] = {"L", "C", "F", "R"};
381 String v[] = {"T", "C", "F", "B"};
382 constraint += h[c.hAlign] + ", " + v[c.vAlign];
383 }
384 else
385 constraint += c.col2 + ", " + c.row2;
386
387 code +=
388 " button = new Button(\"" + constraint + "\");\n" +
389 " frame.add (button, \"" + constraint + "\");\n";
390 }
391 }
392
393 code +=
394 "\n" +
395 " frame.addWindowListener\n" +
396 " (new WindowAdapter()\n" +
397 " {\n" +
398 " public void windowClosing (WindowEvent e)\n" +
399 " {\n" +
400 " System.exit (0);\n" +
401 " }\n" +
402 " }\n" +
403 " );\n\n" +
404 " frame.show();\n" +
405 " }\n" +
406 "}\n";
407
408 textArea.setText (code);
409 }
410
411
412
413 /**
414 * This inner class is a component that looks like a box.
415 */
416
417 public class Box extends Component implements MouseListener
418 {
419 public Box ()
420 {
421 super();
422 addMouseListener(this);
423 }
424
425 public void update (Graphics g)
426 {
427 paint (g);
428 }
429
430 public void paint (Graphics g)
431 {
432 Dimension d = getSize();
433 g.setColor (Color.black);
434 g.drawRect (0, 0, d.width - 1, d.height - 1);
435 }
436
437 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {}
438 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {}
439 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {}
440 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {}
441
442 public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
443 {
444 TableLayoutConstraints c = layout.getConstraints(this);
445 Smiley smiley = new Smiley();
446 Container container = getParent();
447 container.add(smiley, c, 0);
448 container.doLayout();
449 }
450 }
451
452
453
454 /**
455 * This inner class is a component that looks like a smiley face.
456 */
457
458 public class Smiley extends Component implements MouseListener
459 {
460 public Smiley ()
461 {
462 super();
463 addMouseListener (this);
464 }
465
466 public Dimension getPreferredSize ()
467 {
468 return new Dimension(64, 64);
469 }
470
471 public void update (Graphics g)
472 {
473 paint (g);
474 }
475
476 public void paint (Graphics g)
477 {
478 Dimension d = getSize();
479 int width_1_8 = d.width >> 3;
480 int width_7_8 = d.width - width_1_8;
481 int width_1_4 = d.width >> 2;
482 int width_3_4 = d.width - width_1_4;
483 int width_5_8 = width_3_4 - width_1_8;
484 int width_1_2 = d.width >> 1;
485 int height_1_8 = d.height >> 3;
486 int height_7_8 = d.height - height_1_8;
487 int height_1_4 = d.height >> 2;
488 int height_3_4 = d.height - height_1_4;
489 int height_5_8 = height_7_8 - height_1_4;
490
491 g.setColor (Color.yellow);
492 g.fillArc (0, 0, d.width - 1, d.height - 1, 0, 360);
493 g.setColor (Color.blue);
494 g.fillArc (width_1_4, height_1_4, width_1_8, height_1_8, 0, 360);
495 g.fillArc (width_5_8, height_1_4, width_1_8, height_1_8, 0, 360);
496 g.setColor (Color.red);
497 g.fillArc (width_1_4, height_5_8, width_1_2, height_1_4, 180, 180);
498 }
499
500 public void mouseExited(java.awt.event.MouseEvent mouseEvent) {}
501 public void mousePressed(java.awt.event.MouseEvent mouseEvent) {}
502 public void mouseClicked(java.awt.event.MouseEvent mouseEvent) {}
503 public void mouseEntered(java.awt.event.MouseEvent mouseEvent) {}
504
505 public void mouseReleased(java.awt.event.MouseEvent mouseEvent)
506 {
507 // Get constraints applied to this Smiley
508 TableLayoutConstraints c = layout.getConstraints(this);
509
510 // Create controls
511 Panel panel = new Panel();
512
513 int numRow = layout.getNumRow();
514 int numColumn = layout.getNumColumn();
515
516 Choice choiceCol1 = new Choice();
517 Choice choiceCol2 = new Choice();
518 Choice choiceRow1 = new Choice();
519 Choice choiceRow2 = new Choice();
520
521 for (int i = 1; i < numColumn; i++)
522 {
523 choiceCol1.add ("" + i);
524 choiceCol2.add ("" + i);
525 }
526
527 for (int i = 1; i < numRow; i++)
528 {
529 choiceRow1.add ("" + i);
530 choiceRow2.add ("" + i);
531 }
532
533 choiceCol1.select (c.col1 - 1);
534 choiceCol2.select (c.col2 - 1);
535 choiceRow1.select (c.row1 - 1);
536 choiceRow2.select (c.row2 - 1);
537
538 Choice choiceAlignH = new Choice();
539 choiceAlignH.add ("Left");
540 choiceAlignH.add ("Center");
541 choiceAlignH.add ("Full");
542 choiceAlignH.add ("Right");
543 choiceAlignH.select (c.hAlign);
544
545 Choice choiceAlignV = new Choice();
546 choiceAlignV.add ("Top");
547 choiceAlignV.add ("Center");
548 choiceAlignV.add ("Full");
549 choiceAlignV.add ("Bottom");
550 choiceAlignV.select (c.vAlign);
551
552 JLabel labelCol1 = new JLabel("Column 1");
553 JLabel labelCol2 = new JLabel("Column 2");
554 JLabel labelRow1 = new JLabel("Row 1");
555 JLabel labelRow2 = new JLabel("Row 2");
556 JLabel labelAlignH = new JLabel("Horizontal Justification");
557 JLabel labelAlignV = new JLabel("Vertical Justification");
558 labelAlignH.setHorizontalAlignment (JLabel.RIGHT);
559 labelAlignV.setHorizontalAlignment (JLabel.RIGHT);
560
561 // Create layout
562 double f = TableLayout.FILL;
563 double p = TableLayout.PREFERRED;
564 double s = 10;
565
566 double size[][] =
567 {{f, p, s, p, s, p, s, p, f},
568 {p, s, p, s, p, s, p, s, p, s, p}};
569
570 TableLayout panelLayout = new TableLayout(size);
571 panel.setLayout (panelLayout);
572
573 // Add controls
574 panel.add (labelCol1, "1, 0, R, B");
575 panel.add (choiceCol1, "3, 0, L, B");
576 panel.add (labelRow1, "5, 0, R, B");
577 panel.add (choiceRow1, "7, 0, L, B");
578 panel.add (labelCol2, "1, 2, R, B");
579 panel.add (choiceCol2, "3, 2, L, B");
580 panel.add (labelRow2, "5, 2, R, B");
581 panel.add (choiceRow2, "7, 2, L, B");
582 panel.add (labelAlignH, "0, 4, 3, 4");
583 panel.add (choiceAlignH, "5, 4, 7, 4");
584 panel.add (labelAlignV, "0, 6, 3, 6");
585 panel.add (choiceAlignV, "5, 6, 7, 6");
586
587 // Prompt user
588 String button[] = {"Update Smiley", "Remove Smiley", "Cancel"};
589
590 GeneralDialog dialog = new GeneralDialog
591 (RadTool.this, "Update Smiley", "", button, null, panel);
592
593 String answer = dialog.promptUser();
594
595 // Update constraints applied to this Smiley
596 if (answer.equals("Update Smiley"))
597 {
598 // Get columns
599 int col1 = choiceCol1.getSelectedIndex() + 1;
600 int col2 = choiceCol2.getSelectedIndex() + 1;
601 int row1 = choiceRow1.getSelectedIndex() + 1;
602 int row2 = choiceRow2.getSelectedIndex() + 1;
603
604 // Make sure col1 < col2
605 if (col1 > col2)
606 {
607 int temp = col1;
608 col1 = col2;
609 col2 = temp;
610 }
611
612 // Make sure row1 < row2
613 if (row1 > row2)
614 {
615 int temp = row1;
616 row1 = row2;
617 row2 = temp;
618 }
619
620 // Apply new constraints
621 c.col1 = col1;
622 c.col2 = col2;
623 c.row1 = row1;
624 c.row2 = row2;
625 c.hAlign = choiceAlignH.getSelectedIndex();
626 c.vAlign = choiceAlignV.getSelectedIndex();
627 layout.setConstraints (this, c);
628
629 // Repaint and layout container since layout has changed
630 Container container = getParent();
631 container.doLayout();
632 container.repaint();
633 }
634 // Remove Smiley
635 else if (answer.equals("Remove Smiley"))
636 {
637 Container container = getParent();
638 container.remove (this);
639 container.doLayout();
640 container.repaint();
641 }
642 }
643 }
644
645
646
647}
diff --git a/lib/example/Simple$1.class b/lib/example/Simple$1.class
new file mode 100644
index 0000000..d8ad138
--- /dev/null
+++ b/lib/example/Simple$1.class
Binary files differ
diff --git a/lib/example/Simple.class b/lib/example/Simple.class
new file mode 100644
index 0000000..8fc8404
--- /dev/null
+++ b/lib/example/Simple.class
Binary files differ
diff --git a/lib/example/Simple.java b/lib/example/Simple.java
new file mode 100644
index 0000000..3ff9fb9
--- /dev/null
+++ b/lib/example/Simple.java
@@ -0,0 +1,62 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import layout.TableLayout;
8
9
10
11public class Simple
12{
13
14
15
16 public static void main (String args[])
17 {
18 // Create a frame
19 Frame frame = new Frame("Example of TableLayout");
20 frame.setBounds (100, 100, 300, 300);
21
22 // Create a TableLayout for the frame
23 double border = 10;
24 double size[][] =
25 {{border, 0.10, 20, TableLayout.FILL, 20, 0.20, border}, // Columns
26 {border, 0.20, 20, TableLayout.FILL, 20, 0.20, border}}; // Rows
27
28 frame.setLayout (new TableLayout(size));
29
30 // Create some buttons
31 String label[] = {"Top", "Bottom", "Left", "Right", "Center", "Overlap"};
32 Button button[] = new Button[label.length];
33
34 for (int i = 0; i < label.length; i++)
35 button[i] = new Button(label[i]);
36
37 // Add buttons
38 frame.add (button[0], "1, 1, 5, 1"); // Top
39 frame.add (button[1], "1, 5, 5, 5"); // Bottom
40 frame.add (button[2], "1, 3 "); // Left
41 frame.add (button[3], "5, 3 "); // Right
42 frame.add (button[4], "3, 3, c, c"); // Center
43 frame.add (button[5], "3, 3, 3, 5"); // Overlap
44
45 // Allow user to close the window to terminate the program
46 frame.addWindowListener
47 (new WindowAdapter()
48 {
49 public void windowClosing (WindowEvent e)
50 {
51 System.exit (0);
52 }
53 }
54 );
55
56 // Show frame
57 frame.show();
58 }
59
60
61
62} \ No newline at end of file
diff --git a/lib/example/TypicalGui$1.class b/lib/example/TypicalGui$1.class
new file mode 100644
index 0000000..571f3ee
--- /dev/null
+++ b/lib/example/TypicalGui$1.class
Binary files differ
diff --git a/lib/example/TypicalGui$ColorBox.class b/lib/example/TypicalGui$ColorBox.class
new file mode 100644
index 0000000..9c6555d
--- /dev/null
+++ b/lib/example/TypicalGui$ColorBox.class
Binary files differ
diff --git a/lib/example/TypicalGui.class b/lib/example/TypicalGui.class
new file mode 100644
index 0000000..cc6dfb5
--- /dev/null
+++ b/lib/example/TypicalGui.class
Binary files differ
diff --git a/lib/example/TypicalGui.java b/lib/example/TypicalGui.java
new file mode 100644
index 0000000..ab80ff1
--- /dev/null
+++ b/lib/example/TypicalGui.java
@@ -0,0 +1,179 @@
1package example;
2
3
4
5import java.awt.*;
6import java.awt.event.*;
7import javax.swing.*;
8import layout.TableLayout;
9
10
11
12public class TypicalGui extends JFrame
13{
14
15
16
17 public static void main (String args[])
18 {
19 new TypicalGui();
20 }
21
22
23
24 public TypicalGui ()
25 {
26 super ("A Typical GUI");
27
28 Container pane = getContentPane();
29
30 double b = 10;
31 double f = TableLayout.FILL;
32 double p = TableLayout.PREFERRED;
33 double size[][] = {{b, f, 5, p, 5, p, b}, {p, b, f, 10, p, b}};
34 TableLayout layout = new TableLayout(size);
35 pane.setLayout (layout);
36
37 addMenu(pane);
38 addCommandButtons(pane, layout);
39 addColorBoxes(pane, layout);
40 addTextArea(pane, layout);
41
42 allowClosing();
43 setSize (640, 480);
44 show();
45 }
46
47
48
49 public void addMenu (Container pane)
50 {
51 JMenuBar menuBar = new JMenuBar();
52
53 String menuText[] = {"File", "Edit", "View", "Help"};
54 String itemText[][] =
55 {{"New", "Open", "Save", "Print", "Exit"},
56 {"Cut", "Copy", "Paste"},
57 {"Zoom in", "Zoom out"},
58 {"About", "Index", "Search"}};
59
60 for (int i = 0; i < menuText.length; i++)
61 {
62 JMenu menu = new JMenu(menuText[i]);
63 menuBar.add (menu);
64
65 for (int j = 0; j < itemText[i].length; j++)
66 {
67 JMenuItem item = new JMenuItem(itemText[i][j]);
68 menu.add (item);
69 }
70 }
71
72 pane.add (menuBar, "0, 0, 6, 0");
73 }
74
75
76
77 public void addCommandButtons (Container pane, TableLayout layout)
78 {
79 JPanel buttonPanel = new JPanel();
80 pane.add (buttonPanel, "1, 4, 5, 4");
81
82 for (int i = 1; i <= 5; i++)
83 {
84 JButton button = new JButton("Button " + i);
85 buttonPanel.add (button);
86 }
87 }
88
89
90
91 public void addColorBoxes (Container pane, TableLayout layout)
92 {
93 Color color[][] =
94 {{Color.white, Color.black},
95 {Color.green, Color.blue},
96 {Color.red, Color.yellow},
97 {Color.pink, Color.orange},
98 {Color.magenta, Color.cyan}};
99
100 for (int i = 0; i < color.length; i++)
101 {
102 // Add a row for spacing and a row for the color boxes
103 layout.insertRow (2, TableLayout.PREFERRED);
104 layout.insertRow (2, 5);
105
106 // Add color boxes
107 pane.add (new ColorBox(color[i][0]), "3, 3");
108 pane.add (new ColorBox(color[i][1]), "5, 3");
109 }
110
111 // Remove the unnecessary leading space
112 layout.deleteRow (2);
113 }
114
115
116
117 public void addTextArea (Container pane, TableLayout layout)
118 {
119 int numRow = layout.getRow().length;
120 JTextPane textArea = new JTextPane();
121 pane.add (textArea, "1, 2, 1, " + (numRow - 4));
122 }
123
124
125
126 public void allowClosing ()
127 {
128 addWindowListener
129 (new WindowAdapter()
130 {
131 public void windowClosing (WindowEvent e)
132 {
133 System.exit (0);
134 }
135 }
136 );
137 }
138
139
140
141 //**************************************************************************
142 //*** Inner classes ***
143 //**************************************************************************
144
145
146
147 protected class ColorBox extends Component
148 {
149 protected Color color;
150
151 protected ColorBox (Color color)
152 {
153 this.color = color;
154 }
155
156 public void update (Graphics g)
157 {
158 paint (g);
159 }
160
161 public void paint (Graphics g)
162 {
163 Dimension d = getSize();
164 g.setColor (Color.black);
165 g.drawRect (0, 0, d.width - 1, d.height - 1);
166
167 g.setColor (color);
168 g.fillRect (1, 1, d.width - 1, d.height - 1);
169 }
170
171 public Dimension getPreferredSize ()
172 {
173 return new Dimension(40, 20);;
174 }
175 }
176
177
178
179}
diff --git a/lib/hamcrest-core-1.3.jar b/lib/hamcrest-core-1.3.jar
new file mode 100644
index 0000000..9d5fe16
--- /dev/null
+++ b/lib/hamcrest-core-1.3.jar
Binary files differ
diff --git a/lib/jcommon-1.0.16.jar b/lib/jcommon-1.0.16.jar
new file mode 100644
index 0000000..4cd6807
--- /dev/null
+++ b/lib/jcommon-1.0.16.jar
Binary files differ
diff --git a/lib/jfreechart-1.0.13.jar b/lib/jfreechart-1.0.13.jar
new file mode 100644
index 0000000..83c6993
--- /dev/null
+++ b/lib/jfreechart-1.0.13.jar
Binary files differ
diff --git a/lib/junit-4.13.jar b/lib/junit-4.13.jar
new file mode 100644
index 0000000..acc3c43
--- /dev/null
+++ b/lib/junit-4.13.jar
Binary files differ
diff --git a/lib/looks-2.1.4.jar b/lib/looks-2.1.4.jar
new file mode 100644
index 0000000..d2c47c7
--- /dev/null
+++ b/lib/looks-2.1.4.jar
Binary files differ