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.model;
038:
039: import edu.rice.cs.util.Lambda;
040: import java.util.Vector;
041:
042: /** Interface for a region manager.
043: * @version $Id$
044: */
045: public interface RegionManager<R extends DocumentRegion> {
046: /** Returns the region in this manager at the given offset, or null if one does not exist.
047: * @param odd the document
048: * @param offset the offset in the document
049: * @return the DocumentRegion at the given line number, or null if it does not exist.
050: */
051: public R getRegionAt(OpenDefinitionsDocument odd, int offset);
052:
053: /** Get the DocumentRegion that is stored in this RegionsTreePanel overlapping the area for the given document,
054: * or null if it doesn't exist.
055: * @param odd the document
056: * @param startOffset the start offset
057: * @param endOffset the end offset
058: * @return the DocumentRegion or null
059: */
060: public R getRegionOverlapping(OpenDefinitionsDocument odd,
061: int startOffset, int endOffset);
062:
063: /** Add the supplied DocumentRegion to the manager.
064: * @param region the DocumentRegion to be inserted into the manager
065: */
066: public void addRegion(R region);
067:
068: /** Remove the given DocumentRegion from the manager.
069: * @param region the DocumentRegion to be removed.
070: */
071: public void removeRegion(R region);
072:
073: /** Apply the given command to the specified region to change it.
074: * @param region the region to find and change
075: * @param cmd command that mutates the region. */
076: public void changeRegion(R region, Lambda<Object, R> cmd);
077:
078: /** @return a Vector<R> containing the DocumentRegion objects in this mangager. */
079: public Vector<R> getRegions();
080:
081: /** Tells the manager to remove all regions. */
082: public void clearRegions();
083:
084: /** @return the current region or null if none selected */
085: public R getCurrentRegion();
086:
087: /** @return the index of the current region or -1 if none selected */
088: public int getCurrentRegionIndex();
089:
090: /** @return true if the current region is the first in the list, i.e. prevCurrentRegion is without effect */
091: public boolean isCurrentRegionFirst();
092:
093: /** @return true if the current region is the last in the list, i.e. nextCurrentRegion is without effect */
094: public boolean isCurrentRegionLast();
095:
096: /** Set the current region.
097: * @param region new current region */
098: public void setCurrentRegion(R region);
099:
100: /** Make the region that is more recent the current region.
101: * @return new current region */
102: public R nextCurrentRegion();
103:
104: /** Make the region that is less recent the current region.
105: * @return new current region */
106: public R prevCurrentRegion();
107:
108: /**
109: * Set the maximum number of regions that can be stored in this manager.
110: * If the maximum capacity has been reached and another region is added, the region at the end farther
111: * away from the insertion location will be discarded.
112: * @param size maximum number of regions, or 0 if no maximum
113: */
114: public void setMaximumSize(int size);
115:
116: /** @return the maximum number of regions that can be stored in this manager. */
117: public int getMaximumSize();
118:
119: /** Adds a listener to the notifier.
120: * @param listener a listener that reacts on events
121: */
122: public void addListener(RegionManagerListener<R> listener);
123:
124: /** Removes a listener from the notifier.
125: * @param listener a listener that reacts on events
126: */
127: public void removeListener(RegionManagerListener<R> listener);
128:
129: /** Removes all listeners from this notifier. */
130: public void removeAllListeners();
131: }
|