1 /*
2 * Scope: a generic MVC framework.
3 * Copyright (c) 2000-2002, The Scope team
4 * All rights reserved.
5 *
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 *
14 * Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 *
18 * Neither the name "Scope" nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
21 *
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
24 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
25 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
26 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
27 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
28 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
29 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
30 * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
31 * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
32 * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
34 *
35 *
36 * $Id: FSRootsModel.java,v 1.3 2002/09/05 15:41:47 ludovicc Exp $
37 */
38 package samples.filefind;
39
40
41 import java.io.File;
42 import java.util.ArrayList;
43 import java.util.Iterator;
44 import java.util.List;
45
46 /***
47 * Models filesystem roots and its selection
48 *
49 * @author <A HREF="mailto:daniel.michalik@autel.cz">Daniel Michalik</A>
50 * @created 05 September 2002
51 * @version $Revision: 1.3 $ $Date: 2002/09/05 15:41:47 $
52 */
53 public class FSRootsModel {
54
55 private List fileSystemRoots;
56
57
58 /***
59 * Constructor for the FSRootsModel object
60 */
61 public FSRootsModel() {
62 File f[] = File.listRoots();
63 if (f == null) {
64 f = new File[0];
65 }
66 fileSystemRoots = new ArrayList(f.length);
67 for (int i = 0; i < f.length; i++) {
68 fileSystemRoots.add(new FSRoot(f[i]));
69 }
70 }
71
72
73 /***
74 * Gets the selected roots
75 *
76 * @return The selectedRoots value
77 */
78 public List getSelectedRoots() {
79 List l = new ArrayList(3);
80 for (Iterator i = fileSystemRoots.iterator(); i.hasNext(); ) {
81 FSRoot f = (FSRoot) i.next();
82 if (f.isEnabled()) {
83 l.add(f.file);
84 }
85 }
86 return l;
87 }
88
89
90 /***
91 * Gets the file system roots
92 *
93 * @return The fileSystemRoots value
94 */
95 public List getFileSystemRoots() {
96 return fileSystemRoots;
97 }
98
99
100 /***
101 * TODO: document the class
102 *
103 * @author lclaude
104 * @created 05 September 2002
105 */
106 public static class FSRoot {
107 private File file;
108 private boolean enabled = false;
109
110 /***
111 * Constructor for the FSRoot object
112 *
113 * @param f TODO: Describe the Parameter
114 */
115 FSRoot(File f) {
116 file = f;
117 }
118
119 /***
120 * Gets the name
121 *
122 * @return The name value
123 */
124 public String getName() {
125 return file.getPath();
126 }
127
128 // read-only property (no setter)
129
130 /***
131 * Gets the enabled
132 *
133 * @return The enabled value
134 */
135 public boolean isEnabled() {
136 return enabled;
137 }
138
139 /***
140 * Sets the enabled
141 *
142 * @param b The new enabled value
143 */
144 public void setEnabled(boolean b) {
145 enabled = b;
146 }
147 }
148 }
This page was automatically generated by Maven