Ejemplo n.º 1
0
  public final void setLocation(int x, int y) {
    super.setLocation(x, y);

    if (getModelNode() != null) {
      getModelNode().setCenter(x + getWidth() / 2, y + getHeight() / 2);
    }
  }
Ejemplo n.º 2
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);
 }
Ejemplo n.º 3
0
    /** Resets the <code>Popup</code> to an initial state. */
    void reset(Component owner, Component contents, int ownerX, int ownerY) {
      super.reset(owner, contents, ownerX, ownerY);

      JComponent component = (JComponent) getComponent();

      component.setOpaque(contents.isOpaque());
      component.setLocation(ownerX, ownerY);
      component.add(contents, BorderLayout.CENTER);
      contents.invalidate();
      pack();
    }
  public void setSimulator(HackSimulatorGUI simulator) {
    ((JComponent) simulator).setLocation(0, TOOLBAR_HEIGHT);
    this.getContentPane().add((JComponent) simulator, null);
    ((JComponent) simulator).revalidate();
    repaint();

    if (simulator.getUsageFileName() != null) {
      usageWindow = new HTMLViewFrame(simulator.getUsageFileName());
      usageWindow.setSize(450, 430);
    }

    if (simulator.getAboutFileName() != null) {
      aboutWindow = new HTMLViewFrame(simulator.getAboutFileName());
      aboutWindow.setSize(450, 420);
    }
  }
  @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();
      }
    }
  }
Ejemplo n.º 6
0
 public void setLocation(int x, int y) {
   shift_x = x;
   shift_y = y;
   super.setLocation(x, y);
 }
Ejemplo n.º 7
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();
  }
Ejemplo n.º 8
0
 private void addAndSet(JComponent j, int x, int y, int length, int width) {
   j.setLocation(x, y);
   j.setSize(length, width);
   this.add(j);
 }
Ejemplo n.º 9
0
  /**
   * Causes the popup to be displayed at the specified location.
   *
   * @param component The component whose cooredinate system is to be used.
   * @param x The horizontal location of the popup
   * @param y The vertical location of the popup.
   */
  public void showPopup(JComponent component, int x, int y) {
    // Get the root (JFrame probably)
    Component rootComp = SwingUtilities.getRoot(component);

    // Determine where to place the popup
    // (Left or right, top or bottom of the mouse cursor
    // We want to fit the popup within the top level frame

    int componentMaxX = (int) rootComp.getSize().width;

    int componentMaxY = (int) rootComp.getSize().height;

    int xPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).x;

    int yPosOnRoot = SwingUtilities.convertPoint(component, x, y, rootComp).y;

    // Display to the right of the mouse cursor, unless
    // there is not enough room
    int deltaX = xPosOnRoot + content.getWidth() - componentMaxX;

    if (deltaX > 0) {
      xPosOnRoot -= deltaX;

      if (xPosOnRoot < 0) {
        xPosOnRoot = 0;
      }
    }

    int deltaY = yPosOnRoot + content.getHeight() - componentMaxY;

    if (deltaY > 0) {
      yPosOnRoot -= deltaY;

      if (yPosOnRoot < 0) {
        yPosOnRoot = 0;
      }
    }

    // Convert root pos back to component pos

    int xPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).x;

    int yPos = SwingUtilities.convertPoint(rootComp, xPosOnRoot, yPosOnRoot, component).y;

    JRootPane rootPane = component.getRootPane();

    rootPane.setGlassPane(glassPane);

    // Convert the mouse point from the invoking component coordinate
    // system to the glassPane coordinate system
    Point pt = SwingUtilities.convertPoint(component, xPos, yPos, glassPane);

    // Set the location of the popup in the glass pane
    content.setLocation(pt);

    // Show the glass pane.
    glassPane.setVisible(true);

    // If the popup is set to hide automatically after a specified
    // amount of time, then reset the timer.
    if (HIDE_ON_TIMER == true) {
      timer.stop();

      timer.start();
    }
  }
Ejemplo n.º 10
0
    /**
     * Paints the border for the specified component with the specified position and size.
     *
     * @param c the component for which this border is being painted
     * @param g the paint graphics
     * @param x the x position of the painted border
     * @param y the y position of the painted border
     * @param width the width of the painted border
     * @param height the height of the painted border
     */
    public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {

      Border border = getBorder();

      if (label == null) {
        if (border != null) {
          border.paintBorder(c, g, x, y, width, height);
        }
        return;
      }

      Rectangle grooveRect =
          new Rectangle(
              x + EDGE_SPACING,
              y + EDGE_SPACING,
              width - (EDGE_SPACING * 2),
              height - (EDGE_SPACING * 2));

      Dimension labelDim = label.getPreferredSize();
      int baseline = label.getBaseline(labelDim.width, labelDim.height);
      int ascent = Math.max(0, baseline);
      int descent = labelDim.height - ascent;
      int diff;
      Insets insets;

      if (border != null) {
        insets = border.getBorderInsets(c);
      } else {
        insets = new Insets(0, 0, 0, 0);
      }

      diff = Math.max(0, ascent / 2 + TEXT_SPACING - EDGE_SPACING);
      grooveRect.y += diff;
      grooveRect.height -= diff;
      compLoc.y = grooveRect.y + insets.top / 2 - (ascent + descent) / 2 - 1;

      int justification;
      if (c.getComponentOrientation().isLeftToRight()) {
        justification = LEFT;
      } else {
        justification = RIGHT;
      }

      switch (justification) {
        case LEFT:
          compLoc.x = grooveRect.x + TEXT_INSET_H + insets.left;
          break;
        case RIGHT:
          compLoc.x =
              (grooveRect.x + grooveRect.width - (labelDim.width + TEXT_INSET_H + insets.right));
          break;
      }

      // If title is positioned in middle of border AND its fontsize
      // is greater than the border's thickness, we'll need to paint
      // the border in sections to leave space for the component's background
      // to show through the title.
      //
      if (border != null) {
        if (grooveRect.y > compLoc.y - ascent) {
          Rectangle clipRect = new Rectangle();

          // save original clip
          Rectangle saveClip = g.getClipBounds();

          // paint strip left of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(clipRect, x, y, compLoc.x - 1 - x, height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip right of text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x + labelDim.width + 1,
              y,
              x + width - (compLoc.x + labelDim.width + 1),
              height)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // paint strip below text
          clipRect.setBounds(saveClip);
          if (computeIntersection(
              clipRect,
              compLoc.x - 1,
              compLoc.y + ascent + descent,
              labelDim.width + 2,
              y + height - compLoc.y - ascent - descent)) {
            g.setClip(clipRect);
            border.paintBorder(
                c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
          }

          // restore clip
          g.setClip(saveClip);

        } else {
          border.paintBorder(c, g, grooveRect.x, grooveRect.y, grooveRect.width, grooveRect.height);
        }

        label.setLocation(compLoc);
        label.setSize(labelDim);
      }
    }
Ejemplo n.º 11
0
 /** sizes and places a JComponent so that this does not have to be done repeatedly * */
 public static JComponent formatJComponent(
     JComponent component, int width, int height, int x, int y) {
   component.setSize(width, height);
   component.setLocation(x, y);
   return component;
 }