| AbstractDocumentView.java |
1 /*
2 * Copyright (c) 1998-2005, The University of Sheffield.
3 *
4 * This file is part of GATE (see http://gate.ac.uk/), and is free
5 * software, licenced under the GNU Library General Public License,
6 * Version 2, June 1991 (in the distribution as file licence.html,
7 * and also available at http://gate.ac.uk/gate/licence.html).
8 *
9 * AbstractDocumentView.java
10 *
11 * Valentin Tablan, Mar 25, 2004
12 *
13 * $Id: AbstractDocumentView.java,v 1.8 2005/01/11 13:51:35 ian Exp $
14 */
15
16 package gate.gui.docview;
17
18 import java.util.ArrayList;
19 import java.util.List;
20
21 import gate.Document;
22 import gate.creole.AbstractResource;
23 import gate.gui.Handle;
24
25 /**
26 * A convenience implementation of {@link gate.gui.docview.DocumentView} that
27 * can be extended by implementers of document views.
28 * An implementation of a document view that extends this class will need to
29 * provide implementations for the three abstract methods:
30 * {@link #initGUI()}, {@link #registerHooks()} and {@link #unregisterHooks()}.
31 */
32 public abstract class AbstractDocumentView extends AbstractResource
33 implements DocumentView {
34
35 /**
36 * Notifies this view that it has become active or inactive.
37 * This method will initialise the GUI the first time the view becomes active.
38 * @param active a boolean value.
39 */
40 public void setActive(boolean active) {
41 this.active = active;
42 if(active){
43 if(!guiInitialised){
44 initGUI();
45 guiInitialised = true;
46 }
47 registerHooks();
48 }else{
49 unregisterHooks();
50 }
51 }
52
53 /**
54 * Returns the active state of this view.
55 * @return a boolean value
56 */
57 public boolean isActive() {
58 return active;
59 }
60
61
62 /*
63 * By default return an empty list of actions.
64 * @return an empty list.
65 */
66 public List getActions() {
67 return new ArrayList();
68 }
69
70 /*
71 * By default store the handle in the {@link #handle} field.
72 */
73 public void setHandle(Handle handle) {
74 this.handle = handle;
75 }
76
77 /**
78 * Stores the target (which should always be a {@link Document}) into the
79 * {@link #document} field.
80 */
81 public void setTarget(Object target) {
82 this.document = (Document)target;
83 }
84
85 /**
86 * Gets the document this view displays.
87 * @return a {@link Document}
88 */
89 public Document getDocument(){
90 return document;
91 }
92
93 /**
94 * Stores the owner of this view into the {@link #owner} field. The owner is
95 * the {@link DocumentEditor} this view is part of.
96 */
97 public void setOwner(DocumentEditor editor) {
98 this.owner = editor;
99 }
100
101 /**
102 * Implementers should override this method and use it for populating the GUI.
103 *
104 */
105 protected abstract void initGUI();
106
107 /**
108 * This method will be called whenever the view becomes active. Implementers
109 * should use this to add hooks (such as mouse listeners) to the other views
110 * as required by their functionality.
111 */
112 protected abstract void registerHooks();
113
114 /**
115 * This method will be called whenever this view becomes inactive.
116 * Implementers should use it to unregister whatever hooks they registered
117 * in {@link #registerHooks()}.
118 *
119 */
120 protected abstract void unregisterHooks();
121
122 /**
123 * Stores the active state of this view.
124 */
125 protected boolean active = false;
126
127 /**
128 * Stores the handle of this view.
129 */
130 protected Handle handle;
131
132 /**
133 * Has the UI been initialised yet?
134 */
135 protected boolean guiInitialised = false;
136
137 /**
138 * The document this view displays.
139 */
140 protected Document document;
141
142 /**
143 * The {@link DocumentEditor} this view is part of.
144 */
145 protected DocumentEditor owner;
146 }
147
148