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

Last change on this file since 193 was 193, checked in by Maciej Komosinski, 10 years ago

Set svn:eol-style native for all textual files

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