Esempio n. 1
0
  /** Returns the dimensions required to display the icon and label. */
  private Dimension getContentSize(AbstractButton button) {
    Rectangle scratchIconRect = new Rectangle();
    Rectangle scratchTextRect = new Rectangle();
    Rectangle scratchViewRect = new Rectangle(Short.MAX_VALUE, Short.MAX_VALUE);

    FontMetrics fm = button.getFontMetrics(button.getFont());
    SwingUtilities.layoutCompoundLabel(
        fm,
        button.getText(),
        button.getIcon(),
        button.getVerticalAlignment(),
        button.getHorizontalAlignment(),
        button.getVerticalTextPosition(),
        button.getHorizontalTextPosition(),
        scratchViewRect,
        scratchIconRect,
        scratchTextRect,
        button.getIconTextGap());

    Insets textInsets = getTextPadding();
    scratchTextRect.y -= textInsets.top;
    scratchTextRect.x -= textInsets.left;
    scratchTextRect.width += textInsets.left + textInsets.right;
    scratchTextRect.height += textInsets.top + textInsets.bottom;

    Insets iconInsets = getIconPadding();
    scratchIconRect.y -= iconInsets.top;
    scratchIconRect.x -= iconInsets.left;
    scratchIconRect.width += iconInsets.left + iconInsets.right;
    scratchIconRect.height += iconInsets.top + iconInsets.bottom;

    Rectangle sum = getSum(new Rectangle[] {scratchIconRect, scratchTextRect});
    return new Dimension(sum.width, sum.height);
  }
  /** Assumes that the component innards, max position, etc. are up-to-date. */
  private Rectangle getGenericBox(Rectangle r) {
    if (r == null) {
      r = new Rectangle();
    }

    if (progressBar.getOrientation() == JProgressBar.HORIZONTAL) {
      r.width = getBoxLength(componentInnards.width, componentInnards.height);
      if (r.width < 0) {
        r = null;
      } else {
        r.height = componentInnards.height;
        r.y = componentInnards.y;
      }
      // end of HORIZONTAL

    } else { // VERTICAL progress bar
      r.height = getBoxLength(componentInnards.height, componentInnards.width);
      if (r.height < 0) {
        r = null;
      } else {
        r.width = componentInnards.width;
        r.x = componentInnards.x;
      }
    } // end of VERTICAL

    return r;
  }
Esempio n. 3
0
  private String layout(AbstractButton b, FontMetrics fm, int width, int height) {
    Insets i = b.getInsets();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    textRect.x = textRect.y = textRect.width = textRect.height = 0;
    iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;

    // layout the text and icon
    return SwingUtilities.layoutCompoundLabel(
        b,
        fm,
        b.getText(),
        b.getIcon(),
        b.getVerticalAlignment(),
        b.getHorizontalAlignment(),
        b.getVerticalTextPosition(),
        b.getHorizontalTextPosition(),
        viewRect,
        iconRect,
        textRect,
        b.getText() == null ? 0 : b.getIconTextGap());
  }
  public Rectangle getVisualBounds(JComponent c, int type, int width, int height) {
    Rectangle bounds = new Rectangle(0, 0, width, height);
    if (type == VisuallyLayoutable.CLIP_BOUNDS) {
      return bounds;
    }

    AbstractButton b = (AbstractButton) c;

    if (type == VisuallyLayoutable.COMPONENT_BOUNDS
        && b.getBorder() != null
        && b.isBorderPainted()) {
      Border border = b.getBorder();
      if (border instanceof BackgroundBorder) {
        border = ((BackgroundBorder) border).getBackgroundBorder();
        if (border instanceof VisualMargin) {
          InsetsUtil.subtractInto(((VisualMargin) border).getVisualMargin(c), bounds);
        } else if (border instanceof QuaquaButtonBorder) {
          InsetsUtil.subtractInto(((QuaquaButtonBorder) border).getVisualMargin(c), bounds);
        }
      }
      return bounds;
    }

    String text = b.getText();
    boolean isEmpty = (text == null || text.length() == 0);
    if (isEmpty) {
      text = " ";
    }
    Icon icon = (b.isEnabled()) ? b.getIcon() : b.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    FontMetrics fm = c.getFontMetrics(c.getFont());
    Insets insets = c.getInsets(viewInsets);

    viewR.x = insets.left;
    viewR.y = insets.top;
    viewR.width = width - (insets.left + insets.right);
    viewR.height = height - (insets.top + insets.bottom);

    iconR.x = iconR.y = iconR.width = iconR.height = 0;
    textR.x = textR.y = textR.width = textR.height = 0;

    String clippedText = layoutCL(b, fm, text, icon, viewR, iconR, textR);

    Rectangle textBounds = Fonts.getPerceivedBounds(text, c.getFont(), c);
    if (isEmpty) {
      textBounds.width = 0;
    }
    int ascent = fm.getAscent();
    textR.x += textBounds.x;
    textR.width = textBounds.width;
    textR.y += ascent + textBounds.y;
    textR.height -= fm.getHeight() - textBounds.height;

    bounds.setBounds(textR);
    return bounds;
  }
