View Javadoc

1   /*
2    * Copyright (C) 2004 TiongHiang Lee
3    *
4    * This library is free software; you can redistribute it and/or
5    * modify it under the terms of the GNU Lesser General Public
6    * License as published by the Free Software Foundation; either
7    * version 2.1 of the License, or (at your option) any later version.
8    *
9    * This library is distributed in the hope that it will be useful,
10   * but WITHOUT ANY WARRANTY; without even the implied warranty of
11   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12   * Lesser General Public License for more details.
13   *
14   * You should have received a copy of the GNU Lesser General Public
15   * License along with this library; if not,  write to the Free Software
16   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17   *
18   * Email: thlee@onemindsoft.org
19   */
20  
21  package org.onemind.awtbridge.peer;
22  
23  import java.awt.*;
24  import java.awt.List;
25  import java.awt.peer.ListPeer;
26  import java.util.*;
27  import org.onemind.awtbridge.BridgeContext;
28  /***
29   * A list peer
30   * @author TiongHiang Lee (thlee@onemindsoft.org)
31   * @version $Id: BridgeListPeer.java,v 1.3 2005/03/12 23:03:11 thlee Exp $ $Name: awtbridge-1_0_0 $
32   */
33  public class BridgeListPeer extends BridgeComponentPeer implements ListPeer
34  {
35  
36      /*** the selected */
37      private Set _selected = new TreeSet();
38  
39      /***
40       * {@inheritDoc}
41       */
42      public BridgeListPeer(Object componentObject, BridgeContext context)
43      {
44          super(componentObject, context);
45      }
46  
47      /***
48       * {@inheritDoc}
49       */
50      public final int[] getSelectedIndexes()
51      {
52          int[] selected = new int[_selected.size()];
53          Iterator it = _selected.iterator();
54          int i = 0;
55          while (it.hasNext())
56          {
57              selected[i] = ((Integer) it.next()).intValue();
58              i++;
59          }
60          return selected;
61      }
62  
63      /***
64       * {@inheritDoc}
65       */
66      public final void add(String item, int index)
67      {
68          setUpToDate(false);
69          _selected.clear();
70      }
71  
72      /***
73       * set up-to-date false
74       */
75      public final void render()
76      {
77          setUpToDate(false);
78      }
79  
80      /***
81       * {@inheritDoc}
82       */
83      public final void delItems(int start, int end)
84      {
85          setUpToDate(false);
86          _selected.clear();
87      }
88  
89      /***
90       * set up-to-date false
91       */
92      public final void removeAll()
93      {
94          setUpToDate(false);
95          _selected.clear();
96      }
97  
98      /***
99       * {@inheritDoc}
100      */
101     public final void select(int index)
102     {
103         _selected.add(new Integer(index));
104         setUpToDate(false);
105         //TODO: determine if updating the selected
106     }
107 
108     /***
109      * {@inheritDoc}
110      */
111     public final void deselect(int index)
112     {
113         _selected.remove(new Integer(index));
114         setUpToDate(false);
115         //TODO: determine if updating the selected
116     }
117 
118     /***
119      * {@inheritDoc}
120      */
121     public final void makeVisible(int index)
122     {
123         setUpToDate(false);
124     }
125 
126     /***
127      * {@inheritDoc}
128      */
129     public final void setMultipleMode(boolean b)
130     {
131         setUpToDate(false);
132     }
133 
134     /***
135      * {@inheritDoc}
136      */
137     public final Dimension getPreferredSize(int rows)
138     {
139         return preferredSize(rows);
140     }
141 
142     /***
143      * {@inheritDoc}
144      */
145     public final Dimension getMinimumSize(int rows)
146     {
147         return getPreferredSize(rows);
148     }
149 
150     /***
151      * {@inheritDoc}
152      */
153     public final void addItem(String item, int index)
154     {
155         setUpToDate(false);
156     }
157 
158     /***
159      * {@inheritDoc}
160      */
161     public final void clear()
162     {
163         setUpToDate(false);
164     }
165 
166     /***
167      * {@inheritDoc}
168      */
169     public void setMultipleSelections(boolean v)
170     {
171         setUpToDate(false);
172     }
173 
174     /***
175      * {@inheritDoc}
176      */
177     public final Dimension preferredSize(int v)
178     {
179         FontMetrics m = getCurrentFontMetrics();
180         return new Dimension(m.charWidth('A') * 20, m.getHeight() * v);
181     }
182 
183     /***
184      * {@inheritDoc}
185      */
186     public final Dimension minimumSize(int v)
187     {
188         return preferredSize(v);
189     }
190 
191     /***
192      * {@inheritDoc}
193      */
194     public final Dimension preferredSize()
195     {
196         return preferredSize(((List) getComponent()).getRows());
197     }
198 }