KickJava   Java API By Example, From Geeks To Geeks.

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


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  * CookieDisplay.java
22  *
23  *
24  * Created: Wed Jan 31 18:04:22 2001
25  *
26  * @author Ana von Klopp
27  * @version
28  */

29
30 package org.netbeans.modules.web.monitor.client;
31
32 import java.util.ResourceBundle JavaDoc;
33 import javax.accessibility.AccessibleContext JavaDoc;
34 import javax.accessibility.AccessibleRelation JavaDoc;
35 import javax.swing.JLabel JavaDoc;
36
37 import org.openide.util.NbBundle;
38
39 import org.netbeans.modules.web.monitor.data.*;
40
41 // PENDING: can be more helpful with what the cookie data means. Like
42
// I had the expires at the end of this session before, that was kind
43
// of useful. Could also show the actual date that the cookie
44
// expires.
45

46 public class CookieDisplay extends DataDisplay {
47     
48     private final static boolean debug = false;
49         
50     public CookieDisplay() {
51     super();
52     }
53
54     // We're treating these as if they are all strings at the
55
// moment. In reality they can be of different types, though maybe
56
// that does not matter...
57
public void setData(DataRecord md) {
58
59     if(debug) System.out.println("in CookieDisplay.setData()"); //NOI18N
60
this.removeAll();
61     if (md == null)
62         return;
63      
64     CookiesData cd = md.getCookiesData();
65     CookieIn[] in = cd.getCookieIn();
66     CookieOut[] out = cd.getCookieOut();
67
68     int gridy = -1;
69     String JavaDoc headerIn;
70     JLabel JavaDoc incomingLabel;
71     if(in == null || in.length == 0) {
72         headerIn = NbBundle.getBundle(CookieDisplay.class).getString("MON_No_incoming");
73         incomingLabel = createDataLabel(headerIn);
74
75     } else {
76         headerIn = NbBundle.getBundle(CookieDisplay.class).getString("MON_Incoming_cookie");
77         incomingLabel = createHeaderLabel(headerIn, NbBundle.getBundle(CookieDisplay.class).getString("MON_Incoming_cookie_Mnemonic").charAt(0), NbBundle.getBundle(CookieDisplay.class).getString("ACS_MON_Incoming_cookieA11yDesc"), null);
78     }
79
80     addGridBagComponent(this, createTopSpacer(), 0, ++gridy,
81                 fullGridWidth, 1, 0, 0,
82                 java.awt.GridBagConstraints.WEST,
83                 java.awt.GridBagConstraints.NONE,
84                 topSpacerInsets,
85                 0, 0);
86
87     addGridBagComponent(this, incomingLabel, 0, ++gridy,
88                 fullGridWidth, 1, 0, 0,
89                 java.awt.GridBagConstraints.WEST,
90                 java.awt.GridBagConstraints.HORIZONTAL,
91                 labelInsets,
92                 0, 0);
93
94     AccessibleContext JavaDoc aCtx;
95     AccessibleRelation JavaDoc aRel;
96     DisplayTable dt;
97
98     if(in != null && in.length > 0) {
99  
100         for(int i=0; i<in.length; ++i) {
101         String JavaDoc[] data = {
102             in[i].getAttributeValue("name"), //NOI18N
103
in[i].getAttributeValue("value") //NOI18N
104
};
105
106         String JavaDoc[] categoriesIn = {
107             NbBundle.getBundle(CookieDisplay.class).getString("MON_Name"),
108             NbBundle.getBundle(CookieDisplay.class).getString("MON_Value"),
109         };
110
111         dt = new DisplayTable(categoriesIn, data);
112         aCtx = dt.getAccessibleContext();
113                 aCtx.setAccessibleName
114             (NbBundle.getMessage(CookieDisplay.class,
115                      "ACS_MON_Incoming_cookieTableA11yName"));//NOI18N
116
aCtx.setAccessibleDescription
117             (NbBundle.getMessage(CookieDisplay.class,
118                      "ACS_MON_Incoming_cookieTableA11yDesc"));//NOI18N
119
dt.setToolTipText
120             (NbBundle.getMessage(CookieDisplay.class,
121                      "ACS_MON_Incoming_cookieTableA11yDesc")); //NOI18N
122
aRel = new AccessibleRelation JavaDoc(AccessibleRelation.LABELED_BY,
123                           incomingLabel);
124         aCtx.getAccessibleRelationSet().add(aRel);
125         addGridBagComponent(this, dt, 0, ++gridy,
126                 fullGridWidth, 1, tableWeightX, tableWeightY,
127                 java.awt.GridBagConstraints.WEST,
128                 java.awt.GridBagConstraints.BOTH,
129                 tableInsets,
130                 0, 0);
131         }
132     }
133
134     String JavaDoc headerOut;
135     JLabel JavaDoc outgoingLabel;
136     if(out == null || out.length == 0) {
137         headerOut = NbBundle.getBundle(CookieDisplay.class).getString("MON_No_outgoing");
138         outgoingLabel = createDataLabel(headerOut);
139     } else {
140         headerOut = NbBundle.getBundle(CookieDisplay.class).getString("MON_Outgoing_cookie");
141         outgoingLabel = createHeaderLabel(headerOut, NbBundle.getBundle(CookieDisplay.class).getString("MON_Outgoing_cookie_Mnemonic").charAt(0), NbBundle.getBundle(CookieDisplay.class).getString("ACS_MON_Outgoing_cookieA11yDesc"), null);
142     }
143     addGridBagComponent(this, outgoingLabel, 0, ++gridy,
144                 fullGridWidth, 1, 0, 0,
145                 java.awt.GridBagConstraints.WEST,
146                 java.awt.GridBagConstraints.NONE,
147                 labelInsets,
148                 0, 0);
149
150     if(out != null && out.length > 0) {
151
152         for(int i=0; i<out.length; ++i) {
153         String JavaDoc cookieMaxAge =
154             out[i].getAttributeValue("maxAge"); //NOI18N
155
if(cookieMaxAge.equals("-1")) //NOI18N
156
cookieMaxAge = NbBundle.getBundle(CookieDisplay.class).getString("MON_this_session");
157         
158         String JavaDoc[] data = {
159             out[i].getAttributeValue("name"), //NOI18N
160
out[i].getAttributeValue("value"), //NOI18N
161
out[i].getAttributeValue("domain"), //NOI18N
162
out[i].getAttributeValue("path"), //NOI18N
163
cookieMaxAge,
164             out[i].getAttributeValue("version"), //NOI18N
165
out[i].getAttributeValue("secure"), //NOI18N
166
out[i].getAttributeValue("comment") //NOI18N
167
};
168
169         String JavaDoc[] categoriesOut = {
170             NbBundle.getBundle(CookieDisplay.class).getString("MON_Name"),
171             NbBundle.getBundle(CookieDisplay.class).getString("MON_Value"),
172             NbBundle.getBundle(CookieDisplay.class).getString("MON_Domain"),
173             NbBundle.getBundle(CookieDisplay.class).getString("MON_Path"),
174             NbBundle.getBundle(CookieDisplay.class).getString("MON_Max_age"),
175             NbBundle.getBundle(CookieDisplay.class).getString("MON_Version"),
176             NbBundle.getBundle(CookieDisplay.class).getString("MON_Secure"),
177             NbBundle.getBundle(CookieDisplay.class).getString("MON_Comment"),
178         };
179
180         dt = new DisplayTable(categoriesOut, data);
181         aCtx = dt.getAccessibleContext();
182                 aCtx.setAccessibleName
183             (NbBundle.getMessage(CookieDisplay.class,
184                      "ACS_MON_Outgoing_cookieTableA11yName"));//NOI18N
185
aCtx.setAccessibleDescription
186             (NbBundle.getMessage(CookieDisplay.class,
187                      "ACS_MON_Outgoing_cookieTableA11yDesc"));//NOI18N
188
dt.setToolTipText
189             (NbBundle.getMessage(CookieDisplay.class,
190                      "ACS_MON_Outgoing_cookieTableA11yDesc")); //NOI18N
191
aRel = new AccessibleRelation JavaDoc(AccessibleRelation.LABELED_BY,
192                           outgoingLabel);
193         aCtx.getAccessibleRelationSet().add(aRel);
194         addGridBagComponent(this, dt, 0, ++gridy,
195                 fullGridWidth, 1, tableWeightX, tableWeightY,
196                 java.awt.GridBagConstraints.WEST,
197                 java.awt.GridBagConstraints.BOTH,
198                 tableInsets,
199                 0, 0);
200         }
201     }
202
203     addGridBagComponent(this, createGlue(), 0, ++gridy,
204                 1, 1, 1.0, 1.0,
205                 java.awt.GridBagConstraints.WEST,
206                 java.awt.GridBagConstraints.BOTH,
207                 zeroInsets,
208                 0, 0);
209
210     this.setMaximumSize(this.getPreferredSize());
211     this.repaint();
212     }
213 } // CookieDisplay
214
Popular Tags