use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class JsonUtil method getPanel.
public static ObjectNode getPanel(Locale locale, Editor editor, String format) {
if (editor.getAllowInFrameServlet()) {
String title = ((JmriJFrame) editor.getTargetPanel().getTopLevelAncestor()).getTitle();
if (!title.isEmpty() && !Arrays.asList(WebServerPreferences.getDefault().getDisallowedFrames()).contains(title)) {
String type = PANEL;
String name = "Panel";
if (editor instanceof ControlPanelEditor) {
type = CONTROL_PANEL;
name = "ControlPanel";
} else if (editor instanceof LayoutEditor) {
type = LAYOUT_PANEL;
name = "Layout";
}
ObjectNode root = mapper.createObjectNode();
root.put(TYPE, PANEL);
ObjectNode data = root.putObject(DATA);
// NOI18N
data.put(NAME, name + "/" + title.replaceAll(" ", "%20").replaceAll("#", "%23"));
// NOI18N
data.put(URL, "/panel/" + data.path(NAME).asText() + "?format=" + format);
data.put(USERNAME, title);
data.put(TYPE, type);
return root;
}
}
return null;
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class PanelMenu method addEditorPanel.
/**
* Add an Editor panel to Show Panels sub menu
*
* @param panel the panel to add to the menu
*/
public void addEditorPanel(final Editor panel) {
// If this is the first panel, remove the 'No Panels' menu item
if (panelsList.isEmpty()) {
panelsSubMenu.remove(noPanelsItem);
}
panelsList.add(panel);
ActionListener a = (ActionEvent e) -> {
if (panel instanceof LayoutEditor) {
panel.setVisible(true);
panel.repaint();
} else {
panel.getTargetFrame().setVisible(true);
}
updateEditorPanel(panel);
};
JCheckBoxMenuItem r = new JCheckBoxMenuItem(panel.getTitle());
r.addActionListener(a);
panelsSubMenu.add(r);
updateEditorPanel(panel);
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class EntryExitPairsXml method load.
/**
* Load, starting with the layoutBlock element, then all the value-icon
* pairs.
*
* @param shared Top level Element to unpack
* @param perNode ignored in this application
*/
@Override
public boolean load(Element shared, Element perNode) {
// create the objects
EntryExitPairs eep = jmri.InstanceManager.getDefault(jmri.jmrit.signalling.EntryExitPairs.class);
try {
String clearoption = shared.getChild("cleardown").getText();
eep.setClearDownOption(Integer.parseInt(clearoption));
} catch (java.lang.NullPointerException e) {
//Considered normal if it doesn't exist
}
// get attributes
ConfigureManager cm = jmri.InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
ArrayList<Object> loadedPanel;
if (cm != null) {
loadedPanel = cm.getInstanceList(LayoutEditor.class);
} else {
log.error("Failed getting optional default config manager");
loadedPanel = new ArrayList<Object>();
}
if (shared.getChild("dispatcherintegration") != null && shared.getChild("dispatcherintegration").getText().equals("yes")) {
eep.setDispatcherIntegration(true);
}
if (shared.getChild("colourwhilesetting") != null) {
eep.setSettingRouteColor(stringToColor(shared.getChild("colourwhilesetting").getText()));
int settingTimer = 2000;
try {
settingTimer = Integer.parseInt(shared.getChild("settingTimer").getText());
} catch (Exception e) {
log.error("Error in converting timer to int " + shared.getChild("settingTimer"));
}
eep.setSettingTimer(settingTimer);
}
List<Element> panelList = shared.getChildren("layoutPanel");
for (int k = 0; k < panelList.size(); k++) {
String panelName = panelList.get(k).getAttribute("name").getValue();
LayoutEditor panel = null;
for (int i = 0; i < loadedPanel.size(); i++) {
LayoutEditor tmp = (LayoutEditor) loadedPanel.get(i);
if (tmp.getLayoutName().equals(panelName)) {
panel = tmp;
break;
}
}
if (panel != null) {
List<Element> sourceList = panelList.get(k).getChildren("source");
for (int i = 0; i < sourceList.size(); i++) {
String sourceType = sourceList.get(i).getAttribute("type").getValue();
String sourceItem = sourceList.get(i).getAttribute("item").getValue();
NamedBean source = null;
if (sourceType.equals("signalMast")) {
source = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(sourceItem);
} else if (sourceType.equals("sensor")) {
source = jmri.InstanceManager.sensorManagerInstance().getSensor(sourceItem);
} else if (sourceType.equals("signalHead")) {
source = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(sourceItem);
}
//These two could be subbed off.
List<Element> destinationList = sourceList.get(i).getChildren("destination");
if (destinationList.size() > 0) {
eep.addNXSourcePoint(source, panel);
}
for (int j = 0; j < destinationList.size(); j++) {
String id = null;
if (destinationList.get(j).getAttribute("uniqueid") != null) {
id = destinationList.get(j).getAttribute("uniqueid").getValue();
}
String destType = destinationList.get(j).getAttribute("type").getValue();
String destItem = destinationList.get(j).getAttribute("item").getValue();
NamedBean dest = null;
if (destType.equals("signalMast")) {
dest = jmri.InstanceManager.getDefault(jmri.SignalMastManager.class).getSignalMast(destItem);
} else if (destType.equals("sensor")) {
dest = jmri.InstanceManager.sensorManagerInstance().getSensor(destItem);
} else if (destType.equals("signalHead")) {
dest = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(destItem);
}
try {
eep.addNXDestination(source, dest, panel, id);
} catch (java.lang.NullPointerException e) {
log.error("An error occured while trying to add a point");
}
if ((destinationList.get(j).getAttribute("uniDirection") != null) && (destinationList.get(j).getAttribute("uniDirection").getValue().equals("no"))) {
eep.setUniDirection(source, panel, dest, false);
}
if ((destinationList.get(j).getAttribute("enabled") != null) && (destinationList.get(j).getAttribute("enabled").getValue().equals("no"))) {
eep.setEnabled(source, panel, dest, false);
}
if (destinationList.get(j).getAttribute("nxType") != null) {
String nxType = destinationList.get(j).getAttribute("nxType").getValue();
if (nxType.equals("turnoutsetting")) {
eep.setEntryExitType(source, panel, dest, 0x00);
} else if (nxType.equals("signalmastlogic")) {
eep.setEntryExitType(source, panel, dest, 0x01);
} else if (nxType.equals("fullinterlocking")) {
eep.setEntryExitType(source, panel, dest, 0x02);
}
}
}
}
} else {
log.error("Panel has not been loaded");
}
}
return true;
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class SignallingSourcePanel method discoverPressed.
/**
* Respond to the Discover button being pressed.
* Check whether AdvancedRouting is turned on and any Layout Editor Panels
* are present. For each LE Panel, call discoverSignallingDest()
* {@link jmri.SignalMastLogicManager#discoverSignallingDest(SignalMast, LayoutEditor)}
* @param e The button event
*/
void discoverPressed(ActionEvent e) {
if (!jmri.InstanceManager.getDefault(LayoutBlockManager.class).isAdvancedRoutingEnabled()) {
int response = JOptionPane.showConfirmDialog(null, rb.getString("EnableLayoutBlockRouting"));
if (response == 0) {
jmri.InstanceManager.getDefault(LayoutBlockManager.class).enableAdvancedRouting(true);
JOptionPane.showMessageDialog(null, rb.getString("LayoutBlockRoutingEnabledShort"));
}
}
ArrayList<LayoutEditor> layout = jmri.jmrit.display.PanelMenu.instance().getLayoutEditorPanelList();
if (layout.size() > 0) {
signalMastLogicFrame = new JmriJFrame(rb.getString("DiscoverMastsTitle"), false, false);
signalMastLogicFrame.setPreferredSize(null);
JPanel panel1 = new JPanel();
sourceLabel = new JLabel(rb.getString("DiscoveringMasts"));
sourceLabel.setBorder(BorderFactory.createEmptyBorder(5, 20, 5, 20));
panel1.add(sourceLabel);
signalMastLogicFrame.add(sourceLabel);
signalMastLogicFrame.pack();
signalMastLogicFrame.setVisible(true);
jmri.InstanceManager.getDefault(jmri.SignalMastLogicManager.class).addPropertyChangeListener(this);
for (int i = 0; i < layout.size(); i++) {
try {
jmri.InstanceManager.getDefault(jmri.SignalMastLogicManager.class).discoverSignallingDest(sourceMast, layout.get(i));
// indicate progress
sourceLabel.setText(rb.getString("DiscoveringMasts") + " (" + i + "/" + layout.size() + ")");
} catch (jmri.JmriException ex) {
signalMastLogicFrame.setVisible(false);
JOptionPane.showMessageDialog(null, ex.toString());
}
}
jmri.InstanceManager.getDefault(jmri.SignalMastLogicManager.class).removePropertyChangeListener(this);
} else {
// don't take the trouble of searching
JOptionPane.showMessageDialog(null, rb.getString("GenSkipped"));
}
}
use of jmri.jmrit.display.layoutEditor.LayoutEditor in project JMRI by JMRI.
the class EntryExitPairs method getSourcePanelList.
public ArrayList<LayoutEditor> getSourcePanelList() {
ArrayList<LayoutEditor> list = new ArrayList<LayoutEditor>();
for (Entry<PointDetails, Source> e : nxpair.entrySet()) {
PointDetails key = e.getKey();
LayoutEditor pan = key.getPanel();
if (!list.contains(pan)) {
list.add(pan);
}
}
return list;
}
Aggregations