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) {
     }
   }
 }
  /**
   * 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);
    }
  }
  /**
   * 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) {
    }
  }
 @RunsInCurrentThread
 private static Pair<Container, Point> findMaximizeLocation(JInternalFrame internalFrame) {
   Container clickTarget = internalFrame.isIcon() ? internalFrame.getDesktopIcon() : internalFrame;
   Point location = maximizeLocationOf(clickTarget);
   return new Pair<Container, Point>(clickTarget, location);
 }
 @RunsInCurrentThread
 private static void validateIsShowingOrIconified(JInternalFrame internalFrame) {
   if (!internalFrame.isIcon()) validateIsShowing(internalFrame);
 }