1:
49:
50: package ;
51:
52: import ;
53: import ;
54: import ;
55: import ;
56: import ;
57:
58: import ;
59: import ;
60: import ;
61: import ;
62:
63:
68: public class InsetsChooserPanel extends JPanel {
69:
70:
71: private JTextField topValueEditor;
72:
73:
74: private JTextField leftValueEditor;
75:
76:
77: private JTextField bottomValueEditor;
78:
79:
80: private JTextField rightValueEditor;
81:
82:
83: protected static ResourceBundle localizationResources =
84: ResourceBundle.getBundle("org.jfree.ui.LocalizationBundle");
85:
86:
90: public InsetsChooserPanel() {
91: this(new Insets(0, 0, 0, 0));
92: }
93:
94:
100: public InsetsChooserPanel(Insets current) {
101: current = (current == null) ? new Insets(0, 0, 0, 0) : current;
102:
103: this.topValueEditor = new JTextField(new IntegerDocument(), ""
104: + current.top, 0);
105: this.leftValueEditor = new JTextField(new IntegerDocument(), ""
106: + current.left, 0);
107: this.bottomValueEditor = new JTextField(new IntegerDocument(), ""
108: + current.bottom, 0);
109: this.rightValueEditor = new JTextField(new IntegerDocument(), ""
110: + current.right, 0);
111:
112: final JPanel panel = new JPanel(new GridBagLayout());
113: panel.setBorder(
114: new TitledBorder(localizationResources.getString("Insets")));
115:
116:
117: panel.add(new JLabel(localizationResources.getString("Top")),
118: new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0,
119: GridBagConstraints.CENTER, GridBagConstraints.NONE,
120: new Insets(0, 0, 0, 0), 0, 0));
121:
122:
123: panel.add(new JLabel(" "), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
124: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
125: new Insets(0, 12, 0, 12), 8, 0));
126: panel.add(this.topValueEditor, new GridBagConstraints(2, 1, 1, 1, 0.0,
127: 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
128: new Insets(0, 0, 0, 0), 0, 0));
129: panel.add(new JLabel(" "), new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
130: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
131: new Insets(0, 12, 0, 11), 8, 0));
132:
133:
134: panel.add(new JLabel(localizationResources.getString("Left")),
135: new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
136: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
137: new Insets(0, 4, 0, 4), 0, 0));
138: panel.add(this.leftValueEditor, new GridBagConstraints(1, 2, 1, 1,
139: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
140: new Insets(0, 0, 0, 0), 0, 0));
141: panel.add(new JLabel(" "), new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
142: GridBagConstraints.CENTER, GridBagConstraints.NONE,
143: new Insets(0, 12, 0, 12), 8, 0));
144: panel.add(this.rightValueEditor, new GridBagConstraints(3, 2, 1, 1,
145: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
146: new Insets(0, 0, 0, 0), 0, 0));
147: panel.add(new JLabel(localizationResources.getString("Right")),
148: new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0,
149: GridBagConstraints.CENTER, GridBagConstraints.NONE,
150: new Insets(0, 4, 0, 4), 0, 0));
151:
152:
153: panel.add(this.bottomValueEditor, new GridBagConstraints(2, 3, 1, 1,
154: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
155: new Insets(0, 0, 0, 0), 0, 0));
156:
157:
158: panel.add(new JLabel(localizationResources.getString("Bottom")),
159: new GridBagConstraints(1, 4, 3, 1, 0.0, 0.0,
160: GridBagConstraints.CENTER, GridBagConstraints.NONE,
161: new Insets(0, 0, 0, 0), 0, 0));
162: setLayout(new BorderLayout());
163: add(panel, BorderLayout.CENTER);
164:
165: }
166:
167:
173: public Insets getInsetsValue() {
174: return new Insets(
175: Math.abs(stringToInt(this.topValueEditor.getText())),
176: Math.abs(stringToInt(this.leftValueEditor.getText())),
177: Math.abs(stringToInt(this.bottomValueEditor.getText())),
178: Math.abs(stringToInt(this.rightValueEditor.getText())));
179: }
180:
181:
190: protected int stringToInt(String value) {
191: value = value.trim();
192: if (value.length() == 0) {
193: return 0;
194: }
195: else {
196: try {
197: return Integer.parseInt(value);
198: }
199: catch (NumberFormatException e) {
200: return 0;
201: }
202: }
203: }
204:
205:
208: public void removeNotify() {
209: super.removeNotify();
210: removeAll();
211: }
212:
213: }