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: CategoryTreeItem.java 3525 2007-10-16 11:43:48Z 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.preview; 033 034 import java.util.ArrayList; 035 036 /** 037 * Creation-Date: 01.12.2006, 20:01:32 038 * 039 * @author Thomas Morgner 040 */ 041 public class CategoryTreeItem implements Comparable 042 { 043 private CategoryTreeItem parent; 044 private ActionCategory category; 045 private ArrayList childs; 046 private String name; 047 048 public CategoryTreeItem(final ActionCategory category) 049 { 050 this.category = category; 051 this.name = category.getName(); 052 } 053 054 public String getName() 055 { 056 return name; 057 } 058 059 public CategoryTreeItem getParent() 060 { 061 return parent; 062 } 063 064 public void setParent(final CategoryTreeItem parent) 065 { 066 this.parent = parent; 067 } 068 069 public ActionCategory getCategory() 070 { 071 return category; 072 } 073 074 public void add(final CategoryTreeItem item) 075 { 076 if (childs == null) 077 { 078 childs = new ArrayList(); 079 } 080 childs.add(item); 081 } 082 083 public CategoryTreeItem[] getChilds() 084 { 085 if (childs == null) 086 { 087 return new CategoryTreeItem[0]; 088 } 089 return (CategoryTreeItem[]) childs.toArray(new CategoryTreeItem[childs.size()]); 090 } 091 092 /** 093 * Compares this object with the specified object for order. Returns a 094 * negative integer, zero, or a positive integer as this object is less than, 095 * equal to, or greater than the specified object.<p> 096 * <p/> 097 * 098 * @param o the Object to be compared. 099 * @return a negative integer, zero, or a positive integer as this object is 100 * less than, equal to, or greater than the specified object. 101 * @throws ClassCastException if the specified object's type prevents it from 102 * being compared to this Object. 103 */ 104 public int compareTo(final Object o) 105 { 106 final CategoryTreeItem other = (CategoryTreeItem) o; 107 final int position = category.getPosition(); 108 final int otherPosition = other.getCategory().getPosition(); 109 if (position < otherPosition) 110 { 111 return -1; 112 } 113 if (position > otherPosition) 114 { 115 return 1; 116 } 117 return name.compareTo(other.name); 118 } 119 120 }