Search in sources :

Example 1 with PositionablePopupUtil

use of jmri.jmrit.display.PositionablePopupUtil in project JMRI by JMRI.

the class PositionableLabelXml method storeTextInfo.

/**
     * Store the text formatting information.
     * <p>
     * This is always stored, even if the icon isn't in text mode, because some
     * uses (subclasses) of PositionableLabel flip back and forth between icon
     * and text, and want to remember their formatting.
     *
     * @param p the icon to store
     * @param element the XML representation of the icon
     */
protected void storeTextInfo(Positionable p, Element element) {
    //if (p.getText()!=null) element.setAttribute("text", p.getText());
    PositionablePopupUtil util = p.getPopupUtility();
    element.setAttribute("size", "" + util.getFontSize());
    element.setAttribute("style", "" + util.getFontStyle());
    // always write the foreground (text) color
    element.setAttribute("red", "" + util.getForeground().getRed());
    element.setAttribute("green", "" + util.getForeground().getGreen());
    element.setAttribute("blue", "" + util.getForeground().getBlue());
    element.setAttribute("hasBackground", util.hasBackground() ? "yes" : "no");
    if (util.hasBackground()) {
        element.setAttribute("redBack", "" + util.getBackground().getRed());
        element.setAttribute("greenBack", "" + util.getBackground().getGreen());
        element.setAttribute("blueBack", "" + util.getBackground().getBlue());
    }
    if (util.getMargin() != 0) {
        element.setAttribute("margin", "" + util.getMargin());
    }
    if (util.getBorderSize() != 0) {
        element.setAttribute("borderSize", "" + util.getBorderSize());
        element.setAttribute("redBorder", "" + util.getBorderColor().getRed());
        element.setAttribute("greenBorder", "" + util.getBorderColor().getGreen());
        element.setAttribute("blueBorder", "" + util.getBorderColor().getBlue());
    }
    if (util.getFixedWidth() != 0) {
        element.setAttribute("fixedWidth", "" + util.getFixedWidth());
    }
    if (util.getFixedHeight() != 0) {
        element.setAttribute("fixedHeight", "" + util.getFixedHeight());
    }
    String just;
    switch(util.getJustification()) {
        case 0x02:
            just = "right";
            break;
        case 0x04:
            just = "centre";
            break;
        default:
            just = "left";
            break;
    }
    element.setAttribute("justification", just);
    if (util.getOrientation() != PositionablePopupUtil.HORIZONTAL) {
        String ori;
        switch(util.getOrientation()) {
            case PositionablePopupUtil.VERTICAL_DOWN:
                ori = "vertical_down";
                break;
            case PositionablePopupUtil.VERTICAL_UP:
                ori = "vertical_up";
                break;
            default:
                ori = "horizontal";
                break;
        }
        element.setAttribute("orientation", ori);
    }
//return element;
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil)

Example 2 with PositionablePopupUtil

use of jmri.jmrit.display.PositionablePopupUtil in project JMRI by JMRI.

the class DecoratorPanel method updateSamples.

