|
|
/home/brennan/Software/sensix/source/C^4/ConfigMenu.javaGo to the documentation of this file.00001 00010 /* 00011 * Copyright 2008. Los Alamos National Security, LLC. This material 00012 * was produced under U.S. Government contract DE-AC52-06NA25396 for 00013 * Los Alamos National Laboratory (LANL), which is operated by Los 00014 * Alamos National Security, LLC, for the Department of Energy. The 00015 * U.S. Government has rights to use, reproduce, and distribute this 00016 * software. NEITHER THE GOVERNMENT NOR LOS ALAMOS NATIONAL SECURITY, 00017 * LLC, MAKES ANY WARRANTY, EXPRESS OR IMPLIED, OR ASSUMES ANY LEGAL 00018 * LIABILITY FOR THE USE OF THIS SOFTWARE. If software is modified to 00019 * produce derivative works, such modified software should be clearly 00020 * marked, so as not to confuse it with the version available from LANL. 00021 * 00022 * Additionally, this program is free software; you can redistribute 00023 * it and/or modify it under the terms of the GNU General Public 00024 * License as published by the Free Software Foundation; version 2 of 00025 * the License. Accordingly, this program is distributed in the hope 00026 * it will be useful, but WITHOUT ANY WARRANTY; without even the 00027 * implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR 00028 * PURPOSE. See the GNU General Public License for more details. 00029 * 00030 * You should have received a copy of the GNU General Public License 00031 * along with this program; if not, write to the Free Software 00032 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. 00033 */ 00034 00035 import java.awt.*; 00036 import java.awt.event.*; 00037 import java.io.*; 00038 import javax.swing.*; 00039 00040 public class ConfigMenu extends ExtendedMenu 00041 { 00042 private SenseGui gui; 00043 private JMenuItem overall; 00044 private JMenu topology; 00045 private JMenu sources; 00046 private JMenu failures; 00047 private JMenuItem output; 00048 00049 public ConfigMenu(String name, SenseGui g) { 00050 super(name); 00051 gui = g; 00052 00053 overall = new JMenuItem("Overall Configuration"); 00054 00055 topology = new ExtendedMenu("Topology") { 00056 public void handleAction(String s) { 00057 /* 00058 if (s.equalsIgnoreCase("New Configuration ...")) { 00059 ConfigDialog cd = new ConfigDialog(gui, 00060 "Configure a new network"); 00061 cd.show(); 00062 } else if (s.equalsIgnoreCase("Alter Current Configuration ...")) { 00063 ConfigDialog cd = 00064 new ConfigDialog(gui, 00065 "Change the current configuration"); 00066 cd.setNetwork(new Network(gui.topology)); 00067 cd.show(); 00068 } else if (s.equalsIgnoreCase("Load Configuration File ...")) { 00069 FileDialog fd = new FileDialog(gui, "Load Configuration", FileDialog.LOAD); 00070 fd.setDirectory(SenseGui.config_directory); 00071 fd.setFilenameFilter(new XMLFileFilter()); 00072 fd.show(); 00073 if (fd.getFile() != null) 00074 gui.start.initializeConfig( 00075 new File(fd.getDirectory(), fd.getFile()), true); 00076 } else if (s.equalsIgnoreCase("Save Configuration As ...")) { 00077 FileDialog fd = new FileDialog( 00078 gui, "Save Configuration As", FileDialog.SAVE); 00079 fd.setDirectory(SenseGui.config_directory); 00080 fd.show(); 00081 if (fd.getFile() != null) 00082 gui.start.saveConfig(fd.getDirectory() + fd.getFile()); 00083 } else if (s.equalsIgnoreCase("Import A Configuration ...")) { 00084 FileDialog fdi = new FileDialog( 00085 gui, "Import", FileDialog.LOAD); 00086 fdi.setDirectory(SenseGui.default_dir + "config/"); 00087 fdi.show(); 00088 gui.start.importConfig(fdi.getDirectory() + fdi.getFile(), 00089 SenseGui.default_dir + ".import.tmp"); 00090 FileDialog fds = 00091 new FileDialog(gui, "Save Import", FileDialog.SAVE); 00092 fds.setDirectory(SenseGui.default_dir + "xml/"); 00093 fds.show(); 00094 if (fds.getFile() != null) { 00095 (new File(SenseGui.default_dir + ".import.tmp")).renameTo( 00096 new File(fds.getDirectory(), fds.getFile())); 00097 gui.start.initializeConfig( 00098 new File(fds.getDirectory(), fds.getFile()), true); 00099 } 00100 (new File(SenseGui.default_dir + ".import.tmp")).delete(); 00101 } else if (s.equalsIgnoreCase("Export This Configuration As ...")) { 00102 FileDialog fd = new FileDialog( 00103 gui, "Export", FileDialog.SAVE); 00104 fd.setDirectory(SenseGui.default_dir + "config/"); 00105 fd.show(); 00106 if (fd.getFile() != null) { 00107 String name = gui.start.getConfigFile(); 00108 if (name == null) { 00109 name = SenseGui.default_dir + ".export.tmp.xml"; 00110 gui.start.saveConfig(name); 00111 } 00112 gui.start.exportConfig(name, fd.getDirectory() + fd.getFile()); 00113 // (new File(SenseGui.default_dir + ".export.tmp.xml")).delete(); 00114 } 00115 } 00116 */ 00117 } 00118 /* 00119 public void addActionListener(ActionListener ac) { 00120 super.addActionListener(ac); 00121 } 00122 */ 00123 }; 00124 topology.add(new JMenuItem("New Configuration ...")); 00125 topology.add(new JMenuItem("Alter Current Configuration ...")); 00126 topology.addSeparator(); 00127 topology.add(new JMenuItem("Load Configuration File ...")); 00128 topology.add(new JMenuItem("Save Configuration As ...")); 00129 topology.addSeparator(); 00130 topology.add(new JMenuItem("Import A Configuration ...")); 00131 topology.add(new JMenuItem("Export This Configuration As ...")); 00132 00133 sources = new ExtendedMenu("Sources") { 00134 public void handleAction(String s) {} 00135 }; 00136 00137 failures = new ExtendedMenu("Failures") { 00138 public void handleAction(String s) {} 00139 }; 00140 00141 output = new JMenuItem("Output File"); 00142 00143 add(overall); 00144 addSeparator(); 00145 add(topology); 00146 addSeparator(); 00147 add(sources); 00148 addSeparator(); 00149 add(failures); 00150 addSeparator(); 00151 add(output); 00152 } 00153 00154 public void handleAction(String s) { 00155 if (s.equalsIgnoreCase("Overall Configuration")) { 00156 /* ConfigDialog cd = new ConfigDialog(gui, "Configure a new network"); 00157 cd.show();*/ 00158 } else if (s.equalsIgnoreCase("Output File")) { 00159 /* 00160 FileDialog fd = 00161 new FileDialog((Container)gui, "Output File", FileDialog.LOAD); 00162 //fd.setDirectory(SenseGui.default_dir); 00163 fd.setFilenameFilter(new CfgFileFilter()); 00164 //fd.show(); 00165 // if (fd.getFile() != null) 00166 // gui.start.initializeConfig( 00167 // new File(fd.getDirectory(), fd.getFile()), true); 00168 */ 00169 } 00170 } 00171 /* 00172 public void addActionListener(ActionListener ac) { 00173 topology.addActionListener(ac); 00174 sources.addActionListener(ac); 00175 failures.addActionListener(ac); 00176 super.addActionListener(ac); 00177 } 00178 */ 00179 public class XMLFileFilter implements FilenameFilter { 00180 public boolean accept(File dir, String name) { 00181 if (name.endsWith(".xml") || name.endsWith(".XML")) 00182 return true; 00183 return false; 00184 } 00185 } 00186 public class CfgFileFilter implements FilenameFilter { 00187 public boolean accept(File dir, String name) { 00188 if (name.endsWith(".cfg") || name.endsWith(".CFG") || 00189 name.endsWith(".conf") || name.endsWith(".CONF") || 00190 name.endsWith(".config") || name.endsWith(".CONFIG")) 00191 return true; 00192 return false; 00193 } 00194 } 00195 } |