Source for org.jfree.report.modules.gui.swing.preview.ActionCategory

   1: /**
   2:  * ========================================
   3:  * JFreeReport : a free Java report library
   4:  * ========================================
   5:  *
   6:  * Project Info:  http://reporting.pentaho.org/
   7:  *
   8:  * (C) Copyright 2000-2007, by Object Refinery Limited, Pentaho Corporation and Contributors.
   9:  *
  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:  * $Id: ActionCategory.java 3525 2007-10-16 11:43:48Z tmorgner $
  27:  * ------------
  28:  * (C) Copyright 2000-2005, by Object Refinery Limited.
  29:  * (C) Copyright 2005-2007, by Pentaho Corporation.
  30:  */
  31: 
  32: package org.jfree.report.modules.gui.swing.preview;
  33: 
  34: import org.jfree.report.modules.gui.swing.common.SwingGuiContext;
  35: import org.jfree.util.ResourceBundleSupport;
  36: 
  37: /**
  38:  * Creation-Date: 01.12.2006, 18:49:32
  39:  *
  40:  * @author Thomas Morgner
  41:  */
  42: public class ActionCategory implements Comparable
  43: {
  44:   private String resourceBase;
  45:   private String resourcePrefix;
  46:   private int position;
  47:   private ResourceBundleSupport resources;
  48:   private String name;
  49: 
  50:   public ActionCategory()
  51:   {
  52:     name = "";
  53:   }
  54: 
  55:   public void initialize(final SwingGuiContext context)
  56:   {
  57:     resources = new ResourceBundleSupport
  58:         (context.getLocale(), resourceBase);
  59:   }
  60: 
  61:   public String getResourceBase()
  62:   {
  63:     return resourceBase;
  64:   }
  65: 
  66:   public void setResourceBase(final String resourceBase)
  67:   {
  68:     this.resourceBase = resourceBase;
  69:   }
  70: 
  71:   public String getResourcePrefix()
  72:   {
  73:     return resourcePrefix;
  74:   }
  75: 
  76:   public void setResourcePrefix(final String resourcePrefix)
  77:   {
  78:     this.resourcePrefix = resourcePrefix;
  79:   }
  80: 
  81:   public int getPosition()
  82:   {
  83:     return position;
  84:   }
  85: 
  86:   public void setPosition(final int position)
  87:   {
  88:     this.position = position;
  89:   }
  90: 
  91:   public String getName()
  92:   {
  93:     return name;
  94:   }
  95: 
  96:   public void setName(final String name)
  97:   {
  98:     if (name == null)
  99:     {
 100:       throw new NullPointerException();
 101:     }
 102:     this.name = name;
 103:   }
 104: 
 105:   /**
 106:    * Returns the display name for the export action.
 107:    *
 108:    * @return The display name.
 109:    */
 110:   public String getDisplayName()
 111:   {
 112:     return resources.getString(resourcePrefix + "name");
 113:   }
 114: 
 115:   /**
 116:    * Returns the short description for the export action.
 117:    *
 118:    * @return The short description.
 119:    */
 120:   public String getShortDescription()
 121:   {
 122:     return resources.getString(resourcePrefix + "description");
 123:   }
 124: 
 125:   /**
 126:    * Returns the mnemonic key code.
 127:    *
 128:    * @return The code.
 129:    */
 130:   public Integer getMnemonicKey()
 131:   {
 132:     return resources.getOptionalMnemonic(resourcePrefix + "mnemonic");
 133:   }
 134: 
 135:   public boolean equals(final Object o)
 136:   {
 137:     if (this == o)
 138:     {
 139:       return true;
 140:     }
 141:     if (o == null || getClass() != o.getClass())
 142:     {
 143:       return false;
 144:     }
 145: 
 146:     final ActionCategory that = (ActionCategory) o;
 147: 
 148:     if (position != that.position)
 149:     {
 150:       return false;
 151:     }
 152:     if (!name.equals(that.name))
 153:     {
 154:       return false;
 155:     }
 156: 
 157:     return true;
 158:   }
 159: 
 160:   public int hashCode()
 161:   {
 162:     int result = position;
 163:     result = 29 * result + name.hashCode();
 164:     return result;
 165:   }
 166: 
 167:   /**
 168:    * Compares this object with the specified object for order.  Returns a
 169:    * negative integer, zero, or a positive integer as this object is less than,
 170:    * equal to, or greater than the specified object.<p>
 171:    * <p/>
 172:    *
 173:    * @param o the Object to be compared.
 174:    * @return a negative integer, zero, or a positive integer as this object is
 175:    *         less than, equal to, or greater than the specified object.
 176:    * @throws ClassCastException if the specified object's type prevents it from
 177:    *                            being compared to this Object.
 178:    */
 179:   public int compareTo(final Object o)
 180:   {
 181:     final ActionCategory other = (ActionCategory) o;
 182:     if (position < other.position)
 183:     {
 184:       return -1;
 185:     }
 186:     if (position > other.position)
 187:     {
 188:       return 1;
 189:     }
 190:     return name.compareTo(other.name);
 191:   }
 192: 
 193:   public String toString()
 194:   {
 195:     return "ActionCategory{" +
 196:         "name='" + name + '\'' +
 197:         ", position=" + position +
 198:         ", resourceBase='" + resourceBase + '\'' +
 199:         ", resourcePrefix='" + resourcePrefix + '\'' +
 200:         ", resources=" + resources +
 201:         '}';
 202:   }
 203: }