クラス org.objectweb.cjdbc.console.views.InfoTableSorter

すべてのメンバ一覧

説明

This code is inspired from the Swing tutorial demo version 1.5 12/17/97 from Philip Milne. It sorts the table when you click on a header.

作者:
Philip Milne

Emmanuel Cecchet

バージョン:
1.0

InfoTableSorter.java50 行で定義されています。

Public メソッド

 InfoTableSorter (TableModel model)
int getRowCount ()
int getColumnCount ()
String getColumnName (int aColumn)
Class getColumnClass (int aColumn)
void tableChanged (TableModelEvent e)
Object getValueAt (int aRow, int aColumn)
void setValueAt (Object aValue, int aRow, int aColumn)
void addMouseListenerToHeaderInTable (JTable table)

Private メソッド

void setModel (TableModel model)
void sortByColumn (int column, boolean ascending)
int compareRowsByColumn (int row1, int row2, int column)
int compare (int row1, int row2)
void reallocateIndexes ()
void swap (int i, int j)

Private 変数

TableModel model
int indexes []
Vector sortingColumns = new Vector()
boolean ascending = true
int compares


コンストラクタとデストラクタ

org.objectweb.cjdbc.console.views.InfoTableSorter.InfoTableSorter TableModel  model  ) 
 

Constructor

引数:
model TableModel to use
InfoTableSorter.java65 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.setModel().

00066 { 00067 setModel(model); 00068 }


メソッド

void org.objectweb.cjdbc.console.views.InfoTableSorter.addMouseListenerToHeaderInTable JTable  table  ) 
 

Add a mouse listener to the Table to trigger a table sort when a column heading is clicked in the JTable.

引数:
table the JTable to sort
InfoTableSorter.java143 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.ascending, と org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().

参照元 org.objectweb.cjdbc.console.views.InfoViewer.createAndShowGUI().

00144 { 00145 final InfoTableSorter sorter = this; 00146 final JTable tableView = table; 00147 tableView.setColumnSelectionAllowed(false); 00148 MouseAdapter listMouseListener = new MouseAdapter() 00149 { 00150 public void mouseClicked(MouseEvent e) 00151 { 00152 TableColumnModel columnModel = tableView.getColumnModel(); 00153 int viewColumn = columnModel.getColumnIndexAtX(e.getX()); 00154 int column = tableView.convertColumnIndexToModel(viewColumn); 00155 if (e.getClickCount() == 1 && column != -1) 00156 { 00157 int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK; 00158 boolean ascending = (shiftPressed == 0); 00159 sorter.sortByColumn(column, ascending); 00160 } 00161 } 00162 }; 00163 JTableHeader th = tableView.getTableHeader(); 00164 th.addMouseListener(listMouseListener); 00165 }

int org.objectweb.cjdbc.console.views.InfoTableSorter.compare int  row1,
int  row2
[private]
 

InfoTableSorter.java239 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.ascending, org.objectweb.cjdbc.console.views.InfoTableSorter.compareRowsByColumn(), org.objectweb.cjdbc.console.views.InfoTableSorter.compares, と org.objectweb.cjdbc.console.views.InfoTableSorter.sortingColumns.

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().

00240 { 00241 compares++; 00242 for (int level = 0; level < sortingColumns.size(); level++) 00243 { 00244 Integer column = (Integer) sortingColumns.elementAt(level); 00245 int result = compareRowsByColumn(row1, row2, column.intValue()); 00246 if (result != 0) 00247 return ascending ? result : -result; 00248 } 00249 return 0; 00250 }

int org.objectweb.cjdbc.console.views.InfoTableSorter.compareRowsByColumn int  row1,
int  row2,
int  column
[private]
 

InfoTableSorter.java181 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.model.

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.compare().

