Package edu.cmu.cs.stage3.util

Examples of edu.cmu.cs.stage3.util.StringObjectPair


                    question = new edu.cmu.cs.stage3.alice.core.question.array.ItemAtIndex();
                    ((edu.cmu.cs.stage3.alice.core.question.array.ItemAtIndex)question).array.set( expression );
                    ((edu.cmu.cs.stage3.alice.core.question.array.ItemAtIndex)question).index.set( new Double( i ) );
                  }
                  java.util.Vector responseStructure = PopupMenuUtilities.makeResponseStructure( question, factory, context );
                  subStructure.add( new StringObjectPair( "item" + i, responseStructure ) );
                }
                return subStructure;
              }
            };
            structure.add( new StringObjectPair( "item responses", delayedBindingPopupItem ) );
          }
        }
      }
    }
View Full Code Here


  public static java.util.Vector makePrototypeStructure( final ElementPrototype elementPrototype, final PopupItemFactory factory, final edu.cmu.cs.stage3.alice.core.Element context, edu.cmu.cs.stage3.alice.authoringtool.SceneManager sceneManager){
    //System.out.println("make prototype structure");
    java.util.Vector structure = new java.util.Vector();
    final String[] desiredProperties = elementPrototype.getDesiredProperties();
    if( (desiredProperties == null) || (desiredProperties.length == 0) ) {
      structure.add( new StringObjectPair( "no properties to set on " + elementPrototype.getElementClass().getName() + "; please report this bug", factory.createItem( elementPrototype ) ) ); // this should not be reached
    } else if( desiredProperties.length > 0 ) {
      String preRepr = elementPrototype.getElementClass().getName() + "." + desiredProperties[0];
      String propertyRepr = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( preRepr );
      if( propertyRepr.equals( preRepr ) ) {
        propertyRepr = desiredProperties[0];
      }
      structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( propertyRepr, null ) );
//      structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
      Class preValueClass = null;
      java.util.Vector preDefaultStructure = null;
      if( edu.cmu.cs.stage3.alice.core.response.PropertyAnimation.class.isAssignableFrom( elementPrototype.getElementClass() ) ) {
        preDefaultStructure = getDefaultValueStructureForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
        preValueClass = getValueClassForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
      } else if( edu.cmu.cs.stage3.alice.core.question.userdefined.PropertyAssignment.class.isAssignableFrom( elementPrototype.getElementClass() ) ) {
        preDefaultStructure = getDefaultValueStructureForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
        preValueClass = getValueClassForPropertyAnimation( elementPrototype.getKnownPropertyValues() );
      } else if( edu.cmu.cs.stage3.alice.core.question.list.ListBooleanQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
             edu.cmu.cs.stage3.alice.core.question.list.ListNumberQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
             edu.cmu.cs.stage3.alice.core.question.list.ListObjectQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
             edu.cmu.cs.stage3.alice.core.response.list.ListResponse.class.isAssignableFrom( elementPrototype.getElementClass() ) )
      {
        if( desiredProperties[0].equals( "item" ) ) {
          preValueClass = getValueClassForList( elementPrototype.getKnownPropertyValues() );
          preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
        } else if( desiredProperties[0].equals( "index" ) ) { // a bit hackish.
          preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
          preDefaultStructure = getDefaultValueStructureForCollectionIndexProperty( elementPrototype.getKnownPropertyValues() );
        } else {
          preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
          preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );
        }
      } else if( edu.cmu.cs.stage3.alice.core.question.array.ArrayNumberQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
             edu.cmu.cs.stage3.alice.core.question.array.ArrayObjectQuestion.class.isAssignableFrom( elementPrototype.getElementClass() ) ||
             edu.cmu.cs.stage3.alice.core.response.array.ArrayResponse.class.isAssignableFrom( elementPrototype.getElementClass() ) )
      {
        if( desiredProperties[0].equals( "item" ) ) {
          preValueClass = getValueClassForArray( elementPrototype.getKnownPropertyValues() );
          preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
        } else if( desiredProperties[0].equals( "index" ) ) {
          preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
          preDefaultStructure = getDefaultValueStructureForCollectionIndexProperty( elementPrototype.getKnownPropertyValues() );
        } else {
          preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
          preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );
        }
      } else if( elementPrototype instanceof CallToUserDefinedResponsePrototype ) {
        edu.cmu.cs.stage3.alice.core.response.UserDefinedResponse actualResponse = ((CallToUserDefinedResponsePrototype)elementPrototype).getActualResponse();
        Object[] params = actualResponse.requiredFormalParameters.getArrayValue();
        for( int i = 0; i < params.length; i++ ) {
          if( ((edu.cmu.cs.stage3.alice.core.Variable)params[i]).name.getStringValue().equals( desiredProperties[0] ) ) {
            preValueClass = (Class)((edu.cmu.cs.stage3.alice.core.Variable)params[i]).valueClass.getValue();
            break;
          }
        }
        preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
      } else if( elementPrototype instanceof CallToUserDefinedQuestionPrototype ) {
        edu.cmu.cs.stage3.alice.core.question.userdefined.UserDefinedQuestion actualQuestion = ((CallToUserDefinedQuestionPrototype)elementPrototype).getActualQuestion();
        Object[] params = actualQuestion.requiredFormalParameters.getArrayValue();
        for( int i = 0; i < params.length; i++ ) {
          if( ((edu.cmu.cs.stage3.alice.core.Variable)params[i]).name.getStringValue().equals( desiredProperties[0] ) ) {
            preValueClass = (Class)((edu.cmu.cs.stage3.alice.core.Variable)params[i]).valueClass.getValue();
            break;
          }
        }
        preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
      } else if (edu.cmu.cs.stage3.alice.core.question.IsEqualTo.class.isAssignableFrom( elementPrototype.getElementClass()) ||
            edu.cmu.cs.stage3.alice.core.question.IsNotEqualTo.class.isAssignableFrom( elementPrototype.getElementClass())){
        preValueClass = getValueClassForComparator(elementPrototype.knownPropertyValues);
        preDefaultStructure = getDefaultValueStructureForClass( preValueClass );
      }else {
        preValueClass = edu.cmu.cs.stage3.alice.core.Element.getValueClassForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
        preDefaultStructure = getDefaultValueStructureForProperty( elementPrototype.getElementClass(), desiredProperties[0] );       
      }

