Search in sources :

Example 6 with ToolTip

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

the class PanelEditor method init.

@Override
protected void init(String name) {
    Runnable r = new Runnable() {

        @Override
        public void run() {
            try {
                // Build resource catalog and load CatalogTree.xml now
                jmri.jmrit.catalog.CatalogPanel catalog = new jmri.jmrit.catalog.CatalogPanel();
                catalog.createNewBranch("IFJAR", "Program Directory", "resources");
            } catch (Exception ex) {
                log.error("Error in trying to setup preferences " + ex.toString());
            }
        }
    };
    Thread thr = new Thread(r);
    thr.start();
    java.awt.Container contentPane = this.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // common items
    JPanel common = new JPanel();
    common.setLayout(new FlowLayout());
    common.add(new JLabel(" x:"));
    common.add(nextX);
    common.add(new JLabel(" y:"));
    common.add(nextY);
    contentPane.add(common);
    setAllEditable(true);
    setShowHidden(true);
    super.setTargetPanel(null, makeFrame(name));
    super.setTargetPanelSize(400, 300);
    super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("SansSerif", Font.PLAIN, 12), Color.black, new Color(215, 225, 255), Color.black));
    // set scrollbar initial state
    setScroll(SCROLL_BOTH);
    // add menu - not using PanelMenu, because it now
    // has other stuff in it?
    JMenuBar menuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    menuBar.add(fileMenu);
    fileMenu.add(new jmri.jmrit.display.NewPanelAction(Bundle.getMessage("MenuItemNew")));
    fileMenu.add(new jmri.configurexml.StoreXmlUserAction(Bundle.getMessage("MenuItemStore")));
    JMenuItem storeIndexItem = new JMenuItem(Bundle.getMessage("MIStoreImageIndex"));
    fileMenu.add(storeIndexItem);
    storeIndexItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            jmri.jmrit.catalog.ImageIndexEditor.storeImageIndex();
        }
    });
    JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
    editItem.addActionListener(new ActionListener() {

        PanelEditor panelEd;

        @Override
        public void actionPerformed(ActionEvent e) {
            ImageIndexEditor ii = ImageIndexEditor.instance(panelEd);
            ii.pack();
            ii.setVisible(true);
        }

        ActionListener init(PanelEditor pe) {
            panelEd = pe;
            return this;
        }
    }.init(this));
    fileMenu.add(editItem);
    editItem = new JMenuItem(Bundle.getMessage("CPEView"));
    fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            changeView("jmri.jmrit.display.controlPanelEditor.ControlPanelEditor");
        }
    });
    fileMenu.addSeparator();
    JMenuItem deleteItem = new JMenuItem(Bundle.getMessage("DeletePanel"));
    fileMenu.add(deleteItem);
    deleteItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            if (deletePanel()) {
                dispose(true);
            }
        }
    });
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.display.PanelEditor", true);
    // allow naming the panel
    {
        JPanel namep = new JPanel();
        namep.setLayout(new FlowLayout());
        JButton b = new JButton(Bundle.getMessage("ButtonSetName"));
        b.addActionListener(new ActionListener() {

            PanelEditor editor;

            @Override
            public void actionPerformed(ActionEvent e) {
                // prompt for name
                String newName = JOptionPane.showInputDialog(null, Bundle.getMessage("PromptNewName"));
                if (newName == null) {
                    // cancelled
                    return;
                }
                if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(newName)) {
                    JOptionPane.showMessageDialog(null, Bundle.getMessage("CanNotRename"), Bundle.getMessage("PanelExist"), JOptionPane.ERROR_MESSAGE);
                    return;
                }
                if (getTargetPanel().getTopLevelAncestor() != null) {
                    ((JFrame) getTargetPanel().getTopLevelAncestor()).setTitle(newName);
                }
                editor.setTitle();
                jmri.jmrit.display.PanelMenu.instance().renameEditorPanel(editor);
            }

            ActionListener init(PanelEditor e) {
                editor = e;
                return this;
            }
        }.init(this));
        namep.add(b);
        this.getContentPane().add(namep);
    }
    // add a text label
    {
        JPanel panel = new JPanel();
        panel.setLayout(new FlowLayout());
        panel.add(labelAdd);
        labelAdd.setEnabled(false);
        labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
        panel.add(nextLabel);
        labelAdd.addActionListener(new ActionListener() {

            PanelEditor editor;

            @Override
            public void actionPerformed(ActionEvent a) {
                editor.addLabel(nextLabel.getText());
            }

            ActionListener init(PanelEditor e) {
                editor = e;
                return this;
            }
        }.init(this));
        nextLabel.addKeyListener(new KeyAdapter() {

            @Override
            public void keyReleased(KeyEvent a) {
                if (nextLabel.getText().equals("")) {
                    labelAdd.setEnabled(false);
                    labelAdd.setToolTipText(Bundle.getMessage("ToolTipWillActivate"));
                } else {
                    labelAdd.setEnabled(true);
                    labelAdd.setToolTipText(null);
                }
            }
        });
        this.getContentPane().add(panel);
    }
    // Selection of the type of entity for the icon to represent is done from a combobox
    _addIconBox = new JComboBox<ComboBoxItem>();
    _addIconBox.setMinimumSize(new Dimension(75, 75));
    _addIconBox.setMaximumSize(new Dimension(200, 200));
    _addIconBox.addItem(new ComboBoxItem("RightTurnout"));
    _addIconBox.addItem(new ComboBoxItem("LeftTurnout"));
    _addIconBox.addItem(new ComboBoxItem("SlipTOEditor"));
    // NOI18N
    _addIconBox.addItem(new ComboBoxItem("Sensor"));
    _addIconBox.addItem(new ComboBoxItem("SignalHead"));
    _addIconBox.addItem(new ComboBoxItem("SignalMast"));
    _addIconBox.addItem(new ComboBoxItem("Memory"));
    _addIconBox.addItem(new ComboBoxItem("BlockLabel"));
    _addIconBox.addItem(new ComboBoxItem("Reporter"));
    _addIconBox.addItem(new ComboBoxItem("Light"));
    _addIconBox.addItem(new ComboBoxItem("Background"));
    _addIconBox.addItem(new ComboBoxItem("MultiSensor"));
    _addIconBox.addItem(new ComboBoxItem("RPSreporter"));
    _addIconBox.addItem(new ComboBoxItem("FastClock"));
    _addIconBox.addItem(new ComboBoxItem("Icon"));
    _addIconBox.setSelectedIndex(-1);
    // must be AFTER no selection is set
    _addIconBox.addItemListener(this);
    JPanel p1 = new JPanel();
    p1.setLayout(new BoxLayout(p1, BoxLayout.Y_AXIS));
    JPanel p2 = new JPanel();
    p2.setLayout(new FlowLayout());
    p2.add(new JLabel(Bundle.getMessage("selectTypeIcon")));
    p1.add(p2);
    p1.add(_addIconBox);
    contentPane.add(p1);
    // edit, position, control controls
    {
        // edit mode item
        contentPane.add(editableBox);
        editableBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                setAllEditable(editableBox.isSelected());
                hiddenCheckBoxListener();
            }
        });
        editableBox.setSelected(isEditable());
        // positionable item
        contentPane.add(positionableBox);
        positionableBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                setAllPositionable(positionableBox.isSelected());
            }
        });
        positionableBox.setSelected(allPositionable());
        // controlable item
        contentPane.add(controllingBox);
        controllingBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent event) {
                setAllControlling(controllingBox.isSelected());
            }
        });
        controllingBox.setSelected(allControlling());
        // hidden item
        contentPane.add(hiddenBox);
        hiddenCheckBoxListener();
        hiddenBox.setSelected(showHidden());
        /*
             contentPane.add(showCoordinatesBox);
             showCoordinatesBox.addActionListener(new ActionListener() {
             public void actionPerformed(ActionEvent e) {
             setShowCoordinates(showCoordinatesBox.isSelected());
             }
             });
             showCoordinatesBox.setSelected(showCoordinates());
             */
        contentPane.add(showTooltipBox);
        showTooltipBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setAllShowTooltip(showTooltipBox.isSelected());
            }
        });
        showTooltipBox.setSelected(showTooltip());
        contentPane.add(menuBox);
        menuBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setPanelMenuVisible(menuBox.isSelected());
            }
        });
        menuBox.setSelected(true);
        // Show/Hide Scroll Bars
        JPanel scrollPanel = new JPanel();
        scrollPanel.setLayout(new FlowLayout());
        scrollableLabel.setLabelFor(scrollableComboBox);
        scrollPanel.add(scrollableLabel);
        scrollPanel.add(scrollableComboBox);
        contentPane.add(scrollPanel);
        scrollableComboBox.addItem(Bundle.getMessage("ScrollNone"));
        scrollableComboBox.addItem(Bundle.getMessage("ScrollBoth"));
        scrollableComboBox.addItem(Bundle.getMessage("ScrollHorizontal"));
        scrollableComboBox.addItem(Bundle.getMessage("ScrollVertical"));
        scrollableComboBox.setSelectedIndex(SCROLL_BOTH);
        scrollableComboBox.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                setScroll(scrollableComboBox.getSelectedIndex());
            }
        });
    }
    // register the resulting panel for later configuration
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerUser(this);
    }
    // when this window closes, set contents of target uneditable
    addWindowListener(new java.awt.event.WindowAdapter() {

        HashMap<String, JFrameItem> iconAdderFrames;

        @Override
        public void windowClosing(java.awt.event.WindowEvent e) {
            Iterator<JFrameItem> iter = iconAdderFrames.values().iterator();
            while (iter.hasNext()) {
                JFrameItem frame = iter.next();
                frame.dispose();
            }
        }

        WindowAdapter init(HashMap<String, JFrameItem> f) {
            iconAdderFrames = f;
            return this;
        }
    }.init(_iconEditorFrame));
    // and don't destroy the window
    setDefaultCloseOperation(JDialog.HIDE_ON_CLOSE);
    // move this editor panel off the panel's position
    getTargetFrame().setLocationRelativeTo(this);
    getTargetFrame().pack();
    getTargetFrame().setVisible(true);
    log.debug("PanelEditor ctor done.");
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) HashMap(java.util.HashMap) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) Font(java.awt.Font) KeyEvent(java.awt.event.KeyEvent) ConfigureManager(jmri.ConfigureManager) JMenuItem(javax.swing.JMenuItem) Color(java.awt.Color) JLabel(javax.swing.JLabel) Dimension(java.awt.Dimension) ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 7 with ToolTip

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

