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) {
     }
   }
 }
 @RunsInCurrentThread
 private static @Nonnull Pair<Container, Point> findMaximizeLocation(
     @Nonnull JInternalFrame internalFrame) {
   Container clickTarget = internalFrame.isIcon() ? internalFrame.getDesktopIcon() : internalFrame;
   Point location = maximizeButtonLocation(checkNotNull(clickTarget));
   return Pair.of(clickTarget, location);
 }
  public void activateFrame(JInternalFrame f) {
    JInternalFrame currentFrame = currentFrameRef != null ? currentFrameRef.get() : null;
    try {
      super.activateFrame(f);
      if (currentFrame != null && f != currentFrame) {
        // If the current frame is maximized, transfer that
        // attribute to the frame being activated.
        if (currentFrame.isMaximum()
            && (f.getClientProperty("JInternalFrame.frameType") != "optionDialog")) {
          // Special case.  If key binding was used to select next
          // frame instead of minimizing the icon via the minimize
          // icon.
          if (!currentFrame.isIcon()) {
            currentFrame.setMaximum(false);
            if (f.isMaximizable()) {
              if (!f.isMaximum()) {
                f.setMaximum(true);
              } else if (f.isMaximum() && f.isIcon()) {
                f.setIcon(false);
              } else {
                f.setMaximum(false);
              }
            }
          }
        }
        if (currentFrame.isSelected()) {
          currentFrame.setSelected(false);
        }
      }

      if (!f.isSelected()) {
        f.setSelected(true);
      }
    } catch (PropertyVetoException e) {
    }
    if (f != currentFrame) {
      currentFrameRef = new WeakReference(f);
    }
  }
 @RunsInCurrentThread
 private static void checkShowingOrIconified(@Nonnull JInternalFrame internalFrame) {
   if (!internalFrame.isIcon()) {
     checkShowing(internalFrame);
   }
 }
 @RunsInEDT
 private static boolean isIcon(final JInternalFrame internalFrame) {
   return execute(() -> internalFrame.isIcon() && !internalFrame.isMaximum());
 }
 @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);
 }