001: /*
002: * Copyright (C) The Apache Software Foundation. All rights reserved.
003: *
004: * This software is published under the terms of the Apache Software
005: * License version 1.1, a copy of which has been included with this
006: * distribution in the APACHE.txt file. */
007: package org.jahia.sqlprofiler.gui;
008:
009: import java.awt.GridBagConstraints;
010: import java.awt.GridBagLayout;
011: import java.awt.event.ActionEvent;
012: import java.awt.event.ActionListener;
013: import javax.swing.BorderFactory;
014: import javax.swing.JButton;
015: import javax.swing.JComboBox;
016: import javax.swing.JLabel;
017: import javax.swing.JPanel;
018: import javax.swing.JTextField;
019: import javax.swing.event.DocumentEvent;
020: import javax.swing.event.DocumentListener;
021: import org.apache.log4j.Category;
022: import org.apache.log4j.Priority;
023:
024: /**
025: * Represents the controls for filtering, pausing, exiting, etc.
026: *
027: * @author <a href="mailto:oliver@puppycrawl.com">Oliver Burn</a>
028: */
029: class ControlPanel extends JPanel {
030: /** use the log messages **/
031: private static final Category LOG = Category
032: .getInstance(ControlPanel.class);
033:
034: /**
035: * Creates a new <code>ControlPanel</code> instance.
036: *
037: * @param aModel the model to control
038: */
039: ControlPanel(final LoggerTableModel aModel) {
040: setBorder(BorderFactory.createTitledBorder("Controls: "));
041: final GridBagLayout gridbag = new GridBagLayout();
042: final GridBagConstraints c = new GridBagConstraints();
043: setLayout(gridbag);
044:
045: // Pad everything
046: c.ipadx = 5;
047: c.ipady = 5;
048:
049: // Add the 1st column of labels
050: c.gridx = 0;
051: c.anchor = GridBagConstraints.EAST;
052:
053: c.gridy = 0;
054: JLabel label = new JLabel("Filter Level:");
055: gridbag.setConstraints(label, c);
056: add(label);
057:
058: c.gridy++;
059: label = new JLabel("Filter Thread:");
060: gridbag.setConstraints(label, c);
061: add(label);
062:
063: c.gridy++;
064: label = new JLabel("Filter Category:");
065: gridbag.setConstraints(label, c);
066: add(label);
067:
068: c.gridy++;
069: label = new JLabel("Filter NDC:");
070: gridbag.setConstraints(label, c);
071: add(label);
072:
073: c.gridy++;
074: label = new JLabel("Filter Message:");
075: gridbag.setConstraints(label, c);
076: add(label);
077:
078: // Add the 2nd column of filters
079: c.weightx = 1;
080: //c.weighty = 1;
081: c.gridx = 1;
082: c.anchor = GridBagConstraints.WEST;
083:
084: c.gridy = 0;
085: final Priority[] allPriorities = Priority
086: .getAllPossiblePriorities();
087: final JComboBox priorities = new JComboBox(allPriorities);
088: final Priority lowest = allPriorities[allPriorities.length - 1];
089: priorities.setSelectedItem(lowest);
090: aModel.setPriorityFilter(lowest);
091: gridbag.setConstraints(priorities, c);
092: add(priorities);
093: priorities.setEditable(false);
094: priorities.addActionListener(new ActionListener() {
095: public void actionPerformed(ActionEvent aEvent) {
096: aModel.setPriorityFilter((Priority) priorities
097: .getSelectedItem());
098: }
099: });
100:
101: c.fill = GridBagConstraints.HORIZONTAL;
102: c.gridy++;
103: final JTextField threadField = new JTextField("");
104: threadField.getDocument().addDocumentListener(
105: new DocumentListener() {
106: public void insertUpdate(DocumentEvent aEvent) {
107: aModel.setThreadFilter(threadField.getText());
108: }
109:
110: public void removeUpdate(DocumentEvent aEvente) {
111: aModel.setThreadFilter(threadField.getText());
112: }
113:
114: public void changedUpdate(DocumentEvent aEvent) {
115: aModel.setThreadFilter(threadField.getText());
116: }
117: });
118: gridbag.setConstraints(threadField, c);
119: add(threadField);
120:
121: c.gridy++;
122: final JTextField catField = new JTextField("");
123: catField.getDocument().addDocumentListener(
124: new DocumentListener() {
125: public void insertUpdate(DocumentEvent aEvent) {
126: aModel.setCategoryFilter(catField.getText());
127: }
128:
129: public void removeUpdate(DocumentEvent aEvent) {
130: aModel.setCategoryFilter(catField.getText());
131: }
132:
133: public void changedUpdate(DocumentEvent aEvent) {
134: aModel.setCategoryFilter(catField.getText());
135: }
136: });
137: gridbag.setConstraints(catField, c);
138: add(catField);
139:
140: c.gridy++;
141: final JTextField ndcField = new JTextField("");
142: ndcField.getDocument().addDocumentListener(
143: new DocumentListener() {
144: public void insertUpdate(DocumentEvent aEvent) {
145: aModel.setNDCFilter(ndcField.getText());
146: }
147:
148: public void removeUpdate(DocumentEvent aEvent) {
149: aModel.setNDCFilter(ndcField.getText());
150: }
151:
152: public void changedUpdate(DocumentEvent aEvent) {
153: aModel.setNDCFilter(ndcField.getText());
154: }
155: });
156: gridbag.setConstraints(ndcField, c);
157: add(ndcField);
158:
159: c.gridy++;
160: final JTextField msgField = new JTextField("");
161: msgField.getDocument().addDocumentListener(
162: new DocumentListener() {
163: public void insertUpdate(DocumentEvent aEvent) {
164: aModel.setMessageFilter(msgField.getText());
165: }
166:
167: public void removeUpdate(DocumentEvent aEvent) {
168: aModel.setMessageFilter(msgField.getText());
169: }
170:
171: public void changedUpdate(DocumentEvent aEvent) {
172: aModel.setMessageFilter(msgField.getText());
173: }
174: });
175:
176: gridbag.setConstraints(msgField, c);
177: add(msgField);
178:
179: }
180: }
|