001: /*
002: * The contents of this file are subject to the
003: * Mozilla Public License Version 1.1 (the "License");
004: * you may not use this file except in compliance with the License.
005: * You may obtain a copy of the License at http://www.mozilla.org/MPL/
006: *
007: * Software distributed under the License is distributed on an "AS IS"
008: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied.
009: * See the License for the specific language governing rights and
010: * limitations under the License.
011: *
012: * The Initial Developer of the Original Code is Simulacra Media Ltd.
013: * Portions created by Simulacra Media Ltd are Copyright (C) Simulacra Media Ltd, 2004.
014: *
015: * All Rights Reserved.
016: *
017: * Contributor(s):
018: */
019: package org.openharmonise.him.metadata.range.swing.resourcehandling;
020:
021: import java.awt.*;
022: import java.util.*;
023: import java.util.List;
024:
025: import javax.swing.*;
026:
027: import org.openharmonise.vfs.*;
028: import org.openharmonise.vfs.metadata.value.*;
029:
030: /**
031: * DIDN'T GIVE ME A DESCRIPTION!!
032: * @author Matthew Large
033: * @version $Revision: 1.1 $
034: *
035: */
036: public class ResourceSelectionList extends JPanel implements
037: LayoutManager {
038:
039: private ResourceRangeDisplay m_display = null;
040:
041: private ArrayList m_aReasons = new ArrayList();
042:
043: private JPanel m_panel = null;
044:
045: /**
046: *
047: */
048: public ResourceSelectionList(ResourceRangeDisplay display) {
049: super ();
050: this .m_display = display;
051: this .setup();
052: }
053:
054: private void setup() {
055: m_panel = new JPanel();
056: m_panel.setLayout(this );
057: this .setBackground(Color.WHITE);
058: this .m_panel.setBackground(Color.WHITE);
059:
060: JScrollPane scroller = new JScrollPane(m_panel,
061: JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
062: JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
063: scroller.setBorder(BorderFactory.createEmptyBorder());
064: this .setLayout(new BorderLayout());
065: this .add(scroller);
066: }
067:
068: public void addReason(Reason reason) {
069: this .m_aReasons.add(reason);
070:
071: List values = reason.getPropertyInstance().getValues();
072: Iterator itor = values.iterator();
073: while (itor.hasNext()) {
074: ResourceValue value = (ResourceValue) itor.next();
075: ResourceSelectionCell cell = new ResourceSelectionCell(
076: value, reason, this );
077: m_panel.add(cell);
078: int nHeight = 0;
079: for (int i = 0; i < this .m_panel.getComponentCount(); i++) {
080: Component comp = this .m_panel.getComponent(i);
081: if (comp instanceof ResourceSelectionCell) {
082: nHeight = nHeight + 20;
083: }
084: }
085: this .m_panel.setPreferredSize(new Dimension(270, nHeight));
086: }
087: this .refreshReasons();
088: }
089:
090: public void refreshReasons() {
091: for (int i = 0; i < this .m_panel.getComponentCount(); i++) {
092: Component comp = this .m_panel.getComponent(i);
093: if (comp instanceof ResourceSelectionCell) {
094: ((ResourceSelectionCell) comp).refreshReasons();
095: }
096: }
097: }
098:
099: public void addResource(VirtualFile vfFile) {
100: ResourceSelectionCell cell = new ResourceSelectionCell(this ,
101: vfFile);
102: m_panel.add(cell);
103: }
104:
105: public boolean isValid() {
106: boolean bValid = true;
107:
108: Iterator itor = this .m_aReasons.iterator();
109: while (itor.hasNext()) {
110: Reason reason = (Reason) itor.next();
111: if (!reason.isValid()) {
112: bValid = false;
113: }
114: }
115:
116: return bValid;
117: }
118:
119: /* (non-Javadoc)
120: * @see java.awt.LayoutManager#layoutContainer(java.awt.Container)
121: */
122: public void layoutContainer(Container arg0) {
123: int nHeight = 0;
124:
125: for (int i = 0; i < this .m_panel.getComponentCount(); i++) {
126: Component comp = this .m_panel.getComponent(i);
127: if (comp instanceof ResourceSelectionCell) {
128: ResourceSelectionCell cell = (ResourceSelectionCell) comp;
129: cell.setSize(cell.getPreferredSize());
130: cell.setLocation(0, nHeight);
131: nHeight = nHeight + cell.getSize().height;
132: }
133: }
134: }
135:
136: private ResourceSelectionCell getSelectedCell() {
137: ResourceSelectionCell cell = null;
138: for (int i = 0; i < this .m_panel.getComponentCount(); i++) {
139: Component comp = this .m_panel.getComponent(i);
140: if (comp instanceof ResourceSelectionCell
141: && ((ResourceSelectionCell) comp).isSelected()) {
142: cell = (ResourceSelectionCell) comp;
143: }
144: }
145: return cell;
146: }
147:
148: public void cellSelected(ResourceSelectionCell cell) {
149: for (int i = 0; i < this .m_panel.getComponentCount(); i++) {
150: Component comp = this .m_panel.getComponent(i);
151: if (comp instanceof ResourceSelectionCell) {
152: ((ResourceSelectionCell) comp).setCellSelected(false);
153: }
154: }
155: cell.setCellSelected(true);
156: this .validateTree();
157: this .repaint();
158: }
159:
160: public void removeSelectedCell() {
161: ResourceSelectionCell cell = this .getSelectedCell();
162:
163: if (cell != null) {
164: cell.prepareToRemove();
165: this .m_panel.remove(cell);
166: }
167: }
168:
169: /* (non-Javadoc)
170: * @see java.awt.Component#getPreferredSize()
171: */
172: public Dimension getPreferredSize() {
173: return new Dimension(300, 300);
174: }
175:
176: protected List getReasons() {
177: return (List) this .m_aReasons.clone();
178: }
179:
180: /**
181: * @param arg0
182: */
183: private ResourceSelectionList(boolean arg0) {
184: super (arg0);
185: }
186:
187: /**
188: * @param arg0
189: */
190: private ResourceSelectionList(LayoutManager arg0) {
191: super (arg0);
192: }
193:
194: /**
195: * @param arg0
196: * @param arg1
197: */
198: private ResourceSelectionList(LayoutManager arg0, boolean arg1) {
199: super (arg0, arg1);
200: }
201:
202: /* (non-Javadoc)
203: * @see java.awt.LayoutManager#minimumLayoutSize(java.awt.Container)
204: */
205: public Dimension minimumLayoutSize(Container arg0) {
206: return this .getPreferredSize();
207: }
208:
209: /* (non-Javadoc)
210: * @see java.awt.LayoutManager#preferredLayoutSize(java.awt.Container)
211: */
212: public Dimension preferredLayoutSize(Container arg0) {
213: return this .getPreferredSize();
214: }
215:
216: /* (non-Javadoc)
217: * @see java.awt.LayoutManager#removeLayoutComponent(java.awt.Component)
218: */
219: public void removeLayoutComponent(Component arg0) {
220: }
221:
222: /* (non-Javadoc)
223: * @see java.awt.LayoutManager#addLayoutComponent(java.lang.String, java.awt.Component)
224: */
225: public void addLayoutComponent(String arg0, Component arg1) {
226: }
227:
228: }
|