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;
37 static int number_of_windows;
39 MicroPeak SetData(MicroData data) {
41 if (this.data != null) {
43 return mp.SetData(data);
52 void SetName(String name) {
57 private void RunFile(InputStream input, String name) {
59 MicroData data = new MicroData(input, name);
61 } catch (IOException ioe) {
62 JOptionPane.showMessageDialog(this,
65 JOptionPane.ERROR_MESSAGE);
66 } catch (InterruptedException ie) {
70 } catch (IOException ioe) {
74 private void OpenFile(File filename) {
76 RunFile (new FileInputStream(filename), filename.getName());
77 } catch (FileNotFoundException fne) {
78 JOptionPane.showMessageDialog(this,
81 JOptionPane.ERROR_MESSAGE);
85 private void SelectFile() {
86 MicroFileChooser chooser = new MicroFileChooser(this);
87 InputStream input = chooser.runDialog();
90 RunFile(input, chooser.filename);
93 private void Preferences() {
94 new AltosConfigureUI(this);
97 private void DownloadData() {
98 AltosDevice device = MicroDeviceDialog.show(this);
101 new MicroDownload(this, device);
104 private void Save() {
106 JOptionPane.showMessageDialog(this,
109 JOptionPane.INFORMATION_MESSAGE);
112 MicroSave save = new MicroSave (this, data);
113 if (save.runDialog())
117 public void actionPerformed(ActionEvent ev) {
118 if ("Exit".equals(ev.getActionCommand()))
120 else if ("Open".equals(ev.getActionCommand()))
122 else if ("Download".equals(ev.getActionCommand()))
124 else if ("Preferences".equals(ev.getActionCommand()))
126 else if ("Save a Copy".equals(ev.getActionCommand()))
130 public void itemStateChanged(ItemEvent e) {
137 AltosUIPreferences.set_component(this);
139 container = getContentPane();
140 pane = new JTabbedPane();
142 setTitle("MicroPeak");
144 JMenuBar menuBar = new JMenuBar();
145 setJMenuBar(menuBar);
147 JMenu fileMenu = new JMenu("File");
148 menuBar.add(fileMenu);
150 JMenuItem openAction = new JMenuItem("Open");
151 fileMenu.add(openAction);
152 openAction.addActionListener(this);
154 JMenuItem downloadAction = new JMenuItem("Download");
155 fileMenu.add(downloadAction);
156 downloadAction.addActionListener(this);
158 JMenuItem saveAction = new JMenuItem("Save a Copy");
159 fileMenu.add(saveAction);
160 saveAction.addActionListener(this);
162 JMenuItem preferencesAction = new JMenuItem("Preferences");
163 fileMenu.add(preferencesAction);
164 preferencesAction.addActionListener(this);
166 JMenuItem exitAction = new JMenuItem("Exit");
167 fileMenu.add(exitAction);
168 exitAction.addActionListener(this);
170 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
171 addWindowListener(new WindowAdapter() {
173 public void windowClosing(WindowEvent e) {
177 if (number_of_windows == 0)
182 graph = new MicroGraph();
183 stats = new MicroStatsTable();
184 pane.add(graph.panel, "Graph");
185 pane.add(stats, "Statistics");
189 container.doLayout();
190 container.validate();
193 Insets i = getInsets();
194 Dimension ps = pane.getPreferredSize();
195 ps.width += i.left + i.right;
196 ps.height += i.top + i.bottom;
197 setPreferredSize(ps);
202 public static void main(final String[] args) {
203 boolean opened = false;
206 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
207 } catch (Exception e) {
210 for (int i = 0; i < args.length; i++) {
211 MicroPeak m = new MicroPeak();
212 m.OpenFile(new File(args[i]));