This project has retired. For details please refer to its Attic page.
LogFrame xref

1   /*
2    * Licensed to the Apache Software Foundation (ASF) under one
3    * or more contributor license agreements.  See the NOTICE file
4    * distributed with this work for additional information
5    * regarding copyright ownership.  The ASF licenses this file
6    * to you under the Apache License, Version 2.0 (the
7    * "License"); you may not use this file except in compliance
8    * with the License.  You may obtain a copy of the License at
9    *
10   * http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing,
13   * software distributed under the License is distributed on an
14   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15   * KIND, either express or implied.  See the License for the
16   * specific language governing permissions and limitations
17   * under the License.
18   */
19  package org.apache.chemistry.opencmis.workbench;
20  
21  import java.awt.BorderLayout;
22  import java.awt.Dimension;
23  import java.awt.FlowLayout;
24  import java.awt.Font;
25  import java.awt.event.ActionEvent;
26  import java.awt.event.ActionListener;
27  
28  import javax.swing.JButton;
29  import javax.swing.JComboBox;
30  import javax.swing.JFrame;
31  import javax.swing.JPanel;
32  import javax.swing.JScrollPane;
33  import javax.swing.JTextArea;
34  
35  import org.apache.log4j.Level;
36  import org.apache.log4j.Logger;
37  
38  public class LogFrame extends JFrame {
39  
40      private static final long serialVersionUID = 1L;
41  
42      private static final String WINDOW_TITLE = "CMIS Client Logging";
43  
44      private JTextArea logTextArea;
45  
46      public LogFrame() {
47          super();
48          createGUI();
49      }
50  
51      private void createGUI() {
52          setTitle(WINDOW_TITLE);
53          setPreferredSize(new Dimension(800, 600));
54          setMinimumSize(new Dimension(200, 60));
55  
56          setLayout(new BorderLayout());
57  
58          logTextArea = new JTextArea();
59          logTextArea.setEditable(false);
60          logTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
61          logTextArea.setLineWrap(true);
62          logTextArea.setWrapStyleWord(true);
63          add(new JScrollPane(logTextArea), BorderLayout.CENTER);
64  
65          JPanel inputPanel = new JPanel(new FlowLayout());
66          add(inputPanel, BorderLayout.PAGE_END);
67  
68          JButton clearButton = new JButton("Clear");
69          clearButton.addActionListener(new ActionListener() {
70              public void actionPerformed(ActionEvent e) {
71                  logTextArea.setText("");
72              }
73          });
74          inputPanel.add(clearButton);
75  
76          String[] levels = new String[] { Level.ALL.toString(), Level.TRACE.toString(), Level.DEBUG.toString(),
77                  Level.INFO.toString(), Level.WARN.toString(), Level.ERROR.toString(), Level.FATAL.toString(),
78                  Level.OFF.toString() };
79  
80          final JComboBox levelBox = new JComboBox(levels);
81          levelBox.setSelectedItem(Logger.getRootLogger().getLevel().toString());
82          levelBox.addActionListener(new ActionListener() {
83              public void actionPerformed(ActionEvent e) {
84                  Logger.getRootLogger().setLevel(Level.toLevel(levelBox.getSelectedItem().toString()));
85              }
86          });
87          inputPanel.add(levelBox);
88  
89          ClientHelper.installEscapeBinding(this, getRootPane(), false);
90  
91          setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
92          pack();
93  
94          setLocationRelativeTo(null);
95          setVisible(false);
96  
97          ClientWriterAppender.setTextArea(logTextArea);
98      }
99  
100     public void showFrame() {
101         setVisible(true);
102     }
103 }