Search in sources :

Example 1 with ImageIndexEditor

use of jmri.jmrit.catalog.ImageIndexEditor in project JMRI by JMRI.

the class Editor method makeAddIconFrame.

protected JFrameItem makeAddIconFrame(String name, boolean add, boolean table, IconAdder editor) {
    log.debug("makeAddIconFrame for {}, add= {}, table= ", name, add, table);
    String txt;
    String BundleName;
    JFrameItem frame = new JFrameItem(name, editor);
    // use NamedBeanBundle property for basic beans like "Turnout" I18N
    if ("Sensor".equals(name)) {
        BundleName = "BeanNameSensor";
    } else if ("SignalHead".equals(name)) {
        BundleName = "BeanNameSignalHead";
    } else if ("SignalMast".equals(name)) {
        BundleName = "BeanNameSignalMast";
    } else if ("Memory".equals(name)) {
        BundleName = "BeanNameMemory";
    } else if ("Reporter".equals(name)) {
        BundleName = "BeanNameReporter";
    } else if ("Light".equals(name)) {
        BundleName = "BeanNameLight";
    } else if ("Turnout".equals(name)) {
        // called by RightTurnout and LeftTurnout objects in TurnoutIcon.java edit() method
        BundleName = "BeanNameTurnout";
    } else if ("Block".equals(name)) {
        BundleName = "BeanNameBlock";
    } else {
        BundleName = name;
    }
    if (editor != null) {
        JPanel p = new JPanel();
        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
        if (add) {
            txt = java.text.MessageFormat.format(Bundle.getMessage("addItemToPanel"), Bundle.getMessage(BundleName));
        } else {
            txt = java.text.MessageFormat.format(Bundle.getMessage("editItemInPanel"), Bundle.getMessage(BundleName));
        }
        p.add(new JLabel(txt));
        if (table) {
            txt = java.text.MessageFormat.format(Bundle.getMessage("TableSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
        } else {
            if ("MultiSensor".equals(name)) {
                txt = java.text.MessageFormat.format(Bundle.getMessage("SelectMultiSensor", Bundle.getMessage("ButtonAddIcon")), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
            } else {
                txt = java.text.MessageFormat.format(Bundle.getMessage("IconSelect"), Bundle.getMessage(BundleName), (add ? Bundle.getMessage("ButtonAddIcon") : Bundle.getMessage("ButtonUpdateIcon")));
            }
        }
        p.add(new JLabel(txt));
        // add a bit of space on pane above icons
        p.add(new JLabel("    "));
        frame.getContentPane().add(p, BorderLayout.NORTH);
        frame.getContentPane().add(editor);
        JMenuBar menuBar = new JMenuBar();
        JMenu findIcon = new JMenu(Bundle.getMessage("findIconMenu"));
        menuBar.add(findIcon);
        JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
        editItem.addActionListener(new ActionListener() {

            Editor editor;

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

            ActionListener init(Editor ed) {
                editor = ed;
                return this;
            }
        }.init(this));
        findIcon.add(editItem);
        findIcon.addSeparator();
        JMenuItem searchItem = new JMenuItem(Bundle.getMessage("searchFSMenu"));
        searchItem.addActionListener(new ActionListener() {

            IconAdder ea;

            @Override
            public void actionPerformed(ActionEvent e) {
                jmri.jmrit.catalog.DirectorySearcher.instance().searchFS();
                ea.addDirectoryToCatalog();
            }

            ActionListener init(IconAdder ed) {
                ea = ed;
                return this;
            }
        }.init(editor));
        findIcon.add(searchItem);
        frame.setJMenuBar(menuBar);
        editor.setParent(frame);
        // when this window closes, check for saving
        if (add) {
            frame.addWindowListener(new java.awt.event.WindowAdapter() {

                @Override
                public void windowClosing(java.awt.event.WindowEvent e) {
                    setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
                    if (log.isDebugEnabled()) {
                        log.debug("windowClosing: HIDE {}", toString());
                    }
                }
            });
        }
    } else {
        //NOI18N
        log.error("No icon editor specified for {}", name);
    }
    if (add) {
        txt = java.text.MessageFormat.format(Bundle.getMessage("AddItem"), Bundle.getMessage(BundleName));
        _iconEditorFrame.put(name, frame);
    } else {
        txt = java.text.MessageFormat.format(Bundle.getMessage("EditItem"), Bundle.getMessage(BundleName));
    }
    frame.setTitle(txt + " (" + getTitle() + ")");
    frame.pack();
    return frame;
}
Also used : JPanel(javax.swing.JPanel) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuItem(javax.swing.JMenuItem) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 2 with ImageIndexEditor

use of jmri.jmrit.catalog.ImageIndexEditor in project JMRI by JMRI.

the class ControlPanelEditor method makeFileMenu.

private void makeFileMenu() {
    _fileMenu = new JMenu(Bundle.getMessage("MenuFile"));
    _menuBar.add(_fileMenu, 0);
    _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("renamePanelMenu", "..."));
    PositionableJComponent z = new PositionableJComponent(this);
    z.setScale(getPaintScale());
    editItem.addActionListener(CoordinateEdit.getNameEditAction(z));
    _fileMenu.add(editItem);
    editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        ControlPanelEditor panelEd;

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

        ActionListener init(ControlPanelEditor pe) {
            panelEd = pe;
            return this;
        }
    }.init(this));
    editItem = new JMenuItem(Bundle.getMessage("PEView"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            changeView("jmri.jmrit.display.panelEditor.PanelEditor");
            if (_itemPalette != null) {
                _itemPalette.dispose();
            }
        }
    });
    _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);
            }
        }
    });
    _fileMenu.addSeparator();
    editItem = new JMenuItem(Bundle.getMessage("CloseEditor"));
    _fileMenu.add(editItem);
    editItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            setAllEditable(false);
        }
    });
}
Also used : ActionEvent(java.awt.event.ActionEvent) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu)

