001: /*BEGIN_COPYRIGHT_BLOCK
002: *
003: * Copyright (c) 2001-2007, JavaPLT group at Rice University (javaplt@rice.edu)
004: * All rights reserved.
005: *
006: * Redistribution and use in source and binary forms, with or without
007: * modification, are permitted provided that the following conditions are met:
008: * * Redistributions of source code must retain the above copyright
009: * notice, this list of conditions and the following disclaimer.
010: * * Redistributions in binary form must reproduce the above copyright
011: * notice, this list of conditions and the following disclaimer in the
012: * documentation and/or other materials provided with the distribution.
013: * * Neither the names of DrJava, the JavaPLT group, Rice University, nor the
014: * names of its contributors may be used to endorse or promote products
015: * derived from this software without specific prior written permission.
016: *
017: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
018: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
019: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
020: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR
021: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
022: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
023: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
024: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
025: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
026: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
027: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
028: *
029: * This software is Open Source Initiative approved Open Source Software.
030: * Open Source Initative Approved is a trademark of the Open Source Initiative.
031: *
032: * This file is part of DrJava. Download the current version of this project
033: * from http://www.drjava.org/ or http://sourceforge.net/projects/drjava/
034: *
035: * END_COPYRIGHT_BLOCK*/
036:
037: package edu.rice.cs.drjava.project;
038:
039: import java.io.File;
040: import java.io.IOException;
041:
042: import edu.rice.cs.plt.tuple.Pair;
043:
044: public class DocFile extends File {
045:
046: private Pair<Integer, Integer> _sel;
047: private Pair<Integer, Integer> _scroll;
048: private boolean _active;
049: private String _package;
050: private long _mod;
051:
052: /** Creates a docfile that has the same path as the given file, with default values for everything else. */
053: public DocFile(File f) {
054: this (f, null, null, false, null);
055: }
056:
057: /** Creates a docfile from the given pathname with default values for everything else. */
058: public DocFile(String pathname) {
059: this (pathname, null, null, false, null);
060: }
061:
062: /** Creates a docfile from the given parent and child with default values for everything else. */
063: public DocFile(String parent, String child) {
064: this (parent, child, null, null, false, null);
065: }
066:
067: public DocFile(String pathname, Pair<Integer, Integer> selection,
068: Pair<Integer, Integer> scroll, boolean active,
069: String srcRoot) {
070: super (pathname);
071: init(selection, scroll, active, srcRoot);
072: }
073:
074: public DocFile(File f, Pair<Integer, Integer> selection,
075: Pair<Integer, Integer> scroll, boolean active,
076: String srcRoot) {
077: super (f, "");
078: init(selection, scroll, active, srcRoot);
079: }
080:
081: public DocFile(String parent, String child,
082: Pair<Integer, Integer> selection,
083: Pair<Integer, Integer> scroll, boolean active,
084: String srcRoot) {
085: super (parent, child);
086: init(selection, scroll, active, srcRoot);
087: }
088:
089: private void init(Pair<Integer, Integer> selection,
090: Pair<Integer, Integer> scroll, boolean active, String pack) {
091: _sel = selection;
092: _scroll = scroll;
093: _active = active;
094: _package = pack;
095: }
096:
097: ///////////////////// Overriden Methods //////////////////////
098:
099: public DocFile getAbsoluteFile() {
100: if (isAbsolute())
101: return this ;
102: else
103: return new DocFile(super .getAbsoluteFile(), _sel, _scroll,
104: _active, _package);
105: }
106:
107: public DocFile getCanonicalFile() throws IOException {
108: return new DocFile(super .getCanonicalFile(), _sel, _scroll,
109: _active, _package);
110: }
111:
112: ///////////////////// Extra Data Methods /////////////////////
113:
114: /** @return the selection with the start and ending locations paired together. The cursor location is at the second
115: * location in the pair while the selection is defined between the two.
116: */
117: public Pair<Integer, Integer> getSelection() {
118: return _sel;
119: }
120:
121: /** @param sel the pair to set the selection to */
122: public void setSelection(Pair<Integer, Integer> sel) {
123: _sel = sel;
124: }
125:
126: /** @param start the start of the selection
127: * @param end the end of the selection (and the cursor position)
128: */
129: public void setSelection(int start, int end) {
130: _sel = new Pair<Integer, Integer>(new Integer(start),
131: new Integer(end));
132: }
133:
134: /** @return the selection with the first element being the vertical scroll and the second being the horizontal scroll. */
135: public Pair<Integer, Integer> getScroll() {
136: return _scroll;
137: }
138:
139: /** @param scroll the pair to set the selection to */
140: public void setScroll(Pair<Integer, Integer> scroll) {
141: _scroll = scroll;
142: }
143:
144: /** @param vert the vertical scroll of the scroll pane
145: * @param horiz the horizonal scroll of the scroll pane
146: */
147: public void setScroll(int vert, int horiz) {
148: _scroll = new Pair<Integer, Integer>(new Integer(vert),
149: new Integer(horiz));
150: }
151:
152: /** @return {@code true} if this file is supposed to be the active document when opened. */
153: public boolean isActive() {
154: return _active;
155: }
156:
157: /** @param active Whether this file should be the active document when opened. */
158:
159: public void setActive(boolean active) {
160: _active = active;
161: }
162:
163: /** @return the package of the document stored in this file */
164:
165: public String getPackage() {
166: return _package;
167: }
168:
169: /** @param pkg The name of the package defined in the document text. */
170: public void setPackage(String pkg) {
171: _package = pkg;
172: }
173:
174: /** Sets lastModified for this file to the time the including project file was saved. The <code>lastModified</code>
175: * date any documents saved after the project file was written will not match the date recorded in the project file.
176: * @param mod the last known modification date when the project was saved.
177: */
178: public void setSavedModDate(long mod) {
179: _mod = mod;
180: }
181:
182: /** @return The modification date of this file at the time the project file was generated. */
183: public long getSavedModDate() {
184: return _mod;
185: }
186: }
|