001 /*
002 * Copyright (c) 1995-2010, The University of Sheffield. See the file
003 * COPYRIGHT.txt in the software or at http://gate.ac.uk/gate/COPYRIGHT.txt
004 *
005 * This file is part of GATE (see http://gate.ac.uk/), and is free
006 * software, licenced under the GNU Library General Public License,
007 * Version 2, June 1991 (in the distribution as file licence.html,
008 * and also available at http://gate.ac.uk/gate/licence.html).
009 *
010 * AbstractDocumentView.java
011 *
012 * Valentin Tablan, Mar 25, 2004
013 *
014 * $Id: AbstractDocumentView.java 12006 2009-12-01 17:24:28Z thomas_heitz $
015 */
016
017 package gate.gui.docview;
018
019 import java.util.ArrayList;
020 import java.util.List;
021
022 import gate.Document;
023 import gate.creole.AbstractResource;
024 import gate.gui.Handle;
025 import gate.gui.annedit.AnnotationData;
026
027 /**
028 * A convenience implementation of {@link gate.gui.docview.DocumentView} that
029 * can be extended by implementers of document views.
030 * An implementation of a document view that extends this class will need to
031 * provide implementations for the three abstract methods:
032 * {@link #initGUI()}, {@link #registerHooks()} and {@link #unregisterHooks()}.
033 */
034 public abstract class AbstractDocumentView extends AbstractResource
035 implements DocumentView {
036
037 /**
038 * Notifies this view that it has become active or inactive.
039 * This method will initialise the GUI the first time the view becomes active.
040 * @param active a boolean value.
041 */
042 public void setActive(boolean active) {
043 this.active = active;
044 if(active){
045 if(!guiInitialised){
046 initGUI();
047 guiInitialised = true;
048 }
049 registerHooks();
050 }else{
051 unregisterHooks();
052 }
053 }
054
055 /**
056 * Returns the active state of this view.
057 * @return a boolean value
058 */
059 public boolean isActive() {
060 return active;
061 }
062
063 public void setSelectedAnnotations(List<AnnotationData> selectedAnnots){
064 //do nothing
065 }
066
067 /*
068 * By default return an empty list of actions.
069 * @return an empty list.
070 */
071 public List getActions() {
072 return new ArrayList();
073 }
074
075 /*
076 * By default store the handle in the {@link #handle} field.
077 */
078 public void setHandle(Handle handle) {
079 this.handle = handle;
080 }
081
082 /**
083 * Stores the target (which should always be a {@link Document}) into the
084 * {@link #document} field.
085 */
086 public void setTarget(Object target) {
087 this.document = (Document)target;
088 }
089
090 /**
091 * Gets the document this view displays.
092 * @return a {@link Document}
093 */
094 public Document getDocument(){
095 return document;
096 }
097
098 /**
099 * Stores the owner of this view into the {@link #owner} field. The owner is
100 * the {@link DocumentEditor} this view is part of.
101 */
102 public void setOwner(DocumentEditor editor) {
103 this.owner = editor;
104 }
105
106 /**
107 * @return the handle
108 */
109 public Handle getHandle() {
110 return handle;
111 }
112
113 /**
114 * @return the owner
115 */
116 public DocumentEditor getOwner() {
117 return owner;
118 }
119
120 /**
121 * Implementers should override this method and use it for populating the GUI.
122 *
123 */
124 protected abstract void initGUI();
125
126 /**
127 * This method will be called whenever the view becomes active. Implementers
128 * should use this to add hooks (such as mouse listeners) to the other views
129 * as required by their functionality.
130 */
131 protected abstract void registerHooks();
132
133 /**
134 * This method will be called whenever this view becomes inactive.
135 * Implementers should use it to unregister whatever hooks they registered
136 * in {@link #registerHooks()}.
137 *
138 */
139 protected abstract void unregisterHooks();
140
141 /**
142 * Stores the active state of this view.
143 */
144 protected boolean active = false;
145
146 /**
147 * Stores the handle of this view.
148 */
149 protected Handle handle;
150
151 /**
152 * Has the UI been initialised yet?
153 */
154 protected boolean guiInitialised = false;
155
156 /**
157 * The document this view displays.
158 */
159 protected Document document;
160
161 /**
162 * The {@link DocumentEditor} this view is part of.
163 */
164 protected DocumentEditor owner;
165 }
|