Пример #1
0
 @Override
 public Dimension getMaximumSize(JComponent c) {
   Gripper gripper = (Gripper) c;
   if (gripper.getOrientation() == SwingConstants.HORIZONTAL)
     return new Dimension(_size, c.getParent().getHeight());
   else return new Dimension(c.getParent().getWidth(), _size);
 }
 private void setupDragMode(JComponent f) {
   JDesktopPane p = getDesktopPane(f);
   Container parent = f.getParent();
   dragMode = DEFAULT_DRAG_MODE;
   if (p != null) {
     String mode = (String) p.getClientProperty("JDesktopPane.dragMode");
     Window window = SwingUtilities.getWindowAncestor(f);
     if (window != null && !AWTUtilities.isWindowOpaque(window)) {
       dragMode = DEFAULT_DRAG_MODE;
     } else if (mode != null && mode.equals("outline")) {
       dragMode = OUTLINE_DRAG_MODE;
     } else if (mode != null
         && mode.equals("faster")
         && f instanceof JInternalFrame
         && ((JInternalFrame) f).isOpaque()
         && (parent == null || parent.isOpaque())) {
       dragMode = FASTER_DRAG_MODE;
     } else {
       if (p.getDragMode() == JDesktopPane.OUTLINE_DRAG_MODE) {
         dragMode = OUTLINE_DRAG_MODE;
       } else if (p.getDragMode() == JDesktopPane.LIVE_DRAG_MODE
           && f instanceof JInternalFrame
           && ((JInternalFrame) f).isOpaque()) {
         dragMode = FASTER_DRAG_MODE;
       } else {
         dragMode = DEFAULT_DRAG_MODE;
       }
     }
   }
 }
Пример #3
0
 protected void paintBackground(Graphics g, JComponent c, int x, int y, int w, int h) {
   JMenuItem b = (JMenuItem) c;
   ButtonModel model = b.getModel();
   if (c.getParent() instanceof JMenuBar) {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   } else {
     if (model.isArmed() || (c instanceof JMenu && model.isSelected())) {
       g.setColor(AbstractLookAndFeel.getMenuSelectionBackgroundColor());
       g.fillRect(x, y, w, h);
     } else if (!AbstractLookAndFeel.getTheme().isMenuOpaque()) {
       Graphics2D g2D = (Graphics2D) g;
       Composite composite = g2D.getComposite();
       AlphaComposite alpha =
           AlphaComposite.getInstance(
               AlphaComposite.SRC_OVER, AbstractLookAndFeel.getTheme().getMenuAlpha());
       g2D.setComposite(alpha);
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
       g2D.setComposite(composite);
     } else {
       g.setColor(AbstractLookAndFeel.getMenuBackgroundColor());
       g.fillRect(x, y, w, h);
     }
   }
   if (menuItem.isSelected() && menuItem.isArmed()) {
     g.setColor(AbstractLookAndFeel.getMenuSelectionForegroundColor());
   } else {
     g.setColor(AbstractLookAndFeel.getMenuForegroundColor());
   }
 }
