Source code: org/pqt/autorib/instr/InstrAddRIB.java
1 //AutoRIB
2 // Copyright © 1998 - 2002, P W Quint
3 //
4 // Contact: autorib00@aol.com
5 //
6 // This library is free software; you can redistribute it and/or
7 // modify it under the terms of the GNU General Public
8 // License as published by the Free Software Foundation; either
9 // version 2 of the License, or (at your option) any later version.
10 //
11 // This library is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
15 //
16 // You should have received a copy of the GNU General Public
17 // License along with this library; if not, write to the Free Software
18 // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19
20 package org.pqt.autorib.instr;
21 import java.io.*;
22 import java.util.*;
23 import org.pqt.autorib.tokenizer.*;
24 import org.pqt.autorib.globals.*;
25 import org.pqt.autorib.util.*;
26 import org.pqt.autorib.rib.*;
27
28 /**
29 * Add RIB to an existing object or light
30 */
31 public class InstrAddRIB extends InstrBlockRequest {
32
33 public InstrAddRIB(InstrWReader in) throws IOException,
34 FormatException {
35 read(in);
36 }
37
38 public final void read(InstrWReader in) throws IOException,
39 FormatException {
40 readRequestName(in);
41 RIBRequest rq;
42 int t = in.tokenizer.getToken();
43 //note we use the tokenizer for the Instr file and use this to read RIB
44 if (t != Token.OPENBRACE)
45 throw new FormatException("{ expected",in.tokenizer);
46 boolean stop = false;
47 while (!stop) {
48 //read in RIB, taking advantage of the fact that tokenizer
49 //is the common superclass of both RIBTokenizer, and
50 //InstrTokenizer
51 rq = RIBReadRequest.readRequest(in.tokenizer);
52 if (rq instanceof RIBBrace) {
53 if (rq.requestID == Token.CLOSEBRACE)
54 stop = true;
55 else
56 throw new FormatException("} expected",in.tokenizer);
57 }
58 else
59 content.addElement(rq); //content is defined in the superclass
60 }
61 }
62
63 public void write(Writer out) throws IOException {
64 Enumeration i = content.elements();
65 writeRequest(out);
66 out.write("\n{\n");
67 while (i.hasMoreElements()) {
68 ((RIBRequest) i.nextElement()).write(out);
69 out.write("\n");
70 }
71 out.write("}");
72 }
73
74 /**
75 * add RIB to a light */
76 public void process(InstrWReader rw, RIBLight light) throws FormatException,
77 IOException {
78 light.prepend(content); //lights don't have attributes so just prepend
79 }
80
81
82 /**
83 * add RIB that will be output before the beginning of the object, checking
84 * first that it is not an attribute ('Color' 'Opacity' etc) in which case it
85 * overrides the existing attribute */
86 public void process(InstrWReader rw, RIBObjectGroup object) {
87 Enumeration i = content.elements();
88 while (i.hasMoreElements()) {
89 RIBRequest rq = (RIBRequest) i.nextElement();
90 if (!object.attributes.put(rq))
91 object.prepend(rq);
92 }
93 }
94
95 protected boolean filter(RIBLight light) throws FormatException {
96 return true;
97 }
98
99 protected boolean filter(RIBObjectGroup object) {
100 return true;
101 }
102
103
104 }
105
106