View Javadoc

1   /*
2    * Copyright 2006-2016 The JGUIraffe Team.
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License")
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package net.sf.jguiraffe.examples.tutorial.model;
17  
18  import java.io.File;
19  import java.util.List;
20  
21  /**
22   * <p>
23   * A data class for storing information about a directory.
24   * </p>
25   * <p>
26   * Objects of this class are used by the file system browser to keep track about
27   * the directories already scanned. They are stored in the model of the tree
28   * view. Whenever a node in the tree is selected the corresponding {@code
29   * DirectoryData} object is determined. From this object the content of the
30   * directory can be obtained. It is also possible to find out whether this
31   * directory has already been read.
32   * </p>
33   *
34   * @author Oliver Heger
35   * @version $Id: DirectoryData.java 205 2012-01-29 18:29:57Z oheger $
36   */
37  public class DirectoryData
38  {
39      /** Stores the file representing the directory. */
40      private final File directory;
41  
42      /** A list with the content of this directory. */
43      private List<FileData> content;
44  
45      /**
46       * Creates a new instance of {@code DirectoryData} and initializes it with
47       * the {@code File} object representing the associated directory.
48       *
49       * @param dir the directory
50       */
51      public DirectoryData(File dir)
52      {
53          directory = dir;
54      }
55  
56      /**
57       * Returns a list with the content of this directory.
58       *
59       * @return a list with the content of this directory
60       */
61      public List<FileData> getContent()
62      {
63          return content;
64      }
65  
66      /**
67       * Sets the list with the content of this directory.
68       *
69       * @param content the list with the content
70       */
71      public void setContent(List<FileData> content)
72      {
73          this.content = content;
74      }
75  
76      /**
77       * Returns the {@code File} object representing the associated directory.
78       *
79       * @return the directory
80       */
81      public File getDirectory()
82      {
83          return directory;
84      }
85  
86      /**
87       * Returns a flag whether this directory has already been initialized.
88       * Initialized means that the content of the directory is available.
89       *
90       * @return a flag whether this directory has been initialized
91       */
92      public boolean isInitialized()
93      {
94          return content != null;
95      }
96  
97      /**
98       * Returns a string representation for this object. This string contains the
99       * directory object itself and its content as well (if it is available
100      * already).
101      *
102      * @return a string for this object
103      */
104     @Override
105     public String toString()
106     {
107         StringBuilder buf = new StringBuilder();
108         buf.append("DirectoryData [ directory = ").append(getDirectory());
109         if (isInitialized())
110         {
111             buf.append(", content = ").append(content);
112         }
113         buf.append(" ]");
114         return buf.toString();
115     }
116 }