use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class DetectionPanel method checkDetection.
/*
* ******************************************
*/
private void checkDetection() {
String name = _occDetectorName.getText();
if (name != null && name.trim().length() > 0) {
OBlock block = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(name);
if (block != null) {
if (block.equals(_block)) {
return;
}
makePathList(block);
} else {
Sensor sensor = InstanceManager.sensorManagerInstance().getSensor(name);
if (sensor == null) {
JOptionPane.showMessageDialog(_parent._paletteFrame, Bundle.getMessage("InvalidOccDetector", name), Bundle.getMessage("WarningTitle"), JOptionPane.WARNING_MESSAGE);
_occDetectorName.setText(null);
}
_blockPathPanel.setVisible(false);
_block = null;
}
} else {
_blockPathPanel.setVisible(false);
_block = null;
}
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class IndicatorTurnoutIcon method setOccBlockHandle.
@Override
public void setOccBlockHandle(NamedBeanHandle<OBlock> blockHandle) {
if (namedOccBlock != null) {
getOccBlock().removePropertyChangeListener(this);
}
namedOccBlock = blockHandle;
if (namedOccBlock != null) {
OBlock block = getOccBlock();
block.addPropertyChangeListener(this, namedOccBlock.getName(), "Indicator Turnout Icon");
setStatus(block, block.getState());
if (_iconMaps != null) {
displayState(turnoutState());
}
setTooltip(new ToolTip(block.getDescription(), 0, 0));
}
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class IndicatorTurnoutIconXml method store.
/**
* Default implementation for storing the contents of a IndicatorTurnoutIcon
*
* @param o Object to store, of type IndicatorTurnoutIcon
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
IndicatorTurnoutIcon p = (IndicatorTurnoutIcon) o;
if (!p.isActive()) {
// if flagged as inactive, don't store
return null;
}
Element element = new Element("indicatorturnouticon");
storeCommonAttributes(p, element);
NamedBeanHandle<Turnout> t = p.getNamedTurnout();
if (t != null) {
element.addContent(storeNamedBean("turnout", t));
}
NamedBeanHandle<OBlock> b = p.getNamedOccBlock();
if (b != null) {
element.addContent(storeNamedBean("occupancyblock", b));
}
NamedBeanHandle<Sensor> s = p.getNamedOccSensor();
if (b == null && s != null) {
// only write sensor if no OBlock
element.addContent(storeNamedBean("occupancysensor", s));
}
Element elem = new Element("showTrainName");
String show = "no";
if (p.showTrain()) {
show = "yes";
}
elem.addContent(show);
element.addContent(elem);
HashMap<String, HashMap<Integer, NamedIcon>> iconMaps = p.getIconMaps();
Iterator<Entry<String, HashMap<Integer, NamedIcon>>> it = iconMaps.entrySet().iterator();
Element el = new Element("iconmaps");
String family = p.getFamily();
if (family != null) {
el.setAttribute("family", family);
}
while (it.hasNext()) {
Entry<String, HashMap<Integer, NamedIcon>> ent = it.next();
elem = new Element(ent.getKey());
Iterator<Entry<Integer, NamedIcon>> iter = ent.getValue().entrySet().iterator();
while (iter.hasNext()) {
Entry<Integer, NamedIcon> entry = iter.next();
elem.addContent(storeIcon(p.getStateName(entry.getKey()), entry.getValue()));
}
el.addContent(elem);
}
element.addContent(el);
elem = new Element("paths");
ArrayList<String> paths = p.getPaths();
if (paths != null) {
for (int i = 0; i < paths.size(); i++) {
Element e = new Element("path");
e.addContent(paths.get(i));
elem.addContent(e);
}
element.addContent(elem);
}
element.setAttribute("class", "jmri.jmrit.display.configurexml.IndicatorTurnoutIconXml");
return element;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class EditPortalFrame method findAdjacentBlock.
/*
* If icon is on the home block, find another intersecting block
*/
private OBlock findAdjacentBlock(PortalIcon icon) {
ArrayList<OBlock> neighbors = new ArrayList<OBlock>();
OBlockManager manager = InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class);
String[] sysNames = manager.getSystemNameArray();
for (int j = 0; j < sysNames.length; j++) {
OBlock block = manager.getBySystemName(sysNames[j]);
if (block.equals(_homeBlock)) {
continue;
}
if (iconIntersectsBlock(icon, block) == null) {
neighbors.add(block);
}
}
OBlock block = null;
if (neighbors.size() == 1) {
block = neighbors.get(0);
} else if (neighbors.size() > 1) {
// show list
String[] selects = new String[neighbors.size()];
Iterator<OBlock> iter = neighbors.iterator();
int i = 0;
while (iter.hasNext()) {
selects[i++] = iter.next().getDisplayName();
}
Object select = JOptionPane.showInputDialog(this, Bundle.getMessage("multipleBlockSelections", _homeBlock.getDisplayName()), Bundle.getMessage("QuestionTitle"), JOptionPane.QUESTION_MESSAGE, null, selects, null);
if (select != null) {
iter = neighbors.iterator();
while (iter.hasNext()) {
block = iter.next();
if (((String) select).equals(block.getDisplayName())) {
return block;
}
}
}
}
if (log.isDebugEnabled()) {
log.debug("findAdjacentBlock: neighbors.size()= " + neighbors.size() + " return " + (block == null ? "null" : block.getDisplayName()));
}
return block;
}
use of jmri.jmrit.logix.OBlock in project JMRI by JMRI.
the class PortalIconXml method load.
/**
* Create a PositionableLabel, then add to a target JLayeredPane
*
* @param element Top level Element to unpack.
* @param o an Editor as an Object
*/
@Override
public void load(Element element, Object o) {
if (!(o instanceof ControlPanelEditor)) {
log.error("Can't load portalIcon. Panel editor must use ControlPanelEditor.");
return;
}
ControlPanelEditor ed = (ControlPanelEditor) o;
String fromBlk;
try {
fromBlk = element.getAttribute("fromBlockName").getValue();
} catch (NullPointerException e) {
log.error("incorrect information for portalIcon; must use fromBlockName.");
// ed.loadFailed();
return;
}
String portalName;
try {
portalName = element.getAttribute("portalName").getValue();
} catch (NullPointerException e) {
log.error("incorrect information for portalIcon; must use portalName.");
// ed.loadFailed();
return;
}
OBlock block = jmri.InstanceManager.getDefault(jmri.jmrit.logix.OBlockManager.class).getOBlock(fromBlk);
Portal portal = block.getPortalByName(portalName);
PortalIcon l = new PortalIcon(ed, portal);
ed.putItem(l);
// load individual item's option settings after editor has set its global settings
loadCommonAttributes(l, ControlPanelEditor.MARKERS, element);
Attribute a = element.getAttribute("scale");
double scale = 1.0;
if (a != null) {
try {
scale = a.getDoubleValue();
} catch (org.jdom2.DataConversionException dce) {
log.error(l.getNameString() + " can't convert scale " + dce);
}
}
l.setScale(scale);
a = element.getAttribute("rotate");
int deg = 0;
if (a != null) {
try {
deg = a.getIntValue();
} catch (org.jdom2.DataConversionException dce) {
log.error(l.getNameString() + " can't convert rotate " + dce);
}
}
l.rotate(deg);
boolean value = true;
if ((a = element.getAttribute("arrowSwitch")) != null && a.getValue().equals("no")) {
value = false;
}
l.setArrowOrientatuon(value);
value = false;
if ((a = element.getAttribute("arrowHide")) != null && a.getValue().equals("yes")) {
value = true;
}
l.setHideArrows(value);
}
Aggregations