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 OpenFile(File filename) {
37 FileInputStream input = new FileInputStream(filename);
39 data = new MicroData(input);
40 graph = new MicroGraph(data);
41 pane.add(graph.panel);
42 } catch (IOException ioe) {
46 } catch (IOException ioe) {
48 } catch (FileNotFoundException fne) {
52 private void SelectFile() {
55 private void DownloadData() {
56 java.util.List<MicroUSB> devices = MicroUSB.list();
57 for (MicroUSB device : devices)
58 System.out.printf("device %s\n", device.toString());
61 public void actionPerformed(ActionEvent ev) {
62 System.out.printf("action %s %s\n", ev.getActionCommand(), ev.paramString());
63 if ("Exit".equals(ev.getActionCommand()))
65 else if ("Open".equals(ev.getActionCommand()))
67 else if ("New".equals(ev.getActionCommand()))
69 else if ("Download".equals(ev.getActionCommand()))
73 public void itemStateChanged(ItemEvent e) {
76 public MicroPeak(File filename) {
78 this.filename = filename;
80 pane = getContentPane();
82 // JLabel label = new JLabel ("Hello, World");
87 setTitle("MicroPeak");
89 JMenuBar menuBar = new JMenuBar();
92 JMenu fileMenu = new JMenu("File");
93 menuBar.add(fileMenu);
95 JMenuItem newAction = new JMenuItem("New");
96 fileMenu.add(newAction);
97 newAction.addActionListener(this);
99 JMenuItem openAction = new JMenuItem("Open");
100 fileMenu.add(openAction);
101 openAction.addActionListener(this);
103 JMenuItem downloadAction = new JMenuItem("Download");
104 fileMenu.add(downloadAction);
105 downloadAction.addActionListener(this);
107 JMenuItem exitAction = new JMenuItem("Exit");
108 fileMenu.add(exitAction);
109 exitAction.addActionListener(this);
111 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
112 addWindowListener(new WindowAdapter() {
114 public void windowClosing(WindowEvent e) {
119 if (filename != null)
120 this.OpenFile(filename);
128 public static void main(final String[] args) {
129 boolean opened = false;
131 for (int i = 0; i < args.length; i++) {
132 new MicroPeak(new File(args[i]));