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

MURPanel.java

00001 package GuiComponents.SctConf;
00002 
00003 import javax.swing.event.AncestorListener;
00004 import javax.swing.event.AncestorEvent;
00005 
00006 import javax.swing.*;
00007 import java.awt.*;
00008 import java.awt.event.*;
00009 
00010 import java.io.File;
00011 
00012 import java.util.Vector;
00013 
00014 import org.omg.CORBA.IntHolder;
00015 import org.omg.CORBA.StringHolder;
00016 
00017 import sctConf.*;
00018 import Sct.gui.SelectionDialog;
00019 
00020 public class MURPanel extends JPanel {
00021     sctConf.Configuration config;
00022     Proxies.RodProxy rod;
00023 
00024     int mur;
00025     int order;
00026 
00027 //    boolean editable;
00028 
00029     // ChannelPanel [] channels;
00030 
00032     public MURPanel(Configuration conf, Proxies.RodProxy r, int o) {
00033         rod = r;
00034         config = conf;
00035         order = o;
00036 
00037         try {
00038             IntHolder MUR = new IntHolder();
00039 
00040             config.getMapRODMUR(rod.partition(), rod.crate(), rod.index(), order, MUR);
00041             mur = MUR.value;
00042         } catch(NullPointerException e) {
00043             mur = 1;
00044         } catch(ConfigurationException e) {
00045             mur = -1;
00046         }
00047 
00048         if(mur == -1) {
00049             try {
00050                 int newMUR = config.getFreeMurId();
00051                 if(config.getMURType(newMUR) == sctConf.MURType.UNKNOWN) {
00052                     config.mapRODMUR(rod.partition(), rod.crate(), rod.index(), order, newMUR);
00053                 }
00054                 mur = newMUR;
00055             } catch(ConfigurationException cex) {
00056                 JOptionPane.showMessageDialog(null, "Failed to map new MUR to ROD: " + cex.detail);
00057                 return;
00058             }
00059         }
00060 
00061         initComponents();
00062         modifyComponents();
00063     }
00064 
00065     public static void main(String args[]) {
00066         JFrame frame = new JFrame("Test MUR Panel");
00067         frame.getContentPane().add(new MURPanel(null, null, 1));
00068         frame.pack();
00069         frame.setVisible(true);
00070     }
00071     
00077     private void initComponents() {//GEN-BEGIN:initComponents
00078         murBox = new javax.swing.JPanel();
00079         jButton1 = new javax.swing.JButton();
00080         jPanel1 = new javax.swing.JPanel();
00081         chanBox = new javax.swing.JPanel();
00082         chanBox2 = new javax.swing.JPanel();
00083 
00084         setLayout(new java.awt.BorderLayout());
00085 
00086         setBorder(new javax.swing.border.TitledBorder(getTitleString()));
00087         murBox.setLayout(new javax.swing.BoxLayout(murBox, javax.swing.BoxLayout.X_AXIS));
00088 
00089         jButton1.setText("Edit Physical Mapping");
00090         jButton1.addActionListener(new java.awt.event.ActionListener() {
00091             public void actionPerformed(java.awt.event.ActionEvent evt) {
00092                 physicalMappingPerformed(evt);
00093             }
00094         });
00095 
00096         murBox.add(jButton1);
00097 
00098         add(murBox, java.awt.BorderLayout.SOUTH);
00099 
00100         jPanel1.setLayout(new java.awt.GridLayout(1, 2));
00101 
00102         chanBox.setLayout(new java.awt.GridLayout(3, 1));
00103 
00104         jPanel1.add(chanBox);
00105 
00106         chanBox2.setLayout(new java.awt.GridLayout(3, 1));
00107 
00108         jPanel1.add(chanBox2);
00109 
00110         add(jPanel1, java.awt.BorderLayout.CENTER);
00111 
00112     }//GEN-END:initComponents
00113 
00114     private void physicalMappingPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_physicalMappingPerformed
00115         String [] labels;
00116 
00117         String [] defaults = {"", "", ""};
00118 
00119         int type = 0;
00120 
00121         IntHolder plane = new IntHolder(), section = new IntHolder(), position = new IntHolder();
00122 
00123         MURType mType;
00124         try {
00125             mType = config.getMapMURPhysical(mur, plane, section, position);
00126         } catch(ConfigurationException c) {
00127             mType = sctConf.MURType.UNKNOWN;
00128         }
00129 
00130         if(mType == sctConf.MURType.BARREL) {
00131             defaults[0] = "" + plane.value;
00132             defaults[1] = "" + section.value;
00133             defaults[2] = "" + position.value;
00134             type = 1;
00135         } else if(mType == sctConf.MURType.ENDCAP) {
00136             defaults[0] = "" + plane.value;
00137             defaults[1] = "" + section.value;
00138             defaults[2] = "" + position.value;
00139             type = 2;
00140         } else {
00141             // No mapping yet
00142             Object[] possibilities = {"Barrel", "Endcap"};
00143             String s = (String)JOptionPane
00144                         .showInputDialog(null,  // Frame
00145                                          "Select a type for this MUR:",
00146                                          "MUR Type selection",
00147                                          JOptionPane.PLAIN_MESSAGE,
00148                                          null,
00149                                          possibilities,
00150                                          null);
00151 
00152             if(s == possibilities[0]) type = 1;
00153             else if(s == possibilities[1]) type = 2;
00154             else {
00155                 JOptionPane.showMessageDialog(null, "No MUR type selected");
00156                 return;
00157             }
00158         }
00159 
00160         if(type == 1) {
00161             String [] barrelLabels = {"Barrel (3-6)", "Row (0-55)", "Position (-1 or 1)"};
00162             labels = barrelLabels;
00163         } else {
00164             String [] endCapLabels = {"Disk (-9 to -1, 1 to 9)", "Quadrant (0-3)", "Position (0-5)"};
00165             labels = endCapLabels;
00166         }
00167 
00168         SelectionDialog dia = new SelectionDialog(null, "Edit Physical Mapping", labels, defaults);
00169 
00170         dia.pack();
00171         dia.setVisible(true);
00172 
00173         try {
00174             for(int i=0; i<3; i++) {
00175                 System.out.println(labels[i] + ": " + dia.getIntFieldValue(i));
00176             }
00177 
00178             try {
00179                 if(config.getMURType(mur) == sctConf.MURType.BARREL || type == 1) {
00180                     config.mapBarrelMUR(mur,
00181                                         dia.getIntFieldValue(0), dia.getIntFieldValue(1), dia.getIntFieldValue(2));
00182                     System.out.println("Configured Barrel MUR");
00183                 } else if(config.getMURType(mur) == sctConf.MURType.ENDCAP || type == 2) {
00184                     config.mapEndcapMUR(mur,
00185                                         dia.getIntFieldValue(0), dia.getIntFieldValue(1), dia.getIntFieldValue(2));
00186                     System.out.println("Configured Endcap MUR");
00187                 } else {
00188                     // No mapping selected?
00189                 }
00190             } catch(ConfigurationException cex) {
00191                 System.out.println("Failed to mapPhysicalChannel: " + cex);
00192                 return;
00193             }
00194 
00195             // Physical mapping not shown in normal gui...
00196             //                        modifyComponetns();
00197         } catch(SelectionDialog.InvalidDialogException i) {
00198             JOptionPane.showMessageDialog(null, "Failed to interpret entry(ies)");
00199         } catch(SelectionDialog.CancelledDialogException i) {
00200             // Cancel pressed
00201         }
00202     }//GEN-LAST:event_physicalMappingPerformed
00203 
00204     String getTitleString() {
00205         return "MUR " + mur + " position " + getPosition();
00206     }
00207 
00208     void modifyComponents() {
00209         channelPanels = new ChannelParamsPanel[6];
00210         
00211         int channelBase = order*6;
00212 
00213         for(int i=0; i<6; i++) {
00214             channelPanels[i] = new GuiComponents.SctConf.ChannelParamsPanel();
00215 
00216             channelPanels[i].setConfig(getConfig());
00217             channelPanels[i].setPosition(i+1);
00218             channelPanels[i].setRod(rod);
00219             channelPanels[i].setMur(mur);
00220             channelPanels[i].setChannel(channelBase + i);
00221 
00222             if(i<3) {
00223                 chanBox.add(channelPanels[i]);
00224             } else {
00225                 chanBox2.add(channelPanels[i]);
00226             }
00227         }
00228         
00229         validate();
00230     }
00231 
00232     int getPosition() {
00233         return order;
00234     }
00235 
00236     static JFileChooser fileChooser;
00237 
00238     { fileChooser = null; }
00239 
00240     static String getFileName() {
00241         if(fileChooser == null) {
00242             fileChooser = new JFileChooser();
00243         }
00244 
00245         if(fileChooser.showDialog(null, "Pick module configuration file") == JFileChooser.APPROVE_OPTION) {
00246           File file = fileChooser.getSelectedFile();
00247           return file.toString();
00248         } else {
00249           return null;
00250         }
00251     }
00252 
00253     public sctConf.Configuration getConfig() {
00254         return config;
00255     }
00256     
00257     // Variables declaration - do not modify//GEN-BEGIN:variables
00258     private javax.swing.JPanel chanBox;
00259     private javax.swing.JPanel chanBox2;
00260     private javax.swing.JButton jButton1;
00261     private javax.swing.JPanel jPanel1;
00262     private javax.swing.JPanel murBox;
00263     // End of variables declaration//GEN-END:variables
00264 
00265     private ChannelParamsPanel channelPanels[];
00266 }

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