/*
   * (non-Javadoc)
   *
   * @see
   * org.jvnet.flamingo.common.ui.BasicCommandButtonUI#getPreferredSize(javax
   * .swing.JComponent)
   */
  @Override
  public Dimension getPreferredSize(JComponent c) {
    AbstractCommandButton button = (AbstractCommandButton) c;
    SubstanceButtonShaper shaper = SubstanceCoreUtilities.getButtonShaper(button);

    Dimension superPref = super.getPreferredSize(button);
    if (superPref == null) return null;

    if (shaper == null) return superPref;

    // fix for issue 35 on Flamingo - do not enforce
    // min size on buttons in the ribbon
    // Additional fix - buttons with popup action should
    // not have min size enforced as well
    // Additional fix - buttons in popup menus and breadcrumb bars should
    // not have min size enforced
    if ((button.getDisplayState() == CommandButtonDisplayState.MEDIUM)
        && (SwingUtilities.getAncestorOfClass(AbstractRibbonBand.class, button) == null)
        && (SwingUtilities.getAncestorOfClass(JBreadcrumbBar.class, button) == null)
        && (SwingUtilities.getAncestorOfClass(JCommandPopupMenu.class, button) == null)) {
      JButton dummy = new JButton(button.getText(), button.getIcon());
      Dimension result = shaper.getPreferredSize(dummy, superPref);
      if (FlamingoUtilities.hasPopupAction(button)) {
        result.width = superPref.width;
      }
      return result;
    }
    return superPref;
  }
Ejemplo n.º 2
0
 protected void uninstallListeners(JFileChooser fc) {
   if (propertyChangeListener != null) {
     fc.removePropertyChangeListener(propertyChangeListener);
   }
   fc.removePropertyChangeListener(getModel());
   SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   SwingUtilities.replaceUIActionMap(fc, null);
 }
