1 16 package org.apache.log4j.chainsaw; 17 18 import java.awt.GridBagConstraints ; 19 import java.awt.GridBagLayout ; 20 import java.awt.event.ActionEvent ; 21 import java.awt.event.ActionListener ; 22 import javax.swing.BorderFactory ; 23 import javax.swing.JButton ; 24 import javax.swing.JComboBox ; 25 import javax.swing.JLabel ; 26 import javax.swing.JPanel ; 27 import javax.swing.JTextField ; 28 import javax.swing.event.DocumentEvent ; 29 import javax.swing.event.DocumentListener ; 30 import org.apache.log4j.Logger; 31 import org.apache.log4j.Priority; 32 33 38 class ControlPanel extends JPanel { 39 40 private static final Logger LOG = 41 Logger.getLogger(ControlPanel.class); 42 43 48 ControlPanel(final MyTableModel aModel) { 49 setBorder(BorderFactory.createTitledBorder("Controls: ")); 50 final GridBagLayout gridbag = new GridBagLayout (); 51 final GridBagConstraints c = new GridBagConstraints (); 52 setLayout(gridbag); 53 54 c.ipadx = 5; 56 c.ipady = 5; 57 58 c.gridx = 0; 60 c.anchor = GridBagConstraints.EAST; 61 62 c.gridy = 0; 63 JLabel label = new JLabel ("Filter Level:"); 64 gridbag.setConstraints(label, c); 65 add(label); 66 67 c.gridy++; 68 label = new JLabel ("Filter Thread:"); 69 gridbag.setConstraints(label, c); 70 add(label); 71 72 c.gridy++; 73 label = new JLabel ("Filter Logger:"); 74 gridbag.setConstraints(label, c); 75 add(label); 76 77 c.gridy++; 78 label = new JLabel ("Filter NDC:"); 79 gridbag.setConstraints(label, c); 80 add(label); 81 82 c.gridy++; 83 label = new JLabel ("Filter Message:"); 84 gridbag.setConstraints(label, c); 85 add(label); 86 87 c.weightx = 1; 89 c.gridx = 1; 91 c.anchor = GridBagConstraints.WEST; 92 93 c.gridy = 0; 94 final Priority[] allPriorities = Priority.getAllPossiblePriorities(); 95 final JComboBox priorities = new JComboBox (allPriorities); 96 final Priority lowest = allPriorities[allPriorities.length - 1]; 97 priorities.setSelectedItem(lowest); 98 aModel.setPriorityFilter(lowest); 99 gridbag.setConstraints(priorities, c); 100 add(priorities); 101 priorities.setEditable(false); 102 priorities.addActionListener(new ActionListener () { 103 public void actionPerformed(ActionEvent aEvent) { 104 aModel.setPriorityFilter( 105 (Priority) priorities.getSelectedItem()); 106 } 107 }); 108 109 110 c.fill = GridBagConstraints.HORIZONTAL; 111 c.gridy++; 112 final JTextField threadField = new JTextField (""); 113 threadField.getDocument().addDocumentListener(new DocumentListener () { 114 public void insertUpdate(DocumentEvent aEvent) { 115 aModel.setThreadFilter(threadField.getText()); 116 } 117 public void removeUpdate(DocumentEvent aEvente) { 118 aModel.setThreadFilter(threadField.getText()); 119 } 120 public void changedUpdate(DocumentEvent aEvent) { 121 aModel.setThreadFilter(threadField.getText()); 122 } 123 }); 124 gridbag.setConstraints(threadField, c); 125 add(threadField); 126 127 c.gridy++; 128 final JTextField catField = new JTextField (""); 129 catField.getDocument().addDocumentListener(new DocumentListener () { 130 public void insertUpdate(DocumentEvent aEvent) { 131 aModel.setCategoryFilter(catField.getText()); 132 } 133 public void removeUpdate(DocumentEvent aEvent) { 134 aModel.setCategoryFilter(catField.getText()); 135 } 136 public void changedUpdate(DocumentEvent aEvent) { 137 aModel.setCategoryFilter(catField.getText()); 138 } 139 }); 140 gridbag.setConstraints(catField, c); 141 add(catField); 142 143 c.gridy++; 144 final JTextField ndcField = new JTextField (""); 145 ndcField.getDocument().addDocumentListener(new DocumentListener () { 146 public void insertUpdate(DocumentEvent aEvent) { 147 aModel.setNDCFilter(ndcField.getText()); 148 } 149 public void removeUpdate(DocumentEvent aEvent) { 150 aModel.setNDCFilter(ndcField.getText()); 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(new DocumentListener () { 162 public void insertUpdate(DocumentEvent aEvent) { 163 aModel.setMessageFilter(msgField.getText()); 164 } 165 public void removeUpdate(DocumentEvent aEvent) { 166 aModel.setMessageFilter(msgField.getText()); 167 } 168 public void changedUpdate(DocumentEvent aEvent) { 169 aModel.setMessageFilter(msgField.getText()); 170 } 171 }); 172 173 174 gridbag.setConstraints(msgField, c); 175 add(msgField); 176 177 c.weightx = 0; 179 c.fill = GridBagConstraints.HORIZONTAL; 180 c.anchor = GridBagConstraints.EAST; 181 c.gridx = 2; 182 183 c.gridy = 0; 184 final JButton exitButton = new JButton ("Exit"); 185 exitButton.setMnemonic('x'); 186 exitButton.addActionListener(ExitAction.INSTANCE); 187 gridbag.setConstraints(exitButton, c); 188 add(exitButton); 189 190 c.gridy++; 191 final JButton clearButton = new JButton ("Clear"); 192 clearButton.setMnemonic('c'); 193 clearButton.addActionListener(new ActionListener () { 194 public void actionPerformed(ActionEvent aEvent) { 195 aModel.clear(); 196 } 197 }); 198 gridbag.setConstraints(clearButton, c); 199 add(clearButton); 200 201 c.gridy++; 202 final JButton toggleButton = new JButton ("Pause"); 203 toggleButton.setMnemonic('p'); 204 toggleButton.addActionListener(new ActionListener () { 205 public void actionPerformed(ActionEvent aEvent) { 206 aModel.toggle(); 207 toggleButton.setText( 208 aModel.isPaused() ? "Resume" : "Pause"); 209 } 210 }); 211 gridbag.setConstraints(toggleButton, c); 212 add(toggleButton); 213 } 214 } 215 | Popular Tags |