Example 3 with ImageIndexEditor

use of jmri.jmrit.catalog.ImageIndexEditor 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 4 with ImageIndexEditor

use of jmri.jmrit.catalog.ImageIndexEditor in project JMRI by JMRI.

the class ItemPalette method makeMenus.

private void makeMenus(Editor editor) {
    if (!jmri.util.ThreadingUtil.isGUIThread())
        log.error("Not on GUI thread", new Exception("traceback"));
    JMenuBar menuBar = new JMenuBar();
    JMenu findIcon = new JMenu(Bundle.getMessage("findIconMenu"));
    menuBar.add(findIcon);
    JMenuItem editItem = new JMenuItem(Bundle.getMessage("editIndexMenu"));
    editItem.addActionListener(new ActionListener() {

        Editor editor;

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

        ActionListener init(Editor ed) {
            editor = ed;
            return this;
        }
    }.init(editor));
    findIcon.add(editItem);
    findIcon.addSeparator();
    JMenuItem openItem = new JMenuItem(Bundle.getMessage("openDirMenu"));
    openItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            DirectorySearcher.instance().openDirectory();
        }
    });
    findIcon.add(openItem);
    JMenuItem searchItem = new JMenuItem(Bundle.getMessage("searchFSMenu"));
    searchItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            jmri.jmrit.catalog.DirectorySearcher.instance().searchFS();
        }
    });
    findIcon.add(searchItem);
    setJMenuBar(menuBar);
    addHelpMenu("package.jmri.jmrit.display.ItemPalette", true);
}
Also used : ActionListener(java.awt.event.ActionListener) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) Editor(jmri.jmrit.display.Editor) ImageIndexEditor(jmri.jmrit.catalog.ImageIndexEditor) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Aggregations

ActionEvent (java.awt.event.ActionEvent)4 ActionListener (java.awt.event.ActionListener)4 JMenu (javax.swing.JMenu)4 JMenuItem (javax.swing.JMenuItem)4 ImageIndexEditor (jmri.jmrit.catalog.ImageIndexEditor)4 JMenuBar (javax.swing.JMenuBar)3 BoxLayout (javax.swing.BoxLayout)2 JLabel (javax.swing.JLabel)2 JPanel (javax.swing.JPanel)2 Color (java.awt.Color)1 Dimension (java.awt.Dimension)1 FlowLayout (java.awt.FlowLayout)1 Font (java.awt.Font)1 KeyAdapter (java.awt.event.KeyAdapter)1 KeyEvent (java.awt.event.KeyEvent)1 WindowAdapter (java.awt.event.WindowAdapter)1 HashMap (java.util.HashMap)1 JButton (javax.swing.JButton)1 ConfigureManager (jmri.ConfigureManager)1 Editor (jmri.jmrit.display.Editor)1