Пример #4
0
  private Insets getScrollBarInsets(SynthContext context, Insets insets) {
    int troughBorder = getClassSpecificIntValue(context, "trough-border", 1);
    insets.left = insets.right = insets.top = insets.bottom = troughBorder;

    JComponent c = context.getComponent();
    if (c.getParent() instanceof JScrollPane) {
      // This scrollbar is part of a scrollpane; use only the
      // "scrollbar-spacing" style property to determine the padding
      // between the scrollbar and its parent scrollpane.
      int spacing = getClassSpecificIntValue(WidgetType.SCROLL_PANE, "scrollbar-spacing", 3);
      if (((JScrollBar) c).getOrientation() == JScrollBar.HORIZONTAL) {
        insets.top += spacing;
      } else {
        if (c.getComponentOrientation().isLeftToRight()) {
          insets.left += spacing;
        } else {
          insets.right += spacing;
        }
      }
    } else {
      // This is a standalone scrollbar; leave enough room for the
      // focus line in addition to the trough border.
      if (c.isFocusable()) {
        int focusSize = getClassSpecificIntValue(context, "focus-line-width", 1);
        int focusPad = getClassSpecificIntValue(context, "focus-padding", 1);
        int totalFocus = focusSize + focusPad;
        insets.left += totalFocus;
        insets.right += totalFocus;
        insets.top += totalFocus;
        insets.bottom += totalFocus;
      }
    }
    return insets;
  }
  public void paint(Graphics g, JComponent c) {
    Dimension s = c.getSize();
    if (WindowsMenuItemUI.isVistaPainting()) {
      int x = 1;
      Component parent = c.getParent();
      if (parent instanceof JComponent) {
        Object gutterOffsetObject =
            ((JComponent) parent).getClientProperty(WindowsPopupMenuUI.GUTTER_OFFSET_KEY);
        if (gutterOffsetObject instanceof Integer) {
          /*
           * gutter offset is in parent's coordinates.
           * See comment in
           * WindowsPopupMenuUI.getTextOffset(JComponent)
           */
          x = ((Integer) gutterOffsetObject).intValue() - c.getX();
          x += WindowsPopupMenuUI.getGutterWidth();
        }
      }
      Skin skin = XPStyle.getXP().getSkin(c, Part.MP_POPUPSEPARATOR);
      int skinHeight = skin.getHeight();
      int y = (s.height - skinHeight) / 2;
      skin.paintSkin(g, x, y, s.width - x - 1, skinHeight, State.NORMAL);
    } else {
      int y = s.height / 2;
      g.setColor(c.getForeground());
      g.drawLine(1, y - 1, s.width - 2, y - 1);

      g.setColor(c.getBackground());
      g.drawLine(1, y, s.width - 2, y);
    }
  }
  @Override
  protected void paintComponent(final Graphics g) {
    super.paintComponent(g);

    if (myToolbar != null
        && myToolbar.getParent() == this
        && myContent != null
        && myContent.getParent() == this) {
      g.setColor(UIUtil.getBorderColor());
      if (myVertical) {
        final int y = (int) myToolbar.getBounds().getMaxY();
        g.drawLine(0, y, getWidth(), y);
      } else {
        int x = (int) myToolbar.getBounds().getMaxX();
        g.drawLine(x, 0, x, getHeight());
      }
    }
  }
Пример #7
0
 private static void setComponentName(JComponent component, String name) {
   if (component != null) {
     Container parent = component.getParent();
     if (parent != null) {
       component.setName(parent.getName() + "." + name);
     } else {
       component.setName(name);
     }
   }
 }
