Search in sources :

Example 1 with ToolTip

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

the class PositionableLabelXml method loadCommonAttributes.

public void loadCommonAttributes(Positionable l, int defaultLevel, Element element) {
    Attribute a = element.getAttribute("forcecontroloff");
    if ((a != null) && a.getValue().equals("true")) {
        l.setControlling(false);
    } else {
        l.setControlling(true);
    }
    // find coordinates
    int x = 0;
    int y = 0;
    try {
        x = element.getAttribute("x").getIntValue();
        y = element.getAttribute("y").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert positional attribute");
    }
    l.setLocation(x, y);
    // find display level
    int level = defaultLevel;
    try {
        level = element.getAttribute("level").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    l.setDisplayLevel(level);
    a = element.getAttribute("hidden");
    if ((a != null) && a.getValue().equals("yes")) {
        l.setHidden(true);
        l.setVisible(false);
    }
    a = element.getAttribute("positionable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setPositionable(true);
    } else {
        l.setPositionable(false);
    }
    a = element.getAttribute("showtooltip");
    if ((a != null) && a.getValue().equals("true")) {
        l.setShowTooltip(true);
    } else {
        l.setShowTooltip(false);
    }
    a = element.getAttribute("editable");
    if ((a != null) && a.getValue().equals("true")) {
        l.setEditable(true);
    } else {
        l.setEditable(false);
    }
    a = element.getAttribute("degrees");
    if (a != null && l instanceof PositionableLabel) {
        try {
            int deg = a.getIntValue();
            ((PositionableLabel) l).setDegrees(deg);
        } catch (org.jdom2.DataConversionException dce) {
        }
    }
    Element elem = element.getChild("tooltip");
    if (elem == null) {
        // pre JMRI 3.5.2
        elem = element.getChild("toolTip");
    }
    if (elem != null) {
        ToolTip tip = l.getTooltip();
        if (tip != null) {
            tip.setText(elem.getText());
        }
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) PositionableLabel(jmri.jmrit.display.PositionableLabel) DataConversionException(org.jdom2.DataConversionException)

Example 2 with ToolTip

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

the class PositionableLabelXml method storeCommonAttributes.

/**
     * Default implementation for storing the common contents of an Icon
     *
     * @param p the icon to store
     * @param element the XML representation of the icon
     */
public void storeCommonAttributes(Positionable p, Element element) {
    element.setAttribute("x", "" + p.getX());
    element.setAttribute("y", "" + p.getY());
    element.setAttribute("level", String.valueOf(p.getDisplayLevel()));
    element.setAttribute("forcecontroloff", !p.isControlling() ? "true" : "false");
    element.setAttribute("hidden", p.isHidden() ? "yes" : "no");
    element.setAttribute("positionable", p.isPositionable() ? "true" : "false");
    element.setAttribute("showtooltip", p.showTooltip() ? "true" : "false");
    element.setAttribute("editable", p.isEditable() ? "true" : "false");
    ToolTip tip = p.getTooltip();
    String txt = tip.getText();
    if (txt != null) {
        // was written as "toolTip" 3.5.1 and before
        Element elem = new Element("tooltip").addContent(txt);
        element.addContent(elem);
    }
    if (p.getDegrees() != 0) {
        element.setAttribute("degrees", "" + p.getDegrees());
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Element(org.jdom2.Element)

Example 3 with ToolTip

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

the class PositionableShapeXml method storeCommonAttributes.

/**
     * Default implementation for storing the common contents
     *
     * @param element Element in which contents are stored
     */
public void storeCommonAttributes(PositionableShape p, Element element) {
    element.setAttribute("x", "" + p.getX());
    element.setAttribute("y", "" + p.getY());
    element.setAttribute("level", String.valueOf(p.getDisplayLevel()));
    element.setAttribute("forcecontroloff", !p.isControlling() ? "true" : "false");
    element.setAttribute("hidden", p.isHidden() ? "yes" : "no");
    element.setAttribute("positionable", p.isPositionable() ? "true" : "false");
    element.setAttribute("showtooltip", p.showTooltip() ? "true" : "false");
    element.setAttribute("editable", p.isEditable() ? "true" : "false");
    ToolTip tip = p.getTooltip();
    String txt = tip.getText();
    if (txt != null) {
        Element elem = new Element("toolTip").addContent(txt);
        element.addContent(elem);
    }
    if (p.getDegrees() != 0) {
        element.setAttribute("degrees", "" + p.getDegrees());
    }
    Element elem = storeColor("lineColor", p.getLineColor());
    if (elem != null) {
        element.addContent(elem);
    }
    elem = storeColor("fillColor", p.getFillColor());
    if (elem != null) {
        element.addContent(elem);
    }
    element.setAttribute("lineWidth", "" + p.getLineWidth());
    NamedBeanHandle<Sensor> handle = p.getControlSensorHandle();
    if (handle != null) {
        element.setAttribute("controlSensor", handle.getName());
    }
    element.setAttribute("hideOnSensor", p.isHideOnSensor() ? "true" : "false");
    element.setAttribute("changeLevelOnSensor", String.valueOf(p.getChangeLevel()));
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Element(org.jdom2.Element) Sensor(jmri.Sensor)

Example 4 with ToolTip

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

the class SwitchboardEditor method init.

/**
     * Initialize the newly created SwitchBoard.
     *
     * @param name name of the switchboard frame
     */
@Override
protected void init(String name) {
    //setVisible(false);
    // Editor
    Container contentPane = getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // make menus
    setGlobalSetsLocalFlag(false);
    setUseGlobalFlag(false);
    _menuBar = new JMenuBar();
    makeOptionMenu();
    //makeEditMenu();
    makeFileMenu();
    setJMenuBar(_menuBar);
    addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
    //super.setTargetPanel(null, makeFrame(name)); // original CPE version
    //extends JLayeredPane();
    switchboardLayeredPane = new TargetPane();
    switchboardLayeredPane.setPreferredSize(new Dimension(300, 310));
    switchboardLayeredPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(defaultTextColor), Bundle.getMessage("SwitchboardBanner"), TitledBorder.LEADING, TitledBorder.ABOVE_BOTTOM, getFont(), defaultTextColor));
    // create contrast with background, should also specify border style
    // specify title for turnout, sensor, light, mixed? (wait for the Editor to be created)
    switchboardLayeredPane.addMouseMotionListener(this);
    //Add control pane and layered pane to this JPanel
    JPanel beanSetupPane = new JPanel();
    beanSetupPane.setLayout(new FlowLayout(FlowLayout.TRAILING));
    JLabel beanTypeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanTypeLabel")));
    beanSetupPane.add(beanTypeTitle);
    beanTypeList = new JComboBox(beanTypeStrings);
    // select Turnout in comboBox
    beanTypeList.setSelectedIndex(0);
    beanTypeList.setActionCommand(LAYER_COMMAND);
    beanTypeList.addActionListener(this);
    beanSetupPane.add(beanTypeList);
    //Add connection selection comboBox
    // translate from selectedIndex to char
    beanTypeChar = getSwitchType().charAt(0);
    log.debug("beanTypeChar set to [{}]", beanTypeChar);
    JLabel beanManuTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ConnectionLabel")));
    beanSetupPane.add(beanManuTitle);
    beanManuNames = new JComboBox();
    if (getManager(beanTypeChar) instanceof jmri.managers.AbstractProxyManager) {
        // from abstractTableTabAction
        jmri.managers.AbstractProxyManager proxy = (jmri.managers.AbstractProxyManager) getManager(beanTypeChar);
        List<jmri.Manager> managerList = proxy.getManagerList();
        for (int x = 0; x < managerList.size(); x++) {
            String manuPrefix = managerList.get(x).getSystemPrefix();
            log.debug("Prefix = [{}]", manuPrefix);
            String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
            log.debug("Connection name = [{}]", manuName);
            // add to comboBox
            beanManuNames.addItem(manuName);
            // add to list
            beanManuPrefixes.add(manuPrefix);
        }
    } else {
        String manuPrefix = getManager(beanTypeChar).getSystemPrefix();
        String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
        beanManuNames.addItem(manuName);
        // add to list (as only item)
        beanManuPrefixes.add(manuPrefix);
    }
    beanManuNames.setSelectedIndex(0);
    beanManuNames.setActionCommand(MANU_COMMAND);
    beanManuNames.addActionListener(this);
    beanSetupPane.add(beanManuNames);
    add(beanSetupPane);
    // add shape combobox
    JPanel switchShapePane = new JPanel();
    switchShapePane.setLayout(new FlowLayout(FlowLayout.TRAILING));
    JLabel switchShapeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SwitchShape")));
    switchShapePane.add(switchShapeTitle);
    switchShapeList = new JComboBox(switchShapeStrings);
    // select Button in comboBox
    switchShapeList.setSelectedIndex(0);
    switchShapeList.setActionCommand(SWITCHTYPE_COMMAND);
    switchShapeList.addActionListener(this);
    switchShapePane.add(switchShapeList);
    // add column spinner
    JLabel columnLabel = new JLabel(Bundle.getMessage("NumberOfColumns"));
    switchShapePane.add(columnLabel);
    switchShapePane.add(Columns);
    add(switchShapePane);
    JCheckBox hideUnconnected = new JCheckBox(Bundle.getMessage("CheckBoxHideUnconnected"));
    hideUnconnected.setSelected(hideUnconnected());
    hideUnconnected.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setHideUnconnected(hideUnconnected.isSelected());
        }
    });
    add(hideUnconnected);
    // Next, add the buttons to the layered pane.
    switchboardLayeredPane.setLayout(new GridLayout(java.lang.Math.max(2, _range % ((Integer) Columns.getValue())), (Integer) Columns.getValue()));
    // vertical (at least 2 rows), horizontal
    // TODO do some calculation from JPanel size, icon size and determine optimal cols/rows
    addSwitchRange((Integer) minSpinner.getValue(), (Integer) maxSpinner.getValue(), beanTypeList.getSelectedIndex(), beanManuPrefixes.get(beanManuNames.getSelectedIndex()), switchShapeList.getSelectedIndex());
    // provide a JLayeredPane to place the switches on
    super.setTargetPanel(switchboardLayeredPane, makeFrame(name));
    // width x height
    super.getTargetFrame().setSize(550, 330);
    // To do: Add component listener to handle frame resizing event
    // set scrollbar initial state
    setScroll(SCROLL_NONE);
    scrollNone.setSelected(true);
    super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(this);
    }
    add(createControlPanel());
    JPanel updatePanel = new JPanel();
    JButton updateButton = new JButton(Bundle.getMessage("ButtonUpdate"));
    updateButton.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            log.debug("Update clicked");
            updatePressed();
        }
    });
    updatePanel.add(updateButton);
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
    contentPane.add(updatePanel);
    //re-layout all the toolbar items
    setupToolBar();
    // refresh default Switchboard
    updatePressed();
    pack();
    setVisible(true);
