1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24 package com.mindtree.techworks.insight.gui.util;
25
26 import java.awt.Color;
27 import java.awt.Component;
28 import java.awt.Dimension;
29 import java.awt.GridBagConstraints;
30 import java.awt.GridBagLayout;
31 import java.awt.Insets;
32 import java.awt.event.ActionEvent;
33 import java.awt.event.ActionListener;
34 import java.util.Iterator;
35
36 import javax.swing.BorderFactory;
37 import javax.swing.JButton;
38 import javax.swing.JDialog;
39 import javax.swing.JOptionPane;
40 import javax.swing.JScrollPane;
41 import javax.swing.JTextPane;
42
43 import com.mindtree.techworks.insight.InsightConstants;
44 import com.mindtree.techworks.insight.gui.Insight;
45 import com.mindtree.techworks.insight.model.ReceiverFormat;
46 import com.mindtree.techworks.insight.receiver.RuntimeNamespaceContainer;
47 import com.mindtree.techworks.insight.spi.LogNamespace;
48
49
50
51
52
53
54
55
56
57
58 public class LoadedNamespacesFrame extends JDialog {
59
60
61
62
63 private static final long serialVersionUID = -248346217650292459L;
64
65
66
67
68 private static final int WIDTH = 600;
69 private static final int HEIGHT = 300;
70
71
72
73
74 private GridBagLayout gl;
75 private GridBagConstraints gc;
76
77
78
79
80 private JTextPane detailsPane;
81
82
83
84
85 private JButton closeButton;
86
87
88
89
90 private Insight insight;
91
92
93
94
95
96 public LoadedNamespacesFrame(Insight insight) {
97 super(JOptionPane.getFrameForComponent(insight),InsightConstants.getLiteral("LOADED_NAMESPACES"),true);
98 this.setResizable(false);
99 this.insight = insight;
100 gl = new GridBagLayout();
101 gc = new GridBagConstraints();
102 getContentPane().setLayout(gl);
103
104 detailsPane = new JTextPane();
105 detailsPane.setEditable(false);
106 detailsPane.setContentType("text/html");
107 addStylesAndContentToPane(detailsPane);
108
109 JScrollPane scrollPane = new JScrollPane(detailsPane);
110 scrollPane.setBorder(BorderFactory.createTitledBorder(InsightConstants.getLiteral("NAMESPACE_DETAILS")));
111
112 detailsPane.setPreferredSize(new Dimension(WIDTH, HEIGHT));
113 addComponent(scrollPane,0,0,1,1,2,1);
114
115 closeButton = new JButton(InsightConstants.getLiteral("OK"));
116 addComponent(closeButton,0,1,0,0,1,1);
117
118 ButtionActionProcessor actionProcessor = new ButtionActionProcessor();
119 closeButton.addActionListener(actionProcessor);
120
121
122 this.pack();
123
124 int insightX = insight.getX();
125 int insightY = insight.getY();
126 int thisX = insightX + ((this.insight.getWidth() - this.getWidth())/ 2);
127 int thisY = insightY + ((this.insight.getHeight() - this.getHeight())/ 2);
128 this.setLocation(thisX, thisY);
129 this.show();
130 }
131
132
133
134
135 private final void addComponent(Component c, int gridx, int gridy, int weightx,
136 int weighty, int width, int height) {
137 gc.fill = GridBagConstraints.BOTH;
138 gc.anchor = GridBagConstraints.NORTHWEST;
139 gc.insets = new Insets(5,5,5,5);
140 gc.gridx = gridx;
141 gc.gridy = gridy;
142 gc.weightx = weightx;
143 gc.weighty = weighty;
144 gc.gridwidth = width;
145 gc.gridheight = height;
146 gl.setConstraints( c, gc);
147 getContentPane().add(c);
148 }
149
150
151
152
153
154
155 private final void addStylesAndContentToPane(JTextPane detailsPane) {
156 Iterator iterator = RuntimeNamespaceContainer.getLoadedNamespaces().iterator();
157 StringBuffer buffer = new StringBuffer("<table width='100%' border='0'>");
158 while (iterator.hasNext()) {
159 LogNamespace namespace = (LogNamespace)iterator.next();
160 buffer.append("<tr><td bgColor='#");
161 Color color = RuntimeNamespaceContainer.getNamespaceColor(namespace);
162 buffer.append(Integer.toHexString(color.getRed()));
163 buffer.append(Integer.toHexString(color.getGreen()));
164 buffer.append(Integer.toHexString(color.getBlue()));
165 buffer.append("' ><font face='" + InsightConstants.DEFAULT_FONT.getFamily()+ "' size=-1>");
166 buffer.append(InsightConstants.getLiteral("NAMESPACE") + " : " + namespace.getSourceString());
167 buffer.append("<br>");
168 ReceiverFormat[] receiverFormat = namespace.getReceiverFormat();
169 String loadedPatterns = new String("");
170 for(int i=0; i<receiverFormat.length; i++){
171 loadedPatterns += "<br>" + receiverFormat[i].getRawPattern();
172 }
173 buffer.append(InsightConstants.getLiteral("LOG4J_PATTERNS") + " : " + loadedPatterns);
174 buffer.append("<br>");
175 buffer.append(InsightConstants.getLiteral("NODE") + " : " + namespace.getNodeId());
176 buffer.append("</font></td></tr>");
177 }
178 buffer.append("</table>");
179 detailsPane.setText(buffer.toString());
180 detailsPane.setCaretPosition(0);
181 }
182
183
184
185
186 private final class ButtionActionProcessor implements ActionListener {
187
188
189
190
191 public void actionPerformed(ActionEvent e) {
192 Object source = e.getSource();
193 if (source == closeButton) {
194 hide();
195 dispose();
196 }
197 }
198
199 }
200
201 }