Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ModuleListView.java

00001 package GuiComponents.SctConf;
00002 
00003 import javax.swing.*;
00004 import javax.swing.event.*;
00005 import java.awt.*;
00006 import java.awt.event.*;
00007 
00008 import java.util.Vector;
00009 
00010 public class ModuleListView extends JPanel {
00011     sctConf.Configuration config;
00012 //      ConfigGui.Module module;
00013 
00014     JList moduleList;
00015 
00016     boolean unused;
00017 
00018     public ModuleListView(sctConf.Configuration conf) {
00019 //          module = mod;
00020         config = conf;
00021 
00022         unused = true;
00023 
00024         setLayout(new BorderLayout());
00025         JPanel buttons = new JPanel();
00026 
00027         JCheckBox unusedCheck = new JCheckBox("Unused", unused);
00028         unusedCheck.addChangeListener(new ChangeListener() {
00029                 public void stateChanged(ChangeEvent e) {
00030                     System.out.println("CheckBox state changed");
00031 
00032                     boolean tempUnused = ((ButtonModel)((JCheckBox)(e.getSource())).getModel()).isSelected();
00033                     System.out.println("To " + tempUnused);
00034 
00035                     if(tempUnused != unused) {
00036                         System.out.println("Updating");
00037                         unused = tempUnused;
00038                         updateList();
00039                     }
00040                 }
00041             });
00042         buttons.add(unusedCheck);
00043 
00044         JButton addButton = new JButton("Add");
00045         addButton.addActionListener(new ActionListener() {
00046                 public void actionPerformed(ActionEvent e) {
00047                     String fileNames[] = getFileNames();
00048 
00049                     if(fileNames != null) {
00050                         for(int f=0; f<fileNames.length; f++) {
00051                             System.out.println("Add a module to the list using the configuration in file " + fileNames[f]);
00052 
00053                             try {
00054                                 config.configureModuleFromFile(fileNames[f]);
00055                             } catch(sctConf.ConfigurationException ex) {
00056                                 JOptionPane.showMessageDialog(null, "Failed to add " + fileNames[f] + " due to " + ex.detail);
00057                             }
00058                         }
00059                         updateList();
00060                     }
00061                 }
00062             });
00063         buttons.add(addButton);
00064 
00065         JButton close = new JButton("Close");
00066         close.addActionListener(new ActionListener() {
00067                 public void actionPerformed(ActionEvent e) {
00068                     ((Window)getTopLevelAncestor()).dispose();
00069                 }
00070             });
00071         buttons.add(close);
00072 
00073         add(buttons, BorderLayout.SOUTH);
00074 
00075         moduleList = new JList(getList());
00076         moduleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
00077         moduleList.setSelectedIndex(0);
00078 
00079         JScrollPane listScrollPane = new JScrollPane(moduleList);
00080         add(listScrollPane, BorderLayout.CENTER);
00081         validate();
00082 
00083         updateList();
00084     }
00085 
00086     void updateList() {
00087         moduleList.setListData(getList());
00088     }
00089 
00090     public Vector getList() {
00091         Vector result = new Vector();
00092 
00093         try {
00094             String[] modules;
00095 
00096             if(unused) modules = config.listUnusedModules();
00097             else modules = config.listAllModules();
00098 
00099             for(int i=0; i<modules.length; i++) {
00100                 result.addElement(modules[i]);
00101                 System.out.println(modules[i]);
00102             }
00103 
00104 //             int[] parts = config.listPartitions();
00105 //             for(int p=0; p<parts.length; p++) {
00106 //                 int[] crates = config.listCratesInPartition(parts[p]);
00107 //                 for(int c=0; c<crates.length; c++) {
00108 //                     int[] rods = config.listRodsInCrate(parts[p], crates[c]);
00109 //                     for(int r=0; r<rods.length; r++) {
00110 //                         int[] MURs = config.listMURSInRod(parts[p], crates[c], rods[r]);
00111 //                         for(int mur=0; mur<MURs.length; mur++) {
00112 //                             String[] modules = config.listModulesInMUR(parts[p], MURs[mur]);
00113 //                             for(int m=0; m<modules.length; m++) {
00114 //                                 result.addElement(modules[m]);
00115 //                             }
00116 //                         }
00117 //                     }
00118 //                 }
00119 //             }
00120         } catch(sctConf.ConfigurationException e) {
00121             System.out.println("Java caught an exception!: " + e.detail);
00122         }
00123 
00124         System.out.println("Returned list of " + result.size() + " modules");
00125 
00126         return result;
00127     }
00128 
00130     public String getSelected() {
00131         return (String)(moduleList.getSelectedValue());
00132     }
00133 
00134     static JFileChooser fileChooser;
00135 
00136     { fileChooser = null; }
00137 
00138     static String[] getFileNames() {
00139         if(fileChooser == null) {
00140             fileChooser = new JFileChooser();
00141         }
00142 
00143         fileChooser.setMultiSelectionEnabled(true);
00144 
00145         if(fileChooser.showDialog(null, "Pick module configuration file(s)") == JFileChooser.APPROVE_OPTION) {
00146           java.io.File files[] = fileChooser.getSelectedFiles();
00147           String [] result = new String[files.length];
00148 
00149           for(int i=0; i<files.length; i++) {
00150               result[i] = files[i].toString();
00151           }
00152           return result;
00153         } else {
00154           return null;
00155         }
00156     }
00157 }
00158 

Generated on Thu Jul 15 09:55:45 2004 for SCT DAQ/DCS Software - Java by doxygen 1.3.5