//      hack so we can use these in an inner class
     
      final Class valueClass = preValueClass;
          
      PopupItemFactory recursiveFactory = new PopupItemFactory() {
        public Object createItem( Object o ) {
          if (!valueClass.isInstance(o)){ //Add the question here?
            if (valueClass.isAssignableFrom(javax.vecmath.Vector3d.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
              edu.cmu.cs.stage3.alice.core.question.Position positionQuestion = new edu.cmu.cs.stage3.alice.core.question.Position();
              positionQuestion.subject.set(o);
              o = positionQuestion;
            } else if (valueClass.isAssignableFrom(javax.vecmath.Matrix4d.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
              edu.cmu.cs.stage3.alice.core.question.PointOfView POVQuestion = new edu.cmu.cs.stage3.alice.core.question.PointOfView();
              POVQuestion.subject.set(o);
              o = POVQuestion;
            }else if (valueClass.isAssignableFrom(edu.cmu.cs.stage3.math.Quaternion.class) && o instanceof edu.cmu.cs.stage3.alice.core.Transformable){
              edu.cmu.cs.stage3.alice.core.question.Quaternion quaternionQuestion = new edu.cmu.cs.stage3.alice.core.question.Quaternion();
              quaternionQuestion.subject.set(o);
              o = quaternionQuestion;
            }
          }
          if( desiredProperties.length == 1 ) { // end of the line
            //DEBUG System.out.println( "end of the line: " + desiredProperties[0] + ", " + o );
            return factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) );
          } else { // recurse
            //DEBUG System.out.println( "recursive: " + desiredProperties[0] + ", " + o );
            return makePrototypeStructure( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ), factory, context );
          }
        }
      };
