2 * Copyright © 2012 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.micropeak;
21 import java.awt.event.*;
24 import java.util.concurrent.*;
26 import org.altusmetrum.AltosLib.*;
28 public class MicroPeak extends JFrame implements ActionListener, ItemListener {
35 private void RunFile(InputStream input) {
37 data = new MicroData(input);
39 } catch (IOException ioe) {
43 } catch (IOException ioe) {
47 private void OpenFile(File filename) {
49 RunFile (new FileInputStream(filename));
50 } catch (FileNotFoundException fne) {
54 private void SelectFile() {
55 MicroFileChooser chooser = new MicroFileChooser(this);
56 InputStream input = chooser.runDialog();
62 private void DownloadData() {
63 java.util.List<MicroUSB> devices = MicroUSB.list();
64 for (MicroUSB device : devices)
65 System.out.printf("device %s\n", device.toString());
68 public void actionPerformed(ActionEvent ev) {
69 System.out.printf("action %s %s\n", ev.getActionCommand(), ev.paramString());
70 if ("Exit".equals(ev.getActionCommand()))
72 else if ("Open".equals(ev.getActionCommand()))
74 else if ("New".equals(ev.getActionCommand()))
76 else if ("Download".equals(ev.getActionCommand()))
80 public void itemStateChanged(ItemEvent e) {
85 this.filename = filename;
87 pane = getContentPane();
89 setTitle("MicroPeak");
91 JMenuBar menuBar = new JMenuBar();
94 JMenu fileMenu = new JMenu("File");
95 menuBar.add(fileMenu);
97 JMenuItem newAction = new JMenuItem("New");
98 fileMenu.add(newAction);
99 newAction.addActionListener(this);
101 JMenuItem openAction = new JMenuItem("Open");
102 fileMenu.add(openAction);
103 openAction.addActionListener(this);
105 JMenuItem downloadAction = new JMenuItem("Download");
106 fileMenu.add(downloadAction);
107 downloadAction.addActionListener(this);
109 JMenuItem exitAction = new JMenuItem("Exit");
110 fileMenu.add(exitAction);
111 exitAction.addActionListener(this);
113 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
114 addWindowListener(new WindowAdapter() {
116 public void windowClosing(WindowEvent e) {
121 graph = new MicroGraph(data);
122 pane.add(graph.panel);
127 Insets i = getInsets();
128 Dimension ps = pane.getPreferredSize();
129 ps.width += i.left + i.right;
130 ps.height += i.top + i.bottom;
131 setPreferredSize(ps);
136 public static void main(final String[] args) {
137 boolean opened = false;
139 for (int i = 0; i < args.length; i++) {
140 MicroPeak m = new MicroPeak();
141 m.OpenFile(new File(args[i]));