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 {
36 private void RunFile(InputStream input) {
38 data = new MicroData(input);
40 } catch (IOException ioe) {
44 } catch (IOException ioe) {
48 private void OpenFile(File filename) {
50 RunFile (new FileInputStream(filename));
51 } catch (FileNotFoundException fne) {
55 private void SelectFile() {
56 MicroFileChooser chooser = new MicroFileChooser(this);
57 InputStream input = chooser.runDialog();
63 private void Preferences() {
64 new AltosConfigureUI(this);
67 private void DownloadData() {
68 java.util.List<MicroUSB> devices = MicroUSB.list();
69 for (MicroUSB device : devices)
70 System.out.printf("device %s\n", device.toString());
73 public void actionPerformed(ActionEvent ev) {
74 if ("Exit".equals(ev.getActionCommand()))
76 else if ("Open".equals(ev.getActionCommand()))
78 else if ("New".equals(ev.getActionCommand()))
80 else if ("Download".equals(ev.getActionCommand()))
82 else if ("Preferences".equals(ev.getActionCommand()))
86 public void itemStateChanged(ItemEvent e) {
91 AltosUIPreferences.set_component(this);
93 pane = getContentPane();
95 setTitle("MicroPeak");
97 JMenuBar menuBar = new JMenuBar();
100 JMenu fileMenu = new JMenu("File");
101 menuBar.add(fileMenu);
103 JMenuItem newAction = new JMenuItem("New");
104 fileMenu.add(newAction);
105 newAction.addActionListener(this);
107 JMenuItem openAction = new JMenuItem("Open");
108 fileMenu.add(openAction);
109 openAction.addActionListener(this);
111 JMenuItem downloadAction = new JMenuItem("Download");
112 fileMenu.add(downloadAction);
113 downloadAction.addActionListener(this);
115 JMenuItem preferencesAction = new JMenuItem("Preferences");
116 fileMenu.add(preferencesAction);
117 preferencesAction.addActionListener(this);
119 JMenuItem exitAction = new JMenuItem("Exit");
120 fileMenu.add(exitAction);
121 exitAction.addActionListener(this);
123 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
124 addWindowListener(new WindowAdapter() {
126 public void windowClosing(WindowEvent e) {
131 graph = new MicroGraph();
132 pane.add(graph.panel);
137 Insets i = getInsets();
138 Dimension ps = pane.getPreferredSize();
139 ps.width += i.left + i.right;
140 ps.height += i.top + i.bottom;
141 setPreferredSize(ps);
146 public static void main(final String[] args) {
147 boolean opened = false;
150 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
151 } catch (Exception e) {
154 for (int i = 0; i < args.length; i++) {
155 MicroPeak m = new MicroPeak();
156 m.OpenFile(new File(args[i]));