2 * Console - modular Amateur Radio console for clusters and converse.
4 * @version 1.00 - 20010418.
6 * Copyright (C) 2001 Ian Norton.
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public Licence as published by
10 * the Free Software Foundation; either version 2 of the Licence, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public Licence for more details.
18 * You should have received a copy of the GNU General Public Licence
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
22 * Contacting the author :
24 * i.norton@lancaster.ac.uk
25 * http://www.lancs.ac.uk/~norton/
30 import java.awt.event.*;
36 private JFrame frame ;
37 private JPanel buttonpanel ;
38 private JTabbedPane tabbedpane ;
41 public static final int WIDTH = 620 ;
42 public static final int HEIGHT = 350 ;
43 public static final String VERSION = "1.0" ;
44 public static final String INFO = "RadioConsole Version " + VERSION +
45 "\nWritten By Ian Norton (M0AZM)\n" +
46 "i.norton@lancaster.ac.uk" ;
49 private PipedInputMUX inmux ;
50 private PipedOutputMUX outmux ;
52 // Vector to store plugins
53 private Vector plugins ;
55 private int plugnumber ;
58 private Connection connection ;
60 // Host that we connected to (May include port number).
66 public static void main(String[] args)
69 Console c = new Console("DX Cluster Console " + VERSION) ;
73 * Console init method.
76 public Console(String s)
78 // Default host and port to connect to.
79 host = "127.0.0.1:27754" ;
81 // Initialise the frame for the whole thing.
82 frame = new JFrame(s) ;
84 // Build connection here.
85 PipedInputStream pincon = new PipedInputStream() ;
86 PipedOutputStream poscon = new PipedOutputStream() ;
87 connection = new Connection(pincon, poscon, this) ;
89 // Build protocol here.
91 PipedInputStream pinprot ;
92 PipedOutputStream posprot ;
95 pinprot = new PipedInputStream(poscon) ;
96 posprot = new PipedOutputStream(pincon) ;
97 Protocol protocol = new Protocol(pinprot, posprot, this) ;
101 System.out.println("Console: IOException creating protocol.") ;
106 // Build input/output MUX's here.
107 PipedInputStream pinmux ;
108 PipedOutputStream posmux ;
113 pinmux = new PipedInputStream(poscon) ;
114 posmux = new PipedOutputStream(pincon) ;
116 // Initialise the MUX's
117 inmux = new PipedInputMUX(posmux) ;
118 outmux = new PipedOutputMUX(pinmux) ;
120 catch(IOException ex)
122 System.out.println("Console: IOException creating MUXes.") ;
123 System.out.println(ex) ;
127 // Initialise the plugin stuff.
128 plugins = new Vector() ;
131 // Build tabbed panes from the plugins.
137 // Build the button bar.
140 // Add action listener to close the window.
141 frame.addWindowListener(new WindowAdapter() {
142 public void windowClosing(WindowEvent e) {
147 frame.setSize(WIDTH, HEIGHT) ;
149 frame.getContentPane().add(tabbedpane, BorderLayout.CENTER);
152 // Pop a connection dialog or use saved hostname or something here.
153 connection.connect(host) ;
157 * buildTabs - build the tabbed panes with the plugins.
159 public void buildTabs()
161 tabbedpane = new JTabbedPane() ;
162 tabbedpane.setTabPlacement(JTabbedPane.BOTTOM);
164 // The first plugin should always be the cluster plugin.
165 // addPlugin("Cluster") ;
166 addPlugin("SpiderCluster") ;
168 // Call insert plugins method here. **AZM**
173 * buildMenus - build the Menus with the plugins.
175 public void buildMenus()
177 // Create a menu bar and add it to the frame.
178 JMenuBar mbar = new JMenuBar() ;
179 frame.setJMenuBar(mbar) ;
181 // Create the file menu stuff.
182 JMenu filemenu = new JMenu("File") ;
185 filemenu.add(item = new JMenuItem("Connect")) ;
186 item.setMnemonic(KeyEvent.VK_C) ;
187 item.setAccelerator(KeyStroke.getKeyStroke(
188 KeyEvent.VK_C, ActionEvent.ALT_MASK));
189 item.addActionListener(new ActionListener() {
190 public void actionPerformed(ActionEvent e) {
191 connection.connect(host);
194 filemenu.add(item = new JMenuItem("Connect To")) ;
195 // item.setMnemonic(KeyEvent.VK_C) ;
196 // item.setAccelerator(KeyStroke.getKeyStroke(
197 // KeyEvent.VK_C, ActionEvent.ALT_MASK));
198 item.addActionListener(new ActionListener() {
199 public void actionPerformed(ActionEvent e) {
200 // Connection dialog.
201 String ho = JOptionPane.showInputDialog("Enter the host to connect to") ;
202 if(ho == null || ho.indexOf(" ") > -1)
205 if(ho != null && ho.length() > 0)
207 // connection.disconnect() ;
208 connection.connect(ho);
212 filemenu.add(item = new JMenuItem("Disconnect")) ;
213 item.addActionListener(new ActionListener() {
214 public void actionPerformed(ActionEvent e)
215 { connection.disconnect() ; }});
217 filemenu.add(item = new JMenuItem("About")) ;
218 item.addActionListener(new ActionListener() {
219 public void actionPerformed(ActionEvent e)
220 { JOptionPane.showMessageDialog(frame, INFO) ; }});
222 filemenu.addSeparator() ;
224 filemenu.add(item = new JMenuItem("Quit")) ;
225 item.addActionListener(new ActionListener() { // Quit.
226 public void actionPerformed(ActionEvent e) { System.exit(0) ; }});
228 // Add the menus onto the menu bar.
233 * buildToolbar - build the Toolbar with the plugins.
235 public void buildToolbar()
242 * @param String - name of the plugin to insert.
244 private void addPlugin(String p)
250 Class c = Class.forName(p) ;
251 pl = (Plugin)c.newInstance();
253 catch(ClassNotFoundException ex)
255 System.out.println("Exceptional!\n"+ex) ;
257 catch(InstantiationException ex)
259 System.out.println("Exceptional!\n"+ex) ;
261 catch(IllegalAccessException ex)
263 System.out.println("Exceptional!\n"+ex) ;
266 PipedOutputStream plugoutstr = new PipedOutputStream() ;
267 PipedInputStream pluginstr = new PipedInputStream() ;
269 // Insert the object into the vector.
270 plugins.addElement(pl) ;
272 // Add the plug in to the tabbedpane.
273 tabbedpane.addTab(pl.getTabName(), null, pl, pl.getTabTip()) ;
275 PipedInputStream pinmux = null ;
276 PipedOutputStream posmux = null ;
280 pinmux = new PipedInputStream(plugoutstr) ;
281 posmux = new PipedOutputStream(pluginstr) ;
283 catch(IOException ex)
285 System.out.println("Console: IOException creating plugin pipes.") ;
286 System.out.println(ex) ;
289 // Add the streams to the multiplexors.
290 inmux.addInputStream(pinmux) ;
291 outmux.addOutputStream(posmux) ;
293 // Initialise the plugin.
294 pl.init(pluginstr, plugoutstr) ;