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-2007 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:
042: package org.netbeans.modules.xml.nbprefuse;
043:
044: import java.awt.BorderLayout;
045: import java.awt.Dimension;
046: import java.beans.PropertyChangeEvent;
047: import java.beans.PropertyChangeListener;
048: import javax.swing.JComponent;
049: import javax.swing.JPanel;
050: import org.openide.util.NbBundle;
051:
052: /**
053: *
054: * @author Jeri Lockhart
055: */
056: public class AnalysisViewer extends JPanel implements
057:
058: PropertyChangeListener {
059: public static final String PROP_GRAPH_NODE_SELECTION_CHANGE = "prop-graph-node-selection-changed";
060: public static final String PROP_GRAPH_NODE_SELECTION_CHANGED_RELAY = "prop-graph-node-selection-changed-relay";
061:
062: public static final long serialVersionUID = -7710166579907141983L;
063: transient private View currentView;
064: private boolean reshowOnResize = true;
065:
066: /**
067: * Creates new form AnalysisViewer
068: */
069: public AnalysisViewer() {
070: initComponents();
071: initialize();
072: }
073:
074: private void initialize() {
075: setMinimumSize(new Dimension(180, 30));
076: // addComponentListener(new ComponentAdapter(){
077: // public void componentResized(ComponentEvent e) {
078: // if (currentView != null && reshowOnResize){
079: // currentView.usePacer(false);
080: // showCurrentView();
081: // }
082: // }
083: // });
084: }
085:
086: public void setCurrentView(final View view) {
087: this .currentView = view;
088: }
089:
090: public void removeToolBar() {
091: remove(toolbarPnl);
092: validate();
093: repaint();
094: }
095:
096: private void showCurrentView() {
097: if (currentView != null) {
098: showView(currentView);
099: }
100: }
101:
102: public void addDisplayPanel(JPanel displayPanel) {
103: displayContainerPnl.removeAll();
104: displayContainerPnl.setLayout(new BorderLayout());
105: displayContainerPnl.add(displayPanel, BorderLayout.CENTER);
106: }
107:
108: public boolean showView(View view) {
109: currentView = view;
110:
111: if (view.showView(this )) {
112: validate();
113: repaint();
114: }
115: return true;
116: }
117:
118: /**
119: *
120: *
121: */
122: public JPanel getPanel() {
123: return this ;
124: }
125:
126: /**
127: *
128: *
129: */
130: // public Column getColumn(){
131: // return this;
132: // }
133:
134: public void propertyChange(PropertyChangeEvent evt) {
135: String propertyName = evt.getPropertyName();
136: if (propertyName.equals(PROP_GRAPH_NODE_SELECTION_CHANGE)) {
137: // WhereUsedView's selectionFocusControl(FindUsagesFocusControl)
138: // fired this event
139: // now notify RefactoringPanel so it can select
140: // the corresponding node in the RefactoringPanel explorer
141: firePropertyChange(PROP_GRAPH_NODE_SELECTION_CHANGED_RELAY,
142: evt.getOldValue(), evt.getNewValue());
143:
144: }
145: }
146:
147: /**
148: * @return true if this Viewer will reshow the view
149: * when the JPanel is resized
150: * false if not
151: *
152: */
153: public boolean getReshowOnResize() {
154: return this .reshowOnResize;
155: }
156:
157: /**
158: * @param reshowOnResize true if this viewer should
159: * reshow the view when the panel is resized
160: *
161: */
162: public void setReshowOnResize(boolean reshowOnResize) {
163: this .reshowOnResize = reshowOnResize;
164: }
165:
166: /** This method is called from within the constructor to
167: * initialize the form.
168: * WARNING: Do NOT modify this code. The content of this method is
169: * always regenerated by the Form Editor.
170: */
171: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
172: private void initComponents() {
173: toolbarPnl = new javax.swing.JPanel();
174: jToolBar1 = new javax.swing.JToolBar();
175: layoutBtn = new javax.swing.JButton();
176: displayContainerPnl = new javax.swing.JPanel();
177:
178: setLayout(new java.awt.BorderLayout());
179:
180: setBackground(java.awt.Color.white);
181: setPreferredSize(new java.awt.Dimension(200, 200));
182: toolbarPnl.setLayout(new java.awt.BorderLayout());
183:
184: jToolBar1.setFloatable(false);
185: jToolBar1.setOrientation(1);
186: layoutBtn
187: .setIcon(new javax.swing.ImageIcon(
188: getClass()
189: .getResource(
190: "/org/netbeans/modules/xml/nbprefuse/resources/relayout.png")));
191: layoutBtn.setToolTipText(java.util.ResourceBundle.getBundle(
192: "org/netbeans/modules/xml/nbprefuse/Bundle").getString(
193: "LBL_Relayout_graph"));
194: layoutBtn
195: .addActionListener(new java.awt.event.ActionListener() {
196: public void actionPerformed(
197: java.awt.event.ActionEvent evt) {
198: layoutBtnActionPerformed(evt);
199: }
200: });
201:
202: jToolBar1.add(layoutBtn);
203:
204: toolbarPnl.add(jToolBar1, java.awt.BorderLayout.CENTER);
205:
206: add(toolbarPnl, java.awt.BorderLayout.WEST);
207:
208: displayContainerPnl.setLayout(null);
209:
210: displayContainerPnl.setBorder(javax.swing.BorderFactory
211: .createLineBorder(java.awt.Color.gray));
212: add(displayContainerPnl, java.awt.BorderLayout.CENTER);
213:
214: }// </editor-fold>//GEN-END:initComponents
215:
216: private void layoutBtnActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_layoutBtnActionPerformed
217: // TODO add your handling code here:
218: if (currentView != null) {
219: showView(currentView);
220: }
221: }//GEN-LAST:event_layoutBtnActionPerformed
222:
223: // Variables declaration - do not modify//GEN-BEGIN:variables
224: private javax.swing.JPanel displayContainerPnl;
225: private javax.swing.JToolBar jToolBar1;
226: private javax.swing.JButton layoutBtn;
227: private javax.swing.JPanel toolbarPnl;
228: // End of variables declaration//GEN-END:variables
229:
230: }
|