src/org/math/plot/components/DataToolBar.java

00001 package org.math.plot.components;
00002 
00003 import java.awt.event.*;
00004 import java.security.*;
00005 
00006 import javax.swing.*;
00007 
00008 import org.math.plot.*;
00009 
00016 public class DataToolBar extends JToolBar {
00017 
00021         private static final long serialVersionUID = 1L;
00022 
00023         protected JButton buttonPasteToClipboard;
00024 
00025         protected JButton buttonSaveFile;
00026 
00027         private boolean denySaveSecurity;
00028 
00029         private JFileChooser fileChooser;
00030 
00031         private DataPanel dataPanel;
00032 
00033         public DataToolBar(DataPanel dp) {
00034 
00035                 dataPanel = dp;
00036 
00037                 try {
00038                         fileChooser = new JFileChooser();
00039                 } catch (AccessControlException ace) {
00040                         denySaveSecurity = true;
00041                 }
00042 
00043                 buttonPasteToClipboard = new JButton(new ImageIcon(org.math.plot.PlotPanel.class.getResource("icons/toclipboard.png")));
00044                 buttonPasteToClipboard.setToolTipText("Copy data to clipboard");
00045 
00046                 buttonSaveFile = new JButton(new ImageIcon(org.math.plot.PlotPanel.class.getResource("icons/tofile.png")));
00047                 buttonSaveFile.setToolTipText("Save data into ASCII file");
00048 
00049                 buttonPasteToClipboard.addActionListener(new ActionListener() {
00050                         public void actionPerformed(ActionEvent e) {
00051                                 dataPanel.toClipBoard();
00052                         }
00053                 });
00054                 buttonSaveFile.addActionListener(new ActionListener() {
00055                         public void actionPerformed(ActionEvent e) {
00056                                 chooseFile();
00057                         }
00058                 });
00059 
00060                 add(buttonPasteToClipboard, null);
00061                 add(buttonSaveFile, null);
00062 
00063                 if (!denySaveSecurity) {
00064                         fileChooser.addActionListener(new java.awt.event.ActionListener() {
00065                                 public void actionPerformed(ActionEvent e) {
00066                                         saveFile();
00067                                 }
00068                         });
00069                 } else {
00070                         buttonSaveFile.setEnabled(false);
00071                 }
00072         }
00073 
00074         void saveFile() {
00075                 java.io.File file = fileChooser.getSelectedFile();
00076                 dataPanel.toASCIIFile(file);
00077         }
00078 
00079         void chooseFile() {
00080                 fileChooser.showSaveDialog(this);
00081         }
00082 
00083 }

Generated on Wed Sep 5 21:44:01 2007 for jmathplot by  doxygen 1.5.1