001: package JSci.astro.telescope;
002:
003: import java.awt.*;
004: import java.awt.event.*;
005: import java.io.*;
006: import java.rmi.*;
007:
008: public final class LX200ControlPanel extends Panel implements Runnable {
009: private LX200Remote lx200;
010: private Thread statusThr = null;
011: private TextField raField = new TextField(8);
012: private TextField decField = new TextField(8);
013: private Button gotoButton = new Button("Goto");
014: private Button syncButton = new Button("Sync");
015: private Label raLabel = new Label();
016: private Label decLabel = new Label();
017: private Button inButton = new Button("+");
018: private Button outButton = new Button("-");
019: private Choice focusRateCombo = new Choice();
020: private Button northButton = new Button("N");
021: private Button eastButton = new Button("E");
022: private Button southButton = new Button("S");
023: private Button westButton = new Button("W");
024: private Choice slewRateCombo = new Choice();
025:
026: public static void main(String arg[]) {
027: if (arg.length != 1) {
028: System.out
029: .println("Usage: LX200ControlPanel rmi://<host>[:port]/<remote name>");
030: return;
031: }
032: Frame app = new Frame("LX200 Control Panel");
033: app.addWindowListener(new WindowAdapter() {
034: public void windowClosing(WindowEvent evt) {
035: System.exit(0);
036: }
037: });
038: app.add(new LX200ControlPanel(arg[0]));
039: app.setSize(100, 400);
040: app.setVisible(true);
041: }
042:
043: public LX200ControlPanel(String url) {
044: try {
045: lx200 = (LX200Remote) Naming.lookup(url);
046: } catch (Exception e) {
047: e.printStackTrace();
048: }
049: gotoButton.addActionListener(new GotoActionListener());
050: syncButton.addActionListener(new SyncActionListener());
051: inButton.addActionListener(new FocusActionListener(
052: LX200.FOCUS_IN));
053: outButton.addActionListener(new FocusActionListener(
054: LX200.FOCUS_OUT));
055: focusRateCombo.add("Fast");
056: focusRateCombo.add("Slow");
057: focusRateCombo.addItemListener(new FocusRateItemListener());
058: northButton.addActionListener(new SlewActionListener(
059: LX200.SLEW_NORTH));
060: eastButton.addActionListener(new SlewActionListener(
061: LX200.SLEW_EAST));
062: southButton.addActionListener(new SlewActionListener(
063: LX200.SLEW_SOUTH));
064: westButton.addActionListener(new SlewActionListener(
065: LX200.SLEW_WEST));
066: slewRateCombo.add("Slew");
067: slewRateCombo.add("Find");
068: slewRateCombo.add("Center");
069: slewRateCombo.add("Guide");
070: slewRateCombo.addItemListener(new SlewRateItemListener());
071: Panel radecPanel = new Panel();
072: radecPanel.add(raLabel);
073: radecPanel.add(decLabel);
074: radecPanel.add(raField);
075: radecPanel.add(decField);
076: radecPanel.add(gotoButton);
077: radecPanel.add(syncButton);
078: Panel focusPanel = new Panel();
079: focusPanel.setLayout(new GridLayout(3, 1));
080: focusPanel.add(inButton);
081: focusPanel.add(outButton);
082: focusPanel.add(focusRateCombo);
083: Panel slewPanel = new Panel();
084: GridBagConstraints gbc = new GridBagConstraints();
085: GridBagLayout gridbag = new GridBagLayout();
086: slewPanel.setLayout(gridbag);
087: gbc.fill = GridBagConstraints.BOTH;
088: gbc.gridx = 1;
089: gbc.gridy = 0;
090: gridbag.setConstraints(northButton, gbc);
091: slewPanel.add(northButton);
092: gbc.gridx = 0;
093: gbc.gridy = 1;
094: gridbag.setConstraints(westButton, gbc);
095: slewPanel.add(westButton);
096: gbc.gridx = 2;
097: gbc.gridy = 1;
098: gridbag.setConstraints(eastButton, gbc);
099: slewPanel.add(eastButton);
100: gbc.gridx = 1;
101: gbc.gridy = 2;
102: gridbag.setConstraints(southButton, gbc);
103: slewPanel.add(southButton);
104: gbc.gridx = 0;
105: gbc.gridy = 3;
106: gbc.gridwidth = GridBagConstraints.REMAINDER;
107: gridbag.setConstraints(slewRateCombo, gbc);
108: slewPanel.add(slewRateCombo);
109: add(radecPanel);
110: add(focusPanel);
111: add(slewPanel);
112: statusThr = new Thread(this );
113: statusThr.start();
114: }
115:
116: private class GotoActionListener implements ActionListener {
117: public void actionPerformed(ActionEvent evt) {
118: try {
119: lx200.setObjectCoords(raField.getText(), decField
120: .getText());
121: lx200.slewToObject();
122: } catch (IOException e) {
123: }
124: }
125: }
126:
127: private class SyncActionListener implements ActionListener {
128: public void actionPerformed(ActionEvent evt) {
129: try {
130: lx200.setObjectCoords(raField.getText(), decField
131: .getText());
132: lx200.syncCoords();
133: } catch (IOException e) {
134: }
135: }
136: }
137:
138: private class FocusActionListener implements ActionListener {
139: private final int direction;
140: private boolean focusing = false;
141:
142: public FocusActionListener(int dir) {
143: direction = dir;
144: }
145:
146: public void actionPerformed(ActionEvent evt) {
147: if (focusing) {
148: try {
149: lx200.stopFocus();
150: } catch (IOException e) {
151: }
152: focusing = false;
153: } else {
154: try {
155: lx200.startFocus(direction);
156: } catch (IOException e) {
157: }
158: focusing = true;
159: }
160: }
161: }
162:
163: private class FocusRateItemListener implements ItemListener {
164: public void itemStateChanged(ItemEvent evt) {
165: try {
166: lx200
167: .setFocusRate(focusRateCombo.getSelectedIndex() + 1);
168: } catch (IOException e) {
169: }
170: }
171: }
172:
173: private class SlewActionListener implements ActionListener {
174: private final int direction;
175: private boolean slewing = false;
176:
177: public SlewActionListener(int dir) {
178: direction = dir;
179: }
180:
181: public void actionPerformed(ActionEvent evt) {
182: if (slewing) {
183: try {
184: lx200.stopSlew(direction);
185: } catch (IOException e) {
186: }
187: slewing = false;
188: } else {
189: try {
190: lx200.startSlew(direction);
191: } catch (IOException e) {
192: }
193: slewing = true;
194: }
195: }
196: }
197:
198: private class SlewRateItemListener implements ItemListener {
199: public void itemStateChanged(ItemEvent evt) {
200: try {
201: lx200.setSlewRate(slewRateCombo.getSelectedIndex() + 1);
202: } catch (IOException e) {
203: }
204: }
205: }
206:
207: public void run() {
208: while (statusThr == Thread.currentThread()) {
209: try {
210: raLabel.setText("RA: " + lx200.getRA());
211: decLabel.setText("Dec: " + lx200.getDec());
212: } catch (IOException e) {
213: }
214: try {
215: Thread.sleep(2000);
216: } catch (InterruptedException e) {
217: }
218: }
219: }
220: }
|