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 AltosUIConfigure(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 private void Close() {
121 if (number_of_windows == 0)
125 public void actionPerformed(ActionEvent ev) {
126 if ("Exit".equals(ev.getActionCommand()))
128 else if ("Close".equals(ev.getActionCommand()))
130 else if ("Open".equals(ev.getActionCommand()))
132 else if ("Download".equals(ev.getActionCommand()))
134 else if ("Preferences".equals(ev.getActionCommand()))
136 else if ("Save a Copy".equals(ev.getActionCommand()))
140 public void itemStateChanged(ItemEvent e) {
147 AltosUIPreferences.set_component(this);
149 container = getContentPane();
150 pane = new JTabbedPane();
152 setTitle("MicroPeak");
154 JMenuBar menuBar = new JMenuBar();
155 setJMenuBar(menuBar);
157 JMenu fileMenu = new JMenu("File");
158 menuBar.add(fileMenu);
160 JMenuItem openAction = new JMenuItem("Open");
161 fileMenu.add(openAction);
162 openAction.addActionListener(this);
164 JMenuItem downloadAction = new JMenuItem("Download");
165 fileMenu.add(downloadAction);
166 downloadAction.addActionListener(this);
168 JMenuItem saveAction = new JMenuItem("Save a Copy");
169 fileMenu.add(saveAction);
170 saveAction.addActionListener(this);
172 JMenuItem preferencesAction = new JMenuItem("Preferences");
173 fileMenu.add(preferencesAction);
174 preferencesAction.addActionListener(this);
176 JMenuItem closeAction = new JMenuItem("Close");
177 fileMenu.add(closeAction);
178 closeAction.addActionListener(this);
180 JMenuItem exitAction = new JMenuItem("Exit");
181 fileMenu.add(exitAction);
182 exitAction.addActionListener(this);
184 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
185 addWindowListener(new WindowAdapter() {
187 public void windowClosing(WindowEvent e) {
192 graph = new MicroGraph();
193 stats = new MicroStatsTable();
194 pane.add(graph.panel, "Graph");
195 pane.add(stats, "Statistics");
199 container.doLayout();
200 container.validate();
203 Insets i = getInsets();
204 Dimension ps = pane.getPreferredSize();
205 ps.width += i.left + i.right;
206 ps.height += i.top + i.bottom;
207 // setPreferredSize(ps);
209 setLocationByPlatform(true);
213 public static void main(final String[] args) {
214 boolean opened = false;
217 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
218 } catch (Exception e) {
221 for (int i = 0; i < args.length; i++) {
222 MicroPeak m = new MicroPeak();
223 m.OpenFile(new File(args[i]));