1 package JSci.astro.telescope; 2 3 import java.awt.*; 4 import java.awt.event.*; 5 import java.io.*; 6 import java.rmi.*; 7 8 public final class LX200ControlPanel extends Panel implements Runnable { 9 private LX200Remote lx200; 10 private Thread statusThr=null; 11 private TextField raField=new TextField(8); 12 private TextField decField=new TextField(8); 13 private Button gotoButton=new Button("Goto"); 14 private Button syncButton=new Button("Sync"); 15 private Label raLabel=new Label(); 16 private Label decLabel=new Label(); 17 private Button inButton=new Button("+"); 18 private Button outButton=new Button("-"); 19 private Choice focusRateCombo=new Choice(); 20 private Button northButton=new Button("N"); 21 private Button eastButton=new Button("E"); 22 private Button southButton=new Button("S"); 23 private Button westButton=new Button("W"); 24 private Choice slewRateCombo=new Choice(); 25 26 public static void main(String arg[]) { 27 if(arg.length!=1) { 28 System.out.println("Usage: LX200ControlPanel rmi://<host>[:port]/<remote name>"); 29 return; 30 } 31 Frame app=new Frame("LX200 Control Panel"); 32 app.addWindowListener(new WindowAdapter() { 33 public void windowClosing(WindowEvent evt) { 34 System.exit(0); 35 } 36 }); 37 app.add(new LX200ControlPanel(arg[0])); 38 app.setSize(100,400); 39 app.setVisible(true); 40 } 41 public LX200ControlPanel(String url) { 42 try { 43 lx200=(LX200Remote)Naming.lookup(url); 44 } catch(Exception e) { 45 e.printStackTrace(); 46 } 47 gotoButton.addActionListener(new GotoActionListener()); 48 syncButton.addActionListener(new SyncActionListener()); 49 inButton.addActionListener(new FocusActionListener(LX200.FOCUS_IN)); 50 outButton.addActionListener(new FocusActionListener(LX200.FOCUS_OUT)); 51 focusRateCombo.add("Fast"); 52 focusRateCombo.add("Slow"); 53 focusRateCombo.addItemListener(new FocusRateItemListener()); 54 northButton.addActionListener(new SlewActionListener(LX200.SLEW_NORTH)); 55 eastButton.addActionListener(new SlewActionListener(LX200.SLEW_EAST)); 56 southButton.addActionListener(new SlewActionListener(LX200.SLEW_SOUTH)); 57 westButton.addActionListener(new SlewActionListener(LX200.SLEW_WEST)); 58 slewRateCombo.add("Slew"); 59 slewRateCombo.add("Find"); 60 slewRateCombo.add("Center"); 61 slewRateCombo.add("Guide"); 62 slewRateCombo.addItemListener(new SlewRateItemListener()); 63 Panel radecPanel=new Panel(); 64 radecPanel.add(raLabel); 65 radecPanel.add(decLabel); 66 radecPanel.add(raField); 67 radecPanel.add(decField); 68 radecPanel.add(gotoButton); 69 radecPanel.add(syncButton); 70 Panel focusPanel=new Panel(); 71 focusPanel.setLayout(new GridLayout(3,1)); 72 focusPanel.add(inButton); 73 focusPanel.add(outButton); 74 focusPanel.add(focusRateCombo); 75 Panel slewPanel=new Panel(); 76 GridBagConstraints gbc=new GridBagConstraints(); 77 GridBagLayout gridbag=new GridBagLayout(); 78 slewPanel.setLayout(gridbag); 79 gbc.fill=GridBagConstraints.BOTH; 80 gbc.gridx=1;gbc.gridy=0; 81 gridbag.setConstraints(northButton,gbc); 82 slewPanel.add(northButton); 83 gbc.gridx=0;gbc.gridy=1; 84 gridbag.setConstraints(westButton,gbc); 85 slewPanel.add(westButton); 86 gbc.gridx=2;gbc.gridy=1; 87 gridbag.setConstraints(eastButton,gbc); 88 slewPanel.add(eastButton); 89 gbc.gridx=1;gbc.gridy=2; 90 gridbag.setConstraints(southButton,gbc); 91 slewPanel.add(southButton); 92 gbc.gridx=0;gbc.gridy=3; 93 gbc.gridwidth=GridBagConstraints.REMAINDER; 94 gridbag.setConstraints(slewRateCombo,gbc); 95 slewPanel.add(slewRateCombo); 96 add(radecPanel); 97 add(focusPanel); 98 add(slewPanel); 99 statusThr=new Thread (this); 100 statusThr.start(); 101 } 102 private class GotoActionListener implements ActionListener { 103 public void actionPerformed(ActionEvent evt) { 104 try { 105 lx200.setObjectCoords(raField.getText(),decField.getText()); 106 lx200.slewToObject(); 107 } catch(IOException e) {} 108 } 109 } 110 private class SyncActionListener implements ActionListener { 111 public void actionPerformed(ActionEvent evt) { 112 try { 113 lx200.setObjectCoords(raField.getText(),decField.getText()); 114 lx200.syncCoords(); 115 } catch(IOException e) {} 116 } 117 } 118 private class FocusActionListener implements ActionListener { 119 private final int direction; 120 private boolean focusing=false; 121 public FocusActionListener(int dir) { 122 direction=dir; 123 } 124 public void actionPerformed(ActionEvent evt) { 125 if(focusing) { 126 try { 127 lx200.stopFocus(); 128 } catch(IOException e) {} 129 focusing=false; 130 } else { 131 try { 132 lx200.startFocus(direction); 133 } catch(IOException e) {} 134 focusing=true; 135 } 136 } 137 } 138 private class FocusRateItemListener implements ItemListener { 139 public void itemStateChanged(ItemEvent evt) { 140 try { 141 lx200.setFocusRate(focusRateCombo.getSelectedIndex()+1); 142 } catch(IOException e) {} 143 } 144 } 145 private class SlewActionListener implements ActionListener { 146 private final int direction; 147 private boolean slewing=false; 148 public SlewActionListener(int dir) { 149 direction=dir; 150 } 151 public void actionPerformed(ActionEvent evt) { 152 if(slewing) { 153 try { 154 lx200.stopSlew(direction); 155 } catch(IOException e) {} 156 slewing=false; 157 } else { 158 try { 159 lx200.startSlew(direction); 160 } catch(IOException e) {} 161 slewing=true; 162 } 163 } 164 } 165 private class SlewRateItemListener implements ItemListener { 166 public void itemStateChanged(ItemEvent evt) { 167 try { 168 lx200.setSlewRate(slewRateCombo.getSelectedIndex()+1); 169 } catch(IOException e) {} 170 } 171 } 172 public void run() { 173 while(statusThr==Thread.currentThread()) { 174 try { 175 raLabel.setText("RA: "+lx200.getRA()); 176 decLabel.setText("Dec: "+lx200.getDec()); 177 } catch(IOException e) {} 178 try { 179 Thread.sleep(2000); 180 } catch(InterruptedException e) {} 181 } 182 } 183 } 184 185 | Popular Tags |