You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.6 KiB
87 lines
2.6 KiB
package com.net.connor.ld.plm.ld06;
|
|
|
|
import java.awt.Component;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Polygon;
|
|
import java.util.Comparator;
|
|
|
|
import javax.swing.Icon;
|
|
import javax.swing.RowSorter;
|
|
import javax.swing.RowSorter.SortKey;
|
|
import javax.swing.SortOrder;
|
|
import javax.swing.table.TableRowSorter;
|
|
|
|
import antlr.collections.List;
|
|
|
|
public class ArrowIcon implements Icon {
|
|
private final SortOrder sortOrder;
|
|
private final int size;
|
|
private final boolean ascending;
|
|
public ArrowIcon(TableRowSorter<?> sorter, int column, boolean ascending) {
|
|
this.ascending = ascending;
|
|
this.size = 12;
|
|
java.util.List<? extends SortKey> sortKeys = sorter.getSortKeys();
|
|
if (sortKeys.size() > 0 && ((RowSorter.SortKey) sortKeys.get(0)).getColumn() == column) {
|
|
this.sortOrder = ((RowSorter.SortKey) sortKeys.get(0)).getSortOrder();
|
|
} else {
|
|
this.sortOrder = SortOrder.ASCENDING;
|
|
}
|
|
}
|
|
public void paintIcon(Component c, Graphics g, int x, int y) {
|
|
Graphics2D g2 = (Graphics2D) g.create();
|
|
g2.translate(x, y);
|
|
if (ascending) {
|
|
g2.rotate(Math.PI, size / 2.0, size / 2.0);
|
|
}
|
|
if (sortOrder == SortOrder.ASCENDING) {
|
|
g2.draw(createUpTriangle(size));
|
|
} else {
|
|
g2.draw(createDownTriangle(size));
|
|
}
|
|
g2.dispose();
|
|
}
|
|
public int getIconWidth() {
|
|
return size;
|
|
}
|
|
public int getIconHeight() {
|
|
return size;
|
|
}
|
|
private Polygon createUpTriangle(int size) {
|
|
Polygon triangle = new Polygon();
|
|
triangle.addPoint(0, size);
|
|
triangle.addPoint(size / 2, 0);
|
|
triangle.addPoint(size, size);
|
|
return triangle;
|
|
}
|
|
private Polygon createDownTriangle(int size) {
|
|
Polygon triangle = new Polygon();
|
|
triangle.addPoint(0, 0);
|
|
triangle.addPoint(size, 0);
|
|
triangle.addPoint(size / 2, size);
|
|
return triangle;
|
|
}
|
|
}
|
|
//表格列排序类
|
|
class ColumnSorter implements Comparator<Object> {
|
|
private final int col;
|
|
private final boolean ascending;
|
|
public ColumnSorter(int col, boolean ascending) {
|
|
this.col = col;
|
|
this.ascending = ascending;
|
|
}
|
|
@Override
|
|
public int compare(Object a, Object b) {
|
|
if (a instanceof Comparable && b instanceof Comparable) {
|
|
if (ascending) {
|
|
return ((Comparable) a).compareTo((Comparable) b);
|
|
} else {
|
|
return ((Comparable) b).compareTo((Comparable) a);
|
|
}
|
|
} else {
|
|
return 0;
|
|
}
|
|
}
|
|
}
|
|
|