KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > debugger > jpda > ui > models > BoldVariablesTableModelFilterFirst


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 package org.netbeans.modules.debugger.jpda.ui.models;
21
22 import java.awt.Color JavaDoc;
23 import java.util.Map JavaDoc;
24 import java.util.WeakHashMap JavaDoc;
25 import org.netbeans.spi.debugger.ContextProvider;
26 import org.netbeans.spi.debugger.ui.Constants;
27 import org.netbeans.spi.viewmodel.TableModel;
28 import org.netbeans.spi.viewmodel.TableModelFilter;
29 import org.netbeans.spi.viewmodel.ModelListener;
30 import org.netbeans.spi.viewmodel.UnknownTypeException;
31
32
33
34 /**
35  * Filters some original tree of nodes (represented by {@link TreeModel}).
36  *
37  * @author Jan Jancura
38  */

39 public class BoldVariablesTableModelFilterFirst implements TableModelFilter,
40 Constants {
41     
42     private Map JavaDoc variableToValueType = new WeakHashMap JavaDoc ();
43     private Map JavaDoc variableToValueValue = new WeakHashMap JavaDoc ();
44     private Map JavaDoc variableToValueToString = new WeakHashMap JavaDoc ();
45     
46     
47     
48     public Object JavaDoc getValueAt (
49         TableModel original,
50         Object JavaDoc row,
51         String JavaDoc columnID
52     ) throws UnknownTypeException {
53         Object JavaDoc result = original.getValueAt (row, columnID);
54         if ( LOCALS_TYPE_COLUMN_ID.equals (columnID) ||
55              WATCH_TYPE_COLUMN_ID.equals (columnID)
56         )
57             return bold (row, (String JavaDoc) result, variableToValueType);
58         if ( LOCALS_VALUE_COLUMN_ID.equals (columnID) ||
59              WATCH_VALUE_COLUMN_ID.equals (columnID)
60         )
61             return bold (row, (String JavaDoc) result, variableToValueValue);
62         if ( LOCALS_TO_STRING_COLUMN_ID.equals (columnID) ||
63              WATCH_TO_STRING_COLUMN_ID.equals (columnID)
64         )
65             return bold (row, (String JavaDoc) result, variableToValueToString);
66         return result;
67     }
68     
69     public boolean isReadOnly (
70         TableModel original,
71         Object JavaDoc row,
72         String JavaDoc columnID
73     ) throws UnknownTypeException {
74         return original.isReadOnly (row, columnID);
75     }
76     
77     public void setValueAt (
78         TableModel original,
79         Object JavaDoc row,
80         String JavaDoc columnID,
81         Object JavaDoc value
82     ) throws UnknownTypeException {
83         original.setValueAt (row, columnID, value);
84     }
85     
86     /**
87      * Registers given listener.
88      *
89      * @param l the listener to add
90      */

91     public void addModelListener (ModelListener l) {
92     }
93
94     /**
95      * Unregisters given listener.
96      *
97      * @param l the listener to remove
98      */

99     public void removeModelListener (ModelListener l) {
100     }
101     
102     private String JavaDoc bold (Object JavaDoc variable, String JavaDoc value, Map JavaDoc map) {
103         if (map.containsKey (variable)) {
104             String JavaDoc oldValue = (String JavaDoc) map.get (variable);
105             if (oldValue == value ||
106                 oldValue != null && oldValue.equals (value)) {
107                 
108                 return toHTML (value, false, false, null);
109             }
110             map.put (variable, value);
111             return toHTML (value, true, false, null);
112         } else {
113             map.put (variable, value);
114             return toHTML (value, false, false, null);
115         }
116     }
117     
118     public static String JavaDoc toHTML (
119         String JavaDoc text,
120         boolean bold,
121         boolean italics,
122         Color JavaDoc color
123     ) {
124         if (text == null) return null;
125         StringBuffer JavaDoc sb = new StringBuffer JavaDoc ();
126         sb.append ("<html>");
127         if (bold) sb.append ("<b>");
128         if (italics) sb.append ("<i>");
129         if (color != null) {
130             sb.append ("<font color=");
131             sb.append (Integer.toHexString ((color.getRGB () & 0xffffff)));
132             sb.append (">");
133         }
134         text = text.replaceAll ("&", "&amp;");
135         text = text.replaceAll ("<", "&lt;");
136         text = text.replaceAll (">", "&gt;");
137         sb.append (text);
138         if (color != null) sb.append ("</font>");
139         if (italics) sb.append ("</i>");
140         if (bold) sb.append ("</b>");
141         sb.append ("</html>");
142         return sb.toString ();
143     }
144 }
145
Popular Tags