Search in sources :

Example 46 with Positionable

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

the class CircuitBuilder method convertIcons.

protected void convertIcons(ArrayList<Positionable> iconList) {
    if (iconList == null || iconList.size() == 0) {
        return;
    }
    // use global member for finishConvert to remove and add converted icons,
    _circuitIcons = iconList;
    // since iconList will be modified, use a copy to find unconverted icons
    ArrayList<Positionable> list = new ArrayList<Positionable>();
    for (int i = 0; i < iconList.size(); i++) {
        list.add(iconList.get(i));
    }
    if (list.size() > 0) {
        TargetPane targetPane = (TargetPane) _editor.getTargetPanel();
        targetPane.setHighlightColor(_highlightColor);
        for (int i = 0; i < list.size(); i++) {
            Positionable pos = list.get(i);
            if (!(pos instanceof IndicatorTrack) && !(pos instanceof PortalIcon)) {
                if (log.isDebugEnabled()) {
                    log.debug("convertIcons: #" + i + " pos= " + pos.getClass().getName());
                }
                convertIcon(pos);
            }
        }
        targetPane.setHighlightColor(_editGroupColor);
        _editor.highlight(null);
    }
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) ArrayList(java.util.ArrayList) TargetPane(jmri.jmrit.display.Editor.TargetPane) Positionable(jmri.jmrit.display.Positionable)

Example 47 with Positionable

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

the class CircuitBuilder method okToAdd.

/**
     * Can this track icon be added to the circuit? N.B. Be sure Positionable
     * pos passes isTrack() call
     */
private boolean okToAdd(Positionable pos, OBlock editBlock) {
    if (pos instanceof IndicatorTrack) {
        OBlock block = ((IndicatorTrack) pos).getOccBlock();
        if (block != null) {
            if (!block.equals(editBlock)) {
                int result = JOptionPane.showConfirmDialog(_editor, java.text.MessageFormat.format(Bundle.getMessage("iconBlockConflict"), block.getDisplayName(), editBlock.getDisplayName()), Bundle.getMessage("whichCircuit"), JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
                if (result == JOptionPane.YES_OPTION) {
                    // move icon from block to editBlock 
                    java.util.List<Positionable> ic = _circuitMap.get(block);
                    ic.remove(pos);
                    ((IndicatorTrack) pos).setOccBlockHandle(InstanceManager.getDefault(NamedBeanHandleManager.class).getNamedBeanHandle(editBlock.getSystemName(), editBlock));
                    return true;
                }
                return false;
            }
        }
    }
    return true;
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

Example 48 with Positionable

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

the class CircuitBuilder method setPortalsPositionable.

/**
     * ************************ end setup frames *****************************
     */
private void setPortalsPositionable(OBlock block, boolean set) {
    List<Positionable> circuitIcons = _circuitMap.get(block);
    Iterator<Positionable> iter = circuitIcons.iterator();
    while (iter.hasNext()) {
        Positionable p = iter.next();
        if (p instanceof PortalIcon) {
            p.setPositionable(set);
        }
    }
}
Also used : Positionable(jmri.jmrit.display.Positionable)

Example 49 with Positionable

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

the class ControlPanelEditor method zoomRestore.

private void zoomRestore() {
    List<Positionable> contents = getContents();
    for (Positionable p : contents) {
        p.setLocation(p.getX() + _fitX, p.getY() + _fitY);
    }
    setPaintScale(1.0);
}
Also used : Positionable(jmri.jmrit.display.Positionable)

Example 50 with Positionable

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

the class CircuitBuilder method checkPortalIcon.

// end checkCircuits
private boolean checkPortalIcon(Portal portal, PortalIcon icon) {
    OBlock a = portal.getToBlock();
    OBlock b = portal.getFromBlock();
    java.util.List<Positionable> aList = _circuitMap.get(a);
    java.util.List<Positionable> bList = _circuitMap.get(b);
    if (icon == null || aList == null || bList == null) {
        return false;
    }
    boolean ok = false;
    String status = icon.getStatus();
    icon.setStatus(PortalIcon.VISIBLE);
    Rectangle homeRect = new Rectangle();
    Iterator<Positionable> iter = aList.iterator();
    while (iter.hasNext()) {
        Positionable pos = iter.next();
        if (pos instanceof PortalIcon) {
            continue;
        }
        homeRect = pos.getBounds(homeRect);
        if (iconIntersectsRect(icon, homeRect)) {
            ok = true;
            break;
        }
    }
    if (!ok) {
        icon.setStatus(status);
        return false;
    }
    ok = false;
    iter = bList.iterator();
    while (iter.hasNext()) {
        Positionable pos = iter.next();
        if (pos instanceof PortalIcon) {
            continue;
        }
        homeRect = pos.getBounds(homeRect);
        if (iconIntersectsRect(icon, homeRect)) {
            ok = true;
            break;
        }
    }
    icon.setStatus(status);
    return ok;
}
Also used : Rectangle(java.awt.Rectangle) Positionable(jmri.jmrit.display.Positionable) OBlock(jmri.jmrit.logix.OBlock)

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