001: /**
002: * ===========================================
003: * JFreeReport : a free Java reporting library
004: * ===========================================
005: *
006: * Project Info: http://reporting.pentaho.org/
007: *
008: * (C) Copyright 2001-2007, by Object Refinery Ltd, 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: * CategoryTreeItem.java
027: * ------------
028: * (C) Copyright 2001-2007, by Object Refinery Ltd, Pentaho Corporation and Contributors.
029: */package org.jfree.report.modules.gui.base.internal;
030:
031: import java.util.ArrayList;
032:
033: /**
034: * Creation-Date: 01.12.2006, 20:01:32
035: *
036: * @author Thomas Morgner
037: */
038: public class CategoryTreeItem implements Comparable {
039: private CategoryTreeItem parent;
040: private ActionCategory category;
041: private ArrayList childs;
042: private String name;
043: private static final CategoryTreeItem[] EMPTY_CHILDS = new CategoryTreeItem[0];
044:
045: public CategoryTreeItem(final ActionCategory category) {
046: this .category = category;
047: this .name = category.getName();
048: }
049:
050: public String getName() {
051: return name;
052: }
053:
054: public CategoryTreeItem getParent() {
055: return parent;
056: }
057:
058: public void setParent(final CategoryTreeItem parent) {
059: this .parent = parent;
060: }
061:
062: public ActionCategory getCategory() {
063: return category;
064: }
065:
066: public void add(final CategoryTreeItem item) {
067: if (childs == null) {
068: childs = new ArrayList();
069: }
070: childs.add(item);
071: }
072:
073: public CategoryTreeItem[] getChilds() {
074: if (childs == null) {
075: return EMPTY_CHILDS;
076: }
077: return (CategoryTreeItem[]) childs
078: .toArray(new CategoryTreeItem[childs.size()]);
079: }
080:
081: /**
082: * Compares this object with the specified object for order. Returns a
083: * negative integer, zero, or a positive integer as this object is less than,
084: * equal to, or greater than the specified object.<p>
085: * <p/>
086: *
087: * @param o the Object to be compared.
088: * @return a negative integer, zero, or a positive integer as this object is
089: * less than, equal to, or greater than the specified object.
090: * @throws ClassCastException if the specified object's type prevents it from
091: * being compared to this Object.
092: */
093: public int compareTo(final Object o) {
094: final CategoryTreeItem other = (CategoryTreeItem) o;
095: final int position = category.getPosition();
096: final int otherPosition = other.getCategory().getPosition();
097: if (position < otherPosition) {
098: return -1;
099: }
100: if (position > otherPosition) {
101: return 1;
102: }
103: return name.compareTo(other.name);
104: }
105:
106: }
|