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

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

HIGHLIGHTS:

  • upgrade to Java 7
    • use try-multi-catch clauses
    • use try-with-resources were appropriate
  • configure FindBugs? (use mvn site and then navigate in browser to the report)
    • remove most bugs found
  • parametrize Dispatching environment (Dispatcher, RunAt?) to enforce more control on the place of closures actual call

CHANGELOG:
Rework FavouritesXMLFactory.

FindBugs?. Thread start.

FindBugs?. Minor change.

FindBugs?. Iterate over entrySet.

FindBugs?. Various.

FindBug?.

FindBug?. Encoding.

FindBug?. Final fields.

FindBug?.

Remove synchronization bug in ClientConnection?.

Experiments with findbugs.

Finish parametrization.

Make RunAt? an abstract class.

More changes in parametrization.

More changes in parametrizing dispatching.

Several changes to parametrize tasks.

Rename Runnable to RunAt?.

Add specific framsticks Runnable.

Add JSR305 (annotations).

Add findbugs reporting.

More improvements to ParamBuilder? wording.

Make FramsClass? accept also ParamBuilder?.

Change wording of ParamBuilder?.

Change wording of Request creation.

Use Java 7 exception catch syntax.

Add ScopeEnd? class.

Upgrade to Java 7.

File size: 3.1 KB
Line 
1package com.framsticks.gui.windows;
2
3import com.framsticks.gui.ImageProvider;
4import org.apache.log4j.Logger;
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                        Logger.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.