001: //The contents of this file are subject to the Mozilla Public License Version 1.1
002: //(the "License"); you may not use this file except in compliance with the
003: //License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
004: //
005: //Software distributed under the License is distributed on an "AS IS" basis,
006: //WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
007: //for the specific language governing rights and
008: //limitations under the License.
009: //
010: //The Original Code is "The Columba Project"
011: //
012: //The Initial Developers of the Original Code are Frederik Dietz and Timo Stich.
013: //Portions created by Frederik Dietz and Timo Stich are Copyright (C) 2003.
014: //
015: //All Rights Reserved.
016: package org.columba.core.gui.logdisplay;
017:
018: import java.awt.BorderLayout;
019: import java.awt.Dimension;
020: import java.awt.event.ActionEvent;
021: import java.awt.event.ActionListener;
022: import java.awt.event.MouseAdapter;
023: import java.awt.event.MouseEvent;
024: import java.util.logging.Level;
025:
026: import javax.swing.Box;
027: import javax.swing.BoxLayout;
028: import javax.swing.JButton;
029: import javax.swing.JComboBox;
030: import javax.swing.JList;
031: import javax.swing.JPanel;
032: import javax.swing.JScrollPane;
033: import javax.swing.JTextField;
034: import javax.swing.JToggleButton;
035: import javax.swing.ListSelectionModel;
036: import javax.swing.event.ListSelectionEvent;
037: import javax.swing.event.ListSelectionListener;
038:
039: /**
040: * @author redsolo
041: */
042: public class LogPanel extends JPanel {
043:
044: //private JTable logTable;
045: private JList logList;
046:
047: private JToggleButton pauseButton;
048: private JButton clearButton;
049: private JButton closeButton;
050: private JButton detailButton;
051:
052: private JTextField searchTextfield;
053:
054: private JComboBox levelCombobox;
055:
056: /**
057: *
058: */
059: public LogPanel() {
060: super ();
061: initComponents();
062: layoutComponents();
063: }
064:
065: /**
066: * Creates all components in the panel.
067: */
068: private void initComponents() {
069: logList = new JList(LogRecordList.getInstance());
070: logList.setCellRenderer(new LogRecordListRenderer());
071: logList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
072: logList.addMouseListener(new MouseAdapter() {
073: public void mouseClicked(MouseEvent e) {
074: if (e.getClickCount() >= 2) {
075: showDetailedLogRecord();
076: }
077: }
078: });
079: /*logTable = new JTable(new LogPanelModel());
080: logTable.addMouseListener(new MouseAdapter() {
081: public void mouseClicked(MouseEvent e) {
082: if (e.getClickCount() >= 2) {
083: int row = logTable.getSelectedRow();
084: LogPanelModel model = (LogPanelModel) logTable.getModel();
085: LogRecordPanel.showRecord(null, model.getLogRecordForRow(row));
086: }
087: }
088: });*/
089:
090: ButtonListener listener = new ButtonListener();
091: pauseButton = new JToggleButton("Pause");
092: pauseButton.addActionListener(listener);
093: clearButton = new JButton("Clear");
094: clearButton.addActionListener(listener);
095: closeButton = new JButton("Close");
096: closeButton.addActionListener(listener);
097: detailButton = new JButton("Details");
098: detailButton.addActionListener(listener);
099: detailButton.setEnabled(false);
100: logList.addListSelectionListener(new LogListListener());
101:
102: searchTextfield = new JTextField();
103: levelCombobox = new JComboBox(new Object[] { Level.ALL,
104: Level.FINE, Level.INFO, Level.WARNING, Level.SEVERE });
105: }
106:
107: /**
108: * Layouts all components in the panel.
109: */
110: private void layoutComponents() {
111: JPanel topPanel = new JPanel();
112: topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.X_AXIS));
113: topPanel.add(searchTextfield);
114: topPanel.add(Box.createHorizontalGlue());
115: topPanel.add(levelCombobox);
116:
117: JPanel bottomPanel = new JPanel();
118: bottomPanel.setLayout(new BoxLayout(bottomPanel,
119: BoxLayout.X_AXIS));
120: bottomPanel.add(pauseButton);
121: bottomPanel.add(clearButton);
122: bottomPanel.add(detailButton);
123: bottomPanel.add(Box.createHorizontalGlue());
124: //bottomPanel.add(closeButton);
125:
126: JScrollPane scrollPane = new JScrollPane(logList);
127: scrollPane.setPreferredSize(new Dimension(400, 200));
128:
129: setLayout(new BorderLayout());
130: add(topPanel, BorderLayout.NORTH);
131: add(scrollPane, BorderLayout.CENTER);
132: add(bottomPanel, BorderLayout.SOUTH);
133: }
134:
135: /**
136: * Shows a detailed panel about the selected log record.
137: */
138: private void showDetailedLogRecord() {
139: int row = logList.getSelectedIndex();
140: if (row != -1) {
141: LogRecordList model = (LogRecordList) logList.getModel();
142: LogRecordPanel.showRecord(null, model.getLogRecord(row));
143: }
144: }
145:
146: /**
147: * Listens on the buttons.
148: * @author redsolo
149: */
150: private class ButtonListener implements ActionListener {
151:
152: /** {@inheritDoc} */
153: public void actionPerformed(ActionEvent e) {
154: LogRecordList instance = LogRecordList.getInstance();
155: if (e.getSource() == clearButton) {
156: instance.clear();
157:
158: } else if (e.getSource() == pauseButton) {
159:
160: if (pauseButton.isSelected()) {
161: instance.stopLogging();
162: } else {
163: instance.startLogging();
164: }
165: } else if (e.getSource() == detailButton) {
166: showDetailedLogRecord();
167: }
168: }
169: }
170:
171: /**
172: * A list selection listener, to find out if we are going to enable the detail button.
173: * @author redsolo
174: */
175: private class LogListListener implements ListSelectionListener {
176:
177: /** {@inheritDoc} */
178: public void valueChanged(ListSelectionEvent e) {
179: if (!e.getValueIsAdjusting()) {
180: detailButton
181: .setEnabled(logList.getSelectedIndex() != -1);
182: }
183: }
184: }
185: }
|