00182 { 00183 int result = 0; 00184 Class type = model.getColumnClass(column); 00185 TableModel data = model; 00186 00187 // Check for nulls. 00188 00189 Object o1 = data.getValueAt(row1, column); 00190 Object o2 = data.getValueAt(row2, column); 00191 00192 // If both values are null, return 0. 00193 if (o1 == null && o2 == null) 00194 return 0; 00195 else if (o1 == null) 00196 // Define null less than everything. 00197 return -1; 00198 else if (o2 == null) 00199 return 1; 00200 00201 if (type.getSuperclass() == java.lang.Number.class) 00202 { 00203 Number n1 = (Number) data.getValueAt(row1, column); 00204 double d1 = n1.doubleValue(); 00205 Number n2 = (Number) data.getValueAt(row2, column); 00206 double d2 = n2.doubleValue(); 00207 result = (int) (d1 - d2); 00208 } 00209 else if (type == java.util.Date.class) 00210 { 00211 Date d1 = (Date) data.getValueAt(row1, column); 00212 long n1 = d1.getTime(); 00213 Date d2 = (Date) data.getValueAt(row2, column); 00214 long n2 = d2.getTime(); 00215 result = (int) (n1 - n2); 00216 } 00217 else if (type == String.class) 00218 { 00219 String s1 = (String) data.getValueAt(row1, column); 00220 String s2 = (String) data.getValueAt(row2, column); 00221 result = s1.compareTo(s2); 00222 } 00223 else 00224 { 00225 Object v1 = data.getValueAt(row1, column); 00226 String s1 = v1.toString(); 00227 Object v2 = data.getValueAt(row2, column); 00228 String s2 = v2.toString(); 00229 result = s1.compareTo(s2); 00230 } 00231 if (result < 0) 00232 return -1; 00233 else if (result > 0) 00234 return 1; 00235 else 00236 return 0; 00237 }

Class org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnClass int  aColumn  ) 
 

参照:
javax.swing.table.TableModel#getColumnClass(int)
InfoTableSorter.java104 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.model.

00105 { 00106 return model.getColumnClass(aColumn); 00107 }

int org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnCount  ) 
 

参照:
javax.swing.table.TableModel#getColumnCount()
InfoTableSorter.java88 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.model.

00089 { 00090 return (model == null) ? 0 : model.getColumnCount(); 00091 }

String org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnName int  aColumn  ) 
 

参照:
javax.swing.table.TableModel#getColumnName(int)
InfoTableSorter.java96 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.model.

00097 { 00098 return model.getColumnName(aColumn); 00099 }

int org.objectweb.cjdbc.console.views.InfoTableSorter.getRowCount  ) 
 

参照:
javax.swing.table.TableModel#getRowCount()
InfoTableSorter.java80 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.model.

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().

00081 { 00082 return (model == null) ? 0 : model.getRowCount(); 00083 }

Object org.objectweb.cjdbc.console.views.InfoTableSorter.getValueAt int  aRow,
int  aColumn
 

参照:
javax.swing.table.TableModel#getValueAt(int, int)
InfoTableSorter.java124 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.indexes, と org.objectweb.cjdbc.console.views.InfoTableSorter.model.

00125 { 00126 return model.getValueAt(indexes[aRow], aColumn); 00127 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.reallocateIndexes  )  [private]
 

InfoTableSorter.java252 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.indexes, と org.objectweb.cjdbc.console.views.InfoTableSorter.model.

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.setModel(), と org.objectweb.cjdbc.console.views.InfoTableSorter.tableChanged().