Ejemplo n.º 3
0
  protected void installListeners(JFileChooser fc) {
    propertyChangeListener = createPropertyChangeListener(fc);
    if (propertyChangeListener != null) {
      fc.addPropertyChangeListener(propertyChangeListener);
    }
    fc.addPropertyChangeListener(getModel());

    InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    SwingUtilities.replaceUIInputMap(fc, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
    ActionMap actionMap = getActionMap();
    SwingUtilities.replaceUIActionMap(fc, actionMap);
  }
    private void setDispatchComponent(MouseEvent e) {
      // Get location
      Point spreadPoint = e.getPoint();
      int row = grid.rowAtPoint(spreadPoint);
      int column = grid.columnAtPoint(spreadPoint);

      // Get editor component
      Component editorComponent = grid.getEditorComponent();

      // Get dispatchComponent
      Point editorPoint = SwingUtilities.convertPoint(grid, spreadPoint, editorComponent);
      dispatchComponent =
          SwingUtilities.getDeepestComponentAt(editorComponent, editorPoint.x, editorPoint.y);
    }
  protected void installKeyboardActions() {
    InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    if (inputMap != null) {
      SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_IN_FOCUSED_WINDOW, inputMap);
    }
    inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    if (inputMap != null) {
      SwingUtilities.replaceUIInputMap(
          desktop, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
    }

    LazyActionMap.installLazyActionMap(desktop, BasicDesktopPaneUI.class, "DesktopPane.actionMap");
    registerKeyboardActions();
  }
Ejemplo n.º 6
0
    public void mouseClicked(MouseEvent ev) {
      Window w = (Window) ev.getSource();
      Frame f = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else {
        return;
      }

      Point convertedPoint = SwingUtilities.convertPoint(w, ev.getPoint(), getTitlePane());

      int state = f.getExtendedState();
      if (getTitlePane() != null && getTitlePane().contains(convertedPoint)) {
        if ((ev.getClickCount() % 2) == 0 && ((ev.getModifiers() & InputEvent.BUTTON1_MASK) != 0)) {
          if (f.isResizable()) {
            if ((state & Frame.MAXIMIZED_BOTH) != 0) {
              f.setExtendedState(state & ~Frame.MAXIMIZED_BOTH);
            } else {
              f.setExtendedState(state | Frame.MAXIMIZED_BOTH);
            }
            return;
          }
        }
      }
    }
 /** Updates the UI of the passed in window and all its children. */
 private static void updateWindowUI(Window window) {
   SwingUtilities.updateComponentTreeUI(window);
   Window ownedWins[] = window.getOwnedWindows();
   for (int i = 0; i < ownedWins.length; i++) {
     updateWindowUI(ownedWins[i]);
   }
 }
Ejemplo n.º 8
0
 /**
  * Gets the value of the <code>defaultButton</code> property, which if <code>true</code> means
  * that this button is the current default button for its <code>JRootPane</code>. Most look and
  * feels render the default button differently, and may potentially provide bindings to access the
  * default button.
  *
  * @return the value of the <code>defaultButton</code> property
  * @see JRootPane#setDefaultButton
  * @see #isDefaultCapable
  * @beaninfo description: Whether or not this button is the default button
  */
 public boolean isDefaultButton() {
   JRootPane root = SwingUtilities.getRootPane(this);
   if (root != null) {
     return root.getDefaultButton() == this;
   }
   return false;
 }
Ejemplo n.º 9
0
 /**
  * Overrides <code>JComponent.removeNotify</code> to check if this button is currently set as the
  * default button on the <code>RootPane</code>, and if so, sets the <code>RootPane</code>'s
  * default button to <code>null</code> to ensure the <code>RootPane</code> doesn't hold onto an
  * invalid button reference.
  */
 public void removeNotify() {
   JRootPane root = SwingUtilities.getRootPane(this);
   if (root != null && root.getDefaultButton() == this) {
     root.setDefaultButton(null);
   }
   super.removeNotify();
 }
 /* Repost event to dispatchComponent */
 private boolean repostEvent(MouseEvent e) {
   if (dispatchComponent == null) {
     return false;
   }
   MouseEvent editorMouseEvent = SwingUtilities.convertMouseEvent(grid, e, dispatchComponent);
   dispatchComponent.dispatchEvent(editorMouseEvent);
   return true;
 }
  private boolean sizeChanged() {
    if ((oldComponentInnards == null) || (componentInnards == null)) {
      return true;
    }

    oldComponentInnards.setRect(componentInnards);
    componentInnards = SwingUtilities.calculateInnerArea(progressBar, componentInnards);
    return !oldComponentInnards.equals(componentInnards);
  }
 protected void installKeyboardActions() {
   super.installKeyboardActions();
   ActionMap map = SwingUtilities.getUIActionMap(getComponent());
   if (map != null && map.get(DefaultEditorKit.selectWordAction) != null) {
     Action a = map.get(DefaultEditorKit.selectLineAction);
     if (a != null) {
       map.put(DefaultEditorKit.selectWordAction, a);
     }
   }
 }
 /**
  * Requests that all components in the GUI hierarchy be updated to reflect dynamic changes in this
  * look&feel. This update occurs by uninstalling and re-installing the UI objects. Requests are
  * batched and collapsed into a single update pass because often many desktop properties will
  * change at once.
  */
 protected void updateUI() {
   if (!isUpdatePending()) {
     setUpdatePending(true);
     Runnable uiUpdater =
         new Runnable() {
           public void run() {
             updateAllUIs();
             setUpdatePending(false);
           }
         };
     SwingUtilities.invokeLater(uiUpdater);
   }
 }
Ejemplo n.º 14
0
  /**
   * {@inheritDoc}
   *
   * @since 1.7
   */
  public boolean imageUpdate(Image img, int infoflags, int x, int y, int w, int h) {
    if (!isShowing()) {
      return false;
    }

    // Check that there is a label with such image
    Enumeration elements = labelTable.elements();

    while (elements.hasMoreElements()) {
      Component component = (Component) elements.nextElement();

      if (component instanceof JLabel) {
        JLabel label = (JLabel) component;

        if (SwingUtilities.doesIconReferenceImage(label.getIcon(), img)
            || SwingUtilities.doesIconReferenceImage(label.getDisabledIcon(), img)) {
          return super.imageUpdate(img, infoflags, x, y, w, h);
        }
      }
    }

    return false;
  }
Ejemplo n.º 15
0
 /**
  * Installs the necessary Listeners on the parent <code>Window</code>, if there is one.
  *
  * <p>This takes the parent so that cleanup can be done from <code>removeNotify</code>, at which
  * point the parent hasn't been reset yet.
  *
  * @param parent The parent of the JRootPane
  */
 private void installWindowListeners(JRootPane root, Component parent) {
   if (parent instanceof Window) {
     window = (Window) parent;
   } else {
     window = SwingUtilities.getWindowAncestor(parent);
   }
   if (window != null) {
     if (mouseInputListener == null) {
       mouseInputListener = createWindowMouseInputListener(root);
     }
     window.addMouseListener(mouseInputListener);
     window.addMouseMotionListener(mouseInputListener);
   }
 }
Ejemplo n.º 16
0
    public void paintBorder(Component c, Graphics g, int x, int y, int w, int h) {

      Color background;
      Color highlight;
      Color shadow;

      Window window = SwingUtilities.getWindowAncestor(c);
      if (window != null && window.isActive()) {
        background = MetalLookAndFeel.getPrimaryControlDarkShadow();
        highlight = MetalLookAndFeel.getPrimaryControlShadow();
        shadow = MetalLookAndFeel.getPrimaryControlInfo();
      } else {
        background = MetalLookAndFeel.getControlDarkShadow();
        highlight = MetalLookAndFeel.getControlShadow();
        shadow = MetalLookAndFeel.getControlInfo();
      }

      g.setColor(background);
      // Draw outermost lines
      g.drawLine(x + 1, y + 0, x + w - 2, y + 0);
      g.drawLine(x + 0, y + 1, x + 0, y + h - 2);
      g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 2);
      g.drawLine(x + 1, y + h - 1, x + w - 2, y + h - 1);

      // Draw the bulk of the border
      for (int i = 1; i < 5; i++) {
        g.drawRect(x + i, y + i, w - (i * 2) - 1, h - (i * 2) - 1);
      }

      if ((window instanceof Frame) && ((Frame) window).isResizable()) {
        g.setColor(highlight);
        // Draw the Long highlight lines
        g.drawLine(corner + 1, 3, w - corner, 3);
        g.drawLine(3, corner + 1, 3, h - corner);
        g.drawLine(w - 2, corner + 1, w - 2, h - corner);
        g.drawLine(corner + 1, h - 2, w - corner, h - 2);

        g.setColor(shadow);
        // Draw the Long shadow lines
        g.drawLine(corner, 2, w - corner - 1, 2);
        g.drawLine(2, corner, 2, h - corner - 1);
        g.drawLine(w - 3, corner, w - 3, h - corner - 1);
        g.drawLine(corner, h - 3, w - corner - 1, h - 3);
      }
    }