Esempio n. 5
0
 private static void resetRects(JComponent c, int height) {
   Insets insets = c.getInsets();
   viewRect.x = insets.left;
   viewRect.y = insets.top;
   viewRect.width = c.getWidth() - (insets.right + viewRect.x);
   viewRect.height = height - (insets.bottom + viewRect.y);
   textRect.x = textRect.y = textRect.width = textRect.height = 0;
   iconRect.x = iconRect.y = iconRect.width = iconRect.height = 0;
 }
Esempio n. 6
0
  @Override
  public void paint(Graphics g, JComponent c) {
    JButton button = (JButton) c;
    String text = button.getText();
    Icon icon = (button.isEnabled()) ? button.getIcon() : button.getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return;
    }

    FontMetrics fm = g.getFontMetrics();
    paintViewInsets = c.getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;

    // Use inverted height &amp; width
    paintViewR.height = c.getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.width = c.getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
    paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;

    Graphics2D g2 = (Graphics2D) g;
    AffineTransform tr = g2.getTransform();

    if (angle == 90) {
      g2.rotate(Math.PI / 2);
      g2.translate(0, -c.getWidth());
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    } else if (angle == 270) {
      g2.rotate(-Math.PI / 2);
      g2.translate(-c.getHeight(), 0);
      paintViewR.x = c.getHeight() / 2 - (int) fm.getStringBounds(text, g).getWidth() / 2;
      paintViewR.y = c.getWidth() / 2 - (int) fm.getStringBounds(text, g).getHeight() / 2;
    }

    if (icon != null) {
      icon.paintIcon(c, g, paintIconR.x, paintIconR.y);
    }

    if (text != null) {
      int textX = paintTextR.x;
      int textY = paintTextR.y + fm.getAscent();

      if (button.isEnabled()) {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      } else {
        paintText(g, c, new Rectangle(paintViewR.x, paintViewR.y, textX, textY), text);
      }
    }

    g2.setTransform(tr);
  }
Esempio n. 7
0
 /**
  * Updates painted label layout and returns clipped or full label text.
  *
  * @param label label to process
  * @param fm label font metrics
  * @param width label width
  * @param height label height
  * @return clipped or full label text
  */
 protected String layout(final E label, final FontMetrics fm, final int width, final int height) {
   final Insets insets = label.getInsets(null);
   final String text = label.getText();
   final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
   final Rectangle paintViewR = new Rectangle();
   paintViewR.x = insets.left;
   paintViewR.y = insets.top;
   paintViewR.width = width - (insets.left + insets.right);
   paintViewR.height = height - (insets.top + insets.bottom);
   paintIconR.x = paintIconR.y = paintIconR.width = paintIconR.height = 0;
   paintTextR.x = paintTextR.y = paintTextR.width = paintTextR.height = 0;
   return layoutCL(label, fm, text, icon, paintViewR, paintIconR, paintTextR);
 }
  @Override
  public void mouseMoved(MouseEvent e) {
    final MouseEvent event = SwingUtilities.convertMouseEvent(e.getComponent(), e, getParent());
    final boolean insideRec = getBounds().contains(event.getPoint());
    boolean buttonsNotPressed =
        (e.getModifiersEx()
                & (InputEvent.BUTTON1_DOWN_MASK
                    | InputEvent.BUTTON2_DOWN_MASK
                    | InputEvent.BUTTON3_DOWN_MASK))
            == 0;
    if (!myPopupIsShowing && insideRec && buttonsNotPressed) {
      showPopup(null, false);
    } else if (myPopupIsShowing && !insideRec) {
      final Component over =
          SwingUtilities.getDeepestComponentAt(e.getComponent(), e.getX(), e.getY());
      JPopupMenu popup = myUnderPopup.isShowing() ? myUnderPopup : myAbovePopup;
      if (over != null && popup.isShowing()) {
        final Rectangle rec = new Rectangle(popup.getLocationOnScreen(), popup.getSize());
        int delta = 15;
        rec.x -= delta;
        rec.width += delta * 2;
        rec.y -= delta;
        rec.height += delta * 2;

        final Point eventPoint = e.getPoint();
        SwingUtilities.convertPointToScreen(eventPoint, e.getComponent());

        if (rec.contains(eventPoint)) {
          return;
        }
      }

      closePopup();
    }
  }
