Search in sources :

Example 71 with ChangeListener

use of javax.swing.event.ChangeListener in project processdash by dtuma.

the class AbstractEVChart method fireStateChanged.

protected void fireStateChanged() {
    if (changeListeners != null) {
        List<ChangeListener> listeners = new ArrayList<ChangeListener>(changeListeners);
        ChangeEvent evt = new ChangeEvent(this);
        for (ChangeListener l : listeners) l.stateChanged(evt);
    }
}
Also used : PropertyChangeEvent(java.beans.PropertyChangeEvent) ChangeEvent(javax.swing.event.ChangeEvent) ArrayList(java.util.ArrayList) ChangeListener(javax.swing.event.ChangeListener) PropertyChangeListener(java.beans.PropertyChangeListener)

Example 72 with ChangeListener

use of javax.swing.event.ChangeListener in project processdash by dtuma.

the class TeamMemberColumnManager method createColumns.

/** Create or recreate TeamMemberTimeColumn objects for each team member
     */
private void createColumns() {
    List<TeamMemberTimeColumn> obsoletePlanTimeColumns = planTimeColumnList;
    List<TeamMemberActualTimeColumn> obsoleteActualTimeColumns = actualTimeColumnList;
    ArrayList newColumns = new ArrayList();
    planTimeColumnList = new ArrayList<TeamMemberTimeColumn>();
    actualTimeColumnList = new ArrayList<TeamMemberActualTimeColumn>();
    Iterator teamMembers = teamList.getTeamMembers().iterator();
    while (teamMembers.hasNext()) {
        // Loop through the list of team members.
        TeamMember m = (TeamMember) teamMembers.next();
        // try to find a preexisting planned time column for this team member.
        TeamMemberTimeColumn planTimeCol = getExistingValidTimeColumn(obsoletePlanTimeColumns, m);
        if (planTimeCol == null) {
            // create a new column for this team member.
            planTimeCol = new TeamMemberTimeColumn(dataModel, m);
            newColumns.add(planTimeCol);
        }
        // add the column to our master list.
        planTimeColumnList.add(planTimeCol);
        // try to find a preexisting actual time column for this team member.
        TeamMemberActualTimeColumn actualTimeCol = getExistingValidTimeColumn(obsoleteActualTimeColumns, m);
        if (actualTimeCol == null) {
            // create a new column for this team member.
            actualTimeCol = new TeamMemberActualTimeColumn(m);
            newColumns.add(actualTimeCol);
        }
        // add the column to our master list.
        actualTimeColumnList.add(actualTimeCol);
    }
    // make the changes to the columns in the data model.
    if (!newColumns.isEmpty() || !obsoletePlanTimeColumns.isEmpty() || !obsoleteActualTimeColumns.isEmpty()) {
        List obsoleteColumns = new ArrayList();
        obsoleteColumns.addAll(obsoletePlanTimeColumns);
        obsoleteColumns.addAll(obsoleteActualTimeColumns);
        dataModel.addRemoveDataColumns(newColumns, obsoleteColumns);
    }
    // alert any listeners that have registered interest
    ChangeEvent e = new ChangeEvent(this);
    for (ChangeListener l : listeners) l.stateChanged(e);
}
Also used : ChangeEvent(javax.swing.event.ChangeEvent) ArrayList(java.util.ArrayList) Iterator(java.util.Iterator) ArrayList(java.util.ArrayList) List(java.util.List) TeamMemberList(teamdash.team.TeamMemberList) ChangeListener(javax.swing.event.ChangeListener) TeamMember(teamdash.team.TeamMember)

Example 73 with ChangeListener

use of javax.swing.event.ChangeListener 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);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) JRadioButton(javax.swing.JRadioButton) ActionEvent(java.awt.event.ActionEvent) JButton(javax.swing.JButton) JLabel(javax.swing.JLabel) Point(java.awt.Point) ActionListener(java.awt.event.ActionListener) ChangeEvent(javax.swing.event.ChangeEvent) ButtonGroup(javax.swing.ButtonGroup) JSlider(javax.swing.JSlider) ChangeListener(javax.swing.event.ChangeListener)

Example 74 with ChangeListener

use of javax.swing.event.ChangeListener 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();
}
Also used : GridBagLayout(java.awt.GridBagLayout) SpinnerNumberModel(javax.swing.SpinnerNumberModel) Dimension(java.awt.Dimension) ActionEvent(java.awt.event.ActionEvent) SpinnerNumberModel(javax.swing.SpinnerNumberModel) ChangeEvent(javax.swing.event.ChangeEvent) ChangeListener(javax.swing.event.ChangeListener)

Example 75 with ChangeListener

use of javax.swing.event.ChangeListener 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);
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) Insets(java.awt.Insets) GridBagLayout(java.awt.GridBagLayout) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JLabel(javax.swing.JLabel) BorderLayout(java.awt.BorderLayout) ChangeEvent(javax.swing.event.ChangeEvent) ActionListener(java.awt.event.ActionListener) ButtonGroup(javax.swing.ButtonGroup) ChangeListener(javax.swing.event.ChangeListener)

Aggregations

ChangeListener (javax.swing.event.ChangeListener)218 ChangeEvent (javax.swing.event.ChangeEvent)205 JPanel (javax.swing.JPanel)54 ActionEvent (java.awt.event.ActionEvent)47 ActionListener (java.awt.event.ActionListener)46 JLabel (javax.swing.JLabel)34 Dimension (java.awt.Dimension)29 GridBagConstraints (java.awt.GridBagConstraints)27 GridBagLayout (java.awt.GridBagLayout)24 JCheckBox (javax.swing.JCheckBox)24 Insets (java.awt.Insets)21 JSlider (javax.swing.JSlider)20 PropertyChangeListener (java.beans.PropertyChangeListener)19 JButton (javax.swing.JButton)19 BorderLayout (java.awt.BorderLayout)17 PropertyChangeEvent (java.beans.PropertyChangeEvent)17 IOException (java.io.IOException)14 BoxLayout (javax.swing.BoxLayout)14 ButtonGroup (javax.swing.ButtonGroup)14 JSpinner (javax.swing.JSpinner)13