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 2004-2005 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.jmx.mbeanwizard.renderer;
042:
043: import javax.swing.table.DefaultTableCellRenderer;
044: import java.awt.Component;
045: import javax.swing.JComboBox;
046: import javax.swing.JTable;
047:
048: /**
049: * Class managing the rendering for the combo boxes
050: *
051: */
052: public class ComboBoxRenderer extends DefaultTableCellRenderer {
053:
054: /*******************************************************************/
055: // here, the model is not typed because more than one table uses it
056: // i.e we have to call explicitely the model's internal structure
057: // via getValueAt and setValueAt
058: /********************************************************************/
059:
060: private JComboBox comp;
061: private Object obj;
062: private boolean isEnabled;
063: private boolean isEditable = false;
064:
065: /**
066: * Constructor
067: * @param comp the combo box to affect the renderer to
068: */
069: public ComboBoxRenderer(JComboBox comp) {
070: this .comp = comp;
071: this .isEnabled = true;
072: }
073:
074: /**
075: * Constructor
076: * @param comp the combo box to affect the renderer to
077: */
078: public ComboBoxRenderer(JComboBox comp, boolean isEnabled) {
079: this .comp = comp;
080: this .isEnabled = isEnabled;
081: }
082:
083: /**
084: * Constructor
085: * @param comp the combo box to affect the renderer to
086: */
087: public ComboBoxRenderer(JComboBox comp, boolean isEnabled,
088: boolean isEditable) {
089: this .comp = comp;
090: this .isEnabled = isEnabled;
091: this .isEditable = isEditable;
092: }
093:
094: /**
095: * Method returning the modified component (component + rendering)
096: * @param table the table in which the component is contained
097: * @param value the value of the component
098: * @param isSelected true if the component is selected
099: * @param hasFocus true if the component has the focus
100: * @param row the row of the component in the table
101: * @param column the column of the component in the table
102: * @return Component the modified component
103: */
104: public Component getTableCellRendererComponent(JTable table,
105: Object value, boolean isSelected, boolean hasFocus,
106: int row, int column) {
107: obj = table.getModel().getValueAt(row, column);
108: comp.setSelectedItem(obj);
109: comp.setEnabled(isEnabled);
110: comp.setEditable(isEditable);
111:
112: // makes visual line selection possible
113: /*
114: if (row == table.getSelectedRow()) {
115: // set editable false to have the good look when selected
116: comp.setEditable(false);
117: comp.setBackground(table.getSelectionBackground());
118: }
119: */
120:
121: return comp;
122: }
123:
124: /**
125: * Returns simply the component
126: * @return Component the component
127: */
128: public Component getComponent() {
129: return comp;
130: }
131: }
|