use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method getClipGroup.
public ArrayList<Positionable> getClipGroup() {
if (log.isDebugEnabled()) {
// avoid string concatination if not debug
log.debug("getClipGroup: _clipGroup{}", _clipGroup == null ? "=null" : ", size= " + _clipGroup.size());
}
if (_clipGroup == null) {
return null;
}
ArrayList<Positionable> clipGrp = new ArrayList<Positionable>();
for (Positionable _comp : _clipGroup) {
Positionable pos = _comp.deepClone();
clipGrp.add(pos);
// cloned item gets added to _targetPane during cloning
removeFromTarget(pos);
}
return clipGrp;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method mouseReleased.
@Override
public void mouseReleased(MouseEvent event) {
// ends tooltip if displayed
setToolTip(null);
if (log.isDebugEnabled()) {
// avoid string concatination if not debug
log.debug("mouseReleased at ({},{}) dragging={}, pastePending={}, selectRect is{} null", event.getX(), event.getY(), _dragging, _pastePending, (_selectRect == null ? "" : " not"));
}
Positionable selection = getCurrentSelection(event);
if ((event.isPopupTrigger() || event.isMetaDown() || event.isAltDown())) /*&& !_dragging*/
{
if (selection != null) {
_highlightcomponent = null;
showPopUp(selection, event);
} else if (_selectRect != null) {
makeSelectionGroup(event);
}
} else {
if (selection != null) {
selection.doMouseReleased(event);
}
// when dragging, don't change selection group
if (_pastePending && _dragging) {
pasteItems();
}
if (isEditable()) {
if (_shapeDrawer.doMouseReleased(selection, event)) {
_selectRect = null;
}
if (!_circuitBuilder.doMouseReleased(selection, _dragging)) {
if (selection != null) {
if (!_dragging) {
modifySelectionGroup(selection, event);
}
}
if (_selectRect != null) {
makeSelectionGroup(event);
}
if (_currentSelection != null && (_selectionGroup == null || _selectionGroup.isEmpty())) {
if (_selectionGroup == null) {
_selectionGroup = new ArrayList<Positionable>();
}
_selectionGroup.add(_currentSelection);
}
}
_currentSelection = selection;
} else {
deselectSelectionGroup();
_currentSelection = null;
_highlightcomponent = null;
}
}
_selectRect = null;
// if not sending MouseClicked, do it here
if (jmri.util.swing.SwingSettings.getNonStandardMouseEvent()) {
mouseClicked(event);
}
_lastX = event.getX();
_lastY = event.getY();
_dragging = false;
_currentSelection = null;
// needed for ToolTip
_targetPanel.repaint();
// if (_debug) log.debug("mouseReleased at ("+event.getX()+","+event.getY()+
// " _selectionGroup= "+(_selectionGroup==null?"null":_selectionGroup.size()));
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method pasteItems.
void pasteItems() {
if (_selectionGroup != null) {
for (Positionable pos : _selectionGroup) {
if (pos instanceof PositionableIcon) {
jmri.NamedBean bean = pos.getNamedBean();
if (bean != null) {
((PositionableIcon) pos).displayState(bean.getState());
}
}
putItem(pos);
log.debug("Add {}", pos.getNameString());
}
if (_selectionGroup.get(0) instanceof LocoIcon) {
LocoIcon p = (LocoIcon) _selectionGroup.get(0);
CoordinateEdit f = new CoordinateEdit();
f.init("Train Name", p, false);
f.initText();
f.setVisible(true);
f.setLocationRelativeTo(p);
}
}
_pastePending = false;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class ControlPanelEditor method abortPasteItems.
/**
* Showing the popup of a member of _selectionGroup causes an image to be
* placed in to the _targetPanel. If the objects are not put into _contents
* (putItem(p)) the image will persist. Thus set these transitory object
* invisible.
*/
void abortPasteItems() {
if (log.isDebugEnabled()) {
// avoid string concatination if not debug
log.debug("abortPasteItems: _selectionGroup{}", _selectionGroup == null ? "=null" : (".size=" + _selectionGroup.size()));
}
if (_selectionGroup != null) {
for (Positionable comp : _selectionGroup) {
comp.setVisible(false);
comp.remove();
}
}
deselectSelectionGroup();
_pastePending = false;
}
use of jmri.jmrit.display.Positionable in project JMRI by JMRI.
the class LayoutEditorXml method store.
/**
* Default implementation for storing the contents of a LayoutEditor
*
* @param o Object to store, of type LayoutEditor
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LayoutEditor p = (LayoutEditor) o;
Element panel = new Element("LayoutEditor");
panel.setAttribute("class", getClass().getName());
panel.setAttribute("name", p.getLayoutName());
panel.setAttribute("x", "" + p.getUpperLeftX());
panel.setAttribute("y", "" + p.getUpperLeftY());
// From this version onwards separate sizes for window and panel are stored the
// following two statements allow files written here to be read in 2.2 and before
panel.setAttribute("height", "" + p.getLayoutHeight());
panel.setAttribute("width", "" + p.getLayoutWidth());
// From this version onwards separate sizes for window and panel are stored
panel.setAttribute("windowheight", "" + p.getWindowHeight());
panel.setAttribute("windowwidth", "" + p.getWindowWidth());
panel.setAttribute("panelheight", "" + p.getLayoutHeight());
panel.setAttribute("panelwidth", "" + p.getLayoutWidth());
// deprecated
panel.setAttribute("sliders", "" + (p.getScroll() ? "yes" : "no"));
panel.setAttribute("scrollable", "" + p.getScrollable());
panel.setAttribute("editable", "" + (p.isEditable() ? "yes" : "no"));
panel.setAttribute("positionable", "" + (p.allPositionable() ? "yes" : "no"));
panel.setAttribute("controlling", "" + (p.allControlling() ? "yes" : "no"));
panel.setAttribute("animating", "" + (p.isAnimating() ? "yes" : "no"));
panel.setAttribute("showhelpbar", "" + (p.getShowHelpBar() ? "yes" : "no"));
panel.setAttribute("drawgrid", "" + (p.getDrawGrid() ? "yes" : "no"));
panel.setAttribute("snaponadd", "" + (p.getSnapOnAdd() ? "yes" : "no"));
panel.setAttribute("snaponmove", "" + (p.getSnapOnMove() ? "yes" : "no"));
panel.setAttribute("antialiasing", "" + (p.getAntialiasingOn() ? "yes" : "no"));
panel.setAttribute("turnoutcircles", "" + (p.getTurnoutCircles() ? "yes" : "no"));
panel.setAttribute("tooltipsnotedit", "" + (p.getTooltipsNotEdit() ? "yes" : "no"));
panel.setAttribute("tooltipsinedit", "" + (p.getTooltipsInEdit() ? "yes" : "no"));
panel.setAttribute("mainlinetrackwidth", "" + p.getMainlineTrackWidth());
panel.setAttribute("xscale", Float.toString((float) p.getXScale()));
panel.setAttribute("yscale", Float.toString((float) p.getYScale()));
panel.setAttribute("sidetrackwidth", "" + p.getSideTrackWidth());
panel.setAttribute("defaulttrackcolor", p.getDefaultTrackColor());
panel.setAttribute("defaultoccupiedtrackcolor", p.getDefaultOccupiedTrackColor());
panel.setAttribute("defaultalternativetrackcolor", p.getDefaultAlternativeTrackColor());
panel.setAttribute("defaulttextcolor", p.getDefaultTextColor());
panel.setAttribute("turnoutcirclecolor", p.getTurnoutCircleColor());
panel.setAttribute("turnoutcirclesize", "" + p.getTurnoutCircleSize());
panel.setAttribute("turnoutdrawunselectedleg", (p.getTurnoutDrawUnselectedLeg() ? "yes" : "no"));
panel.setAttribute("turnoutbx", Float.toString((float) p.getTurnoutBX()));
panel.setAttribute("turnoutcx", Float.toString((float) p.getTurnoutCX()));
panel.setAttribute("turnoutwid", Float.toString((float) p.getTurnoutWid()));
panel.setAttribute("xoverlong", Float.toString((float) p.getXOverLong()));
panel.setAttribute("xoverhwid", Float.toString((float) p.getXOverHWid()));
panel.setAttribute("xovershort", Float.toString((float) p.getXOverShort()));
panel.setAttribute("autoblkgenerate", "" + (p.getAutoBlockAssignment() ? "yes" : "no"));
if (p.getBackgroundColor() != null) {
panel.setAttribute("redBackground", "" + p.getBackgroundColor().getRed());
panel.setAttribute("greenBackground", "" + p.getBackgroundColor().getGreen());
panel.setAttribute("blueBackground", "" + p.getBackgroundColor().getBlue());
}
panel.setAttribute("gridSize", "" + p.getGridSize());
panel.setAttribute("gridSize2nd", "" + p.getGridSize2nd());
p.resetDirty();
panel.setAttribute("openDispatcher", p.getOpenDispatcherOnLoad() ? "yes" : "no");
panel.setAttribute("useDirectTurnoutControl", p.getDirectTurnoutControl() ? "yes" : "no");
// note: moving zoom attribute into per-window user preference
//panel.setAttribute("zoom", Double.toString(p.getZoom()));
// include contents (Icons and Labels)
List<Positionable> contents = p.getContents();
int num = contents.size();
if (num > 0) {
for (int i = 0; i < num; i++) {
Positionable sub = contents.get(i);
if (sub != null && sub.storeItem()) {
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel contents element: " + e);
}
} else {
log.warn("Null entry found when storing panel contents.");
}
}
}
// include LayoutTurnouts
num = p.turnoutList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutturnout elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turnoutList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutturnout element: " + e);
}
}
}
// include TrackSegments
num = p.trackList.size();
if (log.isDebugEnabled()) {
log.debug("N tracksegment elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.trackList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel tracksegment element: " + e);
}
}
}
// include PositionablePoints
num = p.pointList.size();
if (log.isDebugEnabled()) {
log.debug("N positionablepoint elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.pointList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel positionalpoint element: " + e);
}
}
}
// include LevelXings
num = p.xingList.size();
if (log.isDebugEnabled()) {
log.debug("N levelxing elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.xingList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel levelxing element: " + e);
}
}
}
// include LayoutSlips
num = p.slipList.size();
if (log.isDebugEnabled()) {
log.debug("N layoutSlip elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.slipList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel layoutSlip element: " + e);
}
}
}
// include LayoutTurntables
num = p.turntableList.size();
if (log.isDebugEnabled()) {
log.debug("N turntable elements: " + num);
}
if (num > 0) {
for (int i = 0; i < num; i++) {
Object sub = p.turntableList.get(i);
try {
Element e = jmri.configurexml.ConfigXmlManager.elementFromObject(sub);
if (e != null) {
panel.addContent(e);
}
} catch (Exception e) {
log.error("Error storing panel turntable element: " + e);
}
}
}
return panel;
}
Aggregations