Esempio n. 9
0
  public TabSpawnable spawn() {
    JFrame f = new JFrame();
    f.getContentPane().setLayout(new BorderLayout());
    f.setTitle(_title);
    TabSpawnable newPanel = (TabSpawnable) clone();
    if (newPanel == null) return null; // failed to clone
    newPanel.setTitle(_title);
    if (newPanel instanceof TabToDoTarget) {
      TabToDoTarget me = (TabToDoTarget) this;
      TabToDoTarget it = (TabToDoTarget) newPanel;
      it.setTarget(me.getTarget());
    } else if (newPanel instanceof TabModelTarget) {
      TabModelTarget me = (TabModelTarget) this;
      TabModelTarget it = (TabModelTarget) newPanel;
      it.setTarget(me.getTarget());
    }
    f.getContentPane().add(newPanel, BorderLayout.CENTER);
    Rectangle bounds = getBounds();
    bounds.height += OVERLAPP * 2;
    f.setBounds(bounds);

    Point loc = new Point(0, 0);
    SwingUtilities.convertPointToScreen(loc, this);
    loc.y -= OVERLAPP;
    f.setLocation(loc);
    f.setVisible(true);

    if (_tear && (getParent() instanceof JTabbedPane)) ((JTabbedPane) getParent()).remove(this);

    return newPanel;
  }
  public void zoomIn() {
    Dimension asz = this.getSize();
    int maxzf = 3;
    int coef = 1;
    int r;

    cmdline =
        "/bin/sh get.sh "
            + j2kfilename
            + " "
            + iw
            + " "
            + ih
            + " "
            + rect.x
            + " "
            + rect.y
            + " "
            + rect.width
            + " "
            + rect.height;
    Exec.execPrint(cmdline);

    rect.x = rect.y = rect.width = rect.height = 0;

    img = pgm.open("out.pgm");

    iw = img.getWidth(this);
    ih = img.getHeight(this);
    bi = new BufferedImage(iw, ih, BufferedImage.TYPE_INT_RGB);
    big = bi.createGraphics();
    selected = 0;
    fullRefresh = true;
    repaint();
  }
Esempio n. 11
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);
  }
Esempio n. 12
0
  public void addClient() {
    client =
        new Canvas() {
          public void paint(Graphics g) {
            super.paint(g);
          }
        };
    client.setBackground(new Color(30, 220, 40));
    clientCont.add(client);
    clientCont.validate();
    final ComponentAccessor acc = AWTAccessor.getComponentAccessor();
    WindowIDProvider pid = (WindowIDProvider) acc.getPeer(client);
    log.fine("Added XEmbed server(Canvas) with X window ID " + pid.getWindow());
    Rectangle toFocusBounds = toFocus.getBounds();
    toFocusBounds.setLocation(toFocus.getLocationOnScreen());
    f.validate();

    // KDE doesn't accept clicks on title as activation - click below title
    Rectangle fbounds = f.getBounds();
    fbounds.y += f.getInsets().top;
    fbounds.height -= f.getInsets().top;

    Process proc =
        startClient(
            new Rectangle[] {
              fbounds,
              dummy.getBounds(),
              toFocusBounds,
              new Rectangle(b_modal.getLocationOnScreen(), b_modal.getSize()),
              new Rectangle(10, 130, 20, 20)
            },
            pid.getWindow());
    new ClientWatcher(client, proc, clientCont).start();
  }
