/** * Gets the bounds for the button part of the <code>JideSplitButton</code>. * * @param c the component. In this case, it is the <code>JideSplitButton</code>. * @param orientation the orientation. * @param width the width of the <code>JideSplitButton</code> * @param height the height of the <code>JideSplitButton</code>. * @return the bounds for the button part of the <code>JideSplitButton</code>. */ protected Rectangle getButtonRect(JComponent c, int orientation, int width, int height) { Rectangle rect; if (orientation == SwingConstants.HORIZONTAL && c.getComponentOrientation().isLeftToRight()) { rect = new Rectangle(0, 0, width - _splitButtonMargin, height); } else { rect = new Rectangle(_splitButtonMargin - 1, 0, width - _splitButtonMargin, height); } return rect; }
/** * Gets the bounds for the button part of the <code>JideSplitButton</code>. * * @param c the component. In this case, it is the <code>JideSplitButton</code>. * @param orientation the orientation. * @param width the width of the <code>JideSplitButton</code> * @param height the height of the <code>JideSplitButton</code>. * @return the bounds for the button part of the <code>JideSplitButton</code>. */ protected Rectangle getButtonRect(JComponent c, int orientation, int width, int height) { Rectangle rect; if (orientation == SwingConstants.HORIZONTAL && c.getComponentOrientation().isLeftToRight()) { rect = new Rectangle(0, 0, width - _splitButtonMargin, height); } else { rect = new Rectangle(_splitButtonMargin - 1, 0, width - _splitButtonMargin, height); } c.putClientProperty(ButtonStyle.CLIENT_PROPERTY_SEGMENT_POSITION, ButtonStyle.SEGMENT_POSITION_FIRST); return rect; }
/** * Gets the bounds for the button part of the <code>JideSplitButton</code>. * * @param c the component. In this case, it is the <code>JideSplitButton</code>. * @param orientation the orientation. * @param width the width of the <code>JideSplitButton</code> * @param height the height of the <code>JideSplitButton</code>. * @return the bounds for the button part of the <code>JideSplitButton</code>. */ protected Rectangle getButtonRect(JComponent c, int orientation, int width, int height) { Rectangle rect; if (orientation == SwingConstants.HORIZONTAL && c.getComponentOrientation().isLeftToRight()) { rect = new Rectangle(0, 0, width - _splitButtonMargin, height); } else { rect = new Rectangle(_splitButtonMargin - 1, 0, width - _splitButtonMargin, height); } return rect; }
@Override public void installUI(JComponent c) { super.installUI(c); chooser.applyComponentOrientation(c.getComponentOrientation()); }
public void installUI(JComponent c) { super.installUI(c); chooser.applyComponentOrientation(c.getComponentOrientation()); }
/** * Paints an arrow shape. * * @param c the component * @param g the graphics instance * @param color color * @param startX start X * @param startY start Y * @param width width * @param orientation horizontal or vertical */ public static void paintArrow(JComponent c, Graphics g, Color color, int startX, int startY, int width, int orientation) { if (!c.getComponentOrientation().isLeftToRight()) { Color oldColor = g.getColor(); g.setColor(color); width = width / 2 * 2 + 1; // make sure it's odd for (int i = 0; i < (width + 1) / 2; i++) { g.drawLine(startX + width - i, startY + i, startX + width - i, startY + width - i - 1); } g.setColor(oldColor); return; } paintArrow(g, color, startX, startY, width, orientation); }
class StyledText { StyleRange styleRange; String text; public StyledText(String text) { this.text = text; } public StyledText(String text, StyleRange styleRange) { this.text = text; this.styleRange = styleRange; } }
/** * Resolve the axis type of a component, given a layout orientation * @param c a Swing Component, should be either a Box or a Container * using a BoxLayout. * @param layout the layout orientation of the component. One of * {@link javax.swing.BoxLayout#X_AXIS}, * {@link javax.swing.BoxLayout#Y_AXIS}, * {@link javax.swing.BoxLayout#LINE_AXIS}, or * {@link javax.swing.BoxLayout#PAGE_AXIS}. * @return one of {@link javax.swing.BoxLayout#X_AXIS}, or * {@link javax.swing.BoxLayout#Y_AXIS}, */ public static int getAxis(JComponent c, int layout) { ComponentOrientation o = c.getComponentOrientation(); switch ( layout ) { case BoxLayout.LINE_AXIS: return o.isHorizontal() ? BoxLayout.X_AXIS : BoxLayout.Y_AXIS; case BoxLayout.PAGE_AXIS: return o.isHorizontal() ? BoxLayout.Y_AXIS : BoxLayout.X_AXIS; default: return layout; } }
/** * Paints the border of a text field. * * @param context SynthContext identifying the <code>JComponent</code> and * <code>Region</code> to paint to * @param g <code>Graphics</code> to paint to * @param x X coordinate of the area to paint to * @param y Y coordinate of the area to paint to * @param w Width of the area to paint to * @param h Height of the area to paint to */ public void paintTextFieldBorder(SynthContext context, Graphics g, int x, int y, int w, int h) { if (context.getComponent().getComponentOrientation().isLeftToRight()) { paintBorder(context, g, x, y, w, h, null); } else { AffineTransform transform = new AffineTransform(); transform.translate(x, y); transform.scale(-1, 1); transform.translate(-w, 0); paintBorder(context, g, 0, 0, w, h, transform); } }
private Shape decodeArrowPath(JComponent c, int width, int height) { if (c.getComponentOrientation().isLeftToRight()) { return shapeGenerator.createArrowRight(1, 1, width - 2, height - 2); } else { return shapeGenerator.createArrowLeft(1, 1, width - 2, height - 2); } } }
@Override public void paintPopupMenuSeparator(JComponent c, Graphics g, Rectangle rect, int orientation, int state) { int defaultShadowWidth = UIDefaultsLookup.getInt("MenuItem.shadowWidth"); int defaultTextIconGap = UIDefaultsLookup.getInt("MenuItem.textIconGap"); if (c.getComponentOrientation().isLeftToRight()) { paintMenuShadow(c, g, new Rectangle(rect.x, rect.y, defaultShadowWidth, rect.height), SwingConstants.HORIZONTAL, ThemePainter.STATE_DEFAULT); g.setColor(getMenuItemBackground()); g.fillRect(rect.x + defaultShadowWidth, rect.y, rect.width - defaultShadowWidth, rect.height); g.setColor(getSeparatorForeground()); g.drawLine(rect.x + defaultShadowWidth + defaultTextIconGap, rect.y + 1, rect.x + rect.width, rect.y + 1); } else { paintMenuShadow(c, g, new Rectangle(rect.x + rect.width - defaultShadowWidth, rect.y, defaultShadowWidth, rect.height), SwingConstants.HORIZONTAL, ThemePainter.STATE_DEFAULT); g.setColor(getMenuItemBackground()); g.fillRect(rect.x, rect.y, rect.width - defaultShadowWidth, rect.height); g.setColor(getSeparatorForeground()); g.drawLine(rect.x, rect.y + 1, rect.x + rect.width - defaultShadowWidth - defaultTextIconGap, rect.y + 1); } }
public void paintChevronOption(JComponent c, Graphics g, Rectangle rect, int orientation, int state) { int startX; int startY; if (orientation == SwingConstants.HORIZONTAL || !c.getComponentOrientation().isLeftToRight()) { startX = rect.x + 3; startY = rect.y + rect.height - 7; } else { startX = rect.x + rect.width - 7; startY = rect.y + 3; } if (orientation == SwingConstants.HORIZONTAL || !c.getComponentOrientation().isLeftToRight()) { JideSwingUtilities.paintArrow(g, UIDefaultsLookup.getColor("CommandBar.darkShadow"), startX, startY, 5, SwingConstants.HORIZONTAL); } else { JideSwingUtilities.paintArrow(g, UIDefaultsLookup.getColor("CommandBar.darkShadow"), startX, startY, 5, orientation); } }
@Override public void installUI(JComponent c) { super.installUI(c); oldArrowIcon = arrowIcon; boolean isLeftToRight = c.getComponentOrientation().isLeftToRight(); arrowIcon = NapkinIconFactory.createArrowIcon( (isLeftToRight ? EAST : WEST), 8); c.addPropertyChangeListener("componentOrientation", orientationListener); NapkinUtil.installUI(c); }
/** * @inheritDoc * */ @Override public void toggleVisibility(JComponent owner) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else if (popupMenu.getComponentCount() > 0) { Dimension buttonSize = owner.getSize(); int xPos = owner.getComponentOrientation().isLeftToRight() ? buttonSize.width - popupMenu.getPreferredSize().width : 0; popupMenu.show(owner, // JW: trying to allow popup without CCB showing // weird behaviour // owner.isShowing()? owner : null, xPos, buttonSize.height); } }
/** * @inheritDoc * */ @Override public void toggleVisibility(JComponent owner) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else if (popupMenu.getComponentCount() > 0) { Dimension buttonSize = owner.getSize(); int xPos = owner.getComponentOrientation().isLeftToRight() ? buttonSize.width - popupMenu.getPreferredSize().width : 0; popupMenu.show(owner, // JW: trying to allow popup without CCB showing // weird behaviour // owner.isShowing()? owner : null, xPos, buttonSize.height); } }
/** * @inheritDoc * */ public void toggleVisibility(JComponent owner) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else if (popupMenu.getComponentCount() > 0) { Dimension buttonSize = owner.getSize(); int xPos = owner.getComponentOrientation().isLeftToRight() ? buttonSize.width - popupMenu.getPreferredSize().width : 0; popupMenu.show(owner, // JW: trying to allow popup without CCB showing // weird behaviour // owner.isShowing()? owner : null, xPos, buttonSize.height); } }
/** * @inheritDoc * */ @Override public void toggleVisibility(JComponent owner) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else if (popupMenu.getComponentCount() > 0) { Dimension buttonSize = owner.getSize(); int xPos = owner.getComponentOrientation().isLeftToRight() ? buttonSize.width - popupMenu.getPreferredSize().width : 0; popupMenu.show(owner, // JW: trying to allow popup without CCB showing // weird behaviour // owner.isShowing()? owner : null, xPos, buttonSize.height); } }
/** * @inheritDoc * */ @Override public void toggleVisibility(JComponent owner) { JPopupMenu popupMenu = getPopupMenu(); if (popupMenu.isVisible()) { popupMenu.setVisible(false); } else if (popupMenu.getComponentCount() > 0) { Dimension buttonSize = owner.getSize(); int xPos = owner.getComponentOrientation().isLeftToRight() ? buttonSize.width - popupMenu.getPreferredSize().width : 0; popupMenu.show(owner, // JW: trying to allow popup without CCB showing // weird behaviour // owner.isShowing()? owner : null, xPos, buttonSize.height); } }
@Override public void installUI( JComponent c ) { chooser = (JColorChooser)c; AbstractColorChooserPanel[] oldPanels = chooser.getChooserPanels(); installDefaults(); chooser.setLayout( new BorderLayout() ); mainPanel = new PaletteColorChooserMainPanel(); chooser.add(mainPanel); defaultChoosers = createDefaultChoosers(); chooser.setChooserPanels(defaultChoosers); installPreviewPanel(); AbstractColorChooserPanel[] newPanels = (AbstractColorChooserPanel[]) chooser.getChooserPanels(); updateColorChooserPanels(oldPanels, newPanels); // Note: install listeners only after we have fully installed // all chooser panels. If we do it earlier, we send property // events too early. installListeners(); chooser.applyComponentOrientation(c.getComponentOrientation()); }
@Override public void paintMenuShadow(JComponent c, Graphics g, Rectangle rect, int orientation, int state) { Graphics2D g2d = (Graphics2D) g; if (c.getComponentOrientation().isLeftToRight()) { JideSwingUtilities.fillGradient(g2d, rect, getCurrentTheme().getColor("controlLt"), getCurrentTheme().getColor("controlDk"), orientation != SwingConstants.HORIZONTAL); } else { JideSwingUtilities.fillGradient(g2d, rect, getCurrentTheme().getColor("controlDk"), getCurrentTheme().getColor("controlLt"), orientation != SwingConstants.HORIZONTAL); } }