use of javax.swing.JComponent in project JMRI by JMRI.
the class TurnoutIconWindowTest method testLayoutEditor.
@SuppressWarnings("unchecked")
public void testLayoutEditor() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
jmri.jmrit.display.layoutEditor.LayoutEditor panel = new jmri.jmrit.display.layoutEditor.LayoutEditor("TurnoutIconWindowTest.testLayoutEditor");
JComponent jf = panel.getTargetPanel();
TurnoutIcon icon = new TurnoutIcon(panel);
icon.setDisplayLevel(Editor.TURNOUTS);
Turnout sn = jmri.InstanceManager.turnoutManagerInstance().provideTurnout("IT1");
icon.setTurnout("IT1");
icon.setIcon("TurnoutStateClosed", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-closed.gif"));
icon.setIcon("TurnoutStateThrown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-thrown.gif"));
icon.setIcon("BeanStateInconsistent", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-error.gif"));
icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif", "resources/icons/smallschematics/tracksegments/os-lefthand-east-unknown.gif"));
panel.putItem(icon);
panel.setVisible(true);
Assert.assertEquals("initial state", Turnout.UNKNOWN, sn.getState());
// Click icon change state to Active
java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
getHelper().enterClickAndLeave(new MouseEventData(this, // component
jf, // number clicks
1, // modifiers
EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
false, // sleeptime
10, // position
EventDataConstants.CUSTOM, location));
Assert.assertEquals("state after one click", Turnout.CLOSED, sn.getState());
// Click icon change state to inactive
getHelper().enterClickAndLeave(new MouseEventData(this, icon));
Assert.assertEquals("state after two clicks", Turnout.THROWN, sn.getState());
// if OK to here, close window
TestHelper.disposeWindow(panel.getTargetFrame(), this);
// that pops dialog, find and press Delete
List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
JDialog d = dialogList.get(0);
// Find the button that deletes the panel
AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
JButton button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// that pops dialog, find and press Yes - Delete
dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
d = dialogList.get(0);
// Find the button that deletes the panel
bf = new AbstractButtonFinder("Yes - Dele");
button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class SensorIconWindowTest method testPanelEditor.
// DialogFinder not parameterized
@SuppressWarnings("unchecked")
public void testPanelEditor() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
jmri.jmrit.display.panelEditor.PanelEditor panel = new jmri.jmrit.display.panelEditor.PanelEditor("SensorIconWindowTest.testPanelEditor");
JComponent jf = panel.getTargetPanel();
SensorIcon icon = new SensorIcon(panel);
panel.putItem(icon);
Sensor sn = jmri.InstanceManager.sensorManagerInstance().provideSensor("IS1");
icon.setSensor("IS1");
icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"));
//daboudreau added this for Win7
icon.setDisplayLevel(Editor.SENSORS);
panel.setVisible(true);
//jf.setVisible(true);
Assert.assertEquals("initial state", Sensor.UNKNOWN, sn.getState());
// Click icon change state to Active
java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
getHelper().enterClickAndLeave(new MouseEventData(this, // component
jf, // number clicks
1, // modifiers
EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
false, // sleeptime
10, // position
EventDataConstants.CUSTOM, location));
Assert.assertEquals("state after one click", Sensor.INACTIVE, sn.getState());
// Click icon change state to inactive
getHelper().enterClickAndLeave(new MouseEventData(this, icon));
Assert.assertEquals("state after two clicks", Sensor.ACTIVE, sn.getState());
// if OK to here, close window
TestHelper.disposeWindow(panel.getTargetFrame(), this);
// that pops dialog, find and press Delete
List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
JDialog d = dialogList.get(0);
// Find the button that deletes the panel
AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
JButton button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// that pops dialog, find and press Yes - Delete
dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
d = dialogList.get(0);
// Find the button that deletes the panel
bf = new AbstractButtonFinder("Yes - Dele");
button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
use of javax.swing.JComponent in project JMRI by JMRI.
the class SensorIconWindowTest method testLayoutEditor.
// DialogFinder not parameterized
@SuppressWarnings("unchecked")
public void testLayoutEditor() throws Exception {
if (GraphicsEnvironment.isHeadless()) {
// can't Assume in TestCase
return;
}
jmri.jmrit.display.layoutEditor.LayoutEditor panel = new jmri.jmrit.display.layoutEditor.LayoutEditor("SensorIconWindowTest.testLayoutEditor");
JComponent jf = panel.getTargetPanel();
SensorIcon icon = new SensorIcon(panel);
panel.putItem(icon);
Sensor sn = jmri.InstanceManager.sensorManagerInstance().provideSensor("IS1");
icon.setSensor("IS1");
icon.setIcon("BeanStateUnknown", new NamedIcon("resources/icons/smallschematics/tracksegments/circuit-error.gif", "resources/icons/smallschematics/tracksegments/circuit-error.gif"));
//daboudreau added this for Win7
icon.setDisplayLevel(Editor.SENSORS);
panel.setVisible(true);
//jf.setVisible(true);
Assert.assertEquals("initial state", Sensor.UNKNOWN, sn.getState());
// Click icon change state to Active
java.awt.Point location = new java.awt.Point(icon.getLocation().x + icon.getSize().width / 2, icon.getLocation().y + icon.getSize().height / 2);
getHelper().enterClickAndLeave(new MouseEventData(this, // component
jf, // number clicks
1, // modifiers
EventDataConstants.DEFAULT_MOUSE_MODIFIERS, // isPopUpTrigger
false, // sleeptime
10, // position
EventDataConstants.CUSTOM, location));
Assert.assertEquals("state after one click", Sensor.INACTIVE, sn.getState());
// Click icon change state to inactive
getHelper().enterClickAndLeave(new MouseEventData(this, icon));
Assert.assertEquals("state after two clicks", Sensor.ACTIVE, sn.getState());
// if OK to here, close window
TestHelper.disposeWindow(panel.getTargetFrame(), this);
// that pops dialog, find and press Delete
List<JDialog> dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
JDialog d = dialogList.get(0);
// Find the button that deletes the panel
AbstractButtonFinder bf = new AbstractButtonFinder("Delete Panel");
JButton button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
// that pops dialog, find and press Yes - Delete
dialogList = new DialogFinder(null).findAll(panel.getTargetFrame());
d = dialogList.get(0);
// Find the button that deletes the panel
bf = new AbstractButtonFinder("Yes - Dele");
button = (JButton) bf.find(d, 0);
Assert.assertNotNull(button);
// Click button to delete panel and close window
getHelper().enterClickAndLeave(new MouseEventData(this, button));
}
use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.
the class NimbusLookAndFeel method shouldUpdateStyleOnEvent.
/**
* {@inheritDoc}
*
* <p>Overridden to return {@code true} when one of the following
* properties change:
* <ul>
* <li>{@code "Nimbus.Overrides"}
* <li>{@code "Nimbus.Overrides.InheritDefaults"}
* <li>{@code "JComponent.sizeVariant"}
* </ul>
*
* @since 1.7
*/
@Override
protected boolean shouldUpdateStyleOnEvent(PropertyChangeEvent ev) {
String eName = ev.getPropertyName();
// These properties affect style cached inside NimbusDefaults (6860433)
if ("name" == eName || "ancestor" == eName || "Nimbus.Overrides" == eName || "Nimbus.Overrides.InheritDefaults" == eName || "JComponent.sizeVariant" == eName) {
JComponent c = (JComponent) ev.getSource();
defaults.clearOverridesCache(c);
return true;
}
return super.shouldUpdateStyleOnEvent(ev);
}
use of javax.swing.JComponent in project jdk8u_jdk by JetBrains.
the class TextLayoutStrategy method sync.
/**
* Synchronize the strategy with its FlowView. Allows the strategy
* to update its state to account for changes in that portion of the
* model represented by the FlowView. Also allows the strategy
* to update the FlowView in response to these changes.
*/
void sync(FlowView fv) {
View lv = getLogicalView(fv);
text.setView(lv);
Container container = fv.getContainer();
FontRenderContext frc = sun.swing.SwingUtilities2.getFontRenderContext(container);
frcTx = frc.getTransform();
BreakIterator iter;
Container c = fv.getContainer();
if (c != null) {
iter = BreakIterator.getLineInstance(c.getLocale());
} else {
iter = BreakIterator.getLineInstance();
}
Object shaper = null;
if (c instanceof JComponent) {
shaper = ((JComponent) c).getClientProperty(TextAttribute.NUMERIC_SHAPING);
}
text.setShaper(shaper);
measurer = new LineBreakMeasurer(text, iter, frc);
// If the children of the FlowView's logical view are GlyphViews, they
// need to have their painters updated.
int n = lv.getViewCount();
for (int i = 0; i < n; i++) {
View child = lv.getView(i);
if (child instanceof GlyphView) {
int p0 = child.getStartOffset();
int p1 = child.getEndOffset();
measurer.setPosition(text.toIteratorIndex(p0));
TextLayout layout = measurer.nextLayout(Float.MAX_VALUE, text.toIteratorIndex(p1), false);
((GlyphView) child).setGlyphPainter(new GlyphPainter2(layout));
}
}
// Reset measurer.
measurer.setPosition(text.getBeginIndex());
}
Aggregations