javax.swing.border.AbstractBorder Java Examples

The following examples show how to use javax.swing.border.AbstractBorder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PainterSupport.java    From weblaf with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns {@link java.awt.Component.BaselineResizeBehavior} indicating how baseline of a {@link Component} changes when resized.
 *
 * @param component   {@link JComponent}
 * @param componentUI {@link ComponentUI}
 * @return {@link java.awt.Component.BaselineResizeBehavior} indicating how baseline of a {@link Component} changes when resized
 */
@NotNull
public static Component.BaselineResizeBehavior getBaselineResizeBehavior ( @NotNull final JComponent component,
                                                                           @NotNull final ComponentUI componentUI )
{
    final Component.BaselineResizeBehavior behavior;
    final Painter painter = getPainter ( component );
    if ( painter != null )
    {
        behavior = painter.getBaselineResizeBehavior ( component, componentUI );
    }
    else
    {
        final Border border = component.getBorder ();
        if ( border instanceof AbstractBorder )
        {
            final AbstractBorder abstractBorder = ( AbstractBorder ) border;
            behavior = abstractBorder.getBaselineResizeBehavior ( component );
        }
        else
        {
            behavior = Component.BaselineResizeBehavior.OTHER;
        }
    }
    return behavior;
}
 
Example #2
Source File: DndTableCellRenderer.java    From ghidra with Apache License 2.0 6 votes vote down vote up
@Override
public Insets getBorderInsets(Component c, Insets insets) {
	if (under == null) {
		throw new IllegalStateException("Must set under border");
	}
	if (under instanceof AbstractBorder) {
		// Repeat the sin from JComponent.java:1847 (OpenJDK-1.8.0_25)
		// that necessitate this method in the first place...
		return ((AbstractBorder) under).getBorderInsets(c, insets);
	}
	Insets temp = under.getBorderInsets(c);
	insets.top = temp.top;
	insets.left = temp.left;
	insets.bottom = temp.bottom;
	insets.right = temp.right;
	return insets;
}
 
Example #3
Source File: Test4856008.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #4
Source File: Test4856008.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #5
Source File: Test4856008.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #6
Source File: Test4856008.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #7
Source File: Test4856008.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #8
Source File: Test4856008.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #9
Source File: Test4856008.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #10
Source File: Test4856008.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #11
Source File: Test4856008.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #12
Source File: SeaGlassTableUI.java    From seaglass with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a {@link Border} that paints any empty space to the right of the
 * last column header in the given {@link JTable}'s {@link JTableHeader}.
 *
 * @param  table DOCUMENT ME!
 *
 * @return DOCUMENT ME!
 */
private static Border createTableHeaderEmptyColumnPainter(final JTable table) {
    return new AbstractBorder() {
        @Override
        public void paintBorder(Component c, Graphics g, int x, int y, int width, int height) {
            // if this JTableHeader is parented in a JViewport, then paint
            // the table header background to the right of the last column
            // if neccessary.
            Container viewport = table.getParent();

            if ((viewport instanceof JViewport) && table.getWidth() < viewport.getWidth()) {
                int startX           = table.getWidth();
                int emptyColumnWidth = viewport.getWidth() - table.getWidth();

                TableCellRenderer renderer  = table.getTableHeader().getDefaultRenderer();
                // Rossi: Fix for indexoutofbounds exception: A try catch might be good too?
                Component         component = renderer.getTableCellRendererComponent(table, "", false, false, 0, table.getColumnCount()-1);

                component.setBounds(0, 0, emptyColumnWidth, table.getTableHeader().getHeight());

                ((JComponent) component).setOpaque(true);
                CELL_RENDER_PANE.paintComponent(g, component, null, startX, 0, emptyColumnWidth + 1,
                                                table.getTableHeader().getHeight(), true);
            }
        }
    };
}
 
