source: java/main/src/main/java/com/framsticks/gui/console/DirectConsole.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: 1.9 KB
Line 
1package com.framsticks.gui.console;
2
3import java.util.LinkedList;
4import java.util.List;
5
6import com.framsticks.communication.Address;
7import com.framsticks.communication.ClientSideRawConnection;
8import com.framsticks.communication.ConnectionListener;
9import com.framsticks.params.annotations.FramsClassAnnotation;
10import com.framsticks.params.annotations.ParamAnnotation;
11import com.framsticks.util.dispatching.ThrowExceptionHandler;
12
13@FramsClassAnnotation
14public class DirectConsole extends InteractiveConsole implements ConnectionListener {
15
16        /**
17         * @param connection
18         */
19        public DirectConsole() {
20        }
21
22
23        @ParamAnnotation
24        public DirectConsole setAddress(String address) {
25                return setAddress(new Address(address));
26        }
27
28        public DirectConsole setAddress(Address address) {
29                this.connection = new ClientSideRawConnection();
30                this.connection.setAddress(address);
31                return this;
32        }
33
34        /**
35         * @return the connection
36         */
37        @Override
38        public ClientSideRawConnection getConnection() {
39                return (ClientSideRawConnection) connection;
40        }
41
42
43        protected void sendImplementation(String line) {
44                getConnection().send(line, ThrowExceptionHandler.getInstance());
45        }
46
47        /**
48         * Creates commands tip list.
49         * @param startText Text that user typed.
50         */
51        protected void findCompletionPropositions(String prefix) {
52                List<String> propositions = new LinkedList<String>();
53                for (String entry : history) {
54                        if (entry.startsWith(prefix)) {
55                                propositions.add(entry);
56                        }
57                }
58                processCompletionResult(prefix, propositions);
59        }
60
61        @Override
62        protected void joinableStart() {
63                super.joinableStart();
64                connection.getListeners().add(this);
65        }
66
67        @Override
68        protected void joinableInterrupt() {
69                connection.getListeners().remove(this);
70                super.joinableInterrupt();
71        }
72
73        @Override
74        public void connectionOutgoing(String line) {
75                dispatchWrite(line);
76        }
77
78        @Override
79        public void connectionIncomming(String line) {
80                dispatchWrite(line);
81        }
82}
Note: See TracBrowser for help on using the repository browser.