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.integration.finddialog.ui;
047:
048: import java.awt.Color;
049: import java.awt.Component;
050: import java.awt.Font;
051: import java.awt.event.ActionEvent;
052: import java.awt.event.ActionListener;
053: import java.awt.event.MouseAdapter;
054: import java.awt.event.MouseEvent;
055: import java.awt.event.MouseListener;
056:
057: import javax.swing.Icon;
058: import javax.swing.JComponent;
059: import javax.swing.JLabel;
060: import javax.swing.JTable;
061: import javax.swing.KeyStroke;
062: import javax.swing.UIManager;
063: import javax.swing.border.Border;
064: import javax.swing.event.MouseInputAdapter;
065: import javax.swing.table.DefaultTableCellRenderer;
066: import javax.swing.table.TableCellRenderer;
067:
068: import org.netbeans.modules.uml.integration.finddialog.FindUtilities;
069: import org.netbeans.modules.uml.ui.swing.preferencedialog.ISwingPreferenceTableModel;
070:
071: /**
072: * @author sumitabhk
073: *
074: */
075: public class JFindTable extends JTable {
076: private FindDialogUI m_UI = null;
077:
078: public JFindTable() {
079: super ();
080: }
081:
082: public JFindTable(ISwingPreferenceTableModel model, FindDialogUI ui) {
083: super (model);
084:
085: m_UI = ui;
086:
087: FindTableCellEditor cellEditor = new FindTableCellEditor(ui);
088: FindTableCellRenderer renderer = new FindTableCellRenderer();
089: for (int x = 0; x < getColumnModel().getColumnCount(); x++) {
090: getColumnModel().getColumn(x).setCellEditor(cellEditor);
091: getColumnModel().getColumn(x).setCellRenderer(renderer);
092: }
093:
094: MouseListener mListener = new FindPopupListener();
095: this .addMouseListener(mListener);
096: addMouseListener(new FindMouseHandler());
097:
098: // Add accelerator
099: ActionListener action = new ActionListener() {
100: public void actionPerformed(ActionEvent e) {
101: int selRow = getSelectedRow();
102: if (selRow != -1) {
103: boolean isShift = (e.getModifiers() & ActionEvent.SHIFT_MASK) == ActionEvent.SHIFT_MASK;
104: m_UI.onDblClickFindResults(selRow,
105: (FindTableModel) getModel(), isShift);
106: }
107: }
108: };
109: registerKeyboardAction(action, KeyStroke.getKeyStroke("SPACE"),
110: JComponent.WHEN_IN_FOCUSED_WINDOW);
111:
112: }
113:
114: public class FindMouseHandler extends MouseInputAdapter {
115: public void mousePressed(MouseEvent e) {
116: int selRow = rowAtPoint(e.getPoint());
117: if (e.getClickCount() == 2) {
118: boolean isShift = (e.getModifiers() & MouseEvent.SHIFT_MASK) == MouseEvent.SHIFT_MASK;
119: m_UI.onDblClickFindResults(selRow,
120: (FindTableModel) getModel(), isShift);
121: }
122: }
123: }
124:
125: private class FindTableCellRenderer extends
126: DefaultTableCellRenderer implements TableCellRenderer {
127: /* (non-Javadoc)
128: * @see javax.swing.table.TableCellRenderer#getTableCellRendererComponent(javax.swing.JTable, java.lang.Object, boolean, boolean, int, int)
129: */
130: public Component getTableCellRendererComponent(JTable table,
131: Object value, boolean isSelected, boolean hasFocus,
132: int row, int col) {
133: Font pFont = FindUtilities.getGridFontFromPreferences();
134: setFont(pFont);
135:
136: if (value instanceof String) {
137: setIcon(null);
138: setText((String) value);
139: } else if (value instanceof Icon) {
140: setIcon((Icon) value);
141: setText(null);
142: }
143: Color background;
144: Color foreground;
145:
146: if (isSelected) {
147: background = table.getSelectionBackground();
148: foreground = table.getSelectionForeground();
149: } else {
150: background = table.getBackground();
151: foreground = table.getForeground();
152: }
153: Border highlightBorder = null;
154: if (hasFocus) {
155: highlightBorder = UIManager
156: .getBorder("Table.focusCellHighlightBorder");
157: }
158: TableCellRenderer tcr = getCellRenderer(row, col);
159: if (tcr instanceof DefaultTableCellRenderer) {
160: DefaultTableCellRenderer dtcr = ((DefaultTableCellRenderer) tcr);
161: dtcr.setBackground(background);
162: dtcr.setForeground(foreground);
163: }
164: return this ;
165: }
166: }
167:
168: public class FindPopupListener extends MouseAdapter {
169: /**
170: *
171: */
172: public FindPopupListener() {
173: super ();
174: }
175:
176: public void mousePressed(MouseEvent e) {
177: }
178:
179: public void mouseReleased(MouseEvent e) {
180: }
181:
182: private void maybeShowPopup(MouseEvent e) {
183: }
184:
185: }
186:
187: }
|