Example #13
Source File: Test4856008.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #14
Source File: Test4856008.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #15
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
private static Insets makeBorderInsets(Border border, Component c, Insets insets) {
  if (Objects.isNull(border)) {
    insets.set(0, 0, 0, 0);
  } else if (border instanceof AbstractBorder) {
    AbstractBorder ab = (AbstractBorder) border;
    insets = ab.getBorderInsets(c, insets);
  } else {
    Insets i = border.getBorderInsets(c);
    insets.set(i.top, i.left, i.bottom, i.right);
  }
  return insets;
}
 
Example #16
Source File: MainPanel.java    From java-swing-tips with MIT License 5 votes vote down vote up
private static Insets makeComponentBorderInsets(Border border, Component c, Insets i) {
  Insets ins = new Insets(i.top, i.left, i.bottom, i.right);
  if (Objects.isNull(border)) {
    ins.set(0, 0, 0, 0);
  } else if (border instanceof AbstractBorder) {
    AbstractBorder ab = (AbstractBorder) border;
    ins = ab.getBorderInsets(c, i);
  } else {
    ins = border.getBorderInsets(c);
  }
  return ins;
}
 
Example #17
Source File: TitledBorder2.java    From java-swing-tips with MIT License 5 votes vote down vote up
@SuppressWarnings("PMD.AvoidReassigningParameters")
private static Insets makeBorderInsets(Border border, Component c, Insets insets) {
  if (Objects.isNull(border)) {
    insets.set(0, 0, 0, 0);
  } else if (border instanceof AbstractBorder) {
    AbstractBorder ab = (AbstractBorder) border;
    insets = ab.getBorderInsets(c, insets);
  } else {
    Insets i = border.getBorderInsets(c);
    insets.set(i.top, i.left, i.bottom, i.right);
  }
  return insets;
}
 
Example #18
Source File: PainterSupport.java    From weblaf with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Returns {@link JComponent} baseline measured from the top of the component bounds for the specified {@link JComponent} size.
 * A return value less than {@code 0} indicates this component does not have a reasonable baseline.
 * This method is primarily meant for {@link LayoutManager}s to align components along their baseline.
 *
 * @param component   {@link JComponent}
 * @param componentUI {@link ComponentUI}
 * @param width       offered component width
 * @param height      offered component height
 * @return {@link JComponent} baseline measured from the top of the component bounds for the specified {@link JComponent} size
 */
public static int getBaseline ( @NotNull final JComponent component, @NotNull final ComponentUI componentUI,
                                final int width, final int height )
{
    // Default baseline
    int baseline = -1;

    // Painter baseline support
    final Painter painter = getPainter ( component );
    if ( painter != null )
    {
        // Creating appropriate bounds for painter
        final Bounds componentBounds = new Bounds ( new Dimension ( width, height ) );

        // Retrieving baseline provided by painter
        baseline = painter.getBaseline ( component, componentUI, componentBounds );
    }

    // Border baseline support
    // Taken from JPanel baseline implementation
    if ( baseline == -1 )
    {
        final Border border = component.getBorder ();
        if ( border instanceof AbstractBorder )
        {
            baseline = ( ( AbstractBorder ) border ).getBaseline ( component, width, height );
        }
    }

    return baseline;
}
 
Example #19
Source File: Test4856008.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #20
Source File: Test4856008.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #21
Source File: Test4856008.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #22
Source File: Test4856008.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #23
Source File: Test4856008.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #24
Source File: Test4856008.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #25
Source File: Test4856008.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #26
Source File: Test4856008.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #27
Source File: Test4856008.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #28
Source File: Test4856008.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}
 
Example #29
Source File: Test4856008.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void test(AbstractBorder border) {
    Insets insets = new Insets(0, 0, 0, 0);
    if (insets != border.getBorderInsets(getComponent(border), insets)) {
        throw new Error("both instances are differ for " + border.getClass());
    }
    test(border, insets);
}
 
Example #30
Source File: Test4856008.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) {
    for (Border border : BORDERS) {
        System.out.println(border.getClass());
        test(border, border.getBorderInsets(getComponent(border)));
        if (border instanceof AbstractBorder) {
            test((AbstractBorder) border);
        }
    }
}