//      hack so we can use these in an inner class
      final java.util.Vector defaultStructure = processStructure( preDefaultStructure, recursiveFactory, NO_CURRENT_VALUE );
     
      //System.out.println("defStructure:  " + defaultStructure.size());
     
      // compute recent values
      java.util.Vector recentlyUsedStructure = new java.util.Vector();
      if( recentlyUsedValues.containsKey( preValueClass ) ) {
        java.util.List recentList = (java.util.List)recentlyUsedValues.get( preValueClass );
        int count = 0;
        for( java.util.Iterator iter = recentList.iterator(); iter.hasNext(); ) {
          if( count > Integer.parseInt( authoringToolConfig.getValue( "maxRecentlyUsedValues" ) ) ) {
            break;
          }
          Object value = iter.next();
          if( ! structureContains( preDefaultStructure, value ) ) {
            recentlyUsedStructure.add( value );
            count++;
          }
        }
      }

     

      if( ! defaultStructure.isEmpty() ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        structure.addAll( defaultStructure );
      }

      // add recent values if there are any
      if( ! recentlyUsedStructure.isEmpty() ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        addLabelsToValueStructure( recentlyUsedStructure, elementPrototype.getElementClass(), desiredProperties[0] );
        structure.addAll( processStructure( recentlyUsedStructure, recursiveFactory, NO_CURRENT_VALUE ) );
      }


      // elements
      //   create criterion; handle exceptions
     
      // HERE
      edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion instanceOf = new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( valueClass );

      edu.cmu.cs.stage3.util.Criterion elementIsNamed = new edu.cmu.cs.stage3.util.Criterion() { //HACK; shouldn't have to cull unnamed elements
        public boolean accept( Object o ) {
          if( o instanceof edu.cmu.cs.stage3.alice.core.Element ) {
            if( ((edu.cmu.cs.stage3.alice.core.Element)o).name.get() != null ) {
              return true;
            }
          }
          return false;
        }
      };
      InAppropriateObjectArrayPropertyCriterion inAppropriateOAPCriterion = new InAppropriateObjectArrayPropertyCriterion();
      edu.cmu.cs.stage3.util.Criterion criterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { instanceOf, elementIsNamed, inAppropriateOAPCriterion } );
      Class elementClass = elementPrototype.getElementClass();
      edu.cmu.cs.stage3.util.StringObjectPair[] knownPropertyValues = elementPrototype.getKnownPropertyValues();
     
     
      //Don't get self criterion stuff!

      if( (edu.cmu.cs.stage3.alice.core.response.AbstractPointAtAnimation.class.isAssignableFrom( elementClass && desiredProperties[0].equals( "target" )) ||
        (edu.cmu.cs.stage3.alice.core.response.VehiclePropertyAnimation.class.isAssignableFrom(elementPrototype.elementClass&& desiredProperties[0].equals( "value" )) ){
        for( int i = 0; i < knownPropertyValues.length; i++ ) {
          String propertyName = knownPropertyValues[i].getString();
          if( propertyName.equals( "subject" ) || propertyName.equals( "element" ) ) {
            final Object transformableValue = knownPropertyValues[i].getObject();

            edu.cmu.cs.stage3.util.Criterion notSelf = new edu.cmu.cs.stage3.util.Criterion() {
              public boolean accept( Object o ) {
                if( o == transformableValue ) {
                  return false;
                }
                return true;
              }
            };
            //criterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { instanceOf, elementIsNamed, inAppropriateOAPCriterion, notSelf } );
            break;
          }
        }
      }
      //   make structure
      edu.cmu.cs.stage3.alice.core.Group currentGroup = null;
      if (sceneManager != null) currentGroup = sceneManager.getCurrentGroup();
     
           
      if( edu.cmu.cs.stage3.alice.core.Element.class.isAssignableFrom( valueClass ) || valueClass.isAssignableFrom( edu.cmu.cs.stage3.alice.core.Element.class ) ) {
        edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( criterion );
       
        if( elements.length > 0 ) {
          //CLK begin
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
          if (sceneManager != null) {
            //System.out.println("group: " + sceneManager.getCurrentGroup());
            structure.addAll( makeSceneElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE, sceneManager.getCurrentGroup() ) );
          } else {
            //System.out.println("no scenemanager");
            structure.addAll( makeSceneElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE, null ) );
          }
          /*if( elements.length < 10 ) {
            if( structure.size() > 0 ) {
              structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
            }
            structure.addAll( makeFlatElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
          } else {
            if( structure.size() > 0 ) {
              structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
            }
            structure.addAll( makeElementStructure( context.getRoot(), criterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
          }*/
          //CLK end
        }
      }
     
           
      //if (!Object.class.isAssignableFrom(valueClass)) {
      if (Object.class.isAssignableFrom(valueClass)) {
        //Okay, this needs to build a structure to find models, get their position and pass them to the vector3d property
        if( javax.vecmath.Vector3d.class.isAssignableFrom( valueClass ) || valueClass.isAssignableFrom(javax.vecmath.Vector3d.class)) {
          edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
          edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
          if( elements.length > 0 ) {
            //if( elements.length < 10 ) {
            //  if( structure.size() > 0 ) {
            //    structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
            //  }
            //  structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
            //} else {
              if( structure.size() > 0 ) {
                structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
              }
              structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
            //}
          }
        }
        if( valueClass.isAssignableFrom(javax.vecmath.Matrix4d.class)) {
          edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
        //BEGIN CLK - filter out everything but dummy objects in set point of view
          if (edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.isExperimentalSceneSupportEnabled()) {
           
   
            if( (edu.cmu.cs.stage3.alice.core.response.PointOfViewAnimation.class.isAssignableFrom( elementClass )) && desiredProperties[0].equals( "pointOfView" ) ) {
            edu.cmu.cs.stage3.util.Criterion onlyDummies = new edu.cmu.cs.stage3.util.Criterion() {
              public boolean accept( Object o ) {
                if (o instanceof edu.cmu.cs.stage3.alice.core.Dummy)
                  return true;
                else return false;
              }
            };
            modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion, onlyDummies } );
          }
        }
        // END CLK
       
          edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
          if( elements.length > 0 ) {
            //if( elements.length < 10 ) {
              //if( structure.size() > 0 ) {
              //  structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
              //}
              //structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
            //} else {
              if( structure.size() > 0 ) {
                structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
              }
              structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
            //}
          }
        }
        if( valueClass.isAssignableFrom(edu.cmu.cs.stage3.math.Quaternion.class)) {
          edu.cmu.cs.stage3.util.Criterion modelCriterion = new edu.cmu.cs.stage3.util.criterion.MatchesAllCriterion( new edu.cmu.cs.stage3.util.Criterion[] { new edu.cmu.cs.stage3.util.criterion.InstanceOfCriterion( edu.cmu.cs.stage3.alice.core.Model.class ), elementIsNamed, inAppropriateOAPCriterion } );
          edu.cmu.cs.stage3.alice.core.Element[] elements = context.getRoot().search( modelCriterion );
          if( elements.length > 0 ) {
            //if( elements.length < 10 ) {
            //  if( structure.size() > 0 ) {
            //    structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
            //  }
            //  structure.addAll( makeFlatElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE ) );
            //} else {
              if( structure.size() > 0 ) {
                structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
              }
              structure.addAll( makeSceneElementStructure( context.getRoot(), modelCriterion, recursiveFactory, context, NO_CURRENT_VALUE, currentGroup ) );
            //}
          }
        }
      }
      //else {
      //  System.out.println("bleh");
      //}
     
      // import or record sound if necessary
      final PopupItemFactory metaFactory = new PopupItemFactory() {
        public Object createItem( final Object o ) {
          return new Runnable() {
            public void run() {
              ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) )).run();
            }
          };
        }
      };
      if( valueClass.isAssignableFrom( edu.cmu.cs.stage3.alice.core.Sound.class ) && (valueClass != Object.class) ) {
        java.io.File soundDir = new java.io.File( edu.cmu.cs.stage3.alice.authoringtool.JAlice.getAliceHomeDirectory(), "sounds" ).getAbsoluteFile();
        if( soundDir.exists() && soundDir.isDirectory() ) {
          java.util.ArrayList sounds = new java.util.ArrayList();
          java.io.File[] fileList = soundDir.listFiles();
          for( int i = 0; i < fileList.length; i++ ) {
            if( fileList[i].isFile() && fileList[i].canRead() ) {
              sounds.add( fileList[i] );
            }
          }

          if( sounds.size() > 0 ) {
            if( structure.size() > 0 ) {
              structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
            }
            for( java.util.Iterator iter = sounds.iterator(); iter.hasNext(); ) {
              final java.io.File soundFile = (java.io.File)iter.next();
              String name = soundFile.getName();
              name = name.substring( 0, name.lastIndexOf( '.' ) );
              Runnable importSoundRunnable = new Runnable() {
                public void run() {
                  edu.cmu.cs.stage3.alice.core.Sound sound = (edu.cmu.cs.stage3.alice.core.Sound)edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( soundFile, context.getSandbox() );
                  if( sound != null ) {
                    ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], sound ) ) )).run();
                  }
//                  edu.cmu.cs.stage3.alice.authoringtool.util.SwingWorker worker = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( soundFile, context.getSandbox() );
//                  ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], worker.get() ) ) )).run();
                }
              };
              structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( name, importSoundRunnable ) );
            }
          }
        }

        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        Runnable importRunnable = new Runnable() {
          public void run() {
//            PropertyPopupPostWorker postWorker = new PropertyPopupPostWorker( metaFactory );
            PropertyPopupPostImportRunnable propertyPopupPostImportRunnable = new PropertyPopupPostImportRunnable( metaFactory );
            edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().setImportFileFilter( "Sound Files" );
            edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().importElement( null, context.getSandbox(), propertyPopupPostImportRunnable );
          }
        };
        Runnable recordRunnable = new Runnable() {
          public void run() {
            edu.cmu.cs.stage3.alice.core.Sound sound = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack().promptUserForRecordedSound( context.getSandbox() );
            if( sound != null ) {
              ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], sound ) ) )).run();
            }
          }
        };
        structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "import sound file...", importRunnable ) );
        structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "record new sound...", recordRunnable ) );
      }

      // expressions
      java.util.Vector expressionStructure = makeFlatExpressionStructure( valueClass, recursiveFactory, context, NO_CURRENT_VALUE );
      if( (expressionStructure != null) && (expressionStructure.size() > 0) ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "expressions", expressionStructure ) );
      }

      // Null
      boolean nullValid;
      if( elementPrototype instanceof edu.cmu.cs.stage3.alice.authoringtool.util.CallToUserDefinedResponsePrototype ) {
        nullValid = true;
      } else if( elementPrototype instanceof edu.cmu.cs.stage3.alice.authoringtool.util.CallToUserDefinedQuestionPrototype ) {
        nullValid = true;
      } else {
        nullValid = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.shouldGUIIncludeNone( elementPrototype.getElementClass(), desiredProperties[0] );
//        nullValid = edu.cmu.cs.stage3.alice.core.Element.isNullValidForPropertyNamed( elementPrototype.getElementClass(), desiredProperties[0] );
      }
      if( nullValid ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        String nullRepr = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( null, elementClass, desiredProperties[0], "menuContext" );
        if( desiredProperties.length == 1 ) { // end of the line
          structure.add( new StringObjectPair( nullRepr, factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], null ) ) ) ) );
        } else { // recurse
          structure.add( new StringObjectPair( nullRepr, makePrototypeStructure( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], null ) ), factory, context ) ) );
        }
      }

      // Other...
      final PopupItemFactory otherFactory = new PopupItemFactory() {
        public Object createItem( final Object o ) {
          return new Runnable() {
            public void run() {
              ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], o ) ) )).run();
            }
          };
        }
      };
      if( (desiredProperties.length == 1) && edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.isOtherDialogSupportedForClass( valueClass ) ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        Runnable runnable = new Runnable() {
          public void run() {
            //TODO: context doesn't really want to be passed here... it wants to be the response that will be made...
            edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.showOtherDialog( valueClass, null, otherFactory, context );
          }
        };
        structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "other...", runnable ) );
      }

      // allow user to create new list
      if( edu.cmu.cs.stage3.alice.core.List.class.isAssignableFrom( valueClass ) && (desiredProperties.length == 1) ) {
        if( structure.size() > 0 ) {
          structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
        }
        Runnable createNewListRunnable = new Runnable() {
          public void run() {
            edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool authoringTool = edu.cmu.cs.stage3.alice.authoringtool.AuthoringTool.getHack();
            edu.cmu.cs.stage3.alice.core.property.ObjectArrayProperty variables = context.getSandbox().variables;
            edu.cmu.cs.stage3.alice.core.Variable variable = authoringTool.showNewVariableDialog( "Create new list", context.getRoot(), true, true );
            if( variable != null ) {
              if( variables != null ) {
                authoringTool.getUndoRedoStack().startCompound();
                try {
                  variables.getOwner().addChild( variable );
                  variables.add( variable );
                } finally {
                  authoringTool.getUndoRedoStack().stopCompound();
                }
              }
              ((Runnable)factory.createItem( elementPrototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( desiredProperties[0], variable ) ) )).run();
            }
          }
        };
        structure.add( new StringObjectPair( "create new list...", createNewListRunnable ) );
      }
    }
   

    return structure;
