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-2006 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: * DataDisplay.java
044: *
045: *
046: * Created: Wed Jan 16 14:53:40 2002
047: *
048: * @author Ana von Klopp
049: * @version
050: */package org.netbeans.modules.web.monitor.client;
051:
052: import javax.swing.JPanel;
053: import javax.swing.JButton;
054: import javax.swing.JLabel;
055: import javax.swing.Box;
056: import java.awt.Component;
057: import java.awt.Container;
058: import java.awt.Dimension;
059: import java.awt.Font;
060: import java.awt.GridBagLayout;
061: import java.awt.GridBagConstraints;
062: import java.awt.Insets;
063: import org.netbeans.modules.web.monitor.data.DataRecord;
064: import org.netbeans.modules.web.monitor.data.Param;
065:
066: abstract public class DataDisplay extends JPanel {
067:
068: //
069: // Common Insets
070: // Insets(top, left, bottom, right)
071: final static Insets zeroInsets = new Insets(0, 0, 0, 0);
072: final static Insets tableInsets = new Insets(0, 18, 12, 12);
073: final static Insets labelInsets = new Insets(0, 6, 0, 0);
074: final static Insets buttonInsets = new Insets(6, 0, 5, 6);
075: final static Insets sortButtonInsets = new Insets(0, 12, 0, 0);
076: final static Insets indentInsets = new Insets(0, 18, 0, 0);
077: final static Insets topSpacerInsets = new Insets(12, 0, 0, 0);
078:
079: final static int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
080: final static double tableWeightX = 1.0;
081: final static double tableWeightY = 0;
082:
083: public DataDisplay() {
084: super ();
085: setLayout(new GridBagLayout());
086: }
087:
088: //abstract public void setData(DataRecord md);
089:
090: void addGridBagComponent(Container parent, Component comp,
091: int gridx, int gridy, int gridwidth, int gridheight,
092: double weightx, double weighty, int anchor, int fill,
093: Insets insets, int ipadx, int ipady) {
094: GridBagConstraints cons = new GridBagConstraints();
095: cons.gridx = gridx;
096: cons.gridy = gridy;
097: cons.gridwidth = gridwidth;
098: cons.gridheight = gridheight;
099: cons.weightx = weightx;
100: cons.weighty = weighty;
101: cons.anchor = anchor;
102: cons.fill = fill;
103: cons.insets = insets;
104: cons.ipadx = ipadx;
105: cons.ipady = ipady;
106: parent.add(comp, cons);
107: }
108:
109: /**
110: * create a toggle-able button that changes the sort-order of a
111: * DisplayTable. Showing different buttons (up & down arrow)
112: * depending on the state.
113: */
114: static JButton createSortButton(DisplayTable dt) {
115: SortButton b = new SortButton(dt);
116: return (JButton) b;
117: }
118:
119: static Component createTopSpacer() {
120: return Box.createVerticalStrut(1);
121: }
122:
123: static Component createRigidArea() {
124: return Box.createRigidArea(new Dimension(0, 5));
125: }
126:
127: static Component createGlue() {
128: return Box.createGlue();
129: }
130:
131: //
132: // Routines for creating widgets in centralzied styles.
133: //
134: /**
135: * create a header label that uses bold.
136: */
137:
138: static JLabel createHeaderLabel(String label) {
139: return createHeaderLabel(label, ' ', null, null);
140: }
141:
142: static JLabel createHeaderLabel(String label, char mnemonic,
143: String ad, Component comp) {
144: JLabel jl = new JLabel(label);
145: Font labelFont = jl.getFont();
146: Font boldFont = labelFont.deriveFont(Font.BOLD);
147: jl.setFont(boldFont);
148: if (mnemonic != ' ')
149: jl.setDisplayedMnemonic(mnemonic);
150: if (ad != null)
151: jl.getAccessibleContext().setAccessibleDescription(ad);
152: if (comp != null)
153: jl.setLabelFor(comp);
154: return jl;
155: }
156:
157: static JLabel createDataLabel(String label) {
158: JLabel jl = new JLabel(label);
159: return jl;
160: }
161:
162: static Component createSortButtonLabel(String label,
163: final DisplayTable dt, char mnemonic, String ad) {
164: JPanel panel = new JPanel();
165: panel.add(createHeaderLabel(label, mnemonic, ad, dt));
166: panel.add(createSortButton(dt));
167: return panel;
168: }
169:
170: void log(String s) {
171: System.out.println("DataDisplay::" + s); // NOI18N
172: }
173:
174: Param findParam(Param[] myParams, String name, String value) {
175:
176: for (int i = 0; i < myParams.length; i++) {
177:
178: Param param = myParams[i];
179: if (name.equals(param.getName())
180: && value.equals(param.getValue())) {
181: return param;
182: }
183: }
184: return null;
185: }
186:
187: } // DataDisplay
|