KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > edu > rice > cs > drjava > project > DocFile


1 /*BEGIN_COPYRIGHT_BLOCK
2  *
3  * This file is part of DrJava. Download the current version of this project from http://www.drjava.org/
4  * or http://sourceforge.net/projects/drjava/
5  *
6  * DrJava Open Source License
7  *
8  * Copyright (C) 2001-2005 JavaPLT group at Rice University (javaplt@rice.edu). All rights reserved.
9  *
10  * Developed by: Java Programming Languages Team, Rice University, http://www.cs.rice.edu/~javaplt/
11  *
12  * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
13  * documentation files (the "Software"), to deal with the Software without restriction, including without limitation
14  * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and
15  * to permit persons to whom the Software is furnished to do so, subject to the following conditions:
16  *
17  * - Redistributions of source code must retain the above copyright notice, this list of conditions and the
18  * following disclaimers.
19  * - Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the
20  * following disclaimers in the documentation and/or other materials provided with the distribution.
21  * - Neither the names of DrJava, the JavaPLT, Rice University, nor the names of its contributors may be used to
22  * endorse or promote products derived from this Software without specific prior written permission.
23  * - Products derived from this software may not be called "DrJava" nor use the term "DrJava" as part of their
24  * names without prior written permission from the JavaPLT group. For permission, write to javaplt@rice.edu.
25  *
26  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO
27  * THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
28  * CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF
29  * CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
30  * WITH THE SOFTWARE.
31  *
32  *END_COPYRIGHT_BLOCK*/

33
34 package edu.rice.cs.drjava.project;
35
36 import java.io.File JavaDoc;
37 import java.io.IOException JavaDoc;
38
39 import edu.rice.cs.plt.tuple.Pair;
40
41 public class DocFile extends File JavaDoc {
42   
43   private Pair<Integer JavaDoc,Integer JavaDoc> _sel;
44   private Pair<Integer JavaDoc,Integer JavaDoc> _scroll;
45   private boolean _active;
46   private String JavaDoc _package;
47   private long _mod;
48   
49   /** Creates a docfile that has the same path as the given file, with default values for everything else. */
50   public DocFile(File JavaDoc f) { this(f, null, null, false, null); }
51   
52   /** Creates a docfile from the given pathname with default values for everything else. */
53   public DocFile(String JavaDoc pathname) { this(pathname, null, null, false, null); }
54   
55   /** Creates a docfile from the given parent and child with default values for everything else. */
56   public DocFile(String JavaDoc parent, String JavaDoc child) { this(parent, child, null, null, false, null); }
57   
58   public DocFile(String JavaDoc pathname, Pair<Integer JavaDoc,Integer JavaDoc> selection, Pair<Integer JavaDoc,Integer JavaDoc> scroll, boolean active, String JavaDoc srcRoot) {
59     super(pathname);
60     init(selection, scroll, active, srcRoot);
61   }
62   public DocFile(File JavaDoc f, Pair<Integer JavaDoc,Integer JavaDoc> selection, Pair<Integer JavaDoc,Integer JavaDoc> scroll, boolean active, String JavaDoc srcRoot) {
63     super(f, "");
64     init(selection, scroll, active, srcRoot);
65   }
66   
67   public DocFile(String JavaDoc parent, String JavaDoc child, Pair<Integer JavaDoc,Integer JavaDoc> selection, Pair<Integer JavaDoc,Integer JavaDoc> scroll, boolean active, String JavaDoc srcRoot) {
68     super(parent, child);
69     init(selection, scroll, active, srcRoot);
70   }
71   
72   private void init(Pair<Integer JavaDoc,Integer JavaDoc> selection, Pair<Integer JavaDoc,Integer JavaDoc> scroll, boolean active, String JavaDoc pack) {
73     _sel = selection;
74     _scroll = scroll;
75     _active = active;
76     _package = pack;
77   }
78   ///////////////////// Overriden Methods //////////////////////
79

80   
81   public DocFile getAbsoluteFile() {
82     if (isAbsolute()) return this;
83     else
84       return new DocFile(super.getAbsoluteFile(), _sel, _scroll, _active, _package);
85   }
86   
87   public DocFile getCanonicalFile() throws IOException JavaDoc {
88     return new DocFile(super.getCanonicalFile(), _sel, _scroll, _active, _package);
89   }
90   ///////////////////// Extra Data Methods /////////////////////
91

92   /** @return the selection with the start and ending locations paired together. The cursor location is at the second
93    * location in the pair while the selection is defined between the two.
94    */

95   public Pair<Integer JavaDoc,Integer JavaDoc> getSelection() { return _sel; }
96   
97   /** @param sel the pair to set the selection to */
98   public void setSelection(Pair<Integer JavaDoc,Integer JavaDoc> sel) { _sel = sel; }
99   
100   /** @param start the start of the selection
101    * @param end the end of the selection (and the cursor position)
102    */

103   public void setSelection(int start, int end) {
104     _sel = new Pair<Integer JavaDoc,Integer JavaDoc>(new Integer JavaDoc(start), new Integer JavaDoc(end));
105   }
106   /** @return the selection with the first element being the vertical scroll and the second being the horizontal scroll. */
107   public Pair<Integer JavaDoc,Integer JavaDoc> getScroll() { return _scroll; }
108   
109   /** @param scroll the pair to set the selection to */
110   public void setScroll(Pair<Integer JavaDoc,Integer JavaDoc> scroll) { _scroll = scroll; }
111   
112   /** @param vert the vertical scroll of the scroll pane
113    * @param horiz the horizonal scroll of the scroll pane
114    */

115   public void setScroll(int vert, int horiz) {
116     _scroll = new Pair<Integer JavaDoc,Integer JavaDoc>(new Integer JavaDoc(vert), new Integer JavaDoc(horiz));
117   }
118   
119   /** @return {@code true} if this file is supposed to be the active document when opened. */
120   public boolean isActive() { return _active; }
121   
122   /** @param active Whether this file should be the active document when opened. */
123   
124   public void setActive(boolean active) { _active = active; }
125   /** @return the package of the document stored in this file */
126   
127   public String JavaDoc getPackage() { return _package; }
128   
129   /** @param pkg The name of the package defined in the document text. */
130   public void setPackage(String JavaDoc pkg) { _package = pkg; }
131   
132   /** Sets lastModified for this file to the time the including project file was saved. The <code>lastModified</code>
133    * date any documents saved after the project file was written will not match the date recorded in the project file.
134    * @param mod the last known modification date when the project was saved.
135    */

136   public void setSavedModDate(long mod) { _mod = mod; }
137   
138   /** @return The modification date of this file at the time the project file was generated. */
139   public long getSavedModDate() { return _mod; }
140 }
Popular Tags