Пример #1
0
 void ajustarYCentrar(JComponent porAjustar, JComponent ajustador) {
   // Se agregan 30 de alto y 6 de ancho por adornos de la ventana
   porAjustar.setSize(
       ajustador.getMinimumSize().getSize().width + 16,
       ajustador.getMinimumSize().getSize().height + 44);
   int x = Math.round(Principal.sysAncho / 2) - Math.round(porAjustar.getBounds().width / 2);
   int y = Math.round(Principal.sysAlto / 2) - Math.round(porAjustar.getBounds().height / 2);
   porAjustar.setLocation(x, y);
 }
 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();
 }
 private void initShape(JComponent c) {
   if (!c.getBounds().equals(base)) {
     base = c.getBounds();
     shape =
         new RoundRectangle2D.Float(
             0, 0, c.getWidth() - 1, c.getHeight() - 1, arcwidth, archeight);
     border =
         new RoundRectangle2D.Float(
             focusstroke,
             focusstroke,
             c.getWidth() - 1 - focusstroke * 2,
             c.getHeight() - 1 - focusstroke * 2,
             arcwidth,
             archeight);
   }
 }
Пример #4
0
 private static boolean isMouseOver(JComponent c) {
   Rectangle componentBounds = c.getBounds();
   Point mousePosition = c.getMousePosition();
   return (componentBounds != null
       && mousePosition != null
       && componentBounds.contains(mousePosition));
 }
Пример #5
0
  public static void center(JComponent c, Rectangle r, boolean withInsets) {
    Rectangle visible = c.getVisibleRect();

    visible.x = r.x - (visible.width - r.width) / 2;
    visible.y = r.y - (visible.height - r.height) / 2;

    Rectangle bounds = c.getBounds();
    Insets i = withInsets ? new Insets(0, 0, 0, 0) : c.getInsets();
    bounds.x = i.left;
    bounds.y = i.top;
    bounds.width -= i.left + i.right;
    bounds.height -= i.top + i.bottom;

    if (visible.x < bounds.x) visible.x = bounds.x;

    if (visible.x + visible.width > bounds.x + bounds.width)
      visible.x = bounds.x + bounds.width - visible.width;

    if (visible.y < bounds.y) visible.y = bounds.y;

    if (visible.y + visible.height > bounds.y + bounds.height)
      visible.y = bounds.y + bounds.height - visible.height;

    c.scrollRectToVisible(visible);
  }
 public ParticleContainer(Editor editor) {
   parent = editor.getContentComponent();
   parent.add(this);
   this.setBounds(parent.getBounds());
   setVisible(true);
   parent.addComponentListener(this);
 }
Пример #7
0
  public boolean collides(JComponent c1, JComponent c2) {
    // System.out.println("Comparing:\n " + c1.toString() + " \n " + c2.toString());
    /*
    if(c1.getX() > c2.getX() && c1.getX() + c1.getWidth()*1.8f < c2.getX() + c2.getWidth()*1.8f ){
        if(c1.getY() > c2.getY() && c1.getY() + c1.getHeight()*1.8f < c2.getY() + c2.getHeight()*1.8f){
            return true;
        }
    }
    if(c2.getX() > c1.getX() && c2.getX() + c2.getWidth()*1.8f < c1.getX() + c1.getWidth()*1.8f ){
        if(c2.getY() > c1.getY() && c2.getY() + c2.getHeight()*1.8f < c1.getY() + c1.getHeight()*1.8f){
            return true;
        }
    }
    */

    return c1.getBounds().intersects(c2.getBounds());
  }
