Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: org/pqt/autorib/instr/InstrRIB.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  
24  import org.pqt.autorib.tokenizer.*;
25  import org.pqt.autorib.globals.*;
26  import org.pqt.autorib.util.*;
27  import org.pqt.autorib.rib.*;
28  
29  /**
30   * Add RIB to the header of a global options section, or to the frame options
31   * section - nb this class is used by GlobalRIB, FrameRIB
32   */
33  public class InstrRIB extends InstrBlockRequest {
34      
35      public InstrRIB(InstrWReader in) throws IOException,
36      FormatException {
37          read(in);
38      }
39      
40      public final void read(InstrWReader in) throws IOException,
41      FormatException {
42          readRequestName(in);
43          RIBRequest rq;
44          int t = in.tokenizer.getToken();
45          //note we use the tokenizer for the Instr file and use this to read RIB
46          if (t != Token.OPENBRACE)
47              throw new FormatException("{ expected",in.tokenizer);
48          boolean stop = false;
49          while (!stop) {
50              rq = RIBReadRequest.readRequest(in.tokenizer);
51              if (rq instanceof RIBBrace) {
52                  if (rq.requestID == Token.CLOSEBRACE)
53                      stop = true;
54                  else
55                      throw new FormatException("} expected",in.tokenizer);
56              }
57              else if (rq instanceof RIBLight)  {
58                  //lights are treated separately
59                  in.addedLights.addElement(rq);
60                  
61              } 
62              else
63                  content.addElement(rq);
64          }
65      }
66      
67      public void write(Writer out) throws IOException {
68          Enumeration i = content.elements();
69          writeRequest(out);
70          out.write("\n{\n");
71          while (i.hasMoreElements()) {
72              ((RIBRequest) i.nextElement()).write(out);
73              out.write("\n");
74          }
75          out.write("}");
76      }
77      
78      
79      /**
80       * append RIB to the header for the RIB file (the part that comes
81       * before any FrameBegin) or the header for the frame (ie between
82       * FrameBegin and WorldBegin).
83       * @param header Vector storing the header
84       * @param options stores current options
85       */
86      public void process(Vector header, RIBOptionRec options) {
87          Enumeration i = content.elements();
88          RIBRequest rq;
89          while (i.hasMoreElements()) {
90              rq = (RIBRequest) i.nextElement();
91              if (!options.put(rq)) //if not an option
92                  header.addElement(rq);     //store it in the usual way
93          }
94      }
95  }