001    /**
002     * ========================================
003     * JFreeReport : a free Java report library
004     * ========================================
005     *
006     * Project Info:  http://reporting.pentaho.org/
007     *
008     * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
009     *
010     * This library is free software; you can redistribute it and/or modify it under the terms
011     * of the GNU Lesser General Public License as published by the Free Software Foundation;
012     * either version 2.1 of the License, or (at your option) any later version.
013     *
014     * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
015     * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
016     * See the GNU Lesser General Public License for more details.
017     *
018     * You should have received a copy of the GNU Lesser General Public License along with this
019     * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
020     * Boston, MA 02111-1307, USA.
021     *
022     * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
023     * in the United States and other countries.]
024     *
025     * ------------
026     * $Id: ActionPluginToolbarComparator.java 3048 2007-07-28 18:02:42Z tmorgner $
027     * ------------
028     * (C) Copyright 2000-2005, by Object Refinery Limited.
029     * (C) Copyright 2005-2007, by Pentaho Corporation.
030     */
031    
032    package org.jfree.report.modules.gui.swing.common;
033    
034    import java.util.Comparator;
035    
036    /**
037     * Creation-Date: 16.11.2006, 16:50:39
038     *
039     * @author Thomas Morgner
040     */
041    public class ActionPluginToolbarComparator implements Comparator
042    {
043      public ActionPluginToolbarComparator()
044      {
045      }
046    
047      /**
048       * Compares its two arguments for order.  Returns a negative integer, zero, or
049       * a positive integer as the first argument is less than, equal to, or greater
050       * than the second.<p>
051       * <p/>
052       * The implementor must ensure that <tt>sgn(compare(x, y)) == -sgn(compare(y,
053       * x))</tt> for all <tt>x</tt> and <tt>y</tt>.  (This implies that
054       * <tt>compare(x, y)</tt> must throw an exception if and only if
055       * <tt>compare(y, x)</tt> throws an exception.)<p>
056       * <p/>
057       * The implementor must also ensure that the relation is transitive:
058       * <tt>((compare(x, y)&gt;0) &amp;&amp; (compare(y, z)&gt;0))</tt> implies
059       * <tt>compare(x, z)&gt;0</tt>.<p>
060       * <p/>
061       * Finally, the implementer must ensure that <tt>compare(x, y)==0</tt> implies
062       * that <tt>sgn(compare(x, z))==sgn(compare(y, z))</tt> for all
063       * <tt>z</tt>.<p>
064       * <p/>
065       * It is generally the case, but <i>not</i> strictly required that
066       * <tt>(compare(x, y)==0) == (x.equals(y))</tt>.  Generally speaking, any
067       * comparator that violates this condition should clearly indicate this fact.
068       * The recommended language is "Note: this comparator imposes orderings that
069       * are inconsistent with equals."
070       *
071       * @param o1 the first object to be compared.
072       * @param o2 the second object to be compared.
073       * @return a negative integer, zero, or a positive integer as the first
074       *         argument is less than, equal to, or greater than the second.
075       * @throws ClassCastException if the arguments' types prevent them from being
076       *                            compared by this Comparator.
077       */
078      public int compare(final Object o1, final Object o2)
079      {
080        final ActionPlugin a1 = (ActionPlugin) o1;
081        final ActionPlugin a2 = (ActionPlugin) o2;
082    
083        final int toolbarOrder = a1.getToolbarOrder();
084        final int toolbarOrder2 = a2.getToolbarOrder();
085        if (toolbarOrder < toolbarOrder2)
086        {
087          return -1;
088        }
089        if (toolbarOrder > toolbarOrder2)
090        {
091          return 1;
092        }
093        return 0;
094      }
095    }