00001 package GuiComponents.SctApi;
00002
00003 import javax.swing.*;
00004 import java.awt.*;
00005 import java.awt.event.*;
00006 import javax.swing.table.TableModel;
00007 import javax.swing.table.TableColumn;
00008 import javax.swing.table.JTableHeader;
00009
00010 public class AutoConfigure extends JPanel {
00011 Sct_SctApi.SctApi api;
00012
00013 ResultsTableModel tableModel;
00014
00015 Sct_SctApi.AutoConfigResult[] autoResults;
00016
00017 int suggestedRx[];
00018
00019 public AutoConfigure(Sct_SctApi.SctApi a) {
00020 api = a;
00021
00022 tableModel = new AutoConfigure.ResultsTableModel();
00023 autoResults = null;
00024
00025 initComponents();
00026 modifyComponents();
00027 }
00028
00029
00030 public AutoConfigure() {
00031 initComponents();
00032 autoResults = null;
00033 modifyComponents();
00034 }
00035
00036 public void modifyComponents() {
00037
00038
00039 int columnWidth = jTable1.getFontMetrics(jTable1.getFont()).stringWidth("mmmmmm");
00040
00041
00042 TableColumn column = jTable1.getColumnModel().getColumn(0);
00043 column.setPreferredWidth(columnWidth * 8);
00044 }
00045
00051 private void initComponents() {
00052 jPanel1 = new javax.swing.JPanel();
00053 jButton4 = new javax.swing.JButton();
00054 jPanel3 = new javax.swing.JPanel();
00055 jPanel4 = new javax.swing.JPanel();
00056 jButton2 = new javax.swing.JButton();
00057 jButton3 = new javax.swing.JButton();
00058 jScrollPane1 = new javax.swing.JScrollPane();
00059 jTable1 = new javax.swing.JTable();
00060
00061 setLayout(new java.awt.BorderLayout());
00062
00063 jPanel1.setOpaque(false);
00064 jButton4.setText("Close");
00065 jButton4.addActionListener(new java.awt.event.ActionListener() {
00066 public void actionPerformed(java.awt.event.ActionEvent evt) {
00067 closeButtonPerformed(evt);
00068 }
00069 });
00070
00071 jPanel1.add(jButton4);
00072
00073 add(jPanel1, java.awt.BorderLayout.SOUTH);
00074
00075 jPanel3.setLayout(new java.awt.BorderLayout());
00076
00077 jPanel4.setLayout(new javax.swing.BoxLayout(jPanel4, javax.swing.BoxLayout.X_AXIS));
00078
00079 jButton2.setText("Perform scan");
00080 jButton2.addActionListener(new java.awt.event.ActionListener() {
00081 public void actionPerformed(java.awt.event.ActionEvent evt) {
00082 performScanActionPerformed(evt);
00083 }
00084 });
00085
00086 jPanel4.add(jButton2);
00087
00088 jButton3.setText("Enact configuration changes");
00089 jPanel4.add(jButton3);
00090
00091 jPanel3.add(jPanel4, java.awt.BorderLayout.NORTH);
00092
00093 jTable1.setFont(new java.awt.Font("Monospaced", 0, 12));
00094 jTable1.setModel(getScanResultsTableModel());
00095 jScrollPane1.setViewportView(jTable1);
00096
00097 jPanel3.add(jScrollPane1, java.awt.BorderLayout.CENTER);
00098
00099 add(jPanel3, java.awt.BorderLayout.CENTER);
00100
00101 }
00102
00103 private void performScanActionPerformed(java.awt.event.ActionEvent evt) {
00104
00105 try {
00106 autoResults = api.autoConfigureScan();
00107
00108 updateScanResults();
00109 } catch(Sct_SctApi.SctApiException e) {
00110 javax.swing.JOptionPane.showMessageDialog(null, "Failed autoConfigureScan: " + e);
00111 }
00112 }
00113
00114 private void closeButtonPerformed(java.awt.event.ActionEvent evt) {
00115 ((Window)getTopLevelAncestor()).dispose();
00116 }
00117
00118 TableModel getScanResultsTableModel() {
00119 return tableModel;
00120 }
00121
00122 void updateScanResults() {
00123 tableModel.newData();
00124
00125 suggestedRx = new int[autoResults.length];
00126
00127
00128 for(int i=0; i<autoResults.length; i++) {
00129 suggestedRx[i] = autoResults[i].rx;
00130 }
00131 }
00132
00133 void enactConfigurationChanges() {
00134 sctConf.Configuration conf = GuiComponents.System.SystemInterface.getInstance().getConfigurationService();
00135
00136 for(int i=0; i<autoResults.length; i++) {
00137 try {
00138 conf.setFibreMapping(autoResults[i].partition, autoResults[i].crate, autoResults[i].rod,
00139 autoResults[i].tx, autoResults[i].tx, suggestedRx[i] * 2, suggestedRx[i] * 2 + 1);
00140 } catch(sctConf.ConfigurationException e) {
00141 JOptionPane.showMessageDialog(null, "Failed to set mapping for scan member " + i + ": " + e);
00142 }
00143 }
00144
00145 JOptionPane.showMessageDialog(null, "The mappings have been set as shown.\n"
00146 + " This automated procedure may be confused by settings of the select line from DCS\n"
00147 + " or by incorrectly ordered fibres within a bundle");
00148 }
00149
00150 class ResultsTableModel extends javax.swing.table.AbstractTableModel {
00151 public ResultsTableModel() {
00152 }
00153
00154 public void newData() {
00155 fireTableStructureChanged();
00156 }
00157
00158 public int getColumnCount() {
00159 return 6;
00160 }
00161
00162 public int getRowCount() {
00163 if(autoResults == null) return 0;
00164 return autoResults.length;
00165 }
00166
00167 public Object getValueAt(int rowIndex, int columnIndex) {
00168 if(columnIndex == 0) {
00169 return "" + autoResults[rowIndex].partition;
00170 } else if(columnIndex == 1) {
00171 return "" + autoResults[rowIndex].crate;
00172 } else if(columnIndex == 2) {
00173 return "" + autoResults[rowIndex].rod;
00174 } else if(columnIndex == 3) {
00175 return "" + autoResults[rowIndex].tx;
00176 } else if(columnIndex == 4) {
00177 return "" + autoResults[rowIndex].rx;
00178 } else if(columnIndex == 5) {
00179 return "" + suggestedRx[rowIndex];
00180 } else {
00181 return "Unexpected request";
00182 }
00183 }
00184
00185 public String getColumnName(int columnIndex) {
00186 String retValue;
00187
00188 if(columnIndex == 0) {
00189 retValue = "Partition";
00190 } else if(columnIndex == 1) {
00191 retValue = "Crate";
00192 } else if(columnIndex == 2) {
00193 retValue = "ROD";
00194 } else if(columnIndex == 3) {
00195 retValue = "Tx channel";
00196 } else if(columnIndex == 4) {
00197 retValue = "Rx channel";
00198 } else if(columnIndex == 5) {
00199 retValue = "Rx suggested";
00200 } else {
00201 columnIndex--;
00202 retValue = "Column " + columnIndex;
00203 }
00204
00205 return retValue;
00206 }
00207 }
00208
00209
00210 private javax.swing.JButton jButton2;
00211 private javax.swing.JButton jButton3;
00212 private javax.swing.JButton jButton4;
00213 private javax.swing.JPanel jPanel1;
00214 private javax.swing.JPanel jPanel3;
00215 private javax.swing.JPanel jPanel4;
00216 private javax.swing.JScrollPane jScrollPane1;
00217 private javax.swing.JTable jTable1;
00218
00219 }