Search in sources :

Example 6 with UIResource

use of javax.swing.plaf.UIResource in project Botnak by Gocnak.

the class GraphiteButtonUI method paintBackground.

protected void paintBackground(Graphics g, AbstractButton b) {
    int w = b.getWidth();
    int h = b.getHeight();
    Graphics2D g2D = (Graphics2D) g;
    Shape savedClip = g.getClip();
    if ((b.getBorder() != null) && b.isBorderPainted() && (b.getBorder() instanceof UIResource)) {
        Area clipArea = new Area(new RoundRectangle2D.Double(0, 0, w - 1, h - 1, 6, 6));
        clipArea.intersect(new Area(savedClip));
        g2D.setClip(clipArea);
    }
    super.paintBackground(g, b);
    g2D.setClip(savedClip);
}
Also used : Area(java.awt.geom.Area) RoundRectangle2D(java.awt.geom.RoundRectangle2D) UIResource(javax.swing.plaf.UIResource)

Example 7 with UIResource

use of javax.swing.plaf.UIResource in project intellij-community by JetBrains.

the class JBViewport method updateBorder.

private static void updateBorder(Component view) {
    // tables are not supported yet
    if (view instanceof JTable)
        return;
    if (view instanceof JComponent) {
        JComponent component = (JComponent) view;
        Border border = component.getBorder();
        // already set
        if (border instanceof ViewBorder)
            return;
        component.setBorder(border == null || border instanceof UIResource ? new ResourceViewBorder(border) : new ViewBorder(border));
    }
}
Also used : Border(javax.swing.border.Border) AbstractBorder(javax.swing.border.AbstractBorder) UIResource(javax.swing.plaf.UIResource)

Example 8 with UIResource

use of javax.swing.plaf.UIResource in project intellij-community by JetBrains.

the class DarculaSpinnerUI method createArrow.

private JButton createArrow(@MagicConstant(intValues = { SwingConstants.NORTH, SwingConstants.SOUTH }) int direction) {
    final Color shadow = UIUtil.getPanelBackground();
    final Color enabledColor = new JBColor(Gray._255, UIUtil.getLabelForeground());
    final Color disabledColor = new JBColor(Gray._200, UIUtil.getLabelForeground().darker());
    BasicArrowButton b = new BasicArrowButton(direction, shadow, shadow, enabledColor, shadow) {

        @Override
        public void paint(Graphics g) {
            paintArrowButton(g, this, direction);
        }

        @Override
        public boolean isOpaque() {
            return false;
        }

        @Override
        public void paintTriangle(Graphics g, int x, int y, int size, int direction, boolean isEnabled) {
            final GraphicsConfig config = GraphicsUtil.setupAAPainting(g);
            int mid;
            final int w = 8;
            final int h = 6;
            mid = w / 2;
            g.setColor(isEnabled ? enabledColor : disabledColor);
            g.translate(x, y);
            switch(direction) {
                case SOUTH:
                    g.fillPolygon(new int[] { 0, w, mid }, new int[] { 1, 1, h }, 3);
                    break;
                case NORTH:
                    g.fillPolygon(new int[] { 0, w, mid }, new int[] { h - 1, h - 1, 0 }, 3);
                    break;
                case WEST:
                case EAST:
            }
            g.translate(-x, -y);
            config.restore();
        }
    };
    Border buttonBorder = UIManager.getBorder("Spinner.arrowButtonBorder");
    if (buttonBorder instanceof UIResource) {
        // Wrap the border to avoid having the UIResource be replaced by
        // the ButtonUI. This is the opposite of using BorderUIResource.
        b.setBorder(new CompoundBorder(buttonBorder, null));
    } else {
        b.setBorder(buttonBorder);
    }
    b.setInheritsPopupMenu(true);
    return b;
}
Also used : BasicArrowButton(javax.swing.plaf.basic.BasicArrowButton) JBColor(com.intellij.ui.JBColor) JBColor(com.intellij.ui.JBColor) CompoundBorder(javax.swing.border.CompoundBorder) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) EmptyBorder(javax.swing.border.EmptyBorder) UIResource(javax.swing.plaf.UIResource)

