Search in sources :

Example 6 with Positionable

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

the class EditCircuitFrame method updateIconList.

protected void updateIconList(java.util.List<Positionable> icons) {
    //if (log.isDebugEnabled()) log.debug( 
    int segments = 0;
    int turnouts = 0;
    if (icons != null) {
        if (log.isDebugEnabled()) {
            log.debug("updateIconList: icons.size()= {}", icons.size());
        }
        for (int i = 0; i < icons.size(); i++) {
            Positionable pos = icons.get(i);
            if (pos instanceof IndicatorTurnoutIcon) {
                turnouts++;
            } else if (pos instanceof IndicatorTrackIcon) {
                segments++;
            } else if (pos instanceof TurnoutIcon) {
                turnouts++;
            } else {
                segments++;
            }
        }
    }
    _numTrackSeg.setText(String.valueOf(segments));
    _numTurnouts.setText(String.valueOf(turnouts));
}
Also used : IndicatorTrackIcon(jmri.jmrit.display.IndicatorTrackIcon) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) Positionable(jmri.jmrit.display.Positionable) IndicatorTurnoutIcon(jmri.jmrit.display.IndicatorTurnoutIcon) TurnoutIcon(jmri.jmrit.display.TurnoutIcon) Point(java.awt.Point)

Example 7 with Positionable

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

the class ControlPanelEditor method mouseClicked.

@Override
public void mouseClicked(MouseEvent event) {
    if (jmri.util.swing.SwingSettings.getNonStandardMouseEvent()) {
        long time = System.currentTimeMillis();
        if (time - _clickTime < 20) {
            return;
        }
        _clickTime = time;
    }
    // ends tooltip if displayed
    setToolTip(null);
    log.debug("mouseClicked at ({},{})", event.getX(), event.getY());
    Positionable selection = getCurrentSelection(event);
    if (_shapeDrawer.doMouseClicked(event)) {
        return;
    }
    if (event.isPopupTrigger() || event.isMetaDown() || event.isAltDown()) {
        if (selection != null) {
            _highlightcomponent = null;
            showPopUp(selection, event);
        }
    } else if (selection != null) {
        if (!_circuitBuilder.doMouseClicked(getSelectedItems(event), event)) {
            selection.doMouseClicked(event);
        }
        if (selection instanceof IndicatorTrack) {
            WarrantTableAction.mouseClickedOnBlock(((IndicatorTrack) selection).getOccBlock());
        }
    }
    if (!isEditable()) {
        deselectSelectionGroup();
        _currentSelection = null;
        _highlightcomponent = null;
    }
    // needed for ToolTip
    _targetPanel.repaint();
}
Also used : IndicatorTrack(jmri.jmrit.display.IndicatorTrack) Positionable(jmri.jmrit.display.Positionable)

Example 8 with Positionable

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

the class ControlPanelEditor method copyToClipboard.

/*
     * The editor instance is dragged.  When dropped this editor will reference
     * the list of positionables (_clipGroup) for pasting
     */
private void copyToClipboard() {
    if (_selectionGroup != null) {
        ArrayList<Positionable> dragGroup = new ArrayList<Positionable>();
        for (Positionable comp : _selectionGroup) {
            Positionable pos = comp.deepClone();
            dragGroup.add(pos);
            // cloned item gets added to _targetPane during cloning
            removeFromTarget(pos);
        }
        log.debug("copyToClipboard: cloned _selectionGroup, size= {}", _selectionGroup.size());
        _clipGroup = dragGroup;
        Clipboard clipboard = Toolkit.getDefaultToolkit().getSystemClipboard();
        clipboard.setContents(new PositionableListDnD(_clipGroup), this);
        log.debug("copyToClipboard: setContents _selectionGroup, size= {}", _selectionGroup.size());
    } else {
        _clipGroup = null;
    }
}
Also used : ArrayList(java.util.ArrayList) Positionable(jmri.jmrit.display.Positionable) Clipboard(java.awt.datatransfer.Clipboard)

Example 9 with Positionable

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

the class SwitchboardEditor method keyPressed.

/**
     * KeyListener of Editor.
     *
     * @param e the key event heard
     */
@Override
public void keyPressed(KeyEvent e) {
    int x = 0;
    int y = 0;
    switch(e.getKeyCode()) {
        case KeyEvent.VK_UP:
        case KeyEvent.VK_KP_UP:
        case KeyEvent.VK_NUMPAD8:
            y = -1;
            break;
        case KeyEvent.VK_DOWN:
        case KeyEvent.VK_KP_DOWN:
        case KeyEvent.VK_NUMPAD2:
            y = 1;
            break;
        case KeyEvent.VK_LEFT:
        case KeyEvent.VK_KP_LEFT:
        case KeyEvent.VK_NUMPAD4:
            x = -1;
            break;
        case KeyEvent.VK_RIGHT:
        case KeyEvent.VK_KP_RIGHT:
        case KeyEvent.VK_NUMPAD6:
            x = 1;
            break;
        case KeyEvent.VK_D:
        case KeyEvent.VK_DELETE:
        case KeyEvent.VK_MINUS:
            //_shapeDrawer.delete();
            break;
        case KeyEvent.VK_A:
        case KeyEvent.VK_INSERT:
        case KeyEvent.VK_PLUS:
            //_shapeDrawer.add(e.isShiftDown());
            break;
        default:
            return;
    }
    if (e.isShiftDown()) {
        x *= 5;
        y *= 5;
    }
    if (_selectionGroup != null) {
        for (Positionable comp : _selectionGroup) {
            moveItem(comp, x, y);
        }
    }
    repaint();
}
Also used : Positionable(jmri.jmrit.display.Positionable)

Example 10 with Positionable

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

the class ControlPanelEditor method setCopyMenu.

/**
     * Add an action to copy the Positionable item and the group to which is may
     * belong.
     */
public void setCopyMenu(Positionable p, JPopupMenu popup) {
    JMenuItem edit = new JMenuItem(Bundle.getMessage("MenuItemDuplicate"));
    edit.addActionListener(new ActionListener() {

        Positionable comp;

        @Override
        public void actionPerformed(ActionEvent e) {
            copyItem(comp);
        }

        ActionListener init(Positionable pos) {
            comp = pos;
            return this;
        }
    }.init(p));
    popup.add(edit);
}
Also used : ActionListener(java.awt.event.ActionListener) ActionEvent(java.awt.event.ActionEvent) Positionable(jmri.jmrit.display.Positionable) JMenuItem(javax.swing.JMenuItem)

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