Пример #8
0
  /** Find the top focusable Window, Applet, or InternalFrame */
  private static Container getTopAncestor(JComponent c) {
    for (Container p = c.getParent(); p != null; p = p.getParent()) {
      if (p instanceof Window && ((Window) p).isFocusableWindow()
          || p instanceof Applet
          || p instanceof JInternalFrame) {

        return p;
      }
    }
    return null;
  }
  private Rectangle[] findFloatingItems(JComponent f) {
    Container desktop = f.getParent();
    Component[] children = desktop.getComponents();
    int i = 0;
    for (i = 0; i < children.length; i++) {
      if (children[i] == f) {
        break;
      }
    }
    // System.out.println(i);
    Rectangle[] floaters = new Rectangle[i];
    for (i = 0; i < floaters.length; i++) {
      floaters[i] = children[i].getBounds();
    }

    return floaters;
  }
  JDesktopPane getDesktopPane(JComponent frame) {
    JDesktopPane pane = null;
    Component c = frame.getParent();

    // Find the JDesktopPane
    while (pane == null) {
      if (c instanceof JDesktopPane) {
        pane = (JDesktopPane) c;
      } else if (c == null) {
        break;
      } else {
        c = c.getParent();
      }
    }

    return pane;
  }
  public Point getLocationOn(JComponent c) {
    Point location;
    if (isRealPopup()) {
      location = myPopup.getLocationOnScreen();
      SwingUtilities.convertPointFromScreen(location, c);
    } else {
      if (myCurrentIdeTooltip != null) {
        Point tipPoint = myCurrentIdeTooltip.getPoint();
        Component tipComponent = myCurrentIdeTooltip.getComponent();
        return SwingUtilities.convertPoint(tipComponent, tipPoint, c);
      } else {
        location =
            SwingUtilities.convertPoint(myComponent.getParent(), myComponent.getLocation(), c);
      }
    }

    return location;
  }
  // implements javax.swing.DesktopManager
  public void beginDraggingFrame(JComponent f) {
    setupDragMode(f);

    if (dragMode == FASTER_DRAG_MODE) {
      Component desktop = f.getParent();
      floatingItems = findFloatingItems(f);
      currentBounds = f.getBounds();
      if (desktop instanceof JComponent) {
        desktopBounds = ((JComponent) desktop).getVisibleRect();
      } else {
        desktopBounds = desktop.getBounds();
        desktopBounds.x = desktopBounds.y = 0;
      }
      desktopGraphics = JComponent.safelyGetGraphics(desktop);
      ((JInternalFrame) f).isDragging = true;
      didDrag = false;
    }
  }
  public void setSize(final Dimension size) {
    if (myIsRealPopup && myPopup != null) {
      // There is a possible case that a popup wraps target content component into other components
      // which might have borders.
      // That's why we can't just apply component's size to the whole popup. It needs to be adjusted
      // before that.
      JComponent popupContent = myPopup.getContent();
      int widthExpand = 0;
      int heightExpand = 0;
      boolean adjustSize = false;
      JComponent prev = myComponent;
      for (Container c = myComponent.getParent(); c != null; c = c.getParent()) {
        if (c == popupContent) {
          adjustSize = true;
          break;
        }
        if (c instanceof JComponent) {
          Border border = ((JComponent) c).getBorder();
          if (prev != null && border != null) {
            Insets insets = border.getBorderInsets(prev);
            widthExpand += insets.left + insets.right;
            heightExpand += insets.top + insets.bottom;
          }
          prev = (JComponent) c;
        } else {
          prev = null;
        }
      }
      Dimension sizeToUse = size;
      if (adjustSize && (widthExpand != 0 || heightExpand != 0)) {
        sizeToUse = new Dimension(size.width + widthExpand, size.height + heightExpand);
      }
      myPopup.setSize(sizeToUse);
    } else if (!isAwtTooltip()) {
      myComponent.setSize(size);

      myComponent.revalidate();
      myComponent.repaint();
    }
  }
Пример #14
0
 public static boolean isActive(JComponent c) {
   if (c == null) {
     return false;
   }
   boolean active = true;
   if (c instanceof JInternalFrame) {
     active = ((JInternalFrame) c).isSelected();
   }
   if (active) {
     Container parent = c.getParent();
     while (parent != null) {
       if (parent instanceof JInternalFrame) {
         active = ((JInternalFrame) parent).isSelected();
         break;
       }
       parent = parent.getParent();
     }
   }
   if (active) {
     active = isFrameActive(c);
   }
   return active;
 }
  @Override
  public void setLocation(@NotNull RelativePoint point) {
    if (isRealPopup()) {
      myPopup.setLocation(point.getScreenPoint());
    } else {
      if (myCurrentIdeTooltip != null) {
        Point screenPoint = point.getScreenPoint();
        if (!screenPoint.equals(
            new RelativePoint(myCurrentIdeTooltip.getComponent(), myCurrentIdeTooltip.getPoint())
                .getScreenPoint())) {
          myCurrentIdeTooltip.setPoint(point.getPoint());
          myCurrentIdeTooltip.setComponent(point.getComponent());
          IdeTooltipManager.getInstance().show(myCurrentIdeTooltip, true, false);
        }
      } else {
        Point targetPoint = point.getPoint(myComponent.getParent());
        myComponent.setLocation(targetPoint);

        myComponent.revalidate();
        myComponent.repaint();
      }
    }
  }
Пример #16
0
 /** Returns true if the specified widget is in a toolbar. */
 static boolean isToolBarButton(JComponent c) {
   return (c.getParent() instanceof JToolBar);
 }
Пример #17
0
 /**
  * Checks and answers if this combo is in a tool bar.
  *
  * @param c the component to check
  * @return true if in tool bar, false otherwise
  */
 protected boolean isToolBarComboBox(JComponent c) {
   Container parent = c.getParent();
   return parent != null && (parent instanceof JToolBar || parent.getParent() instanceof JToolBar);
 }
