Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: jac/aspects/gui/web/ReferenceView.java


1   /*
2     Copyright (C) 2002 Laurent Martelli <laurent@aopsys.com>
3     
4     This program is free software; you can redistribute it and/or modify
5     it under the terms of the GNU Lesser General Public License as
6     published by the Free Software Foundation; either version 2 of the
7     License, or (at your option) any later version.
8   
9     This program is distributed in the hope that it will be useful, but
10    WITHOUT ANY WARRANTY; without even the implied warranty of
11    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
12    Lesser General Public License for more details.
13  
14    You should have received a copy of the GNU Lesser General Public
15    License along with this program; if not, write to the Free Software
16    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
17    USA */
18  
19  package jac.aspects.gui.web;
20  
21  import jac.aspects.gui.*;
22  import jac.core.rtti.ClassItem;
23  import jac.core.rtti.FieldItem;
24  import jac.util.Log;
25  import jac.util.Stack;
26  import java.io.PrintWriter;
27  
28  /**
29   * This class defines a Swing component view for references in
30   * objects.
31   *
32   * <p>By default this view constructs an embedded <code>JLabel</code>
33   * containing the string representation of the referenced object. However,
34   * the field can be attributed to be displayed with a customized
35   * rendering by the GUI aspect component.
36   *
37   * @see GuiAC
38   * @see FieldView 
39   */
40  
41  public class ReferenceView extends AbstractFieldView 
42     implements FieldView, FieldUpdate, ObjectUpdate, HTMLViewer, SelectionListener {
43  
44     Object object;
45     String text;
46     String eventURL;
47  
48     /**
49      * Constructs a new reference view.
50      *
51      * @param substance the object the viewed field belongs to */
52  
53     public ReferenceView(Object value, Object substance, FieldItem reference) {
54        super(substance,reference);
55        this.object = value;
56  
57        Utils.registerField(substance,reference,this);
58  
59        refreshView();
60     }
61  
62     public ReferenceView() {
63     }
64  
65  
66     public void refreshView() {
67        Utils.registerObject(object,this);
68        if (object!=null) {
69           text = GuiAC.toString(object,contexts);
70        } else {
71           text = "";
72        }
73     }
74  
75     /**
76      * Set the URL to link to.
77      */
78     public void setEventURL(String eventURL) {
79        this.eventURL = eventURL;
80     }
81  
82     // FieldView interface
83  
84     public void setValue(Object value) {
85        Utils.unregisterObject(object,this);
86        this.object = value;
87        refreshView();
88     }
89  
90     public void close() {
91        Utils.unregisterObject(object,this);
92        Utils.unregisterField(substance,field,this);
93     }
94  
95     // FieldUpdate interface
96  
97     public void fieldUpdated(Object substance, FieldItem field, Object value, Object param) {
98        setValue(value);
99     }
100 
101    // ObjectUpdate interface
102 
103    public void objectUpdated(Object object, Object param) {
104       refreshView();
105    }
106 
107    // HTMLViewer interface
108    public void genHTML(PrintWriter out) {
109       out.println("<a href=\""+
110                   (eventURL!=null?eventURL:eventURL("onSelection"))+"\">"+text+"</a>");
111    }
112 
113    // SelectionListener interface
114 
115    public void onSelection() {
116       EventHandler.get().onSelection(context,field,object,null,null,true);
117    }
118 
119 }