001: package com.xoetrope.carousel.visualizer;
002:
003: import java.awt.BorderLayout;
004: import java.util.Vector;
005: import javax.swing.JPanel;
006: import net.xoetrope.editor.project.XEditorProject;
007: import net.xoetrope.editor.project.pages.IXPagePanel;
008: import net.xoetrope.editor.project.pages.XComponentSizer;
009: import net.xoetrope.editor.project.pages.components.ComponentHelper;
010: import net.xoetrope.editor.project.pages.components.PropertyHelper;
011: import net.xoetrope.editor.project.pages.events.ComponentSelectListener;
012: import net.xoetrope.xui.XProject;
013: import net.xoetrope.xui.XProjectManager;
014: import net.xoetrope.xui.data.XModel;
015:
016: /**
017: *
018: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
019: * the GNU Public License (GPL), please see license.txt for more details. If
020: * you make commercial use of this software you must purchase a commercial
021: * license from Xoetrope.</p>
022: * <p> $Revision: 1.18 $</p>
023: */
024: public class VisualiserContainer extends JPanel implements
025: ModelTreeListener, ComponentSelectListener {
026: private ModelVisualiserPanel visualiserPanel;
027: private Vector activeComponents;
028: private IXPagePanel activePage;
029: private XProject currentProject;
030: private VisualiserProxy visualiserProxy;
031: private XEditorProject currentEditorProject;
032: private XModel rootModel;
033: private boolean debugView;
034:
035: /**
036: * Creates a new instance of VisualiserPanel
037: */
038: public VisualiserContainer(VisualiserDebuggerEngine debuggerEngine) {
039: this (debuggerEngine, 200);
040: }
041:
042: /**
043: * Creates a new instance of VisualiserPanel
044: */
045: public VisualiserContainer(VisualiserDebuggerEngine debuggerEngine,
046: int preferredWidth) {
047: currentProject = XProjectManager.getCurrentProject();
048: if (currentProject instanceof XEditorProject) {
049: currentEditorProject = (XEditorProject) currentProject;
050: // currentEditorProject.addComponentSelectionListener( this );
051: }
052: debugView = (debuggerEngine != null);
053: setLayout(new BorderLayout());
054:
055: visualiserPanel = new ModelVisualiserPanel(preferredWidth,
056: debuggerEngine);
057: visualiserPanel.setVisible(true);
058: visualiserPanel.setModelTreeListener(this );
059:
060: if (!debugView)
061: setRootModel(currentProject.getModel());
062:
063: add(visualiserPanel, BorderLayout.CENTER);
064: }
065:
066: /**
067: * Refresh the display
068: */
069: public void refresh() {
070: visualiserPanel.refresh(null);
071: }
072:
073: /**
074: * Set the root mode node displayed by this visualizer
075: * @param root the root of the node hierarchy
076: */
077: public void setRootModel(XModel root) {
078: rootModel = root;
079: visualiserPanel.setRootModel(rootModel);
080: }
081:
082: public void setVisualiserProxy(VisualiserProxy proxy) {
083: visualiserProxy = proxy;
084: }
085:
086: public void nodeInvoked(String modelPath) {
087: if (visualiserProxy != null)
088: visualiserProxy.nodeDoubleClicked(modelPath);
089: }
090:
091: public void componentClosed() {
092: if (currentEditorProject != null)
093: currentEditorProject.removeComponentSelectionListener(this );
094: }
095:
096: public void setSelectedPath(String path) {
097: visualiserPanel.setSelectedPath(path);
098: }
099:
100: public void setSelectedComponents(IXPagePanel currentPanel,
101: Vector selectedComponents, boolean contentsChanged) {
102: if (!contentsChanged)
103: return;
104: activeComponents = selectedComponents;
105: activePage = currentPanel;
106: if ((selectedComponents != null)
107: && (selectedComponents.size() > 0)) {
108: XComponentSizer comp = (XComponentSizer) selectedComponents
109: .get(0);
110: PropertyHelper helper = new ComponentHelper()
111: .getPropertyHelper(comp.getTarget());
112: String attributeValue = helper.getPropertyValue(comp
113: .getPageResource(), comp.getTarget(), "Data");
114: visualiserPanel.setSelectedPath(attributeValue);
115: }
116: }
117:
118: }
|