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

Quick Search    Search Deep

Source code: com/trapezium/chisel/ChiselRow.java


1   /*
2    * @(#)ChiselRow.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  
12  package com.trapezium.chisel;
13  
14  import com.trapezium.chisel.gui.LabelConstants;
15  import com.trapezium.chisel.gui.TextLabel;
16  import com.trapezium.chisel.gui.ChiselController;
17  import com.trapezium.chisel.gui.LabelledImageButton;
18  import com.trapezium.chisel.gui.ChiselReporter;
19  import com.trapezium.chisel.gui.TableRowComponent;
20  import com.trapezium.factory.FactoryResponseListener;
21  import com.trapezium.factory.FactoryData;
22  import com.trapezium.factory.ParserFactory;
23  import com.trapezium.factory.FactoryChain;
24  import com.trapezium.parse.TokenEnumerator;
25  import java.awt.event.*;
26  import java.awt.Color;
27  import java.awt.Component;
28  import java.awt.Insets;
29  import java.awt.Font;
30  import java.io.File;
31  
32  /**
33   *  Handles GUI interface to a row in a chisel table.
34   *
35   *  @author          Michael St. Hippolyte
36   *  @version         1.1, 29 Jan 1998
37   *
38   *  @since           1.0
39   */
40  public class ChiselRow extends TableRow implements LabelConstants, FactoryResponseListener, ActionListener, RowState {
41      static Color greenGray = new Color(153, 204, 153);
42  
43      boolean enabled;    // user-set state
44    ChiselDescriptor theChisel;
45      ChiselOptionTable optionTable;
46      ChiselTable owner;
47      ChiselRowListener listener;
48      
49      boolean automaticallyChecked = false;
50  
51      /** global row number */
52      int rowNumber;
53      static int rowCounter = 1;
54  
55    public ChiselRow(int columns, Insets insets, ChiselRowListener listener, ChiselTable owner) {
56        super(columns, insets);
57        this.owner = owner;
58        this.listener = listener;
59        rowNumber = rowCounter;
60        rowCounter++;
61  
62        if (listener == null) {
63            //setEnabled(false);
64            return;
65        }
66  
67          ChiselController controller = new ChiselController(this);
68      setColumn(0, controller);
69  
70      for (int i = 1; i < columns; i++) {
71          setColumn(i, new ChiselReporter());
72      }
73      getChiselReporter(0).setForeground(Color.darkGray);
74      }
75  
76       public void actionPerformed( ActionEvent e ) {
77           Object s = e.getSource();
78           if ( s instanceof LabelledImageButton ) {
79               LabelledImageButton lib = (LabelledImageButton)s;
80               setEnabled( lib.getBooleanValue() );
81               if ( !lib.getBooleanValue() ) {
82                   owner.rowDisabled();
83               }
84           }
85      }
86  
87      public boolean isAutomaticallyChecked() {
88          return( automaticallyChecked );
89      }
90      
91    public void setChisel( ChiselDescriptor chisel, boolean autocheck ) {
92        automaticallyChecked = autocheck;
93      theChisel = chisel;
94      if (chisel != null) {
95          getChiselController().setLabel(new TextLabel(chisel.getShortDescription()));
96          if ( chisel.getInitialValue() instanceof String ) {
97              String s = (String)chisel.getInitialValue();
98              if ( s.compareTo( "true" ) == 0 ) {
99                  setEnabled( true );
100               }
101             }
102         getChiselController().setValue( String.valueOf(chisel.getInitialValue()) );
103             if (optionTable != null) {
104                 removeFromExpansion(optionTable.getComponent());
105             }
106             optionTable = new ChiselOptionTable(chisel);
107             addToExpansion(optionTable.getComponent());
108             setExpandible(chisel.getNumberOptions() > 0);
109         }
110   }
111 
112   public ChiselDescriptor getChisel() {
113     return theChisel;
114   }
115 
116   public ChiselTable getOwner() {
117     return owner;
118   }
119 
120     public ChiselController getChiselController() {
121         return (ChiselController) getColumn(0);
122     }
123 
124     public ChiselReporter getChiselReporter(int n) {
125         return (ChiselReporter) getColumn(n + 1);
126     }
127 
128     public boolean isEnabled() {
129         return enabled;
130     }
131 
132     public void setEnabled(boolean enabled) {
133         this.enabled = enabled;
134         if (listener != null) {
135             listener.rowStateChanged(this);
136         }
137     }
138 
139   // The following are the FactoryResponseListener interface
140   public void done( FactoryData result ) {
141       owner.reset(); //setPercent( -1 );
142   }
143 
144   /** replacement for the obsolete 'state' */
145   public void rowReady() {
146       ChiselController controller = getChiselController();
147       controller.setColor( Color.lightGray );
148   }
149 
150   public void rowRunning() {
151         ChiselController controller = getChiselController();
152         controller.setColor( Color.green );
153     }
154 
155     public void rowDone() {
156         ChiselController controller = getChiselController();
157         controller.setColor( greenGray );
158     }
159 
160   public void update( FactoryData result ) {
161   }
162 
163   public void setNumberOfLines( int n ) {
164   }
165 
166   public void setLinePercent( int percent ) {
167       int main = percent/10;
168       int remainder = percent%10;
169       owner.setPercent( main );
170   }
171 
172     long fileLength = 0;
173     public void setFileLength( long flen ) {
174         fileLength = flen;
175         TokenEnumerator.presetLength = flen;
176     }
177 
178   public void setPolygonCount( int n ) {
179       if ( n == 0 ) {
180           owner.setText( "No polygons." );
181       } else if ( n == 1 ) {
182           owner.setText( "1 polygon." );
183       } else {
184           owner.setText( n + " polygons." );
185       }
186   }
187 
188   public void setText( String s ) {
189         ChiselReporter resultReporter = getChiselReporter(0);
190         resultReporter.setLabelText( s );
191   }
192 
193   public void setAction( String action ) {
194       owner.setTitle( action );
195   }
196 
197   public void setFactoryData( FactoryData fd ) {
198   }
199 
200     static final Insets optionCellInsets = new Insets(2, 2, 2, 2);
201   class ChiselOptionTable extends Table implements ActionListener {
202 
203       public ChiselOptionTable(ChiselDescriptor chisel) {
204           super(2, chisel.getNumberOptions(), optionCellInsets);
205             getComponent().setBackground(inBetween(DEFAULT_TABLECOLOR, DEFAULT_TABLECOLOR.brighter()));
206             int n = chisel.getNumberOptions();
207             int maxwidth = 200;
208             TableRow row;
209             for (int i = 0; i < n; i++) {
210                 row = getRow(i);
211               row.setColumnWidth(0, 32);
212               Component ed = chisel.getOptionEditor(i, this);
213               row.setColumn(1, ed);
214               int edwidth = ed.getPreferredSize().width;
215               if (edwidth > maxwidth) {
216                   maxwidth = edwidth;
217               }
218           }
219 
220             for (int i = 0; i < n; i++) {
221                 row = getRow(i);
222               row.setColumnWidth(1, maxwidth);
223                 ((TableRowComponent) row.getComponent()).setColumnVaries(1, true);
224           }
225       }
226         /** by returning null from createHeader we make this a headerless table */
227         public TableRow createHeader(int columns, Insets insets, Object data) {
228             return null;
229         }
230 
231         Color inBetween(Color c1, Color c2) {
232             return new Color( (c1.getRed() + c2.getRed())/2,  (c1.getGreen() + c2.getGreen())/2, (c1.getBlue() + c2.getBlue())/2 );
233         }
234          public void actionPerformed( ActionEvent e ) {
235 /*             Object s = e.getSource();
236              if ( s instanceof LabelledImageButton ) {
237                  LabelledImageButton lib = (LabelledImageButton)s;
238                  ChiselController chiselController = getChiselController();
239                  setEnabled( lib.getValue() );
240              }*/
241         }
242     }
243 }