Ejemplo n.º 17
0
 private static void repaintMnemonics(@NotNull Component focusOwner, boolean pressed) {
   if (pressed != myAltPressed) return;
   Window window = SwingUtilities.windowForComponent(focusOwner);
   if (window != null) {
     for (Component component : window.getComponents()) {
       if (component instanceof JComponent) {
         for (JComponent c :
             UIUtil.findComponentsOfType((JComponent) component, JComponent.class)) {
           if ((c instanceof JLabel && ((JLabel) c).getDisplayedMnemonicIndex() != -1)
               || (c instanceof AbstractButton
                   && ((AbstractButton) c).getDisplayedMnemonicIndex() != -1)) {
             c.repaint();
           }
         }
       }
     }
   }
 }
Ejemplo n.º 18
0
  public void installUI(JComponent c) {
    super.installUI(c);
    arrowIcon =
        new MotifComboBoxArrowIcon(
            UIManager.getColor("controlHighlight"),
            UIManager.getColor("controlShadow"),
            UIManager.getColor("control"));

    Runnable initCode =
        new Runnable() {
          public void run() {
            if (motifGetEditor() != null) {
              motifGetEditor().setBackground(UIManager.getColor("text"));
            }
          }
        };

    SwingUtilities.invokeLater(initCode);
  }
