KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > lib > terminalemulator > InterpDtTerm


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is Terminal Emulator.
16  * The Initial Developer of the Original Software is Sun Microsystems, Inc..
17  * Portions created by Sun Microsystems, Inc. are Copyright (C) 2001.
18  * All Rights Reserved.
19  *
20  * Contributor(s): Ivan Soleimanipour.
21  */

22
23 /*
24  * "InterpDtTerm.java"
25  * InterpDtTerm.java 1.2 01/07/23
26  * Input stream interpreter
27  * Decodes incoming characters into cursor motion etc.
28  */

29
30 package org.netbeans.lib.terminalemulator;
31
32
33 class InterpDtTerm extends InterpANSI {
34
35     protected static class InterpTypeDtTerm extends InterpTypeANSI {
36     protected final State st_esc_rb = new State("esc_rb"); // NOI18N
37
protected final State st_esc_lb_q = new State("esc_lb_q");// NOI18N
38
protected final State st_esc_lb_b = new State("esc_lb_b");// NOI18N
39
protected final State st_wait = new State("wait"); // NOI18N
40

41     protected final Actor act_DEC_private = new ACT_DEC_PRIVATE();
42     protected final Actor act_M = new ACT_M();
43     protected final Actor act_D = new ACT_D();
44     protected final Actor act_done_collect = new ACT_DONE_COLLECT();
45     protected final Actor act_collect = new ACT_COLLECT();
46     protected final Actor act_start_collect = new ACT_START_COLLECT();
47
48
49     protected InterpTypeDtTerm() {
50         st_esc.setAction(']', st_esc_rb, act_start_collect);
51
52         // the following two may be generic ANSI escapes
53
st_esc.setAction('D', st_base, act_D);
54         st_esc.setAction('M', st_base, act_M);
55
56         for (char c = 0; c < 128; c++)
57         st_esc_rb.setAction(c, st_esc_rb, act_collect);
58         st_esc_rb.setAction((char) 27, st_wait, act_nop);
59
60         st_wait.setAction('\\', st_base, act_done_collect);
61
62         st_esc_lb.setAction('?', st_esc_lb_q, act_reset_number);
63
64         for (char c = '0'; c <= '9'; c++)
65         st_esc_lb_q.setAction(c, st_esc_lb_q, act_remember_digit);
66         st_esc_lb_q.setAction('h', st_base, act_DEC_private);
67         st_esc_lb_q.setAction('l', st_base, act_DEC_private);
68         st_esc_lb_q.setAction('r', st_base, act_DEC_private);
69         st_esc_lb_q.setAction('s', st_base, act_DEC_private);
70
71         st_esc_lb.setAction('!', st_esc_lb_b, act_reset_number);
72         st_esc_lb_b.setAction('p', st_base, new ACT_DEC_STR());
73     }
74
75     protected static final class ACT_START_COLLECT implements Actor {
76         public String JavaDoc action(AbstractInterp ai, char c) {
77         InterpDtTerm i = (InterpDtTerm) ai;
78         i.text = ""; // NOI18N
79
return null;
80         }
81     }
82
83     protected static final class ACT_COLLECT implements Actor {
84         public String JavaDoc action(AbstractInterp ai, char c) {
85         // java bug 4318526 text += c;
86
InterpDtTerm i = (InterpDtTerm) ai;
87         i.text = i.text + c;
88         return null;
89         }
90     }
91
92     protected static final class ACT_DONE_COLLECT implements Actor {
93         public String JavaDoc action(AbstractInterp ai, char c) {
94         /* DEBUG
95         System.out.println("DtTerm emulation: got '" + text + "'"); // NOI18N
96         */

97         return null;
98         }
99     }
100
101     protected static final class ACT_D implements Actor {
102         public String JavaDoc action(AbstractInterp ai, char c) {
103         ai.ops.op_do(1);
104         return null;
105         }
106     };
107
108     protected static final class ACT_M implements Actor {
109         public String JavaDoc action(AbstractInterp ai, char c) {
110         ai.ops.op_up(1);
111         return null;
112         }
113     }
114
115     protected static final class ACT_DEC_PRIVATE implements Actor {
116         public String JavaDoc action(AbstractInterp ai, char c) {
117         if (ai.noNumber())
118             return "act_DEC_private: no number"; // NOI18N
119
int n = ai.numberAt(0);
120         switch(c) {
121             case 'h':
122             if (n == 5)
123                 ai.ops.op_reverse(true);
124             else if (n == 25)
125                 ai.ops.op_cursor_visible(true);
126             else
127                 return "act_DEC_private: unrecognized cmd " + c; // NOI18N
128
break;
129             case 'l':
130             if (n == 5)
131                 ai.ops.op_reverse(false);
132             else if (n == 25)
133                 ai.ops.op_cursor_visible(false);
134             else
135                 return "act_DEC_private: unrecognized cmd " + c; // NOI18N
136
break;
137             case 'r':
138             case 's':
139             /* DEBUG
140             System.out.println("act_DEC_private " + // NOI18N
141                 numberAt(0) + " " + c); // NOI18N
142             */

143             break;
144             default:
145             return "act_DEC_private: unrecognized cmd " + c; // NOI18N
146
}
147         return null;
148         }
149     }
150
151     protected static final class ACT_DEC_STR implements Actor {
152         public String JavaDoc action(AbstractInterp ai, char c) {
153         ai.ops.op_soft_reset();
154         return null;
155         }
156     }
157     }
158
159     private String JavaDoc text = null;
160
161     private InterpTypeDtTerm type;
162
163     public static final InterpTypeDtTerm type_singleton = new InterpTypeDtTerm();
164
165     public InterpDtTerm(Ops ops) {
166     super(ops, type_singleton);
167     this.type = type_singleton;
168     setup();
169     }
170
171     protected InterpDtTerm(Ops ops, InterpTypeDtTerm type) {
172     super(ops, type);
173     this.type = type;
174     setup();
175     }
176
177     public String JavaDoc name() {
178     return "dtterm"; // NOI18N
179
}
180
181     public void reset() {
182     super.reset();
183     text = null;
184     }
185
186
187     private void setup() {
188     state = type.st_base;
189     }
190
191 }
192
Popular Tags