use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class CircuitBuilder method getSelection.
private Positionable getSelection(List<Positionable> tracks) {
if (tracks.size() > 0) {
if (tracks.size() == 1) {
return tracks.get(0);
}
if (tracks.size() > 1) {
String[] selects = new String[tracks.size()];
Iterator<Positionable> iter = tracks.iterator();
int i = 0;
while (iter.hasNext()) {
selects[i++] = iter.next().getNameString();
}
Object select = JOptionPane.showInputDialog(_editor, Bundle.getMessage("multipleSelections"), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
if (select != null) {
iter = tracks.iterator();
while (iter.hasNext()) {
Positionable pos = iter.next();
if (((String) select).equals(pos.getNameString())) {
return pos;
}
}
} else {
return tracks.get(tracks.size() - 1);
}
}
}
return null;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class CircuitBuilder method doMouseClicked.
protected boolean doMouseClicked(List<Positionable> selections, MouseEvent event) {
if (_editCircuitFrame != null || _editPathsFrame != null || _editPortalFrame != null || _editDirectionFrame != null) {
if (selections != null && selections.size() > 0) {
ArrayList<Positionable> tracks = new ArrayList<Positionable>();
Iterator<Positionable> iter = selections.iterator();
if (_editCircuitFrame != null) {
while (iter.hasNext()) {
Positionable pos = iter.next();
if (isTrack(pos)) {
tracks.add(pos);
}
}
} else if (_editPathsFrame != null) {
while (iter.hasNext()) {
Positionable pos = iter.next();
if (isTrack(pos) || pos instanceof PortalIcon) {
tracks.add(pos);
}
}
} else {
while (iter.hasNext()) {
Positionable pos = iter.next();
if (pos instanceof PortalIcon) {
tracks.add(pos);
}
}
}
if (tracks.size() > 0) {
Positionable selection = null;
if (tracks.size() == 1) {
selection = tracks.get(0);
} else {
selection = getSelection(tracks);
}
if (_editPathsFrame != null && event.isShiftDown() && !event.isControlDown()) {
selection.doMouseClicked(event);
}
handleSelection(selection, event);
}
}
return true;
}
return false;
}
use of jmri.jmrit.display.Positionable 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);
}
}
}
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method paintTargetPanel.
@Override
protected void paintTargetPanel(Graphics g) {
// needed to create PositionablePolygon
_shapeDrawer.paint(g);
if (_secondSelectionGroup != null) {
Graphics2D g2d = (Graphics2D) g;
g2d.setColor(new Color(150, 150, 255));
g2d.setStroke(new java.awt.BasicStroke(2.0f));
for (Positionable p : _secondSelectionGroup) {
if (!(p instanceof jmri.jmrit.display.controlPanelEditor.shape.PositionableShape)) {
g.drawRect(p.getX(), p.getY(), p.maxWidth(), p.maxHeight());
}
}
}
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method selectLevel.
private void selectLevel(int i) {
_selectionGroup = new ArrayList<Positionable>();
Iterator<Positionable> it = _contents.iterator();
while (it.hasNext()) {
Positionable pos = it.next();
if (pos.getDisplayLevel() == i) {
_selectionGroup.add(pos);
}
}
_targetPanel.repaint();
}
Aggregations