Main Page | Packages | Class Hierarchy | Alphabetical List | Class List | File List | Class Members | Related Pages

ComponentView.java

Go to the documentation of this file.
00001 
00058 package com.arcle.rmt.j2se.swing.ui;
00059 
00060 import javax.swing.*;
00061 import java.io.StringWriter;
00062 import java.io.PrintWriter;
00063 import java.util.Observable;
00064 import com.arcle.rmt.j2se.framework.Document;
00065 
00071 public class ComponentView extends JComponent implements View {
00072     public ComponentView() {
00073     }
00074 
00075     //-----------------------------------------------------------------------
00076     // Utility methods
00077 
00084     protected boolean addObservable(Object obj) {
00085         if (obj instanceof Observable) {
00086             Observable o = (Observable) obj;
00087             o.addObserver(this);
00088             return true;
00089         }
00090         return false;
00091     }
00092 
00100     protected boolean deleteObservable(Object obj) {
00101         if (obj instanceof Observable) {
00102             Observable o = (Observable) obj;
00103             o.deleteObserver(this);
00104             return true;
00105         }
00106         return false;
00107     }
00108 
00113     protected void showException(Exception e) {
00114         MoreSwingUtilities.showException(this, e);
00115     }
00116 
00117     //-----------------------------------------------------------------------
00118     // JComponent implementations
00119 
00124     public void addNotify() {
00125         super.addNotify();
00130         if (!initialized) {
00131             initChildren();
00132             layoutChildren();
00133             initialized = true;
00134         }
00135     }
00136 
00137     //-----------------------------------------------------------------------
00138     // Accessor Methods
00139 
00140     protected void setDead(boolean d) {
00141         dead = d;
00142     }
00143 
00144     protected boolean isDead() {
00145         return dead;
00146     }
00147 
00148     //-----------------------------------------------------------------------
00149     // View implementations
00150 
00155     public JComponent getComponent() {
00156         return this;
00157     }
00158 
00163     public void update(Observable o, Object param) {
00164         if (isDead()) {
00165             deleteObservable(o);
00166         }
00167     }
00168 
00175     public void setDocument(Document doc) {
00176         // check trivial case
00177         if (_document == doc) {
00178             return; // re-assignment, do nothing
00179         }
00180         Document old = _document;
00181         deleteObservable(_document);
00182         _document = doc;
00183         addObservable(_document);
00184         firePropertyChange("document", old, doc);
00185     }
00186 
00190     public Document getDocument() {
00191         return _document;
00192     }
00193 
00197     public Controller getController() {
00198         return null;
00199     }
00200 
00201     //-----------------------------------------------------------------------
00202     // Strategy Methods
00203 
00208     protected void initChildren() {  }
00209 
00214     protected void layoutChildren() {   }
00215 
00216     //-----------------------------------------------------------------------
00217     // Factory Methods
00218 
00219 
00220     //-----------------------------------------------------------------------
00221     // Member variables.
00222 
00226     private Document _document;
00227 
00231     private boolean initialized = false;
00232 
00237     private boolean dead = false;
00238 }

Generated on Fri Jun 18 19:51:00 2004 for Arcle Rambutan by doxygen 1.3.5