コード例 #1
0
 /**
  * Removes the frame, and, if necessary, the <code>desktopIcon</code>, from its parent.
  *
  * @param f the <code>JInternalFrame</code> to be removed
  */
 public void closeFrame(JInternalFrame f) {
   JDesktopPane d = f.getDesktopPane();
   if (d == null) {
     return;
   }
   boolean findNext = f.isSelected();
   Container c = f.getParent();
   JInternalFrame nextFrame = null;
   if (findNext) {
     nextFrame = d.getNextFrame(f);
     try {
       f.setSelected(false);
     } catch (PropertyVetoException e2) {
     }
   }
   if (c != null) {
     c.remove(f); // Removes the focus.
     c.repaint(f.getX(), f.getY(), f.getWidth(), f.getHeight());
   }
   removeIconFor(f);
   if (f.getNormalBounds() != null) f.setNormalBounds(null);
   if (wasIcon(f)) setWasIcon(f, null);
   if (nextFrame != null) {
     try {
       nextFrame.setSelected(true);
     } catch (PropertyVetoException e2) {
     }
   } else if (findNext && d.getComponentCount() == 0) {
     // It was selected and was the last component on the desktop.
     d.requestFocus();
   }
 }
コード例 #2
0
 /**
  * Removes the desktopIcon from its parent and adds its frame to the parent.
  *
  * @param f the <code>JInternalFrame</code> to be de-iconified
  */
 public void deiconifyFrame(JInternalFrame f) {
   JInternalFrame.JDesktopIcon desktopIcon = f.getDesktopIcon();
   Container c = desktopIcon.getParent();
   JDesktopPane d = f.getDesktopPane();
   if (c != null && d != null) {
     c.add(f);
     // If the frame is to be restored to a maximized state make
     // sure it still fills the whole desktop.
     if (f.isMaximum()) {
       Rectangle desktopBounds = c.getBounds();
       if (f.getWidth() != desktopBounds.width || f.getHeight() != desktopBounds.height) {
         setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
       }
     }
     removeIconFor(f);
     if (f.isSelected()) {
       f.moveToFront();
       f.restoreSubcomponentFocus();
     } else {
       try {
         f.setSelected(true);
       } catch (PropertyVetoException e2) {
       }
     }
   }
 }
コード例 #3
0
 /**
  * This will activate <b>f</b> moving it to the front. It will set the current active frame's (if
  * any) <code>IS_SELECTED_PROPERTY</code> to <code>false</code>. There can be only one active
  * frame across all Layers.
  *
  * @param f the <code>JInternalFrame</code> to be activated
  */
 public void activateFrame(JInternalFrame f) {
   Container p = f.getParent();
   Component[] c;
   JDesktopPane d = f.getDesktopPane();
   JInternalFrame currentlyActiveFrame = (d == null) ? null : d.getSelectedFrame();
   // fix for bug: 4162443
   if (p == null) {
     // If the frame is not in parent, its icon maybe, check it
     p = f.getDesktopIcon().getParent();
     if (p == null) return;
   }
   // we only need to keep track of the currentActive InternalFrame, if any
   if (currentlyActiveFrame == null) {
     if (d != null) {
       d.setSelectedFrame(f);
     }
   } else if (currentlyActiveFrame != f) {
     // if not the same frame as the current active
     // we deactivate the current
     if (currentlyActiveFrame.isSelected()) {
       try {
         currentlyActiveFrame.setSelected(false);
       } catch (PropertyVetoException e2) {
       }
     }
     if (d != null) {
       d.setSelectedFrame(f);
     }
   }
   f.moveToFront();
 }
コード例 #4
0
  public Component add(JInternalFrame frame) {
    JInternalFrame[] array = getAllFrames();
    Point p;
    int w;
    int h;

    Component retval = super.add(frame);
    checkDesktopSize();
    if (array.length > 0) {
      p = array[0].getLocation();
      p.x = p.x + FRAME_OFFSET;
      p.y = p.y + FRAME_OFFSET;
    } else {
      p = new Point(0, 0);
    }
    frame.setLocation(p.x, p.y);
    /* Jimmy: this is a bit buggy (frames get constant size)
    if (frame.isResizable()) {
        w = getWidth() - (getWidth()/3);
        h = getHeight() - (getHeight()/3);
        if (w < frame.getMinimumSize().getWidth()) w = (int)frame.getMinimumSize().getWidth();
        if (h < frame.getMinimumSize().getHeight()) h = (int)frame.getMinimumSize().getHeight();
        frame.setSize(w, h);
    }*/
    moveToFront(frame);
    frame.setVisible(true);
    try {
      frame.setSelected(true);
    } catch (PropertyVetoException e) {
      frame.toBack();
    }
    return retval;
  }
