|
AbstractVisualResource |
|
1 /* 2 * AbstractVisualResource.java 3 * 4 * Copyright (c) 1998-2001, The University of Sheffield. 5 * 6 * This file is part of GATE (see http://gate.ac.uk/), and is free 7 * software, licenced under the GNU Library General Public License, 8 * Version 2, June 1991 (in the distribution as file licence.html, 9 * and also available at http://gate.ac.uk/gate/licence.html). 10 * 11 * Cristian URSU, 24/Jan/2001 12 * 13 * $Id: AbstractVisualResource.java,v 1.11 2001/11/12 18:54:50 kalina Exp $ 14 */ 15 16 package gate.creole; 17 18 import javax.swing.JPanel; 19 20 21 import gate.*; 22 import gate.util.*; 23 import gate.gui.Handle; 24 25 import java.beans.*; 26 import java.util.*; 27 import java.lang.reflect.*; 28 29 /** A convenience implementation of VisualResource with some default code. */ 30 public abstract class AbstractVisualResource extends JPanel 31 implements VisualResource{ 32 33 /** 34 * Package access constructor to stop normal initialisation. 35 * This kind of resources should only be created by the Factory class 36 */ 37 public AbstractVisualResource(){ 38 } 39 40 /** Accessor for features. */ 41 public FeatureMap getFeatures(){ 42 return features; 43 }//getFeatures() 44 45 /** Mutator for features*/ 46 public void setFeatures(FeatureMap features){ 47 this.features = features; 48 }// setFeatures() 49 50 /** Initialise this resource, and return it. */ 51 public Resource init() throws ResourceInstantiationException { 52 return this; 53 }//init() 54 55 /** Does nothing now, but meant to clear all internal data **/ 56 public void cleanup() { 57 }//clear() 58 59 /** 60 * Called by the GUI when this viewer/editor has to initialise itself for a 61 * specific object. 62 * @param target the object (be it a {@link gate.Resource}, 63 * {@link gate.DataStore} or whatever) this viewer has to display 64 */ 65 public void setTarget(Object target){ 66 throw new RuntimeException( 67 "Class " + getClass() + " hasn't implemented the setTarget() method!"); 68 } 69 70 71 /** 72 * Used by the main GUI to tell this VR what handle created it. The VRs can 73 * use this information e.g. to add items to the popup for the resource. 74 */ 75 public void setHandle(Handle handle){ 76 } 77 78 //Parameters utility methods 79 /** 80 * Gets the value of a parameter of this resource. 81 * @param paramaterName the name of the parameter 82 * @return the current value of the parameter 83 */ 84 public Object getParameterValue(String paramaterName) 85 throws ResourceInstantiationException{ 86 return AbstractResource.getParameterValue(this, paramaterName); 87 } 88 89 /** 90 * Sets the value for a specified parameter. 91 * 92 * @param paramaterName the name for the parameteer 93 * @param parameterValue the value the parameter will receive 94 */ 95 public void setParameterValue(String paramaterName, Object parameterValue) 96 throws ResourceInstantiationException{ 97 // get the beaninfo for the resource bean, excluding data about Object 98 BeanInfo resBeanInf = null; 99 try { 100 resBeanInf = Introspector.getBeanInfo(this.getClass(), Object.class); 101 } catch(Exception e) { 102 throw new ResourceInstantiationException( 103 "Couldn't get bean info for resource " + this.getClass().getName() 104 + Strings.getNl() + "Introspector exception was: " + e 105 ); 106 } 107 AbstractResource.setParameterValue(this, resBeanInf, paramaterName, parameterValue); 108 } 109 110 /** 111 * Sets the values for more parameters in one step. 112 * 113 * @param parameters a feature map that has paramete names as keys and 114 * parameter values as values. 115 */ 116 public void setParameterValues(FeatureMap parameters) 117 throws ResourceInstantiationException{ 118 AbstractResource.setParameterValues(this, parameters); 119 } 120 121 // Properties for the resource 122 protected FeatureMap features; 123 124 }//AbstractVisualResource
|
AbstractVisualResource |
|