Example 9 with UIResource

use of javax.swing.plaf.UIResource in project intellij-community by JetBrains.

the class DialogWrapper method unregisterKeyboardActions.

public static void unregisterKeyboardActions(@Nullable Component rootPane) {
    int[] flags = { JComponent.WHEN_FOCUSED, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, JComponent.WHEN_IN_FOCUSED_WINDOW };
    for (JComponent eachComp : UIUtil.uiTraverser(rootPane).traverse().filter(JComponent.class)) {
        ActionMap actionMap = eachComp.getActionMap();
        if (actionMap == null)
            continue;
        for (KeyStroke eachStroke : eachComp.getRegisteredKeyStrokes()) {
            boolean remove = true;
            for (int i : flags) {
                Object key = eachComp.getInputMap(i).get(eachStroke);
                Action action = key == null ? null : actionMap.get(key);
                if (action instanceof UIResource)
                    remove = false;
            }
            if (remove)
                eachComp.unregisterKeyboardAction(eachStroke);
        }
    }
}
Also used : DumbAwareAction(com.intellij.openapi.project.DumbAwareAction) RelativePoint(com.intellij.ui.awt.RelativePoint) UIResource(javax.swing.plaf.UIResource)

Example 10 with UIResource

use of javax.swing.plaf.UIResource in project intellij-community by JetBrains.

the class JBList method installDefaultCopyAction.

private void installDefaultCopyAction() {
    final Action copy = getActionMap().get("copy");
    if (copy == null || copy instanceof UIResource) {
        Action newCopy = new AbstractAction() {

            @Override
            public boolean isEnabled() {
                return getSelectedIndex() != -1;
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                ArrayList<String> selected = new ArrayList<>();
                JBList list = JBList.this;
                ListCellRenderer renderer = list.getCellRenderer();
                if (renderer != null) {
                    for (int index : getSelectedIndices()) {
                        Object value = list.getModel().getElementAt(index);
                        //noinspection unchecked
                        Component c = renderer.getListCellRendererComponent(list, value, index, true, true);
                        SimpleColoredComponent coloredComponent = null;
                        if (c instanceof JComponent) {
                            coloredComponent = UIUtil.findComponentOfType((JComponent) c, SimpleColoredComponent.class);
                        }
                        if (coloredComponent != null) {
                            selected.add(coloredComponent.toString());
                        } else if (c instanceof JTextComponent) {
                            selected.add(((JTextComponent) c).getText());
                        } else if (value != null) {
                            selected.add(value.toString());
                        }
                    }
                }
                if (selected.size() > 0) {
                    String text = StringUtil.join(selected, " ");
                    CopyPasteManager.getInstance().setContents(new StringSelection(text));
                }
            }
        };
        getActionMap().put("copy", newCopy);
    }
}
Also used : ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) JTextComponent(javax.swing.text.JTextComponent) UIResource(javax.swing.plaf.UIResource) StringSelection(java.awt.datatransfer.StringSelection) JTextComponent(javax.swing.text.JTextComponent)

Aggregations

UIResource (javax.swing.plaf.UIResource)33 Border (javax.swing.border.Border)16 FocusEvent (java.awt.event.FocusEvent)6 FocusListener (java.awt.event.FocusListener)6 EmptyBorder (javax.swing.border.EmptyBorder)4 View (javax.swing.text.View)4 JBColor (com.intellij.ui.JBColor)3 Color (java.awt.Color)3 ColorUIResource (javax.swing.plaf.ColorUIResource)3 Area (java.awt.geom.Area)2 FontUIResource (javax.swing.plaf.FontUIResource)2 JTextComponent (javax.swing.text.JTextComponent)2 JRSUIState (apple.laf.JRSUIState)1 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)1 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)1 RelativePoint (com.intellij.ui.awt.RelativePoint)1 Component (java.awt.Component)1 Dimension (java.awt.Dimension)1 Insets (java.awt.Insets)1 StringSelection (java.awt.datatransfer.StringSelection)1