Ejemplo n.º 19
0
    public void mousePressed(MouseEvent ev) {
      JRootPane rootPane = getRootPane();

      if (rootPane.getWindowDecorationStyle() == JRootPane.NONE) {
        return;
      }
      Point dragWindowOffset = ev.getPoint();
      Window w = (Window) ev.getSource();
      if (w != null) {
        w.toFront();
      }
      Point convertedDragWindowOffset =
          SwingUtilities.convertPoint(w, dragWindowOffset, getTitlePane());

      Frame f = null;
      Dialog d = null;

      if (w instanceof Frame) {
        f = (Frame) w;
      } else if (w instanceof Dialog) {
        d = (Dialog) w;
      }

      int frameState = (f != null) ? f.getExtendedState() : 0;

      if (getTitlePane() != null && getTitlePane().contains(convertedDragWindowOffset)) {
        if ((f != null && ((frameState & Frame.MAXIMIZED_BOTH) == 0) || (d != null))
            && dragWindowOffset.y >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x >= BORDER_DRAG_THICKNESS
            && dragWindowOffset.x < w.getWidth() - BORDER_DRAG_THICKNESS) {
          isMovingWindow = true;
          dragOffsetX = dragWindowOffset.x;
          dragOffsetY = dragWindowOffset.y;
        }
      } else if (f != null && f.isResizable() && ((frameState & Frame.MAXIMIZED_BOTH) == 0)
          || (d != null && d.isResizable())) {
        dragOffsetX = dragWindowOffset.x;
        dragOffsetY = dragWindowOffset.y;
        dragWidth = w.getWidth();
        dragHeight = w.getHeight();
        dragCursor = getCursor(calculateCorner(w, dragWindowOffset.x, dragWindowOffset.y));
      }
    }
 /**
  * Forwards the call to SwingUtilities.layoutCompoundLabel(). This method is here so that a
  * subclass could do Label specific layout and to shorten the method name a little.
  *
  * @see SwingUtilities#layoutCompoundLabel
  */
 protected String layoutCL(
     AbstractButton c,
     FontMetrics fontMetrics,
     String text,
     Icon icon,
     Rectangle viewR,
     Rectangle iconR,
     Rectangle textR) {
   return SwingUtilities.layoutCompoundLabel(
       c,
       fontMetrics,
       text,
       icon,
       c.getVerticalAlignment(),
       c.getHorizontalAlignment(),
       c.getVerticalTextPosition(),
       c.getHorizontalTextPosition(),
       viewR,
       iconR,
       textR,
       Methods.invokeGetter(c, "getIconTextGap", 4));
 }
    /**
     * Adds the range to be damaged into the range queue. If the range queue is empty (the first
     * call or run() was already invoked) then adds this class instance into EventDispatch queue.
     *
     * <p>The method also tracks if the current document changed or component is null. In this case
     * it removes all ranges added before from range queue.
     */
    public synchronized void damageRange(Position pos0, Position pos1) {
      if (component == null) {
        p0.clear();
        lastDoc = null;
        return;
      }

      boolean addToQueue = p0.isEmpty();
      Document curDoc = component.getDocument();
      if (curDoc != lastDoc) {
        if (!p0.isEmpty()) {
          p0.clear();
          p1.clear();
        }
        lastDoc = curDoc;
      }
      p0.add(pos0);
      p1.add(pos1);

      if (addToQueue) {
        SwingUtilities.invokeLater(this);
      }
    }
