Search in sources :

Example 1 with PositionableJComponent

use of jmri.jmrit.display.PositionableJComponent 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 2 with PositionableJComponent

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

the class SwitchboardEditor 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);
    _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);
            // hide Editor pane
            setVisible(false);
        }
    });
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) JMenuItem(javax.swing.JMenuItem) JMenu(javax.swing.JMenu) PositionableJComponent(jmri.jmrit.display.PositionableJComponent)

Example 3 with PositionableJComponent

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

the class ControlPanelEditor method pasteFromClipboard.

private void pasteFromClipboard() {
    Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
    DataFlavor[] flavors = clipboard.getAvailableDataFlavors();
    for (DataFlavor flavor : flavors) {
        if (_positionableListDataFlavor.equals(flavor)) {
            try {
                @SuppressWarnings("unchecked") List<Positionable> clipGroup = (List<Positionable>) clipboard.getData(_positionableListDataFlavor);
                if (clipGroup != null && clipGroup.size() > 0) {
                    Positionable pos = clipGroup.get(0);
                    int minX = pos.getLocation().x;
                    int minY = pos.getLocation().y;
                    // locate group at mouse point
                    for (int i = 1; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        minX = Math.min(minX, pos.getLocation().x);
                        minY = Math.min(minY, pos.getLocation().y);
                    }
                    if (_pastePending) {
                        abortPasteItems();
                    }
                    _selectionGroup = new ArrayList<Positionable>();
                    for (int i = 0; i < clipGroup.size(); i++) {
                        pos = clipGroup.get(i);
                        // make positionable belong to this editor
                        pos.setEditor(this);
                        pos.setLocation(pos.getLocation().x + _anchorX - minX, pos.getLocation().y + _anchorY - minY);
                        // now set display level in the pane.
                        pos.setDisplayLevel(pos.getDisplayLevel());
                        putItem(pos);
                        pos.updateSize();
                        pos.setVisible(true);
                        _selectionGroup.add(pos);
                        if (pos instanceof PositionableIcon) {
                            jmri.NamedBean bean = pos.getNamedBean();
                            if (bean != null) {
                                ((PositionableIcon) pos).displayState(bean.getState());
                            }
                        } else if (pos instanceof MemoryIcon) {
                            ((MemoryIcon) pos).displayState();
                        } else if (pos instanceof PositionableJComponent) {
                            ((PositionableJComponent) pos).displayState();
                        }
                        log.debug("Paste Added at ({}, {})", pos.getLocation().x, pos.getLocation().y);
                    }
                }
                return;
            } catch (IOException ioe) {
                log.warn("Editor Paste caught IOException", ioe);
            } catch (UnsupportedFlavorException ufe) {
                log.warn("Editor Paste caught UnsupportedFlavorException", ufe);
            }
        }
    }
}
Also used : MemoryIcon(jmri.jmrit.display.MemoryIcon) PositionableIcon(jmri.jmrit.display.PositionableIcon) IOException(java.io.IOException) UnsupportedFlavorException(java.awt.datatransfer.UnsupportedFlavorException) Point(java.awt.Point) DataFlavor(java.awt.datatransfer.DataFlavor) PositionableJComponent(jmri.jmrit.display.PositionableJComponent) List(java.util.List) ArrayList(java.util.ArrayList) Clipboard(java.awt.datatransfer.Clipboard) Positionable(jmri.jmrit.display.Positionable)

Example 4 with PositionableJComponent

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

the class ControlPanelEditor method makeZoomMenu.

protected void makeZoomMenu() {
    _zoomMenu = new JMenu(Bundle.getMessage("MenuZoom"));
    _menuBar.add(_zoomMenu, 0);
    JMenuItem addItem = new JMenuItem(Bundle.getMessage("NoZoom"));
    _zoomMenu.add(addItem);
    addItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent event) {
            zoomRestore();
        }
    });
    addItem = new JMenuItem(Bundle.getMessage("Zoom", "..."));
    _zoomMenu.add(addItem);
    PositionableJComponent z = new PositionableJComponent(this);
    z.setScale(getPaintScale());
    addItem.addActionListener(CoordinateEdit.getZoomEditAction(z));
    addItem = new JMenuItem(Bundle.getMessage("ZoomFit"));
    _zoomMenu.add(addItem);
    addItem.addActionListener(new ActionListener() {

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

Aggregations

PositionableJComponent (jmri.jmrit.display.PositionableJComponent)4 ActionEvent (java.awt.event.ActionEvent)3 ActionListener (java.awt.event.ActionListener)3 JMenu (javax.swing.JMenu)3 JMenuItem (javax.swing.JMenuItem)3 Point (java.awt.Point)1 Clipboard (java.awt.datatransfer.Clipboard)1 DataFlavor (java.awt.datatransfer.DataFlavor)1 UnsupportedFlavorException (java.awt.datatransfer.UnsupportedFlavorException)1 IOException (java.io.IOException)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 ImageIndexEditor (jmri.jmrit.catalog.ImageIndexEditor)1 MemoryIcon (jmri.jmrit.display.MemoryIcon)1 Positionable (jmri.jmrit.display.Positionable)1 PositionableIcon (jmri.jmrit.display.PositionableIcon)1