001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: *
041: * Contributor(s): Ivan Soleimanipour.
042: */
043:
044: /*
045: * "InterpDtTerm.java"
046: * InterpDtTerm.java 1.2 01/07/23
047: * Input stream interpreter
048: * Decodes incoming characters into cursor motion etc.
049: */
050:
051: package org.netbeans.lib.terminalemulator;
052:
053: class InterpDtTerm extends InterpANSI {
054:
055: protected static class InterpTypeDtTerm extends InterpTypeANSI {
056: protected final State st_esc_rb = new State("esc_rb"); // NOI18N
057: protected final State st_esc_lb_q = new State("esc_lb_q");// NOI18N
058: protected final State st_esc_lb_b = new State("esc_lb_b");// NOI18N
059: protected final State st_wait = new State("wait"); // NOI18N
060:
061: protected final Actor act_DEC_private = new ACT_DEC_PRIVATE();
062: protected final Actor act_M = new ACT_M();
063: protected final Actor act_D = new ACT_D();
064: protected final Actor act_done_collect = new ACT_DONE_COLLECT();
065: protected final Actor act_collect = new ACT_COLLECT();
066: protected final Actor act_start_collect = new ACT_START_COLLECT();
067:
068: protected InterpTypeDtTerm() {
069: st_esc.setAction(']', st_esc_rb, act_start_collect);
070:
071: // the following two may be generic ANSI escapes
072: st_esc.setAction('D', st_base, act_D);
073: st_esc.setAction('M', st_base, act_M);
074:
075: for (char c = 0; c < 128; c++)
076: st_esc_rb.setAction(c, st_esc_rb, act_collect);
077: st_esc_rb.setAction((char) 27, st_wait, act_nop);
078:
079: st_wait.setAction('\\', st_base, act_done_collect);
080:
081: st_esc_lb.setAction('?', st_esc_lb_q, act_reset_number);
082:
083: for (char c = '0'; c <= '9'; c++)
084: st_esc_lb_q.setAction(c, st_esc_lb_q,
085: act_remember_digit);
086: st_esc_lb_q.setAction('h', st_base, act_DEC_private);
087: st_esc_lb_q.setAction('l', st_base, act_DEC_private);
088: st_esc_lb_q.setAction('r', st_base, act_DEC_private);
089: st_esc_lb_q.setAction('s', st_base, act_DEC_private);
090:
091: st_esc_lb.setAction('!', st_esc_lb_b, act_reset_number);
092: st_esc_lb_b.setAction('p', st_base, new ACT_DEC_STR());
093: }
094:
095: protected static final class ACT_START_COLLECT implements Actor {
096: public String action(AbstractInterp ai, char c) {
097: InterpDtTerm i = (InterpDtTerm) ai;
098: i.text = ""; // NOI18N
099: return null;
100: }
101: }
102:
103: protected static final class ACT_COLLECT implements Actor {
104: public String action(AbstractInterp ai, char c) {
105: // java bug 4318526 text += c;
106: InterpDtTerm i = (InterpDtTerm) ai;
107: i.text = i.text + c;
108: return null;
109: }
110: }
111:
112: protected static final class ACT_DONE_COLLECT implements Actor {
113: public String action(AbstractInterp ai, char c) {
114: /* DEBUG
115: System.out.println("DtTerm emulation: got '" + text + "'"); // NOI18N
116: */
117: return null;
118: }
119: }
120:
121: protected static final class ACT_D implements Actor {
122: public String action(AbstractInterp ai, char c) {
123: ai.ops.op_do(1);
124: return null;
125: }
126: };
127:
128: protected static final class ACT_M implements Actor {
129: public String action(AbstractInterp ai, char c) {
130: ai.ops.op_up(1);
131: return null;
132: }
133: }
134:
135: protected static final class ACT_DEC_PRIVATE implements Actor {
136: public String action(AbstractInterp ai, char c) {
137: if (ai.noNumber())
138: return "act_DEC_private: no number"; // NOI18N
139: int n = ai.numberAt(0);
140: switch (c) {
141: case 'h':
142: if (n == 5)
143: ai.ops.op_reverse(true);
144: else if (n == 25)
145: ai.ops.op_cursor_visible(true);
146: else
147: return "act_DEC_private: unrecognized cmd " + c; // NOI18N
148: break;
149: case 'l':
150: if (n == 5)
151: ai.ops.op_reverse(false);
152: else if (n == 25)
153: ai.ops.op_cursor_visible(false);
154: else
155: return "act_DEC_private: unrecognized cmd " + c; // NOI18N
156: break;
157: case 'r':
158: case 's':
159: /* DEBUG
160: System.out.println("act_DEC_private " + // NOI18N
161: numberAt(0) + " " + c); // NOI18N
162: */
163: break;
164: default:
165: return "act_DEC_private: unrecognized cmd " + c; // NOI18N
166: }
167: return null;
168: }
169: }
170:
171: protected static final class ACT_DEC_STR implements Actor {
172: public String action(AbstractInterp ai, char c) {
173: ai.ops.op_soft_reset();
174: return null;
175: }
176: }
177: }
178:
179: private String text = null;
180:
181: private InterpTypeDtTerm type;
182:
183: public static final InterpTypeDtTerm type_singleton = new InterpTypeDtTerm();
184:
185: public InterpDtTerm(Ops ops) {
186: super (ops, type_singleton);
187: this .type = type_singleton;
188: setup();
189: }
190:
191: protected InterpDtTerm(Ops ops, InterpTypeDtTerm type) {
192: super (ops, type);
193: this .type = type;
194: setup();
195: }
196:
197: public String name() {
198: return "dtterm"; // NOI18N
199: }
200:
201: public void reset() {
202: super .reset();
203: text = null;
204: }
205:
206: private void setup() {
207: state = type.st_base;
208: }
209:
210: }
|