001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041: package org.netbeans.modules.vmd.analyzer;
042:
043: import org.netbeans.modules.vmd.api.analyzer.Analyzer;
044: import org.netbeans.modules.vmd.api.io.DataEditorView;
045: import org.netbeans.modules.vmd.api.io.DataObjectContext;
046: import org.netbeans.modules.vmd.api.io.DesignDocumentAwareness;
047: import org.netbeans.modules.vmd.api.model.DesignDocument;
048: import org.openide.awt.UndoRedo;
049: import org.openide.util.HelpCtx;
050: import org.openide.util.Lookup;
051: import org.openide.util.NbBundle;
052: import org.openide.util.Utilities;
053:
054: import javax.swing.*;
055: import java.awt.*;
056: import java.awt.event.ActionEvent;
057: import java.awt.event.ActionListener;
058: import java.io.IOException;
059: import java.util.Collection;
060: import java.util.Collections;
061: import java.util.HashMap;
062: import java.util.Map;
063:
064: /**
065: * @author David Kaspar
066: */
067: public class AnalyzerEditorView implements DataEditorView,
068: DesignDocumentAwareness {
069:
070: private static final Color BACKGROUND_COLOR = new Color(0xFBF9F3);
071:
072: private static final long serialVersionUID = -1;
073:
074: static final String ANALYZER_ID = "analyzer"; // NOI18N
075:
076: private DataObjectContext context;
077: private transient HashMap<Analyzer, JComponent> components;
078: private transient DesignDocument document;
079: private transient JScrollPane scroll;
080: private transient JToolBar toolbar;
081:
082: public AnalyzerEditorView(DataObjectContext context) {
083: this .context = context;
084: init();
085: }
086:
087: private void init() {
088: components = new HashMap<Analyzer, JComponent>();
089: Collection<? extends Analyzer> analyzers = Lookup.getDefault()
090: .lookupResult(Analyzer.class).allInstances();
091:
092: JPanel panel = new JPanel();
093: panel.setLayout(new GridBagLayout());
094: panel.setBackground(BACKGROUND_COLOR);
095: panel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
096: scroll = new JScrollPane(panel);
097:
098: GridBagConstraints constraints = new GridBagConstraints();
099: constraints.weightx = 1.0;
100: constraints.weighty = 0.0;
101: constraints.insets = new Insets(10, 10, 10, 10);
102: constraints.fill = GridBagConstraints.HORIZONTAL;
103: constraints.gridx = GridBagConstraints.REMAINDER;
104: constraints.gridy = GridBagConstraints.RELATIVE;
105: constraints.anchor = GridBagConstraints.NORTHWEST;
106:
107: for (Analyzer analyzer : analyzers) {
108: String projectType = context.getProjectType();
109: if (projectType == null
110: || !projectType.equals(analyzer.getProjectType()))
111: continue;
112: JComponent visualRepresentation = analyzer
113: .createVisualRepresentation();
114: components.put(analyzer, visualRepresentation);
115: if (visualRepresentation != null)
116: panel.add(new AnalyzerPanel(analyzer,
117: visualRepresentation), constraints);
118: }
119: constraints.weighty = 1.0;
120: JPanel filler = new JPanel();
121: filler.setOpaque(false);
122: panel.add(filler, constraints);
123: context.addDesignDocumentAwareness(this );
124:
125: toolbar = new JToolBar();
126: toolbar.setFloatable(false);
127: toolbar.setRollover(true);
128: toolbar.setPreferredSize(new Dimension(14, 14));
129: toolbar.setSize(new Dimension(14, 14));
130: JToolBar.Separator separator = new JToolBar.Separator();
131: separator.setOrientation(JSeparator.VERTICAL);
132: toolbar.add(separator);
133:
134: JButton refreshButton = new JButton();
135: refreshButton.setOpaque(false);
136: refreshButton.setToolTipText(NbBundle.getMessage(
137: AnalyzerEditorView.class, "TTIP_Refresh")); // NOI18N
138: refreshButton.setBorderPainted(false);
139: refreshButton.setRolloverEnabled(true);
140: refreshButton.setSize(14, 14);
141: refreshButton
142: .setIcon(new ImageIcon(
143: Utilities
144: .loadImage("org/netbeans/modules/vmd/analyzer/resources/refresh.png"))); // NOI18N
145: refreshButton.addActionListener(new ActionListener() {
146: public void actionPerformed(ActionEvent e) {
147: updateAnalyzers();
148: }
149: });
150: toolbar.add(refreshButton);
151:
152: // vlv: print
153: panel.putClientProperty(java.awt.print.Printable.class, ""); // NOI18N
154: }
155:
156: public DataObjectContext getContext() {
157: return context;
158: }
159:
160: public DataEditorView.Kind getKind() {
161: return DataEditorView.Kind.MODEL;
162: }
163:
164: public boolean canShowSideWindows() {
165: return true;
166: }
167:
168: public Collection<String> getTags() {
169: return Collections.emptySet();
170: }
171:
172: public String preferredID() {
173: return ANALYZER_ID;
174: }
175:
176: public String getDisplayName() {
177: return NbBundle.getMessage(AnalyzerEditorView.class,
178: "DISP_AnalyzerView"); // NOI18N
179: }
180:
181: public HelpCtx getHelpCtx() {
182: return new HelpCtx(AnalyzerEditorView.class);
183: }
184:
185: public JComponent getVisualRepresentation() {
186: return scroll;
187: }
188:
189: public JComponent getToolbarRepresentation() {
190: return toolbar;
191: }
192:
193: public UndoRedo getUndoRedo() {
194: return null;
195: }
196:
197: public void componentOpened() {
198: }
199:
200: public void componentClosed() {
201: }
202:
203: public void componentShowing() {
204: }
205:
206: public void componentHidden() {
207: }
208:
209: public void componentActivated() {
210: updateAnalyzers();
211: }
212:
213: public void componentDeactivated() {
214: }
215:
216: public int getOpenPriority() {
217: return 0;
218: }
219:
220: public int getEditPriority() {
221: return 0;
222: }
223:
224: public int getOrder() {
225: return 3000;
226: }
227:
228: private void writeObject(java.io.ObjectOutputStream out)
229: throws IOException {
230: out.writeObject(context);
231: }
232:
233: private void readObject(java.io.ObjectInputStream in)
234: throws IOException, ClassNotFoundException {
235: Object object = in.readObject();
236: if (!(object instanceof DataObjectContext))
237: throw new ClassNotFoundException(
238: "DataObjectContext expected but not found"); // NOI18N
239: context = (DataObjectContext) object;
240: init();
241: }
242:
243: public void setDesignDocument(DesignDocument designDocument) {
244: document = designDocument;
245: componentActivated();
246: }
247:
248: private void updateAnalyzers() {
249: final DesignDocument doc = document;
250: for (Map.Entry<Analyzer, JComponent> entry : components
251: .entrySet())
252: entry.getKey().update(entry.getValue(), doc);
253: }
254:
255: }
|