Пример #18
0
  public static void main(String args[]) {
    JComponent ch = new JComponent() {};
    ch.getAccessibleContext();
    ch.isFocusTraversable();
    ch.setEnabled(false);
    ch.setEnabled(true);
    ch.requestFocus();
    ch.requestFocusInWindow();
    ch.getPreferredSize();
    ch.getMaximumSize();
    ch.getMinimumSize();
    ch.contains(1, 2);
    Component c1 = ch.add(new Component() {});
    Component c2 = ch.add(new Component() {});
    Component c3 = ch.add(new Component() {});
    Insets ins = ch.getInsets();
    ch.getAlignmentY();
    ch.getAlignmentX();
    ch.getGraphics();
    ch.setVisible(false);
    ch.setVisible(true);
    ch.setForeground(Color.red);
    ch.setBackground(Color.red);
    for (String font : Toolkit.getDefaultToolkit().getFontList()) {
      for (int j = 8; j < 17; j++) {
        Font f1 = new Font(font, Font.PLAIN, j);
        Font f2 = new Font(font, Font.BOLD, j);
        Font f3 = new Font(font, Font.ITALIC, j);
        Font f4 = new Font(font, Font.BOLD | Font.ITALIC, j);

        ch.setFont(f1);
        ch.setFont(f2);
        ch.setFont(f3);
        ch.setFont(f4);

        ch.getFontMetrics(f1);
        ch.getFontMetrics(f2);
        ch.getFontMetrics(f3);
        ch.getFontMetrics(f4);
      }
    }
    ch.enable();
    ch.disable();
    ch.reshape(10, 10, 10, 10);
    ch.getBounds(new Rectangle(1, 1, 1, 1));
    ch.getSize(new Dimension(1, 2));
    ch.getLocation(new Point(1, 2));
    ch.getX();
    ch.getY();
    ch.getWidth();
    ch.getHeight();
    ch.isOpaque();
    ch.isValidateRoot();
    ch.isOptimizedDrawingEnabled();
    ch.isDoubleBuffered();
    ch.getComponentCount();
    ch.countComponents();
    ch.getComponent(1);
    ch.getComponent(2);
    Component[] cs = ch.getComponents();
    ch.getLayout();
    ch.setLayout(new FlowLayout());
    ch.doLayout();
    ch.layout();
    ch.invalidate();
    ch.validate();
    ch.remove(0);
    ch.remove(c2);
    ch.removeAll();
    ch.preferredSize();
    ch.minimumSize();
    ch.getComponentAt(1, 2);
    ch.locate(1, 2);
    ch.getComponentAt(new Point(1, 2));
    ch.isFocusCycleRoot(new Container());
    ch.transferFocusBackward();
    ch.setName("goober");
    ch.getName();
    ch.getParent();
    ch.getGraphicsConfiguration();
    ch.getTreeLock();
    ch.getToolkit();
    ch.isValid();
    ch.isDisplayable();
    ch.isVisible();
    ch.isShowing();
    ch.isEnabled();
    ch.enable(false);
    ch.enable(true);
    ch.enableInputMethods(false);
    ch.enableInputMethods(true);
    ch.show();
    ch.show(false);
    ch.show(true);
    ch.hide();
    ch.getForeground();
    ch.isForegroundSet();
    ch.getBackground();
    ch.isBackgroundSet();
    ch.getFont();
    ch.isFontSet();
    Container c = new Container();
    c.add(ch);
    ch.getLocale();
    for (Locale locale : Locale.getAvailableLocales()) ch.setLocale(locale);

    ch.getColorModel();
    ch.getLocation();

    boolean exceptions = false;
    try {
      ch.getLocationOnScreen();
    } catch (IllegalComponentStateException e) {
      exceptions = true;
    }
    if (!exceptions)
      throw new RuntimeException("IllegalComponentStateException did not occur when expected");

    ch.location();
    ch.setLocation(1, 2);
    ch.move(1, 2);
    ch.setLocation(new Point(1, 2));
    ch.getSize();
    ch.size();
    ch.setSize(1, 32);
    ch.resize(1, 32);
    ch.setSize(new Dimension(1, 32));
    ch.resize(new Dimension(1, 32));
    ch.getBounds();
    ch.bounds();
    ch.setBounds(10, 10, 10, 10);
    ch.setBounds(new Rectangle(10, 10, 10, 10));
    ch.isLightweight();
    ch.setCursor(new Cursor(Cursor.CROSSHAIR_CURSOR));
    ch.getCursor();
    ch.isCursorSet();
    ch.inside(1, 2);
    ch.contains(new Point(1, 2));
    ch.isFocusable();
    ch.setFocusable(true);
    ch.setFocusable(false);
    ch.transferFocus();
    ch.getFocusCycleRootAncestor();
    ch.nextFocus();
    ch.transferFocusUpCycle();
    ch.hasFocus();
    ch.isFocusOwner();
    ch.toString();
    ch.setComponentOrientation(ComponentOrientation.LEFT_TO_RIGHT);
    ch.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
    ch.setComponentOrientation(ComponentOrientation.UNKNOWN);
    ch.getComponentOrientation();
  }
  private void dragFrameFaster(JComponent f, int newX, int newY) {

    Rectangle previousBounds =
        new Rectangle(currentBounds.x, currentBounds.y, currentBounds.width, currentBounds.height);

    // move the frame
    currentBounds.x = newX;
    currentBounds.y = newY;

    if (didDrag) {
      // Only initiate cleanup if we have actually done a drag.
      emergencyCleanup(f);
    } else {
      didDrag = true;
      // We reset the danger field as until now we haven't actually
      // moved the internal frame so we don't need to initiate repaint.
      ((JInternalFrame) f).danger = false;
    }

    boolean floaterCollision = isFloaterCollision(previousBounds, currentBounds);

    // System.out.println(previousBounds);
    JComponent parent = (JComponent) f.getParent();
    Rectangle visBounds = previousBounds.intersection(desktopBounds);
    //  System.out.println(previousBounds);

    // System.out.println(visBounds);

    RepaintManager currentManager = RepaintManager.currentManager(f);

    currentManager.beginPaint();
    try {
      if (!floaterCollision) {
        currentManager.copyArea(
            parent,
            desktopGraphics,
            visBounds.x,
            visBounds.y,
            visBounds.width,
            visBounds.height,
            newX - previousBounds.x,
            newY - previousBounds.y,
            true);
      }

      f.setBounds(currentBounds);

      if (floaterCollision) {
        // since we couldn't blit we just redraw as fast as possible
        // the isDragging mucking is to avoid activating emergency
        // cleanup
        ((JInternalFrame) f).isDragging = false;
        parent.paintImmediately(currentBounds);
        ((JInternalFrame) f).isDragging = true;
      }

      // fake out the repaint manager.  We'll take care of everything

      currentManager.markCompletelyClean(parent);
      currentManager.markCompletelyClean(f);

      // compute the minimal newly exposed area
      // if the rects intersect then we use computeDifference.  Otherwise
      // we'll repaint the entire previous bounds
      Rectangle[] dirtyRects = null;
      if (previousBounds.intersects(currentBounds)) {
        dirtyRects = SwingUtilities.computeDifference(previousBounds, currentBounds);
      } else {
        dirtyRects = new Rectangle[1];
        dirtyRects[0] = previousBounds;
        //  System.out.println("no intersection");
      }
      ;

      // Fix the damage
      for (int i = 0; i < dirtyRects.length; i++) {
        parent.paintImmediately(dirtyRects[i]);
      }

      // new areas of blit were exposed
      if (!(visBounds.equals(previousBounds))) {
        dirtyRects = SwingUtilities.computeDifference(previousBounds, desktopBounds);
        for (int i = 0; i < dirtyRects.length; i++) {
          dirtyRects[i].x += newX - previousBounds.x;
          dirtyRects[i].y += newY - previousBounds.y;
          ((JInternalFrame) f).isDragging = false;

          parent.paintImmediately(dirtyRects[i]);
          ((JInternalFrame) f).isDragging = true;

          // System.out.println(dirtyRects[i]);
        }
      }
    } finally {
      currentManager.endPaint();
    }

    // update window if it's non-opaque
    Window topLevel = SwingUtilities.getWindowAncestor(f);
    Toolkit tk = Toolkit.getDefaultToolkit();
    if (!AWTAccessor.getWindowAccessor().isOpaque(topLevel)
        && (tk instanceof SunToolkit)
        && ((SunToolkit) tk).needUpdateWindow()) {
      AWTAccessor.getWindowAccessor().updateWindow(topLevel);
    }
  }