01: /**
02: * ===========================================
03: * JFreeReport : a free Java reporting library
04: * ===========================================
05: *
06: * Project Info: http://reporting.pentaho.org/
07: *
08: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
09: *
10: * This library is free software; you can redistribute it and/or modify it under the terms
11: * of the GNU Lesser General Public License as published by the Free Software Foundation;
12: * either version 2.1 of the License, or (at your option) any later version.
13: *
14: * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15: * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16: * See the GNU Lesser General Public License for more details.
17: *
18: * You should have received a copy of the GNU Lesser General Public License along with this
19: * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20: * Boston, MA 02111-1307, USA.
21: *
22: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
23: * in the United States and other countries.]
24: *
25: * ------------
26: * ActionPluginMenuComparator.java
27: * ------------
28: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
29: */package org.jfree.report.modules.gui.commonswing;
30:
31: import java.io.Serializable;
32: import java.util.Comparator;
33:
34: /**
35: * Creation-Date: 16.11.2006, 16:50:39
36: *
37: * @author Thomas Morgner
38: */
39: public class ActionPluginMenuComparator implements Comparator,
40: Serializable {
41: public ActionPluginMenuComparator() {
42: }
43:
44: /**
45: * Compares its two arguments for order. Returns a negative integer, zero, or
46: * a positive integer as the first argument is less than, equal to, or greater
47: * than the second.<p>
48: * <p/>
49: * The implementor must ensure that <tt>sgn(compare(x, y)) == -sgn(compare(y,
50: * x))</tt> for all <tt>x</tt> and <tt>y</tt>. (This implies that
51: * <tt>compare(x, y)</tt> must throw an exception if and only if
52: * <tt>compare(y, x)</tt> throws an exception.)<p>
53: * <p/>
54: * The implementor must also ensure that the relation is transitive:
55: * <tt>((compare(x, y)>0) && (compare(y, z)>0))</tt> implies
56: * <tt>compare(x, z)>0</tt>.<p>
57: * <p/>
58: * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> implies
59: * that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
60: * <tt>z</tt>.<p>
61: * <p/>
62: * It is generally the case, but <i>not</i> strictly required that
63: * <tt>(compare(x, y)==0) == (x.equals(y))</tt>. Generally speaking, any
64: * comparator that violates this condition should clearly indicate this fact.
65: * The recommended language is "Note: this comparator imposes orderings that
66: * are inconsistent with equals."
67: *
68: * @param o1 the first object to be compared.
69: * @param o2 the second object to be compared.
70: * @return a negative integer, zero, or a positive integer as the first
71: * argument is less than, equal to, or greater than the second.
72: * @throws ClassCastException if the arguments' types prevent them from being
73: * compared by this Comparator.
74: */
75: public int compare(final Object o1, final Object o2) {
76: final ActionPlugin a1 = (ActionPlugin) o1;
77: final ActionPlugin a2 = (ActionPlugin) o2;
78:
79: final int toolbarOrder = a1.getMenuOrder();
80: final int toolbarOrder2 = a2.getMenuOrder();
81: if (toolbarOrder < toolbarOrder2) {
82: return -1;
83: }
84: if (toolbarOrder > toolbarOrder2) {
85: return 1;
86: }
87: return 0;
88: }
89: }
|