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

ChannelParamsPanel.java

00001 /*
00002  * ChannelParamsPanel.java
00003  *
00004  * Created on 02 April 2004, 10:05
00005  */
00006 
00007 package GuiComponents.SctConf;
00008 
00009 import org.omg.CORBA.IntHolder;
00010 import org.omg.CORBA.StringHolder;
00011 
00012 import sctConf.ConfigurationException;
00013 import sctConf.BOCChannelConfig;
00014 
00015 import javax.swing.JComponent;
00016 import javax.swing.JFrame;
00017 import javax.swing.JOptionPane;
00018 import java.awt.event.WindowAdapter;
00019 import java.awt.event.WindowEvent;
00020 import java.util.Vector;
00021 import javax.swing.event.AncestorEvent;
00022 import javax.swing.event.AncestorListener;
00023 import java.awt.Dimension;
00024 
00029 public class ChannelParamsPanel extends javax.swing.JPanel {
00030     
00032     public ChannelParamsPanel() {
00033         initComponents();
00034         
00035         modifyComponents();
00036 
00037         addAncestorListener(new CheckDispose(this));
00038     }
00039     
00045     private void initComponents() {//GEN-BEGIN:initComponents
00046         jPanel4 = new javax.swing.JPanel();
00047         serNoLabel = new javax.swing.JLabel();
00048         removeButton = new javax.swing.JButton();
00049         remapModuleButton = new javax.swing.JButton();
00050         jPanel3 = new javax.swing.JPanel();
00051         jLabel4 = new javax.swing.JLabel();
00052         currentText = new javax.swing.JTextField();
00053         jLabel3 = new javax.swing.JLabel();
00054         delayText = new javax.swing.JTextField();
00055         jLabel2 = new javax.swing.JLabel();
00056         markSpaceText = new javax.swing.JTextField();
00057         jLabel1 = new javax.swing.JLabel();
00058         txFibreCombo = new javax.swing.JComboBox();
00059         jPanel1 = new javax.swing.JPanel();
00060         jLabel8 = new javax.swing.JLabel();
00061         threshold0Text = new javax.swing.JTextField();
00062         jLabel7 = new javax.swing.JLabel();
00063         delay0Text = new javax.swing.JTextField();
00064         jLabel10 = new javax.swing.JLabel();
00065         rxFibre0Combo = new javax.swing.JComboBox();
00066         jPanel2 = new javax.swing.JPanel();
00067         jLabel6 = new javax.swing.JLabel();
00068         threshold1Text = new javax.swing.JTextField();
00069         jLabel5 = new javax.swing.JLabel();
00070         delay1Text = new javax.swing.JTextField();
00071         jLabel11 = new javax.swing.JLabel();
00072         rxFibre1Combo = new javax.swing.JComboBox();
00073 
00074         setLayout(new javax.swing.BoxLayout(this, javax.swing.BoxLayout.Y_AXIS));
00075 
00076         setBorder(new javax.swing.border.TitledBorder("Position " + getPosition()));
00077         serNoLabel.setText(getModuleSerial());
00078         jPanel4.add(serNoLabel);
00079 
00080         removeButton.setText("Remove");
00081         removeButton.addActionListener(new java.awt.event.ActionListener() {
00082             public void actionPerformed(java.awt.event.ActionEvent evt) {
00083                 removeButtonActionPerformed(evt);
00084             }
00085         });
00086 
00087         jPanel4.add(removeButton);
00088 
00089         remapModuleButton.setText("Remap module");
00090         remapModuleButton.addActionListener(new java.awt.event.ActionListener() {
00091             public void actionPerformed(java.awt.event.ActionEvent evt) {
00092                 remapModuleButtonActionPerformed(evt);
00093             }
00094         });
00095 
00096         jPanel4.add(remapModuleButton);
00097 
00098         add(jPanel4);
00099 
00100         jLabel4.setText("Current:");
00101         jPanel3.add(jLabel4);
00102 
00103         currentText.setColumns(4);
00104         currentText.setText("jTextField4");
00105         currentText.setMinimumSize(new java.awt.Dimension(50, 19));
00106         jPanel3.add(currentText);
00107 
00108         jLabel3.setText("Delay:");
00109         jPanel3.add(jLabel3);
00110 
00111         delayText.setColumns(4);
00112         delayText.setText("jTextField7");
00113         jPanel3.add(delayText);
00114 
00115         jLabel2.setText("Mark space:");
00116         jPanel3.add(jLabel2);
00117 
00118         markSpaceText.setColumns(4);
00119         markSpaceText.setText("jTextField3");
00120         jPanel3.add(markSpaceText);
00121 
00122         jLabel1.setText("TX fibre:");
00123         jPanel3.add(jLabel1);
00124 
00125         txFibreCombo.setEditable(true);
00126         txFibreCombo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "default" }));
00127         jPanel3.add(txFibreCombo);
00128 
00129         add(jPanel3);
00130 
00131         jLabel8.setText("Threshold:");
00132         jPanel1.add(jLabel8);
00133 
00134         threshold0Text.setColumns(4);
00135         threshold0Text.setText("jTextField2");
00136         jPanel1.add(threshold0Text);
00137 
00138         jLabel7.setText("Delay:");
00139         jPanel1.add(jLabel7);
00140 
00141         delay0Text.setColumns(4);
00142         delay0Text.setText("jTextField1");
00143         jPanel1.add(delay0Text);
00144 
00145         jLabel10.setText("RX fibre 0:");
00146         jPanel1.add(jLabel10);
00147 
00148         rxFibre0Combo.setEditable(true);
00149         rxFibre0Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "default" }));
00150         jPanel1.add(rxFibre0Combo);
00151 
00152         add(jPanel1);
00153 
00154         jLabel6.setText("Threshold:");
00155         jPanel2.add(jLabel6);
00156 
00157         threshold1Text.setColumns(4);
00158         threshold1Text.setText("jTextField5");
00159         jPanel2.add(threshold1Text);
00160 
00161         jLabel5.setText("Delay:");
00162         jPanel2.add(jLabel5);
00163 
00164         delay1Text.setColumns(4);
00165         delay1Text.setText("jTextField8");
00166         jPanel2.add(delay1Text);
00167 
00168         jLabel11.setText("RX fibre 1:");
00169         jPanel2.add(jLabel11);
00170 
00171         rxFibre1Combo.setEditable(true);
00172         rxFibre1Combo.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "default" }));
00173         jPanel2.add(rxFibre1Combo);
00174 
00175         add(jPanel2);
00176 
00177     }//GEN-END:initComponents
00178 
00179     private void removeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_removeButtonActionPerformed
00180         try {
00181             config.unmapModuleMUR(mur, position);
00182             updateSerial();
00183         } catch(ConfigurationException c) {
00184             JOptionPane.showMessageDialog(null, "Failed to map module to MUR: " + c.detail);
00185         }
00186     }//GEN-LAST:event_removeButtonActionPerformed
00187 
00188     private void remapModuleButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_remapModuleButtonActionPerformed
00189         // Map existing module
00190         ModuleListView moduleList = new ModuleListView(config);
00191 
00192         Vector list = moduleList.getList();
00193 
00194         if(list.size() == 0) {
00195             JOptionPane.showMessageDialog(null, "No modules to select, add in module list");
00196 
00197             JFrame frame = new JFrame("Module list");
00198             frame.getContentPane().add(moduleList);
00199 
00200             frame.addWindowListener(new WindowAdapter() {
00201                     public void windowClosing(WindowEvent e) {
00202                         e.getWindow().dispose();
00203                     }
00204                 });
00205             frame.pack();
00206             frame.setVisible(true);
00207 
00208             return;
00209         }
00210 
00211         Object [] objList = new Object[list.size()];
00212         list.copyInto(objList);
00213                 
00214         String item = (String)JOptionPane
00215             .showInputDialog((JComponent)(evt.getSource()),
00216                              "Select an unused module",
00217                              "Module selector",
00218                              JOptionPane.OK_CANCEL_OPTION,
00219                              null, // JOptionPane.PLAIN_MESSAGE,
00220                              objList,
00221                              objList[0]);
00222 
00223         System.out.println("Found a module! " + item); //  + ": " + list.get(item));
00224 
00225         String sn;
00226         sn = item;
00227 
00228         try {
00229             config.mapModuleMUR(mur, position, mur, (position% 6) + 1, sn);
00230             updateSerial();
00231         } catch(ConfigurationException c) {
00232             JOptionPane.showMessageDialog(null, "Failed to map module to MUR: " + c.detail);
00233         }
00234     }//GEN-LAST:event_remapModuleButtonActionPerformed
00235 
00236     void modifyComponents() {
00237         updateBOCConfig();
00238     }
00239     
00240     void updateBOCConfig() {
00241         int [] mappings = new int[48*3];
00242 
00243         try {
00244             BOCChannelConfig boc = config.getBOCConfig(rod.partition(), rod.crate(), rod.index(), channel); 
00245 
00246             currentText.setText("" + boc.current);
00247             delayText.setText("" + boc.delay);
00248             markSpaceText.setText("" + boc.markSpace);
00249             txFibreCombo.setSelectedItem("" + mappings[channel * 3+0]);
00250             threshold0Text.setText("" + boc.threshold0);
00251             delay0Text.setText("" + boc.delay0);
00252             threshold1Text.setText("" + boc.threshold1);
00253             delay1Text.setText("" + boc.delay1);
00254 
00255 //            addAncestorListener(new CheckDispose(this, position));
00256         } catch(Exception e) {
00257             currentText.setText("0");
00258             delayText.setText("0");
00259             markSpaceText.setText("0");
00260             // txFibreCombo.setSelectedItem("" + mappings[channel * 3+0]);
00261             threshold0Text.setText("0");
00262             delay0Text.setText("0");
00263             threshold1Text.setText("0");
00264             delay1Text.setText("0");
00265         }
00266     }
00267     
00272     public int getMur() {
00273         return this.mur;
00274     }    
00275 
00280     public void setMur(int mur) {
00281         this.mur = mur;
00282     }
00283     
00288     public int getPosition() {
00289         return this.position;
00290     }
00291     
00296     public void setPosition(int position) {
00297         this.position = position;
00298 
00299          setBorder(new javax.swing.border.TitledBorder("Position " + getPosition()));
00300     }
00301     
00306     public Proxies.RodProxy getRod() {
00307         return this.rod;
00308     }
00309     
00314     public void setRod(Proxies.RodProxy rod) {
00315         this.rod = rod;
00316     }
00317     
00322     public int getChannel() {
00323         return this.channel;
00324     }
00325     
00330     public void setChannel(int channel) {
00331         this.channel = channel;
00332 
00333         updateSerial();
00334         updateBOCConfig();
00335     }
00336     
00337     public void updateSerial() {
00338         serNoLabel.setText(getModuleSerial());
00339     }
00340     
00341     public String getModuleSerial() {
00342         if(config == null) {
00343             removeButton.setEnabled(false);
00344             return "No config!";
00345         }
00346 
00347         try {
00348             StringHolder serial = new StringHolder();
00349 
00350             IntHolder MUR = new IntHolder(), num = new IntHolder();
00351 
00352             config.translateFromROD(rod.partition(), rod.crate(), rod.index(), channel, MUR, num);
00353             
00354             setMur(MUR.value);
00355             
00356             config.translateToSN(MUR.value, num.value, serial);
00357 
00358             removeButton.setEnabled(true);
00359             return serial.value;
00360         } catch(ConfigurationException c) {
00361             removeButton.setEnabled(false);
00362             return "Unconfigured";
00363         }
00364     }
00365 
00366     public String getBorderString() {
00367         return "Position " + position;
00368     }
00369     
00374     public sctConf.Configuration getConfig() {
00375         return this.config;
00376     }
00377     
00382     public void setConfig(sctConf.Configuration config) {
00383         this.config = config;
00384     }
00385     
00386     public java.awt.Dimension dimensionOf(java.lang.String string) {
00387         Dimension result = new Dimension(getFontMetrics(getFont()).stringWidth(string), 
00388                                          getFontMetrics(getFont()).getHeight());
00389         System.out.println("Dimension is: " + result);
00390         return result;
00391     }    
00392   
00393     // Variables declaration - do not modify//GEN-BEGIN:variables
00394     private javax.swing.JTextField currentText;
00395     private javax.swing.JTextField delay0Text;
00396     private javax.swing.JTextField delay1Text;
00397     private javax.swing.JTextField delayText;
00398     private javax.swing.JLabel jLabel1;
00399     private javax.swing.JLabel jLabel10;
00400     private javax.swing.JLabel jLabel11;
00401     private javax.swing.JLabel jLabel2;
00402     private javax.swing.JLabel jLabel3;
00403     private javax.swing.JLabel jLabel4;
00404     private javax.swing.JLabel jLabel5;
00405     private javax.swing.JLabel jLabel6;
00406     private javax.swing.JLabel jLabel7;
00407     private javax.swing.JLabel jLabel8;
00408     private javax.swing.JPanel jPanel1;
00409     private javax.swing.JPanel jPanel2;
00410     private javax.swing.JPanel jPanel3;
00411     private javax.swing.JPanel jPanel4;
00412     private javax.swing.JTextField markSpaceText;
00413     private javax.swing.JButton remapModuleButton;
00414     private javax.swing.JButton removeButton;
00415     private javax.swing.JComboBox rxFibre0Combo;
00416     private javax.swing.JComboBox rxFibre1Combo;
00417     private javax.swing.JLabel serNoLabel;
00418     private javax.swing.JTextField threshold0Text;
00419     private javax.swing.JTextField threshold1Text;
00420     private javax.swing.JComboBox txFibreCombo;
00421     // End of variables declaration//GEN-END:variables
00422 
00424     private int mur;
00425     
00427     private int position;
00428     
00430     private Proxies.RodProxy rod;
00431     
00433     private int channel;
00434     
00436     private sctConf.Configuration config;
00437 
00438     class CheckDispose implements AncestorListener {
00439         ChannelParamsPanel chan;
00440 
00441         public CheckDispose(ChannelParamsPanel m) {
00442             chan = m;
00443         }
00444 
00445         public void ancestorAdded(AncestorEvent e) {
00446         }
00447 
00448         public void ancestorMoved(AncestorEvent e) {
00449         }
00450 
00451         public void ancestorRemoved(AncestorEvent e) {
00452             System.out.println("Ancestor removed on mur: " + mur + " position: " + position);
00453             if(chan.mur >= 0 ) {
00454                 BOCChannelConfig bConf = new BOCChannelConfig();
00455 
00456                 try {
00457                     bConf.current = Short.parseShort(chan.currentText.getText());
00458                     bConf.delay = Short.parseShort(chan.delayText.getText());
00459                     bConf.markSpace = Short.parseShort(chan.markSpaceText.getText());
00460                     bConf.threshold0 = Short.parseShort(chan.threshold0Text.getText());
00461                     bConf.delay0 = Short.parseShort(chan.delay0Text.getText());
00462                     bConf.threshold1 = Short.parseShort(chan.threshold1Text.getText());
00463                     bConf.delay1 = Short.parseShort(chan.delay1Text.getText());
00464                 } catch(NumberFormatException ex) {
00465                 } catch(NullPointerException ex) {
00466                 }
00467 
00468                 try {
00469                     config.configureBOCChannel(chan.mur, chan.position, bConf);
00470                 } catch(ConfigurationException ex) {
00471                     JOptionPane.showMessageDialog(null, "Failed to update configuration for mur " + chan.mur + ": " + ex.detail);
00472                 }
00473             }
00474         }
00475     }
00476 }

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