source: java/main/src/main/java/com/framsticks/gui/console/Console.java @ 97

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

HIGHLIGHTS:

  • add proper exception passing between communication sides:

if exception occur during handling client request, it is
automatically passed as comment to error response.

it may be used to snoop communication between peers

  • fix algorithm choosing text controls in GUI
  • allow GUI testing in virtual frame buffer (xvfb)

FEST had some problem with xvfb but workaround was found

supports tab-completion based on requests history

CHANGELOG:
Further improve handling of exceptions in GUI.

Add StatusBar? implementing ExceptionResultHandler?.

Make completion processing asynchronous.

Minor changes.

Improve completion in console.

Improve history in InteractiveConsole?.

First working version of DirectConsole?.

Minor changes.

Make Connection.address non final.

It is more suitable to use in configuration.

Improvement of consoles.

Improve PopupMenu? and closing of FrameJoinable?.

Fix BrowserTest?.

Found bug with FEST running under xvfb.

JButtonFixture.click() is not working under xvfb.
GuiTest? has wrapper which uses JButton.doClick() directly.

Store CompositeParam? param in TreeNode?.

Simplify ClientSideManagedConnection? connecting.

There is now connectedFunctor needed, ApplicationRequests? can be
send right after creation. They are buffered until the version
and features are negotiated.

Narow down interface of ClientSideManagedConnection?.

Allow that connection specialization send only
ApplicationRequests?.

Improve policy of text control choosing.

Change name of Genotype in BrowserTest?.

Make BrowserTest? change name of Genotype.

Minor change.

First working draft of TrackConsole?.

Simplify Consoles.

More improvements with gui joinables.

Unify initialization on gui joinables.

More rework of Frame based entities.

Refactorize structure of JFrames based entities.

Extract GuiTest? from BrowserBaseTest?.

Reorganize Console classes structure.

Add Collection view to JoinableCollection?.

Configure timeout in testing.

Minor changes.

Rework connections hierarchy.

Add Mode to the get operation.

Make get and set in Tree take PrimitiveParam?.

Unify naming of operations.

Make RunAt? use the given ExceptionHandler?.

It wraps the virtual runAt() method call with
try-catch passing exception to handler.

Force RunAt? to include ExceptionHandler?.

Improve ClientAtServer?.

Minor change.

Another sweep with FindBugs?.

Rename Instance to Tree.

Minor changes.

Minor changes.

Further clarify semantics of Futures.

Add FutureHandler?.

FutureHandler? is refinement of Future, that proxifies
exception handling to ExceptionResultHandler? given
at construction time.

Remove StateFunctor? (use Future<Void> instead).

Make Connection use Future<Void>.

Unparametrize *ResponseFuture?.

Remove StateCallback? not needed anymore.

Distinguish between sides of ResponseFuture?.

Base ResponseCallback? on Future (now ResponseFuture?).

Make asynchronous store taking Future for flags.

Implement storeValue in ObjectInstance?.

File size: 3.2 KB
Line 
1package com.framsticks.gui.console;
2
3import java.awt.BorderLayout;
4import java.awt.Dimension;
5
6import javax.swing.BorderFactory;
7import javax.swing.JPanel;
8import javax.swing.JScrollPane;
9import javax.swing.JTextPane;
10
11import org.apache.log4j.Logger;
12
13import com.framsticks.communication.Connection;
14import com.framsticks.gui.FrameJoinable;
15import com.framsticks.params.annotations.FramsClassAnnotation;
16import com.framsticks.util.FramsticksException;
17import com.framsticks.util.dispatching.Dispatching;
18import com.framsticks.util.dispatching.ExceptionResultHandler;
19import com.framsticks.util.dispatching.Joinable;
20import com.framsticks.util.dispatching.JoinableParent;
21import com.framsticks.util.dispatching.JoinableState;
22import com.framsticks.util.dispatching.RunAt;
23
24@FramsClassAnnotation
25public abstract class Console extends FrameJoinable implements JoinableParent {
26        private static final Logger log = Logger.getLogger(Console.class);
27
28        /**
29         * Painter coloring manager responses before display.
30         */
31        protected ConsolePainter consolePainter;
32
33        protected Connection connection;
34
35        protected JPanel panel;
36
37        /**
38         * @param connection
39         */
40        public Console() {
41                setTitle("console");
42        }
43
44        /**
45         * @return the connection
46         */
47        public Connection getConnection() {
48                return connection;
49        }
50
51        @Override
52        public String getName() {
53                return connection != null ? "console for " + connection.getName() : "console";
54        }
55
56        @Override
57        protected void initializeGui() {
58                super.initializeGui();
59                panel = new JPanel();
60                panel.setLayout(new BorderLayout());
61                panel.setSize(new Dimension(440, 400));
62                panel.setMinimumSize(new Dimension(440, 400));
63
64                JTextPane text = new JTextPane();
65                consolePainter = new ConsolePainter(text);
66
67                text.setEditable(false);
68                final JScrollPane scrollText = new JScrollPane(text);
69                scrollText.setBorder(BorderFactory.createEtchedBorder());
70
71                JPanel scrollPanel = new JPanel();
72                scrollPanel.setLayout(new BorderLayout());
73                scrollPanel.add(scrollText, BorderLayout.CENTER);
74                scrollPanel.setBorder(BorderFactory.createEmptyBorder(7, 7, 7, 7));
75
76                panel.add(scrollPanel, BorderLayout.CENTER);
77
78                getSwing().getContentPane().add(panel, BorderLayout.CENTER);
79
80                log.debug("initialized gui");
81        }
82
83        @Override
84        public void childChangedState(Joinable joinable, JoinableState state) {
85                if (joinable == connection) {
86                        proceedToState(state);
87                }
88        }
89
90        protected ExceptionResultHandler getExceptionHandler() {
91                return new ExceptionResultHandler() {
92
93                        @Override
94                        public void handle(FramsticksException exception) {
95                                throw exception;
96
97                        }
98                };
99        }
100
101        @Override
102        protected void joinableStart() {
103                if (connection == null) {
104                        throw new FramsticksException().msg("connection was not set").arg("console", this);
105                }
106                super.joinableStart();
107                Dispatching.use(connection, this);
108        }
109
110        @Override
111        protected void joinableInterrupt() {
112                Dispatching.drop(connection, this);
113                super.joinableInterrupt();
114        }
115
116        @Override
117        protected void joinableFinish() {
118                super.joinableFinish();
119        }
120
121        @Override
122        protected void joinableJoin() throws InterruptedException {
123                Dispatching.join(connection);
124                super.joinableJoin();
125        }
126
127        protected void dispatchWrite(final String line) {
128                dispatch(new RunAt<Console>(getExceptionHandler()) {
129                        @Override
130                        protected void runAt() {
131                                consolePainter.userLine(line);
132                        }
133                });
134        }
135
136}
Note: See TracBrowser for help on using the repository browser.