00001 package edu.stanford.hci.r3.tools.design.gui.toolbar;
00002
00003 import java.awt.Component;
00004 import java.awt.event.ActionEvent;
00005 import java.awt.event.ActionListener;
00006 import java.util.ArrayList;
00007 import java.util.List;
00008
00009 import javax.swing.ImageIcon;
00010 import javax.swing.JButton;
00011 import javax.swing.JFileChooser;
00012
00013 import edu.stanford.hci.r3.util.components.ribbons.RibbonPanel;
00014 import edu.stanford.hci.r3.util.files.FileUtils;
00015
00026 public class DocumentTasks {
00027
00028 private RibbonPanel filePanel;
00029
00030 private RibbonPanel measurementPanel;
00031
00032 private JButton measuringBoxButton;
00033
00034 private JButton measuringTapeButton;
00035
00036 private JButton newDocumentButton;
00037
00038 private JButton openDocumentButton;
00039
00040 private JButton importFileButton;
00041
00046 private RibbonPanel getFilePanel() {
00047 if (filePanel == null) {
00048 filePanel = new RibbonPanel("File");
00049 filePanel.add(getNewDocument());
00050 filePanel.add(getOpenDocument());
00051 filePanel.add(getImportFile());
00052 filePanel.layoutComponents();
00053 }
00054 return filePanel;
00055 }
00056
00060 private Component getImportFile() {
00061 importFileButton = new JButton("Import File");
00062 importFileButton.addActionListener(new ActionListener() {
00063 public void actionPerformed(ActionEvent ae) {
00064 System.out.println("Import File");
00065 JFileChooser chooser = FileUtils.createNewFileChooser(new String[] { "jpg", "pdf" });
00066 chooser.showOpenDialog(null);
00067 }
00068 });
00069 return importFileButton;
00070 }
00071
00075 private Component getMeasureBoxes() {
00076 if (measuringBoxButton == null) {
00077 measuringBoxButton = new JButton("Measuring Box");
00078 measuringBoxButton.addActionListener(new ActionListener() {
00079 public void actionPerformed(ActionEvent ae) {
00080 System.out.println("Box");
00081 }
00082 });
00083 }
00084 return measuringBoxButton;
00085 }
00086
00087 private Component getMeasureLines() {
00088 if (measuringTapeButton == null) {
00089 measuringTapeButton = new JButton("Measuring Tape");
00090 measuringTapeButton.addActionListener(new ActionListener() {
00091 public void actionPerformed(ActionEvent arg0) {
00092 System.out.println("Tape");
00093 }
00094 });
00095 }
00096 return measuringTapeButton;
00097 }
00098
00102 private RibbonPanel getMeasurementPanel() {
00103 if (measurementPanel == null) {
00104 measurementPanel = new RibbonPanel("Measurement");
00105 measurementPanel.add(getMeasureLines());
00106 measurementPanel.add(getMeasureBoxes());
00107 measurementPanel.layoutComponents(1, 2);
00108 }
00109 return measurementPanel;
00110 }
00111
00115 private Component getNewDocument() {
00116 if (newDocumentButton == null) {
00117 newDocumentButton = new JButton("New", makeIcon("New"));
00118 newDocumentButton.addActionListener(new ActionListener() {
00119 public void actionPerformed(ActionEvent ae) {
00120 System.out.println("New Document");
00121 }
00122 });
00123
00124 }
00125 return newDocumentButton;
00126 }
00127
00134 private Component getOpenDocument() {
00135 if (openDocumentButton == null) {
00136 openDocumentButton = new JButton("Open", makeIcon("Open"));
00137 openDocumentButton.addActionListener(new ActionListener() {
00138 public void actionPerformed(ActionEvent ae) {
00139 System.out.println("Open Document");
00140 FileUtils.createNewFileChooser(new String[] { "jpg", "pdf" });
00141 }
00142 });
00143
00144 }
00145 return openDocumentButton;
00146 }
00147
00151 public List<RibbonPanel> getPanels() {
00152 final List<RibbonPanel> panels = new ArrayList<RibbonPanel>();
00153 panels.add(getFilePanel());
00154 panels.add(getMeasurementPanel());
00155 return panels;
00156 }
00157
00158 private ImageIcon makeIcon(String iconName) {
00159 return new ImageIcon(DocumentTasks.class.getResource("/icons/" + iconName + ".png"));
00160 }
00161 }