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.*;
27 import org.altusmetrum.altosuilib.*;
29 public class MicroPeak extends MicroFrame implements ActionListener, ItemListener {
33 MicroStatsTable stats;
38 private void RunFile(InputStream input) {
40 data = new MicroData(input);
43 } catch (IOException ioe) {
47 } catch (IOException ioe) {
51 private void OpenFile(File filename) {
53 RunFile (new FileInputStream(filename));
54 } catch (FileNotFoundException fne) {
58 private void SelectFile() {
59 MicroFileChooser chooser = new MicroFileChooser(this);
60 InputStream input = chooser.runDialog();
66 private void Preferences() {
67 new AltosConfigureUI(this);
70 private void DownloadData() {
71 java.util.List<MicroUSB> devices = MicroUSB.list();
72 for (MicroUSB device : devices)
73 System.out.printf("device %s\n", device.toString());
76 public void actionPerformed(ActionEvent ev) {
77 if ("Exit".equals(ev.getActionCommand()))
79 else if ("Open".equals(ev.getActionCommand()))
81 else if ("New".equals(ev.getActionCommand()))
83 else if ("Download".equals(ev.getActionCommand()))
85 else if ("Preferences".equals(ev.getActionCommand()))
89 public void itemStateChanged(ItemEvent e) {
94 AltosUIPreferences.set_component(this);
96 container = getContentPane();
97 pane = new JTabbedPane();
99 setTitle("MicroPeak");
101 JMenuBar menuBar = new JMenuBar();
102 setJMenuBar(menuBar);
104 JMenu fileMenu = new JMenu("File");
105 menuBar.add(fileMenu);
107 JMenuItem newAction = new JMenuItem("New");
108 fileMenu.add(newAction);
109 newAction.addActionListener(this);
111 JMenuItem openAction = new JMenuItem("Open");
112 fileMenu.add(openAction);
113 openAction.addActionListener(this);
115 JMenuItem downloadAction = new JMenuItem("Download");
116 fileMenu.add(downloadAction);
117 downloadAction.addActionListener(this);
119 JMenuItem preferencesAction = new JMenuItem("Preferences");
120 fileMenu.add(preferencesAction);
121 preferencesAction.addActionListener(this);
123 JMenuItem exitAction = new JMenuItem("Exit");
124 fileMenu.add(exitAction);
125 exitAction.addActionListener(this);
127 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
128 addWindowListener(new WindowAdapter() {
130 public void windowClosing(WindowEvent e) {
135 graph = new MicroGraph();
136 stats = new MicroStatsTable();
137 pane.add(graph.panel, "Graph");
138 pane.add(stats, "Statistics");
142 container.doLayout();
143 container.validate();
146 Insets i = getInsets();
147 Dimension ps = pane.getPreferredSize();
148 ps.width += i.left + i.right;
149 ps.height += i.top + i.bottom;
150 setPreferredSize(ps);
155 public static void main(final String[] args) {
156 boolean opened = false;
159 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
160 } catch (Exception e) {
163 for (int i = 0; i < args.length; i++) {
164 MicroPeak m = new MicroPeak();
165 m.OpenFile(new File(args[i]));