Source code: com/trapezium/vrml/MultipleTokenElement.java
1 /*
2 * @(#)MultipleTokenElement.java
3 *
4 * Copyright (c) 1998 by Trapezium Development LLC. All Rights Reserved.
5 *
6 * The information in this file is the property of Trapezium Development LLC
7 * and may be used only in accordance with the terms of the license granted
8 * by Trapezium.
9 *
10 */
11 package com.trapezium.vrml;
12 import com.trapezium.parse.TokenEnumerator;
13
14 /**
15 * Scene graph component representing a range of tokens.
16 *
17 * @author Johannes N. Johannsen
18 * @version 1.12, 29 March 1998, added "adjust" method
19 * @version 1.0, 25 Nov 1997
20 *
21 * @since 1.0
22 */
23 public class MultipleTokenElement extends SingleTokenElement {
24 int lastTokenOffset = -1;
25
26 public MultipleTokenElement( int firstTokenOffset ) {
27 super( firstTokenOffset );
28 }
29
30 public void setLastTokenOffset( int lastTokenOffset ) {
31 this.lastTokenOffset = lastTokenOffset;
32 }
33
34 public int getLastTokenOffset() {
35 return( lastTokenOffset );
36 }
37
38 public boolean isTraversable() {
39 return( true );
40 }
41
42 /** Adjust the token offset if greater than or equal to boundary */
43 public void adjust( int boundary, int amount ) {
44 super.adjust( boundary, amount );
45 if ( lastTokenOffset >= boundary ) {
46 lastTokenOffset += amount;
47 }
48 }
49
50 /** Get the text of the element as a String */
51 public String getText() {
52 Scene s = (Scene)getScene();
53 if ( s != null ) {
54 TokenEnumerator te = s.getTokenEnumerator();
55 if ( te != null ) {
56 StringBuffer sb = new StringBuffer();
57 int scanner = getFirstTokenOffset();
58 int end = getLastTokenOffset();
59 te.setState( scanner );
60 while ( scanner <= end ) {
61 sb.append( te.toString( scanner ));
62 sb.append( " " );
63 scanner = te.getNextToken();
64 }
65 return( new String( sb ));
66 }
67 }
68 return( null );
69 }
70 }