< prev index next >

src/com/sun/interview/wizard/RenderingUtilities.java

Print this page
rev 145 : 7902237: Fixing raw use of parameterized class
Reviewed-by: jjg


  58 import com.sun.interview.PropertiesQuestion;
  59 import com.sun.interview.PropertiesQuestion.BooleanConstraints;
  60 import com.sun.interview.PropertiesQuestion.FilenameConstraints;
  61 import com.sun.interview.PropertiesQuestion.FloatConstraints;
  62 import com.sun.interview.PropertiesQuestion.IntConstraints;
  63 import com.sun.interview.PropertiesQuestion.StringConstraints;
  64 import com.sun.interview.PropertiesQuestion.ValueConstraints;
  65 import com.sun.javatest.tool.UIFactory;
  66 
  67 /**
  68  * Utilities for rendering questions.
  69  */
  70 public class RenderingUtilities {
  71     public static class PCE implements TableCellEditor {
  72         private DefaultCellEditor cbCE;
  73         private DefaultCellEditor tfCE;
  74         private DefaultCellEditor delegate;
  75         private PropertiesQuestion q;
  76 
  77         public PCE(PropertiesQuestion q) {
  78             cbCE =  new PropCellEditor(new JComboBox(), q);
  79             tfCE =  new RestrainedCellEditor(new JTextField(), q);
  80             this.q = q;
  81         }
  82 
  83         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  84             assignDelegate(table, row, column);
  85             return delegate.getTableCellEditorComponent(table, value, isSelected, row, column);
  86         }
  87 
  88         public static boolean gotChoice(ValueConstraints vc) {
  89             if (vc == null) {
  90                 return false;
  91             }
  92 
  93             if (vc.isUnsetAllowed()) {
  94                return true;
  95             }
  96 
  97             if (vc instanceof IntConstraints) {
  98                 IntConstraints ic = (IntConstraints) vc;


 201             }
 202 
 203             if (vc instanceof FloatConstraints) {
 204                 FloatConstraints fc = (FloatConstraints)vc;
 205                 tf.setEditable(fc.isCustomValuesAllowed());
 206             }
 207 
 208             return tf;
 209         }
 210 
 211         private PropertiesQuestion q;
 212     }
 213 
 214 
 215 
 216     /**
 217      * Table cell renderer for enforcing constraints on the combo box used
 218      * for editing.
 219      */
 220     public static class PropCellEditor extends DefaultCellEditor {
 221         protected PropCellEditor(JComboBox box) {
 222             super(box);
 223         }
 224 
 225         PropCellEditor(JComboBox box, PropertiesQuestion q) {
 226             this(box);
 227             question = q;
 228         }
 229 
 230         /**
 231          * For use when this renderer is being used outside the context of
 232          * an interview and question.
 233          */
 234         PropCellEditor(JComboBox box, ValueConstraints rules) {
 235             this(box);
 236             this.rules = rules;
 237         }
 238 
 239         @Override
 240         public Object getCellEditorValue() {
 241             if (rules != null){
 242                 if (rules instanceof BooleanConstraints){
 243                     if (((BooleanConstraints)rules).isYesNo()) {
 244                         return yesNoBox.getValue();
 245                     }
 246                     else {
 247                         return jCheckBox.isSelected() ? BooleanConstraints.TRUE : BooleanConstraints.FALSE;
 248                     }
 249                 }
 250             }
 251             return super.getCellEditorValue();
 252         }
 253 
 254     @Override




  58 import com.sun.interview.PropertiesQuestion;
  59 import com.sun.interview.PropertiesQuestion.BooleanConstraints;
  60 import com.sun.interview.PropertiesQuestion.FilenameConstraints;
  61 import com.sun.interview.PropertiesQuestion.FloatConstraints;
  62 import com.sun.interview.PropertiesQuestion.IntConstraints;
  63 import com.sun.interview.PropertiesQuestion.StringConstraints;
  64 import com.sun.interview.PropertiesQuestion.ValueConstraints;
  65 import com.sun.javatest.tool.UIFactory;
  66 
  67 /**
  68  * Utilities for rendering questions.
  69  */
  70 public class RenderingUtilities {
  71     public static class PCE implements TableCellEditor {
  72         private DefaultCellEditor cbCE;
  73         private DefaultCellEditor tfCE;
  74         private DefaultCellEditor delegate;
  75         private PropertiesQuestion q;
  76 
  77         public PCE(PropertiesQuestion q) {
  78             cbCE =  new PropCellEditor(new JComboBox<Object>(), q);
  79             tfCE =  new RestrainedCellEditor(new JTextField(), q);
  80             this.q = q;
  81         }
  82 
  83         public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
  84             assignDelegate(table, row, column);
  85             return delegate.getTableCellEditorComponent(table, value, isSelected, row, column);
  86         }
  87 
  88         public static boolean gotChoice(ValueConstraints vc) {
  89             if (vc == null) {
  90                 return false;
  91             }
  92 
  93             if (vc.isUnsetAllowed()) {
  94                return true;
  95             }
  96 
  97             if (vc instanceof IntConstraints) {
  98                 IntConstraints ic = (IntConstraints) vc;


 201             }
 202 
 203             if (vc instanceof FloatConstraints) {
 204                 FloatConstraints fc = (FloatConstraints)vc;
 205                 tf.setEditable(fc.isCustomValuesAllowed());
 206             }
 207 
 208             return tf;
 209         }
 210 
 211         private PropertiesQuestion q;
 212     }
 213 
 214 
 215 
 216     /**
 217      * Table cell renderer for enforcing constraints on the combo box used
 218      * for editing.
 219      */
 220     public static class PropCellEditor extends DefaultCellEditor {
 221         protected PropCellEditor(JComboBox<Object> box) {
 222             super(box);
 223         }
 224 
 225         PropCellEditor(JComboBox<Object> box, PropertiesQuestion q) {
 226             this(box);
 227             question = q;
 228         }
 229 
 230         /**
 231          * For use when this renderer is being used outside the context of
 232          * an interview and question.
 233          */
 234         PropCellEditor(JComboBox<Object> box, ValueConstraints rules) {
 235             this(box);
 236             this.rules = rules;
 237         }
 238 
 239         @Override
 240         public Object getCellEditorValue() {
 241             if (rules != null){
 242                 if (rules instanceof BooleanConstraints){
 243                     if (((BooleanConstraints)rules).isYesNo()) {
 244                         return yesNoBox.getValue();
 245                     }
 246                     else {
 247                         return jCheckBox.isSelected() ? BooleanConstraints.TRUE : BooleanConstraints.FALSE;
 248                     }
 249                 }
 250             }
 251             return super.getCellEditorValue();
 252         }
 253 
 254     @Override


< prev index next >