javax.swing.border.Border#getBorderInsets ( )源码实例Demo

下面列出了javax.swing.border.Border#getBorderInsets ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: binnavi   文件: UrlLabel.java
@Override
public void paint(final Graphics g) {
  super.paint(g);

  final Border border = getBorder();

  int realLeft = 0;
  int realWidth = getWidth();

  if (border != null) {
    final Insets insets = border.getBorderInsets(this);

    realWidth -= insets.right;
    realWidth -= insets.left;
    realLeft += insets.left;
  }

  g.drawLine(realLeft, getHeight() - 2, realWidth, getHeight() - 2);
}
 
源代码2 项目: jdk8u_jdk   文件: Test6657026.java
private static void test(Border border) {
    Insets actual = border.getBorderInsets(null);
    if (NEGATIVE.equals(actual)) {
        throw new Error("unexpected insets in " + border.getClass());
    }
    Insets expected = (Insets) actual.clone();
    // modify
    actual.top++;
    actual.left++;
    actual.right++;
    actual.bottom++;
    // validate
    if (!expected.equals(border.getBorderInsets(null))) {
        throw new Error("shared insets in " + border.getClass());
    }
}
 
源代码3 项目: openjdk-jdk8u-backup   文件: Test6657026.java
private static void test(Border border) {
    Insets actual = border.getBorderInsets(null);
    if (NEGATIVE.equals(actual)) {
        throw new Error("unexpected insets in " + border.getClass());
    }
    Insets expected = (Insets) actual.clone();
    // modify
    actual.top++;
    actual.left++;
    actual.right++;
    actual.bottom++;
    // validate
    if (!expected.equals(border.getBorderInsets(null))) {
        throw new Error("shared insets in " + border.getClass());
    }
}
 
源代码4 项目: netbeans   文件: DefaultCheckListCellRenderer.java
public Component getListCellRendererComponent(JList list, Object value,
    int index, boolean isSelected, boolean cellHasFocus) {
    setComponentOrientation(list.getComponentOrientation());
    if (isSelected) {
        setBackground(list.getSelectionBackground());
        setForeground(list.getSelectionForeground());
    }
    else {
        setBackground(list.getBackground());
        setForeground(list.getForeground());
    }

    setEnabled(list.isEnabled());
    setFont(list.getFont());
    if( cellHasFocus ) {
        Border b = UIManager.getBorder("List.focusCellHighlightBorder"); //NOI18N
        if( null != b && null != b.getBorderInsets(this) )
            setBorder( b );
    } else {
        setBorder( noFocusBorder);
    }

    setText((value == null) ? "" : value.toString());
    setSelected(((CheckListModel) list.getModel()).isChecked(index));
    return this;
}
 
源代码5 项目: openjdk-8-source   文件: AquaCaret.java
/**
 * 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
 */
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();
}
 
源代码6 项目: jdk8u-dev-jdk   文件: Test6963870.java
void test(String uiName) {
    Border b = UIManager.getBorder(uiName);
    Insets i = b.getBorderInsets(null);
    if (i == null) {
        throw new RuntimeException("getBorderInsets() returns null for " + uiName);
    }
}
 
源代码7 项目: jdk8u-jdk   文件: AquaCaret.java
/**
 * 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
 */
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();
}
 
源代码8 项目: consulo   文件: ModernPasswordFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof ModernTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  }
  else {
    super.paintBackground(g);
  }
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: Test6978482.java
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
源代码10 项目: openjdk-8   文件: BasicSplitPaneDivider.java
/**
 * If a border has been set on this component, returns the
 * border's insets, else calls super.getInsets.
 *
 * @return the value of the insets property.
 * @see #setBorder
 */
public Insets getInsets() {
    Border    border = getBorder();

    if (border != null) {
        return border.getBorderInsets(this);
    }
    return super.getInsets();
}
 
源代码11 项目: hottub   文件: Test4856008.java
private static void test(Border border, Insets insets) {
    Insets result = border.getBorderInsets(getComponent(border));
    if (insets == result) {
        throw new Error("both instances are the same for " + border.getClass());
    }
    if (!insets.equals(result)) {
        throw new Error("both insets are not equal for " + border.getClass());
    }
}
 
源代码12 项目: jdk8u_jdk   文件: Test6963870.java
void test(String uiName) {
    Border b = UIManager.getBorder(uiName);
    Insets i = b.getBorderInsets(null);
    if (i == null) {
        throw new RuntimeException("getBorderInsets() returns null for " + uiName);
    }
}
 
源代码13 项目: jdk8u-jdk   文件: Test4856008.java
private static void test(Border border, Insets insets) {
    Insets result = border.getBorderInsets(getComponent(border));
    if (insets == result) {
        throw new Error("both instances are the same for " + border.getClass());
    }
    if (!insets.equals(result)) {
        throw new Error("both insets are not equal for " + border.getClass());
    }
}
 
源代码14 项目: Darcula   文件: DarculaPasswordFieldUI.java
@Override
protected void paintBackground(Graphics graphics) {
  Graphics2D g = (Graphics2D)graphics;
  final JTextComponent c = getComponent();
  final Container parent = c.getParent();
  if (parent != null) {
    g.setColor(parent.getBackground());
    g.fillRect(0, 0, c.getWidth(), c.getHeight());
  }
  final Border border = c.getBorder();
  if (border instanceof DarculaTextBorder) {
    g.setColor(c.getBackground());
    final int width = c.getWidth();
    final int height = c.getHeight();
    final Insets i = border.getBorderInsets(c);
    if (c.hasFocus()) {
      final GraphicsConfig config = new GraphicsConfig(g);
      g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
      g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);

      g.fillRoundRect(i.left - 5, i.top - 2, width - i.left - i.right + 10, height - i.top - i.bottom + 6, 5, 5);
      config.restore();
    }
    else {
      g.fillRect(i.left - 5, i.top - 2, width - i.left - i.right + 12, height - i.top - i.bottom + 6);
    }
  } else {
    super.paintBackground(g);
  }
}
 