Пример #8
0
 private static Rectangle calculateInnerArea(JComponent comp, int pixels) {
   Rectangle result = new Rectangle();
   Rectangle compRect = comp.getBounds();
   result.x = pixels;
   result.y = pixels;
   result.height = compRect.height - (pixels * 2);
   result.width = compRect.width - (pixels * 2);
   return result;
 }
  @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());
      }
    }
  }
 private static void validateIfNeeded(final JComponent c, final Rectangle rect) {
   if (!Splitter.isNull(c)) {
     if (!c.getBounds().equals(rect)) {
       c.setBounds(rect);
       c.revalidate();
     }
   } else {
     Splitter.hideNull(c);
   }
 }
  /**
   * Determines if the mouse is pressed over a control button. If so, handles the event accordingly.
   */
  private boolean handleControlButton(MouseEvent e) {
    if (e.getID() == MouseEvent.MOUSE_PRESSED) {
      java.awt.Container btnpanel = m_comp.getButtonPanel();
      JComponent btn = m_comp.getExpandButton();
      Point local_pt =
          SwingUtilities.convertPoint((Component) e.getSource(), e.getPoint(), btnpanel);

      Rectangle rect = btn.getBounds();
      if (rect.contains(local_pt)) {
        m_comp.setGridViewVisible(!m_comp.isGridViewVisible());
        return true;
      }

      btn = m_comp.getEditButton();
      rect = btn.getBounds();
      if (rect.contains(local_pt)) {
        FormManager fmgr = (FormManager) JETARegistry.lookup(FormManager.COMPONENT_ID);
        fmgr.showForm(m_comp.getId());
        return true;
      }

      btn = m_comp.getGridButton();
      rect = btn.getBounds();
      if (rect.contains(local_pt)) {
        GridView view = m_comp.getChildView();
        boolean bvis = !view.isGridVisible();
        if (bvis) {
          m_comp.setGridViewVisible(bvis);
        } else {
          view.setGridVisible(bvis);
        }
        return true;
      }
    }

    return false;
  }
  public void paint(Graphics g, JComponent c) {
    if (Boolean.FALSE.equals(c.getClientProperty("roundedCorners"))) paintSquare(g, c);
    else paintRounded(g, c);

    KCollapsiblePane pane =
        (KCollapsiblePane) c.getClientProperty(KCollapsiblePane.HEADER_UI_PROPERTY_OWNER_PANE);
    if (pane != null) {
      Rectangle bounds = c.getBounds();
      Icon arrowIcon = pane.isExpanded() ? arrowExpandedIcon : arrowCollapsedIcon;
      arrowIcon.paintIcon(
          c,
          g,
          bounds.width - arrowIcon.getIconWidth(),
          (bounds.height - arrowIcon.getIconWidth()) / 2);
    }
  }
 // Event forwarding. We need it if user does press-and-drag gesture for opening popup and
 // choosing item there.
 // It works in JComboBox, here we provide the same behavior
 private void dispatchEventToPopup(MouseEvent e) {
   if (myPopup != null && myPopup.isVisible()) {
     JComponent content = myPopup.getContent();
     Rectangle rectangle = content.getBounds();
     Point location = rectangle.getLocation();
     SwingUtilities.convertPointToScreen(location, content);
     Point eventPoint = e.getLocationOnScreen();
     rectangle.setLocation(location);
     if (rectangle.contains(eventPoint)) {
       MouseEvent event =
           SwingUtilities.convertMouseEvent(e.getComponent(), e, myPopup.getContent());
       Component component =
           SwingUtilities.getDeepestComponentAt(content, event.getX(), event.getY());
       if (component != null) component.dispatchEvent(event);
     }
   }
 }
  public void paintSquare(Graphics g, JComponent c) {
    AbstractButton button = (AbstractButton) c;
    button.getInsets();
    float strokeSize =
        UIManager.getInt(
            "CollapsiblePaneHeader.borderSize"); // KorsakowLookAndFeel.BORDER_STROKE_SIZE;
    int width = c.getWidth();
    width -= 1; // rounded rect gets clipped slightly
    int height = c.getHeight();

    Rectangle bounds = c.getBounds();
    Graphics2D g2 = (Graphics2D) g;

    // background
    // background comes after to cover the crossign lines of the two border rects
    GradientPaint paint =
        new GradientPaint(
            0,
            0,
            UIManager.getColor("CollapsiblePaneHeader.background"),
            0,
            height,
            UIManager.getColor("CollapsiblePaneHeader.background2"),
            false);
    boolean isOver = button.getMousePosition(true) != null;
    if (isOver)
      paint =
          new GradientPaint(
              0,
              0,
              UIManager.getColor("CollapsiblePaneHeader.activeBackground"),
              0,
              height,
              UIManager.getColor("CollapsiblePaneHeader.activeBackground2"),
              false);
    ;
    g2.setPaint(paint);
    g2.fill(bounds);

    // border
    g2.setStroke(new BasicStroke(strokeSize));
    g2.setColor(UIManager.getColor("CollapsiblePaneHeader.border"));
    g2.draw(bounds);

    super.paint(g2, c);
  }
  public void hide(boolean ok) {
    if (isVisible()) {
      if (myIsRealPopup) {
        if (ok) {
          myPopup.closeOk(null);
        } else {
          myPopup.cancel();
        }
        myPopup = null;
      } else {
        if (myCurrentIdeTooltip != null) {
          IdeTooltip tooltip = myCurrentIdeTooltip;
          myCurrentIdeTooltip = null;
          tooltip.hide();
        } else {
          final JRootPane rootPane = myComponent.getRootPane();
          if (rootPane != null) {
            final Rectangle bounds = myComponent.getBounds();
            final JLayeredPane layeredPane = rootPane.getLayeredPane();

            try {
              if (myFocusBackComponent != null) {
                LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(myFocusBackComponent);
              }
              layeredPane.remove(myComponent);
            } finally {
              LayoutFocusTraversalPolicyExt.setOverridenDefaultComponent(null);
            }

            layeredPane.paintImmediately(bounds.x, bounds.y, bounds.width, bounds.height);
          }
        }
      }
    }
    if (myEscListener != null) {
      myComponent.unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0));
    }

    TooltipController.getInstance().hide(this);

    fireHintHidden();
  }
