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);
    }
  }
  /**
   * Creates preview for the device(video) in the video container.
   *
   * @param device the device
   * @param videoContainer the container
   * @throws IOException a problem accessing the device.
   * @throws MediaException a problem getting preview.
   */
  private static void createPreview(MediaDevice device, final JComponent videoContainer)
      throws IOException, MediaException {
    videoContainer.removeAll();

    videoContainer.revalidate();
    videoContainer.repaint();

    if (device == null) return;

    Component c =
        (Component)
            GuiActivator.getMediaService()
                .getVideoPreviewComponent(
                    device, videoContainer.getSize().width, videoContainer.getSize().height);

    videoContainer.add(c);
  }
 public Point getLocation() {
   Document doc = frame.getDocument();
   Editor editor = doc.getEditor();
   JComponent image = editor.getImage();
   Point loc = image.getLocationOnScreen();
   Dimension size = image.getSize();
   Point p = new Point(loc.x + size.width - 200, loc.y + size.height - 200);
   return p;
 }
Exemple #4
0
 @Nullable
 private Rectangle getHintBounds() {
   LightweightHint hint = myHint;
   if (hint == null) {
     return null;
   }
   JComponent hintComponent = hint.getComponent();
   if (!hintComponent.isShowing()) {
     return null;
   }
   return new Rectangle(hintComponent.getLocationOnScreen(), hintComponent.getSize());
 }
  /*
   *  Create a BufferedImage for Swing components.
   *  The entire component will be captured to an image.
   *
   *  @param	 component Swing component to create image from
   *  @param	 fileName name of file to be created or null
   *  @return	image the image for the given region
   *  @exception IOException if an error occurs during writing
   */
  public static BufferedImage createImage(JComponent component, String fileName)
      throws IOException {
    Dimension d = component.getSize();

    if (d.width == 0) {
      d = component.getPreferredSize();
      component.setSize(d);
    }

    Rectangle region = new Rectangle(0, 0, d.width, d.height);
    return ScreenCapture.createImage(component, region, fileName);
  }
 private static void processRootContainerResize(
     final RadContainer container, final boolean isRow, final int newSize) {
   final JComponent parentDelegee = container.getDelegee();
   Dimension containerSize = parentDelegee.getSize();
   if (isRow) {
     containerSize.height = newSize + parentDelegee.getBounds().y;
   } else {
     containerSize.width = newSize + parentDelegee.getBounds().x;
   }
   parentDelegee.setSize(containerSize);
   parentDelegee.revalidate();
 }
  public boolean isInsideHint(RelativePoint target) {
    if (myComponent == null || !myComponent.isShowing()) return false;

    if (myIsRealPopup) {
      Window wnd = SwingUtilities.getWindowAncestor(myComponent);
      return wnd.getBounds().contains(target.getScreenPoint());
    } else if (myCurrentIdeTooltip != null) {
      return myCurrentIdeTooltip.isInside(target);
    } else {
      return new Rectangle(myComponent.getLocationOnScreen(), myComponent.getSize())
          .contains(target.getScreenPoint());
    }
  }
 /**
  * Asks to show balloon that contains information related to the given component.
  *
  * @param component component for which we want to show information
  * @param messageType balloon message type
  * @param message message to show
  */
 public static void showBalloon(
     @NotNull JComponent component, @NotNull MessageType messageType, @NotNull String message) {
   final BalloonBuilder delegate =
       JBPopupFactory.getInstance().createHtmlTextBalloonBuilder(message, messageType, null);
   BalloonBuilder balloonBuilder = new GradleBalloonBuilder(delegate, APPLICATION_BALLOONS);
   ApplicationBalloonsDisposeActivator.ensureActivated();
   Balloon balloon = balloonBuilder.setFadeoutTime(TimeUnit.SECONDS.toMillis(1)).createBalloon();
   Dimension size = component.getSize();
   Balloon.Position position;
   int x;
   int y;
   if (size == null) {
     x = y = 0;
     position = Balloon.Position.above;
   } else {
     x = Math.min(10, size.width / 2);
     y = size.height;
     position = Balloon.Position.below;
   }
   balloon.show(new RelativePoint(component, new Point(x, y)), position);
 }
 public Dimension getSize() {
   return myComponent.getSize();
 }
  @Nullable
  private Point createToolTipImage(@NotNull KeyType key) {
    UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, true);
    Pair<Component, Rectangle> rendererAndBounds = getCellRendererAndBounds(key);
    UIUtil.putClientProperty(myComponent, EXPANDED_RENDERER, null);
    if (rendererAndBounds == null) return null;

    JComponent renderer = ObjectUtils.tryCast(rendererAndBounds.first, JComponent.class);
    if (renderer == null) return null;
    if (renderer.getClientProperty(DISABLE_EXPANDABLE_HANDLER) != null) return null;

    if (UIUtil.getClientProperty((JComponent) rendererAndBounds.getFirst(), USE_RENDERER_BOUNDS)
        == Boolean.TRUE) {
      rendererAndBounds.getSecond().translate(renderer.getX(), renderer.getY());
      rendererAndBounds.getSecond().setSize(renderer.getSize());
    }

    myKeyItemBounds = rendererAndBounds.second;

    Rectangle cellBounds = myKeyItemBounds;
    Rectangle visibleRect = getVisibleRect(key);

    if (cellBounds.y < visibleRect.y) return null;

    int cellMaxY = cellBounds.y + cellBounds.height;
    int visMaxY = visibleRect.y + visibleRect.height;
    if (cellMaxY > visMaxY) return null;

    int cellMaxX = cellBounds.x + cellBounds.width;
    int visMaxX = visibleRect.x + visibleRect.width;

    Point location = new Point(visMaxX, cellBounds.y);
    SwingUtilities.convertPointToScreen(location, myComponent);

    Rectangle screen =
        !Registry.is("ide.expansion.hints.on.all.screens")
            ? ScreenUtil.getScreenRectangle(location)
            : ScreenUtil.getAllScreensRectangle();

    int borderWidth = isPaintBorder() ? 1 : 0;
    int width = Math.min(screen.width + screen.x - location.x - borderWidth, cellMaxX - visMaxX);
    int height = cellBounds.height;

    if (width <= 0 || height <= 0) return null;

    Dimension size = getImageSize(width, height);
    myImage = UIUtil.createImage(size.width, size.height, BufferedImage.TYPE_INT_RGB);

    Graphics2D g = myImage.createGraphics();
    g.setClip(null);
    doFillBackground(height, width, g);
    g.translate(cellBounds.x - visMaxX, 0);
    doPaintTooltipImage(renderer, cellBounds, g, key);

    CustomLineBorder border = null;
    if (borderWidth > 0) {
      border = new CustomLineBorder(getBorderColor(), borderWidth, 0, borderWidth, borderWidth);
      location.y -= borderWidth;
      size.width += borderWidth;
      size.height += borderWidth + borderWidth;
    }

    g.dispose();
    myRendererPane.remove(renderer);

    myTipComponent.setBorder(border);
    myTipComponent.setPreferredSize(size);
    return location;
  }
  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();
  }