38 |
package javax.swing; |
package javax.swing; |
39 |
|
|
40 |
import java.awt.Component; |
import java.awt.Component; |
41 |
|
import java.awt.Container; |
42 |
import java.awt.Dimension; |
import java.awt.Dimension; |
43 |
import java.awt.Graphics; |
import java.awt.Graphics; |
44 |
import java.awt.GridLayout; |
import java.awt.GridLayout; |
47 |
import java.beans.PropertyChangeListener; |
import java.beans.PropertyChangeListener; |
48 |
import java.io.IOException; |
import java.io.IOException; |
49 |
import java.io.ObjectOutputStream; |
import java.io.ObjectOutputStream; |
|
|
|
50 |
import javax.accessibility.Accessible; |
import javax.accessibility.Accessible; |
51 |
import javax.accessibility.AccessibleContext; |
import javax.accessibility.AccessibleContext; |
52 |
import javax.accessibility.AccessibleRole; |
import javax.accessibility.AccessibleRole; |
53 |
import javax.accessibility.AccessibleStateSet; |
import javax.accessibility.AccessibleStateSet; |
54 |
import javax.swing.plaf.ToolBarUI; |
import javax.swing.plaf.ToolBarUI; |
55 |
|
|
56 |
|
|
57 |
/** |
/** |
58 |
* JToolBar |
* JToolBar is a component that provides a toolbar to Swing programs. Users |
59 |
* @author Andrew Selkirk |
* can add buttons (or actions that will be represented by JButtons) as well |
60 |
* @version 1.0 |
* as other components to the JToolBar. JToolBars can be dragged in and out |
61 |
|
* of their parent components. If the JToolBar is dragged out of the parent, |
62 |
|
* then it will be displayed in its own RootPaneContainer. For dragging to |
63 |
|
* work properly, JToolBars need to be placed in a Container that has a |
64 |
|
* BorderLayout. That parent Container cannot have components in the NORTH, |
65 |
|
* EAST, SOUTH, or WEST components (that is not the JToolBar). |
66 |
*/ |
*/ |
67 |
public class JToolBar extends JComponent |
public class JToolBar extends JComponent implements SwingConstants, Accessible |
|
implements SwingConstants, Accessible |
|
68 |
{ |
{ |
69 |
/** |
/** |
70 |
* AccessibleJToolBar |
* AccessibleJToolBar |
71 |
*/ |
*/ |
72 |
protected class AccessibleJToolBar extends AccessibleJComponent |
protected class AccessibleJToolBar extends AccessibleJComponent |
73 |
{ |
{ |
74 |
|
/** DOCUMENT ME! */ |
75 |
private static final long serialVersionUID = -5516888265903814215L; |
private static final long serialVersionUID = -5516888265903814215L; |
76 |
|
|
77 |
/** |
/** |
83 |
|
|
84 |
/** |
/** |
85 |
* getAccessibleStateSet |
* getAccessibleStateSet |
86 |
|
* |
87 |
* @return AccessibleStateSet |
* @return AccessibleStateSet |
88 |
*/ |
*/ |
89 |
public AccessibleStateSet getAccessibleStateSet() |
public AccessibleStateSet getAccessibleStateSet() |
93 |
|
|
94 |
/** |
/** |
95 |
* getAccessibleRole |
* getAccessibleRole |
96 |
|
* |
97 |
* @return AccessibleRole |
* @return AccessibleRole |
98 |
*/ |
*/ |
99 |
public AccessibleRole getAccessibleRole() |
public AccessibleRole getAccessibleRole() |
103 |
} |
} |
104 |
|
|
105 |
/** |
/** |
106 |
* Separator |
* This is the private JToolBar layout manager. |
107 |
|
*/ |
108 |
|
private class DefaultToolBarLayout implements LayoutManager |
109 |
|
{ |
110 |
|
/** |
111 |
|
* This method is called when a new component is added to the container. |
112 |
|
* |
113 |
|
* @param name The name of the component added. |
114 |
|
* @param comp The component that was added. |
115 |
*/ |
*/ |
116 |
public static class Separator extends JSeparator { |
public void addLayoutComponent(String name, Component comp) |
117 |
|
{ |
118 |
|
// Do nothing. |
119 |
|
} |
120 |
|
|
121 |
private static final long serialVersionUID = -1656745644823105219L; |
/** |
122 |
|
* This method is called to lay out the given container to position and |
123 |
|
* size the child components. |
124 |
|
* |
125 |
|
* @param c The container to lay out. |
126 |
|
* |
127 |
|
* @throws Error DOCUMENT ME! |
128 |
|
*/ |
129 |
|
public void layoutContainer(Container c) |
130 |
|
{ |
131 |
|
if (! (c instanceof JToolBar)) |
132 |
|
throw new Error("DefaultToolBarLayout can only be used on JToolBars."); |
133 |
|
Insets insets = getInsets(); |
134 |
|
Insets margin = getMargin(); |
135 |
|
int middle; |
136 |
|
if (margin != null) |
137 |
|
{ |
138 |
|
insets.left += margin.left; |
139 |
|
insets.top += margin.top; |
140 |
|
insets.bottom += margin.bottom; |
141 |
|
insets.right += margin.right; |
142 |
|
} |
143 |
|
Component[] components = c.getComponents(); |
144 |
|
Dimension tdims = c.getSize(); |
145 |
|
int start = 0; |
146 |
|
Dimension pref; |
147 |
|
|
148 |
//------------------------------------------------------------- |
if (getOrientation() == SwingUtilities.HORIZONTAL) |
149 |
// Variables -------------------------------------------------- |
{ |
150 |
//------------------------------------------------------------- |
start += insets.left; |
151 |
|
for (int i = 0; i < components.length; i++) |
152 |
|
{ |
153 |
|
if (components[i] != null && components[i].isVisible()) |
154 |
|
{ |
155 |
|
pref = components[i].getPreferredSize(); |
156 |
|
if (pref != null) |
157 |
|
{ |
158 |
|
middle = (tdims.height - pref.height) / 2; |
159 |
|
components[i].setBounds(start, middle, pref.width, |
160 |
|
pref.height); |
161 |
|
start += pref.width; |
162 |
|
} |
163 |
|
} |
164 |
|
} |
165 |
|
} |
166 |
|
else |
167 |
|
{ |
168 |
|
start += insets.top; |
169 |
|
for (int i = 0; i < components.length; i++) |
170 |
|
{ |
171 |
|
if (components[i] != null && components[i].isVisible()) |
172 |
|
{ |
173 |
|
pref = components[i].getPreferredSize(); |
174 |
|
if (pref != null) |
175 |
|
{ |
176 |
|
middle = (tdims.width - pref.width) / 2; |
177 |
|
components[i].setBounds(middle, start, pref.width, |
178 |
|
pref.height); |
179 |
|
start += pref.height; |
180 |
|
} |
181 |
|
} |
182 |
|
} |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
|
/** |
187 |
|
* This method returns the minimum size of the given container given the |
188 |
|
* child components. |
189 |
|
* |
190 |
|
* @param parent The container to measure. |
191 |
|
* |
192 |
|
* @return The minimum size of the given container. |
193 |
|
*/ |
194 |
|
public Dimension minimumLayoutSize(Container parent) |
195 |
|
{ |
196 |
|
return preferredLayoutSize(parent); |
197 |
|
} |
198 |
|
|
199 |
/** |
/** |
200 |
* separatorSize |
* This method returns the preferred size of the given container given the |
201 |
|
* child components. |
202 |
|
* |
203 |
|
* @param parent The container to measure. |
204 |
|
* |
205 |
|
* @return The preferred size of the given container. |
206 |
*/ |
*/ |
207 |
private Dimension size; |
public Dimension preferredLayoutSize(Container parent) |
208 |
|
{ |
209 |
|
int orientation = getOrientation(); |
210 |
|
Component[] components = getComponents(); |
211 |
|
|
212 |
|
int limit = 0; |
213 |
|
int total = 0; |
214 |
|
Dimension dims; |
215 |
|
|
216 |
|
int w = 0; |
217 |
|
int h = 0; |
218 |
|
|
219 |
|
if (orientation == SwingConstants.HORIZONTAL) |
220 |
|
{ |
221 |
|
for (int i = 0; i < components.length; i++) |
222 |
|
{ |
223 |
|
dims = components[i].getPreferredSize(); |
224 |
|
if (dims != null) |
225 |
|
{ |
226 |
|
if (dims.height > limit) |
227 |
|
limit = dims.height; |
228 |
|
total += dims.width; |
229 |
|
} |
230 |
|
} |
231 |
|
w = total; |
232 |
|
h = limit; |
233 |
|
} |
234 |
|
else |
235 |
|
{ |
236 |
|
for (int i = 0; i < components.length; i++) |
237 |
|
{ |
238 |
|
dims = components[i].getPreferredSize(); |
239 |
|
if (dims != null) |
240 |
|
{ |
241 |
|
if (dims.width > limit) |
242 |
|
limit = dims.width; |
243 |
|
total += dims.height; |
244 |
|
} |
245 |
|
} |
246 |
|
w = limit; |
247 |
|
h = total; |
248 |
|
} |
249 |
|
|
250 |
|
Insets insets = getInsets(); |
251 |
|
w += insets.left + insets.right; |
252 |
|
h += insets.top + insets.bottom; |
253 |
|
|
254 |
|
Insets margin = getMargin(); |
255 |
|
if (margin != null) |
256 |
|
{ |
257 |
|
w += margin.left + margin.right; |
258 |
|
h += margin.top + margin.bottom; |
259 |
|
} |
260 |
|
|
261 |
//------------------------------------------------------------- |
return new Dimension(w, h); |
262 |
// Initialization --------------------------------------------- |
} |
|
//------------------------------------------------------------- |
|
263 |
|
|
264 |
/** |
/** |
265 |
* Constructor Separator |
* This method is called when the given component is removed from the |
266 |
|
* container. |
267 |
|
* |
268 |
|
* @param comp The component removed. |
269 |
*/ |
*/ |
270 |
public Separator() { |
public void removeLayoutComponent(Component comp) |
271 |
// TODO |
{ |
272 |
} // Separator() |
// Do nothing. |
273 |
|
} |
274 |
|
} |
275 |
|
|
276 |
/** |
/** |
277 |
* Constructor Separator |
* This is an extension of JSeparator used in toolbars. Unlike JSeparator, |
278 |
* @param size TODO |
* nothing is painted for this Separator, it is only blank space that |
279 |
|
* separates components. |
280 |
*/ |
*/ |
281 |
public Separator(Dimension size) { |
public static class Separator extends JSeparator |
282 |
// TODO |
{ |
283 |
} // Separator() |
/** DOCUMENT ME! */ |
284 |
|
private static final long serialVersionUID = -1656745644823105219L; |
285 |
|
|
286 |
|
/** |
287 |
|
* Creates a new Separator object. |
288 |
|
*/ |
289 |
|
public Separator() |
290 |
|
{ |
291 |
|
super(); |
292 |
|
} // Separator() |
293 |
|
|
294 |
//------------------------------------------------------------- |
/** |
295 |
// Methods ---------------------------------------------------- |
* Creates a new Separator object with the given size. |
296 |
//------------------------------------------------------------- |
* |
297 |
|
* @param size The size of the separator. |
298 |
|
*/ |
299 |
|
public Separator(Dimension size) |
300 |
|
{ |
301 |
|
setPreferredSize(size); |
302 |
|
} // Separator() |
303 |
|
|
304 |
/** |
/** |
305 |
* getUIClassID |
* This method returns the String ID of the UI class of Separator. |
306 |
* @returns String |
* |
307 |
|
* @return The UI class' String ID. |
308 |
*/ |
*/ |
309 |
public String getUIClassID() { |
public String getUIClassID() |
310 |
return null; // TODO |
{ |
311 |
|
return "ToolBarSeparatorUI"; |
312 |
} // getUIClassID() |
} // getUIClassID() |
313 |
|
|
314 |
/** |
/** |
315 |
* getPreferredSize |
* This method returns the preferred size of the Separator. |
316 |
* @returns Dimension |
* |
317 |
|
* @return The preferred size of the Separator. |
318 |
*/ |
*/ |
319 |
public Dimension getPreferredSize() { |
public Dimension getPreferredSize() |
320 |
return null; // TODO |
{ |
321 |
|
return super.getPreferredSize(); |
322 |
} // getPreferredSize() |
} // getPreferredSize() |
323 |
|
|
324 |
/** |
/** |
325 |
* getMaximumSize |
* This method returns the maximum size of the Separator. |
326 |
* @returns Dimension |
* |
327 |
|
* @return The maximum size of the Separator. |
328 |
*/ |
*/ |
329 |
public Dimension getMaximumSize() { |
public Dimension getMaximumSize() |
330 |
return null; // TODO |
{ |
331 |
|
return super.getPreferredSize(); |
332 |
} // getMaximumSize() |
} // getMaximumSize() |
333 |
|
|
334 |
/** |
/** |
335 |
* getMinimumSize |
* This method returns the minimum size of the Separator. |
336 |
* @returns Dimension |
* |
337 |
|
* @return The minimum size of the Separator. |
338 |
*/ |
*/ |
339 |
public Dimension getMinimumSize() { |
public Dimension getMinimumSize() |
340 |
return null; // TODO |
{ |
341 |
|
return super.getPreferredSize(); |
342 |
} // getMinimumSize() |
} // getMinimumSize() |
343 |
|
|
344 |
/** |
/** |
345 |
* getSeparatorSize |
* This method returns the size of the Separator. |
346 |
* @returns Dimension |
* |
347 |
|
* @return The size of the Separator. |
348 |
*/ |
*/ |
349 |
public Dimension getSeparatorSize() { |
public Dimension getSeparatorSize() |
350 |
return null; // TODO |
{ |
351 |
|
return super.getPreferredSize(); |
352 |
} // getSeparatorSize() |
} // getSeparatorSize() |
353 |
|
|
354 |
/** |
/** |
355 |
* setSeparatorSize |
* This method sets the size of the Separator. |
356 |
* @param size TODO |
* |
357 |
|
* @param size The new size of the Separator. |
358 |
*/ |
*/ |
359 |
public void setSeparatorSize(Dimension size) { |
public void setSeparatorSize(Dimension size) |
360 |
// TODO |
{ |
361 |
|
setPreferredSize(size); |
362 |
} // setSeparatorSize() |
} // setSeparatorSize() |
|
|
|
|
|
|
363 |
} // Separator |
} // Separator |
364 |
|
|
365 |
// /** |
/** DOCUMENT ME! */ |
|
// * DefaultJToolBarLayout |
|
|
// */ |
|
|
// private class DefaultJToolBarLayout { |
|
|
// |
|
|
// private void DefaultJToolBarLayout() { |
|
|
// } |
|
|
// |
|
|
// private LayoutManager getLayout() { |
|
|
// switch (JToolBar.this.getOrientation()) { |
|
|
// case HORIZONTAL: setLayout(new GridLayout(1, 0, 4, 4)); |
|
|
// break; |
|
|
// case VERTICAL: setLayout(new GridLayout(0, 1, 4, 4)); |
|
|
// break; |
|
|
// } |
|
|
// } |
|
|
// } // DefaultJToolBarLayout |
|
|
|
|
|
|
|
366 |
private static final long serialVersionUID = -1269915519555129643L; |
private static final long serialVersionUID = -1269915519555129643L; |
367 |
|
|
368 |
//------------------------------------------------------------- |
/** Whether the JToolBar paints its border. */ |
369 |
// Variables -------------------------------------------------- |
private transient boolean paintBorder = true; |
|
//------------------------------------------------------------- |
|
370 |
|
|
371 |
/** |
/** The extra insets around the JToolBar. */ |
372 |
* uiClassID |
private transient Insets margin; |
|
*/ |
|
|
private static final String uiClassID = "ToolBarUI"; |
|
373 |
|
|
374 |
/** |
/** Whether the JToolBar can float (and be dragged around). */ |
375 |
* paintBorder |
private transient boolean floatable = true; |
|
*/ |
|
|
private boolean paintBorder; |
|
376 |
|
|
377 |
/** |
/** Whether the buttons will have rollover borders. */ |
378 |
* margin |
private transient boolean rollover; |
|
*/ |
|
|
private Insets margin; |
|
379 |
|
|
380 |
/** |
/** The orientation of the JToolBar. */ |
|
* floatable |
|
|
*/ |
|
|
private boolean floatable; |
|
|
|
|
|
/** |
|
|
* orientation |
|
|
*/ |
|
381 |
private int orientation = HORIZONTAL; |
private int orientation = HORIZONTAL; |
382 |
|
|
383 |
// protected transient DefaultJToolBarLayout toolbarLayout; |
/** Fired in a PropertyChangeEvent when the orientation property changes. */ |
|
|
|
|
/** Fired in a PropertyChangeEvent when the "orientation" property changes. |
|
|
*/ |
|
384 |
public static final String ORIENTATION_CHANGED_PROPERTY = "orientation"; |
public static final String ORIENTATION_CHANGED_PROPERTY = "orientation"; |
385 |
|
|
386 |
//------------------------------------------------------------- |
/** Fired in a PropertyChangeEvent when the floatable property changes. */ |
387 |
// Initialization --------------------------------------------- |
public static final String FLOATABLE_CHANGED_PROPERTY = "floatable"; |
388 |
//------------------------------------------------------------- |
|
389 |
|
/** Fired in a PropertyChangeEvent when the borderPainted property changes. */ |
390 |
|
public static final String BORDER_PAINTED_CHANGED_PROPERTY = "borderPainted"; |
391 |
|
|
392 |
|
/** Fired in a PropertyChangeEvent when the margin property changes. */ |
393 |
|
public static final String MARGIN_CHANGED_PROPERTY = "margin"; |
394 |
|
|
395 |
|
/** Fired in a PropertyChangeEvent when the rollover property changes. */ |
396 |
|
public static final String ROLLOVER_CHANGED_PROPERTY = "rollover"; |
397 |
|
|
398 |
/** |
/** |
399 |
* Constructor JToolBar |
* This method creates a new JToolBar object with horizontal orientation |
400 |
|
* and no name. |
401 |
*/ |
*/ |
402 |
public JToolBar() { |
public JToolBar() |
403 |
this(null); |
{ |
404 |
|
this(null, HORIZONTAL); |
405 |
} // JToolBar() |
} // JToolBar() |
406 |
|
|
407 |
/** |
/** |
408 |
* Constructor JToolBar |
* This method creates a new JToolBar with the given orientation and no |
409 |
|
* name. |
410 |
|
* |
411 |
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) |
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) |
412 |
*/ |
*/ |
413 |
public JToolBar(int orientation) { |
public JToolBar(int orientation) |
414 |
|
{ |
415 |
this(null, orientation); |
this(null, orientation); |
416 |
} // JToolBar() |
} // JToolBar() |
417 |
|
|
418 |
/** |
/** |
419 |
* Constructor JToolBar |
* This method creates a new JToolBar object with the given name and |
420 |
|
* horizontal orientation. |
421 |
|
* |
422 |
* @param name Name assigned to undocked tool bar. |
* @param name Name assigned to undocked tool bar. |
423 |
*/ |
*/ |
424 |
public JToolBar(String name) { |
public JToolBar(String name) |
425 |
|
{ |
426 |
this(name, HORIZONTAL); |
this(name, HORIZONTAL); |
427 |
} // JToolBar() |
} // JToolBar() |
428 |
|
|
429 |
/** |
/** |
430 |
* Constructor JToolBar |
* This method creates a new JToolBar object with the given name and |
431 |
|
* orientation. |
432 |
|
* |
433 |
* @param name Name assigned to undocked tool bar. |
* @param name Name assigned to undocked tool bar. |
434 |
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) |
* @param orientation JToolBar orientation (HORIZONTAL or VERTICAL) |
435 |
*/ |
*/ |
436 |
public JToolBar(String name, int orientation) { |
public JToolBar(String name, int orientation) |
437 |
|
{ |
438 |
setName(name); |
setName(name); |
439 |
if (orientation != HORIZONTAL && orientation != VERTICAL) |
setOrientation(orientation); |
440 |
throw new IllegalArgumentException(orientation + " is not a legal orientation"); |
setLayout(new DefaultToolBarLayout()); |
441 |
this.orientation = orientation; |
revalidate(); |
|
// toolbarLayout = new DefaultJToolBarLayout(); |
|
442 |
updateUI(); |
updateUI(); |
443 |
} // JToolBar() |
} // JToolBar() |
444 |
|
|
|
|
|
|
//------------------------------------------------------------- |
|
|
// Methods ---------------------------------------------------- |
|
|
//------------------------------------------------------------- |
|
|
|
|
|
/** |
|
|
* writeObject |
|
|
* @param stream TODO |
|
|
* @exception IOException TODO |
|
|
*/ |
|
|
private void writeObject(ObjectOutputStream stream) throws IOException { |
|
|
// TODO |
|
|
} // writeObject() |
|
|
|
|
445 |
/** |
/** |
446 |
* add |
* This method adds a new JButton that performs the given Action to the |
447 |
* @param action TODO |
* JToolBar. |
448 |
* @returns JButton |
* |
449 |
|
* @param action The Action to add to the JToolBar. |
450 |
|
* |
451 |
|
* @return The JButton that wraps the Action. |
452 |
*/ |
*/ |
453 |
public JButton add(Action action) { |
public JButton add(Action action) |
454 |
return null; // TODO |
{ |
455 |
|
JButton b = createActionComponent(action); |
456 |
|
add(b); |
457 |
|
return b; |
458 |
} // add() |
} // add() |
459 |
|
|
460 |
/** |
/** |
461 |
* paintBorder |
* This method paints the border if the borderPainted property is true. |
462 |
* @param graphics TODO |
* |
463 |
|
* @param graphics The graphics object to paint with. |
464 |
*/ |
*/ |
465 |
protected void paintBorder(Graphics graphics) { |
protected void paintBorder(Graphics graphics) |
466 |
// TODO |
{ |
467 |
|
if (paintBorder && isFloatable()) |
468 |
|
super.paintBorder(graphics); |
469 |
} // paintBorder() |
} // paintBorder() |
470 |
|
|
471 |
/** |
/** |
472 |
* getUI |
* This method returns the UI class used to paint this JToolBar. |
473 |
* @returns ToolBarUI |
* |
474 |
|
* @return The UI class for this JToolBar. |
475 |
*/ |
*/ |
476 |
public ToolBarUI getUI() { |
public ToolBarUI getUI() |
477 |
System.out.println("ui = " + ui); |
{ |
478 |
return (ToolBarUI) ui; |
return (ToolBarUI) ui; |
479 |
} // getUI() |
} // getUI() |
480 |
|
|
481 |
/** |
/** |
482 |
* setUI |
* This method sets the UI used with the JToolBar. |
483 |
* @param ui TODO |
* |
484 |
|
* @param ui The UI used with the JToolBar. |
485 |
*/ |
*/ |
486 |
public void setUI(ToolBarUI ui) { |
public void setUI(ToolBarUI ui) |
487 |
|
{ |
488 |
super.setUI(ui); |
super.setUI(ui); |
489 |
} // setUI() |
} // setUI() |
490 |
|
|
491 |
/** |
/** |
492 |
* updateUI |
* This method resets the UI used to the Look and Feel defaults. |
493 |
*/ |
*/ |
494 |
public void updateUI() { |
public void updateUI() |
495 |
|
{ |
496 |
setUI((ToolBarUI)UIManager.getUI(this)); |
setUI((ToolBarUI)UIManager.getUI(this)); |
497 |
|
revalidate(); |
498 |
|
repaint(); |
499 |
} // updateUI() |
} // updateUI() |
500 |
|
|
501 |
/** |
/** |
502 |
* getUIClassID |
* This method returns the String identifier for the UI class to the used |
503 |
* @returns String |
* with the JToolBar. |
504 |
|
* |
505 |
|
* @return The String identifier for the UI class. |
506 |
*/ |
*/ |
507 |
public String getUIClassID() { |
public String getUIClassID() |
508 |
return uiClassID; |
{ |
509 |
|
return "ToolBarUI"; |
510 |
} // getUIClassID() |
} // getUIClassID() |
511 |
|
|
512 |
/** |
/** |
513 |
* getComponentIndex |
* This method sets the rollover property for the JToolBar. In rollover |
514 |
* @param component TODO |
* mode, JButtons inside the JToolBar will only display their borders when |
515 |
* @returns int |
* the mouse is moving over them. |
516 |
|
* |
517 |
|
* @param b The new rollover property. |
518 |
*/ |
*/ |
519 |
public int getComponentIndex(Component component) { |
public void setRollover(boolean b) |
520 |
return 0; // TODO |
{ |
521 |
|
if (b != rollover) |
522 |
|
{ |
523 |
|
rollover = b; |
524 |
|
firePropertyChange(ROLLOVER_CHANGED_PROPERTY, ! rollover, rollover); |
525 |
|
revalidate(); |
526 |
|
repaint(); |
527 |
|
} |
528 |
|
} |
529 |
|
|
530 |
|
/** |
531 |
|
* This method returns the rollover property. |
532 |
|
* |
533 |
|
* @return The rollover property. |
534 |
|
*/ |
535 |
|
public boolean isRollover() |
536 |
|
{ |
537 |
|
return rollover; |
538 |
|
} |
539 |
|
|
540 |
|
/** |
541 |
|
* This method returns the index of the given component. |
542 |
|
* |
543 |
|
* @param component The component to find. |
544 |
|
* |
545 |
|
* @return The index of the given component. |
546 |
|
*/ |
547 |
|
public int getComponentIndex(Component component) |
548 |
|
{ |
549 |
|
Component[] components = getComponents(); |
550 |
|
if (components == null) |
551 |
|
return -1; |
552 |
|
|
553 |
|
for (int i = 0; i < components.length; i++) |
554 |
|
if (components[i] == component) |
555 |
|
return i; |
556 |
|
|
557 |
|
return -1; |
558 |
} // getComponentIndex() |
} // getComponentIndex() |
559 |
|
|
560 |
/** |
/** |
561 |
* getComponentAtIndex |
* This method returns the component at the given index. |
562 |
* @param index TODO |
* |
563 |
* @returns Component |
* @param index The index of the component. |
564 |
|
* |
565 |
|
* @return The component at the given index. |
566 |
*/ |
*/ |
567 |
public Component getComponentAtIndex(int index) { |
public Component getComponentAtIndex(int index) |
568 |
return null; // TODO |
{ |
569 |
|
return getComponent(index); |
570 |
} // getComponentAtIndex() |
} // getComponentAtIndex() |
571 |
|
|
572 |
/** |
/** |
573 |
* getMargin |
* This method returns the margin property. |
574 |
* @returns Insets |
* |
575 |
|
* @return The margin property. |
576 |
*/ |
*/ |
577 |
public Insets getMargin() { |
public Insets getMargin() |
578 |
return null; // TODO |
{ |
579 |
|
return margin; |
580 |
} // getMargin() |
} // getMargin() |
581 |
|
|
582 |
/** |
/** |
583 |
* setMargin |
* This method sets the margin property. The margin property determines the |
584 |
* @param margin TODO |
* extra space between the children components of the JToolBar and the |
585 |
|
* border. |
586 |
|
* |
587 |
|
* @param margin The margin property. |
588 |
*/ |
*/ |
589 |
public void setMargin(Insets margin) { |
public void setMargin(Insets margin) |
590 |
// TODO |
{ |
591 |
|
if ((this.margin != null && margin == null) |
592 |
|
|| (this.margin == null && margin != null) |
593 |
|
|| (margin != null && this.margin != null |
594 |
|
&& (margin.left != this.margin.left |
595 |
|
|| margin.right != this.margin.right || margin.top != this.margin.top |
596 |
|
|| margin.bottom != this.margin.bottom))) |
597 |
|
{ |
598 |
|
Insets oldMargin = this.margin; |
599 |
|
this.margin = margin; |
600 |
|
firePropertyChange(MARGIN_CHANGED_PROPERTY, oldMargin, this.margin); |
601 |
|
revalidate(); |
602 |
|
repaint(); |
603 |
|
} |
604 |
} // setMargin() |
} // setMargin() |
605 |
|
|
606 |
/** |
/** |
607 |
* isBorderPainted |
* This method returns the borderPainted property. |
608 |
* @returns boolean |
* |
609 |
|
* @return The borderPainted property. |
610 |
*/ |
*/ |
611 |
public boolean isBorderPainted() { |
public boolean isBorderPainted() |
612 |
return false; // TODO |
{ |
613 |
|
return paintBorder; |
614 |
} // isBorderPainted() |
} // isBorderPainted() |
615 |
|
|
616 |
/** |
/** |
617 |
* setBorderPainted |
* This method sets the borderPainted property. If set to false, the border |
618 |
* @param painted TODO |
* will not be painted. |
619 |
|
* |
620 |
|
* @param painted Whether the border will be painted. |
621 |
*/ |
*/ |
622 |
public void setBorderPainted(boolean painted) { |
public void setBorderPainted(boolean painted) |
623 |
// TODO |
{ |
624 |
|
if (painted != paintBorder) |
625 |
|
{ |
626 |
|
paintBorder = painted; |
627 |
|
firePropertyChange(BORDER_PAINTED_CHANGED_PROPERTY, ! paintBorder, |
628 |
|
paintBorder); |
629 |
|
repaint(); |
630 |
|
} |
631 |
} // setBorderPainted() |
} // setBorderPainted() |
632 |
|
|
633 |
/** |
/** |
634 |
* isFloatable |
* This method returns the floatable property. |
635 |
* @returns boolean |
* |
636 |
|
* @return The floatable property. |
637 |
*/ |
*/ |
638 |
public boolean isFloatable() { |
public boolean isFloatable() |
639 |
return false; // TODO |
{ |
640 |
|
return floatable; |
641 |
} // isFloatable() |
} // isFloatable() |
642 |
|
|
643 |
/** |
/** |
644 |
* setFloatable |
* This method sets the floatable property. If set to false, the JToolBar |
645 |
* @param floatable TODO |
* cannot be dragged. |
646 |
|
* |
647 |
|
* @param floatable Whether the JToolBar can be dragged. |
648 |
*/ |
*/ |
649 |
public void setFloatable(boolean floatable) { |
public void setFloatable(boolean floatable) |
650 |
// TODO |
{ |
651 |
|
if (floatable != this.floatable) |
652 |
|
{ |
653 |
|
this.floatable = floatable; |
654 |
|
firePropertyChange(FLOATABLE_CHANGED_PROPERTY, ! floatable, floatable); |
655 |
|
} |
656 |
} // setFloatable() |
} // setFloatable() |
657 |
|
|
658 |
/** |
/** |
659 |
* getOrientation |
* This method returns the orientation of the JToolBar. |
660 |
* @returns int |
* |
661 |
|
* @return The orientation of the JToolBar. |
662 |
*/ |
*/ |
663 |
public int getOrientation() { |
public int getOrientation() |
664 |
return this.orientation; |
{ |
665 |
|
return orientation; |
666 |
} // getOrientation() |
} // getOrientation() |
667 |
|
|
668 |
/** |
/** |
669 |
* setLayout |
* This method sets the layout manager to be used with the JToolBar. |
670 |
* @param mgr |
* |
671 |
|
* @param mgr The Layout Manager used with the JToolBar. |
672 |
*/ |
*/ |
673 |
public void setLayout(LayoutManager mgr) { |
public void setLayout(LayoutManager mgr) |
674 |
|
{ |
675 |
super.setLayout(mgr); |
super.setLayout(mgr); |
676 |
|
revalidate(); |
677 |
|
repaint(); |
678 |
} // setLayout() |
} // setLayout() |
679 |
|
|
680 |
/** |
/** |
681 |
* setOrientation |
* This method sets the orientation property for JToolBar. |
682 |
* @param orientation |
* |
683 |
|
* @param orientation The new orientation for JToolBar. |
684 |
|
* |
685 |
|
* @throws IllegalArgumentException If the orientation is not HORIZONTAL or |
686 |
|
* VERTICAL. |
687 |
*/ |
*/ |
688 |
public void setOrientation(int orientation) { |
public void setOrientation(int orientation) |
689 |
|
{ |
690 |
if (orientation != HORIZONTAL && orientation != VERTICAL) |
if (orientation != HORIZONTAL && orientation != VERTICAL) |
691 |
throw new IllegalArgumentException(orientation + " is not a legal orientation"); |
throw new IllegalArgumentException(orientation |
692 |
|
+ " is not a legal orientation"); |
693 |
if (orientation != this.orientation) |
if (orientation != this.orientation) |
694 |
{ |
{ |
695 |
int oldOrientation = this.orientation; |
int oldOrientation = this.orientation; |
696 |
this.orientation = orientation; |
this.orientation = orientation; |
697 |
firePropertyChange(ORIENTATION_CHANGED_PROPERTY, oldOrientation, |
firePropertyChange(ORIENTATION_CHANGED_PROPERTY, oldOrientation, |
698 |
this.orientation); |
this.orientation); |
699 |
|
revalidate(); |
700 |
|
repaint(); |
701 |
} |
} |
702 |
} // setOrientation() |
} // setOrientation() |
703 |
|
|
704 |
/** |
/** |
705 |
* addSeparator |
* This method adds a Separator of default size to the JToolBar. |
706 |
*/ |
*/ |
707 |
public void addSeparator() { |
public void addSeparator() |
708 |
// TODO |
{ |
709 |
|
add(new Separator()); |
710 |
} // addSeparator() |
} // addSeparator() |
711 |
|
|
712 |
/** |
/** |
713 |
* addSeparator |
* This method adds a Separator with the given size to the JToolBar. |
714 |
* @param size TODO |
* |
715 |
|
* @param size The size of the Separator. |
716 |
*/ |
*/ |
717 |
public void addSeparator(Dimension size) { |
public void addSeparator(Dimension size) |
718 |
// TODO |
{ |
719 |
|
add(new Separator(size)); |
720 |
} // addSeparator() |
} // addSeparator() |
721 |
|
|
722 |
/** |
/** |
723 |
* createActionComponent |
* This method is used to create JButtons which can be added to the JToolBar |
724 |
* @param action TODO |
* for the given action. |
725 |
* @returns JButton |
* |
726 |
|
* @param action The action to create a JButton for. |
727 |
|
* |
728 |
|
* @return The JButton created from the action. |
729 |
*/ |
*/ |
730 |
protected JButton createActionComponent(Action action) { |
protected JButton createActionComponent(Action action) |
731 |
return null; // TODO |
{ |
732 |
|
return new JButton(action); |
733 |
} // createActionComponent() |
} // createActionComponent() |
734 |
|
|
735 |
/** |
/** |
736 |
* createActionChangeListener |
* This method creates a pre-configured PropertyChangeListener which updates |
737 |
* @param button TODO |
* the control as changes are made to the Action. However, this is no |
738 |
* @returns PropertyChangeListener |
* longer the recommended way of adding Actions to Containers. As such, |
739 |
|
* this method returns null. |
740 |
|
* |
741 |
|
* @param button The JButton to configure a PropertyChangeListener for. |
742 |
|
* |
743 |
|
* @return null. |
744 |
*/ |
*/ |
745 |
protected PropertyChangeListener createActionChangeListener(JButton button) { |
protected PropertyChangeListener createActionChangeListener(JButton button) |
746 |
return null; // TODO |
{ |
747 |
|
// XXX: As specified, this returns null. But seems kind of strange, usually deprecated methods don't just return null, verify! |
748 |
|
return null; |
749 |
} // createActionChangeListener() |
} // createActionChangeListener() |
750 |
|
|
751 |
/** |
/** |
752 |
* addImpl |
* This method overrides Container's addImpl method. If a JButton is added, |
753 |
* @param component TODO |
* it is disabled. |
754 |
* @param constraints TODO |
* |
755 |
* @param index TODO |
* @param component The Component to add. |
756 |
*/ |
* @param constraints The Constraints placed on the component. |
757 |
/* |
* @param index The index to place the Component at. |
|
protected void addImpl(Component component, Object constraints, int index) { |
|
|
// TODO |
|
|
} // addImpl() |
|
758 |
*/ |
*/ |
759 |
|
protected void addImpl(Component component, Object constraints, int index) |
760 |
|
{ |
761 |
|
// XXX: Sun says disable button but test cases show otherwise. |
762 |
|
super.addImpl(component, constraints, index); |
763 |
|
} // addImpl() |
764 |
|
|
765 |
/** |
/** |
766 |
* paramString |
* This method returns a String description of the JToolBar. |
767 |
* @returns String |
* |
768 |
|
* @return A String description of the JToolBar. |
769 |
*/ |
*/ |
770 |
protected String paramString() { |
protected String paramString() |
771 |
return null; // TODO |
{ |
772 |
|
return "JToolBar"; |
773 |
} // paramString() |
} // paramString() |
774 |
|
|
775 |
/** |
/** |
776 |
* getAccessibleContext |
* getAccessibleContext |
777 |
|
* |
778 |
* @return AccessibleContext |
* @return AccessibleContext |
779 |
*/ |
*/ |
780 |
public AccessibleContext getAccessibleContext() |
public AccessibleContext getAccessibleContext() |