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    *  Valentin Tablan 27/02/2002
10   *
11   *  $Id: PRViewer.java,v 1.8 2005/01/11 13:51:34 ian Exp $
12   *
13   */
14  package gate.gui;
15  
16  import java.awt.BorderLayout;
17  import java.awt.Component;
18  
19  import javax.swing.JScrollPane;
20  
21  import gate.Gate;
22  import gate.Resource;
23  import gate.creole.AbstractVisualResource;
24  import gate.creole.ResourceData;
25  import gate.util.GateRuntimeException;
26  
27  
28  public class PRViewer extends AbstractVisualResource {
29  
30    public PRViewer() {
31      initLocalData();
32      initGuiComponents();
33      initListeners();
34    }
35  
36    protected void initLocalData(){
37    }
38  
39    protected void initGuiComponents(){
40      setLayout(new BorderLayout());
41      editor = new ResourceParametersEditor();
42      editor.setEditable(false);
43      JScrollPane scroller = new JScrollPane(editor);
44      scroller.setAlignmentX(Component.LEFT_ALIGNMENT);
45      scroller.setAlignmentY(Component.TOP_ALIGNMENT);
46      add(scroller, BorderLayout.CENTER);
47    }
48  
49    protected void initListeners(){
50    }
51  
52    public void cleanup(){
53      super.cleanup();
54      editor.cleanup();
55    }
56  
57    public void setTarget(Object target){
58      if(target == null) return;
59      if(!(target instanceof Resource)){
60        throw new GateRuntimeException(this.getClass().getName() +
61                                       " can only be used to display " +
62                                       Resource.class.getName() +
63                                       "\n" + target.getClass().getName() +
64                                       " is not a " +
65                                       Resource.class.getName() + "!");
66      }
67      if(target != null){
68        Resource pr = (Resource)target;
69        ResourceData rData = (ResourceData)Gate.getCreoleRegister().
70                                                get(pr.getClass().getName());
71        if(rData != null){
72          editor.init(pr, rData.getParameterList().getInitimeParameters());
73        }else{
74          editor.init(pr, null);
75        }
76      }else{
77        editor.init(null, null);
78      }
79      editor.removeCreoleListenerLink();
80    }
81  
82    ResourceParametersEditor editor;
83  }