SelectorPane.java

00001 package DisplayGUI;
00002 import java.awt.*;
00003 import java.awt.event.*;
00004 import javax.swing.*;
00005 import javax.swing.event.*;
00006 
00007 import java.util.*;
00008 
00009 //SelectorPane itself is not a visible component.
00010 public class SelectorPane extends JPanel implements ListSelectionListener,displayParams,SCTInfo,TestDataInfo {
00011     private JList displayParameters, sctViews, mouseOptions, viewCategories;
00012     private JSplitPane splitPane;
00013     private String[] defaultString = {"...None"};
00014     private String[] resultStatusString = {"Overall Status"};
00015     private String[] defectCountString = {"Total Count"};
00016     private String[] dataString = {"Module Data"};
00017         private String[] viewCats={"SCT Views","ROD Crates"};
00018     private String[][] displayParameterStrings = {
00019                         {},
00020                         {},
00021                         {"Module Probe"},
00022                         {"Raw Data","Fitted Data","Analysed Data"},
00023                         {},
00024                         {},
00025                         {},
00026                         {},
00027                                 {"Result Status","IVScan Data","DCS Conditions"}
00028                        };
00029     private String[][] mouseOptionStrings = {
00030                         {},
00031                         {"Group 0","Group 1","Group 2","Group 3","Group 4","Group 5","Group 6","Group 7"},
00032                         {"Link 0","Link 1"},
00033                         {"Object Count"},
00034                         {},
00035                         {},
00036                                                 {},
00037                                                 {"Current Conditions"},
00038                                                 {}
00039                         };
00040     private gui guiControl;
00041 
00042     private boolean selectionListenerIsActive=true;
00043 
00044     private Map viewMap;
00045 
00046 
00047     public SelectorPane(gui parent) {
00048         guiControl=parent;
00049 
00050         buildViewMap();
00051 
00052                 sctViews = new JList();
00053                 viewCategories = new JList();
00054                 displayParameters = new JList();
00055         mouseOptions = new JList();
00056 
00057                 viewCategories.setListData(viewCats);
00058                 sctViews.setListData(SCTViewNames);
00059 
00060         int viewIndex=0;
00061         try {
00062          Preferences.PreferencesInterface prefs = Preferences.PreferencesInterface.getInstance();
00063          String preferredView = prefs.getPreference(Preferences.PreferencesInterface.SCT_VIEW);
00064          if(!preferredView.equals(Preferences.PreferencesInterface.unDefinedString)) {
00065             Integer i1 = (Integer)viewMap.get(preferredView);
00066             if(i1!=null) viewIndex = i1.intValue();
00067             }
00068         }catch(Exception e){}
00069         sctViews.setSelectedIndex(viewIndex);
00070                 viewCategories.setSelectedIndex(0);
00071 
00072                 JScrollPane viewScrollPane = defineScrollPane(sctViews,"View Options");
00073                 JScrollPane viewCategoryScrollPane = defineScrollPane(viewCategories,"Views");
00074                 JScrollPane paramScrollPane = defineScrollPane(displayParameters,"Data");
00075                 JScrollPane mouseScrollPane = defineScrollPane(mouseOptions,"Data Options");
00076 
00077         //Create a split pane with the two scroll panes in it
00078         JSplitPane topSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, paramScrollPane, mouseScrollPane);
00079         topSplit.setDividerSize(8);
00080         topSplit.setDividerLocation(0.50);
00081         topSplit.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
00082 
00083         JSplitPane bottomSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, viewCategoryScrollPane, viewScrollPane);
00084         bottomSplit.setDividerSize(8);
00085         bottomSplit.setDividerLocation(0.25);
00086         bottomSplit.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
00087 
00088         splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT,
00089                                    topSplit, bottomSplit);
00090 //        splitPane.setOneTouchExpandable(true);
00091         splitPane.setDividerLocation(0.6);
00092         splitPane.setDividerSize(8);
00093         splitPane.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
00094 
00095         //Provide minimum sizes for the two components in the split pane
00096         Dimension minimumSize = new Dimension(95, 16);
00097         paramScrollPane.setMinimumSize(minimumSize);
00098         mouseScrollPane.setMinimumSize(minimumSize);
00099         viewScrollPane.setMinimumSize(minimumSize);
00100                 viewCategoryScrollPane.setMinimumSize(minimumSize);
00101 
00102         //Provide a preferred size for the split pane
00103         splitPane.setPreferredSize(new Dimension(95,yOffSet+56*boxHeight)); 
00104         add(splitPane);
00105         setBackground(backgroundColor);
00106         setBorder(new javax.swing.border.TitledBorder(null, "Display", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 0, 11), new java.awt.Color(0, 0, 153)));
00107 
00108     }
00109 
00110 
00111         private JScrollPane defineScrollPane(JList list, String title) {
00112         list.setFont(displayScaleFont);
00113         list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
00114         list.addListSelectionListener(this);
00115         JScrollPane scrollPane = new JScrollPane(list);
00116         JLabel header = new JLabel(title);
00117         header.setForeground(darkBlueColor);
00118         header.setBackground(backgroundColor);
00119         header.setFont(displayTextFont);
00120         scrollPane.setColumnHeaderView(header);
00121         scrollPane.getColumnHeader().setBackground(backgroundColor);
00122         scrollPane.setBorder(new javax.swing.border.EmptyBorder(0,0,0,0));
00123         scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
00124         scrollPane.getVerticalScrollBar().setBackground(backgroundColor);
00125                 return scrollPane;
00126                 }
00127                 
00128     public void initParamList() {
00129 
00130         selectionListenerIsActive=false;
00131 
00132         int displayType = guiControl.displayStatus.getStatus();
00133         boolean noParameters=true, noOptions=true, noViews=false;
00134         int previousParameterSelection = getDisplayParameterIndex();
00135         int previousOptionSelection = getMouseClickIndex();
00136                 int previousViewCategorySelection = getViewCategoryIndex();
00137                 int previousViewSelection = getViewIndex();
00138 
00139                 // first rebuild the views
00140                 if(previousViewCategorySelection==ConfigurationInterface.SCT_VIEWS) {
00141                         sctViews.setListData(SCTViewNames);
00142                         }
00143                 else {
00144                         Set viewList = ConfigurationInterface.getInstance().getRodCrateViewMap().keySet();
00145                         if(viewList.size()>0) sctViews.setListData(viewList.toArray());
00146                         else noViews=true;
00147                         }
00148 
00149         int nParams = sctViews.getModel().getSize();
00150         int selectionIndex=0;
00151 
00152         if(nParams>0) {
00153            if(previousViewSelection<nParams && previousViewSelection>=0) selectionIndex=previousViewSelection;
00154            else if(previousViewSelection>=nParams) selectionIndex =sctViews.getLastVisibleIndex();
00155                    sctViews.setSelectedIndex(selectionIndex);
00156            }
00157                 if(noViews) sctViews.setListData(defaultString);
00158 
00159         TestSelection testSelection = guiControl.tablesDisplayPane.getTestSelection();
00160         int testIndex = (testSelection!=null) ? testSelection.getTestIndex() : -1;
00161 
00162         if(displayType==DisplayStatus.UNDEFINED) {
00163                         selectionListenerIsActive=true;
00164                         return;
00165                         }
00166         switch(displayType) {
00167             case DisplayStatus.MODULE_GROUP_SELECTION:
00168                 displayParameters.setListData(configParams);
00169                         // if not yet defined, or module group selection, set module group selection
00170                         if(previousParameterSelection<=0) mouseOptions.setListData(mouseOptionStrings[displayType]);
00171                         // otherwise could be link options or no options
00172                         else {
00173                                 if(configParams_links[previousParameterSelection])mouseOptions.setListData(linkOptions);
00174                                 else mouseOptions.setListData(dataString);
00175                                 }
00176                noParameters=false;
00177                noOptions=false;
00178                break;
00179             case DisplayStatus.IS_MONITOR:
00180                displayParameters.setListData(displayParameterStrings[displayType]);
00181                            mouseOptions.setListData(mouseOptionStrings[displayType]);
00182                noParameters=false;
00183                noOptions=false;
00184                break;
00185             case DisplayStatus.TEST_DATA:
00186                 case DisplayStatus.SCTDB_DATA:
00187                 case DisplayStatus.SCTDB_RODDAQ_DATA:
00188                if(testIndex!=-1 && testIndex!=TEST_DEFAULT) {
00189                     displayParameters.setListData(testParameters[testIndex]);
00190                     noParameters=false;
00191                     switch(previousParameterSelection) {
00192                     case 0: // Result Status
00193                     case -1: // no previous selection - will be set to 0 by default
00194                         mouseOptions.setListData(resultStatusString);
00195                         noOptions=false;
00196                         break;
00197                     case 1: // Defect count
00198                                 case 2: // bad channel count
00199                         mouseOptions.setListData(defectCountString);
00200                         noOptions=false;
00201                         break;
00202                     case 3:
00203                         mouseOptions.setListData(dcsOptions);
00204                         noOptions=false;
00205                         break;
00206                     default:
00207                         if(testIndex==TEST_RXTHRESHOLD || testIndex==TEST_RXTHRESHOLDBASEDONCONFIGREGISTER ||testIndex==TEST_RXDELAY) mouseOptions.setListData(linkOptions);
00208                         else mouseOptions.setListData(chipOptions);
00209                         noOptions=false;
00210                         }
00211                     }
00212 
00213                break;
00214             case DisplayStatus.DCS_DATA:
00215                displayParameters.setListData(dcsOptions);
00216                noParameters=false;
00217                mouseOptions.setListData(mouseOptionStrings[displayType]);
00218                noOptions=false;
00219                break;
00220             case DisplayStatus.IV_DATA:
00221                IVTestSelection iv = guiControl.tablesDisplayPane.getIVTestSelection();
00222                if(iv==null) {
00223                  displayParameters.setListData(defaultString);
00224                  noParameters=true;
00225                  mouseOptions.setListData(defaultString);
00226                  noOptions=true;
00227                  }
00228               else {
00229                  displayParameters.setListData(displayParameterStrings[displayType]);
00230                  noParameters=false;
00231                  switch(previousParameterSelection) {
00232                     case 0:
00233                     case -1: // no previous selection - will be set to 0 by default
00234                         mouseOptions.setListData(resultStatusString);
00235                         noOptions=false;
00236                         break;
00237                     case 1:                      
00238                         mouseOptions.setListData(iv.getVList());
00239                         noOptions=false;
00240                         break;
00241                     case 2:                      
00242                         mouseOptions.setListData(dcsOptions);
00243                         noOptions=false;
00244                         break;
00245                         }
00246                  }
00247                break;
00248              case DisplayStatus.PROBE_DATA:
00249                  displayParameters.setListData(displayParameterStrings[displayType]);
00250                noParameters=false;
00251                mouseOptions.setListData(mouseOptionStrings[displayType]);
00252                noOptions=false;
00253                break;
00254 
00255             case DisplayStatus.UNDEFINED:
00256             default:
00257               displayParameters.setListData(defaultString);
00258               mouseOptions.setListData(defaultString);
00259             }
00260 
00261         int numParameters = displayParameters.getModel().getSize();
00262         selectionIndex=0;
00263         if(numParameters>0) {
00264            if(previousParameterSelection<numParameters && previousParameterSelection>=0) selectionIndex=previousParameterSelection;
00265            else if(previousParameterSelection>=numParameters) selectionIndex =displayParameters.getLastVisibleIndex();
00266                    displayParameters.setSelectedIndex(selectionIndex);
00267            }
00268 
00269         numParameters = mouseOptions.getModel().getSize();
00270         selectionIndex=0;
00271         if(numParameters>0) {
00272             if(previousOptionSelection<numParameters && previousOptionSelection>=0) selectionIndex= previousOptionSelection;
00273             else if(previousOptionSelection>=numParameters) selectionIndex = mouseOptions.getLastVisibleIndex();
00274                         mouseOptions.setSelectedIndex(selectionIndex);
00275             }
00276 
00277         if(noParameters) displayParameters.setListData(defaultString);
00278         if(noOptions) mouseOptions.setListData(defaultString);
00279 
00280         setVisible(true);
00281         selectionListenerIsActive=true;
00282     }
00283    public String getIVParameter() {
00284      if(getDisplayParameterIndex()==0) return "Result Status";
00285      return getOption();
00286      }
00287 
00288    public int getDisplayParameterIndex() {
00289      return displayParameters.getSelectedIndex();
00290      }
00291    public int getMouseClickIndex() {
00292      return mouseOptions.getSelectedIndex();
00293      }
00294    public void setMouseClickIndex(int row) {
00295      mouseOptions.setSelectedIndex(row);
00296      }
00297    public int getViewIndex() {
00298      return sctViews.getSelectedIndex();
00299      }
00300 
00301    public int getViewCategoryIndex() {
00302          return viewCategories.getSelectedIndex();
00303          }
00304    public String getOption() {
00305       if(getMouseClickIndex()==-1) return null;
00306       return (String)mouseOptions.getSelectedValue();
00307       }
00308    public String getDisplayParameter() {
00309      if(getDisplayParameterIndex()==-1) return null;
00310      return (String)displayParameters.getSelectedValue();
00311      }
00312    public String getViewName() {
00313         if(getViewIndex()<0) return null;
00314         return (String)sctViews.getSelectedValue();
00315         }
00316 
00317     public JSplitPane getSplitPane() {
00318         return splitPane;
00319     }
00320 
00321     public void valueChanged(ListSelectionEvent e) {
00322 
00323                 if(!selectionListenerIsActive) return;
00324         if (e.getValueIsAdjusting()) return;
00325         JList theList = (JList)e.getSource();
00326         if (theList.isSelectionEmpty()) return;  // huh?
00327 
00328         int index = theList.getSelectedIndex();
00329 
00330         if(theList==sctViews) {
00331                 guiControl.tablesDisplayPane.updateTables();
00332             return;
00333             }
00334 
00335                 if(theList==viewCategories) {  // change of view category, requires change in view options
00336                         initParamList();
00337                 guiControl.tablesDisplayPane.updateTables();
00338                         return;
00339                         }
00340 
00341         switch(guiControl.displayStatus.getStatus()) {
00342             case DisplayStatus.MODULE_GROUP_SELECTION:
00343                         if(theList==displayParameters) {
00344                                 initParamList(); // in case the mouse option list needs changing
00345                                 if(getDisplayParameterIndex()>0) SctApiInfo.getInstance().probeConfig(getViewCategoryIndex(),getViewIndex(),getDisplayParameterIndex());
00346                                 }
00347                 guiControl.tablesDisplayPane.updateTables(true); // for module group, just update tables
00348                   guiControl.colorScalePane.setColorScale();
00349                   guiControl.displayPane.setDisplayColors();
00350                         guiControl.displayPane.refreshDisplay();
00351                         //if(getDisplayParameterIndex()>0)guiControl.tablesDisplayPane.listTestResults();
00352                 break;
00353             case DisplayStatus.IS_MONITOR:
00354 //              guiControl.isInterface.setServerName(index);
00355                 guiControl.tablesDisplayPane.checkForRetrievedObjects();
00356                 guiControl.colorScalePane.setColorScale();
00357                 guiControl.displayPane.setDisplayColors();
00358                 guiControl.displayPane.refreshDisplay();
00359                 guiControl.tablesDisplayPane.listISObjects(guiControl.displayPane.getLastClickedCell());
00360                 break;
00361                 case DisplayStatus.TEST_DATA:
00362                 case DisplayStatus.SCTDB_DATA:
00363                         case DisplayStatus.SCTDB_RODDAQ_DATA:
00364                 if(theList==displayParameters) initParamList();
00365                 guiControl.colorScalePane.setColorScale();
00366                 guiControl.displayPane.setDisplayColors();
00367                 guiControl.displayPane.refreshDisplay();
00368                 guiControl.tablesDisplayPane.listTestResults();
00369                         break;
00370                         case DisplayStatus.DCS_DATA:
00371                         if(theList==displayParameters) { // must resubscribe, depending on which DCS data we are looking at
00372                                 guiControl.isInterface.unsubscribe();
00373                                         guiControl.isInterface.subscribe();
00374                                         }
00375                         guiControl.colorScalePane.setColorScale();
00376                 guiControl.displayPane.setDisplayColors();
00377                 guiControl.displayPane.refreshDisplay();
00378                 guiControl.tablesDisplayPane.listTestResults();
00379                 break;
00380                         case DisplayStatus.IV_DATA:
00381                         case DisplayStatus.PROBE_DATA:
00382                 if(theList==displayParameters) initParamList();
00383                 guiControl.colorScalePane.setColorScale();
00384                 guiControl.displayPane.setDisplayColors();
00385                 guiControl.displayPane.refreshDisplay();
00386                 guiControl.tablesDisplayPane.listTestResults();
00387                         break;
00388                 default:
00389                 }
00390 
00391     }
00392   private void buildViewMap() {
00393      viewMap = new HashMap();
00394      for(int i=0;i<SCTViewNames.length;i++) viewMap.put(SCTViewNames[i], new Integer(i));
00395      }
00396   public void setSCTView(String value) {
00397      if(!viewMap.containsKey(value)) return;
00398      sctViews.setSelectedIndex(((Integer)viewMap.get(value)).intValue());
00399          guiControl.tablesDisplayPane.updateTables();
00400      }
00401 
00402 
00403 }

Generated on Mon Feb 6 14:12:19 2006 for SCT DAQ/DCS Software - Java by  doxygen 1.4.6