KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > web > monitor > client > DataDisplay


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 /**
21  * DataDisplay.java
22  *
23  *
24  * Created: Wed Jan 16 14:53:40 2002
25  *
26  * @author Ana von Klopp
27  * @version
28  */

29 package org.netbeans.modules.web.monitor.client;
30
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JLabel JavaDoc;
34 import javax.swing.Box JavaDoc;
35 import java.awt.Component JavaDoc;
36 import java.awt.Container JavaDoc;
37 import java.awt.Dimension JavaDoc;
38 import java.awt.Font JavaDoc;
39 import java.awt.GridBagLayout JavaDoc;
40 import java.awt.GridBagConstraints JavaDoc;
41 import java.awt.Insets JavaDoc;
42 import org.netbeans.modules.web.monitor.data.DataRecord;
43 import org.netbeans.modules.web.monitor.data.Param;
44
45 abstract public class DataDisplay extends JPanel JavaDoc {
46     
47     //
48
// Common Insets
49
// Insets(top, left, bottom, right)
50
final static Insets JavaDoc zeroInsets = new Insets JavaDoc( 0, 0, 0, 0);
51     final static Insets JavaDoc tableInsets = new Insets JavaDoc( 0, 18, 12, 12);
52     final static Insets JavaDoc labelInsets = new Insets JavaDoc( 0, 6, 0, 0);
53     final static Insets JavaDoc buttonInsets = new Insets JavaDoc( 6, 0, 5, 6);
54     final static Insets JavaDoc sortButtonInsets = new Insets JavaDoc( 0, 12, 0, 0);
55     final static Insets JavaDoc indentInsets = new Insets JavaDoc( 0, 18, 0, 0);
56     final static Insets JavaDoc topSpacerInsets = new Insets JavaDoc(12, 0, 0, 0);
57
58     final static int fullGridWidth = java.awt.GridBagConstraints.REMAINDER;
59     final static double tableWeightX = 1.0;
60     final static double tableWeightY = 0;
61
62     public DataDisplay() {
63     super();
64     setLayout(new GridBagLayout JavaDoc());
65     }
66     
67     //abstract public void setData(DataRecord md);
68

69     void addGridBagComponent(Container JavaDoc parent,
70                  Component JavaDoc comp,
71                  int gridx, int gridy,
72                  int gridwidth, int gridheight,
73                  double weightx, double weighty,
74                  int anchor, int fill,
75                  Insets JavaDoc insets,
76                  int ipadx, int ipady) {
77     GridBagConstraints JavaDoc cons = new GridBagConstraints JavaDoc();
78     cons.gridx = gridx;
79     cons.gridy = gridy;
80     cons.gridwidth = gridwidth;
81     cons.gridheight = gridheight;
82     cons.weightx = weightx;
83     cons.weighty = weighty;
84     cons.anchor = anchor;
85     cons.fill = fill;
86     cons.insets = insets;
87     cons.ipadx = ipadx;
88     cons.ipady = ipady;
89     parent.add(comp,cons);
90     }
91
92
93     /**
94      * create a toggle-able button that changes the sort-order of a
95      * DisplayTable. Showing different buttons (up & down arrow)
96      * depending on the state.
97      */

98     static JButton JavaDoc createSortButton(DisplayTable dt) {
99     SortButton b = new SortButton(dt);
100     return(JButton JavaDoc)b;
101     }
102
103     static Component JavaDoc createTopSpacer() {
104     return Box.createVerticalStrut(1);
105     }
106
107     static Component JavaDoc createRigidArea() {
108     return Box.createRigidArea(new Dimension JavaDoc(0,5));
109     }
110
111     static Component JavaDoc createGlue() {
112     return Box.createGlue();
113     }
114
115
116     //
117
// Routines for creating widgets in centralzied styles.
118
//
119
/**
120      * create a header label that uses bold.
121      */

122
123
124     static JLabel JavaDoc createHeaderLabel(String JavaDoc label) {
125         return createHeaderLabel(label, ' ', null, null);
126     }
127
128
129     static JLabel JavaDoc createHeaderLabel(String JavaDoc label, char mnemonic, String JavaDoc ad, Component JavaDoc comp) {
130     JLabel JavaDoc jl = new JLabel JavaDoc(label);
131     Font JavaDoc labelFont = jl.getFont();
132     Font JavaDoc boldFont = labelFont.deriveFont(Font.BOLD);
133     jl.setFont(boldFont);
134         if (mnemonic != ' ')
135             jl.setDisplayedMnemonic(mnemonic);
136         if (ad != null)
137             jl.getAccessibleContext().setAccessibleDescription(ad);
138         if (comp != null)
139             jl.setLabelFor(comp);
140     return jl;
141     }
142
143     static JLabel JavaDoc createDataLabel(String JavaDoc label) {
144     JLabel JavaDoc jl = new JLabel JavaDoc(label);
145     return jl;
146     }
147
148     
149     static Component JavaDoc createSortButtonLabel(String JavaDoc label, final DisplayTable dt, char mnemonic, String JavaDoc ad) {
150     JPanel JavaDoc panel = new JPanel JavaDoc();
151     panel.add(createHeaderLabel(label, mnemonic, ad, dt));
152     panel.add(createSortButton(dt));
153     return panel;
154     }
155
156     void log(String JavaDoc s) {
157     System.out.println("DataDisplay::" + s); // NOI18N
158
}
159
160
161     Param findParam(Param [] myParams, String JavaDoc name, String JavaDoc value) {
162
163     for (int i=0; i < myParams.length; i++) {
164     
165         Param param = myParams[i];
166         if (name.equals(param.getName()) &&
167         value.equals(param.getValue()) ) {
168         return param;
169         }
170     }
171     return null;
172     }
173
174 } // DataDisplay
175
Popular Tags