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

FirstClassPanel.java

Go to the documentation of this file.
00001 
00058 package com.arcle.rmt.j2se.swing.vc.rqml;
00059 
00060 import javax.swing.*;
00061 import javax.swing.event.*;
00062 import java.util.List;
00063 import java.util.Observable;
00064 import java.awt.BorderLayout;
00065 import java.awt.GridBagLayout;
00066 import java.awt.GridBagConstraints;
00067 import java.awt.Insets;
00068 import java.awt.Component;
00069 
00070 import com.arcle.rmt.rqml.RQMLFirstClass;
00071 import com.arcle.rmt.j2se.swing.ui.Controller;
00072 import com.arcle.rmt.j2se.swing.ui.Form;
00073 import com.arcle.rmt.j2se.swing.ui.View;
00074 import com.arcle.rmt.j2se.swing.ui.Controller;
00075 import com.arcle.rmt.j2se.swing.ui.ComponentView;
00076 
00082 public abstract class FirstClassPanel extends ComponentView {
00083     public FirstClassPanel(RQMLFirstClass elem) {
00084         if (elem == null) {
00085             throw new IllegalArgumentException("Parameter 'elem' cannot be null.");
00086         }
00087         _elem = elem;
00088         PanelController ctrl = (PanelController) getController();
00089         addAncestorListener(ctrl);
00090     }
00091 
00092     //-----------------------------------------------------------------------
00093     // View implementations
00094 
00095     public void update(Observable source, Object param) {
00096         if (source == getElement()) {
00097             loadData();
00098         }
00099     }
00100 
00101     //-----------------------------------------------------------------------
00102 
00107     protected abstract void loadData();
00108 
00113     protected abstract void saveData();
00114 
00124     protected void layoutForm(JComponent container, JComponent[][] components,
00125             float labelWeight, float controlWeight, int xGap, int yGap) {
00126         JPanel p1, p2;
00127         GridBagLayout gbl = new GridBagLayout();
00128         GridBagConstraints gbc = new GridBagConstraints();
00129         container.setLayout(gbl);
00130 
00131         gbc.weighty = 0;
00132         gbc.fill = gbc.NONE;
00133 
00134         for (int row=0; row < components.length; row++) {
00135             gbc.gridy = row;
00136 
00137             gbc.gridx = 0;
00138             gbc.weightx = labelWeight;
00139             gbc.anchor = gbc.EAST;
00140             gbc.insets = new Insets(yGap, 0, 0, xGap);
00141             container.add(components[row][0], gbc);
00142 
00143             gbc.gridx = 1;
00144             gbc.weightx = controlWeight;
00145             gbc.anchor = gbc.WEST;
00146             gbc.insets = new Insets(yGap, 0, 0, 0);
00147             container.add(components[row][1], gbc);
00148         }
00149     }
00150 
00151 
00157     protected void layoutForm(JComponent container,
00158             JComponent[][] components) {
00159         final float LABEL_WEIGHT = 0.3F;
00160         final float CONTROL_WEIGHT = 0.7F;
00161         final int xGap = 4;
00162         final int yGap = 2;
00163         layoutForm(container, components, LABEL_WEIGHT, CONTROL_WEIGHT, xGap,
00164             yGap);
00165     }
00166 
00167     //-----------------------------------------------------------------------
00168     // Accessor methods
00169 
00173     protected RQMLFirstClass getElement() {
00174         return _elem;
00175     }
00176 
00180     public Controller getController() {
00181         if (_controller == null) {
00182             _controller = createController();
00183         }
00184         return _controller;
00185     }
00186 
00187     //-----------------------------------------------------------------------
00188     // Factory Methods
00189 
00190 
00194     protected JLabel createLabel(String text) {
00195         return new JLabel(text);
00196     }
00197 
00201     protected JTextField createTextField() {
00202         return new JTextField();
00203     }
00204 
00208     protected JTextArea createTextArea() {
00209         JTextArea ta = new JTextArea();
00210         ta.setLineWrap(true);
00211         ta.setWrapStyleWord(true);
00212         return ta;
00213     }
00214 
00218     protected JComboBox createComboBox(Object[] items) {
00219         return new JComboBox(items);
00220     }
00221 
00226     protected JScrollPane createScrollPane(Component view) {
00227         return new JScrollPane(view);
00228     }
00229 
00233     protected PanelController createController() {
00234         return new PanelController();
00235     }
00236 
00237     //-----------------------------------------------------------------------
00238     // Member Variables
00239 
00243     private RQMLFirstClass _elem;
00244 
00248     private PanelController _controller = null;
00249 
00250     //-----------------------------------------------------------------------
00251     // Inner classes
00252 
00258     protected class PanelController implements AncestorListener, Controller {
00259         //-------------------------------------------------------------------
00260         // AncestorListener implementations
00261 
00265         public void ancestorAdded(AncestorEvent event)  {
00266             addObservable(getElement());
00267             loadData();
00268         }
00269 
00270         public void ancestorMoved(AncestorEvent event)  { }
00271 
00275         public void ancestorRemoved(AncestorEvent event) {
00276             saveData();
00277             if (getElement() instanceof Observable) {
00278                 Observable obs = (Observable) getElement();
00279                 obs.notifyObservers();
00280                 deleteObservable(obs);
00281             }
00282         }
00283 
00284         //-------------------------------------------------------------------
00285         // Controller implementations
00286 
00291         public List getActions() {
00292             return null;
00293         }
00294     }
00295 }

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