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: /*
043: * Created on Jun 18, 2003
044: *
045: */
046: package org.netbeans.modules.uml.ui.swing.treetable;
047:
048: import java.awt.GridBagLayout;
049: import java.awt.event.ActionEvent;
050: import java.awt.event.ActionListener;
051: import java.awt.event.MouseEvent;
052: import java.awt.event.MouseListener;
053:
054: import javax.swing.JMenuItem;
055: import javax.swing.JPopupMenu;
056: import javax.swing.ToolTipManager;
057: import javax.swing.event.MouseInputAdapter;
058: import javax.swing.table.TableColumnModel;
059: import javax.swing.tree.TreePath;
060:
061: import org.netbeans.modules.uml.common.ETSystem;
062: import org.netbeans.modules.uml.core.support.umlutils.IPropertyDefinition;
063: import org.netbeans.modules.uml.core.support.umlutils.IPropertyElement; //import org.netbeans.modules.uml.ui.addins.webreport.WebRPTFormatDlg;
064: import org.netbeans.modules.uml.ui.swing.propertyeditor.PropertyEditorResources;
065:
066: public class RPTWizPropertyTreeTable extends JTreeTable implements
067: ActionListener {
068: private JPopupMenu m_popup = null;
069: //private WebRPTFormatDlg m_editor = null;
070:
071: private int m_CurRow = 0;
072: private IPropertyElement m_CurElement = null;
073:
074: /**
075: *
076: */
077: public RPTWizPropertyTreeTable(TreeTableModel treeTableModel/*, WebRPTFormatDlg editor*/) {
078: super (treeTableModel);
079: // m_editor = editor;
080:
081: m_popup = new JPopupMenu();
082:
083: GridBagLayout gbl = new GridBagLayout();
084: double[] vals = { 0.0, 0.5, 0.5 };
085: gbl.columnWeights = vals;
086: setLayout(gbl);
087: gbl.invalidateLayout(this );
088: doLayout();
089:
090: TableColumnModel colMod = getColumnModel();
091: TreeTableCellEditor cellEditor = new TreeTableCellEditor(tree/*, editor*/);
092: colMod.getColumn(1).setCellEditor(cellEditor);
093: colMod.getColumn(2).setCellEditor(cellEditor);
094: colMod.getColumn(0).setCellEditor(cellEditor);
095:
096: colMod.getColumn(0).setMinWidth(16);
097: colMod.getColumn(0).setMaxWidth(16);
098:
099: RPTWizPropertyValueCellRenderer valueRenderer = new RPTWizPropertyValueCellRenderer();
100: colMod.getColumn(1).setCellRenderer(tree);
101: colMod.getColumn(2).setCellRenderer(valueRenderer);
102:
103: MouseListener popupListener = new TreeTablePopupListener();
104:
105: this .addMouseListener(popupListener);
106: getTree().addMouseListener(new TreeMouseHandler());
107:
108: ToolTipManager.sharedInstance().registerComponent(this );
109: setShowVerticalLines(true);
110: }
111:
112: public void handlePopupDisplay(MouseEvent e) {
113: m_popup.removeAll();
114: //pass this on to the PropertyEditor, passing in the location of
115: // mouse click.
116: int row = rowAtPoint(e.getPoint());
117: //TreePath path = getTree().getPathForLocation(e.getX(), e.getY());
118: TreePath path = getTree().getPathForRow(row);
119:
120: if (path != null) {
121: Object obj = path.getLastPathComponent();
122: ETSystem.out.println(obj.getClass());
123: JDefaultMutableTreeNode node = (JDefaultMutableTreeNode) obj;
124: IPropertyElement ele = (IPropertyElement) node
125: .getUserObject();
126: if (ele != null) {
127: //set the current row and selected element to get popup menu to work.
128: m_CurRow = row;
129: m_CurElement = ele;
130:
131: IPropertyDefinition def = ele.getPropertyDefinition();
132: // String[] strs = m_editor.showMenuBasedOnDefinition(def, ele);
133: // m_editor.setRightClickRow(row);
134: // if (strs != null)
135: // {
136: // int count = strs.length;
137: // for (int i=0; i<count; i++)
138: // {
139: // JMenuItem menuItem = new JMenuItem(strs[i]);
140: // menuItem.addActionListener(this);
141: // m_popup.add(menuItem);
142: // }
143: // }
144: }
145: }
146: if (m_popup != null) {
147: m_popup.show(e.getComponent(), e.getX(), e.getY());
148: }
149:
150: }
151:
152: // public WebRPTFormatDlg getPropertyEditor()
153: // {
154: // return null; //m_editor;
155: // }
156:
157: public void actionPerformed(ActionEvent e) {
158: JMenuItem source = (JMenuItem) (e.getSource());
159: String srcText = source.getText();
160: if (srcText.equals(PropertyEditorResources
161: .getString("PropertyEditor.Create_Menu"))) {
162: // m_editor.onPopupCreate(m_CurRow, m_CurElement);
163: } else if (srcText.equals(PropertyEditorResources
164: .getString("PropertyEditor.Delete_Menu"))) {
165: // m_editor.onPopupDelete();
166: }
167: }
168:
169: public class TreeMouseHandler extends MouseInputAdapter {
170: public void mousePressed(MouseEvent e) {
171: int selRow = getTree()
172: .getRowForLocation(e.getX(), e.getY());
173: TreePath selPath = getTree().getPathForLocation(e.getX(),
174: e.getY());
175: if (selRow != -1) {
176: if (e.getClickCount() == 2) {
177: // m_editor.handleDoubleClick(selRow, selPath);
178: // m_editor.refresh();
179: } else if (e.getClickCount() == 1) {
180: Object obj = selPath.getLastPathComponent();
181: if (obj instanceof JDefaultMutableTreeNode) {
182: //getTree().getUI().
183: // if(selPath != null && !getModel().isLeaf(selPath.getLastPathComponent())){
184: // int boxWidth;
185: // java.awt.Insets i = tree.getInsets();
186: //
187: // if(getExpandedIcon() != null)
188: // boxWidth = getExpandedIcon().getIconWidth();
189: // else
190: // boxWidth = 8;
191: //
192: // int boxLeftX = (i != null) ? i.left : 0;
193: //
194: // if (leftToRight) {
195: // boxLeftX += (((path.getPathCount() + depthOffset - 2) *
196: // totalChildIndent) + getLeftChildIndent()) -
197: // boxWidth / 2;
198: // }
199: // else {
200: // boxLeftX += lastWidth - 1 -
201: // ((path.getPathCount() - 2 + depthOffset) *
202: // totalChildIndent) - getLeftChildIndent() -
203: // boxWidth / 2;
204: // }
205: // int boxRightX = boxLeftX + boxWidth;
206: //
207: // return mouseX >= boxLeftX && mouseX <= boxRightX;
208: // }
209: // return false;
210: }
211: }
212: }
213: }
214:
215: }
216:
217: }
|