the class ControlPanelEditor method init.

@Override
protected void init(String name) {
    setVisible(false);
    java.awt.Container contentPane = this.getContentPane();
    contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
    // make menus
    setGlobalSetsLocalFlag(false);
    setUseGlobalFlag(false);
    _menuBar = new JMenuBar();
    _circuitBuilder = new CircuitBuilder(this);
    _shapeDrawer = new ShapeDrawer(this);
    makeDrawMenu();
    makeWarrantMenu(false);
    makeIconMenu();
    makeZoomMenu();
    makeMarkerMenu();
    makeOptionMenu();
    makeEditMenu();
    makeFileMenu();
    setJMenuBar(_menuBar);
    addHelpMenu("package.jmri.jmrit.display.ControlPanelEditor", true);
    super.setTargetPanel(null, null);
    super.setTargetPanelSize(300, 300);
    makeDataFlavors();
    // set scrollbar initial state
    setScroll(SCROLL_BOTH);
    scrollBoth.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);
    }
    pack();
    setVisible(true);
    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) BoxLayout(javax.swing.BoxLayout) Color(java.awt.Color) Font(java.awt.Font) ShapeDrawer(jmri.jmrit.display.controlPanelEditor.shape.ShapeDrawer) ConfigureManager(jmri.ConfigureManager) SwingWorker(javax.swing.SwingWorker) Container(java.awt.Container) JMenuBar(javax.swing.JMenuBar)