private void updateSamples() {
    if (_previewPanel == null) {
        return;
    }
    int mar = _util.getMargin();
    int bor = _util.getBorderSize();
    Border outlineBorder;
    if (bor == 0) {
        outlineBorder = BorderFactory.createEmptyBorder(0, 0, 0, 0);
    } else {
        outlineBorder = new LineBorder(_util.getBorderColor(), bor);
    }
    Font font = _util.getFont();
    int just = _util.getJustification();
    Iterator<PositionableLabel> it = _sample.values().iterator();
    while (it.hasNext()) {
        PositionableLabel sam = it.next();
        PositionablePopupUtil util = sam.getPopupUtility();
        sam.setFont(font);
        util.setFixedWidth(_util.getFixedWidth());
        util.setFixedHeight(_util.getFixedHeight());
        util.setMargin(mar);
        util.setBorderSize(bor);
        Border borderMargin;
        if (sam.isOpaque()) {
            borderMargin = new LineBorder(sam.getBackground(), mar);
        } else {
            borderMargin = BorderFactory.createEmptyBorder(mar, mar, mar, mar);
        }
        sam.setBorder(new CompoundBorder(outlineBorder, borderMargin));
        switch(just) {
            case PositionablePopupUtil.LEFT:
                sam.setHorizontalAlignment(JLabel.LEFT);
                break;
            case PositionablePopupUtil.RIGHT:
                sam.setHorizontalAlignment(JLabel.RIGHT);
                break;
            default:
                sam.setHorizontalAlignment(JLabel.CENTER);
        }
        sam.updateSize();
        sam.setPreferredSize(sam.getSize());
        sam.repaint();
    }
    if (_dialog != null) {
        _dialog.pack();
    }
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) LineBorder(javax.swing.border.LineBorder) PositionableLabel(jmri.jmrit.display.PositionableLabel) CompoundBorder(javax.swing.border.CompoundBorder) LineBorder(javax.swing.border.LineBorder) Border(javax.swing.border.Border) CompoundBorder(javax.swing.border.CompoundBorder) Font(java.awt.Font)

Example 3 with PositionablePopupUtil

use of jmri.jmrit.display.PositionablePopupUtil in project JMRI by JMRI.

the class PanelEditor method showPopUp.

/**
     * Create popup for a Positionable object Popup items common to all
     * positionable objects are done before and after the items that pertain
     * only to specific Positionable types.
     */
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
    if (!((JComponent) p).isVisible()) {
        // component must be showing on the screen to determine its location
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    PositionablePopupUtil util = p.getPopupUtility();
    if (p.isEditable()) {
        // items for all Positionables
        if (p.doViemMenu()) {
            popup.add(p.getNameString());
            setPositionableMenu(p, popup);
            if (p.isPositionable()) {
                setShowCoordinatesMenu(p, popup);
                setShowAlignmentMenu(p, popup);
            }
            setDisplayLevelMenu(p, popup);
            setHiddenMenu(p, popup);
            popup.addSeparator();
        }
        // Positionable items with defaults or using overrides
        boolean popupSet = false;
        popupSet |= p.setRotateOrthogonalMenu(popup);
        popupSet |= p.setRotateMenu(popup);
        popupSet |= p.setScaleMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setEditIconMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setTextEditMenu(popup);
        if (util != null) {
            util.setFixedTextMenu(popup);
            util.setTextMarginMenu(popup);
            util.setTextBorderMenu(popup);
            util.setTextFontMenu(popup);
            util.setBackgroundMenu(popup);
            util.setTextJustificationMenu(popup);
            util.setTextOrientationMenu(popup);
            util.copyItem(popup);
            popup.addSeparator();
            util.propertyUtil(popup);
            util.setAdditionalEditPopUpMenu(popup);
            popupSet = true;
        }
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        p.setDisableControlMenu(popup);
        // for Positionables with unique item settings
        p.showPopUp(popup);
        setRemoveMenu(p, popup);
    } else {
        p.showPopUp(popup);
        if (util != null) {
            util.setAdditionalViewPopUpMenu(popup);
        }
    }
    popup.show((Component) p, p.getWidth() / 2, p.getHeight() / 2);
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) JPopupMenu(javax.swing.JPopupMenu)

Example 4 with PositionablePopupUtil

use of jmri.jmrit.display.PositionablePopupUtil in project JMRI by JMRI.

the class ControlPanelEditor method showPopUp.

/**
     * Create popup for a Positionable object Popup items common to all
     * positionable objects are done before and after the items that pertain
     * only to specific Positionable types.
     */