Пример #16
0
  /**
   * Utility method to acquire a Picture object which can paint the content of a screen component.
   * The component should not be altered while the picture is in use.
   *
   * @param comp screen component
   * @return object to draw comp's content
   */
  public static Picture toPicture(final JComponent comp) {
    final Rectangle bounds = comp.getBounds();
    return new Picture() {
      public int getPictureWidth() {
        return bounds.width;
      }

      public int getPictureHeight() {
        return bounds.height;
      }

      public void paintPicture(Graphics2D g) {
        int xoff = -bounds.x;
        int yoff = -bounds.y;
        g.translate(xoff, yoff);
        comp.print(g);
        g.translate(-xoff, -yoff);
      }
    };
  }
Пример #17
0
  /**
   * Looks for a bean (if any) whose bounds contain the supplied point
   *
   * @param p a point
   * @return a bean that contains the supplied point or null if no bean contains the point
   */
  public static BeanInstance findInstance(Point p, Integer... tab) {
    int index = 0;
    if (tab.length > 0) {
      index = tab[0].intValue();
    }

    Vector<Object> components = null;
    if (TABBED_COMPONENTS.size() > 0 && index < TABBED_COMPONENTS.size()) {
      components = TABBED_COMPONENTS.get(index);
    }

    Rectangle tempBounds = new Rectangle();
    for (int i = 0; i < components.size(); i++) {

      BeanInstance t = (BeanInstance) components.elementAt(i);
      JComponent temp = (JComponent) t.getBean();

      tempBounds = temp.getBounds(tempBounds);
      if (tempBounds.contains(p)) {
        return t;
      }
    }
    return null;
  }
Пример #18
0
 /**
  * Returns the bounds of the delegate component or null if the delegate is null.
  *
  * <p>PENDING JW: where do we use it? Maybe it was for testing only?
  *
  * @return the bounds of the delegate, or null if the delegate is null.
  */
 public Rectangle getDelegateBounds() {
   if (delegate == null) return null;
   return delegate.getBounds();
 }
  public void paintRounded(Graphics g, JComponent c) {
    AbstractButton button = (AbstractButton) c;
    button.getInsets();
    int arcWidth =
        UIManager.getInt(
            "CollapsiblePaneHeader.roundedCornerSize"); // KorsakowLookAndFeel.ROUNDED_CORNER_SIZE;
    int arcHeight =
        UIManager.getInt(
            "CollapsiblePaneHeader.roundedCornerSize"); // KorsakowLookAndFeel.ROUNDED_CORNER_SIZE;
    float strokeSize =
        UIManager.getInt(
            "CollapsiblePaneHeader.borderSize"); // KorsakowLookAndFeel.BORDER_STROKE_SIZE;
    int width = c.getWidth();
    width -= 1; // rounded rect gets clipped slightly
    int height = c.getHeight();

    Rectangle bounds = c.getBounds();
    Graphics2D g2 = (Graphics2D) g;

    RoundRectangle2D.Float borderTopRect =
        new RoundRectangle2D.Float(
            strokeSize / 2,
            strokeSize / 2,
            width - strokeSize,
            height - strokeSize,
            arcWidth,
            arcHeight);
    Rectangle2D.Float borderBottomRect =
        new Rectangle2D.Float(strokeSize / 2, height / 2, width, height / 2);

    // background
    // background comes after to cover the crossign lines of the two border rects
    GradientPaint paint =
        new GradientPaint(
            0,
            0,
            UIManager.getColor("CollapsiblePaneHeader.background"),
            0,
            height,
            UIManager.getColor("CollapsiblePaneHeader.background2"),
            false);
    boolean isOver = button.getMousePosition(true) != null;
    if (isOver)
      paint =
          new GradientPaint(
              0,
              0,
              UIManager.getColor("CollapsiblePaneHeader.activeBackground"),
              0,
              height,
              UIManager.getColor("CollapsiblePaneHeader.activeBackground2"),
              false);
    ;
    g2.setPaint(paint);
    g2.fill(borderTopRect);
    g2.fill(borderBottomRect);

    // border
    g2.setStroke(new BasicStroke(strokeSize));
    g2.setColor(UIManager.getColor("CollapsiblePaneHeader.borderColor"));
    //    	g2.setColor(Color.red);
    KorsakowLafUtil.drawTopRoundedRect(g2, 0, 0, width, height, arcWidth, arcHeight);
    //    	g2.drawArc((int)(borderTopRect.x), (int)(borderTopRect.y), arcWidth, arcHeight*2, 90,
    // 90); // top left
    //    	g2.drawArc((int)(borderTopRect.x+borderTopRect.width-arcWidth), (int)(borderTopRect.y),
    // arcWidth, arcHeight, 0, 90); // top right
    //    	g2.drawLine((int)(borderTopRect.x+arcWidth/2), (int)(borderTopRect.y),
    // (int)(borderTopRect.width-arcWidth/2), (int)borderTopRect.y); // top
    //    	g2.drawLine((int)(borderTopRect.x), (int)(borderTopRect.y+arcHeight/2),
    // (int)(borderTopRect.x), (int)(borderBottomRect.y+borderBottomRect.height)); // left
    //    	g2.drawLine((int)(borderTopRect.x+borderTopRect.width),
    // (int)(borderTopRect.y+arcHeight/2), (int)(borderTopRect.x+borderTopRect.width),
    // (int)(borderBottomRect.y+borderBottomRect.height)); // right
    //    	g2.drawLine((int)(borderTopRect.x), (int)(borderBottomRect.y+borderBottomRect.height-1),
    // (int)(borderTopRect.x + borderTopRect.width),
    // (int)(borderBottomRect.y+borderBottomRect.height-1)); // bottom
    //    	g2.draw(borderTopRect);
    //    	g2.draw(borderBottomRect);

    super.paint(g2, c);
  }