源代码15 项目: stendhal   文件: StyledSplitPaneUI.java
/**
 * Paint highlighted borders. Meanot to be used at mouseover.
 *
 * @param g graphics
 */
private void highLightBorder(Graphics g) {
	g.setColor(style.getHighLightColor());

	Border border = style.getBorder();
	if (orientation == JSplitPane.HORIZONTAL_SPLIT) {
		int width = border.getBorderInsets(this).left;
		g.fillRect(0, 0, width, getHeight());
		g.fillRect(getWidth() - width, 0, width, getHeight());
	} else {
		int height = border.getBorderInsets(this).top;
		g.fillRect(0, 0, getWidth(), height);
		g.fillRect(0, getHeight() - height, getWidth(), height);
	}
}
 
源代码16 项目: jdk8u_jdk   文件: Test6978482.java
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
源代码17 项目: hottub   文件: Test6978482.java
public static void main(String[] args) {
    Component c = new Component() {};
    c.setBackground(Color.WHITE);
    c.setForeground(Color.BLACK);
    Graphics g = new BufferedImage(1024, 768, BufferedImage.TYPE_INT_RGB).getGraphics();
    g.setClip(0, 0, 1024, 768);
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        border.getBorderInsets(c);
        border.paintBorder(c, g, 0, 0, 1024, 768);
    }
}
 
源代码18 项目: Bytecoder   文件: BasicComboPopup.java
/**
 * Calculate the placement and size of the popup portion of the combo box based
 * on the combo box location and the enclosing screen bounds. If
 * no transformations are required, then the returned rectangle will
 * have the same values as the parameters.
 *
 * @param px starting x location
 * @param py starting y location
 * @param pw starting width
 * @param ph starting height
 * @return a rectangle which represents the placement and size of the popup
 */
protected Rectangle computePopupBounds(int px,int py,int pw,int ph) {
    Toolkit toolkit = Toolkit.getDefaultToolkit();
    Rectangle screenBounds;

    // Calculate the desktop dimensions relative to the combo box.
    GraphicsConfiguration gc = comboBox.getGraphicsConfiguration();
    Point p = new Point();
    SwingUtilities.convertPointFromScreen(p, comboBox);
    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 += (p.x + screenInsets.left);
        screenBounds.y += (p.y + screenInsets.top);
    }
    else {
        screenBounds = new Rectangle(p, toolkit.getScreenSize());
    }
    int borderHeight = 0;
    Border popupBorder = getBorder();
    if (popupBorder != null) {
        Insets borderInsets = popupBorder.getBorderInsets(this);
        borderHeight = borderInsets.top + borderInsets.bottom;
        screenBounds.width -= (borderInsets.left + borderInsets.right);
        screenBounds.height -= borderHeight;
    }
    Rectangle rect = new Rectangle(px, py, pw, ph);
    if (py + ph > screenBounds.y + screenBounds.height) {
        if (ph <= -screenBounds.y - borderHeight) {
            // popup goes above
            rect.y = -ph - borderHeight;
        } else {
            // a full screen height popup
            rect.y = screenBounds.y + Math.max(0, (screenBounds.height - ph) / 2 );
            rect.height = Math.min(screenBounds.height, ph);
        }
    }
    return rect;
}
 
源代码19 项目: pumpernickel   文件: ControlGridLayout.java
private Map<Component, Rectangle> createBlueprint(Container parent) {
	CellLayout masterLayout;
	if (group.contains(parent)) {
		masterLayout = new CellLayout();
		for (Container container : group) {
			if (container.isVisible()) {
				CellLayout cellLayout = getCellLayout(container);
				masterLayout.add(cellLayout);
			}
		}
	} else {
		masterLayout = getCellLayout(parent);
	}

	int x = 0;
	int y = 0;
	if (parent instanceof JComponent) {
		Border b = ((JComponent) parent).getBorder();
		if (b != null) {
			Insets i = b.getBorderInsets(parent);
			x = i.left;
			y = i.top;
		}
	}

	List<List<Component>> grid = createGrid(parent);

	Map<Component, Rectangle> returnValue = new HashMap<>();
	int y0 = y;
	for (int row = 0; row < grid.size(); row++) {
		int x0 = x;
		for (int column = 0; column < grid.get(row).size(); column++) {
			Component c = grid.get(row).get(column);
			Dimension d = c.getPreferredSize();
			Rectangle r = new Rectangle(x0, y0, d.width, d.height);
			// masterLayout.columnWidths[column],
			// masterLayout.rowHeights[row]);
			returnValue.put(c, r);

			x0 += masterLayout.columnWidths[column];
			x0 += horizontalPadding;
		}
		y0 += masterLayout.rowHeights[row];
		y0 += verticalPadding;
	}

	return returnValue;
}
 
源代码20 项目: visualvm   文件: ConnectionsCustomizer.java
private static Border emptyBorder(Border border) {
    Insets i = border == null ? null : border.getBorderInsets(new JTextField());
    return i == null ? BorderFactory.createEmptyBorder() :
           BorderFactory.createEmptyBorder(i.top, i.left, i.bottom, i.right);
}