@Override
protected void showPopUp(Positionable p, MouseEvent event) {
    if (!((JComponent) p).isVisible()) {
        // component must be showing on the screen to determine its location
        return;
    }
    JPopupMenu popup = new JPopupMenu();
    PositionablePopupUtil util = p.getPopupUtility();
    if (p.isEditable()) {
        // items common to all
        if (p.doViemMenu()) {
            popup.add(p.getNameString());
            setPositionableMenu(p, popup);
            if (p.isPositionable()) {
                setShowCoordinatesMenu(p, popup);
                setShowAlignmentMenu(p, popup);
            }
            setDisplayLevelMenu(p, popup);
            setHiddenMenu(p, popup);
            popup.addSeparator();
            setCopyMenu(p, popup);
        }
        // items with defaults or using overrides
        boolean popupSet = false;
        //            popupSet |= p.setRotateOrthogonalMenu(popup);
        popupSet |= p.setRotateMenu(popup);
        popupSet |= p.setScaleMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        popupSet = p.setEditItemMenu(popup);
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        if (p instanceof PositionableLabel) {
            PositionableLabel pl = (PositionableLabel) p;
            /*                if (pl.isIcon() && "javax.swing.JLabel".equals(pl.getClass().getSuperclass().getName()) ) {
                    popupSet |= setTextAttributes(pl, popup);       // only for plain icons
                }   Add backgrounds & text over icons later */
            if (!pl.isIcon()) {
                popupSet |= setTextAttributes(pl, popup);
                if (p instanceof MemoryIcon) {
                    popupSet |= p.setTextEditMenu(popup);
                }
            } else if (p instanceof SensorIcon) {
                popup.add(CoordinateEdit.getTextEditAction(p, "OverlayText"));
                if (pl.isText()) {
                    popupSet |= setTextAttributes(p, popup);
                }
            } else {
                popupSet = p.setTextEditMenu(popup);
            }
        } else if (p instanceof PositionableJPanel) {
            popupSet |= setTextAttributes(p, popup);
        }
        if (p instanceof LinkingObject) {
            ((LinkingObject) p).setLinkMenu(popup);
        }
        if (popupSet) {
            popup.addSeparator();
            popupSet = false;
        }
        p.setDisableControlMenu(popup);
        if (util != null) {
            util.setAdditionalEditPopUpMenu(popup);
        }
        // for Positionables with unique settings
        p.showPopUp(popup);
        if (p.doViemMenu()) {
            setShowTooltipMenu(p, popup);
            setRemoveMenu(p, popup);
        }
    } else {
        if (p instanceof LocoIcon) {
            setCopyMenu(p, popup);
        }
        p.showPopUp(popup);
        if (util != null) {
            util.setAdditionalViewPopUpMenu(popup);
        }
    }
    popup.show((Component) p, p.getWidth() / 2 + (int) ((getPaintScale() - 1.0) * p.getX()), p.getHeight() / 2 + (int) ((getPaintScale() - 1.0) * p.getY()));
    _currentSelection = null;
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) SensorIcon(jmri.jmrit.display.SensorIcon) LinkingObject(jmri.jmrit.display.LinkingObject) LocoIcon(jmri.jmrit.display.LocoIcon) MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableLabel(jmri.jmrit.display.PositionableLabel) JPopupMenu(javax.swing.JPopupMenu) PositionableJPanel(jmri.jmrit.display.PositionableJPanel)

Example 5 with PositionablePopupUtil

use of jmri.jmrit.display.PositionablePopupUtil in project JMRI by JMRI.

the class PositionableLabelXml method loadTextInfo.

