source: java/main/src/main/java/com/framsticks/gui/StatusBar.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: 2.3 KB
Line 
1package com.framsticks.gui;
2
3
4import java.awt.BorderLayout;
5import java.awt.Dimension;
6// import java.awt.Dimension;
7
8import javax.swing.JPanel;
9import javax.swing.JTextField;
10
11import org.apache.logging.log4j.Logger;
12import org.apache.logging.log4j.LogManager;
13
14import com.framsticks.gui.controls.Control;
15import com.framsticks.util.ExceptionHandler;
16import com.framsticks.util.FramsticksException;
17import com.framsticks.util.dispatching.Dispatcher;
18import com.framsticks.util.dispatching.Dispatching;
19import com.framsticks.util.dispatching.RunAt;
20
21public class StatusBar implements ExceptionHandler {
22        private static final Logger log = LogManager.getLogger(StatusBar.class);
23
24        protected JTextField statusBar;
25        protected JPanel swing;
26        protected ExceptionHandler exceptionHandler;
27        protected final Dispatcher<?> dispatcher;
28
29        /**
30         *
31         */
32        public StatusBar(Dispatcher<?> dispatcher) {
33                this.dispatcher = dispatcher;
34        }
35
36        @SuppressWarnings({"rawtypes", "unchecked"})
37        public void showInfo(final Object value) {
38                Dispatching.dispatchIfNotActive(dispatcher, new RunAt(this) {
39
40                        @Override
41                        protected void runAt() {
42                                String text = value.toString();
43                                log.info("info: {}", text);
44                                statusBar.setText(text);
45
46                        }
47                });
48        }
49
50        @Override
51        @SuppressWarnings({"rawtypes", "unchecked"})
52        public void handle(final FramsticksException exception) {
53                dispatcher.dispatch(new RunAt(this) {
54
55                        @Override
56                        protected void runAt() {
57                                log.error("error: {}", exception.getMessage());
58                                statusBar.setText(exception.getShortMessage(new StringBuilder()).toString());
59                                if (exceptionHandler != null) {
60                                        exceptionHandler.handle(exception);
61                                }
62                        }
63                });
64        }
65
66        public void initializeGui() {
67                statusBar = new JTextField();
68                statusBar.setEditable(false);
69
70                swing = new JPanel();
71                swing.setMaximumSize(new Dimension(Integer.MAX_VALUE, Control.LINE_HEIGHT));
72
73                swing.setLayout(new BorderLayout());
74                swing.add(statusBar, BorderLayout.CENTER);
75                // swing.add(statusBar);
76        }
77
78        /**
79         * @return the swing
80         */
81        public JPanel getSwing() {
82                return swing;
83        }
84
85        /**
86         * @return the exceptionHandler
87         */
88        public ExceptionHandler getExceptionHandler() {
89                return exceptionHandler;
90        }
91
92        /**
93         * @param exceptionHandler the exceptionHandler to set
94         */
95        public void setExceptionHandler(ExceptionHandler exceptionHandler) {
96                this.exceptionHandler = exceptionHandler;
97        }
98
99}
Note: See TracBrowser for help on using the repository browser.