001package jmri.jmrix.rps.trackingpanel;
002
003import java.awt.FlowLayout;
004import java.awt.event.ActionEvent;
005import java.awt.event.ActionListener;
006import javax.swing.BoxLayout;
007import javax.swing.JButton;
008import javax.swing.JLabel;
009import javax.swing.JPanel;
010import javax.swing.JTextField;
011
012/**
013 *
014 * Panel to control the scaling of a RpsTrackingPane.
015 *
016 * @author Bob Jacobsen Copyright (C) 2008
017 */
018public class RpsTrackingControlPane extends JPanel {
019
020    RpsTrackingPanel panel;
021
022    public RpsTrackingControlPane(RpsTrackingPanel panel) {
023        super();
024
025        this.panel = panel;
026
027        setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
028
029        JPanel p;
030
031        trXf = new JTextField(6);
032        trYf = new JTextField(6);
033        blXf = new JTextField(6);
034        blYf = new JTextField(6);
035
036        p = new JPanel();
037        p.setLayout(new FlowLayout());
038        p.add(new JLabel("Upper-right corner X, Y:"));
039        p.add(trXf);
040        p.add(trYf);
041        this.add(p);
042
043        p = new JPanel();
044        p.setLayout(new FlowLayout());
045        p.add(new JLabel("Lower-left corner X, Y:"));
046        p.add(blXf);
047        p.add(blYf);
048        this.add(p);
049
050        // set button
051        JButton set = new JButton("Set");
052        set.addActionListener(new ActionListener() {
053            @Override
054            public void actionPerformed(ActionEvent event) {
055                update();
056            }
057        });
058        this.add(set);
059    }
060
061    void set(double blX, double blY, double trX, double trY) {
062        trXf.setText("" + trX);
063        trYf.setText("" + trY);
064        blXf.setText("" + blX);
065        blYf.setText("" + blY);
066    }
067
068    public void update() {
069        trX = Double.parseDouble(trXf.getText());
070        trY = Double.parseDouble(trYf.getText());
071        blX = Double.parseDouble(blXf.getText());
072        blY = Double.parseDouble(blYf.getText());
073
074        panel.setOrigin(blX, blY);
075        panel.setCoordMax(trX, trY);
076        panel.repaint();
077    }
078
079    public JTextField trXf;
080    public JTextField trYf;
081    public JTextField blXf;
082    public JTextField blYf;
083    double trX, trY, blX, blY;
084
085}