View Full Code Here

      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "list", listVariable ) };
      String[] desired = new String[] { "index" };
      ElementPrototype ithPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.list.ItemAtIndex.class, known, desired );
      java.util.Vector ithStructure = makePrototypeStructure( ithPrototype, prototypeToItemFactory, context );

      structure.add( new StringObjectPair( "first item from list", firstItemRunnable ) );
      structure.add( new StringObjectPair( "last item from list", lastItemRunnable ) );
      structure.add( new StringObjectPair( "random item from list", randomItemRunnable ) );
      structure.add( new StringObjectPair( "ith item from list", ithStructure ) );
    }
    if ( edu.cmu.cs.stage3.alice.core.Element.class.isAssignableFrom( list.valueClass.getClassValue() ) ){
//      public static java.util.Vector makePropertyValueStructure( final edu.cmu.cs.stage3.alice.core.Element element, Class valueClass, final PopupItemFactory factory, edu.cmu.cs.stage3.alice.core.Element context ) {
//      java.util.Vector structure = new java.util.Vector();
// 
//      Class elementClass = null;
//      if( element instanceof edu.cmu.cs.stage3.alice.core.Expression ) {
//        elementClass = ((edu.cmu.cs.stage3.alice.core.Expression)element).getValueClass();
//      } else {
//        elementClass = element.getClass();
//      }
// 
//      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "element", element ) };
//      String[] desired = new String[] { "propertyName" };
//      ElementPrototype prototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.PropertyValue.class, known, desired );
// 
//      String[] propertyNames = getPropertyNames( elementClass, valueClass );
// 
//      String prefix = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( element, false ) + ".";
//      for( int i = 0; i < propertyNames.length; i++ ) {
//        if( (! propertyNames[i].equals( "visualization" )) && (! propertyNames[i].equals( "isFirstClass" )) ) { // HACK suppression
//          String propertyName = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( propertyNames[i], false );
//          structure.add( new StringObjectPair( prefix + propertyName, factory.createItem( prototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( "propertyName", propertyName ) ) ) ) );
//        }
//      }
// 
//      return structure;
    }
    if( returnValueClass.isAssignableFrom( Boolean.class ) ) {
      Runnable isEmptyRunnable = new Runnable() { public void run() {
        edu.cmu.cs.stage3.alice.core.question.list.IsEmpty isEmpty = new edu.cmu.cs.stage3.alice.core.question.list.IsEmpty();
        isEmpty.list.set( listVariable );
        ((Runnable)factory.createItem( isEmpty )).run();
      } };

      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "list", listVariable ) };
      String[] desired = new String[] { "item" };
      ElementPrototype containsPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.list.Contains.class, known, desired );
      java.util.Vector containsStructure = makePrototypeStructure( containsPrototype, prototypeToItemFactory, context );

      if( structure.size() > 0 ) {
        structure.add( new StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
      }
      structure.add( new StringObjectPair( "is list empty", isEmptyRunnable ) );
      structure.add( new StringObjectPair( "list contains", containsStructure ) );
    }

    if( returnValueClass.isAssignableFrom( Number.class ) ) {
      Runnable sizeRunnable = new Runnable() { public void run() {
        edu.cmu.cs.stage3.alice.core.question.list.Size size = new edu.cmu.cs.stage3.alice.core.question.list.Size();
        size.list.set( listVariable );
        ((Runnable)factory.createItem( size )).run();
      } };

      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "list", listVariable ) };
      String[] desired = new String[] { "item" };

      ElementPrototype firstIndexOfItemPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.list.FirstIndexOfItem.class, known, desired );
      java.util.Vector firstIndexOfItemStructure = makePrototypeStructure( firstIndexOfItemPrototype, prototypeToItemFactory, context );

      ElementPrototype lastIndexOfItemPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.list.LastIndexOfItem.class, known, desired );
      java.util.Vector lastIndexOfItemStructure = makePrototypeStructure( lastIndexOfItemPrototype, prototypeToItemFactory, context );

      if( structure.size() > 0 ) {
        structure.add( new StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
      }
      structure.add( new StringObjectPair( "size of list", sizeRunnable ) );
      structure.add( new StringObjectPair( "first index of", firstIndexOfItemStructure ) );
      structure.add( new StringObjectPair( "last index of", lastIndexOfItemStructure ) );
    }

    return structure;
  }
