Search in sources :

Example 41 with Positionable

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

the class PanelEditor method showMultiSelectPopUp.

protected void showMultiSelectPopUp(final MouseEvent event, Positionable p) {
    JPopupMenu popup = new JPopupMenu();
    // changed "edit" to "copy"
    JMenuItem copy = new JMenuItem(Bundle.getMessage("ButtonCopy"));
    if (p.isPositionable()) {
        setShowAlignmentMenu(p, popup);
    }
    copy.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            _multiItemCopyGroup = new ArrayList<Positionable>();
            // must make a copy or pasteItem() will hang
            if (_selectionGroup != null) {
                for (Positionable comp : _selectionGroup) {
                    _multiItemCopyGroup.add(comp);
                }
            }
        }
    });
    // adding Lock Position for all
    setMultiItemsPositionableMenu(popup);
    // selected items
    setRemoveMenu(p, popup);
    //showAddItemPopUp(event, popup); // no need to Add when group selected
    popup.add(copy);
    popup.show(event.getComponent(), event.getX(), event.getY());
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem) JPopupMenu(javax.swing.JPopupMenu)

Example 42 with Positionable

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

the class JmriJFrameServlet method sendClick.

void sendClick(String name, Component c, int xg, int yg, Container FrameContentPane) {
    // global positions
    int x = xg - c.getLocation().x;
    int y = yg - c.getLocation().y;
    // log.debug("component is {}", c);
    log.debug("Local click at {},{}", x, y);
    if (c.getClass().equals(JButton.class)) {
        ((AbstractButton) c).doClick();
    } else if (c.getClass().equals(JCheckBox.class)) {
        ((AbstractButton) c).doClick();
    } else if (c.getClass().equals(JRadioButton.class)) {
        ((AbstractButton) c).doClick();
    } else if (MouseListener.class.isAssignableFrom(c.getClass())) {
        log.debug("Invoke directly on MouseListener, at {},{}", x, y);
        sendClickSequence((MouseListener) c, c, x, y);
    } else if (c instanceof jmri.jmrit.display.MultiSensorIcon) {
        log.debug("Invoke Clicked on MultiSensorIcon");
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
        0, // modifiers
        0, // this component expects global positions for some reason
        xg, // this component expects global positions for some reason
        yg, // one click
        1, // not a popup
        false);
        ((Positionable) c).doMouseClicked(e);
    } else if (Positionable.class.isAssignableFrom(c.getClass())) {
        log.debug("Invoke Pressed, Released and Clicked on Positionable");
        MouseEvent e = new MouseEvent(c, MouseEvent.MOUSE_PRESSED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMousePressed(e);
        e = new MouseEvent(c, MouseEvent.MOUSE_RELEASED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMouseReleased(e);
        e = new MouseEvent(c, MouseEvent.MOUSE_CLICKED, // time
        0, // modifiers
        0, // x, y not in this component?
        x, // x, y not in this component?
        y, // one click
        1, // not a popup
        false);
        ((jmri.jmrit.display.Positionable) c).doMouseClicked(e);
    } else {
        MouseListener[] la = c.getMouseListeners();
        log.debug("Invoke {} contained mouse listeners", la.length);
        log.debug("component is {}", c);
        // y -= (int)(pc.getY() - pf.getY());
        for (MouseListener ml : la) {
            log.debug("Send click sequence at {},{}", x, y);
            sendClickSequence(ml, c, x, y);
        }
    }
}
Also used : JCheckBox(javax.swing.JCheckBox) AbstractButton(javax.swing.AbstractButton) MouseListener(java.awt.event.MouseListener) MouseEvent(java.awt.event.MouseEvent) Positionable(jmri.jmrit.display.Positionable)

Example 43 with Positionable

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

the class CircuitBuilder method checkCircuits.

/**
     * ************** end closing frames *******************
     */
/**
     * Find the blocks with no icons and the blocks with icons that need
     * conversion Setup for main Frame - used in both initialization and close
     * of an editing frame Build Lists that are used to create menu items
     */
private void checkCircuits() {
    _portalIconMap.clear();
    _darkTrack.clear();
    _unconvertedTrack.clear();
    PortalManager portalMgr = InstanceManager.getDefault(jmri.jmrit.logix.PortalManager.class);
    Iterator<Positionable> it = _editor.getContents().iterator();
    while (it.hasNext()) {
        Positionable pos = it.next();
        //            if (log.isDebugEnabled()) log.debug("class: "+pos.getClass().getName());
        if (pos instanceof IndicatorTrack) {
            OBlock block = ((IndicatorTrack) pos).getOccBlock();
            ((IndicatorTrack) pos).removePath(EditCircuitPaths.TEST_PATH);
            if (block != null) {
                addIcon(block, pos);
            } else {
                _darkTrack.add(pos);
            }
        } else if (pos instanceof PortalIcon) {
            PortalIcon pIcon = (PortalIcon) pos;
            String name = pIcon.getName();
            Portal portal = portalMgr.getByUserName(name);
            if (portal == null) {
                log.error("No Portal for PortalIcon called \"" + name + "\". Discarding icon.");
                pIcon.remove();
            } else {
                PortalIcon pi = _portalIconMap.get(name);
                if (pi != null) {
                    log.error("Removing duplicate PortalIcon for Portal \"" + name + "\".");
                    pi.remove();
                }
                _portalIconMap.put(name, pIcon);
            }
        }
    }
    Iterator<Entry<OBlock, ArrayList<Positionable>>> iters = _circuitMap.entrySet().iterator();
    while (iters.hasNext()) {
        Entry<OBlock, ArrayList<Positionable>> entry = iters.next();
        Iterator<Positionable> iter = entry.getValue().iterator();
        while (iter.hasNext()) {
            Positionable pos = iter.next();
            if (isUnconvertedTrack(pos)) {
                if (!_unconvertedTrack.contains(pos)) {
                    _unconvertedTrack.add(pos);
                }
            }
        }
    }
    _bareBlock.clear();
    _convertBlock.clear();
    _badPortalIcon.clear();
    OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
    String[] sysNames = manager.getSystemNameArray();
    hasOBlocks = (sysNames.length > 0);
    for (int i = 0; i < sysNames.length; i++) {
        OBlock block = manager.getBySystemName(sysNames[i]);
        java.util.List<Portal> list = block.getPortals();
        if (list != null) {
            Iterator<Portal> iter = list.iterator();
            while (iter.hasNext()) {
                Portal portal = iter.next();
                // update circuitMap
                PortalIcon pi = _portalIconMap.get(portal.getName());
                if (pi != null) {
                    addIcon(block, pi);
                }
            }
        }
        java.util.List<Positionable> icons = _circuitMap.get(block);
        if (log.isDebugEnabled()) {
            log.debug("checkCircuits: block " + block.getDisplayName() + " has " + icons.size() + " icons.");
        }
        if (icons == null || icons.size() == 0) {
            _bareBlock.add(block);
        } else {
            _bareBlock.remove(block);
            for (int k = 0; k < icons.size(); k++) {
                Positionable pos = icons.get(k);
                if (!(pos instanceof IndicatorTrack) && !(pos instanceof PortalIcon)) {
                    if (!_convertBlock.contains(block)) {
                        _convertBlock.add(block);
                        break;
                    }
                }
            }
        }
    }
    List<NamedBean> list = portalMgr.getNamedBeanList();
    Iterator<NamedBean> iter = list.iterator();
    while (iter.hasNext()) {
        Portal portal = (Portal) iter.next();
        String name = portal.getName();
        PortalIcon pi = _portalIconMap.get(name);
        if (pi != null) {
            if (!checkPortalIcon(portal, pi)) {
                _badPortalIcon.put(name, portal);
            }
        } else {
            // no icon for this Portal
            _badPortalIcon.put(name, portal);
        }
    }
    makeToDoMenu();
}
Also used : NamedBean(jmri.NamedBean) PortalManager(jmri.jmrit.logix.PortalManager) ArrayList(java.util.ArrayList) OBlockManager(jmri.jmrit.logix.OBlockManager) Entry(java.util.Map.Entry) IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Portal(jmri.jmrit.logix.Portal) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 44 with Positionable

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

the class ControlPanelEditor method zoomToFit.

private void zoomToFit() {
    double minX = 1000.0;
    double maxX = 0.0;
    double minY = 1000.0;
    double maxY = 0.0;
    List<Positionable> contents = getContents();
    for (Positionable p : contents) {
        minX = Math.min(p.getX(), minX);
        minY = Math.min(p.getY(), minY);
        maxX = Math.max(p.getX() + p.getWidth(), maxX);
        maxY = Math.max(p.getY() + p.getHeight(), maxY);
    }
    _fitX = (int) Math.floor(minX);
    _fitY = (int) Math.floor(minY);
    JFrame frame = getTargetFrame();
    Container contentPane = getTargetFrame().getContentPane();
    Dimension dim = contentPane.getSize();
    Dimension d = getTargetPanel().getSize();
    getTargetPanel().setSize((int) Math.ceil(maxX - minX), (int) Math.ceil(maxY - minY));
    JScrollPane scrollPane = getPanelScrollPane();
    scrollPane.getHorizontalScrollBar().setValue(0);
    scrollPane.getVerticalScrollBar().setValue(0);
    JViewport viewPort = scrollPane.getViewport();
    Dimension dv = viewPort.getExtentSize();
    int dX = frame.getWidth() - dv.width;
    int dY = frame.getHeight() - dv.height;
    log.debug("zoomToFit: layoutWidth= {}, layoutHeight= {}\n\tframeWidth= {}, frameHeight= {}, viewWidth= {}, viewHeight= {}\n\tconWidth= {}, conHeight= {}, panelWidth= {}, panelHeight= {}", (maxX - minX), (maxY - minY), frame.getWidth(), frame.getHeight(), dv.width, dv.height, dim.width, dim.height, d.width, d.height);
    double ratioX = dv.width / (maxX - minX);
    double ratioY = dv.height / (maxY - minY);
    double ratio = Math.min(ratioX, ratioY);
    /*
         if (ratioX<ratioY) {
         if (ratioX>1.0) {
         ratio = ratioX;
         } else {
         ratio = ratioY;
         }
         } else {
         if (ratioY<1.0) {
         ratio = ratioX;
         } else {
         ratio = ratioY;
         }
         } */
    _fitX = (int) Math.floor(minX);
    _fitY = (int) Math.floor(minY);
    for (Positionable p : contents) {
        p.setLocation(p.getX() - _fitX, p.getY() - _fitY);
    }
    setScroll(SCROLL_BOTH);
    setPaintScale(ratio);
    setScroll(SCROLL_NONE);
    scrollNone.setSelected(true);
    //getTargetPanel().setSize((int)Math.ceil(maxX), (int)Math.ceil(maxY));
    frame.setSize((int) Math.ceil((maxX - minX) * ratio) + dX, (int) Math.ceil((maxY - minY) * ratio) + dY);
    scrollPane.getHorizontalScrollBar().setValue(0);
    scrollPane.getVerticalScrollBar().setValue(0);
    log.debug("zoomToFit: ratio= {}, w= {}, h= {}, frameWidth= {}, frameHeight= {}", ratio, (maxX - minX), (maxY - minY), frame.getWidth(), frame.getHeight());
}
Also used : JScrollPane(javax.swing.JScrollPane) Container(java.awt.Container) JFrame(javax.swing.JFrame) JViewport(javax.swing.JViewport) Positionable(jmri.jmrit.display.Positionable) Dimension(java.awt.Dimension) Point(java.awt.Point)

Example 45 with Positionable

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

the class CircuitBuilder method makeMenu.

/**
     * Makes menu for ControlPanelEditor Called by ControlPanelEditor at init
     * before contents have been loaded
     */
protected JMenu makeMenu() {
    if (_circuitMenu == null) {
        _circuitMenu = new JMenu(Bundle.getMessage("CircuitBuilder"));
        _circuitMap = new HashMap<OBlock, ArrayList<Positionable>>();
        OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
        String[] sysNames = manager.getSystemNameArray();
        for (int i = 0; i < sysNames.length; i++) {
            OBlock block = manager.getBySystemName(sysNames[i]);
            _circuitMap.put(block, new ArrayList<Positionable>());
        }
    }
    makeCircuitMenu();
    return _circuitMenu;
}
Also used : ArrayList(java.util.ArrayList) OBlockManager(jmri.jmrit.logix.OBlockManager) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock) JMenu(javax.swing.JMenu)

Aggregations

Positionable (jmri.jmrit.display.Positionable)60 ArrayList (java.util.ArrayList)18 Point (java.awt.Point)15 IndicatorTrack (jmri.jmrit.display.IndicatorTrack)12 Portal (jmri.jmrit.logix.Portal)7 Element (org.jdom2.Element)7 JFrame (javax.swing.JFrame)6 OBlock (jmri.jmrit.logix.OBlock)6 ActionEvent (java.awt.event.ActionEvent)5 ActionListener (java.awt.event.ActionListener)5 IOException (java.io.IOException)4 JMenuItem (javax.swing.JMenuItem)4 Color (java.awt.Color)3 Dimension (java.awt.Dimension)3 Rectangle (java.awt.Rectangle)3 PanelEditor (jmri.jmrit.display.panelEditor.PanelEditor)3 JsonGenerationException (com.fasterxml.jackson.core.JsonGenerationException)2 JsonMappingException (com.fasterxml.jackson.databind.JsonMappingException)2 Graphics2D (java.awt.Graphics2D)2 Clipboard (java.awt.datatransfer.Clipboard)2