Example usage for com.jgoodies.looks.plastic PlasticLookAndFeel getFocusColor

List of usage examples for com.jgoodies.looks.plastic PlasticLookAndFeel getFocusColor

Introduction

In this page you can find the example usage for com.jgoodies.looks.plastic PlasticLookAndFeel getFocusColor.

Prototype

public static ColorUIResource getFocusColor() 

Source Link

Usage

From source file:edu.ku.brc.ui.DropDownButton.java

License:Open Source License

/**
 * @param label//  w ww  . j  ava  2s  .com
 * @param icon
 * @param toolTip
 */
protected void init(final String label, final ImageIcon icon, final String toolTip, final boolean addArrowBtn) {
    setOpaque(false);

    FocusListener focusListener = UIHelper.isMacOS() ? createFocusListener() : null;
    MouseInputAdapter mouseInputAdapter = createMouseInputAdapter();

    mainBtn = createLabelBtn(label, icon, toolTip, this, focusListener, mouseInputAdapter, this, this,
            overrideButtonBorder);
    arrowBtn = createArrowBtn(mouseInputAdapter);
    mainBtn.setOpaque(false);

    popupAnchorComponent = mainBtn;

    PanelBuilder pb = new PanelBuilder(new FormLayout("p:g" + (addArrowBtn ? ",p" : ""), "f:p:g"), this);
    CellConstraints cc = new CellConstraints();

    pb.add(mainBtn, cc.xy(1, 1));
    if (addArrowBtn) {
        pb.add(arrowBtn, cc.xy(2, 1));
    }

    if (UIHelper.isMacOS()) {
        focusBorder = new MacBtnBorder();
        emptyBorder = new EmptyBorder(focusBorder.getBorderInsets(this));

    } else {
        if (UIManager.getLookAndFeel() instanceof PlasticLookAndFeel) {
            focusColor = PlasticLookAndFeel.getFocusColor();
        } else {
            focusColor = UIManager.getColor("Button.focus");
        }
        if (focusColor == null) {
            focusColor = Color.DARK_GRAY;
        }

        //focusBorder = new LineBorder(focusColor, 1, true);
        //emptyBorder = new EmptyBorder(focusBorder.getBorderInsets(this));
    }

    if (!overrideButtonBorder) {
        setBorder(emptyBorder);
    }

    addMouseListener(mouseInputAdapter);
    addMouseMotionListener(mouseInputAdapter);
}

From source file:edu.ku.brc.ui.RolloverCommand.java

License:Open Source License

/**
 * Helper function that paint the component.
 * @param g graphics/*from  w ww  .j  a v  a2 s.co m*/
 */
protected void paintComp(Graphics g) {
    super.paint(g);

    if (!isEditing) {
        Insets insets = getInsets();
        Dimension size = getSize();

        if (verticalLayout) {
            int y = insets.top;

            if (imgIcon != null && imgIcon.getImage() != null) {
                g.drawImage(imgIcon.getImage(), (size.width - imgIcon.getIconWidth()) / 2, y,
                        imgIcon.getIconWidth(), imgIcon.getIconHeight(), null);
                y += imgIcon.getIconHeight() + 1;
            }

            if (label != null) {
                if (defaultFont != null) {
                    g.setFont(defaultFont);
                }
                FontMetrics fm = g.getFontMetrics();
                g.setColor(getForeground());
                ((Graphics2D) g).setRenderingHints(UIHelper.createTextRenderingHints());
                g.drawString(label, (size.width - fm.stringWidth(label)) / 2, y + fm.getHeight());
            }

        } else {
            int x = insets.left + 1;
            int y = insets.top;

            int xOffset = 0;
            if (imgIcon != null && imgIcon.getImage() != null) {
                if (label == null) {
                    x = (size.width - imgIcon.getIconWidth()) / 2;
                }
                g.drawImage(imgIcon.getImage(), x, y + (size.height - imgIcon.getIconHeight()) / 2,
                        imgIcon.getIconWidth(), imgIcon.getIconHeight(), null);
                xOffset = imgIcon.getIconWidth() + ICON_TEXT_GAP;
            }

            if (label != null) {
                if (defaultFont != null) {
                    g.setFont(defaultFont);
                }
                FontMetrics fm = g.getFontMetrics();
                g.setColor(getForeground());
                ((Graphics2D) g).setRenderingHints(UIHelper.createTextRenderingHints());
                g.drawString(label, x + xOffset + 1, y + ((size.height - fm.getHeight()) / 2) + fm.getAscent());
            }

        }

        if ((isActive || (!DragAndDropLock.isDragAndDropStarted() && isOver)) && !this.hasFocus()) {
            Color color;
            if (isActive) {
                color = DragAndDropLock.isDragAndDropStarted() && isOver ? dropColor : activeColor;
            } else {
                Color mouseOverColor = dragFlavors.size() > 0 ? activeColor : hoverColor;
                color = (this.hasFocus() && UIManager.getLookAndFeel() instanceof PlasticLookAndFeel)
                        ? PlasticLookAndFeel.getFocusColor()
                        : mouseOverColor;
            }
            g.setColor(color);

            if (!useEmptyBorder) {
                insets.set(1, 1, 1, 1);
            }
            //g.drawRect(insets.left, insets.top, size.width-insets.right-insets.left, size.height-insets.bottom-insets.top);
            Graphics2D g2d = (Graphics2D) g;
            g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
            //g2d.setRenderingHints(hints);
            RoundRectangle2D.Double rr = new RoundRectangle2D.Double(insets.left, insets.top,
                    size.width - insets.right - insets.left, size.height - insets.bottom - insets.top, 10, 10);
            g2d.draw(rr);
            rr = new RoundRectangle2D.Double(insets.left + 1, insets.top + 1,
                    size.width - insets.right - insets.left - 2, size.height - insets.bottom - insets.top - 2,
                    10, 10);
            g2d.draw(rr);
        }

        if (isOver && hoverImg != null && isActive && DragAndDropLock.isDragAndDropStarted()) {
            int x = size.width - hoverImg.getIconWidth() - 1;
            int y = (size.height - hoverImg.getIconHeight()) / 2;
            g.drawImage(hoverImg.getImage(), x, y, null);
        }
    }
}

From source file:edu.ku.brc.ui.UIHelper.java

License:Open Source License

/**
 * @return a Triple containing the platform specific Focus Border, Empty Border and Focus Color
 *//*from   w w  w .  j a  v  a  2  s.  c o m*/
public static Triple<Border, Border, Color> getFocusBorders(final Component comp) {
    Triple<Border, Border, Color> focusInfo = new Triple<Border, Border, Color>();
    if (focusInfo.first == null) {
        if (UIHelper.isMacOS()) {
            focusInfo.first = new MacBtnBorder();
            Insets fbInsets = focusInfo.first.getBorderInsets(comp);
            focusInfo.second = new EmptyBorder(fbInsets);

        } else {
            if (UIManager.getLookAndFeel() instanceof PlasticLookAndFeel) {
                focusInfo.third = PlasticLookAndFeel.getFocusColor();
            } else {
                focusInfo.third = UIManager.getColor("Button.focus");
            }

            if (focusInfo.third == null) // Shouldn't happen
            {
                focusInfo.third = Color.YELLOW;
            }

            focusInfo.first = new LineBorder(focusInfo.third, 1, true);
            focusInfo.second = new EmptyBorder(focusBorder.getBorderInsets(comp));
        }
    }
    return focusInfo;
}