View Full Code Here

      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "array", arrayVariable ) };
      String[] desired = new String[] { "index" };
      ElementPrototype ithPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.array.ItemAtIndex.class, known, desired );
      java.util.Vector ithStructure = makePrototypeStructure( ithPrototype, prototypeToItemFactory, context );

      structure.add( new StringObjectPair( "ith item from array", ithStructure ) );
    }

    if( returnValueClass.isAssignableFrom( Number.class ) ) {
      Runnable sizeRunnable = new Runnable() { public void run() {
        edu.cmu.cs.stage3.alice.core.question.array.Size size = new edu.cmu.cs.stage3.alice.core.question.array.Size();
        size.array.set( arrayVariable );
        ((Runnable)factory.createItem( size )).run();
      } };

      edu.cmu.cs.stage3.util.StringObjectPair[] known = new edu.cmu.cs.stage3.util.StringObjectPair[] { new edu.cmu.cs.stage3.util.StringObjectPair( "array", arrayVariable ) };
      String[] desired = new String[] { "item" };

      if( structure.size() > 0 ) {
        structure.add( new StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
      }
      structure.add( new StringObjectPair( "size of array", sizeRunnable ) );
    }

    return structure;
  }
View Full Code Here

    ElementPrototype multiplyPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberMultiplication.class, known, desired );
    java.util.Vector multiplyStructure = makePrototypeStructure( multiplyPrototype, factory, context );
    ElementPrototype dividePrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberDivision.class, known, desired );
    java.util.Vector divideStructure = makePrototypeStructure( dividePrototype, factory, context );

    structure.add( new StringObjectPair( firstOperandRepr + " +", addStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " -", subtractStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " *", multiplyStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " /", divideStructure ) );

    return structure;
  }