Esempio n. 13
0
  @Override
  public void setBounds(int x, int y, int w, int h, int op) {

    if ((op & NO_EMBEDDED_CHECK) == 0 && getPeerType() == PeerType.VIEW_EMBEDDED_FRAME) {
      return;
    }

    if ((op & SET_CLIENT_SIZE) != 0) {
      // SET_CLIENT_SIZE is only applicable to window peers, so handle it here
      // instead of pulling 'insets' field up to LWComponentPeer
      // no need to add insets since Window's notion of width and height includes insets.
      op &= ~SET_CLIENT_SIZE;
      op |= SET_SIZE;
    }

    // Don't post ComponentMoved/Resized and Paint events
    // until we've got a notification from the delegate
    Rectangle cb = constrainBounds(x, y, w, h);

    Rectangle newBounds = new Rectangle(getBounds());
    if ((op & (SET_LOCATION | SET_BOUNDS)) != 0) {
      newBounds.x = cb.x;
      newBounds.y = cb.y;
    }
    if ((op & (SET_SIZE | SET_BOUNDS)) != 0) {
      newBounds.width = cb.width;
      newBounds.height = cb.height;
    }
    // Native system could constraint bounds, so the peer wold be updated in the callback
    platformWindow.setBounds(newBounds.x, newBounds.y, newBounds.width, newBounds.height);
  }
  public TaskbarPositionTest() {
    super("Use CTRL-down to show a JPopupMenu");
    setContentPane(panel = createContentPane());
    setJMenuBar(createMenuBar("1 - First Menu", true));
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    // CTRL-down will show the popup.
    panel
        .getInputMap()
        .put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, InputEvent.CTRL_MASK), "OPEN_POPUP");
    panel.getActionMap().put("OPEN_POPUP", new PopupHandler());

    pack();

    Toolkit toolkit = Toolkit.getDefaultToolkit();
    fullScreenBounds = new Rectangle(new Point(), toolkit.getScreenSize());
    screenBounds = new Rectangle(new Point(), toolkit.getScreenSize());

    // Place the frame near the bottom. This is a pretty wild guess.
    this.setLocation(0, (int) screenBounds.getHeight() - 2 * this.getHeight());

    // Reduce the screen bounds by the insets.
    GraphicsConfiguration gc = this.getGraphicsConfiguration();
    if (gc != null) {
      Insets screenInsets = toolkit.getScreenInsets(gc);
      screenBounds = gc.getBounds();
      screenBounds.width -= (screenInsets.left + screenInsets.right);
      screenBounds.height -= (screenInsets.top + screenInsets.bottom);
      screenBounds.x += screenInsets.left;
      screenBounds.y += screenInsets.top;
    }

    setVisible(true);
  }