コード例 #5
0
 public void openInBox() {
   JInternalFrame doc = new MetalworksInBox();
   desktop.add(doc, DOCLAYER);
   try {
     doc.setVisible(true);
     doc.setSelected(true);
   } catch (java.beans.PropertyVetoException e2) {
   }
 }
コード例 #6
0
 public void openHelpWindow() {
   JInternalFrame help = new MetalworksHelp();
   desktop.add(help, HELPLAYER);
   try {
     help.setVisible(true);
     help.setSelected(true);
   } catch (java.beans.PropertyVetoException e2) {
   }
 }
コード例 #7
0
 private void setState(JDesktopPane dp, String state) {
   if (state == CLOSE) {
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     f.doDefaultCloseAction();
   } else if (state == MAXIMIZE) {
     // maximize the selected frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     if (!f.isMaximum()) {
       if (f.isIcon()) {
         try {
           f.setIcon(false);
           f.setMaximum(true);
         } catch (PropertyVetoException pve) {
         }
       } else {
         try {
           f.setMaximum(true);
         } catch (PropertyVetoException pve) {
         }
       }
     }
   } else if (state == MINIMIZE) {
     // minimize the selected frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     if (!f.isIcon()) {
       try {
         f.setIcon(true);
       } catch (PropertyVetoException pve) {
       }
     }
   } else if (state == RESTORE) {
     // restore the selected minimized or maximized frame
     JInternalFrame f = dp.getSelectedFrame();
     if (f == null) {
       return;
     }
     try {
       if (f.isIcon()) {
         f.setIcon(false);
       } else if (f.isMaximum()) {
         f.setMaximum(false);
       }
       f.setSelected(true);
     } catch (PropertyVetoException pve) {
     }
   }
 }
コード例 #8
0
 // Aqui no creo que deba ir un TaskFrame por si se quiere activar otro tipo de JinternalFrame
 public void activateFrame(JInternalFrame frame) {
   frame.moveToFront();
   frame.requestFocus();
   try {
     frame.setSelected(true);
     if (!(frame instanceof TaskFrame)) {
       frame.setMaximum(false);
     }
   } catch (PropertyVetoException e) {
     warnUser(StringUtil.stackTrace(e));
   }
 }
コード例 #9
0
 public void testPlaysEvent() throws Exception {
   Mock mockComponentFinder = mock(ComponentFinder.class);
   JInternalFrame internalFrame = createInternalFrame();
   mockComponentFinder
       .expects(once())
       .method("findInternalFrame")
       .will(returnValue(internalFrame));
   internalFrame.setSelected(false);
   new CloseInternalFrameEvent("title")
       .play(null, (ComponentFinder) mockComponentFinder.proxy(), null, null);
   assertTrue(internalFrame.isClosed());
 }
コード例 #10
0
  /**
   * maximizes the internal frame to the viewport bounds rather than the desktop bounds
   *
   * @param f the internal frame being maximized
   */
  public void maximizeFrame(JInternalFrame f) {

    Rectangle p = desktopPane.getScrollPaneRectangle();
    f.setNormalBounds(f.getBounds());
    setBoundsForFrame(f, p.x, p.y, p.width, p.height);
    try {
      f.setSelected(true);
    } catch (PropertyVetoException pve) {
      System.out.println(pve.getMessage());
    }

    removeIconFor(f);
  }
コード例 #11
0
  /**
   * Restores the frame back to its size and position prior to a <code>maximizeFrame</code> call.
   *
   * @param f the <code>JInternalFrame</code> to be restored
   */
  public void minimizeFrame(JInternalFrame f) {
    // If the frame was an icon restore it back to an icon.
    if (f.isIcon()) {
      iconifyFrame(f);
      return;
    }

    if ((f.getNormalBounds()) != null) {
      Rectangle r = f.getNormalBounds();
      f.setNormalBounds(null);
      try {
        f.setSelected(true);
      } catch (PropertyVetoException e2) {
      }
      setBoundsForFrame(f, r.x, r.y, r.width, r.height);
    }
  }
コード例 #12
0
  /**
   * Resizes the frame to fill its parents bounds.
   *
   * @param f the frame to be resized
   */
  public void maximizeFrame(JInternalFrame f) {
    if (f.isIcon()) {
      try {
        // In turn calls deiconifyFrame in the desktop manager.
        // That method will handle the maximization of the frame.
        f.setIcon(false);
      } catch (PropertyVetoException e2) {
      }
    } else {
      f.setNormalBounds(f.getBounds());
      Rectangle desktopBounds = f.getParent().getBounds();
      setBoundsForFrame(f, 0, 0, desktopBounds.width, desktopBounds.height);
    }

    // Set the maximized frame as selected.
    try {
      f.setSelected(true);
    } catch (PropertyVetoException e2) {
    }
  }