Example 8 with ToolTip

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

the class EditCircuitFrame method changeBlockName.

/**
     * *********************** end setup *************************
     */
private void changeBlockName() {
    String name = _blockName.getText();
    if (name == null || name.trim().length() == 0) {
        JOptionPane.showMessageDialog(this, Bundle.getMessage("changeBlockName"), Bundle.getMessage("editCiruit"), JOptionPane.INFORMATION_MESSAGE);
        return;
    }
    _block.setUserName(name);
    // block user name change will change portal names.  Change PortalIcon names to match
    java.util.List<Positionable> list = _parent.getCircuitIcons(_block);
    if (list != null) {
        for (int i = 0; i < list.size(); i++) {
            if (list.get(i) instanceof PortalIcon) {
                PortalIcon icon = (PortalIcon) list.get(i);
                Portal portal = icon.getPortal();
                icon.setName(portal.getName());
                icon.setTooltip(new ToolTip(portal.getDescription(), 0, 0));
            }
        }
    }
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) Point(java.awt.Point)

Example 9 with ToolTip

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

the class PositionableShapeXml method loadCommonAttributes.

public void loadCommonAttributes(PositionableShape ps, int defaultLevel, Element element) {
    int x = getInt(element, "x");
    int y = getInt(element, "y");
    ps.setLocation(x, y);
    ps.setDisplayLevel(getInt(element, "level"));
    Attribute a = element.getAttribute("hidden");
    if ((a != null) && a.getValue().equals("yes")) {
        ps.setHidden(true);
        ps.setVisible(false);
    }
    a = element.getAttribute("positionable");
    if ((a != null) && a.getValue().equals("true")) {
        ps.setPositionable(true);
    } else {
        ps.setPositionable(false);
    }
    a = element.getAttribute("showtooltip");
    if ((a != null) && a.getValue().equals("true")) {
        ps.setShowTooltip(true);
    } else {
        ps.setShowTooltip(false);
    }
    a = element.getAttribute("editable");
    if ((a != null) && a.getValue().equals("true")) {
        ps.setEditable(true);
    } else {
        ps.setEditable(false);
    }
    Element elem = element.getChild("toolTip");
    if (elem != null) {
        ToolTip tip = ps.getTooltip();
        if (tip != null) {
            tip.setText(elem.getText());
        }
    }
    ps.setLineWidth(getInt(element, "lineWidth"));
    int alpha = -1;
    try {
        a = element.getAttribute("alpha");
        if (a != null) {
            alpha = a.getIntValue();
        }
    } catch (DataConversionException ex) {
        log.warn("invalid 'alpha' value (non integer)");
    }
    ps.setLineColor(getColor(element, "lineColor", alpha));
    ps.setFillColor(getColor(element, "fillColor", alpha));
    ps.makeShape();
    ps.rotate(getInt(element, "degrees"));
    a = element.getAttribute("hideOnSensor");
    boolean hide = false;
    if (a != null) {
        hide = a.getValue().equals("true");
    }
    int changeLevel = -1;
    try {
        changeLevel = getInt(element, "changeLevelOnSensor");
    } catch (Exception e) {
        log.error("failed to get changeLevel attribute ex= " + e);
    }
    try {
        Attribute attr = element.getAttribute("controlSensor");
        if (attr != null) {
            ps.setControlSensor(attr.getValue(), hide, changeLevel);
        }
    } catch (NullPointerException e) {
        log.error("incorrect information for controlSensor of PositionableShape");
    }
    ps.updateSize();
}
Also used : ToolTip(jmri.jmrit.display.ToolTip) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException) DataConversionException(org.jdom2.DataConversionException)

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