source: java/main/src/main/java/com/framsticks/gui/windows/ServerLogFrame.java @ 77

Last change on this file since 77 was 77, checked in by psniegowski, 11 years ago

Add new java codebase.

File size: 3.2 KB
Line 
1package com.framsticks.gui.windows;
2
3import com.framsticks.gui.ImageProvider;
4import com.framsticks.gui.components.Control;
5import org.apache.log4j.Logger;
6
7import javax.swing.*;
8import java.awt.*;
9import java.awt.event.ActionEvent;
10import java.awt.event.ActionListener;
11
12/**
13 * Frame displaying manager logs.
14 */
15@SuppressWarnings("serial")
16public class ServerLogFrame extends JFrame {
17        public JTextArea logText;
18        private int levelReporting = -1;
19        private boolean popUp = true;
20
21        private final static String[] STR_ = {"DEBUG", "INFO", "WARNING", "ERROR",
22                        "CRITICAL"};
23
24
25        public ServerLogFrame() {
26
27                super("FNC - Manager Log");
28                Dimension size = new Dimension(440, 400);
29                this.setSize(size);
30                this.setMinimumSize(size);
31                this.setIconImage(ImageProvider.loadImage(ImageProvider.LOGO).getImage());
32                JFrame.setDefaultLookAndFeelDecorated(true);
33                /*
34                try {
35                        UIManager
36                                        .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
37                } catch (Exception ex) {
38                }
39                */
40                this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
41                logText = new JTextArea();
42                //logText.setFont(Control.FONT);
43                logText.setEditable(false);
44                logText.setWrapStyleWord(true);
45                logText.setLineWrap(true);
46                JComboBox levelBox = new JComboBox();
47                for (String i : STR_) {
48                        levelBox.addItem(i);
49                }
50                levelBox.addActionListener(new ActionListener() {
51                        public void actionPerformed(ActionEvent e) {
52                                levelReporting = ((JComboBox) e.getSource()).getSelectedIndex();
53                        }
54                });
55                JCheckBox logPopup = new JCheckBox();
56                logPopup.addActionListener(new ActionListener() {
57                        public void actionPerformed(ActionEvent e) {
58                                popUp = ((JCheckBox) e.getSource()).isSelected();
59                        }
60                });
61                logPopup.setSelected(true);
62                JLabel levelLabel = new JLabel("Select reporting level ");
63                JLabel popupLabel = new JLabel("Window popup ? ");
64                JPanel panel = new JPanel();
65                panel.setLayout(new FlowLayout());
66                panel.add(levelLabel);
67                panel.add(levelBox);
68                panel.add(logPopup);
69                panel.add(popupLabel);
70                JScrollPane scrollPane = new JScrollPane(logText);
71                scrollPane.setBorder(BorderFactory.createEtchedBorder());
72                Container contentPane = this.getContentPane();
73                contentPane.setLayout(new BorderLayout());
74                contentPane.add(scrollPane, BorderLayout.CENTER);
75                contentPane.add(panel, BorderLayout.SOUTH);
76                levelReporting = 0;
77        }
78
79        public void setLevelReporting(int level) {
80                levelReporting = level;
81        }
82
83        public void log(int level, String clazz, String function,
84                        String message) {
85                if (level >= levelReporting) {
86                        if (popUp && !this.isVisible())
87                                this.setVisible(true);
88                        Logger.getLogger(ServerLogFrame.class).error(
89                                        "level " + level + " class " + clazz + " function "
90                                                        + function + " msg " + message);
91                        logText.append("[" + STR_[level] + "] " + clazz + "::"
92                                        + function + " - " + message + "\n");
93                }
94        }
95
96        /**
97         * Shows frame sets location relative to parent.
98         *
99         * @param parent Frame relative to which console window will be localized.
100         */
101        public void show(final JFrame parent) {
102                if (parent != null) {
103                        final Point parentLocation = parent.getLocation();
104                        final Point location = new Point(parentLocation.x + 20,
105                                        parentLocation.y + 20);
106                        this.setLocation(location);
107                }
108                this.setVisible(true);
109        }
110}
Note: See TracBrowser for help on using the repository browser.