Esempio n. 15
0
  /**
   * Damages the area surrounding the caret to cause it to be repainted in a new location. If
   * paint() is reimplemented, this method should also be reimplemented. This method should update
   * the caret bounds (x, y, width, and height).
   *
   * @param r the current location of the caret
   * @see #paint
   */
  @Override
  protected synchronized void damage(final Rectangle r) {
    if (r == null || fPainting) return;

    x = r.x - 4;
    y = r.y;
    width = 10;
    height = r.height;

    // Don't damage the border area.  We can't paint a partial border, so get the
    // intersection of the caret rectangle and the component less the border, if any.
    final Rectangle caretRect = new Rectangle(x, y, width, height);
    final Border border = getComponent().getBorder();
    if (border != null) {
      final Rectangle alloc = getComponent().getBounds();
      alloc.x = alloc.y = 0;
      final Insets borderInsets = border.getBorderInsets(getComponent());
      alloc.x += borderInsets.left;
      alloc.y += borderInsets.top;
      alloc.width -= borderInsets.left + borderInsets.right;
      alloc.height -= borderInsets.top + borderInsets.bottom;
      Rectangle2D.intersect(caretRect, alloc, caretRect);
    }
    x = caretRect.x;
    y = caretRect.y;
    width = Math.max(caretRect.width, 1);
    height = Math.max(caretRect.height, 1);
    repaint();
  }
 @Override
 public Rectangle getCellRect(int row, int column, boolean includeSpacing) {
   Rectangle r = super.getCellRect(row, column, includeSpacing);
   int height = table.getRowHeight(row);
   if (getRowHeight(row) != height) setRowHeight(row, height);
   r.height = height;
   return r;
 }
 public void layoutContainer(Container parent) {
   if (motifGetEditor() != null) {
     Rectangle cvb = rectangleForCurrentValue();
     cvb.x += 1;
     cvb.y += 1;
     cvb.width -= 1;
     cvb.height -= 2;
     motifGetEditor().setBounds(cvb);
   }
 }
 protected Dimension getPreferredMenuItemSize(
     JComponent comp, Icon checkIcon, Icon arrowIcon, int defaultTextIconGap) {
   JMenu jMenu = (JMenu) comp;
   Icon icon1 = getIcon();
   Icon icon2 = getAllowedIcon();
   String text = jMenu.getText();
   Font font = jMenu.getFont();
   FontMetrics fontmetrics = jMenu.getToolkit().getFontMetrics(font);
   resetRects();
   layoutMenuItem(
       fontmetrics,
       text,
       icon1,
       icon2,
       arrowIcon,
       jMenu.getVerticalAlignment(),
       jMenu.getHorizontalAlignment(),
       jMenu.getVerticalTextPosition(),
       jMenu.getHorizontalTextPosition(),
       ourViewRect,
       ourIconRect,
       ourTextRect,
       ourAcceleratorRect,
       ourCheckIconRect,
       ourArrowIconRect,
       text != null ? defaultTextIconGap : 0,
       defaultTextIconGap);
   ourPreferredSizeRect.setBounds(ourTextRect);
   ourPreferredSizeRect =
       SwingUtilities.computeUnion(
           ourIconRect.x,
           ourIconRect.y,
           ourIconRect.width,
           ourIconRect.height,
           ourPreferredSizeRect);
   if (useCheckAndArrow()) {
     ourPreferredSizeRect.width += myMaxGutterIconWidth;
     ourPreferredSizeRect.width += defaultTextIconGap;
     ourPreferredSizeRect.width += defaultTextIconGap;
     ourPreferredSizeRect.width += ourArrowIconRect.width;
   }
   ourPreferredSizeRect.width += 2 * defaultTextIconGap;
   Insets insets = jMenu.getInsets();
   if (insets != null) {
     ourPreferredSizeRect.width += insets.left + insets.right;
     ourPreferredSizeRect.height += insets.top + insets.bottom;
   }
   if (ourPreferredSizeRect.width % 2 == 0) {
     ourPreferredSizeRect.width++;
   }
   if (ourPreferredSizeRect.height % 2 == 0) {
     ourPreferredSizeRect.height++;
   }
   return ourPreferredSizeRect.getSize();
 }
Esempio n. 19
0
  protected Rectangle getVisibleEditorRect() {
    final Rectangle rect = super.getVisibleEditorRect();
    if (rect == null) return null;

    if (!getComponent().isOpaque()) {
      rect.y -= 3;
      rect.height += 6;
    }

    return rect;
  }
  @Override
  protected void paintComponent(Graphics g) {
    super.paintComponent(g);
    if (UIUtil.isUnderAquaLookAndFeel()) {
      return;
    }

    switch (getState()) {
      case DONT_CARE:
        Icon icon = getIcon();
        if (icon == null) {
          icon = UIManager.getIcon("CheckBox.icon");
        }
        if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) {
          icon = EmptyIcon.create(20, 18);
        }
        if (icon != null) {
          final Insets i = getInsets();
          final Rectangle r = getBounds();
          final Rectangle r1 = new Rectangle();
          r1.x = i.left;
          r1.y = i.top;
          r1.width = r.width - (i.right + r1.x);
          r1.height = r.height - (i.bottom + r1.y);

          final Rectangle r2 = new Rectangle();
          final Rectangle r3 = new Rectangle();
          SwingUtilities.layoutCompoundLabel(
              this,
              getFontMetrics(getFont()),
              getText(),
              icon,
              getVerticalAlignment(),
              getHorizontalAlignment(),
              getVerticalTextPosition(),
              getHorizontalTextPosition(),
              r1,
              r2,
              r3,
              getText() == null ? 0 : getIconTextGap());

          // selected table cell: do not paint white on white
          g.setColor(UIUtil.getTreeForeground());
          int height = r2.height / 10;
          int width = r2.width / 3;
          g.fillRect(
              r2.x + r2.width / 2 - width / 2, r2.y + r2.height / 2 - height / 2, width, height);
        }
        break;
      default:
        break;
    }
  }
