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 static int number_of_windows;
40 MicroPeak SetData(MicroData data) {
42 if (this.data != null) {
44 return mp.SetData(data);
54 void SetName(String name) {
59 private void RunFile(InputStream input, String name) {
61 MicroData data = new MicroData(input, name);
63 } catch (IOException ioe) {
64 JOptionPane.showMessageDialog(this,
67 JOptionPane.ERROR_MESSAGE);
68 } catch (InterruptedException ie) {
72 } catch (IOException ioe) {
76 private void OpenFile(File filename) {
78 RunFile (new FileInputStream(filename), filename.getName());
79 } catch (FileNotFoundException fne) {
80 JOptionPane.showMessageDialog(this,
83 JOptionPane.ERROR_MESSAGE);
87 private void SelectFile() {
88 MicroFileChooser chooser = new MicroFileChooser(this);
89 InputStream input = chooser.runDialog();
92 RunFile(input, chooser.filename);
95 private void Preferences() {
96 new AltosUIConfigure(this);
99 private void DownloadData() {
100 AltosDevice device = MicroDeviceDialog.show(this);
103 new MicroDownload(this, device);
106 private void no_data() {
107 JOptionPane.showMessageDialog(this,
110 JOptionPane.INFORMATION_MESSAGE);
112 private void Save() {
117 MicroSave save = new MicroSave (this, data);
118 if (save.runDialog())
122 private void Export() {
127 MicroExport export = new MicroExport (this, data);
131 private void Close() {
135 if (number_of_windows == 0)
139 public void actionPerformed(ActionEvent ev) {
140 if ("Exit".equals(ev.getActionCommand()))
142 else if ("Close".equals(ev.getActionCommand()))
144 else if ("Open".equals(ev.getActionCommand()))
146 else if ("Download".equals(ev.getActionCommand()))
148 else if ("Export".equals(ev.getActionCommand()))
150 else if ("Preferences".equals(ev.getActionCommand()))
152 else if ("Save a Copy".equals(ev.getActionCommand()))
156 public void itemStateChanged(ItemEvent e) {
163 AltosUIPreferences.set_component(this);
165 container = getContentPane();
166 pane = new JTabbedPane();
168 setTitle("MicroPeak");
170 JMenuBar menuBar = new JMenuBar();
171 setJMenuBar(menuBar);
173 JMenu fileMenu = new JMenu("File");
174 menuBar.add(fileMenu);
176 JMenuItem openAction = new JMenuItem("Open");
177 fileMenu.add(openAction);
178 openAction.addActionListener(this);
180 JMenuItem downloadAction = new JMenuItem("Download");
181 fileMenu.add(downloadAction);
182 downloadAction.addActionListener(this);
184 JMenuItem saveAction = new JMenuItem("Save a Copy");
185 fileMenu.add(saveAction);
186 saveAction.addActionListener(this);
188 JMenuItem exportAction = new JMenuItem("Export");
189 fileMenu.add(exportAction);
190 exportAction.addActionListener(this);
192 JMenuItem preferencesAction = new JMenuItem("Preferences");
193 fileMenu.add(preferencesAction);
194 preferencesAction.addActionListener(this);
196 JMenuItem closeAction = new JMenuItem("Close");
197 fileMenu.add(closeAction);
198 closeAction.addActionListener(this);
200 JMenuItem exitAction = new JMenuItem("Exit");
201 fileMenu.add(exitAction);
202 exitAction.addActionListener(this);
204 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
205 addWindowListener(new WindowAdapter() {
207 public void windowClosing(WindowEvent e) {
212 graph = new MicroGraph();
213 stats = new MicroStatsTable();
214 raw = new MicroRaw();
215 pane.add(graph.panel, "Graph");
216 pane.add(stats, "Statistics");
217 JScrollPane scroll = new JScrollPane(raw);
218 pane.add(scroll, "Raw Data");
222 container.doLayout();
223 container.validate();
226 Insets i = getInsets();
227 Dimension ps = pane.getPreferredSize();
228 ps.width += i.left + i.right;
229 ps.height += i.top + i.bottom;
230 // setPreferredSize(ps);
232 setLocationByPlatform(true);
236 public static void main(final String[] args) {
237 boolean opened = false;
240 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
241 } catch (Exception e) {
244 for (int i = 0; i < args.length; i++) {
245 MicroPeak m = new MicroPeak();
246 m.OpenFile(new File(args[i]));