KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openharmonise > him > metadata > range > swing > resourcehandling > ResourceSelectionList


1 /*
2  * The contents of this file are subject to the
3  * Mozilla Public License Version 1.1 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at http://www.mozilla.org/MPL/
6  *
7  * Software distributed under the License is distributed on an "AS IS"
8  * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
9  * See the License for the specific language governing rights and
10  * limitations under the License.
11  *
12  * The Initial Developer of the Original Code is Simulacra Media Ltd.
13  * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
14  *
15  * All Rights Reserved.
16  *
17  * Contributor(s):
18  */

19 package org.openharmonise.him.metadata.range.swing.resourcehandling;
20
21 import java.awt.*;
22 import java.util.*;
23 import java.util.List JavaDoc;
24
25 import javax.swing.*;
26
27 import org.openharmonise.vfs.*;
28 import org.openharmonise.vfs.metadata.value.*;
29
30
31 /**
32  * DIDN'T GIVE ME A DESCRIPTION!!
33  * @author Matthew Large
34  * @version $Revision: 1.1 $
35  *
36  */

37 public class ResourceSelectionList extends JPanel implements LayoutManager {
38
39     private ResourceRangeDisplay m_display = null;
40     
41     private ArrayList m_aReasons = new ArrayList();
42     
43     private JPanel m_panel = null;
44
45     /**
46      *
47      */

48     public ResourceSelectionList(ResourceRangeDisplay display) {
49         super();
50         this.m_display = display;
51         this.setup();
52     }
53     
54     private void setup() {
55         m_panel = new JPanel();
56         m_panel.setLayout(this);
57         this.setBackground(Color.WHITE);
58         this.m_panel.setBackground(Color.WHITE);
59         
60         JScrollPane scroller = new JScrollPane(m_panel, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
61         scroller.setBorder(BorderFactory.createEmptyBorder());
62         this.setLayout(new BorderLayout());
63         this.add(scroller);
64     }
65     
66     public void addReason(Reason reason) {
67         this.m_aReasons.add(reason);
68         
69         List JavaDoc values = reason.getPropertyInstance().getValues();
70         Iterator itor = values.iterator();
71         while (itor.hasNext()) {
72             ResourceValue value = (ResourceValue) itor.next();
73             ResourceSelectionCell cell = new ResourceSelectionCell(value, reason, this);
74             m_panel.add(cell);
75             int nHeight = 0;
76             for(int i=0; i<this.m_panel.getComponentCount(); i++) {
77                 Component comp = this.m_panel.getComponent(i);
78                 if(comp instanceof ResourceSelectionCell) {
79                     nHeight = nHeight + 20;
80                 }
81             }
82             this.m_panel.setPreferredSize(new Dimension(270, nHeight));
83         }
84         this.refreshReasons();
85     }
86     
87     public void refreshReasons() {
88         for(int i=0; i<this.m_panel.getComponentCount(); i++) {
89             Component comp = this.m_panel.getComponent(i);
90             if(comp instanceof ResourceSelectionCell) {
91                 ((ResourceSelectionCell)comp).refreshReasons();
92             }
93         }
94     }
95     
96     public void addResource(VirtualFile vfFile) {
97         ResourceSelectionCell cell = new ResourceSelectionCell(this, vfFile);
98         m_panel.add(cell);
99     }
100     
101     public boolean isValid() {
102         boolean bValid = true;
103         
104         Iterator itor = this.m_aReasons.iterator();
105         while (itor.hasNext()) {
106             Reason reason = (Reason) itor.next();
107             if(!reason.isValid()) {
108                 bValid = false;
109             }
110         }
111         
112         return bValid;
113     }
114
115     /* (non-Javadoc)
116      * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
117      */

118     public void layoutContainer(Container arg0) {
119         int nHeight = 0;
120         
121         for(int i=0; i<this.m_panel.getComponentCount(); i++) {
122             Component comp = this.m_panel.getComponent(i);
123             if(comp instanceof ResourceSelectionCell) {
124                 ResourceSelectionCell cell = (ResourceSelectionCell) comp;
125                 cell.setSize(cell.getPreferredSize());
126                 cell.setLocation(0, nHeight);
127                 nHeight = nHeight + cell.getSize().height;
128             }
129         }
130     }
131     
132     private ResourceSelectionCell getSelectedCell() {
133         ResourceSelectionCell cell = null;
134         for(int i=0; i<this.m_panel.getComponentCount(); i++) {
135             Component comp = this.m_panel.getComponent(i);
136             if(comp instanceof ResourceSelectionCell && ((ResourceSelectionCell)comp).isSelected() ) {
137                 cell = (ResourceSelectionCell) comp;
138             }
139         }
140         return cell;
141     }
142     
143     public void cellSelected(ResourceSelectionCell cell) {
144         for(int i=0; i<this.m_panel.getComponentCount(); i++) {
145             Component comp = this.m_panel.getComponent(i);
146             if(comp instanceof ResourceSelectionCell) {
147                 ((ResourceSelectionCell)comp).setCellSelected(false);
148             }
149         }
150         cell.setCellSelected(true);
151         this.validateTree();
152         this.repaint();
153     }
154     
155     public void removeSelectedCell() {
156         ResourceSelectionCell cell = this.getSelectedCell();
157         
158         if(cell!=null) {
159             cell.prepareToRemove();
160             this.m_panel.remove(cell);
161         }
162     }
163
164     /* (non-Javadoc)
165      * @see java.awt.Component#getPreferredSize()
166      */

167     public Dimension getPreferredSize() {
168         return new Dimension(300,300);
169     }
170     
171     protected List JavaDoc getReasons() {
172         return (List JavaDoc) this.m_aReasons.clone();
173     }
174
175     /**
176      * @param arg0
177      */

178     private ResourceSelectionList(boolean arg0) {
179         super(arg0);
180     }
181
182     /**
183      * @param arg0
184      */

185     private ResourceSelectionList(LayoutManager arg0) {
186         super(arg0);
187     }
188
189     /**
190      * @param arg0
191      * @param arg1
192      */

193     private ResourceSelectionList(LayoutManager arg0, boolean arg1) {
194         super(arg0, arg1);
195     }
196
197     /* (non-Javadoc)
198      * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
199      */

200     public Dimension minimumLayoutSize(Container arg0) {
201         return this.getPreferredSize();
202     }
203
204     /* (non-Javadoc)
205      * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
206      */

207     public Dimension preferredLayoutSize(Container arg0) {
208         return this.getPreferredSize();
209     }
210
211     /* (non-Javadoc)
212      * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
213      */

214     public void removeLayoutComponent(Component arg0) {
215     }
216
217     /* (non-Javadoc)
218      * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
219      */

220     public void addLayoutComponent(String JavaDoc arg0, Component arg1) {
221     }
222
223 }
224
Popular Tags