1 /*
2 * JInternalFrameComparator.java
3 *
4 * Copyright (c) 2004-2006 Gregory Kotsaftis
5 * gregkotsaftis@yahoo.com
6 * http://zeus-jscl.sourceforge.net/
7 *
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public
10 * License as published by the Free Software Foundation; either
11 * version 2.1 of the License, or (at your option) any later version.
12 *
13 * This library is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
17 *
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 */
22 package ch.elca.el4j.services.gui.swing.mdi;
23
24 import java.io.Serializable;
25 import java.util.Comparator;
26 import javax.swing.JInternalFrame;
27
28 /**
29 * A simple comparator for <code>JInternalFrames</code>, based on their title.
30 * <p>
31 *
32 * @svnLink $Revision: 3878 $;$Date: 2009-08-04 15:06:35 +0200 (Di, 04. Aug 2009) $;$Author: swismer $;$URL: https://el4j.svn.sourceforge.net/svnroot/el4j/branches/el4j_3_1/el4j/framework/modules/swing/src/main/java/ch/elca/el4j/services/gui/swing/mdi/JInternalFrameComparator.java $
33 *
34 * @author Gregory Kotsaftis
35 * @since 1.04
36 */
37 public final class JInternalFrameComparator
38 implements Comparator<JInternalFrame>, Serializable {
39
40 /**
41 * Compares internal frames based on their title.
42 * <p>
43 * @param o1 First frame.
44 * @param o2 Second frame.
45 * <p>
46 * @return The comparison.
47 */
48 public int compare(JInternalFrame o1, JInternalFrame o2)
49 {
50 int ret = 0;
51
52 if( o1!=null && o2!=null )
53 {
54 String t1 = o1.getTitle();
55 String t2 = o2.getTitle();
56
57 if( t1 != null && t2 != null )
58 {
59 ret = t1.compareTo(t2);
60 }
61 else if( t1 == null && t2 != null )
62 {
63 ret = -1;
64 }
65 else if( t1 != null && t2 == null )
66 {
67 ret = 1;
68 }
69 else
70 {
71 ret = 0;
72 }
73 }
74
75 return( ret );
76 }
77
78 }