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 no_data() {
105 JOptionPane.showMessageDialog(this,
108 JOptionPane.INFORMATION_MESSAGE);
110 private void Save() {
115 MicroSave save = new MicroSave (this, data);
116 if (save.runDialog())
120 private void Export() {
125 MicroExport export = new MicroExport (this, data);
129 private void Close() {
133 if (number_of_windows == 0)
137 public void actionPerformed(ActionEvent ev) {
138 if ("Exit".equals(ev.getActionCommand()))
140 else if ("Close".equals(ev.getActionCommand()))
142 else if ("Open".equals(ev.getActionCommand()))
144 else if ("Download".equals(ev.getActionCommand()))
146 else if ("Export".equals(ev.getActionCommand()))
148 else if ("Preferences".equals(ev.getActionCommand()))
150 else if ("Save a Copy".equals(ev.getActionCommand()))
154 public void itemStateChanged(ItemEvent e) {
161 AltosUIPreferences.set_component(this);
163 container = getContentPane();
164 pane = new JTabbedPane();
166 setTitle("MicroPeak");
168 JMenuBar menuBar = new JMenuBar();
169 setJMenuBar(menuBar);
171 JMenu fileMenu = new JMenu("File");
172 menuBar.add(fileMenu);
174 JMenuItem openAction = new JMenuItem("Open");
175 fileMenu.add(openAction);
176 openAction.addActionListener(this);
178 JMenuItem downloadAction = new JMenuItem("Download");
179 fileMenu.add(downloadAction);
180 downloadAction.addActionListener(this);
182 JMenuItem saveAction = new JMenuItem("Save a Copy");
183 fileMenu.add(saveAction);
184 saveAction.addActionListener(this);
186 JMenuItem exportAction = new JMenuItem("Export");
187 fileMenu.add(exportAction);
188 exportAction.addActionListener(this);
190 JMenuItem preferencesAction = new JMenuItem("Preferences");
191 fileMenu.add(preferencesAction);
192 preferencesAction.addActionListener(this);
194 JMenuItem closeAction = new JMenuItem("Close");
195 fileMenu.add(closeAction);
196 closeAction.addActionListener(this);
198 JMenuItem exitAction = new JMenuItem("Exit");
199 fileMenu.add(exitAction);
200 exitAction.addActionListener(this);
202 setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
203 addWindowListener(new WindowAdapter() {
205 public void windowClosing(WindowEvent e) {
210 graph = new MicroGraph();
211 stats = new MicroStatsTable();
212 pane.add(graph.panel, "Graph");
213 pane.add(stats, "Statistics");
217 container.doLayout();
218 container.validate();
221 Insets i = getInsets();
222 Dimension ps = pane.getPreferredSize();
223 ps.width += i.left + i.right;
224 ps.height += i.top + i.bottom;
225 // setPreferredSize(ps);
227 setLocationByPlatform(true);
231 public static void main(final String[] args) {
232 boolean opened = false;
235 UIManager.setLookAndFeel(AltosUIPreferences.look_and_feel());
236 } catch (Exception e) {
239 for (int i = 0; i < args.length; i++) {
240 MicroPeak m = new MicroPeak();
241 m.OpenFile(new File(args[i]));