Search in sources :

Example 1 with DimensionUIResource

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

the class DarculaComboBoxUI method createArrowButton.

protected JButton createArrowButton() {
    final Color bg = myComboBox.getBackground();
    final Color fg = myComboBox.getForeground();
    JButton button = new BasicArrowButton(SwingConstants.SOUTH, bg, fg, fg, fg) {

        @Override
        public void paint(Graphics g2) {
            final Graphics2D g = (Graphics2D) g2;
            final GraphicsConfig config = new GraphicsConfig(g);
            final int w = getWidth();
            final int h = getHeight();
            if (!isTableCellEditor(myComboBox)) {
                g.setColor(getArrowButtonFillColor(UIUtil.getControlColor()));
                g.fillRect(0, 0, w, h);
            }
            g.setColor(new JBColor(Gray._255, comboBox.isEnabled() ? getForeground() : getBorderColor()));
            config.setupRoundedBorderAntialiasing();
            final int tW = JBUI.scale(8);
            final int tH = JBUI.scale(6);
            final int xU = (w - tW) / 2;
            final int yU = (h - tH) / 2;
            g.translate(JBUI.scale(2), JBUI.scale(1));
            final Path2D.Double path = new Path2D.Double();
            path.moveTo(xU, yU);
            path.lineTo(xU + tW, yU);
            path.lineTo(xU + tW / 2, yU + tH);
            path.lineTo(xU, yU);
            //path.moveTo(xU + 1, yU + 2);
            //path.lineTo(3 * xU + 1, yU + 2);
            //path.lineTo(2 * xU + 1, 3 * yU);
            //path.lineTo(xU + 1, yU + 2);
            path.closePath();
            g.fill(path);
            g.translate(-JBUI.scale(2), -JBUI.scale(1));
            if (!isTableCellEditor(myComboBox)) {
                g.setColor(getArrowButtonFillColor(getBorderColor()));
                g.drawLine(0, -1, 0, h);
            }
            config.restore();
        }

        @Override
        public Dimension getPreferredSize() {
            int size = getFont().getSize() + 4;
            if (size % 2 == 1)
                size++;
            return new DimensionUIResource(size, size);
        }
    };
    button.setBorder(BorderFactory.createEmptyBorder());
    button.setOpaque(false);
    return button;
}
Also used : BasicArrowButton(javax.swing.plaf.basic.BasicArrowButton) JBColor(com.intellij.ui.JBColor) Path2D(java.awt.geom.Path2D) JBColor(com.intellij.ui.JBColor) GraphicsConfig(com.intellij.openapi.ui.GraphicsConfig) DimensionUIResource(javax.swing.plaf.DimensionUIResource)

Example 2 with DimensionUIResource

use of javax.swing.plaf.DimensionUIResource in project jdk8u_jdk by JetBrains.

the class SynthSeparatorUI method updateStyle.

private void updateStyle(JSeparator sep) {
    SynthContext context = getContext(sep, ENABLED);
    SynthStyle oldStyle = style;
    style = SynthLookAndFeel.updateStyle(context, this);
    if (style != oldStyle) {
        if (sep instanceof JToolBar.Separator) {
            Dimension size = ((JToolBar.Separator) sep).getSeparatorSize();
            if (size == null || size instanceof UIResource) {
                size = (DimensionUIResource) style.get(context, "ToolBar.separatorSize");
                if (size == null) {
                    size = new DimensionUIResource(10, 10);
                }
                ((JToolBar.Separator) sep).setSeparatorSize(size);
            }
        }
    }
    context.dispose();
}
Also used : Dimension(java.awt.Dimension) DimensionUIResource(javax.swing.plaf.DimensionUIResource) UIResource(javax.swing.plaf.UIResource) DimensionUIResource(javax.swing.plaf.DimensionUIResource)

Example 3 with DimensionUIResource

use of javax.swing.plaf.DimensionUIResource in project jdk8u_jdk by JetBrains.

the class SynthParser method startProperty.

private void startProperty(Attributes attributes, Object property) throws SAXException {
    Object value = null;
    String key = null;
    // Type of the value: 0=idref, 1=boolean, 2=dimension, 3=insets,
    // 4=integer,5=string
    int iType = 0;
    String aValue = null;
    for (int i = attributes.getLength() - 1; i >= 0; i--) {
        String aName = attributes.getQName(i);
        if (aName.equals(ATTRIBUTE_TYPE)) {
            String type = attributes.getValue(i).toUpperCase();
            if (type.equals("IDREF")) {
                iType = 0;
            } else if (type.equals("BOOLEAN")) {
                iType = 1;
            } else if (type.equals("DIMENSION")) {
                iType = 2;
            } else if (type.equals("INSETS")) {
                iType = 3;
            } else if (type.equals("INTEGER")) {
                iType = 4;
            } else if (type.equals("STRING")) {
                iType = 5;
            } else {
                throw new SAXException(property + " unknown type, use" + "idref, boolean, dimension, insets or integer");
            }
        } else if (aName.equals(ATTRIBUTE_VALUE)) {
            aValue = attributes.getValue(i);
        } else if (aName.equals(ATTRIBUTE_KEY)) {
            key = attributes.getValue(i);
        }
    }
    if (aValue != null) {
        switch(iType) {
            case // idref
            0:
                value = lookup(aValue, Object.class);
                break;
            case // boolean
            1:
                if (aValue.toUpperCase().equals("TRUE")) {
                    value = Boolean.TRUE;
                } else {
                    value = Boolean.FALSE;
                }
                break;
            case // dimension
            2:
                StringTokenizer tok = new StringTokenizer(aValue);
                value = new DimensionUIResource(nextInt(tok, "Invalid dimension"), nextInt(tok, "Invalid dimension"));
                break;
            case // insets
            3:
                value = parseInsets(aValue, property + " invalid insets");
                break;
            case // integer
            4:
                try {
                    value = new Integer(Integer.parseInt(aValue));
                } catch (NumberFormatException nfe) {
                    throw new SAXException(property + " invalid value");
                }
                break;
            case //string
            5:
                value = aValue;
                break;
        }
    }
    if (value == null || key == null) {
        throw new SAXException(property + ": you must supply a " + "key and value");
    }
    if (property == ELEMENT_DEFAULTS_PROPERTY) {
        _defaultsMap.put(key, value);
    } else if (_stateInfo != null) {
        if (_stateInfo.getData() == null) {
            _stateInfo.setData(new HashMap());
        }
        _stateInfo.getData().put(key, value);
    } else if (_style != null) {
        if (_style.getData() == null) {
            _style.setData(new HashMap());
        }
        _style.getData().put(key, value);
    }
}
Also used : StringTokenizer(java.util.StringTokenizer) HashMap(java.util.HashMap) DimensionUIResource(javax.swing.plaf.DimensionUIResource) SAXException(org.xml.sax.SAXException)

Aggregations

DimensionUIResource (javax.swing.plaf.DimensionUIResource)3 GraphicsConfig (com.intellij.openapi.ui.GraphicsConfig)1 JBColor (com.intellij.ui.JBColor)1 Dimension (java.awt.Dimension)1 Path2D (java.awt.geom.Path2D)1 HashMap (java.util.HashMap)1 StringTokenizer (java.util.StringTokenizer)1 UIResource (javax.swing.plaf.UIResource)1 BasicArrowButton (javax.swing.plaf.basic.BasicArrowButton)1 SAXException (org.xml.sax.SAXException)1