00253 { 00254 int rowCount = model.getRowCount(); 00255 00256 // Set up a new array of indexes with the right number of elements 00257 // for the new data model. 00258 indexes = new int[rowCount]; 00259 00260 // Initialise with the identity mapping. 00261 for (int row = 0; row < rowCount; row++) 00262 { 00263 indexes[row] = row; 00264 } 00265 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.setModel TableModel  model  )  [private]
 

InfoTableSorter.java70 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.reallocateIndexes().

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.InfoTableSorter().

00071 { 00072 this.model = model; 00073 model.addTableModelListener(this); 00074 reallocateIndexes(); 00075 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.setValueAt Object  aValue,
int  aRow,
int  aColumn
 

参照:
javax.swing.table.TableModel#setValueAt(java.lang.Object, int, int)
InfoTableSorter.java132 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.indexes, と org.objectweb.cjdbc.console.views.InfoTableSorter.model.

00133 { 00134 model.setValueAt(aValue, indexes[aRow], aColumn); 00135 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn int  column,
boolean  ascending
[private]
 

InfoTableSorter.java167 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.compare(), org.objectweb.cjdbc.console.views.InfoTableSorter.compares, org.objectweb.cjdbc.console.views.InfoTableSorter.getRowCount(), org.objectweb.cjdbc.console.views.InfoTableSorter.indexes, org.objectweb.cjdbc.console.views.InfoTableSorter.sortingColumns, と org.objectweb.cjdbc.console.views.InfoTableSorter.swap().

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.addMouseListenerToHeaderInTable().

00168 { 00169 this.ascending = ascending; 00170 sortingColumns.removeAllElements(); 00171 sortingColumns.addElement(new Integer(column)); 00172 compares = 0; 00173 for (int i = 0; i < getRowCount(); i++) 00174 for (int j = i + 1; j < getRowCount(); j++) 00175 if (compare(indexes[i], indexes[j]) == -1) 00176 swap(i, j); 00177 00178 fireTableChanged(new TableModelEvent(this)); 00179 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.swap int  i,
int  j
[private]
 

InfoTableSorter.java267 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.indexes.

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().

00268 { 00269 int tmp = indexes[i]; 00270 indexes[i] = indexes[j]; 00271 indexes[j] = tmp; 00272 }

void org.objectweb.cjdbc.console.views.InfoTableSorter.tableChanged TableModelEvent  e  ) 
 

参照:
javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent)
InfoTableSorter.java112 行で定義されています。

参照先 org.objectweb.cjdbc.console.views.InfoTableSorter.reallocateIndexes().

00113 { 00114 reallocateIndexes(); 00115 fireTableChanged(e); 00116 }


変数

boolean org.objectweb.cjdbc.console.views.InfoTableSorter.ascending = true [private]
 

InfoTableSorter.java57 行で定義されています。

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.addMouseListenerToHeaderInTable(), と org.objectweb.cjdbc.console.views.InfoTableSorter.compare().

int org.objectweb.cjdbc.console.views.InfoTableSorter.compares [private]
 

InfoTableSorter.java58 行で定義されています。

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.compare(), と org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().

int org.objectweb.cjdbc.console.views.InfoTableSorter.indexes[] [private]
 

InfoTableSorter.java55 行で定義されています。

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.getValueAt(), org.objectweb.cjdbc.console.views.InfoTableSorter.reallocateIndexes(), org.objectweb.cjdbc.console.views.InfoTableSorter.setValueAt(), org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn(), と org.objectweb.cjdbc.console.views.InfoTableSorter.swap().

TableModel org.objectweb.cjdbc.console.views.InfoTableSorter.model [private]
 

InfoTableSorter.java54 行で定義されています。

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.compareRowsByColumn(), org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnClass(), org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnCount(), org.objectweb.cjdbc.console.views.InfoTableSorter.getColumnName(), org.objectweb.cjdbc.console.views.InfoTableSorter.getRowCount(), org.objectweb.cjdbc.console.views.InfoTableSorter.getValueAt(), org.objectweb.cjdbc.console.views.InfoTableSorter.reallocateIndexes(), と org.objectweb.cjdbc.console.views.InfoTableSorter.setValueAt().

Vector org.objectweb.cjdbc.console.views.InfoTableSorter.sortingColumns = new Vector() [private]
 

InfoTableSorter.java56 行で定義されています。

参照元 org.objectweb.cjdbc.console.views.InfoTableSorter.compare(), と org.objectweb.cjdbc.console.views.InfoTableSorter.sortByColumn().


このクラスの説明は次のファイルから生成されました:
CJDBCversion1.0.4に対してTue Oct 12 15:16:34 2004に生成されました。 doxygen 1.3.8