View Full Code Here

    ElementPrototype equalPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.IsEqualTo.class, known, desired );
    java.util.Vector equalStructure = makePrototypeStructure( equalPrototype, factory, context );
    ElementPrototype notEqualPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.IsNotEqualTo.class, known, desired );
    java.util.Vector notEqualStructure = makePrototypeStructure( notEqualPrototype, factory, context );

    structure.add( new StringObjectPair( firstOperandRepr + " and", andStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " or", orStructure ) );
    structure.add( new StringObjectPair( "not " + firstOperandRepr, notItem ) );
    structure.add( new edu.cmu.cs.stage3.util.StringObjectPair( "Separator", javax.swing.JSeparator.class ) );
    structure.add( new StringObjectPair( firstOperandRepr + " ==", equalStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " !=", notEqualStructure ) );

    return structure;
  }
View Full Code Here

    ElementPrototype equalPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.IsEqualTo.class, known, desired );
    java.util.Vector equalStructure = makePrototypeStructure( equalPrototype, factory, context );
    ElementPrototype notEqualPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.IsNotEqualTo.class, known, desired );
    java.util.Vector notEqualStructure = makePrototypeStructure( notEqualPrototype, factory, context );

    structure.add( new StringObjectPair( firstOperandRepr + " ==", equalStructure ) );
    structure.add( new StringObjectPair( firstOperandRepr + " !=", notEqualStructure ) );

    if( (firstOperand instanceof Number) || ((firstOperand instanceof edu.cmu.cs.stage3.alice.core.Expression) && Number.class.isAssignableFrom( ((edu.cmu.cs.stage3.alice.core.Expression)firstOperand).getValueClass() )) ) {
//      ElementPrototype equalToPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsEqualTo.class, known, desired );
//      java.util.Vector equalToStructure = makePrototypeStructure( equalToPrototype, factory, context );
//      ElementPrototype notEqualToPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsNotEqualTo.class, known, desired );
//      java.util.Vector notEqualToStructure = makePrototypeStructure( notEqualToPrototype, factory, context );
     
      ElementPrototype lessThanPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsLessThan.class, known, desired );
      java.util.Vector lessThanStructure = makePrototypeStructure( lessThanPrototype, factory, context );
      ElementPrototype greaterThanPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsGreaterThan.class, known, desired );
      java.util.Vector greaterThanStructure = makePrototypeStructure( greaterThanPrototype, factory, context );
      ElementPrototype lessThanOrEqualPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsLessThanOrEqualTo.class, known, desired );
      java.util.Vector lessThanOrEqualStructure = makePrototypeStructure( lessThanOrEqualPrototype, factory, context );
      ElementPrototype greaterThanOrEqualPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.NumberIsGreaterThanOrEqualTo.class, known, desired );
      java.util.Vector greaterThanOrEqualStructure = makePrototypeStructure( greaterThanOrEqualPrototype, factory, context );
     