Esempio n. 21
0
  /** {@inheritDoc} */
  @Override
  public int getBaseline(JComponent c, int width, int height) {
    if (c == null) {
      throw new NullPointerException("Component must be non-null");
    }
    if (width < 0 || height < 0) {
      throw new IllegalArgumentException("Width and height must be >= 0");
    }
    AbstractButton b = (AbstractButton) c;
    String text = b.getText();
    if (text == null || "".equals(text)) {
      return -1;
    }
    Insets i = b.getInsets();
    Rectangle viewRect = new Rectangle();
    Rectangle textRect = new Rectangle();
    Rectangle iconRect = new Rectangle();
    viewRect.x = i.left;
    viewRect.y = i.top;
    viewRect.width = width - (i.right + viewRect.x);
    viewRect.height = height - (i.bottom + viewRect.y);

    // layout the text and icon
    SynthContext context = getContext(b);
    FontMetrics fm = context.getComponent().getFontMetrics(context.getStyle().getFont(context));
    context
        .getStyle()
        .getGraphicsUtils(context)
        .layoutText(
            context,
            fm,
            b.getText(),
            b.getIcon(),
            b.getHorizontalAlignment(),
            b.getVerticalAlignment(),
            b.getHorizontalTextPosition(),
            b.getVerticalTextPosition(),
            viewRect,
            iconRect,
            textRect,
            b.getIconTextGap());
    View view = (View) b.getClientProperty(BasicHTML.propertyKey);
    int baseline;
    if (view != null) {
      baseline = BasicHTML.getHTMLBaseline(view, textRect.width, textRect.height);
      if (baseline >= 0) {
        baseline += textRect.y;
      }
    } else {
      baseline = textRect.y + fm.getAscent();
    }
    return baseline;
  }
Esempio n. 22
0
  /** Draws the panel. */
  public void paintComponent(Graphics g) {
    super.paintComponent(g);

    Log.setTrace(true);
    //      Log.trace(this, getBounds().toString());
    //      Log.trace(this, getInsets().toString());

    // respect borders
    Insets insets = getInsets();
    Rectangle r = getBounds();
    r.x += insets.left;
    r.y += insets.top;
    r.width -= insets.left + insets.right;
    r.height -= insets.top + insets.bottom;

    // System.out.println("paintComponent" + count++);

    g.setColor(Color.black);
    DirectedGraph<LayoutNode, DirectedEdge<LayoutNode>> graph = fLayout.graph();

    // draw edges
    Iterator<DirectedEdge<LayoutNode>> edgeIter = graph.edgeIterator();
    while (edgeIter.hasNext()) {
      DirectedEdge<LayoutNode> edge = edgeIter.next();
      // Log.trace(this, edge.toString());
      LayoutNode source = (LayoutNode) edge.source();
      LayoutNode target = (LayoutNode) edge.target();
      int x1 = source.getX() * 80 + 30;
      int y1 = 50 + source.fLayer * 50;
      //          if (source.isDummy() )
      //          x1 += 5;
      int x2 = target.getX() * 80 + 30;
      int y2 = 50 + target.fLayer * 50;
      //          if (target.isDummy() )
      //          x2 += 5;
      g.drawLine(x1, y1, x2, y2);
    }

    // draw nodes
    Iterator<LayoutNode> nodeIter = graph.iterator();
    while (nodeIter.hasNext()) {
      LayoutNode node = nodeIter.next();
      if (node.isDummy()) continue;
      int x = node.getX() * 80 + 30;
      int y = 50 + node.fLayer * 50;
      g.setColor(Color.white);
      g.fillRect(x - 10, y - 10, 20, 20);
      g.setColor(Color.black);
      g.drawRect(x - 10, y - 10, 20, 20);
      g.drawString(node.toString(), x - 7, y + 8);
    }
  }