protected void loadTextInfo(Positionable l, Element element) {
    if (log.isDebugEnabled()) {
        log.debug("loadTextInfo");
    }
    jmri.jmrit.display.PositionablePopupUtil util = l.getPopupUtility();
    if (util == null) {
        log.warn("PositionablePopupUtil is null! " + element.toString());
        return;
    }
    Attribute a = element.getAttribute("size");
    try {
        if (a != null) {
            util.setFontSize(a.getFloatValue());
        }
    } catch (DataConversionException ex) {
        log.warn("invalid size attribute value");
    }
    a = element.getAttribute("style");
    try {
        if (a != null) {
            int style = a.getIntValue();
            int drop = 0;
            switch(style) {
                case 0:
                    //0 Normal
                    drop = 1;
                    break;
                case 2:
                    //italic
                    drop = 1;
                    break;
                default:
                    // fall through
                    break;
            }
            util.setFontStyle(style, drop);
        }
    } catch (DataConversionException ex) {
        log.warn("invalid style attribute value");
    }
    // set color if needed
    try {
        int red = element.getAttribute("red").getIntValue();
        int blue = element.getAttribute("blue").getIntValue();
        int green = element.getAttribute("green").getIntValue();
        util.setForeground(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse color attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    a = element.getAttribute("hasBackground");
    if (a != null) {
        util.setHasBackground("yes".equals(a.getValue()));
    } else {
        util.setHasBackground(true);
    }
    if (util.hasBackground()) {
        try {
            int red = element.getAttribute("redBack").getIntValue();
            int blue = element.getAttribute("blueBack").getIntValue();
            int green = element.getAttribute("greenBack").getIntValue();
            util.setBackgroundColor(new Color(red, green, blue));
        } catch (org.jdom2.DataConversionException e) {
            log.warn("Could not parse background color attributes!");
        } catch (NullPointerException e) {
            // if the attributes are not listed, we consider the background as clear.
            util.setHasBackground(false);
        }
    }
    int fixedWidth = 0;
    int fixedHeight = 0;
    try {
        fixedHeight = element.getAttribute("fixedHeight").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse fixed Height attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    try {
        fixedWidth = element.getAttribute("fixedWidth").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse fixed Width attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    if (!(fixedWidth == 0 && fixedHeight == 0)) {
        util.setFixedSize(fixedWidth, fixedHeight);
    }
    if ((util.getFixedWidth() == 0) || (util.getFixedHeight() == 0)) {
        try {
            util.setMargin(element.getAttribute("margin").getIntValue());
        } catch (org.jdom2.DataConversionException e) {
            log.warn("Could not parse margin attribute!");
        } catch (NullPointerException e) {
        // considered normal if the attributes are not present
        }
    }
    try {
        util.setBorderSize(element.getAttribute("borderSize").getIntValue());
        int red = element.getAttribute("redBorder").getIntValue();
        int blue = element.getAttribute("blueBorder").getIntValue();
        int green = element.getAttribute("greenBorder").getIntValue();
        util.setBorderColor(new Color(red, green, blue));
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse border attributes!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    a = element.getAttribute("justification");
    if (a != null) {
        util.setJustification(a.getValue());
    } else {
        util.setJustification("left");
    }
    a = element.getAttribute("orientation");
    if (a != null) {
        util.setOrientation(a.getValue());
    } else {
        util.setOrientation("horizontal");
    }
    int deg = 0;
    try {
        a = element.getAttribute("degrees");
        if (a != null) {
            deg = a.getIntValue();
            l.rotate(deg);
        }
    } catch (DataConversionException ex) {
        log.warn("invalid 'degrees' value (non integer)");
    }
    if (deg == 0 && util.hasBackground()) {
        l.setOpaque(true);
    }
}
Also used : PositionablePopupUtil(jmri.jmrit.display.PositionablePopupUtil) Attribute(org.jdom2.Attribute) Color(java.awt.Color) DataConversionException(org.jdom2.DataConversionException) DataConversionException(org.jdom2.DataConversionException)

Aggregations

PositionablePopupUtil (jmri.jmrit.display.PositionablePopupUtil)6 JPopupMenu (javax.swing.JPopupMenu)2 PositionableLabel (jmri.jmrit.display.PositionableLabel)2 Color (java.awt.Color)1 Font (java.awt.Font)1 Border (javax.swing.border.Border)1 CompoundBorder (javax.swing.border.CompoundBorder)1 LineBorder (javax.swing.border.LineBorder)1 LinkingObject (jmri.jmrit.display.LinkingObject)1 LocoIcon (jmri.jmrit.display.LocoIcon)1 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 PositionableJPanel (jmri.jmrit.display.PositionableJPanel)1 SensorIcon (jmri.jmrit.display.SensorIcon)1 Attribute (org.jdom2.Attribute)1 DataConversionException (org.jdom2.DataConversionException)1