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 java.util.ArrayList;
046: import javax.swing.JButton;
047: import javax.swing.JTextField;
048: import javax.swing.JTable;
049: import javax.swing.JPanel;
050: import org.netbeans.modules.jmx.MBeanOperationParameter;
051:
052: /**
053: * Class managing the rendering for the panel responsible for the
054: * operation parameter popup display and result textfield
055: *
056: */
057: public class OperationParameterPanelRenderer extends
058: DefaultTableCellRenderer {
059:
060: /*******************************************************************/
061: // here, the model is not typed because more than one table uses it
062: // i.e we have to call explicitely the model's internal structure
063: // via getValueAt and setValueAt
064: /********************************************************************/
065:
066: private JPanel comp;
067: private JTextField text;
068:
069: /**
070: * Constructor
071: * @param comp the panel containing the popup button and the result
072: * text field
073: * @param text the result text field
074: */
075: public OperationParameterPanelRenderer(JPanel comp, JTextField text) {
076: this .comp = comp;
077: this .text = text;
078: }
079:
080: /**
081: * Method returning the modified component (component + rendering)
082: * @param table the table in which the component is contained
083: * @param value the value of the component
084: * @param isSelected true if the component is selected
085: * @param hasFocus true if the component has the focus
086: * @param row the row of the component in the table
087: * @param column the column of the component in the table
088: * @return Component the modified component
089: */
090: public Component getTableCellRendererComponent(JTable table,
091: Object value, boolean isSelected, boolean hasFocus,
092: int row, int column) {
093:
094: // gets the whole information also we only want to have the name
095: // and for example not the description
096: ArrayList<MBeanOperationParameter> oText = (ArrayList<MBeanOperationParameter>) table
097: .getModel().getValueAt(row, column);
098: String paramString = "";// NOI18N
099: for (int i = 0; i < oText.size(); i++) {
100: paramString += oText.get(i).getParamType() + " " + // NOI18N
101: oText.get(i).getParamName();
102:
103: if (i < oText.size() - 1)
104: paramString += ",";// NOI18N
105: }
106: text.setText(paramString);
107:
108: /*
109: // makes visual line selection possible
110: if (row == table.getSelectedRow()) {
111: text.setBackground(table.getSelectionBackground());
112: }
113: */
114: return comp;
115: }
116:
117: /**
118: * Returns simply the component
119: * @return Component the component
120: */
121: public Component getComponent() {
122: return comp;
123: }
124: }
|