1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287
|
/*
*
* Copyright (C) 1999, Institute for MicroTherapy
*
* This software and supporting documentation were developed by
*
* University of Witten/Herdecke
* Department of Radiology and MicroTherapy
* Institute for MicroTherapy
* Medical computer science
*
* Universitaetsstrasse 142
* 44799 Bochum, Germany
*
* http://www.microtherapy.de/go/cs
* mailto:computer.science@microtherapy.de
*
* THIS SOFTWARE IS MADE AVAILABLE, AS IS, AND THE INSTITUTE MAKES NO
* WARRANTY REGARDING THE SOFTWARE, ITS PERFORMANCE, ITS MERCHANTABILITY
* OR FITNESS FOR ANY PARTICULAR USE, FREEDOM FROM ANY COMPUTER DISEASES
* OR ITS CONFORMITY TO ANY SPECIFICATION. THE ENTIRE RISK AS TO QUALITY
* AND PERFORMANCE OF THE SOFTWARE IS WITH THE USER.
*
* Author : $Author: kleber $
* Last update : $Date: 2001/06/06 10:32:30 $
* Revision : $Revision: 1.1.1.1 $
* State: $State: Exp $
*/
package processCommunication;
import java.awt.BorderLayout;
import java.awt.event.*;
import java.util.*;
import javax.swing.*;
import javax.swing.table.*;
import javax.swing.event.*;
import javax.swing.text.*;
/**
*
*/
public final class ProcessTable extends JTable
{
private TableData tableData; // die Tabellendaten
private JTextArea textArea;
private boolean sortUp = false;
Object[] columnIdentifiers = {"Status","Process Type","Process Id","Date","Message Type","Text"};
// Konstruktion des Tabellen-Dialogs
public ProcessTable(JTextArea textArea, Vector messageList, java.awt.Font f)
{
super();
this.textArea =textArea;
textArea.setFont(f);
//init model
tableData = new TableData(columnIdentifiers);
setModel(tableData); // Konstruktion der sichtbaren Tabelle
// init table
getColumnModel().removeColumn(getColumn("Text"));
getColumnModel ().getColumn (0).setPreferredWidth (80);
getColumnModel ().getColumn (1).setPreferredWidth (80);
getColumnModel ().getColumn (2).setPreferredWidth (80);
getColumnModel ().getColumn (3).setPreferredWidth (200);
setAutoResizeMode (AUTO_RESIZE_LAST_COLUMN);
// init selection
setSelectionMode(ListSelectionModel.SINGLE_SELECTION); // immer nur eine Zeile auswhlbar
getSelectionModel().addListSelectionListener(new SelectRowListener(textArea));
// init Mouse Listener
getTableHeader().addMouseListener(new TableMouseListener()); // Mausaktion im Header abfangen
}
/**
* Sort the table.
* @param index Specifies the colum to be sorted
*/
private void sort (int index)
{
if (sortUp)
{// Bubblesort
for(int i = 0; i < tableData.getRowCount(); i++)
{
for(int j = i + 1; j < tableData.getRowCount(); j++)
{
if (tableData.compareTo(index, i, j) > 0)
{
tableData.swapRows(i, j);
}
}
}
sortUp = false;
}
else
{
for(int i = 0; i < tableData.getRowCount(); i++)
{
for(int j = i + 1; j < tableData.getRowCount(); j++)
{
if (tableData.compareTo(index, i, j) < 0)
{
tableData.swapRows(i, j);
}
}
}
sortUp = true;
}
repaint(); // Tabelle neuzeichnen
}
/**
* Inserts the specified DicomScopeMessage as a row
*/
public void insertData(DicomScopeMessage m)
{
Object[] o = {m.statusName,m.processTypeName,new Integer(m.processId),m.date,m.messageName,m.text};
tableData.addRow(o);
}
/**
* Deletes all Rows
*/
public void deleteAll()
{
tableData.setRowCount(0);
}
/**
* This class extends the DefaultTableModel do that the needed
* columnIdentifiers
*
*/
private class TableData extends DefaultTableModel
{
int[][] sortMatrix = {
{ 3, 2, 3, 3, 3 }, /* second column: second sort criterion */
{ 3, 3, 3, 3, 3 } /* third column: third sort criterion */
};
/**
* Checks if row1< row2. The type of comparison is defined by cols.
* @return 0 if equals, -1 if row1 < row2, 1 if row1>row2.
*/
public int compareTo(int col, int row1, int row2)
{
int secondCriterion=sortMatrix[0][col];
int thirdCriterion=sortMatrix[1][col];
int result = ((Comparable)tableData.getValueAt(row1, col)).compareTo((tableData.getValueAt(row2, col)));
if (result == 0) result = ((Comparable)tableData.getValueAt(row1, secondCriterion)).compareTo((tableData.getValueAt(row2, secondCriterion)));
if (result == 0) result = ((Comparable)tableData.getValueAt(row1, thirdCriterion)).compareTo((tableData.getValueAt(row2, thirdCriterion)));
return result;
}
/**
* Constructor. Sets the colum identifiers.
* @param columnIdentifiers column identifiers
*/
public TableData(Object[] columnIdentifiers)
{
super(columnIdentifiers,0);
}
/**
* Sets an editable
*/
public boolean isCellEditable(int row, int cols)
{
return false;
}
/**
* Returns the index of the invislibe cols
*/
public int[] getInvisibleColumns()
{
//Number of cols in the model
int cols = getColumnCount(); // Anzahl der Spalten merken
//init array with size of invisible cols
//( cols of the modle - cols of the table
int[] invisible = new int[cols - getColumnCount()];
//Fills array
for(int i = 0, j = 0; i < cols; i++) //
{
if(convertColumnIndexToView(i) < 0)
{
invisible[j++] = i;
}
}
return invisible;
}
public void setRowCount(int index)
{
super.setRowCount(index);
}
/**
* Swaps the rows.
* @param row1 First row
* @param row2 Secound row
*/
public void swapRows(int row1, int row2)
{
Vector dummy = (Vector)dataVector.elementAt(row1);
dataVector.setElementAt(dataVector.elementAt(row2), row1);
dataVector.setElementAt(dummy, row2);
}
}
/**
* Testet auf Klicks in den Tabellenheader
*/
private class TableMouseListener extends MouseAdapter
{
public void mouseClicked(MouseEvent e)
{
if(SwingUtilities.isRightMouseButton(e)) // nur mit der rechten Maustaste zulassen
{
TableColumnModel tcm = getTableHeader().getColumnModel(); // schon mal das Spaltenmodell holen
int index = tcm.getColumnIndexAtX(e.getX()); // Index der angeklickten Spalte ermitteln
if(index >= 0) // wurde tatschlich eine Spalte angeklickt...
{
int modelIndex = convertColumnIndexToModel(index); // ...hole Spaltenindex des Modells
sort(modelIndex);
}
}
}
}
/**
* This class listens for the selelction of rows and set the
* text of the specified row (which presents a DicomScopeMessage)
* to a TextField
*/
private class SelectRowListener implements ListSelectionListener
{
/**
* Displays the text
*/
private JTextComponent textField;
/**
* Constructor
*/
public SelectRowListener(JTextComponent textField)
{
this.textField = textField;
}
public void valueChanged(ListSelectionEvent e)
{
if (e == null) return;
int index = getSelectedRow();
if (index != -1&& e.getValueIsAdjusting())
{
textField.setText((String)tableData.getValueAt(index, tableData. getColumnCount()-1));
textField.select(0,0);
}
}
}
}
/*
* CVS Log
* $Log: ProcessTable.java,v $
* Revision 1.1.1.1 2001/06/06 10:32:30 kleber
* Init commit for DICOMscope 3.5
* Create new CVS
*
*/
|