// TODO choose your own icons
//        class makeCatalog extends SwingWorker<CatalogPanel, Object> {
//
//            @Override
//            public CatalogPanel doInBackground() {
//                return CatalogPanel.makeDefaultCatalog();
//            }
//        }
//        (new makeCatalog()).execute();
//        log.debug("Init SwingWorker launched");
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) InstanceManager(jmri.InstanceManager) ConfigureManager(jmri.ConfigureManager) Manager(jmri.Manager) Font(java.awt.Font) Container(java.awt.Container) GridLayout(java.awt.GridLayout) ConfigureManager(jmri.ConfigureManager) JComboBox(javax.swing.JComboBox) Color(java.awt.Color) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) JCheckBox(javax.swing.JCheckBox) ActionListener(java.awt.event.ActionListener) JMenuBar(javax.swing.JMenuBar)

Example 5 with ToolTip

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

the class PortalIcon method setPortal.

public void setPortal(Portal portal) {
    if (portal == null) {
        return;
    }
    if (_portalHdl != null) {
        Portal port = getPortal();
        if (port.equals(portal)) {
            return;
        } else {
            port.removePropertyChangeListener(this);
        }
    }
    _portalHdl = jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(portal.getUserName(), portal);
    portal.addPropertyChangeListener(this);
    setName(portal.getName());
    setTooltip(new ToolTip(portal.getDescription(), 0, 0));
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Portal(jmri.jmrit.logix.Portal)

Aggregations

ToolTip (jmri.jmrit.display.ToolTip)9 Element (org.jdom2.Element)4 Color (java.awt.Color)3 Font (java.awt.Font)3 BoxLayout (javax.swing.BoxLayout)3 JMenuBar (javax.swing.JMenuBar)3 ConfigureManager (jmri.ConfigureManager)3 Container (java.awt.Container)2 Dimension (java.awt.Dimension)2 FlowLayout (java.awt.FlowLayout)2 ActionEvent (java.awt.event.ActionEvent)2 ActionListener (java.awt.event.ActionListener)2 JButton (javax.swing.JButton)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 Portal (jmri.jmrit.logix.Portal)2 Attribute (org.jdom2.Attribute)2 DataConversionException (org.jdom2.DataConversionException)2 GridLayout (java.awt.GridLayout)1 Point (java.awt.Point)1