@NotNull private JPanel getOptionsPanel(final JPanel root) { JPanel options = new JPanel(new GridBagLayout()); GridBag bag = new GridBag() .setDefaultInsets(new JBInsets(0, 4, 0, 4)) .setDefaultFill(GridBagConstraints.HORIZONTAL); cbAddInternal = new JBCheckBox("Internal"); cbAddJ2EE = new JBCheckBox("J2EE"); ItemListener itemListener = e -> { root.remove(comboBox); comboBox = getSelector(); root.add(comboBox); root.revalidate(); }; cbAddInternal.addItemListener(itemListener); cbAddJ2EE.addItemListener(itemListener); options.add(cbAddInternal, bag.nextLine().next()); options.add(cbAddJ2EE, bag.next()); return options; }
@Override public void paint(final Graphics g) { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); bounds.x += (bounds.width - myIcon.getIconWidth()) / 2; bounds.y += (bounds.height - myIcon.getIconHeight()) / 2; if (myBehavior.isHovered()) { // todo } if (myBehavior.isPressedByMouse()) { bounds.x++; bounds.y++; } myIcon.paintIcon(this, g, bounds.x, bounds.y); }
private String layout(AbstractButton b, FontMetrics fm, int width, int height) { viewRect.setBounds(0, 0, width, height); JBInsets.removeFrom(viewRect, b.getInsets()); 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 static void moveToFit(final Rectangle rectangle, final Rectangle container, @Nullable Insets padding) { Rectangle move = new Rectangle(rectangle); JBInsets.addTo(move, padding); if (move.getMaxX() > container.getMaxX()) { move.x = (int)container.getMaxX() - move.width; } if (move.getMinX() < container.getMinX()) { move.x = (int)container.getMinX(); } if (move.getMaxY() > container.getMaxY()) { move.y = (int)container.getMaxY() - move.height; } if (move.getMinY() < container.getMinY()) { move.y = (int)container.getMinY(); } JBInsets.removeFrom(move, padding); rectangle.setBounds(move); }
public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl(ApplicationInfoEx.getInstanceEx(), myActionManager, myDataManager, ApplicationManager.getApplication()); myProject2Frame.put(null, frame); if (myFrameBounds == null || !ScreenUtil.isVisible(myFrameBounds)) { //avoid situations when IdeFrame is out of all screens myFrameBounds = ScreenUtil.getMainScreenBounds(); int xOff = myFrameBounds.width / 8; int yOff = myFrameBounds.height / 8; JBInsets.removeFrom(myFrameBounds, new Insets(yOff, xOff, yOff, xOff)); } fixForOracleBug8007219(frame); frame.setBounds(myFrameBounds); frame.setExtendedState(myFrameExtendedState); frame.setVisible(true); }
@Override public void validate() { super.validate(); DialogWrapper wrapper = myDialogWrapper.get(); if (wrapper != null && wrapper.isAutoAdjustable()) { Window window = wrapper.getWindow(); if (window != null) { Dimension size = getMinimumSize(); if (!(size == null ? myLastMinimumSize == null : size.equals(myLastMinimumSize))) { // update window minimum size only if root pane minimum size is changed if (size == null) { myLastMinimumSize = null; } else { myLastMinimumSize = new Dimension(size); JBInsets.addTo(size, window.getInsets()); } window.setMinimumSize(size); } } } }
public void paintComponent(Graphics g) { Icon icon = getIcon(); FontMetrics fm = getFontMetrics(getFont()); Rectangle viewRect = new Rectangle(getSize()); JBInsets.removeFrom(viewRect, getInsets()); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); String text = SwingUtilities.layoutCompoundLabel(this, fm, getText(), icon, SwingConstants.CENTER, horizontalTextAlignment(), SwingConstants.CENTER, horizontalTextPosition(), viewRect, iconRect, textRect, iconTextSpace()); ActionButtonLook look = ActionButtonLook.IDEA_LOOK; look.paintBackground(g, this); look.paintIconAt(g, this, icon, iconRect.x, iconRect.y); look.paintBorder(g, this); UISettings.setupAntialiasing(g); g.setColor(isButtonEnabled() ? getForeground() : getInactiveTextColor()); SwingUtilities2.drawStringUnderlineCharAt(this, g, text, getMnemonicCharIndex(text), textRect.x, textRect.y + fm.getAscent()); }
@Override public Dimension getMinimumSize() { if (super.isMinimumSizeSet()) { return super.getMinimumSize(); } Dimension size = new Dimension(1, 20); if (myEditor != null) { size.height = myEditor.getLineHeight(); JBInsets.addTo(size, getInsets()); JBInsets.addTo(size, myEditor.getInsets()); } return size; }
@Override public void doLayout() { synchronized (getTreeLock()) { int count = getComponentCount(); if (count == 1) { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); Component child = getComponent(0); child.setBounds(bounds); if (child instanceof CellRendererPanel) { ((CellRendererPanel)child).invalidateLayout(); child.doLayout(); } } else { invalidateLayout(); super.doLayout(); for (int i = 0; i < count; i++) { Component c = getComponent(i); if (c instanceof CellRendererPanel) { c.doLayout(); } } } } }
private static int calculateCheckBoxIndent() { JCheckBox checkBox = new JCheckBox(); Icon icon = checkBox.getIcon(); int indent = 0; if (icon == null) { icon = UIManager.getIcon("CheckBox.icon"); } if (UIUtil.isUnderDarcula() || UIUtil.isUnderIntelliJLaF()) { icon = EmptyIcon.create(20, 18); } if (icon != null) { final Rectangle r1 = new Rectangle(checkBox.getWidth(), checkBox.getHeight()); JBInsets.removeFrom(r1, checkBox.getInsets()); final Rectangle iconRect = new Rectangle(); SwingUtilities.layoutCompoundLabel( checkBox, checkBox.getFontMetrics(checkBox.getFont()), checkBox.getText(), icon, checkBox.getVerticalAlignment(), checkBox.getHorizontalAlignment(), checkBox.getVerticalTextPosition(), checkBox.getHorizontalTextPosition(), r1, new Rectangle(), iconRect, checkBox.getText() == null ? 0 : checkBox.getIconTextGap()); indent = iconRect.x; } return indent + checkBox.getIconTextGap(); }
@Override public JComponent getComponent() { if (myWrapperPanel == null) { myWrapperPanel = new MTWrapperPanel(new BorderLayout()) { @Override public Insets getInsets() { return new JBInsets(0, 0, 0, 0); } @Override protected void paintComponent(final Graphics g) { super.paintComponent(g); } }; myWrapperPanel.add(buildMTPanel(), BorderLayout.CENTER); } return myWrapperPanel; }
private Dimension getPreferredSize(Container container, boolean aligned) { synchronized (container.getTreeLock()) { Dimension top = getPreferredSize(myTop); Dimension bottom = getPreferredSize(myBottom); Dimension center = getPreferredSize(myCenter); Dimension result = join(join(join(null, myGap + myGap, top), myGap + myGap, center), myGap + myGap, bottom); if (result == null) { result = new Dimension(); } else if (aligned && center != null) { int topHeight = top == null ? 0 : top.height; int bottomHeight = bottom == null ? 0 : bottom.height; result.width += Math.abs(topHeight - bottomHeight); } JBInsets.addTo(result, container.getInsets()); return result; } }
@Override public Dimension getMinimumSize() { if (isMinimumSizeSet()) { return super.getMinimumSize(); } Dimension size = new Dimension(1, 20); if (myEditor != null) { size.height = myEditor.getLineHeight(); JBInsets.addTo(size, getInsets()); JBInsets.addTo(size, myEditor.getInsets()); } return size; }
private void relayout() { final Dimension size = myLayeredPane.getSize(); JBInsets.removeFrom(size, myInsets); final Rectangle layoutRec = new Rectangle(new Point(myInsets.left, myInsets.top), size); List<ArrayList<Balloon>> columns = createColumns(layoutRec); while (columns.size() > 1) { remove(myBalloons.get(0), true); columns = createColumns(layoutRec); } ToolWindowPanelImplEx pane = UIUtil.findComponentOfType2(myParent, ToolWindowPanelImplEx.class); JComponent layeredPane = pane != null ? pane.getMyLayeredPane() : null; int eachColumnX = (layeredPane == null ? myLayeredPane.getWidth() : layeredPane.getX() + layeredPane.getWidth()) - 4; newLayout(columns.get(0), eachColumnX + 4, (int)myLayeredPane.getBounds().getMaxY()); }
@Override public void doLayout() { int count = getComponentCount(); if (count == 1) { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); Component child = getComponent(0); child.setBounds(bounds); if (child instanceof CellRendererPanel) { ((CellRendererPanel)child).invalidateLayout(); child.doLayout(); } } else { invalidateLayout(); super.doLayout(); for (int i = 0; i < count; i++) { Component c = getComponent(i); if (c instanceof CellRendererPanel) { c.doLayout(); } } } }
@Override public void paint(Graphics graphics) { Graphics2D g = (Graphics2D)graphics.create(); try { g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_PURE); myHelper.paint(g); } finally { g.dispose(); } super.paint(graphics); if (UIUtil.isUnderGTKLookAndFeel()) { graphics.setColor(myTextArea.getBackground()); Rectangle bounds = myScrollPane.getViewport().getBounds(); if (myScrollPane.getVerticalScrollBar().isVisible()) { bounds.width -= myScrollPane.getVerticalScrollBar().getWidth(); } bounds = SwingUtilities.convertRectangle(myScrollPane.getViewport()/*myTextArea*/, bounds, this); JBInsets.addTo(bounds, new JBInsets(2, 2, -1, -1)); ((Graphics2D)graphics).draw(bounds); } }
@Override void paint(Graphics2D g) { Rectangle r = new Rectangle(getSize()); JBInsets.removeFrom(r, getInsets()); if (r.height % 2 == 1) r.height++; int arcSize = JBUI.scale(26); JBInsets.removeFrom(r, new JBInsets(1, 1, 1, 1)); if (myTextArea.hasFocus()) { g.setColor(myTextArea.getBackground()); RectanglePainter.FILL.paint(g, r.x, r.y, r.width, r.height, arcSize); DarculaUIUtil.paintSearchFocusRing(g, r, myTextArea, arcSize); } else { arcSize -= JBUI.scale(5); RectanglePainter .paint(g, r.x, r.y, r.width, r.height, arcSize, myTextArea.getBackground(), myTextArea.isEnabled() ? Gray._100 : Gray._83); } }
public void showFrame() { final IdeFrameImpl frame = new IdeFrameImpl(ApplicationInfoEx.getInstanceEx(), myActionManager, myDataManager, ApplicationManager.getApplication()); myProject2Frame.put(null, frame); if (myFrameBounds == null || !ScreenUtil.isVisible(myFrameBounds)) { //avoid situations when IdeFrame is out of all screens myFrameBounds = ScreenUtil.getMainScreenBounds(); int xOff = myFrameBounds.width / 8; int yOff = myFrameBounds.height / 8; JBInsets.removeFrom(myFrameBounds, new Insets(yOff, xOff, yOff, xOff)); } frame.setBounds(myFrameBounds); frame.setExtendedState(myFrameExtendedState); frame.setVisible(true); }
public IdeaTitledBorder(String title, int indent, Insets insets) { super(title); titledSeparator = new TitledSeparator(title); titledSeparator.setText(title); DialogUtil.registerMnemonic(titledSeparator.getLabel(), null); outsideInsets = JBInsets.create(insets); insideInsets = new JBInsets(TitledSeparator.BOTTOM_INSET, indent, 0, 0); }
@Override public Dimension getPreferredSize() { Dimension size = super.getPreferredSize(); Border border = super.getBorder(); if (border != null && UIUtil.isUnderAquaLookAndFeel()) { JBInsets.addTo(size, border.getBorderInsets(this)); } return size; }
public SimpleColoredComponent() { myFragments = new ArrayList<String>(3); myAttributes = new ArrayList<SimpleTextAttributes>(3); myIpad = new JBInsets(1, 2, 1, 2); myIconTextGap = JBUI.scale(2); myBorder = new MyBorder(); myFragmentPadding = new TIntIntHashMap(10); myFragmentAlignment = new TIntIntHashMap(10); setOpaque(true); }
@Override public Dimension getPreferredSize() { final Dimension size = super.getPreferredSize(); size.width += myMoreRec.width; JBInsets.addTo(size, myDownIconInsets); return size; }
@Override public Dimension getPreferredSize() { final ArrayList<Rectangle> bounds = new ArrayList<Rectangle>(); calculateBounds(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE), bounds); if (bounds.isEmpty()) return JBUI.emptySize(); int xLeft = Integer.MAX_VALUE; int yTop = Integer.MAX_VALUE; int xRight = Integer.MIN_VALUE; int yBottom = Integer.MIN_VALUE; for (int i = bounds.size() - 1; i >= 0; i--) { final Rectangle each = bounds.get(i); if (each.x == Integer.MAX_VALUE) continue; xLeft = Math.min(xLeft, each.x); yTop = Math.min(yTop, each.y); xRight = Math.max(xRight, each.x + each.width); yBottom = Math.max(yBottom, each.y + each.height); } final Dimension dimension = new Dimension(xRight - xLeft, yBottom - yTop); if (myLayoutPolicy == AUTO_LAYOUT_POLICY && myReservePlaceAutoPopupIcon) { if (myOrientation == SwingConstants.HORIZONTAL) { dimension.width += AllIcons.Ide.Link.getIconWidth(); } else { dimension.height += AllIcons.Ide.Link.getIconHeight(); } } JBInsets.addTo(dimension, getInsets()); return dimension; }
@Override public Dimension getPreferredSize() { if (super.isPreferredSizeSet()) { return super.getPreferredSize(); } boolean toReleaseEditor = false; if (myEditor == null && myEnsureWillComputePreferredSize) { myEnsureWillComputePreferredSize = false; initEditor(); toReleaseEditor = true; } Dimension size = new Dimension(100, 20); if (myEditor != null) { final Dimension preferredSize = new Dimension(myEditor.getComponent().getPreferredSize()); if (myPreferredWidth != -1) { preferredSize.width = myPreferredWidth; } JBInsets.addTo(preferredSize, getInsets()); size = preferredSize; } else if (myPassivePreferredSize != null) { size = myPassivePreferredSize; } if (toReleaseEditor) { releaseEditor(); myPassivePreferredSize = size; } return size; }
@Override public Dimension getPreferredSize() { if (UIUtil.isUnderIntelliJLaF() || UIUtil.isUnderDarcula()) { return super.getPreferredSize(); } if (myEditorField != null) { final Dimension preferredSize = new Dimension(myEditorField.getComponent().getPreferredSize()); JBInsets.addTo(preferredSize, getInsets()); return preferredSize; } //final int cbHeight = new JComboBox().getPreferredSize().height; // should be used actually return new Dimension(100, UIUtil.fixComboBoxHeight(20)); }
private void setLocationInTheCenterOfScreen() { Rectangle bounds = getGraphicsConfiguration().getBounds(); if (SystemInfo.isWindows) { JBInsets.removeFrom(bounds, ScreenUtil.getScreenInsets(getGraphicsConfiguration())); } setLocation(UIUtil.getCenterPoint(bounds, getSize())); }
@Override public void doLayout() { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); for (Component component : getComponents()) { component.setBounds(bounds); } }
@Override protected void layoutEditor(@NotNull JComponent editor) { int w = spinner.getWidth(); int h = spinner.getHeight(); JBInsets insets = JBUI.insets(spinner.getInsets()); editor.setBounds(insets.left + 5, insets.top + 5, w - 5 - 26 - insets.width(), h - insets.height() - 10); }
@Override public synchronized void paint(Graphics g2d, JComponent c) { Graphics2D g = (Graphics2D)g2d; JCheckBox b = (JCheckBox) c; final Dimension size = c.getSize(); final Font font = c.getFont(); g.setFont(font); FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, font); Rectangle viewRect = new Rectangle(size); Rectangle iconRect = new Rectangle(); Rectangle textRect = new Rectangle(); JBInsets.removeFrom(viewRect, c.getInsets()); String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); //background if (c.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(0, 0, size.width, size.height); } final boolean selected = b.isSelected(); final boolean enabled = b.isEnabled(); drawCheckIcon(c, g, b, iconRect, selected, enabled); drawText(c, g, b, fm, textRect, text); }
protected Rectangle getDrawingRect() { final JTextComponent c = myTextField; final JBInsets i = JBInsets.create(c.getInsets()); final int x = i.right - JBUI.scale(4) - JBUI.scale(16); final int y = i.top - 3; final int w = c.getWidth() - i.width() + JBUI.scale(16*2 +7*2 - 5); int h = c.getBounds().height - i.height() + JBUI.scale(4*2 - 3); if (h%2==1) h++; return new Rectangle(x, y, w, h); }
protected void paintMenuItem(Graphics g, JComponent c, Icon checkIcon, Icon arrowIcon, Color background, Color foreground, int defaultTextIconGap) { // Save original graphics font and color Font holdf = g.getFont(); Color holdc = g.getColor(); JMenuItem mi = (JMenuItem) c; g.setFont(mi.getFont()); Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); JBInsets.removeFrom(viewRect, mi.getInsets()); MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, arrowIcon, viewRect, defaultTextIconGap, "-", //todo[kb] use protected field BasicMenuItemUI.acceleratorDelimiter when we move to java 1.7 mi.getComponentOrientation().isLeftToRight(), mi.getFont(), acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), getPropertyPrefix()); MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); paintBackground(g, mi, background); paintCheckIcon(g, lh, lr, holdc, foreground); paintIcon(g, lh, lr, holdc); g.setColor(foreground); paintText(g, lh, lr); paintAccText(g, lh, lr); paintArrowIcon(g, lh, lr, foreground); // Restore original graphics font and color g.setColor(holdc); g.setFont(holdf); }
@Override public Insets getWrapperPanelInsets(Insets insets) { final JBInsets result = JBUI.insets(insets); if (shouldPaintWrapperPanel()) { result.top += JBUI.scale(1); } return result; }
@Override public void paint(Graphics g) { Rectangle bounds = new Rectangle(getWidth(), getHeight()); JBInsets.removeFrom(bounds, getInsets()); bounds.x += (bounds.width - myIcon.getIconWidth()) / 2; bounds.y += (bounds.height - myIcon.getIconHeight()) / 2; if (myBehavior.isPressedByMouse()) { bounds.x++; bounds.y++; } myIcon.paintIcon(this, g, bounds.x, bounds.y); }
private static Insets parseInsets(final String value) { final java.util.List<String> numbers = StringUtil.split(value, ","); return new JBInsets(Integer.parseInt(numbers.get(0)), Integer.parseInt(numbers.get(1)), Integer.parseInt(numbers.get(2)), Integer.parseInt(numbers.get(3))).asUIResource(); }
protected final void paintMenuItem(final Graphics g, final JComponent c, final Icon checkIcon, final Icon arrowIcon, final Color background, final Color foreground, final int defaultTextIconGap) { // Save original graphics font and color Font holdf = g.getFont(); Color holdc = g.getColor(); JMenuItem mi = (JMenuItem) c; g.setFont(mi.getFont()); Rectangle viewRect = new Rectangle(0, 0, mi.getWidth(), mi.getHeight()); JBInsets.removeFrom(viewRect, mi.getInsets()); MenuItemLayoutHelper lh = new MenuItemLayoutHelper(mi, checkIcon, arrowIcon, viewRect, defaultTextIconGap, "-", //todo[kb] use protected field BasicMenuItemUI.acceleratorDelimiter when we // move to java 1.7 mi.getComponentOrientation().isLeftToRight(), mi.getFont(), acceleratorFont, MenuItemLayoutHelper.useCheckAndArrow(menuItem), getPropertyPrefix()); MenuItemLayoutHelper.LayoutResult lr = lh.layoutMenuItem(); paintBackground(g, mi, background); paintCheckIcon(g, lh, lr, holdc, foreground); paintIcon(g, lh, lr, holdc); g.setColor(foreground); UISettings.setupAntialiasing(g); paintText(g, lh, lr); paintAccText(g, lh, lr); paintArrowIcon(g, lh, lr, foreground); // Restore original graphics font and color g.setColor(holdc); g.setFont(holdf); }
@Override public synchronized void paint(final Graphics g2d, final JComponent c) { final Graphics2D g = (Graphics2D) g2d; final JCheckBox b = (JCheckBox) c; final Dimension size = c.getSize(); final Font font = c.getFont(); g.setFont(font); final FontMetrics fm = SwingUtilities2.getFontMetrics(c, g, font); final Rectangle viewRect = new Rectangle(size); final Rectangle iconRect = new Rectangle(); final Rectangle textRect = new Rectangle(); JBInsets.removeFrom(viewRect, c.getInsets()); final String text = SwingUtilities.layoutCompoundLabel(c, fm, b.getText(), getDefaultIcon(), b.getVerticalAlignment(), b.getHorizontalAlignment(), b.getVerticalTextPosition(), b.getHorizontalTextPosition(), viewRect, iconRect, textRect, b.getIconTextGap()); //background if (c.isOpaque()) { g.setColor(b.getBackground()); g.fillRect(0, 0, size.width, size.height); } final boolean selected = b.isSelected(); final boolean enabled = b.isEnabled(); drawCheckIcon(c, g, b, iconRect, selected, enabled); drawText(c, g, b, fm, textRect, text); }
protected Rectangle getDrawingRect() { final JTextComponent c = myTextField; final JBInsets i = JBInsets.create(c.getInsets()); final int x = i.right - JBUI.scale(4) - JBUI.scale(16); final int y = i.top - JBUI.scale(3); final int w = c.getWidth() - i.width() + JBUI.scale(16 * 2 + 7 * 2 - 5); int h = c.getBounds().height - i.height() + JBUI.scale(4 * 2 - 3); if (h % 2 == 1) { h++; } return new Rectangle(x, y, w, h); }
private Rectangle getDrawingRect() { JComponent c = passwordField; final JBInsets i = JBInsets.create(c.getInsets()); final int x = i.right - JBUI.scale(4) - JBUI.scale(16 * 2); final int y = i.top - JBUI.scale(3); final int w = c.getWidth() - i.width() + JBUI.scale(16 * 2 + 7 * 2 - 5); int h = c.getBounds().height - i.height() + JBUI.scale(4 * 2 - 3); if (h % 2 == 1) { h++; } return new Rectangle(x, y, w, h); }
protected Rectangle getDrawingRect() { final JTextComponent c = getComponent(); final JBInsets i = JBInsets.create(c.getInsets()); final int x = i.right - 4 - 16; final int y = i.top - 3; final int w = c.getWidth() - i.width() + 16*2 +7*2 - 5; int h = c.getBounds().height - i.height() + 4*2 - 3; if (h%2==1) h++; return new Rectangle(x, y, w, h); }