00001
00002
00003
00004
00005
00006
00007 package DisplayGUI;
00008 import javax.swing.JTable;
00009 import javax.swing.event.*;
00010 import javax.swing.ListSelectionModel;
00011 import javax.swing.table.TableModel;
00012 import javax.swing.event.ListSelectionListener;
00013 import javax.swing.event.ListSelectionEvent;
00014 import java.util.Hashtable;
00015 import java.util.Collections;
00016 import java.util.Vector;
00017
00022 public class GuiTable implements displayParams,TableModelListener {
00023 gui guiControl;
00024 guiTableAdapter resultTable = new guiTableAdapter();
00025 JTable table = new JTable();
00026 Vector objectNames = new Vector();
00027 ListSelectionModel rowSM;
00028 String title;
00029 public javax.swing.JLabel tableTitle;
00030 boolean selectionListenerIsActive=true;
00031
00032 public GuiTable(gui parent) {
00033 guiControl=parent;
00034 title=null;
00035 tableTitle=new javax.swing.JLabel("");
00036 resultTable = new guiTableAdapter();
00037 table = new JTable(resultTable) {
00038 public String getToolTipText(java.awt.event.MouseEvent e) {
00039 TableModel model = getModel();
00040 int rowSelect = this.rowAtPoint(new java.awt.Point(e.getX(),e.getY()));
00041 if(rowSelect<0) return null;
00042 String sn = (String)model.getValueAt(rowSelect,0);
00043 if(sn.matches("\\d{14}")) {
00044 ConfigurationInterface config = ConfigurationInterface.getInstance();
00045 ModuleCell thisCell = config.getModuleCell(sn);
00046 StringBuffer infoString = new StringBuffer(sn+" - ");
00047 infoString.append("MUR "+thisCell.getMUR()+", Row "+thisCell.getRow()+", Position "+thisCell.getPosition());
00048 infoString.append(", ROD Crate "+config.getSNInfo(sn,SNInfo.ROD_CRATE)+", ROD Slot "+config.getSNInfo(sn,SNInfo.ROD_NUMBER)+", ROD Channel "+config.getSNInfo(sn,SNInfo.ROD_CHANNEL));
00049 infoString.append(", PS Crate "+config.getSNInfo(sn,SNInfo.DCS_CRATE)+", PS Channel "+config.getSNInfo(sn,SNInfo.DCS_CHANNEL));
00050 return infoString.toString();
00051 }
00052 else return null;
00053 }
00054 };
00055 rowSM = table.getSelectionModel();
00056 table.setFont(tableFont);
00057
00058 }
00059
00060 public JTable getTable() {
00061 return table;
00062 }
00063 public void setSelectedSerialNo(String sn, boolean changeSelection) {
00064 int is = rowSM.getMinSelectionIndex();
00065 if(is!=-1 && !changeSelection) return;
00066 for(int i=0;i<resultTable.getRowCount();i++) {
00067 if(sn.equals((String)resultTable.getValueAt(i,0))) {
00068 rowSM.setSelectionInterval(i,i);
00069 break;
00070 }
00071 }
00072 }
00073
00074 public int getRowCount() {
00075 return resultTable.getRowCount();
00076 }
00077
00078 public String getSelectedObject() {
00079 if(objectNames==null) return null;
00080 int selectedRow = rowSM.getMinSelectionIndex();
00081 if(selectedRow==-1 || objectNames.size()==0 || selectedRow>objectNames.size()-1) return null;
00082 return (String)objectNames.elementAt(selectedRow);
00083 }
00084
00085 public int getSelectedIndex() {
00086 return rowSM.getMinSelectionIndex();
00087 }
00088
00089 public void setTableContent(Vector data) {
00090 objectNames=data;
00091 }
00092 public Vector getObjectNames() {
00093 return objectNames;
00094 }
00095 public void addTableObject(String theObjectName) {
00096 if(objectNames==null) return;
00097 if(!objectNames.contains(theObjectName)) objectNames.addElement(theObjectName);
00098 }
00099
00100 public void removeTableObject(String theObjectName) {
00101 if(objectNames.contains(theObjectName)) objectNames.removeElement(theObjectName);
00102 }
00103
00104 public void tableChanged(javax.swing.event.TableModelEvent e) {
00105 updateTitle();
00106 }
00107
00108 public void updateTitle() {
00109 tableTitle.setText((title==null) ? "" : title+" : "+Integer.toString(resultTable.getRowCount()));
00110 }
00111
00112 public void setTitle(String title) {
00113 this.title=title;
00114 updateTitle();
00115 }
00116 public void refresh(Vector newObjectNames, Vector tableContents, String title) {
00117 objectNames = new Vector(newObjectNames);
00118 refresh(tableContents,title);
00119 }
00120 public void refresh(Vector tableContents, String title) {
00121 selectionListenerIsActive=false;
00122 int oldSelect = rowSM.getMinSelectionIndex();
00123 resultTable.reTable(tableContents);
00124 if(oldSelect>=0 && oldSelect<=tableContents.size()-1) rowSM.setSelectionInterval(oldSelect,oldSelect);
00125 selectionListenerIsActive=true;
00126 javax.swing.table.TableColumn column = table.getColumnModel().getColumn(0);
00127 column.setPreferredWidth(110);
00128 setTitle(title);
00129 }
00130 public void refresh(Vector tableContents, int rowSelection) {
00131 selectionListenerIsActive=false;
00132 resultTable.reTable(tableContents);
00133 javax.swing.table.TableColumn column = table.getColumnModel().getColumn(0);
00134 column.setPreferredWidth(110);
00135 selectionListenerIsActive=true;
00136 if(rowSelection>=0 && rowSelection<=tableContents.size()-1) rowSM.setSelectionInterval(rowSelection,rowSelection);
00137 }
00138 }