use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class MemorySpinnerIconTest method testShow.
public void testShow() {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
JmriJFrame jf = new JmriJFrame();
jf.getContentPane().setLayout(new java.awt.FlowLayout());
tos1 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(tos1);
tos2 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(tos2);
toi1 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(toi1);
toi2 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(toi2);
jmri.util.JUnitUtil.resetInstanceManager();
tos1.setMemory("IM1");
tos2.setMemory("IM1");
jmri.InstanceManager.memoryManagerInstance().getMemory("IM1").setValue("4");
toi1.setMemory("IM2");
toi2.setMemory("IM2");
jmri.InstanceManager.memoryManagerInstance().getMemory("IM2").setValue(10);
tos3 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(tos3);
toi3 = new MemorySpinnerIcon(panel);
jf.getContentPane().add(toi3);
tos3.setMemory("IM1");
toi3.setMemory("IM2");
jmri.InstanceManager.memoryManagerInstance().getMemory("IM1").setValue(11.58F);
jmri.InstanceManager.memoryManagerInstance().getMemory("IM2").setValue(0.89);
tos1.setMemory("IM1");
Assert.assertEquals("Spinner 1", "12", tos1.getValue());
tos2.setMemory("IM2");
Assert.assertEquals("Spinner 2", "12", tos1.getValue());
jf.pack();
jf.setVisible(true);
if (!System.getProperty("jmri.demo", "false").equals("false")) {
jf.setVisible(false);
}
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class MemoryIconTest method testShowBlank.
public void testShowBlank() {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
log.debug("testShowBlank");
JFrame jf = new JmriJFrame();
jf.setTitle("Expect blank");
jf.getContentPane().setLayout(new java.awt.FlowLayout());
jf.getContentPane().setBackground(Color.white);
MemoryIcon to = new MemoryIcon("MemoryTest2", panel);
jf.getContentPane().add(to);
to.getPopupUtility().setBackgroundColor(Color.white);
jf.getContentPane().add(new javax.swing.JLabel("| Expect blank: "));
jmri.InstanceManager.memoryManagerInstance().provideMemory("IM2").setValue("");
to.setMemory("IM2");
jf.pack();
jf.setVisible(true);
flushAWT();
int[] colors = getColor("Expect blank", "| Expect blank", 0, 6, 10);
//for (int i=0; i< 10; i++) System.out.println(" "+String.format("0x%8s", Integer.toHexString(colors[i])).replace(' ', '0'));
boolean white = (colors[3] == 0xffffffff) && (colors[4] == 0xffffffff);
Assert.assertTrue("Expect white pixels", white);
if (System.getProperty("jmri.demo", "false").equals("false")) {
jf.setVisible(false);
jf.dispose();
}
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class LocationsTableFrameTest method testLocationsEditFrame.
@Test
public void testLocationsEditFrame() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
LocationsTableFrame f = new LocationsTableFrame();
// create edit location frame
f.locationsModel.setValueAt(null, 2, LocationsTableModel.EDITCOLUMN);
// confirm location edit frame creation
JUnitUtil.waitFor(() -> {
return JmriJFrame.getFrame("Edit Location") != null;
}, "lef not null");
JmriJFrame lef = JmriJFrame.getFrame("Edit Location");
Assert.assertNotNull(lef);
// close windows
JFrameOperator jfolef = new JFrameOperator(lef);
jfolef.close();
JFrameOperator jfof = new JFrameOperator(f);
jfof.close();
Assert.assertNull(JmriJFrame.getFrame("Edit Location"));
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class RpsTrackingPanelTest method testShow.
@Test
public void testShow() {
Assume.assumeFalse(GraphicsEnvironment.isHeadless());
new Engine() {
void reset() {
_instance = null;
}
}.reset();
Engine.instance().setMaxReceiverNumber(2);
Engine.instance().setReceiver(1, new Receiver(new Point3d(12., 12., 0.)));
Engine.instance().setReceiver(2, new Receiver(new Point3d(13., 13., 0.)));
JmriJFrame f = new JmriJFrame("Test Tracking Panel");
f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
RpsTrackingPanel p = new RpsTrackingPanel();
p.setSize(400, 400);
p.setOrigin(0, 0);
p.setCoordMax(30., 30.);
f.getContentPane().add(p);
f.pack();
// add some regions to probe corners
Region r = new Region("(4,4,0);(10,16,0);(18,10,0);(4,4,0)");
Model.instance().addRegion(r);
r = new Region("(30,15,0);(25,15,0);(25,20,0);(30,15,0)");
Model.instance().addRegion(r);
r = new Region("(15,30,0);(15,25,0);(20,25,0);(15,30,0)");
Model.instance().addRegion(r);
r = new Region("(25,25,0);(25,28,0);(30,30,1);(29,25,0);(25,25,0)");
Model.instance().addRegion(r);
// show overlap
r = new Region("(20,20,0);(22,20,0);(22,22,1);(20,22,0)");
Model.instance().addRegion(r);
r = new Region("(19,19,0);(21,19,0);(21,21,1);(19,21,0)");
Model.instance().addRegion(r);
// show panel
f.setSize(400, 400);
f.setVisible(true);
Reading loco = new Reading("21", null);
Measurement m = new Measurement(loco, 0.0, 0.0, 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 0., 5., 0.0, 0.133, 5, "source");
p.notify(m);
loco = new Reading("21", null);
m = new Measurement(loco, 5., 0., 0.0, 0.133, 5, "source");
p.notify(m);
// check separate locos
int NUM_LOCO = 64;
for (int i = 0; i < NUM_LOCO; i++) {
loco = new Reading("" + i, null);
m = new Measurement(loco, 6. + 1. * i, 0., 0.0, 0.133, 5, "source");
p.notify(m);
m = new Measurement(loco, 6. + 1. * i, 12., 0.0, 0.133, 5, "source");
p.notify(m);
}
Assert.assertNotNull("found frame", f);
f.dispose();
}
use of jmri.util.JmriJFrame in project JMRI by JMRI.
the class SystemConsole method createFrame.
/**
* Layout the console frame
*/
private void createFrame() {
// Use a JmriJFrame to ensure that we fit on the screen
frame = new JmriJFrame(Bundle.getMessage("TitleConsole"));
pref = jmri.InstanceManager.getDefault(jmri.UserPreferencesManager.class);
// Add Help menu (Windows menu automaitically added)
// NOI18N
frame.addHelpMenu("package.apps.SystemConsole", true);
// Grab a reference to the system clipboard
final Clipboard clipboard = frame.getToolkit().getSystemClipboard();
// Setup the scroll pane
JScrollPane scroll = new JScrollPane(console);
frame.add(scroll, BorderLayout.CENTER);
// Add button to allow copy to clipboard
JPanel p = new JPanel();
JButton copy = new JButton(Bundle.getMessage("ButtonCopyClip"));
copy.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
p.add(copy);
// Add button to allow console window to be closed
JButton close = new JButton(Bundle.getMessage("ButtonClose"));
close.addActionListener((ActionEvent event) -> {
frame.setVisible(false);
frame.dispose();
});
p.add(close);
JButton stackTrace = new JButton(Bundle.getMessage("ButtonStackTrace"));
stackTrace.addActionListener((ActionEvent event) -> {
performStackTrace();
});
p.add(stackTrace);
// Add checkbox to enable/disable auto-scrolling
// Use the inverted SimplePreferenceState to default as enabled
p.add(autoScroll = new JCheckBox(Bundle.getMessage("CheckBoxAutoScroll"), !pref.getSimplePreferenceState(alwaysScrollCheck)));
autoScroll.addActionListener((ActionEvent event) -> {
doAutoScroll(console, autoScroll.isSelected());
pref.setSimplePreferenceState(alwaysScrollCheck, !autoScroll.isSelected());
});
// Add checkbox to enable/disable always on top
p.add(alwaysOnTop = new JCheckBox(Bundle.getMessage("CheckBoxOnTop"), pref.getSimplePreferenceState(alwaysOnTopCheck)));
alwaysOnTop.setVisible(true);
alwaysOnTop.setToolTipText(Bundle.getMessage("ToolTipOnTop"));
alwaysOnTop.addActionListener((ActionEvent event) -> {
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
pref.setSimplePreferenceState(alwaysOnTopCheck, alwaysOnTop.isSelected());
});
frame.setAlwaysOnTop(alwaysOnTop.isSelected());
// Define the pop-up menu
copySelection = new JMenuItem(Bundle.getMessage("MenuItemCopy"));
copySelection.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getSelectedText());
clipboard.setContents(text, text);
});
popup.add(copySelection);
JMenuItem menuItem = new JMenuItem(Bundle.getMessage("ButtonCopyClip"));
menuItem.addActionListener((ActionEvent event) -> {
StringSelection text = new StringSelection(console.getText());
clipboard.setContents(text, text);
});
popup.add(menuItem);
popup.add(new JSeparator());
JRadioButtonMenuItem rbMenuItem;
// Define the colour scheme sub-menu
schemeMenu = new JMenu(rbc.getString("ConsoleSchemeMenu"));
schemeGroup = new ButtonGroup();
for (final Scheme s : schemes) {
rbMenuItem = new JRadioButtonMenuItem(s.description);
rbMenuItem.addActionListener((ActionEvent event) -> {
setScheme(schemes.indexOf(s));
});
rbMenuItem.setSelected(getScheme() == schemes.indexOf(s));
schemeMenu.add(rbMenuItem);
schemeGroup.add(rbMenuItem);
}
popup.add(schemeMenu);
// Define the wrap style sub-menu
wrapMenu = new JMenu(rbc.getString("ConsoleWrapStyleMenu"));
wrapGroup = new ButtonGroup();
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleNone"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_NONE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_NONE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleLine"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_LINE);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_LINE);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
rbMenuItem = new JRadioButtonMenuItem(rbc.getString("ConsoleWrapStyleWord"));
rbMenuItem.addActionListener((ActionEvent event) -> {
setWrapStyle(WRAP_STYLE_WORD);
});
rbMenuItem.setSelected(getWrapStyle() == WRAP_STYLE_WORD);
wrapMenu.add(rbMenuItem);
wrapGroup.add(rbMenuItem);
popup.add(wrapMenu);
// Bind pop-up to objects
MouseListener popupListener = new PopupListener();
console.addMouseListener(popupListener);
frame.addMouseListener(popupListener);
// Add document listener to scroll to end when modified if required
console.getDocument().addDocumentListener(new DocumentListener() {
// References to the JTextArea and JCheckBox
// of this instantiation
JTextArea ta = console;
JCheckBox chk = autoScroll;
@Override
public void insertUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void removeUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
@Override
public void changedUpdate(DocumentEvent e) {
doAutoScroll(ta, chk.isSelected());
}
});
// Add the button panel to the frame & then arrange everything
frame.add(p, BorderLayout.SOUTH);
frame.pack();
}
Aggregations