Esempio n. 23
0
  /** {@inheritDoc} */
  @Override
  public Dimension getPreferredSize(final E label) {
    final String text = label.getText();
    final Icon icon = (label.isEnabled()) ? label.getIcon() : label.getDisabledIcon();
    final Insets insets = label.getInsets(null);
    final Font font = label.getFont();

    final int dx = insets.left + insets.right;
    final int dy = insets.top + insets.bottom;

    if ((icon == null) && ((text == null) || ((text != null) && (font == null)))) {
      return new Dimension(dx, dy);
    } else if ((text == null) || ((icon != null) && (font == null))) {
      return new Dimension(icon.getIconWidth() + dx, icon.getIconHeight() + dy);
    } else {
      final FontMetrics fm = label.getFontMetrics(font);

      final Rectangle iconR = new Rectangle();
      final Rectangle textR = new Rectangle();
      final Rectangle viewR = new Rectangle();
      iconR.x = iconR.y = iconR.width = iconR.height = 0;
      textR.x = textR.y = textR.width = textR.height = 0;
      viewR.x = dx;
      viewR.y = dy;
      viewR.width = viewR.height = Short.MAX_VALUE;

      layoutCL(label, fm, text, icon, viewR, iconR, textR);

      final int x1 = Math.min(iconR.x, textR.x);
      final int x2 = Math.max(iconR.x + iconR.width, textR.x + textR.width);
      final int y1 = Math.min(iconR.y, textR.y);
      final int y2 = Math.max(iconR.y + iconR.height, textR.y + textR.height);
      final Dimension rv = new Dimension(x2 - x1, y2 - y1);
      rv.width += dx;
      rv.height += dy;
      return rv;
    }
  }
Esempio n. 24
0
 private void adjust(
     Rectangle bounds, Dimension min, int deltaX, int deltaY, int deltaWidth, int deltaHeight) {
   bounds.x += deltaX;
   bounds.y += deltaY;
   bounds.width += deltaWidth;
   bounds.height += deltaHeight;
   if (min != null) {
     if (bounds.width < min.width) {
       int correction = min.width - bounds.width;
       if (deltaX != 0) {
         bounds.x -= correction;
       }
       bounds.width = min.width;
     }
     if (bounds.height < min.height) {
       int correction = min.height - bounds.height;
       if (deltaY != 0) {
         bounds.y -= correction;
       }
       bounds.height = min.height;
     }
   }
 }
  @Override
  protected void paintComponent(final Graphics g) {
    String s = getText();
    final Rectangle bounds = getBounds();
    if (UIUtil.isUnderDarcula()) {
      g.setColor(UIUtil.getPanelBackground());
      g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
    }
    if (s == null) return;
    final Insets insets = getInsets();

    final Graphics2D g2 = (Graphics2D) g;
    g2.setFont(getFont());

    UIUtil.applyRenderingHints(g2);

    final FontMetrics fm = g2.getFontMetrics();
    final int sWidth = fm.stringWidth(s);

    int x = insets.left;
    if (myAlignment == Component.CENTER_ALIGNMENT || myAlignment == Component.RIGHT_ALIGNMENT) {
      x =
          myAlignment == Component.CENTER_ALIGNMENT
              ? (bounds.width - sWidth) / 2
              : bounds.width - insets.right - sWidth;
    }

    final Rectangle textR = new Rectangle();
    final Rectangle iconR = new Rectangle();
    final Rectangle viewR = new Rectangle(bounds);
    textR.x = textR.y = textR.width = textR.height = 0;

    viewR.width -= insets.left;
    viewR.width -= insets.right;

    final int maxWidth = bounds.width - insets.left - insets.right;
    if (sWidth > maxWidth) {
      s = truncateText(s, bounds, fm, textR, iconR, maxWidth);
    }

    final int y = UIUtil.getStringY(s, bounds, g2);
    if (SystemInfo.isMac && !UIUtil.isUnderDarcula() && myDecorate) {
      g2.setColor(myCustomColor == null ? Gray._215 : myCustomColor);
      g2.drawString(s, x, y + 1);
    }

    g2.setColor(myCustomColor == null ? getForeground() : myCustomColor);
    g2.drawString(s, x, y);
  }
