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