001: package abbot.tester;
002:
003: import java.awt.*;
004: import java.beans.PropertyVetoException;
005:
006: import javax.swing.JInternalFrame;
007:
008: public class JInternalFrameTester extends JComponentTester {
009:
010: private class VetoFailure {
011: public PropertyVetoException e = null;
012: }
013:
014: /** Maximize or normalize the given frame. Iconified frames should use
015: * deiconify, not normalize.
016: */
017: protected void maximize(final JInternalFrame frame, final boolean b) {
018:
019: if (b && !frame.isMaximizable())
020: throw new ActionFailedException(
021: "The given JInternalFrame (" + toString(frame)
022: + ") is not " + "maximizable");
023: if (!b && frame.isIcon())
024: throw new ActionFailedException(
025: "The given JInternalFrame (" + toString(frame)
026: + ") is " + "iconified and must be "
027: + "deiconified before it can "
028: + "be normalized");
029:
030: Container clickTarget = frame;
031: if (frame.isIcon()) {
032: clickTarget = frame.getDesktopIcon();
033: }
034: Point p = getMaximizeLocation(clickTarget);
035: mouseMove(clickTarget, p.x, p.y);
036: if (frame.isIcon()) {
037: iconify(frame, false);
038: }
039: final VetoFailure veto = new VetoFailure();
040: invokeAndWait(new Runnable() {
041: public void run() {
042: try {
043: frame.setMaximum(b);
044: } catch (PropertyVetoException e) {
045: veto.e = e;
046: }
047: }
048: });
049: if (veto.e != null) {
050: throw new ActionFailedException("Maximize of "
051: + Robot.toString(frame) + " was vetoed (" + veto.e
052: + ")");
053: }
054: }
055:
056: public void actionMaximize(Component comp) {
057: maximize((JInternalFrame) comp, true);
058: }
059:
060: public void actionNormalize(Component comp) {
061: maximize((JInternalFrame) comp, false);
062: }
063:
064: /** Iconify/deiconify the given frame. If the frame is already in the
065: * desired state, does nothing.
066: */
067: protected void iconify(final JInternalFrame frame, final boolean b) {
068: if ((b && frame.isIcon()) || (!b && !frame.isIcon()))
069: return;
070:
071: if (b) {
072: if (!frame.isIconifiable())
073: throw new ActionFailedException(
074: "The given JInternalFrame (" + toString(frame)
075: + ") is not " + "iconifiable");
076: Point p = getIconifyLocation(frame);
077: mouseMove(frame, p.x, p.y);
078: } else {
079: Container c = frame.getDesktopIcon();
080: Point p = getIconifyLocation(c);
081: mouseMove(c, p.x, p.y);
082: }
083: final VetoFailure veto = new VetoFailure();
084: invokeAndWait(new Runnable() {
085: public void run() {
086: try {
087: frame.setIcon(b);
088: } catch (PropertyVetoException e) {
089: veto.e = e;
090: }
091: }
092: });
093: if (veto.e != null) {
094: throw new ActionFailedException("Iconify of "
095: + Robot.toString(frame) + " was vetoed (" + veto.e
096: + ")");
097: }
098: }
099:
100: /** Iconify the given Frame. */
101: public void actionIconify(Component comp) {
102: iconify((JInternalFrame) comp, true);
103: }
104:
105: /** Deiconify the given Frame. */
106: public void actionDeiconify(Component comp) {
107: iconify((JInternalFrame) comp, false);
108: }
109:
110: /** Move the given internal frame. */
111: public void actionMove(Component comp, int x, int y) {
112: move((JInternalFrame) comp, x, y);
113: waitForIdle();
114: }
115:
116: /** Resize the given internal frame. */
117: public void actionResize(Component comp, int width, int height) {
118: resize((JInternalFrame) comp, width, height);
119: waitForIdle();
120: }
121:
122: /** Close the internal frame. */
123: public void actionClose(Component comp) {
124: // This is LAF-specific, so it must be done programmatically.
125: final JInternalFrame frame = (JInternalFrame) comp;
126: if (!frame.isClosable())
127: throw new ActionFailedException(
128: "The given JInternalFrame (" + toString(frame)
129: + ") is not " + "closable");
130: Point p = getCloseLocation(frame);
131: mouseMove(frame, p.x, p.y);
132: /*
133: final InternalFrameEvent ife =
134: new InternalFrameEvent(frame, InternalFrameEvent.
135: INTERNAL_FRAME_CLOSING);
136: */
137: // cf. BasicInternalFrameTitlePane#postClosingEvent handling of
138: // close
139: // Seems to be a bug in the handling of internal frame events; they're
140: // not normally posted to the AWT event queue.
141: invokeAndWait(new Runnable() {
142: public void run() {
143: frame.doDefaultCloseAction();
144: }
145: });
146: }
147: }
|