//      structure.add( new StringObjectPair( firstOperandRepr + " ==", equalToStructure ) );
//      structure.add( new StringObjectPair( firstOperandRepr + " !=", notEqualToStructure ) );
      structure.add( new StringObjectPair( firstOperandRepr + " <", lessThanStructure ) );
      structure.add( new StringObjectPair( firstOperandRepr + " >", greaterThanStructure ) );
      structure.add( new StringObjectPair( firstOperandRepr + " <=", lessThanOrEqualStructure ) );
      structure.add( new StringObjectPair( firstOperandRepr + " >=", greaterThanOrEqualStructure ) );
    }

    return structure;
  }
View Full Code Here

    ElementPrototype yPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.vector3.Y.class, known, new String[0] );
    Object yItem = factory.createItem( yPrototype );
    ElementPrototype zPrototype = new ElementPrototype( edu.cmu.cs.stage3.alice.core.question.vector3.Z.class, known, new String[0] );
    Object zItem = factory.createItem( zPrototype );

    structure.add( new StringObjectPair( positionRepr + "'s distance right", xItem ) );
    structure.add( new StringObjectPair( positionRepr + "'s distance up", yItem ) );
    structure.add( new StringObjectPair( positionRepr + "'s distance forward", zItem ) );

    return structure;
  }
View Full Code Here

    String[] propertyNames = getPropertyNames( elementClass, valueClass );
    String prefix = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( element, false ) + ".";
    for( int i = 0; i < propertyNames.length; i++ ) {
      if( (! propertyNames[i].equals( "visualization" )) && (! propertyNames[i].equals( "isFirstClass" )) ) { // HACK suppression
        String propertyName = edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue( propertyNames[i], false );
        structure.add( new StringObjectPair( prefix + propertyName, factory.createItem( prototype.createCopy( new edu.cmu.cs.stage3.util.StringObjectPair( "propertyName", propertyName ) ) ) ) );
      }
    }

    return structure;
  }
View Full Code Here

    java.util.Vector structure = new java.util.Vector();
    if( realCollection != null ) {
      int size = realCollection.values.size();
      for( int i = 0; (i < size) && (i < 10); i++ ) {
        structure.add( new StringObjectPair( Integer.toString( i ), new Double( (double)i ) ) );
      }
    }

    if( structure.size() < 1 ) {
      structure.add( new StringObjectPair( "0", new Double( 0.0 ) ) );
    }

    return structure;
  }
View Full Code Here

TOP

Related Classes of edu.cmu.cs.stage3.util.StringObjectPair

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.