Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/paradoxpoint/libitina/gui/binding/ItemReferrence.java


1   /*
2    * Libitina - Funeral Monument Image Compositor
3    * Copyright (C) 2003,2004  Luke Imhoff
4    *
5    * Contact Info:
6    * luke@paradoxpoint.com
7    * Luke Imhoff
8    * 2514 Pied Piper Lane
9    * Wausau, WI 54403 
10   *
11   * This program is free software; you can redistribute it and/or
12   * modify it under the terms of the GNU General Public License
13   * as published by the Free Software Foundation; either version 2
14   * of the License, or (at your option) any later version.
15   * 
16   * This program is distributed in the hope that it will be useful,
17   * but WITHOUT ANY WARRANTY; without even the implied warranty of
18   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
19   * GNU General Public License for more details.
20   *
21   * You should have received a copy of the GNU General Public License
22   * along with this program; if not, write to the Free Software
23   * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
24   *
25   * ItemReferrence.java
26   *
27   * Created on June 9, 2003, 1:33 AM
28   */
29  
30  package com.paradoxpoint.libitina.gui.binding;
31  
32  import javax.swing.*;
33  
34  /** Allows a referrence to specific item in a <CODE>JComboBox</CODE> by
35   * encapsulating the containing <CODE>JComboBox</CODE> and item <CODE>Object</CODE>
36   * into a single <CODE>Object</CODE>.
37   * @author Luke Imhoff
38   */
39  public class ItemReferrence {
40      
41      private volatile int hashCode = 0;
42      
43      /** <CODE>JComboBox</CODE> containing <CODE>item</CODE> */    
44      protected JComboBox comboBox;
45      /** item in comboBox */    
46      protected Object item;
47  
48      /** Constructs a new <CODE>ItemReferrence</CODE> instance with the given combo box
49       * and item
50       * @param comboBox <CODE>JComboBox</CODE> containing <CODE>item</CODE>
51       * @param item item in <CODE>JComboBox</CODE>
52       */    
53      public ItemReferrence(JComboBox comboBox, Object item) {
54          this.comboBox = comboBox;
55          this.item = item;
56      }
57  
58      /**
59       * Compares this <code>ItemReferrence</code> to the specified object.
60       * The result is <code>true</code> if and only if the argument is not
61       * <code>null</code> and is an <code>ItemReferrence</code> object that contains
62       * <code>equal()</code> elements
63       *
64       * @param   obj   the object to compare this <code>ItemReferrence</code>
65       *                     against.
66       * @return  <code>true</code> if the <code>ItemReferrence</code>are equal;
67       *          <code>false</code> otherwise.
68       */   
69      public boolean equals(Object obj) {
70          if (obj == this) return true;
71          if (!(obj instanceof ItemReferrence)) return false;
72          ItemReferrence ir = (ItemReferrence) obj;
73          return (item == null ? ir.item == null : item.equals(ir.item)) && (comboBox == ir.comboBox || (comboBox != null && comboBox.equals(ir.comboBox)));
74      }
75      
76      /**
77       * Returns a hash code for this ItemReferrence. The hash code for a
78       * <code>ItemReferrence</code> object is computed using the method outlined
79       * in <i>Effective Java</i> by Joshua Bloch
80       * @return  a hash code value for this object.
81       */    
82      public int hashCode() {
83          if (hashCode == 0) {
84              int result = 17;
85              result = 37 * result + (item == null ? 0 : item.hashCode());
86              result = 37 * result + (comboBox == null ? 0 : comboBox.hashCode());
87              hashCode = result;
88          }
89          return hashCode;
90      }
91      
92      /** Getter for property comboBox.
93       * @return Value of property comboBox.
94       *
95       */
96      public javax.swing.JComboBox getComboBox() {
97          return comboBox;
98      }
99      
100     /** Getter for property item.
101      * @return Value of property item.
102      *
103      */
104     public Object getItem() {
105         return item;
106     }
107     
108 }