00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 package ikayaki.gui;
00024
00025 import ikayaki.Ikayaki;
00026 import ikayaki.Project;
00027 import ikayaki.ProjectEvent;
00028 import ikayaki.Settings;
00029 import ikayaki.squid.SerialIO;
00030 import ikayaki.squid.Squid;
00031
00032 import javax.swing.*;
00033 import java.awt.*;
00034 import java.awt.event.ActionEvent;
00035 import java.awt.event.ActionListener;
00036 import java.awt.event.KeyEvent;
00037 import java.io.BufferedInputStream;
00038 import java.io.File;
00039 import java.io.IOException;
00040
00047 public class MainViewPanel extends ProjectComponent {
00048
00049 private static final int DIVIDER_DEFAULT_LOCATION = 300;
00050 private static final int DIVIDER_SIZE = 5;
00051
00055 private Squid squid;
00056
00060 private Project project = null;
00061
00065 private Project latestMeasuringProject = null;
00066
00067
00068 private MainMenuBar menuBar;
00069 private MainStatusBar statusBar;
00070
00071 private JSplitPane splitPane;
00072 private ProjectExplorerPanel projectExplorerPanel;
00073 private CalibrationPanel calibrationPanel;
00074
00075 private ProjectInformationPanel projectInformationPanel;
00076 private MeasurementSequencePanel measurementSequencePanel;
00077 private MeasurementControlsPanel measurementControlsPanel;
00078 private MeasurementDetailsPanel measurementDetailsPanel;
00079 private MeasurementGraphsPanel measurementGraphsPanel;
00080
00081
00082 private Action newProjectAction;
00083 private Action openProjectAction;
00084 private Action exportProjectToDATAction;
00085 private Action exportProjectToDTDAction;
00086 private Action exportProjectToSRMAction;
00087 private Action printAction;
00088 private Action printPreviewAction;
00089 private Action exitAction;
00090 private Action programSettingsAction;
00091 private Action deviceSettingsAction;
00092 private Action helpAction;
00093 private Action aboutAction;
00094
00101 public MainViewPanel(Project project) {
00102
00103
00104 if (project == null) {
00105 File[] projectHistory = Settings.getProjectHistory();
00106 if (projectHistory.length > 0) {
00107 project = Project.loadProject(projectHistory[0]);
00108 }
00109 }
00110
00111
00112 new Thread() {
00113 @Override public void run() {
00114 try {
00115 final Squid squid = Squid.instance();
00116 if (!squid.isOK()) {
00117 JOptionPane.showMessageDialog(getParentFrame(),
00118 "SQUID is not OK!", "Squid error", JOptionPane.ERROR_MESSAGE);
00119 return;
00120 }
00121 SwingUtilities.invokeLater(new Runnable() {
00122 public void run() {
00123 setSquid(squid);
00124 }
00125 });
00126
00127 } catch (IOException e) {
00128
00129
00130 System.err.println("Unable to initialize the SQUID interface.");
00131 }
00132 }
00133 }.start();
00134
00135
00136 final JPanel left = new JPanel(new GridBagLayout());
00137 final JPanel right = new JPanel(new GridBagLayout());
00138 GridBagConstraints gc = new GridBagConstraints();
00139 gc.fill = GridBagConstraints.BOTH;
00140
00141
00142 gc.gridx = 0;
00143 gc.gridy = 0;
00144 gc.weightx = 1.0;
00145 gc.weighty = 0.0;
00146 left.add(getCalibrationPanel(), gc);
00147 gc.gridx = 0;
00148 gc.gridy = 1;
00149 gc.weightx = 1.0;
00150 gc.weighty = 1.0;
00151 left.add(getProjectExplorerPanel(), gc);
00152 gc.gridx = 0;
00153 gc.gridy = 2;
00154 gc.weightx = 1.0;
00155 gc.weighty = 0.0;
00156 left.add(getProjectInformationPanel(), gc);
00157
00158
00159 gc.gridx = 0;
00160 gc.gridy = 0;
00161 gc.weightx = 1.0;
00162 gc.weighty = 1.0;
00163 right.add(getMeasurementSequencePanel(), gc);
00164 gc.gridx = 1;
00165 gc.gridy = 0;
00166 gc.weightx = 0.0;
00167 gc.weighty = 1.0;
00168 right.add(getMeasurementControlsPanel(), gc);
00169 if (false) {
00170 gc.gridx = 0;
00171 gc.gridy = 1;
00172 gc.weightx = 1.0;
00173 gc.weighty = 0.0;
00174 right.add(getMeasurementDetailsPanel(), gc);
00175 gc.gridx = 1;
00176 gc.gridy = 1;
00177 gc.weightx = 0.0;
00178 gc.weighty = 0.0;
00179 right.add(getMeasurementGraphsPanel(), gc);
00180 } else {
00181
00182 JPanel bottom = new JPanel(new BorderLayout());
00183 bottom.add(getMeasurementDetailsPanel(), BorderLayout.WEST);
00184 bottom.add(getMeasurementGraphsPanel(), BorderLayout.CENTER);
00185 gc.gridx = 0;
00186 gc.gridy = 1;
00187 gc.gridwidth = 2;
00188 gc.weightx = 1.0;
00189 gc.weighty = 0.0;
00190 right.add(bottom, gc);
00191 }
00192
00193
00194 splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
00195 splitPane.setLeftComponent(left);
00196 splitPane.setRightComponent(right);
00197
00198 splitPane.setContinuousLayout(true);
00199
00200 splitPane.setDividerLocation(DIVIDER_DEFAULT_LOCATION);
00201 splitPane.setResizeWeight(0.0);
00202
00203 splitPane.setBorder(null);
00204 splitPane.setDividerSize(DIVIDER_SIZE);
00205
00206
00207 Dimension d = left.getMinimumSize();
00208 d.width = DIVIDER_DEFAULT_LOCATION / 2;
00209 left.setMinimumSize(d);
00210
00211
00212
00213 Box tabControls = new Box(BoxLayout.Y_AXIS);
00214 final Icon tabButtonDown = new ImageIcon(ClassLoader.getSystemResource("resources/projectExplorerTabDown.png"));
00215 final Icon tabButtonUp = new ImageIcon(ClassLoader.getSystemResource("resources/projectExplorerTabUp.png"));
00216 final JButton tabButton = new JButton(tabButtonDown);
00217 tabButton.setContentAreaFilled(false);
00218 tabButton.setBorder(null);
00219 tabButton.setFocusable(false);
00220 tabButton.setMnemonic('P');
00221 tabButton.addActionListener(new ActionListener() {
00222 public void actionPerformed(ActionEvent e) {
00223 if (splitPane.getDividerLocation() == 0) {
00224
00225 splitPane.setDividerLocation(splitPane.getLastDividerLocation());
00226 splitPane.setDividerSize(DIVIDER_SIZE);
00227 tabButton.setIcon(tabButtonDown);
00228 } else {
00229
00230 splitPane.setDividerLocation(0);
00231 splitPane.setDividerSize(0);
00232 tabButton.setIcon(tabButtonUp);
00233 }
00234 }
00235 });
00236 tabControls.add(tabButton);
00237 tabControls.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
00238
00239
00240 setLayout(new BorderLayout());
00241 add(splitPane, "Center");
00242 add(tabControls, "West");
00243 setBackground(new Color(247, 243, 239));
00244
00245
00246
00247
00248
00249 setProject(project);
00250 }
00251
00256 public Squid getSquid() {
00257 return squid;
00258 }
00259
00268 public void setSquid(Squid squid) {
00269 if (squid == null) {
00270 throw new NullPointerException();
00271 }
00272 if (this.squid != null) {
00273 throw new IllegalStateException();
00274 }
00275 this.squid = squid;
00276 setProject(getProject());
00277 }
00278
00282 @Override public Project getProject() {
00283 return project;
00284 }
00285
00292 @Override public void setProject(Project project) {
00293 if (project != null) {
00294
00295 if (project.getType() != Project.Type.CALIBRATION) {
00296 Settings.updateProjectHistory(project.getFile());
00297 Settings.updateDirectoryHistory(project.getFile().getAbsoluteFile().getParentFile());
00298 }
00299
00300
00301 project.addProjectListener(this);
00302 project.setSquid(squid);
00303
00304
00305 Frame parent = getParentFrame();
00306 if (parent != null) {
00307 parent.setTitle(project.getFile().getAbsolutePath());
00308 } else {
00309
00310 SwingUtilities.invokeLater(new Runnable() {
00311 public void run() {
00312 getParentFrame().setTitle(getProject().getFile().getAbsolutePath());
00313 }
00314 });
00315 }
00316 getProjectInformationPanel().setBorder(
00317 BorderFactory.createTitledBorder(project.getName() + " (" + project.getType() + " Project)"));
00318 getExportProjectToDATAction().setEnabled(true);
00319 getExportProjectToTDTAction().setEnabled(true);
00320 getExportProjectToSRMAction().setEnabled(true);
00321 getPrintAction().setEnabled(true);
00322 getPrintPreviewAction().setEnabled(true);
00323 } else {
00324
00325 Frame parent = getParentFrame();
00326 if (parent != null) {
00327 getParentFrame().setTitle(null);
00328 }
00329 getProjectInformationPanel().setBorder(BorderFactory.createTitledBorder("Project Information"));
00330 getExportProjectToDATAction().setEnabled(false);
00331 getExportProjectToTDTAction().setEnabled(false);
00332 getExportProjectToSRMAction().setEnabled(false);
00333 getPrintAction().setEnabled(false);
00334 getPrintPreviewAction().setEnabled(false);
00335 }
00336
00337
00338 Project oldProject = this.project;
00339 this.project = project;
00340
00341 getProjectExplorerPanel().setProject(project);
00342 getCalibrationPanel().setProject(project);
00343 getProjectInformationPanel().setProject(project);
00344 getMeasurementSequencePanel().setProject(project);
00345 getMeasurementControlsPanel().setProject(project);
00346 getMeasurementDetailsPanel().setProject(project);
00347 getMeasurementGraphsPanel().setProject(project);
00348
00349
00350 if (oldProject != null && oldProject != project && oldProject != latestMeasuringProject) {
00351 if (!Project.closeProject(oldProject)) {
00352 JOptionPane.showMessageDialog(getParentFrame(),
00353 "Unable to close the project " + oldProject.getName(),
00354 "Error", JOptionPane.ERROR_MESSAGE);
00355 }
00356 }
00357 }
00358
00362 @Override public void projectUpdated(ProjectEvent event) {
00363 if (event.getType() == ProjectEvent.Type.STATE_CHANGED) {
00364
00365
00366 if (event.getProject().getState() != Project.State.IDLE) {
00367
00368
00369 if (latestMeasuringProject != null
00370 && latestMeasuringProject != project
00371 && latestMeasuringProject != event.getProject()) {
00372 if (!Project.closeProject(latestMeasuringProject)) {
00373 JOptionPane.showMessageDialog(getParentFrame(),
00374 "Unable to close the project " + latestMeasuringProject.getName(),
00375 "Error", JOptionPane.ERROR_MESSAGE);
00376 }
00377 }
00378 latestMeasuringProject = event.getProject();
00379 }
00380 return;
00381 }
00382 }
00383
00388 public void exitProgram() {
00389
00390
00391 if (latestMeasuringProject != null && latestMeasuringProject.getState() != Project.State.IDLE) {
00392 JOptionPane.showMessageDialog(getParentFrame(),
00393 "Can not exit. A measurement is running.",
00394 "Error", JOptionPane.ERROR_MESSAGE);
00395 return;
00396 }
00397
00398
00399 if (!Settings.saveNow()) {
00400 JOptionPane.showMessageDialog(getParentFrame(),
00401 "Can not exit. Unable to save the settings.",
00402 "Error", JOptionPane.ERROR_MESSAGE);
00403 return;
00404 }
00405
00406
00407 setProject(null);
00408
00409
00410 if (latestMeasuringProject != null) {
00411 if (!Project.closeProject(latestMeasuringProject)) {
00412 JOptionPane.showMessageDialog(getParentFrame(),
00413 "Can not exit. Unable to close the project " + latestMeasuringProject.getName() + ".",
00414 "Error", JOptionPane.ERROR_MESSAGE);
00415 return;
00416 }
00417 }
00418
00419
00420 Project[] cachedProjects = Project.getCachedProjects();
00421 for (Project cached : cachedProjects) {
00422 System.err.println("Found a cached project, closing it: " + cached.getFile());
00423 if (!Project.closeProject(cached)) {
00424 JOptionPane.showMessageDialog(getParentFrame(),
00425 "Can not exit. Unable to close the (cached) project " + cached.getName() + ".",
00426 "Error", JOptionPane.ERROR_MESSAGE);
00427 return;
00428 }
00429 }
00430
00431
00432 SerialIO.closeAllPorts();
00433
00434
00435 System.exit(0);
00436 }
00437
00444 public void loadProject(File file) {
00445 if (file == null) {
00446 throw new NullPointerException();
00447 }
00448 Project project = Project.loadProject(file);
00449 if (project != null) {
00450 setProject(project);
00451 } else {
00452 JOptionPane.showMessageDialog(getParentFrame(),
00453 "Unable to open the file " + file,
00454 "Error", JOptionPane.ERROR_MESSAGE);
00455 }
00456 }
00457
00465 public void createProject(File file, Project.Type type) {
00466 if (file == null || type == null) {
00467 throw new NullPointerException();
00468 }
00469 Project project = Project.createProject(file, type);
00470 if (project != null) {
00471 setProject(project);
00472 } else {
00473 JOptionPane.showMessageDialog(getParentFrame(),
00474 "Unable to create the file " + file,
00475 "Error", JOptionPane.ERROR_MESSAGE);
00476 }
00477 }
00478
00488 public void exportProject(Project project, String type, File output) {
00489 if (project == null) {
00490 throw new NullPointerException();
00491 }
00492 type = type.toLowerCase();
00493 JFileChooser chooser = new JFileChooser(Settings.getLastDirectory());
00494 chooser.setFileFilter(new GenericFileFilter(type.toUpperCase() + " File", type));
00495
00496 do {
00497
00498 int returnVal;
00499 if (output == null) {
00500 returnVal = chooser.showSaveDialog(MainViewPanel.this);
00501 } else {
00502 chooser.setSelectedFile(output);
00503 returnVal = JFileChooser.APPROVE_OPTION;
00504 output = null;
00505 }
00506
00507 if (returnVal == JFileChooser.APPROVE_OPTION) {
00508 File file = chooser.getSelectedFile();
00509
00510 if (!file.getName().toLowerCase().endsWith("." + type)) {
00511 file = new File(file.getAbsolutePath() + "." + type);
00512 }
00513
00514
00515 if (file.exists()) {
00516 returnVal = JOptionPane.showConfirmDialog(getParentFrame(),
00517 "Overwrite the file " + file + "?",
00518 "Confirm", JOptionPane.YES_NO_CANCEL_OPTION);
00519 if (returnVal == JOptionPane.NO_OPTION) {
00520 continue;
00521 } else if (returnVal == JOptionPane.CANCEL_OPTION) {
00522 break;
00523 }
00524 }
00525
00526
00527 boolean ok;
00528 if (type.equals("dat")) {
00529 ok = project.exportToDAT(chooser.getSelectedFile());
00530 } else if (type.equals("tdt")) {
00531 ok = project.exportToTDT(chooser.getSelectedFile());
00532 } else if (type.equals("srm")) {
00533 ok = project.exportToSRM(chooser.getSelectedFile());
00534 } else {
00535 throw new IllegalArgumentException("Unkown export type: " + type);
00536 }
00537 if (!ok) {
00538 JOptionPane.showMessageDialog(getParentFrame(),
00539 "Unable to write the file " + file,
00540 "Error", JOptionPane.ERROR_MESSAGE);
00541 }
00542 }
00543 break;
00544 } while (true);
00545 }
00546
00547
00548
00549 public MainMenuBar getMenuBar() {
00550 if (menuBar == null) {
00551 menuBar = new MainMenuBar(this);
00552 }
00553 return menuBar;
00554 }
00555
00556 public MainStatusBar getStatusBar() {
00557 if (statusBar == null) {
00558 statusBar = new MainStatusBar();
00559 }
00560 return statusBar;
00561 }
00562
00563 public MeasurementGraphsPanel getMeasurementGraphsPanel() {
00564 if (measurementGraphsPanel == null) {
00565 measurementGraphsPanel = new MeasurementGraphsPanel();
00566 measurementGraphsPanel.setBorder(BorderFactory.createTitledBorder("Graphs"));
00567 }
00568 return measurementGraphsPanel;
00569 }
00570
00571 public MeasurementDetailsPanel getMeasurementDetailsPanel() {
00572 if (measurementDetailsPanel == null) {
00573 measurementDetailsPanel = getMeasurementSequencePanel().getDetailsPanel();
00574 measurementDetailsPanel.setBorder(BorderFactory.createTitledBorder("Details"));
00575 }
00576 return measurementDetailsPanel;
00577 }
00578
00579 public MeasurementControlsPanel getMeasurementControlsPanel() {
00580 if (measurementControlsPanel == null) {
00581 measurementControlsPanel = new MeasurementControlsPanel();
00582 measurementControlsPanel.setBorder(BorderFactory.createTitledBorder("Controls"));
00583 }
00584 return measurementControlsPanel;
00585 }
00586
00587 public MeasurementSequencePanel getMeasurementSequencePanel() {
00588 if (measurementSequencePanel == null) {
00589 measurementSequencePanel = new MeasurementSequencePanel();
00590 measurementSequencePanel.setBorder(BorderFactory.createTitledBorder("Sequence"));
00591 }
00592 return measurementSequencePanel;
00593 }
00594
00595 public ProjectInformationPanel getProjectInformationPanel() {
00596 if (projectInformationPanel == null) {
00597 projectInformationPanel = new ProjectInformationPanel();
00598 projectInformationPanel.setBorder(BorderFactory.createTitledBorder("Project Information"));
00599 }
00600 return projectInformationPanel;
00601 }
00602
00603 public CalibrationPanel getCalibrationPanel() {
00604 if (calibrationPanel == null) {
00605 calibrationPanel = new CalibrationPanel(this);
00606 calibrationPanel.setBorder(BorderFactory.createTitledBorder("Calibration"));
00607 }
00608 return calibrationPanel;
00609 }
00610
00611 public ProjectExplorerPanel getProjectExplorerPanel() {
00612 if (projectExplorerPanel == null) {
00613 projectExplorerPanel = new ProjectExplorerPanel(this, project);
00614 projectExplorerPanel.setBorder(BorderFactory.createTitledBorder("Project Explorer"));
00615 }
00616 return projectExplorerPanel;
00617 }
00618
00619
00620
00621 public Action getNewProjectAction() {
00622 if (newProjectAction == null) {
00623 newProjectAction = new AbstractAction() {
00624 public void actionPerformed(ActionEvent e) {
00625 NewProjectFileChooser chooser = new NewProjectFileChooser(Settings.getLastDirectory());
00626 chooser.setFileFilter(new GenericFileFilter(Ikayaki.FILE_DESCRIPTION, Ikayaki.FILE_TYPE));
00627 int returnVal = chooser.showSaveDialog(MainViewPanel.this);
00628
00629 if (returnVal == JFileChooser.APPROVE_OPTION) {
00630 File file = chooser.getSelectedFile();
00631 Project.Type type = chooser.getProjectType();
00632
00633 if (!file.getName().toLowerCase().endsWith(Ikayaki.FILE_TYPE)) {
00634 file = new File(file.getAbsolutePath() + Ikayaki.FILE_TYPE);
00635 }
00636 createProject(file, type);
00637 }
00638 }
00639 };
00640 newProjectAction.putValue(Action.NAME, "New...");
00641 newProjectAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_N);
00642 newProjectAction.putValue(Action.ACCELERATOR_KEY,
00643 KeyStroke.getKeyStroke(KeyEvent.VK_N, KeyEvent.CTRL_MASK));
00644 }
00645 return newProjectAction;
00646 }
00647
00648 public Action getOpenProjectAction() {
00649 if (openProjectAction == null) {
00650 openProjectAction = new AbstractAction() {
00651 public void actionPerformed(ActionEvent e) {
00652 JFileChooser chooser = new JFileChooser(Settings.getLastDirectory());
00653 chooser.setFileFilter(new GenericFileFilter(Ikayaki.FILE_DESCRIPTION, Ikayaki.FILE_TYPE));
00654 int returnVal = chooser.showOpenDialog(MainViewPanel.this);
00655
00656 if (returnVal == JFileChooser.APPROVE_OPTION) {
00657 loadProject(chooser.getSelectedFile());
00658 }
00659 }
00660 };
00661 openProjectAction.putValue(Action.NAME, "Open...");
00662 openProjectAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O);
00663 openProjectAction.putValue(Action.ACCELERATOR_KEY,
00664 KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK));
00665 }
00666 return openProjectAction;
00667 }
00668
00669 public Action getExportProjectToDATAction() {
00670 if (exportProjectToDATAction == null) {
00671 exportProjectToDATAction = new AbstractAction() {
00672 public void actionPerformed(ActionEvent e) {
00673 exportProject(getProject(), "dat", null);
00674 }
00675 };
00676 exportProjectToDATAction.putValue(Action.NAME, "DAT File...");
00677 exportProjectToDATAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_D);
00678 }
00679 return exportProjectToDATAction;
00680 }
00681
00682 public Action getExportProjectToTDTAction() {
00683 if (exportProjectToDTDAction == null) {
00684 exportProjectToDTDAction = new AbstractAction() {
00685 public void actionPerformed(ActionEvent e) {
00686 exportProject(getProject(), "tdt", null);
00687 }
00688 };
00689 exportProjectToDTDAction.putValue(Action.NAME, "TDT File...");
00690 exportProjectToDTDAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_T);
00691 }
00692 return exportProjectToDTDAction;
00693 }
00694
00695 public Action getExportProjectToSRMAction() {
00696 if (exportProjectToSRMAction == null) {
00697 exportProjectToSRMAction = new AbstractAction() {
00698 public void actionPerformed(ActionEvent e) {
00699 exportProject(getProject(), "srm", null);
00700 }
00701 };
00702 exportProjectToSRMAction.putValue(Action.NAME, "SRM File...");
00703 exportProjectToSRMAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_S);
00704
00705 }
00706 return exportProjectToSRMAction;
00707 }
00708
00709 public Action getPrintAction() {
00710 if (printAction == null) {
00711 printAction = new AbstractAction() {
00712 public void actionPerformed(ActionEvent e) {
00713
00714
00715
00716 SettingsDialog.showPrintPreview(getParentFrame(), "Print Preview", getProject(), true);
00717 }
00718 };
00719 printAction.putValue(Action.NAME, "Print");
00720 printAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_P);
00721 printAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_MASK));
00722 }
00723 return printAction;
00724 }
00725
00726 public Action getPrintPreviewAction() {
00727 if (printPreviewAction == null) {
00728 printPreviewAction = new AbstractAction() {
00729 public void actionPerformed(ActionEvent e) {
00730 SettingsDialog.showPrintPreview(getParentFrame(), "Print Preview", getProject(), false);
00731 }
00732 };
00733 printPreviewAction.putValue(Action.NAME, "Print Preview");
00734 printPreviewAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_V);
00735 }
00736 return printPreviewAction;
00737 }
00738
00739
00740 public Action getExitAction() {
00741 if (exitAction == null) {
00742 exitAction = new AbstractAction() {
00743 public void actionPerformed(ActionEvent e) {
00744 exitProgram();
00745 }
00746 };
00747 exitAction.putValue(Action.NAME, "Exit");
00748 exitAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_X);
00749 exitAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_Q, KeyEvent.CTRL_MASK));
00750 }
00751 return exitAction;
00752 }
00753
00754 public Action getProgramSettingsAction() {
00755 if (programSettingsAction == null) {
00756 programSettingsAction = new AbstractAction() {
00757 public void actionPerformed(ActionEvent e) {
00758 SettingsDialog.showProgramSettingsDialog(getParentFrame(), "Options");
00759 setProject(getProject());
00760 }
00761 };
00762 programSettingsAction.putValue(Action.NAME, "Options");
00763 programSettingsAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_O);
00764 }
00765 return programSettingsAction;
00766 }
00767
00768 public Action getDeviceSettingsAction() {
00769 if (deviceSettingsAction == null) {
00770 deviceSettingsAction = new AbstractAction() {
00771 public void actionPerformed(ActionEvent e) {
00772 SettingsDialog.showDeviceSettingsDialog(getParentFrame(), "Device Configuration");
00773 getMeasurementControlsPanel().measurementUpdated(null);
00774 }
00775 };
00776 deviceSettingsAction.putValue(Action.NAME, "Device Configuration");
00777 deviceSettingsAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_C);
00778 }
00779 return deviceSettingsAction;
00780 }
00781
00782 public Action getHelpAction() {
00783 if (helpAction == null) {
00784 helpAction = new AbstractAction() {
00785 public void actionPerformed(ActionEvent event) {
00786 if (!System.getProperty("os.name").startsWith("Windows")) {
00787 JOptionPane.showMessageDialog(getParentFrame(),
00788 "Open this file in your web browser to view the help pages:\n" + Ikayaki.HELP_PAGES);
00789 return;
00790 }
00791
00792
00793 String[] cmd = {"cmd", "/c", "start", Ikayaki.HELP_PAGES};
00794
00795
00796 try {
00797 Process p = Runtime.getRuntime().exec(cmd);
00798 BufferedInputStream in = new BufferedInputStream(p.getInputStream());
00799
00800
00801 int i;
00802 while ((i = in.read()) >= 0) {
00803 System.err.print((char) i);
00804 }
00805
00806 } catch (IOException e) {
00807 e.printStackTrace();
00808 }
00809 }
00810 };
00811 helpAction.putValue(Action.NAME, "Help Topics");
00812 helpAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_H);
00813 helpAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
00814 }
00815 return helpAction;
00816 }
00817
00818 public Action getAboutAction() {
00819 if (aboutAction == null) {
00820 aboutAction = new AbstractAction() {
00821 public void actionPerformed(ActionEvent e) {
00822 String message = Ikayaki.APP_NAME + " " + Ikayaki.APP_VERSION + "\n" +
00823 Ikayaki.APP_BUILD + "\n\n" +
00824 Ikayaki.APP_HOME_PAGE + "\n\n";
00825 for (String author : Ikayaki.AUTHORS) {
00826 message += author + "\n";
00827 }
00828 JOptionPane.showMessageDialog(getParentFrame(),
00829 message, "About " + Ikayaki.APP_NAME, JOptionPane.INFORMATION_MESSAGE,
00830 new ImageIcon(ClassLoader.getSystemResource("resources/ikayaki.png")));
00831 }
00832 };
00833 aboutAction.putValue(Action.NAME, "About");
00834 aboutAction.putValue(Action.MNEMONIC_KEY, KeyEvent.VK_A);
00835 }
00836 return aboutAction;
00837 }
00838
00844 private class NewProjectFileChooser extends JFileChooser {
00845
00846 private JComboBox projectType;
00847
00848 public NewProjectFileChooser(File currentDirectory) {
00849 super(currentDirectory);
00850 projectType = new JComboBox(Project.Type.values());
00851 projectType.setSelectedItem(Project.Type.AF);
00852 }
00853
00854 protected JDialog createDialog(Component parent) throws HeadlessException {
00855 JDialog dialog = super.createDialog(parent);
00856 Container origCP = dialog.getContentPane();
00857 JPanel newCP = new JPanel(new BorderLayout(0, 0));
00858
00859 newCP.add(origCP, "Center");
00860 newCP.add(createExtraButtons(), "South");
00861 dialog.setContentPane(newCP);
00862
00863 Dimension d = dialog.getSize();
00864 dialog.setSize((int) d.getWidth(), (int) d.getHeight() + 70);
00865
00866 return dialog;
00867 }
00868
00869 private Component createExtraButtons() {
00870 Box b = new Box(BoxLayout.X_AXIS);
00871 b.setBorder(BorderFactory.createEmptyBorder(0, 12, 11, 11));
00872 b.add(new JLabel("Type of Project: "));
00873 b.add(projectType);
00874 return b;
00875 }
00876
00877 public Project.Type getProjectType() {
00878 return (Project.Type) projectType.getSelectedItem();
00879 }
00880 }
00881 }