Пример #20
0
  @Override
  protected void paintComponent(Graphics g) {
    Graphics2D g2 = (Graphics2D) g.create();

    if (image != null && bounds != null) {
      int width = image.getWidth(this);
      width += (int) (image.getWidth(this) * MAGNIFY_FACTOR * getZoom());

      int height = image.getHeight(this);
      height += (int) (image.getHeight(this) * MAGNIFY_FACTOR * getZoom());

      int x = (bounds.width - width) / 2;
      int y = (bounds.height - height) / 2;

      g2.setRenderingHint(
          RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);

      g2.setComposite(AlphaComposite.SrcOver.derive(1.0f - getZoom()));
      g2.drawImage(image, x + bounds.x, y + bounds.y, width, height, null);
    }

    if (showHint) {
      bounds = link.getBounds();
      Point location = new Point(0, 0);
      location = SwingUtilities.convertPoint(link, location, this);
      bounds.setLocation(location);

      Font font = new Font(Font.SANS_SERIF, Font.BOLD, 12);
      FontMetrics m = getFontMetrics(font);
      int width = m.charsWidth(hint.toCharArray(), 0, hint.length());

      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g2.setColor(Color.black);
      g2.setComposite(AlphaComposite.SrcOver.derive(hintOpacity));

      int balloon_x = bounds.x + bounds.width / 2 - width / 2 - hint_x_offset;
      int balloon_width = width + 2 * hint_width_inset;
      int balloon_center = balloon_x + balloon_width / 2;
      int balloon_height = 20;

      int[] arrow_x = new int[3];
      int[] arrow_y = new int[3];

      arrow_x[0] = balloon_center - 5;
      arrow_x[1] = balloon_center + 5;
      arrow_x[2] = balloon_center;

      arrow_y[0] = bounds.y - hint_y_pos + balloon_height;
      arrow_y[1] = bounds.y - hint_y_pos + balloon_height;
      arrow_y[2] = bounds.y - hint_y_pos + balloon_height + 10;

      g2.fillRoundRect(balloon_x, bounds.y - hint_y_pos, balloon_width, balloon_height, 15, 15);
      g2.fillPolygon(arrow_x, arrow_y, arrow_x.length);
      g2.setColor(Color.white);
      g2.setFont(font);
      g2.setComposite(AlphaComposite.SrcOver.derive(Math.min(1.0f, 2.0f * hintOpacity)));
      g2.drawString(hint, balloon_x + hint_width_inset, bounds.y - hint_y_pos + font.getSize() + 3);

      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
      g2.dispose();
    }
  }
Пример #21
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();
  }
 /** @return bounds of hint component in the layered pane. */
 public final Rectangle getBounds() {
   return myComponent.getBounds();
 }
 @Override
 public void componentResized(ComponentEvent e) {
   ParticleContainer.this.setBounds(parent.getBounds());
 }
 private void shakeEditor(JComponent parent, int dx, int dy, boolean dir) {
   final Rectangle bounds = parent.getBounds();
   parent.setBounds(
       bounds.x + (dir ? -dx : dx), bounds.y + (dir ? -dy : dy), bounds.width, bounds.height);
 }