use of jmri.ConfigureManager in project JMRI by JMRI.
the class SwitchboardEditorXml method load.
/**
* Create a SwitchboardEditor object, then register and fill it, then pop it in a
* JFrame
*
* @param shared Top level Element to unpack.
* @return true if successful
*/
@Override
public boolean load(Element shared, Element perNode) {
boolean result = true;
// find coordinates
int x = 0;
int y = 0;
int height = 400;
int width = 300;
int rangemin = 1;
int rangemax = 32;
int columns = 4;
String type = "T";
String connection = "I";
String shape = "key";
String name;
try {
x = shared.getAttribute("x").getIntValue();
y = shared.getAttribute("y").getIntValue();
height = shared.getAttribute("height").getIntValue();
width = shared.getAttribute("width").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's attribute");
result = false;
}
// find the name
// this will be replaced by the name as stored NOI18N
name = "Switchboard";
if (shared.getAttribute("name") != null) {
name = shared.getAttribute("name").getValue();
}
// confirm that panel hasn't already been loaded
if (jmri.jmrit.display.PanelMenu.instance().isPanelNameUsed(name)) {
log.warn("File contains a panel with the same name (" + name + ") as an existing panel");
result = false;
}
SwitchboardEditor panel = new SwitchboardEditor(name);
//panel.makeFrame(name);
jmri.jmrit.display.PanelMenu.instance().addEditorPanel(panel);
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
panel.setTitle();
// Load editor option flags. This has to be done before the content
// items are loaded, to preserve the individual item settings.
Attribute a;
boolean value = true;
if ((a = shared.getAttribute("editable")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllEditable(value);
value = true;
if ((a = shared.getAttribute("showtooltips")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllShowTooltip(value);
value = true;
if ((a = shared.getAttribute("controlling")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setAllControlling(value);
value = false;
if ((a = shared.getAttribute("hide")) != null && a.getValue().equals("yes")) {
value = true;
}
panel.setShowHidden(value);
value = true;
if ((a = shared.getAttribute("panelmenu")) != null && a.getValue().equals("no")) {
value = false;
}
panel.setPanelMenuVisible(value);
String state = "both";
if ((a = shared.getAttribute("scrollable")) != null) {
state = a.getValue();
}
panel.setScroll(state);
value = false;
if ((a = shared.getAttribute("hideunconnected")) != null && a.getValue().equals("yes")) {
value = true;
}
panel.setHideUnconnected(value);
try {
rangemin = shared.getAttribute("rangemin").getIntValue();
rangemax = shared.getAttribute("rangemax").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's range");
result = false;
}
panel.setPanelMenuRangeMin(rangemin);
panel.setPanelMenuRangeMax(rangemax);
type = shared.getAttribute("type").getValue();
panel.setSwitchType(type);
connection = shared.getAttribute("connection").getValue();
panel.setSwitchManu(connection);
shape = shared.getAttribute("shape").getValue();
panel.setSwitchShape(shape);
try {
columns = shared.getAttribute("columns").getIntValue();
} catch (org.jdom2.DataConversionException e) {
log.error("failed to convert Switchboard's column count");
result = false;
}
panel.setColumns(columns);
String defaultTextColor = "black";
if (shared.getAttribute("defaulttextcolor") != null) {
defaultTextColor = shared.getAttribute("defaulttextcolor").getValue();
}
panel.setDefaultTextColor(defaultTextColor);
// set color if needed
try {
int red = shared.getAttribute("redBackground").getIntValue();
int blue = shared.getAttribute("blueBackground").getIntValue();
int green = shared.getAttribute("greenBackground").getIntValue();
//panel.setBackground(new Color(red, green, blue));
panel.setDefaultBackgroundColor(new Color(red, green, blue));
} catch (org.jdom2.DataConversionException e) {
log.warn("Could not parse color attributes!");
} catch (NullPointerException e) {
// considered normal if the attributes are not present
}
//set the (global) editor display widgets to their flag settings
panel.initView();
// load the contents with their individual option settings
List<Element> items = shared.getChildren();
for (int i = 0; i < items.size(); i++) {
// get the class, hence the adapter object to do loading
Element item = items.get(i);
String adapterName = item.getAttribute("class").getValue();
log.debug("load via " + adapterName);
try {
XmlAdapter adapter = (XmlAdapter) Class.forName(adapterName).newInstance();
// and do it
adapter.load(item, panel);
if (!panel.loadOK()) {
result = false;
}
} catch (Exception e) {
log.error("Exception while loading " + item.getName() + ":" + e);
result = false;
e.printStackTrace();
}
}
// dispose of url correction data
panel.disposeLoadData();
// display the results, with the editor in back
panel.pack();
panel.setAllEditable(panel.isEditable());
// we don't pack the target frame here, because size was specified
// TODO: Work out why, when calling this method, panel size is increased
// vertically (at least on MS Windows)
// always show the panel
panel.getTargetFrame().setVisible(true);
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(panel);
}
// reset the size and position, in case the display caused it to change
panel.getTargetFrame().setLocation(x, y);
panel.getTargetFrame().setSize(width, height);
panel.updatePressed();
return result;
}
use of jmri.ConfigureManager in project JMRI by JMRI.
the class SwitchboardEditor method init.
/**
* Initialize the newly created SwitchBoard.
*
* @param name name of the switchboard frame
*/
@Override
protected void init(String name) {
//setVisible(false);
// Editor
Container contentPane = getContentPane();
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
// make menus
setGlobalSetsLocalFlag(false);
setUseGlobalFlag(false);
_menuBar = new JMenuBar();
makeOptionMenu();
//makeEditMenu();
makeFileMenu();
setJMenuBar(_menuBar);
addHelpMenu("package.jmri.jmrit.display.SwitchboardEditor", true);
//super.setTargetPanel(null, makeFrame(name)); // original CPE version
//extends JLayeredPane();
switchboardLayeredPane = new TargetPane();
switchboardLayeredPane.setPreferredSize(new Dimension(300, 310));
switchboardLayeredPane.setBorder(BorderFactory.createTitledBorder(BorderFactory.createLineBorder(defaultTextColor), Bundle.getMessage("SwitchboardBanner"), TitledBorder.LEADING, TitledBorder.ABOVE_BOTTOM, getFont(), defaultTextColor));
// create contrast with background, should also specify border style
// specify title for turnout, sensor, light, mixed? (wait for the Editor to be created)
switchboardLayeredPane.addMouseMotionListener(this);
//Add control pane and layered pane to this JPanel
JPanel beanSetupPane = new JPanel();
beanSetupPane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel beanTypeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("BeanTypeLabel")));
beanSetupPane.add(beanTypeTitle);
beanTypeList = new JComboBox(beanTypeStrings);
// select Turnout in comboBox
beanTypeList.setSelectedIndex(0);
beanTypeList.setActionCommand(LAYER_COMMAND);
beanTypeList.addActionListener(this);
beanSetupPane.add(beanTypeList);
//Add connection selection comboBox
// translate from selectedIndex to char
beanTypeChar = getSwitchType().charAt(0);
log.debug("beanTypeChar set to [{}]", beanTypeChar);
JLabel beanManuTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("ConnectionLabel")));
beanSetupPane.add(beanManuTitle);
beanManuNames = new JComboBox();
if (getManager(beanTypeChar) instanceof jmri.managers.AbstractProxyManager) {
// from abstractTableTabAction
jmri.managers.AbstractProxyManager proxy = (jmri.managers.AbstractProxyManager) getManager(beanTypeChar);
List<jmri.Manager> managerList = proxy.getManagerList();
for (int x = 0; x < managerList.size(); x++) {
String manuPrefix = managerList.get(x).getSystemPrefix();
log.debug("Prefix = [{}]", manuPrefix);
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
log.debug("Connection name = [{}]", manuName);
// add to comboBox
beanManuNames.addItem(manuName);
// add to list
beanManuPrefixes.add(manuPrefix);
}
} else {
String manuPrefix = getManager(beanTypeChar).getSystemPrefix();
String manuName = ConnectionNameFromSystemName.getConnectionName(manuPrefix);
beanManuNames.addItem(manuName);
// add to list (as only item)
beanManuPrefixes.add(manuPrefix);
}
beanManuNames.setSelectedIndex(0);
beanManuNames.setActionCommand(MANU_COMMAND);
beanManuNames.addActionListener(this);
beanSetupPane.add(beanManuNames);
add(beanSetupPane);
// add shape combobox
JPanel switchShapePane = new JPanel();
switchShapePane.setLayout(new FlowLayout(FlowLayout.TRAILING));
JLabel switchShapeTitle = new JLabel(Bundle.getMessage("MakeLabel", Bundle.getMessage("SwitchShape")));
switchShapePane.add(switchShapeTitle);
switchShapeList = new JComboBox(switchShapeStrings);
// select Button in comboBox
switchShapeList.setSelectedIndex(0);
switchShapeList.setActionCommand(SWITCHTYPE_COMMAND);
switchShapeList.addActionListener(this);
switchShapePane.add(switchShapeList);
// add column spinner
JLabel columnLabel = new JLabel(Bundle.getMessage("NumberOfColumns"));
switchShapePane.add(columnLabel);
switchShapePane.add(Columns);
add(switchShapePane);
JCheckBox hideUnconnected = new JCheckBox(Bundle.getMessage("CheckBoxHideUnconnected"));
hideUnconnected.setSelected(hideUnconnected());
hideUnconnected.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
setHideUnconnected(hideUnconnected.isSelected());
}
});
add(hideUnconnected);
// Next, add the buttons to the layered pane.
switchboardLayeredPane.setLayout(new GridLayout(java.lang.Math.max(2, _range % ((Integer) Columns.getValue())), (Integer) Columns.getValue()));
// vertical (at least 2 rows), horizontal
// TODO do some calculation from JPanel size, icon size and determine optimal cols/rows
addSwitchRange((Integer) minSpinner.getValue(), (Integer) maxSpinner.getValue(), beanTypeList.getSelectedIndex(), beanManuPrefixes.get(beanManuNames.getSelectedIndex()), switchShapeList.getSelectedIndex());
// provide a JLayeredPane to place the switches on
super.setTargetPanel(switchboardLayeredPane, makeFrame(name));
// width x height
super.getTargetFrame().setSize(550, 330);
// To do: Add component listener to handle frame resizing event
// set scrollbar initial state
setScroll(SCROLL_NONE);
scrollNone.setSelected(true);
super.setDefaultToolTip(new ToolTip(null, 0, 0, new Font("Serif", Font.PLAIN, 12), Color.black, new Color(255, 250, 210), Color.black));
// register the resulting panel for later configuration
ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cm != null) {
cm.registerUser(this);
}
add(createControlPanel());
JPanel updatePanel = new JPanel();
JButton updateButton = new JButton(Bundle.getMessage("ButtonUpdate"));
updateButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
log.debug("Update clicked");
updatePressed();
}
});
updatePanel.add(updateButton);
contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.PAGE_AXIS));
contentPane.add(updatePanel);
//re-layout all the toolbar items
setupToolBar();
// refresh default Switchboard
updatePressed();
pack();
setVisible(true);
// TODO choose your own icons
// class makeCatalog extends SwingWorker<CatalogPanel, Object> {
//
// @Override
// public CatalogPanel doInBackground() {
// return CatalogPanel.makeDefaultCatalog();
// }
// }
// (new makeCatalog()).execute();
// log.debug("Init SwingWorker launched");
}
use of jmri.ConfigureManager in project JMRI by JMRI.
the class JmrixConfigPane method dispose.
/**
* Disposes of the underlying connection for a configuration pane.
*
* @param confPane the pane to dispose of
*/
public static void dispose(JmrixConfigPane confPane) {
if (confPane == null) {
log.debug("no instance found therefore can not dispose of it!");
return;
}
if (confPane.ccCurrent != null) {
try {
confPane.ccCurrent.dispose();
} catch (Exception ex) {
log.error("Error Occured while disposing connection {}", ex.toString());
}
}
ConfigureManager cmOD = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cmOD != null) {
cmOD.deregister(confPane);
cmOD.deregister(confPane.ccCurrent);
}
InstanceManager.getDefault(ConnectionConfigManager.class).remove(confPane.ccCurrent);
}
use of jmri.ConfigureManager in project JMRI by JMRI.
the class Apps method doDeferredLoad.
private boolean doDeferredLoad(File file) {
boolean result;
log.debug("start deferred load from config");
try {
ConfigureManager cmOD = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
if (cmOD != null) {
result = cmOD.loadDeferred(file);
} else {
log.error("Failed to get default configure manager");
result = false;
}
} catch (JmriException e) {
log.error("Unhandled problem loading deferred configuration", e);
result = false;
}
log.debug("end deferred load from config file, OK={}", result);
return result;
}
use of jmri.ConfigureManager in project JMRI by JMRI.
the class AppsBase method installConfigurationManager.
protected void installConfigurationManager() {
ConfigureManager cm = new JmriConfigurationManager();
FileUtil.createDirectory(FileUtil.getUserFilesPath());
InstanceManager.store(cm, ConfigureManager.class);
InstanceManager.setDefault(ConfigureManager.class, cm);
log.debug("config manager installed");
}
Aggregations