304 lines
10 KiB
Java
304 lines
10 KiB
Java
package jmri.jmrit.throttle;
|
|
|
|
import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
|
import java.awt.Component;
|
|
|
|
import javax.swing.JMenuItem;
|
|
import javax.swing.JPopupMenu;
|
|
|
|
import jmri.DccLocoAddress;
|
|
import jmri.jmrit.throttle.panels.AddressPanel;
|
|
import jmri.jmrit.throttle.panels.ConsistFunctionPanel;
|
|
import jmri.jmrit.throttle.panels.FunctionButton;
|
|
|
|
import org.netbeans.jemmy.ComponentChooser;
|
|
import org.netbeans.jemmy.operators.JButtonOperator;
|
|
import org.netbeans.jemmy.operators.JCheckBoxOperator;
|
|
import org.netbeans.jemmy.operators.JDialogOperator;
|
|
import org.netbeans.jemmy.operators.JFrameOperator;
|
|
import org.netbeans.jemmy.operators.JInternalFrameOperator;
|
|
import org.netbeans.jemmy.operators.JMenuBarOperator;
|
|
import org.netbeans.jemmy.operators.JMenuItemOperator;
|
|
import org.netbeans.jemmy.operators.JMenuOperator;
|
|
import org.netbeans.jemmy.operators.JPopupMenuOperator;
|
|
import org.netbeans.jemmy.operators.JTextFieldOperator;
|
|
import org.netbeans.jemmy.operators.JToggleButtonOperator;
|
|
import org.netbeans.jemmy.operators.JRadioButtonOperator;
|
|
import org.netbeans.jemmy.operators.JSliderOperator;
|
|
import org.netbeans.jemmy.operators.JSpinnerOperator;
|
|
|
|
/*
|
|
* Helper class for operating the Throttle Frame.
|
|
*
|
|
* @author Paul Bender Copyright (C) 2018
|
|
*/
|
|
public class ThrottleOperator extends JFrameOperator {
|
|
|
|
public ThrottleOperator() {
|
|
this(Bundle.getMessage("ThrottleTitle"));
|
|
}
|
|
|
|
public ThrottleOperator(String title) {
|
|
super(title);
|
|
}
|
|
|
|
// Address Panel Operations
|
|
public JInternalFrameOperator getAddressPanelOperator() {
|
|
return new JInternalFrameOperator(this,
|
|
Bundle.getMessage("ThrottleMenuViewAddressPanel"));
|
|
}
|
|
|
|
private AddressPanel getAddressPanel() {
|
|
AddressPanel ap = (AddressPanel) findSubComponent(
|
|
new ComponentChooser() {
|
|
@Override
|
|
public boolean checkComponent(Component c) {
|
|
if (c instanceof AddressPanel) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Find AddressSelector";
|
|
}
|
|
});
|
|
return ap;
|
|
}
|
|
|
|
// type the address value.
|
|
public void typeAddressValue(int address) {
|
|
JInternalFrameOperator ifo = getAddressPanelOperator();
|
|
JTextFieldOperator jtfo = new JTextFieldOperator(ifo); // only one text field in the address panel.
|
|
jtfo.requestFocus(); // try focus, but need a window manager to work
|
|
jtfo.clickForPopup(); // force with right click (left lick would moce carret), fortunatly there is no right click handler in this component
|
|
jtfo.typeText("" + address);
|
|
}
|
|
|
|
// is the address field enabled
|
|
public boolean addressFieldEnabled() {
|
|
JInternalFrameOperator ifo = getAddressPanelOperator();
|
|
JTextFieldOperator jtfo = new JTextFieldOperator(ifo); // only one text field in the address panel.
|
|
return jtfo.isEnabled();
|
|
}
|
|
|
|
// get the address value.
|
|
public DccLocoAddress getAddressValue() {
|
|
AddressPanel ap = getAddressPanel();
|
|
return ap.getCurrentAddress();
|
|
}
|
|
|
|
// get the consist address value.
|
|
public DccLocoAddress getConsistAddressValue() {
|
|
AddressPanel ap = getAddressPanel();
|
|
return ap.getConsistAddress();
|
|
}
|
|
|
|
// set the address value.
|
|
public void setAddressValue(DccLocoAddress addr) {
|
|
AddressPanel ap = getAddressPanel();
|
|
ap.setCurrentAddress(addr);
|
|
}
|
|
|
|
// get the consist address value.
|
|
public jmri.Throttle getAttachedThrottle() {
|
|
AddressPanel ap = getAddressPanel();
|
|
return ap.getThrottle();
|
|
}
|
|
|
|
public void pushSetButton() {
|
|
new JButtonOperator(this, Bundle.getMessage("ButtonSet")).push();
|
|
}
|
|
|
|
public boolean setButtonEnabled() {
|
|
return (new JButtonOperator(this, Bundle.getMessage("ButtonSet"))).isEnabled();
|
|
}
|
|
|
|
public void pushDispatchButton() {
|
|
new JButtonOperator(this, Bundle.getMessage("ButtonDispatch")).push();
|
|
}
|
|
|
|
public void pushReleaseButton() {
|
|
new JButtonOperator(this, Bundle.getMessage("ButtonRelease")).push();
|
|
}
|
|
|
|
public boolean releaseButtonEnabled() {
|
|
return (new JButtonOperator(this, Bundle.getMessage("ButtonRelease"))).isEnabled();
|
|
}
|
|
|
|
public boolean dispatchButtonEnabled() {
|
|
return (new JButtonOperator(this, Bundle.getMessage("ButtonDispatch"))).isEnabled();
|
|
}
|
|
|
|
// Function panel operations
|
|
public JInternalFrameOperator getFunctionPanelOperator() {
|
|
return new JInternalFrameOperator(this,
|
|
Bundle.getMessage("ThrottleMenuViewFunctionPanel"));
|
|
}
|
|
|
|
public void pushFunctionButton(String Function) {
|
|
new JButtonOperator(getFunctionPanelOperator(), Function).push();
|
|
}
|
|
|
|
public FunctionButton getFunctionButton(int function) {
|
|
FunctionButton retval = (FunctionButton) findSubComponent(
|
|
new ComponentChooser() {
|
|
@Override
|
|
public boolean checkComponent(Component c) {
|
|
if (c instanceof FunctionButton) {
|
|
if (((FunctionButton) c).getIdentity() == function) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Find Function Button";
|
|
}
|
|
});
|
|
return retval;
|
|
}
|
|
|
|
public void openFunctionPopupMenu(int function) {
|
|
FunctionButton fb = getFunctionButton(function);
|
|
JToggleButtonOperator jbo = new JToggleButtonOperator(fb);
|
|
jbo.clickForPopup();
|
|
JPopupMenuOperator jpmo = new JPopupMenuOperator();
|
|
jpmo.pushMenuNoBlock(Bundle.getMessage("MenuItemProperties"));
|
|
}
|
|
|
|
public void toggleFunctionMomentary(int function) {
|
|
openFunctionPopupMenu(function);
|
|
JDialogOperator jdo = new JDialogOperator(Bundle.getMessage("ButtonEditFunction"));
|
|
(new JCheckBoxOperator(jdo, Bundle.getMessage("CheckBoxLockable"))).doClick();
|
|
(new JButtonOperator(jdo, Bundle.getMessage("ButtonApply"))).doClick();
|
|
(new JButtonOperator(jdo, Bundle.getMessage("ButtonClose"))).doClick();
|
|
}
|
|
|
|
// Consist function panel operations
|
|
public boolean showConsistFunctionsPanel() {
|
|
JMenuBarOperator mainbar = new JMenuBarOperator(this);
|
|
JMenuOperator jmo = new JMenuOperator(mainbar, Bundle.getMessage("ThrottleMenuView"));
|
|
JPopupMenu jpm = jmo.getPopupMenu();
|
|
JMenuItem viewCFP = (JMenuItem) jpm.getComponent(5);
|
|
assertEquals(Bundle.getMessage("ThrottleMenuViewConsistFunctionsPanel"), viewCFP.getText());
|
|
new JMenuItemOperator(viewCFP).doClick();
|
|
return true;
|
|
}
|
|
|
|
private ConsistFunctionPanel getConsistFunctionsPanel() {
|
|
showConsistFunctionsPanel();
|
|
ConsistFunctionPanel ap = (ConsistFunctionPanel) findSubComponent(
|
|
new ComponentChooser() {
|
|
@Override
|
|
public boolean checkComponent(Component c) {
|
|
if (c instanceof ConsistFunctionPanel) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public String getDescription() {
|
|
return "Find ConsistFunctionPanel";
|
|
}
|
|
});
|
|
return ap;
|
|
}
|
|
|
|
// get the consist address value.
|
|
public DccLocoAddress getConsistFunctionAddressValue() {
|
|
ConsistFunctionPanel cfp = getConsistFunctionsPanel();
|
|
return (DccLocoAddress) cfp.getFunctionThrottle().getLocoAddress();
|
|
}
|
|
|
|
// Control (Speed and Direction) panel operations
|
|
public JInternalFrameOperator getControlPanelOperator() {
|
|
return new JInternalFrameOperator(this,
|
|
Bundle.getMessage("ThrottleMenuViewControlPanel"));
|
|
}
|
|
|
|
public void pushStopButton() {
|
|
new JButtonOperator(getControlPanelOperator(),
|
|
Bundle.getMessage("ButtonStop")).push();
|
|
}
|
|
|
|
public void pushEStopButton() {
|
|
new JButtonOperator(getControlPanelOperator(),
|
|
Bundle.getMessage("ButtonStop")).push();
|
|
}
|
|
|
|
public void pushIdleButton() {
|
|
new JButtonOperator(getControlPanelOperator(),
|
|
Bundle.getMessage("ButtonIdle")).push();
|
|
}
|
|
|
|
public void pushForwardButton() {
|
|
new JRadioButtonOperator(getControlPanelOperator(),
|
|
Bundle.getMessage("ButtonForward")).push();
|
|
}
|
|
|
|
public void pushReverseButton() {
|
|
new JRadioButtonOperator(getControlPanelOperator(),
|
|
Bundle.getMessage("ButtonReverse")).push();
|
|
}
|
|
|
|
public int getSpeedSliderValue() {
|
|
return new JSliderOperator(getControlPanelOperator()).getValue();
|
|
}
|
|
|
|
public void setSpeedSlider(int i) {
|
|
new JSliderOperator(getControlPanelOperator()).setValue(i);
|
|
}
|
|
|
|
public void slideSpeedSlider(int i) {
|
|
new JSliderOperator(getControlPanelOperator()).scrollToValue(i);
|
|
}
|
|
|
|
public void speedSliderMaximum() {
|
|
new JSliderOperator(getControlPanelOperator()).scrollToMaximum();
|
|
}
|
|
|
|
public void speedSliderMinimum() {
|
|
new JSliderOperator(getControlPanelOperator()).scrollToMinimum();
|
|
}
|
|
|
|
public void openControlPanelPopupMenu() {
|
|
JInternalFrameOperator jifo = getControlPanelOperator();
|
|
jifo.clickForPopup();
|
|
JPopupMenuOperator jpmo = new JPopupMenuOperator();
|
|
jpmo.pushMenuNoBlock(Bundle.getMessage("ControlPanelProperties"));
|
|
}
|
|
|
|
public void setSpeedStepDisplay() {
|
|
openControlPanelPopupMenu();
|
|
JDialogOperator jdo = new JDialogOperator(Bundle.getMessage("TitleEditSpeedControlPanel"));
|
|
(new JRadioButtonOperator(jdo, Bundle.getMessage("ButtonDisplaySpeedSteps"))).doClick();
|
|
(new JButtonOperator(jdo, Bundle.getMessage("ButtonApply"))).doClick();
|
|
(new JButtonOperator(jdo, Bundle.getMessage("ButtonClose"))).doClick();
|
|
|
|
}
|
|
|
|
public void setSpeedSpinner(int i) {
|
|
new JSpinnerOperator(getControlPanelOperator()).setValue(i);
|
|
}
|
|
|
|
public void speedSpinnerMaximum() {
|
|
new JSpinnerOperator(getControlPanelOperator()).scrollToMaximum();
|
|
}
|
|
|
|
public void speedSpinnerMinimum() {
|
|
new JSpinnerOperator(getControlPanelOperator()).scrollToMinimum();
|
|
}
|
|
|
|
}
|