source: java/main/src/main/java/com/framsticks/gui/FrameJoinable.java @ 99

Last change on this file since 99 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.3 KB
Line 
1package com.framsticks.gui;
2
3import java.awt.BorderLayout;
4import java.awt.Container;
5import java.awt.event.WindowAdapter;
6import java.awt.event.WindowEvent;
7import java.util.concurrent.atomic.AtomicBoolean;
8
9import javax.swing.JFrame;
10import javax.swing.UIManager;
11
12import org.apache.log4j.Logger;
13
14import com.framsticks.util.FramsticksException;
15import com.framsticks.util.dispatching.ExceptionResultHandler;
16import com.framsticks.util.dispatching.RunAt;
17import com.framsticks.util.dispatching.ThrowExceptionHandler;
18
19public abstract class FrameJoinable extends SwingJoinable<JFrame> implements ExceptionResultHandler {
20        private static final Logger log =
21                Logger.getLogger(FrameJoinable.class);
22
23        protected String title;
24
25        protected final StatusBar statusBar;
26
27
28        /**
29         *
30         */
31        public FrameJoinable() {
32                statusBar = new StatusBar();
33        }
34
35        public void setTitle(String title) {
36                this.title = title;
37                if (hasSwing()) {
38                        getSwing().setTitle(title);
39                }
40        }
41
42        /**
43         * @return the statusBar
44         */
45        public StatusBar getStatusBar() {
46                return statusBar;
47        }
48
49        @Override
50        public String getName() {
51                return title;
52        }
53
54        private final static AtomicBoolean sentGuiInitialization = new AtomicBoolean(false);
55
56
57        @Override
58        protected void joinableStart() {
59
60                if (sentGuiInitialization.compareAndSet(false, true)) {
61                        dispatch(new RunAt<FrameJoinable>(ThrowExceptionHandler.getInstance()) {
62                                @Override
63                                protected void runAt() {
64                                        try {
65                                                boolean found = false;
66                                                // for (LookAndFeelInfo info : UIManager.getInstalledLookAndFeels()) {
67                                                //      log.info("look and feel available: " + info.getName());
68                                                //      if ("Nimbus".equals(info.getName())) {
69                                                //              UIManager.setLookAndFeel(info.getClassName());
70                                                //              found = true;
71                                                //              break;
72                                                //      }
73                                                // }
74                                                if (!found) {
75                                                        UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
76                                                }
77                                                JFrame.setDefaultLookAndFeelDecorated(true);
78                                        } catch (Exception e) {
79                                                throw new FramsticksException().msg("failed to initialize Look&Feel").cause(e);
80                                        }
81                                }
82                        });
83                }
84
85                super.joinableStart();
86                dispatch(new RunAt<FrameJoinable>(ThrowExceptionHandler.getInstance()) {
87                        @Override
88                        protected void runAt() {
89                                getSwing().setVisible(true);
90                        }
91                });
92
93        }
94
95        @Override
96        protected void joinableInterrupt() {
97                super.joinableInterrupt();
98
99                dispatch(new RunAt<Frame>(ThrowExceptionHandler.getInstance()) {
100                        @Override
101                        protected void runAt() {
102                                finish();
103                        }
104                });
105
106        }
107
108        @Override
109        protected void joinableFinish() {
110                super.joinableFinish();
111                log.debug("disposing frame " + this);
112                getSwing().dispose();
113        }
114
115        @Override
116        protected void joinableJoin() throws InterruptedException {
117                super.joinableJoin();
118
119        }
120
121        @Override
122        protected void initializeGui() {
123                setSwing(new JFrame(title));
124                statusBar.initializeGui();
125
126                Container contentPane = getSwing().getContentPane();
127                contentPane.setLayout(new BorderLayout());
128                contentPane.add(statusBar.getSwing(), BorderLayout.SOUTH);
129
130                getSwing().setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
131
132                getSwing().addWindowListener(new WindowAdapter() {
133                        @Override
134                        public void windowClosing(WindowEvent e) {
135                                log.info("received closing");
136                                interrupt();
137                        }
138                });
139
140
141        }
142
143        @Override
144        public void handle(FramsticksException exception) {
145                statusBar.handle(exception);
146        }
147
148}
Note: See TracBrowser for help on using the repository browser.