1:
51:
52: package ;
53:
54: import ;
55: import ;
56: import ;
57: import ;
58: import ;
59:
60: import ;
61: import ;
62: import ;
63: import ;
64:
65: import ;
66:
67:
72: public class InsetsChooserPanel extends JPanel {
73:
74:
75: private JTextField topValueEditor;
76:
77:
78: private JTextField leftValueEditor;
79:
80:
81: private JTextField bottomValueEditor;
82:
83:
84: private JTextField rightValueEditor;
85:
86:
87: protected static ResourceBundle localizationResources
88: = ResourceBundleWrapper.getBundle(
89: "org.jfree.ui.LocalizationBundle");
90:
91:
95: public InsetsChooserPanel() {
96: this(new Insets(0, 0, 0, 0));
97: }
98:
99:
105: public InsetsChooserPanel(Insets current) {
106: current = (current == null) ? new Insets(0, 0, 0, 0) : current;
107:
108: this.topValueEditor = new JTextField(new IntegerDocument(), ""
109: + current.top, 0);
110: this.leftValueEditor = new JTextField(new IntegerDocument(), ""
111: + current.left, 0);
112: this.bottomValueEditor = new JTextField(new IntegerDocument(), ""
113: + current.bottom, 0);
114: this.rightValueEditor = new JTextField(new IntegerDocument(), ""
115: + current.right, 0);
116:
117: final JPanel panel = new JPanel(new GridBagLayout());
118: panel.setBorder(
119: new TitledBorder(localizationResources.getString("Insets")));
120:
121:
122: panel.add(new JLabel(localizationResources.getString("Top")),
123: new GridBagConstraints(1, 0, 3, 1, 0.0, 0.0,
124: GridBagConstraints.CENTER, GridBagConstraints.NONE,
125: new Insets(0, 0, 0, 0), 0, 0));
126:
127:
128: panel.add(new JLabel(" "), new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0,
129: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
130: new Insets(0, 12, 0, 12), 8, 0));
131: panel.add(this.topValueEditor, new GridBagConstraints(2, 1, 1, 1, 0.0,
132: 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
133: new Insets(0, 0, 0, 0), 0, 0));
134: panel.add(new JLabel(" "), new GridBagConstraints(3, 1, 1, 1, 0.0, 0.0,
135: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
136: new Insets(0, 12, 0, 11), 8, 0));
137:
138:
139: panel.add(new JLabel(localizationResources.getString("Left")),
140: new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0,
141: GridBagConstraints.CENTER, GridBagConstraints.BOTH,
142: new Insets(0, 4, 0, 4), 0, 0));
143: panel.add(this.leftValueEditor, new GridBagConstraints(1, 2, 1, 1,
144: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH,
145: new Insets(0, 0, 0, 0), 0, 0));
146: panel.add(new JLabel(" "), new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0,
147: GridBagConstraints.CENTER, GridBagConstraints.NONE,
148: new Insets(0, 12, 0, 12), 8, 0));
149: panel.add(this.rightValueEditor, new GridBagConstraints(3, 2, 1, 1,
150: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
151: new Insets(0, 0, 0, 0), 0, 0));
152: panel.add(new JLabel(localizationResources.getString("Right")),
153: new GridBagConstraints(4, 2, 1, 1, 0.0, 0.0,
154: GridBagConstraints.CENTER, GridBagConstraints.NONE,
155: new Insets(0, 4, 0, 4), 0, 0));
156:
157:
158: panel.add(this.bottomValueEditor, new GridBagConstraints(2, 3, 1, 1,
159: 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
160: new Insets(0, 0, 0, 0), 0, 0));
161:
162:
163: panel.add(new JLabel(localizationResources.getString("Bottom")),
164: new GridBagConstraints(1, 4, 3, 1, 0.0, 0.0,
165: GridBagConstraints.CENTER, GridBagConstraints.NONE,
166: new Insets(0, 0, 0, 0), 0, 0));
167: setLayout(new BorderLayout());
168: add(panel, BorderLayout.CENTER);
169:
170: }
171:
172:
178: public Insets getInsetsValue() {
179: return new Insets(
180: Math.abs(stringToInt(this.topValueEditor.getText())),
181: Math.abs(stringToInt(this.leftValueEditor.getText())),
182: Math.abs(stringToInt(this.bottomValueEditor.getText())),
183: Math.abs(stringToInt(this.rightValueEditor.getText())));
184: }
185:
186:
195: protected int stringToInt(String value) {
196: value = value.trim();
197: if (value.length() == 0) {
198: return 0;
199: }
200: else {
201: try {
202: return Integer.parseInt(value);
203: }
204: catch (NumberFormatException e) {
205: return 0;
206: }
207: }
208: }
209:
210:
213: public void removeNotify() {
214: super.removeNotify();
215: removeAll();
216: }
217:
218: }