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

Quick Search    Search Deep

Source code: com/trapezium/chisel/condensers/Remove_material_node.java


1   /*
2    * @(#)Remove_material_node.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.chisel.condensers;
12  
13  import com.trapezium.chisel.Optimizer;
14  import com.trapezium.chisel.TokenPrinter;
15  import com.trapezium.vrml.node.*;
16  import com.trapezium.vrml.fields.*;
17  
18  /**
19   * Remove_material_node is a custom chisel designed by Johannes Johannsen
20   *
21   * This code was generated by Chisel Developer Kit version 1.0
22   */
23  public class Remove_material_node extends Optimizer {
24    // constants defining options by offset
25    static final int REMOVE_ONLY_IF_TEXTURE_AVAILABLE_OPTION = 0;
26  
27    // variables for storing option values
28    boolean remove_only_if_texture_available;
29  
30    public Remove_material_node() {
31      super( "Appearance", "Removing material nodes" );
32      remove_only_if_texture_available = true;
33    }
34  
35    /** reset called just before chisel is run on a new file */
36    public void reset() {
37    }
38  
39    /** Get the number of options available for this chisel */
40    public int getNumberOptions() {
41      return( 1 );
42    }
43  
44    /** Get the data type of an option */
45    public Class getOptionClass( int offset ) {
46      if ( offset == REMOVE_ONLY_IF_TEXTURE_AVAILABLE_OPTION ) {
47        return( Boolean.TYPE );
48      }
49      return( null );
50    }
51  
52    /** Get the label for an option */
53    public String getOptionLabel( int offset ) {
54      if ( offset == REMOVE_ONLY_IF_TEXTURE_AVAILABLE_OPTION ) {
55        return( "remove only if texture available" );
56      }
57      return( null );
58    }
59  
60    /** Get the value of an option */
61    public Object getOptionValue( int offset ) {
62      if ( offset == REMOVE_ONLY_IF_TEXTURE_AVAILABLE_OPTION ) {
63        return( booleanToOptionValue( remove_only_if_texture_available ));
64      }
65      return( null );
66    }
67  
68    /** Set the value of an option */
69    public void setOptionValue( int offset, Object value ) {
70      if ( offset == REMOVE_ONLY_IF_TEXTURE_AVAILABLE_OPTION ) {
71        remove_only_if_texture_available = optionValueToBoolean( value );
72      }
73    }
74  
75    /** Get the constraints on an option */
76    public Object getOptionConstraints( int offset ) {
77      return( null );
78    }
79  
80    /** Check if Node should be modified.
81     * TODO: user defined
82     */
83    boolean optimizationOK( Node n ) {
84      // MUST BE USER DEFINED
85      return( true );
86    }
87  
88    /** Called when node of specified type found in graph traversal */
89    public void attemptOptimization( Node n ) {
90      if ( optimizationOK( n )) {
91        // if you need to access any of the fields, here they are
92        // Field value is null if field not specified in file
93        Field texture = n.getField( "texture" );
94        Field material = n.getField( "material" );
95        Field textureTransform = n.getField( "textureTransform" );
96        // register entire node for regeneration
97        // last parameter can be any object, it is passed to "optimize" method
98        // as the "param" parameter
99        if ( remove_only_if_texture_available ) {
100           if ( texture != null ) {
101               if ( material != null ) {
102                   replaceRange( material.getFirstTokenOffset(), material.getLastTokenOffset(), null );
103               }
104           }
105       } else {
106           if ( material != null )
107           replaceRange( material.getFirstTokenOffset(), material.getLastTokenOffset(), null );
108       }
109     }
110   }
111 
112   /** Called to regenerate a portion of the text in a file.
113    *
114    *  @param tp object that takes regenerated text, similar to a PrintStream
115    *  @param param Object passed to "replaceRange" in "attemptOptimization" method above
116    *  @param startTokenOffset offset of first token in sequence being regenerated
117    *  @param endTokenOffset offset of last token in sequence being regenerated
118    */
119   public void optimize( TokenPrinter tp, Object param, int startTokenOffset, int endTokenOffset ) {
120     // TODO: user defined
121     // if nothing done here, entire range is removed
122   }
123 
124 }