use of javax.swing.event.ChangeEvent in project JMRI by JMRI.
the class GuiLafConfigPane method doToolTipDismissDelay.
public void doToolTipDismissDelay(JPanel panel) {
GuiLafPreferencesManager manager = InstanceManager.getDefault(GuiLafPreferencesManager.class);
JLabel toolTipDismissDelayLabel = new JLabel(ConfigBundle.getMessage("GUIToolTipDismissDelay"));
toolTipDismissDelaySpinner = new JSpinner(new SpinnerNumberModel(manager.getToolTipDismissDelay() / 1000, MIN_TOOLTIP_TIME, MAX_TOOLTIP_TIME, 1));
this.toolTipDismissDelaySpinner.addChangeListener((ChangeEvent e) -> {
// convert to milliseconds from seconds
manager.setToolTipDismissDelay((int) toolTipDismissDelaySpinner.getValue() * 1000);
});
this.toolTipDismissDelaySpinner.setToolTipText(MessageFormat.format(ConfigBundle.getMessage("GUIToolTipDismissDelayToolTip"), MIN_TOOLTIP_TIME, MAX_TOOLTIP_TIME));
toolTipDismissDelayLabel.setToolTipText(this.toolTipDismissDelaySpinner.getToolTipText());
JLabel toolTipDismissDelayUoM = new JLabel(ConfigBundle.getMessage("GUIToolTipDismissDelayUoM"));
toolTipDismissDelayUoM.setToolTipText(this.toolTipDismissDelaySpinner.getToolTipText());
panel.add(toolTipDismissDelayLabel);
panel.add(toolTipDismissDelaySpinner);
panel.add(toolTipDismissDelayUoM);
}
use of javax.swing.event.ChangeEvent in project JMRI by JMRI.
the class AutoTrainsFrame method newTrainLine.
private void newTrainLine() {
int i = _JPanels.size();
final String s = "" + i;
newSeparator();
JPanel px = new JPanel();
px.setLayout(new FlowLayout());
_JPanels.add(px);
JLabel tLabel = new JLabel(" ");
px.add(tLabel);
px.add(tLabel);
_trainLabels.add(tLabel);
JButton tStop = new JButton(Bundle.getMessage("ResumeButton"));
px.add(tStop);
_stopButtons.add(tStop);
tStop.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
stopResume(s);
}
});
JButton tManual = new JButton(Bundle.getMessage("ToManualButton"));
px.add(tManual);
_manualButtons.add(tManual);
tManual.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
manualAuto(s);
}
});
JButton tResumeAuto = new JButton(Bundle.getMessage("ResumeAutoButton"));
px.add(tResumeAuto);
_resumeAutoRunningButtons.add(tResumeAuto);
tResumeAuto.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
resumeAutoOperation(s);
}
});
tResumeAuto.setVisible(false);
tResumeAuto.setToolTipText(Bundle.getMessage("ResumeAutoButtonHint"));
ButtonGroup directionGroup = new ButtonGroup();
JRadioButton fBut = new JRadioButton(Bundle.getMessage("ForwardRadio"));
px.add(fBut);
_forwardButtons.add(fBut);
fBut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
directionButton(s);
}
});
directionGroup.add(fBut);
JRadioButton rBut = new JRadioButton(Bundle.getMessage("ReverseRadio"));
px.add(rBut);
_reverseButtons.add(rBut);
rBut.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
directionButton(s);
}
});
directionGroup.add(rBut);
JSlider sSlider = new JSlider(0, 100, 0);
px.add(sSlider);
_speedSliders.add(sSlider);
sSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int val = ((JSlider) (e.getSource())).getValue();
sliderChanged(s, val);
}
});
JLabel _throttle = new JLabel();
_throttle.setText("Speed Unknown");
_throttleStatus.add(_throttle);
px.add(_throttle);
contentPane.add(px);
}
use of javax.swing.event.ChangeEvent in project JMRI by JMRI.
the class CoordinateEdit method initSetXY.
public void initSetXY() {
oldX = pl.getX();
oldY = pl.getY();
textX = new javax.swing.JLabel();
textX.setText("X: " + pl.getX());
textX.setVisible(true);
textY = new javax.swing.JLabel();
textY.setText("Y: " + pl.getY());
textY.setVisible(true);
SpinnerNumberModel model = new SpinnerNumberModel(0, 0, 10000, 1);
ChangeListener listener = new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
int x = ((Number) spinX.getValue()).intValue();
int y = ((Number) spinY.getValue()).intValue();
pl.setLocation(x, y);
textX.setText("X: " + pl.getX());
textY.setText("Y: " + pl.getY());
}
};
spinX = new javax.swing.JSpinner(model);
spinX.setValue(Integer.valueOf(pl.getX()));
spinX.setToolTipText(Bundle.getMessage("EnterXcoord"));
spinX.setMaximumSize(new Dimension(spinX.getMaximumSize().width, spinX.getPreferredSize().height));
spinX.addChangeListener(listener);
model = new javax.swing.SpinnerNumberModel(0, 0, 10000, 1);
spinY = new javax.swing.JSpinner(model);
spinY.setValue(Integer.valueOf(pl.getY()));
spinY.setToolTipText(Bundle.getMessage("EnterYcoord"));
spinY.setMaximumSize(new Dimension(spinY.getMaximumSize().width, spinY.getPreferredSize().height));
spinY.addChangeListener(listener);
getContentPane().setLayout(new GridBagLayout());
addSpinItems(true);
okButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
int x = ((Number) spinX.getValue()).intValue();
int y = ((Number) spinY.getValue()).intValue();
pl.setLocation(x, y);
textX.setText("X: " + pl.getX());
textY.setText("Y: " + pl.getY());
dispose();
}
});
okButton.getRootPane().setDefaultButton(okButton);
cancelButton.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
pl.setLocation(oldX, oldY);
dispose();
}
});
// make large enough to easily move
setMinimumSize(new Dimension(250, 175));
pack();
}
use of javax.swing.event.ChangeEvent in project JMRI by JMRI.
the class ControlPanel method initGUI.
/**
* Create, initialize and place GUI components.
*/
private void initGUI() {
JPanel mainPanel = new JPanel();
this.setContentPane(mainPanel);
mainPanel.setLayout(new BorderLayout());
this.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
speedControlPanel = new JPanel();
speedControlPanel.setLayout(new BoxLayout(speedControlPanel, BoxLayout.X_AXIS));
this.getContentPane().add(speedControlPanel, BorderLayout.CENTER);
sliderPanel = new JPanel();
sliderPanel.setLayout(new GridBagLayout());
GridBagConstraints constraints = new GridBagConstraints();
constraints.anchor = GridBagConstraints.CENTER;
constraints.fill = GridBagConstraints.BOTH;
constraints.gridheight = 1;
constraints.gridwidth = 1;
constraints.ipadx = 0;
constraints.ipady = 0;
Insets insets = new Insets(2, 2, 2, 2);
constraints.insets = insets;
constraints.weightx = 1;
constraints.weighty = 1;
constraints.gridx = 0;
constraints.gridy = 0;
sliderPanel.add(speedSlider, constraints);
//this.getContentPane().add(sliderPanel,BorderLayout.CENTER);
speedControlPanel.add(sliderPanel);
speedSlider.setOrientation(JSlider.VERTICAL);
speedSlider.setMajorTickSpacing(MAX_SPEED / 2);
java.util.Hashtable<Integer, JLabel> labelTable = new java.util.Hashtable<Integer, JLabel>();
labelTable.put(Integer.valueOf(MAX_SPEED / 2), new JLabel("50%"));
labelTable.put(Integer.valueOf(MAX_SPEED), new JLabel("100%"));
labelTable.put(Integer.valueOf(0), new JLabel(Bundle.getMessage("LabelStop")));
speedSlider.setLabelTable(labelTable);
speedSlider.setPaintTicks(true);
speedSlider.setPaintLabels(true);
// remove old actions
speedSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
boolean doIt = false;
if (!speedSlider.getValueIsAdjusting()) {
doIt = true;
} else if (System.currentTimeMillis() - lastTrackedSliderMovementTime >= trackSliderMinInterval) {
doIt = true;
lastTrackedSliderMovementTime = System.currentTimeMillis();
}
if (doIt) {
float newSpeed = (speedSlider.getValue() / (MAX_SPEED * 1.0f));
if (log.isDebugEnabled()) {
log.debug("stateChanged: slider pos: " + speedSlider.getValue() + " speed: " + newSpeed);
}
_throttle.setSpeedSetting(newSpeed);
if (speedSpinner != null) {
speedSpinnerModel.setValue(Integer.valueOf(speedSlider.getValue()));
}
}
} else {
internalAdjust = false;
}
}
});
spinnerPanel = new JPanel();
spinnerPanel.setLayout(new GridBagLayout());
if (speedSpinner != null) {
spinnerPanel.add(speedSpinner, constraints);
}
//this.getContentPane().add(spinnerPanel,BorderLayout.CENTER);
speedControlPanel.add(spinnerPanel);
// remove old actions
if (speedSpinner != null) {
speedSpinner.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
if (!internalAdjust) {
float newSpeed = ((Integer) speedSpinner.getValue()).floatValue() / (MAX_SPEED * 1.0f);
if (log.isDebugEnabled()) {
log.debug("stateChanged: spinner pos: " + speedSpinner.getValue() + " speed: " + newSpeed);
}
_throttle.setSpeedSetting(newSpeed);
//_throttleFrame.setSpeedSetting( newSpeed );
speedSlider.setValue(((Integer) speedSpinner.getValue()).intValue());
} else {
internalAdjust = false;
}
}
});
}
ButtonGroup speedStepButtons = new ButtonGroup();
speedStepButtons.add(SpeedStep128Button);
speedStepButtons.add(SpeedStep28Button);
speedStepButtons.add(SpeedStep27Button);
speedStepButtons.add(SpeedStep14Button);
constraints.fill = GridBagConstraints.NONE;
constraints.gridy = 1;
spinnerPanel.add(SpeedStep128Button, constraints);
constraints.gridy = 2;
spinnerPanel.add(SpeedStep28Button, constraints);
constraints.gridy = 3;
spinnerPanel.add(SpeedStep27Button, constraints);
constraints.gridy = 4;
spinnerPanel.add(SpeedStep14Button, constraints);
SpeedStep14Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode14);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode14);
}
});
SpeedStep27Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode27);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode27);
}
});
SpeedStep28Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode28);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode28);
}
});
SpeedStep128Button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
setSpeedSteps(DccThrottle.SpeedStepMode128);
_throttle.setSpeedStepMode(DccThrottle.SpeedStepMode128);
}
});
// set by default which speed selection method is on top
setSpeedController(_displaySlider);
}
use of javax.swing.event.ChangeEvent in project JMRI by JMRI.
the class VSDecoderPane method initComponents.
/**
* initComponents()
*
* initialzies the GUI components.
*/
@Override
public void initComponents() {
log.debug("initComponents()");
//buildMenu();
setLayout(new GridBagLayout());
setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
// Add the tabbed pane to the VSDecoderPane. The tabbedPane will contain all the other panes.
tabbedPane = new JTabbedPane();
GridBagConstraints gbc1 = new GridBagConstraints();
gbc1.gridx = 0;
gbc1.gridy = 0;
gbc1.fill = GridBagConstraints.BOTH;
gbc1.anchor = GridBagConstraints.CENTER;
gbc1.weightx = 1.0;
gbc1.weighty = 1.0;
this.add(tabbedPane, gbc1);
//-------------------------------------------------------------------
// configPanel
// The configPanel holds the stuff for addressing and configuration.
configPanel = new VSDConfigPanel(decoder_id, this);
tabbedPane.addTab("Config", configPanel);
//-------------------------------------------------------------------
// soundsPanel
// The optionPanel holds controls for selecting sound options.
optionPanel = new VSDOptionPanel(decoder_id, this);
tabbedPane.addTab("Options", optionPanel);
//-------------------------------------------------------------------
// soundsPanel
// The soundsPanel holds buttons for specific sounds.
soundsPanel = new VSDSoundsPanel(decoder_id, this);
tabbedPane.addTab("Sounds", soundsPanel);
//-------------------------------------------------------------------
// volumePanel
// The volumePanel holds the master volume and mute controls.
volumePanel = new JPanel();
volumePanel.setLayout(new BorderLayout(10, 0));
TitledBorder title = BorderFactory.createTitledBorder(BorderFactory.createLoweredBevelBorder(), "Volume");
title.setTitlePosition(TitledBorder.DEFAULT_POSITION);
volumePanel.setBorder(title);
JSlider volume = new JSlider(0, 100);
volume.setMinorTickSpacing(10);
volume.setPaintTicks(true);
volume.setValue(80);
volume.setPreferredSize(new Dimension(200, 20));
volume.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
volumeChange(e);
}
});
volumePanel.add(volume, BorderLayout.LINE_START);
JToggleButton mute_button = new JToggleButton("Mute");
mute_button.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
muteButtonPressed(e);
}
});
volumePanel.add(mute_button, BorderLayout.LINE_END);
GridBagConstraints gbc2 = new GridBagConstraints();
gbc2.gridx = 0;
gbc2.gridy = 1;
gbc2.fill = GridBagConstraints.BOTH;
gbc2.anchor = GridBagConstraints.CENTER;
gbc2.weightx = 1.0;
gbc2.weighty = 0.1;
this.add(volumePanel, gbc2);
//-------------------------------------------------------------------
// statusBar
// The statusBar shows decoder status.
statusBar = new jmri.util.swing.StatusBar();
statusBar.setMessage("Status: No decoder assigned");
GridBagConstraints gbc3 = new GridBagConstraints();
gbc3.gridx = 0;
gbc3.gridy = 2;
gbc3.fill = GridBagConstraints.BOTH;
gbc3.anchor = GridBagConstraints.PAGE_END;
gbc3.weightx = 1.0;
gbc3.weighty = 0.1;
this.add(statusBar, gbc3);
//-------------------------------------------------------------------
// Pack and set visible
parent.pack();
parent.setVisible(true);
}
Aggregations