protected BuddyLayoutAndBorder createBuddyLayoutAndBorder() { return new BuddyLayoutAndBorder(); }
@Override public String toString() { return String.format("%s (%s): %s", getClass().getName(), getBorderInsets(null), borderDelegate); } }
/** * @return the rectangle allocated by the text field, including the space * allocated by the child components left and right, the text fields * original border insets and the outer margin. * */ protected Rectangle getVisibleRect() { Rectangle alloc = SwingUtilities.getLocalBounds(textField); substractInsets(alloc, getRealBorderInsets()); substractInsets(alloc, BuddySupport.getOuterMargin(textField)); return alloc; }
/** * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the * given text field. Registers a {@link PropertyChangeListener} to wrap any * subsequently set border on the text field. */ protected void install(JTextField textField) { uninstall(); this.textField = textField; textField.setLayout(this); replaceBorderIfNecessary(); textField.addPropertyChangeListener("border", this); }
@Override public void layoutContainer(Container parent) { Rectangle visibleRect = getVisibleRect(); Dimension size; for (Component comp : BuddySupport.getLeft(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x, centerY(visibleRect, size), size.width, size.height); visibleRect.x += size.width; visibleRect.width -= size.width; } for (Component comp : BuddySupport.getRight(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x + visibleRect.width - size.width, centerY(visibleRect, size), size.width, size.height); visibleRect.width -= size.width; } }
@Override public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); }
/** * This does nothing, if the search field is rendered natively on * Leopard. */ @Override protected void replaceBorderIfNecessary() { if (!isNativeSearchField()) { super.replaceBorderIfNecessary(); } }
@Override public void paint(Graphics g, JComponent c) { // yet another dirty mac hack to prevent painting background outside of // border. if (hasMacTextFieldBorder(c)) { Insets borderInsets = layoutAndBorder.getRealBorderInsets(); borderInsets.left -= MAC_MARGIN.left; int height = c.getHeight() - borderInsets.bottom - borderInsets.top + MAC_MARGIN.bottom + MAC_MARGIN.top; int width = c.getWidth() - borderInsets.left - borderInsets.right + MAC_MARGIN.right; g.clipRect(borderInsets.left, borderInsets.top, width, height); } super.paint(g, c); }
private boolean hasMacTextFieldBorder(JComponent c) { Border border = c.getBorder(); if (border == layoutAndBorder) { border = layoutAndBorder.getBorderDelegate(); } return border != null && border.getClass().getName().equals("apple.laf.CUIAquaTextFieldBorder"); }
@Override public void installUI(JComponent c) { super.installUI(c); layoutAndBorder = createBuddyLayoutAndBorder(); layoutAndBorder.install((JTextField) c); }
/** * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the * given text field. Registers a {@link PropertyChangeListener} to wrap any * subsequently set border on the text field. */ protected void install(JTextField textField) { uninstall(); this.textField = textField; textField.setLayout(this); replaceBorderIfNecessary(); textField.addPropertyChangeListener("border", this); }
@Override public void layoutContainer(Container parent) { Rectangle visibleRect = getVisibleRect(); Dimension size; for (Component comp : BuddySupport.getLeft(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x, centerY(visibleRect, size), size.width, size.height); visibleRect.x += size.width; visibleRect.width -= size.width; } for (Component comp : BuddySupport.getRight(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x + visibleRect.width - size.width, centerY(visibleRect, size), size.width, size.height); visibleRect.width -= size.width; } }
@Override public Dimension minimumLayoutSize(Container parent) { return preferredLayoutSize(parent); }
/** * This does nothing, if the search field is rendered natively on * Leopard. */ @Override protected void replaceBorderIfNecessary() { if (!isNativeSearchField()) { super.replaceBorderIfNecessary(); } }
@Override public void paint(Graphics g, JComponent c) { // yet another dirty mac hack to prevent painting background outside of // border. if (hasMacTextFieldBorder(c)) { Insets borderInsets = layoutAndBorder.getRealBorderInsets(); borderInsets.left -= MAC_MARGIN.left; int height = c.getHeight() - borderInsets.bottom - borderInsets.top + MAC_MARGIN.bottom + MAC_MARGIN.top; int width = c.getWidth() - borderInsets.left - borderInsets.right + MAC_MARGIN.right; g.clipRect(borderInsets.left, borderInsets.top, width, height); } super.paint(g, c); }
private boolean hasMacTextFieldBorder(JComponent c) { Border border = c.getBorder(); if (border == layoutAndBorder) { border = layoutAndBorder.getBorderDelegate(); } return border != null && border.getClass().getName().equals("apple.laf.CUIAquaTextFieldBorder"); }
@Override public void installUI(JComponent c) { super.installUI(c); layoutAndBorder = createBuddyLayoutAndBorder(); layoutAndBorder.install((JTextField) c); }
/** * @return the rectangle allocated by the text field, including the space * allocated by the child components left and right, the text fields * original border insets and the outer margin. * */ protected Rectangle getVisibleRect() { Rectangle alloc = SwingUtilities.getLocalBounds(textField); substractInsets(alloc, getRealBorderInsets()); substractInsets(alloc, BuddySupport.getOuterMargin(textField)); return alloc; }
/** * Installs a {@link BuddyLayoutAndBorder} as a layout and border of the * given text field. Registers a {@link PropertyChangeListener} to wrap any * subsequently set border on the text field. */ protected void install(JTextField textField) { uninstall(); this.textField = textField; textField.setLayout(this); replaceBorderIfNecessary(); textField.addPropertyChangeListener("border", this); }
@Override public void layoutContainer(Container parent) { Rectangle visibleRect = getVisibleRect(); Dimension size; for (Component comp : BuddySupport.getLeft(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x, centerY(visibleRect, size), size.width, size.height); visibleRect.x += size.width; visibleRect.width -= size.width; } for (Component comp : BuddySupport.getRight(textField)) { if (!comp.isVisible()) { continue; } size = comp.getPreferredSize(); comp.setBounds(visibleRect.x + visibleRect.width - size.width, centerY(visibleRect, size), size.width, size.height); visibleRect.width -= size.width; } }