00001
00058 package com.arcle.rmt.j2se.swing.vc;
00059
00060 import javax.swing.*;
00061 import java.awt.Toolkit;
00062 import java.awt.BorderLayout;
00063 import java.awt.Container;
00064 import java.awt.Dimension;
00065
00066 import com.arcle.rmt.rqml.RQMLFirstClass;
00067 import com.arcle.rmt.j2se.swing.ui.View;
00068 import com.arcle.rmt.j2se.swing.ui.Controller;
00069 import com.arcle.rmt.j2se.swing.ui.ComponentView;
00070 import com.arcle.rmt.j2se.framework.Document;
00071
00101 public abstract class AbstractDesktop extends ComponentView {
00102 public AbstractDesktop() {
00103 }
00104
00108 protected void layoutChildren() {
00109 try {
00110 setLayout(new BorderLayout());
00111 JSplitPane sp1, sp2;
00112 JComponent p1, p2, p3;
00113
00114
00115 sp1 = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
00116
00117
00118 sp1.add(getDocumentTreeView().getComponent(), JSplitPane.LEFT);
00119
00120
00121 sp1.add(getDesktopPane(), JSplitPane.RIGHT);
00122
00123 sp1.setOneTouchExpandable(true);
00124 sp1.setResizeWeight(MASTER_PANE_WEIGHT);
00125
00126 add(sp1, BorderLayout.CENTER);
00127
00128
00129 add(getStatusBar().getComponent(), BorderLayout.SOUTH);
00130
00131 } catch(Exception e) {
00132 e.printStackTrace();
00133
00134 }
00135 }
00136
00137
00138
00139
00148 public void setDocument(Document doc) {
00149 super.setDocument(doc);
00150 JDesktopPane dp = getDesktopPane();
00151 View dtv = getDocumentTreeView();
00152 View sb = getStatusBar();
00153 if (doc != null) {
00154 dp.removeAll();
00155 dp.revalidate();
00156 dp.repaint();
00157 }
00158 dtv.setDocument(doc);
00159 sb.setDocument(doc);
00160 }
00161
00166 public Controller getController() {
00167 return getDocumentTreeView().getController();
00168 }
00169
00170
00171
00172
00177 protected JDesktopPane getDesktopPane() {
00178 if (_desktopPane == null) {
00179 _desktopPane = createDesktopPane();
00180 }
00181 return _desktopPane;
00182 }
00183
00187 protected View getDocumentTreeView() {
00188 if (_documentTreeView == null) {
00189 _documentTreeView = createDocumentTreeView();
00190 }
00191 return _documentTreeView;
00192 }
00193
00197 protected View getStatusBar() {
00198 if (_statusBar == null) {
00199 _statusBar = createStatusBar();
00200 }
00201 return _statusBar;
00202 }
00203
00207 protected ElementEditFactory getElementEditFactory() {
00208 if (_editFactory == null) {
00209 _editFactory = createElementEditFactory();
00210 }
00211 return _editFactory;
00212 }
00213
00214
00215
00216
00217
00222 protected abstract View createDocumentTreeView();
00223
00228 protected abstract View createStatusBar();
00229
00234 protected ElementEditFactory createElementEditFactory() {
00235 return new EditFactory();
00236 }
00237
00241 protected JDesktopPane createDesktopPane() {
00242 JDesktopPane dp = new JDesktopPane();
00243 dp.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
00244 return dp;
00245 }
00246
00251 protected JInternalFrame createInternalFrame(JComponent content) {
00252 final JInternalFrame fr = new JInternalFrame(content.getName(), true,
00253 true, true, true);
00254 final JDesktopPane dp = getDesktopPane();
00255
00256
00257 fr.setSize(150, 100);
00258 fr.setOpaque(true);
00259 fr.setVisible(true);
00260 dp.add(fr);
00261 final Container cp = fr.getContentPane();
00262 cp.add(content);
00263 fr.pack();
00264 dp.revalidate();
00265
00266 return fr;
00267 }
00268
00269
00270
00274 private View _documentTreeView = null;
00275
00279 private View _statusBar = null;
00280
00284 private JDesktopPane _desktopPane = null;
00285
00289 private ElementEditFactory _editFactory = null;
00290
00294 private static final float MASTER_PANE_WEIGHT = 0f;
00295
00296
00297
00308 protected class EditFactory implements ElementEditFactory {
00318 public ElementEdit createElementEdit(RQMLFirstClass elem) {
00319 ElementEdit ed = ElementEdit.createElementEdit(elem);
00320 setup(ed);
00321 return ed;
00322 }
00323
00329 protected void setup(ElementEdit edit) {
00330 edit.setDocument(getDocumentTreeView().getDocument());
00331 final JInternalFrame frame = createInternalFrame(edit);
00332 SwingUtilities.invokeLater(new Runnable() {
00333 public void run() {
00334 try {
00335 frame.show();
00336 frame.setMaximum(true);
00337 } catch(Exception e) {
00338 showException(e);
00339 }
00340 }
00341 });
00342 }
00343 }
00344 }
00345