Ejemplo n.º 22
0
    public void mouseClicked(MouseEvent evt) {
      // Note: we can't depend on evt.getSource() because of backward
      // compatability
      if (list != null && SwingUtilities.isLeftMouseButton(evt) && (evt.getClickCount() % 2 == 0)) {

        int index = SwingUtilities2.loc2IndexFileList(list, evt.getPoint());
        if (index >= 0) {
          File f = (File) list.getModel().getElementAt(index);
          try {
            // Strip trailing ".."
            f = ShellFolder.getNormalizedFile(f);
          } catch (IOException ex) {
            // That's ok, we'll use f as is
          }
          if (getFileChooser().isTraversable(f)) {
            list.clearSelection();
            changeDirectory(f);
          } else {
            getFileChooser().approveSelection();
          }
        }
      }
    }
  public static Dimension getPreferredSize(AbstractButton b) {
    String style = (String) b.getClientProperty("Quaqua.Button.style");
    if (style == null) {
      style = "push";
    }
    if (style.equals("help")) {
      Icon helpIcon = UIManager.getIcon("Button.helpIcon");
      Insets insets = b.getInsets();

      return new Dimension(
          helpIcon.getIconWidth() + insets.left + insets.right,
          helpIcon.getIconHeight() + insets.top + insets.bottom);
    }
    if (b.getComponentCount() > 0) {
      return null;
    }

    int textIconGap = Methods.invokeGetter(b, "getIconTextGap", 4);
    Icon icon = (Icon) b.getIcon();
    String text = b.getText();

    Font font = b.getFont();
    FontMetrics fm = b.getFontMetrics(font);

    viewR.x = viewR.y = 0;
    viewR.width = Short.MAX_VALUE;
    viewR.height = Short.MAX_VALUE;
    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    SwingUtilities.layoutCompoundLabel(
        (JComponent) b,
        fm,
        text,
        icon,
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewR,
        iconR,
        textR,
        (text == null ? 0 : textIconGap));

    /* The preferred size of the button is the size of
     * the text and icon rectangles plus the buttons insets.
     */

    Rectangle r = iconR.union(textR);

    // if (b.isBorderPainted()) {
    Insets insets = b.getInsets();
    r.width += insets.left + insets.right;
    r.height += insets.top + insets.bottom;
    // }
    if (!QuaquaUtilities.isSmallSizeVariant(b)
        && style.equals("push")
        && b.getIcon() == null
        && b.getText() != null) {
      r.width = Math.max(r.width, UIManager.getInt("Button.minimumWidth"));
    }
    return r.getSize();
  }
  @Override
  protected void paintText(
      Graphics g,
      int tabPlacement,
      Font font,
      FontMetrics metrics,
      int tabIndex,
      String title,
      Rectangle textRect,
      boolean isSelected) {
    g.setFont(font);

    int titleWidth = SwingUtilities.computeStringWidth(metrics, title);

    int preferredWidth = 0;
    if (isOneActionButtonEnabled()) {
      preferredWidth = calculateTabWidth(tabPlacement, tabIndex, metrics) - WIDTHDELTA - 15;

      if (isCloseEnabled()) preferredWidth -= BUTTONSIZE;

      if (isMaxEnabled()) preferredWidth -= BUTTONSIZE;
    } else {
      preferredWidth = titleWidth;
    }

    while (titleWidth > preferredWidth) {
      if (title.endsWith("...")) title = title.substring(0, title.indexOf("...") - 1).concat("...");
      else title = title.substring(0, title.length() - 4).concat("...");

      titleWidth = SwingUtilities.computeStringWidth(metrics, title);
    }

    textRect.width = titleWidth;

    View v = getTextViewForTab(tabIndex);
    if (v != null) {
      // html
      v.paint(g, textRect);
    } else {
      // plain text
      int mnemIndex = tabPane.getDisplayedMnemonicIndexAt(tabIndex);

      if (tabPane.isEnabled() && tabPane.isEnabledAt(tabIndex)) {
        if (isSelected) g.setColor(TAB_SELECTED_FOREGROUND_COLOR);
        else {
          if (this.isTabHighlighted(tabIndex)) {
            g.setColor(TAB_HIGHLIGHT_FOREGROUND_COLOR);
          } else g.setColor(tabPane.getForegroundAt(tabIndex));
        }

        BasicGraphicsUtils.drawString(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());
      } else { // tab disabled
        g.setColor(tabPane.getBackgroundAt(tabIndex).brighter());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x, textRect.y + metrics.getAscent());

        g.setColor(tabPane.getBackgroundAt(tabIndex).darker());
        BasicGraphicsUtils.drawStringUnderlineCharAt(
            g, title, mnemIndex, textRect.x - 1, textRect.y + metrics.getAscent() - 1);
      }
    }
  }
 private boolean shouldIgnore(MouseEvent e) {
   return e.isConsumed() || (!(SwingUtilities.isLeftMouseButton(e) && grid.isEnabled()));
 }
 protected void uninstallKeyboardActions() {
   unregisterKeyboardActions();
   SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_IN_FOCUSED_WINDOW, null);
   SwingUtilities.replaceUIInputMap(desktop, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, null);
   SwingUtilities.replaceUIActionMap(desktop, null);
 }
    public void actionPerformed(ActionEvent e) {
      JDesktopPane dp = (JDesktopPane) e.getSource();
      String key = getName();

      if (CLOSE == key || MAXIMIZE == key || MINIMIZE == key || RESTORE == key) {
        setState(dp, key);
      } else if (ESCAPE == key) {
        if (sourceFrame == dp.getSelectedFrame() && focusOwner != null) {
          focusOwner.requestFocus();
        }
        moving = false;
        resizing = false;
        sourceFrame = null;
        focusOwner = null;
      } else if (MOVE == key || RESIZE == key) {
        sourceFrame = dp.getSelectedFrame();
        if (sourceFrame == null) {
          return;
        }
        moving = (key == MOVE) ? true : false;
        resizing = (key == RESIZE) ? true : false;

        focusOwner = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        if (!SwingUtilities.isDescendingFrom(focusOwner, sourceFrame)) {
          focusOwner = null;
        }
        sourceFrame.requestFocus();
      } else if (LEFT == key
          || RIGHT == key
          || UP == key
          || DOWN == key
          || SHRINK_RIGHT == key
          || SHRINK_LEFT == key
          || SHRINK_UP == key
          || SHRINK_DOWN == key) {
        JInternalFrame c = dp.getSelectedFrame();
        if (sourceFrame == null
            || c != sourceFrame
            || KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner()
                != sourceFrame) {
          return;
        }
        Insets minOnScreenInsets = UIManager.getInsets("Desktop.minOnScreenInsets");
        Dimension size = c.getSize();
        Dimension minSize = c.getMinimumSize();
        int dpWidth = dp.getWidth();
        int dpHeight = dp.getHeight();
        int delta;
        Point loc = c.getLocation();
        if (LEFT == key) {
          if (moving) {
            c.setLocation(
                loc.x + size.width - MOVE_RESIZE_INCREMENT < minOnScreenInsets.right
                    ? -size.width + minOnScreenInsets.right
                    : loc.x - MOVE_RESIZE_INCREMENT,
                loc.y);
          } else if (resizing) {
            c.setLocation(loc.x - MOVE_RESIZE_INCREMENT, loc.y);
            c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height);
          }
        } else if (RIGHT == key) {
          if (moving) {
            c.setLocation(
                loc.x + MOVE_RESIZE_INCREMENT > dpWidth - minOnScreenInsets.left
                    ? dpWidth - minOnScreenInsets.left
                    : loc.x + MOVE_RESIZE_INCREMENT,
                loc.y);
          } else if (resizing) {
            c.setSize(size.width + MOVE_RESIZE_INCREMENT, size.height);
          }
        } else if (UP == key) {
          if (moving) {
            c.setLocation(
                loc.x,
                loc.y + size.height - MOVE_RESIZE_INCREMENT < minOnScreenInsets.bottom
                    ? -size.height + minOnScreenInsets.bottom
                    : loc.y - MOVE_RESIZE_INCREMENT);
          } else if (resizing) {
            c.setLocation(loc.x, loc.y - MOVE_RESIZE_INCREMENT);
            c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT);
          }
        } else if (DOWN == key) {
          if (moving) {
            c.setLocation(
                loc.x,
                loc.y + MOVE_RESIZE_INCREMENT > dpHeight - minOnScreenInsets.top
                    ? dpHeight - minOnScreenInsets.top
                    : loc.y + MOVE_RESIZE_INCREMENT);
          } else if (resizing) {
            c.setSize(size.width, size.height + MOVE_RESIZE_INCREMENT);
          }
        } else if (SHRINK_LEFT == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.width - minSize.width;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.x + size.width - delta < minOnScreenInsets.left) {
            delta = loc.x + size.width - minOnScreenInsets.left;
          }
          c.setSize(size.width - delta, size.height);
        } else if (SHRINK_RIGHT == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.width < (size.width - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.width - minSize.width;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.x + delta > dpWidth - minOnScreenInsets.right) {
            delta = (dpWidth - minOnScreenInsets.right) - loc.x;
          }

          c.setLocation(loc.x + delta, loc.y);
          c.setSize(size.width - delta, size.height);
        } else if (SHRINK_UP == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.height - minSize.height;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.y + size.height - delta < minOnScreenInsets.bottom) {
            delta = loc.y + size.height - minOnScreenInsets.bottom;
          }

          c.setSize(size.width, size.height - delta);
        } else if (SHRINK_DOWN == key && resizing) {
          // Make sure we don't resize less than minimum size.
          if (minSize.height < (size.height - MOVE_RESIZE_INCREMENT)) {
            delta = MOVE_RESIZE_INCREMENT;
          } else {
            delta = size.height - minSize.height;
          }

          // Ensure that we keep the internal frame on the desktop.
          if (loc.y + delta > dpHeight - minOnScreenInsets.top) {
            delta = (dpHeight - minOnScreenInsets.top) - loc.y;
          }

          c.setLocation(loc.x, loc.y + delta);
          c.setSize(size.width, size.height - delta);
        }
      } else if (NEXT_FRAME == key || PREVIOUS_FRAME == key) {
        dp.selectFrame((key == NEXT_FRAME) ? true : false);
      } else if (NAVIGATE_NEXT == key || NAVIGATE_PREVIOUS == key) {
        boolean moveForward = true;
        if (NAVIGATE_PREVIOUS == key) {
          moveForward = false;
        }
        Container cycleRoot = dp.getFocusCycleRootAncestor();

        if (cycleRoot != null) {
          FocusTraversalPolicy policy = cycleRoot.getFocusTraversalPolicy();
          if (policy != null && policy instanceof SortingFocusTraversalPolicy) {
            SortingFocusTraversalPolicy sPolicy = (SortingFocusTraversalPolicy) policy;
            boolean idc = sPolicy.getImplicitDownCycleTraversal();
            try {
              sPolicy.setImplicitDownCycleTraversal(false);
              if (moveForward) {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().focusNextComponent(dp);
              } else {
                KeyboardFocusManager.getCurrentKeyboardFocusManager().focusPreviousComponent(dp);
              }
            } finally {
              sPolicy.setImplicitDownCycleTraversal(idc);
            }
          }
        }
      }
    }
 protected void installKeyboardActions() {
   ActionMap map = getActionMap();
   SwingUtilities.replaceUIActionMap(grid, map);
   InputMap inputMap = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
   SwingUtilities.replaceUIInputMap(grid, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, inputMap);
 }