📄 xycomparator.java
字号:
/* * Created on 20.06.2005 * */package org.jdesktop.demo.swingx.common;import java.awt.Dimension;import java.awt.Point;import java.util.Comparator;/** * A custom comparator implementation for Point and Dimension. * * @author Jeanette Winzenburg */public class XYComparator implements Comparator { public int compare(Object o1, Object o2) { if ((o1 instanceof Point) && (o2 instanceof Point)) { return comparePoint((Point) o1, (Point) o2); } if ((o1 instanceof Dimension) && (o2 instanceof Dimension)) { return compareDimension((Dimension) o1, (Dimension) o2); } return 0; // can't decide } private int compareDimension(Dimension dim1, Dimension dim2) { if (dim1.width == dim2.width) { if (dim1.height == dim2.height) return 0; return dim1.height < dim2.height ? -1 : 1; } return dim1.width < dim2.width ? -1 : 1; } private int comparePoint(Point p1, Point p2) { if (p1.x == p2.x) { if (p1.y == p2.y) return 0; return p1.y < p2.y ? -1 : 1; } return p1.x < p2.x ? -1 : 1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -