LE のバックアップ(No.3)


パターン3追加色テスト用1

果物価格
|林檎|25|
|オレンジ|5|
|梨|20|
|マンゴー|500|
}}

script type="text/javascript">

!--
new OrderByColumn("tableID",["type_of_column", ... ]);

/script>

#table_edit(ほげふが)

[果物][林檎] : [価格][25]

#table_edit(表ページの名前 [, ソート文字列])

#sortabletable(Number|String|String,1){{{

#table_edit(ほげふが)
#table_edit(ほげふが, 2)
#table_edit(ほげふが, 2n)
#table_edit(ほげふが, 2nr)

|CENTER:年度||CENTER: 男 |CENTER: 女 ||CENTER:TOTAL|
|幅255pix|幅64pix|
|||||||
|CENTER:2001||RIGHT:20|RIGHT:30||RIGHT:50|
|CENTER:2002||RIGHT:30|RIGHT:40||RIGHT:70|
|||||||
|CENTER:TOTAL||RIGHT:50|RIGHT:70||RIGHT:120|

|LEFT:255|RIGHT:64|c
|幅255pix|幅64pix|


|>|>|CENTER:40|c
|1|>|2|>|3|
|4|5|7|
|~|8|~|



class SortableTableModel extends DefaultTableModel {

 public SortableTableModel(String[] str, int row) {
   super(str, row);
 }
 public void sortByColumn(int column, boolean isAscent) {
   Collections.sort(getDataVector(), new ColumnComparator(column, isAscent));
   fireTableDataChanged();
 }

}
class ColumnComparator implements Comparator {

 final protected int index;
 final protected boolean ascending;
 public ColumnComparator(int index, boolean ascending) {
   this.index = index;
   this.ascending = ascending;
 }
 public int compare(Object one, Object two) {
   if (one instanceof Vector && two instanceof Vector) {
     Object oOne = ((Vector) one).elementAt(index);
     Object oTwo = ((Vector) two).elementAt(index);
     if (oOne == null && oTwo == null) {
       return 0;
     } else if (oOne == null) {
       return ascending ? -1 :  1;
     } else if (oTwo == null) {
       return ascending ?  1 : -1;
     } else if (oOne instanceof Comparable && oTwo instanceof Comparable) {
       Comparable cOne = (Comparable) oOne;
       Comparable cTwo = (Comparable) oTwo;
       return ascending ? cOne.compareTo(cTwo) : cTwo.compareTo(cOne);
     }
   }
   return 1;
 }
 public int compare(Number o1, Number o2) {
   double n1 = o1.doubleValue();
   double n2 = o2.doubleValue();
   if (n1 < n2) {
     return -1;
   } else if (n1 > n2) {
     return 1;
   } else {
     return 0;
   }
 }

}