Esempio n. 26
0
    private static boolean computeIntersection(Rectangle dest, int rx, int ry, int rw, int rh) {
      int x1 = Math.max(rx, dest.x);
      int x2 = Math.min(rx + rw, dest.x + dest.width);
      int y1 = Math.max(ry, dest.y);
      int y2 = Math.min(ry + rh, dest.y + dest.height);
      dest.x = x1;
      dest.y = y1;
      dest.width = x2 - x1;
      dest.height = y2 - y1;

      if (dest.width <= 0 || dest.height <= 0) {
        return false;
      }
      return true;
    }
  protected Rectangle rectangleForArrowIcon() {
    Rectangle b = comboBox.getBounds();
    Border border = comboBox.getBorder();
    Insets in;
    if (border != null) {
      in = border.getBorderInsets(comboBox);
    } else {
      in = new Insets(0, 0, 0, 0);
    }
    b.x = in.left;
    b.y = in.top;
    b.width -= (in.left + in.right);
    b.height -= (in.top + in.bottom);

    if (MotifGraphicsUtils.isLeftToRight(comboBox)) {
      b.x = b.x + b.width - HORIZ_MARGIN - arrowIcon.getIconWidth();
    } else {
      b.x += HORIZ_MARGIN;
    }
    b.y = b.y + (b.height - arrowIcon.getIconHeight()) / 2;
    b.width = arrowIcon.getIconWidth();
    b.height = arrowIcon.getIconHeight();
    return b;
  }
  public Rectangle getScreenViewableBounds(GraphicsDevice gd) {

    Rectangle bounds = new Rectangle(0, 0, 0, 0);

    if (gd != null) {
      GraphicsConfiguration gc = gd.getDefaultConfiguration();
      bounds = gc.getBounds();
      Insets insets = Toolkit.getDefaultToolkit().getScreenInsets(gc);

      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= (insets.left + insets.right);
      bounds.height -= (insets.top + insets.bottom);
    }
    return bounds;
  }
  /** This method is taken from inside the source of JLabel (in the inner AccessibleJLabel class) */
  private Rectangle getTextRectangle() {
    final String text = getText();
    final Icon icon = (isEnabled()) ? getIcon() : getDisabledIcon();

    if ((icon == null) && (text == null)) {
      return null;
    }

    final Rectangle paintIconR = new Rectangle();
    final Rectangle paintTextR = new Rectangle();
    final Rectangle paintViewR = new Rectangle();

    Insets paintViewInsets = new Insets(0, 0, 0, 0);
    paintViewInsets = getInsets(paintViewInsets);

    paintViewR.x = paintViewInsets.left;
    paintViewR.y = paintViewInsets.top;
    paintViewR.width = getWidth() - (paintViewInsets.left + paintViewInsets.right);
    paintViewR.height = getHeight() - (paintViewInsets.top + paintViewInsets.bottom);

    final Graphics g = getGraphics();
    if (g == null) {
      return null;
    }

    SwingUtilities.layoutCompoundLabel(
        this,
        g.getFontMetrics(),
        text,
        icon,
        getVerticalAlignment(),
        getHorizontalAlignment(),
        getVerticalTextPosition(),
        getHorizontalTextPosition(),
        paintViewR,
        paintIconR,
        paintTextR,
        getIconTextGap());

    final Rectangle returnValue = new Rectangle(paintTextR);
    returnValue.add(paintIconR);

    return returnValue;
  }
  public void paint(Graphics g) {
    // repaint the whole transformer in case the view component was repainted
    Rectangle clipBounds = g.getClipBounds();
    if (clipBounds != null && !clipBounds.equals(visibleRect)) {
      repaint();
    }
    // clear the background
    g.setColor(getBackground());
    g.fillRect(0, 0, getWidth(), getHeight());

    if (view != null && at.getDeterminant() != 0) {
      Graphics2D g2 = (Graphics2D) g.create();
      Insets insets = getInsets();
      Rectangle bounds = getBounds();

      // don't forget about insets
      bounds.x += insets.left;
      bounds.y += insets.top;
      bounds.width -= insets.left + insets.right;
      bounds.height -= insets.top + insets.bottom;
      double centerX1 = bounds.getCenterX();
      double centerY1 = bounds.getCenterY();

      Rectangle tb = getTransformedSize();
      double centerX2 = tb.getCenterX();
      double centerY2 = tb.getCenterY();

      // set antialiasing by default
      g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      if (renderingHints != null) {
        g2.addRenderingHints(renderingHints);
      }
      // translate it to the center of the view component again
      double tx = centerX1 - centerX2 - getX();
      double ty = centerY1 - centerY2 - getY();
      g2.translate((int) tx, (int) ty);
      g2.transform(at);
      view.paint(g2);
      g2.dispose();
    }
    // paint the border
    paintBorder(g);
  }