Exemple #1
0
  public void mousePressed(
      java.awt.event.MouseEvent ev,
      edu.cmu.cs.stage3.alice.core.Transformable pickedTransformable,
      edu.cmu.cs.stage3.alice.scenegraph.renderer.PickInfo pickInfo) {
    if (isButton1(ev)) {
      undoRedoStack.startCompound();
      if (pickedTransformable != null) {
        String name =
            edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getNameForNewChild(
                pickedTransformable.name.getStringValue(), pickedTransformable.getParent());
        int index = pickedTransformable.getParent().getIndexOfChild(pickedTransformable) + 1;

        //				if( undoRedoStack != null ) {
        //					undoRedoStack.setIsListening( true ); // make the copy get automatically picked up by
        // the undoRedoStack
        //				}
        pickedTransformable =
            (edu.cmu.cs.stage3.alice.core.Transformable)
                pickedTransformable.HACK_createCopy(
                    name, pickedTransformable.getParent(), index, classesToShare, null);
        edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources
            .addElementToAppropriateProperty(pickedTransformable, pickedTransformable.getParent());
        //				undoRedoStack.push( new
        // edu.cmu.cs.stage3.alice.authoringtool.util.PropertyUndoableRedoable(
        // pickedTransformable.vehicle, null, pickedTransformable.vehicle.get() ) );
        //				if( undoRedoStack != null ) {
        //					undoRedoStack.setIsListening( false );
        //				}
      }
      super.mousePressed(ev, pickedTransformable, pickInfo);
      hasBeenDragged = false;
    }
  }
  protected void refreshGUI() {
    Object value = property.get();
    StringBuffer repr = new StringBuffer();

    if (!omitPropertyName) {
      repr.append(
          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue(property)
              + " = ");
    }

    if (value instanceof edu.cmu.cs.stage3.alice.core.Expression) {
      repr.append(
          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getNameInContext(
              (edu.cmu.cs.stage3.alice.core.Element) value, property.getOwner()));
    } else if (value == null) {
      repr.append("<None>");
    } else if (value instanceof java.awt.Font) {
      java.awt.Font font = (java.awt.Font) value;
      repr.append(font.getFontName());
      if (!(property.getOwner() instanceof edu.cmu.cs.stage3.alice.core.Text3D)) {
        repr.append(", " + font.getSize());
      }
    } else {
      throw new RuntimeException("Bad value: " + value);
    }

    setText(repr.toString());
    revalidate();
    repaint();
  }
 public ForEachElementPanel() {
   super();
   backgroundColor =
       edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor("ForEachInOrder");
   headerText = "For all";
   endHeaderText = "at a time";
   middleHeaderText = ", one";
 }
 @Override
 protected void updateGUI() {
   super.updateGUI();
   edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory pif =
       new edu.cmu.cs.stage3.alice.authoringtool.util.SetPropertyImmediatelyFactory(m_condition);
   conditionalInput =
       edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getPropertyViewController(
           m_condition,
           true,
           true,
           edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.shouldGUIOmitPropertyName(
               m_condition),
           pif);
   headerPanel.remove(glue);
   headerPanel.add(
       conditionalInput,
       new java.awt.GridBagConstraints(
           3,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       endHeader,
       new java.awt.GridBagConstraints(
           4,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       glue,
       new java.awt.GridBagConstraints(
           5,
           0,
           1,
           1,
           1,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.BOTH,
           new java.awt.Insets(0, 0, 0, 0),
           0,
           0));
 }
 public void set(edu.cmu.cs.stage3.alice.core.Property property, boolean omitPropertyName) {
   clean();
   this.property = property;
   this.omitPropertyName = omitPropertyName;
   setBackground(
       edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
           "propertyViewControllerBackground"));
   setMargin(new java.awt.Insets(0, 4, 0, 4));
   startListening();
   refreshGUI();
 }
 @Override
 public void update() {
   setText(
       edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue(
           property.get(), property));
 }
 public WhileElementPanel() {
   super();
   headerText = "While";
   backgroundColor =
       edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor("WhileLoopInOrder");
 }
 protected void updateGUI() {
   super.updateGUI();
   edu.cmu.cs.stage3.alice.authoringtool.util.PopupItemFactory pif =
       new edu.cmu.cs.stage3.alice.authoringtool.util.SetPropertyImmediatelyFactory(m_list) {
         public void run(Object v) {
           edu.cmu.cs.stage3.alice.core.Element inputList;
           String name;
           if (v instanceof edu.cmu.cs.stage3.alice.core.List) {
           } else if (v instanceof edu.cmu.cs.stage3.alice.core.Variable) {
             if (!(((edu.cmu.cs.stage3.alice.core.Variable) v).value.get()
                 instanceof edu.cmu.cs.stage3.alice.core.List)) {
               return;
             }
           } else {
             return;
           }
           super.run(v);
         }
       };
   if (m_list.get() != null) {
     setVariable();
   }
   variable =
       edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getVariableDnDPanel(
           (edu.cmu.cs.stage3.alice.core.Variable) m_each.get());
   listInput =
       edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getPropertyViewController(
           m_list,
           false,
           true,
           edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.shouldGUIOmitPropertyName(
               m_list),
           pif);
   headerPanel.remove(glue);
   headerPanel.add(
       listInput,
       new java.awt.GridBagConstraints(
           3,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       new javax.swing.JLabel(middleHeaderText),
       new java.awt.GridBagConstraints(
           4,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       variable,
       new java.awt.GridBagConstraints(
           5,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       endHeader,
       new java.awt.GridBagConstraints(
           6,
           0,
           1,
           1,
           0,
           0,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.NONE,
           new java.awt.Insets(0, 2, 0, 2),
           0,
           0));
   headerPanel.add(
       glue,
       new java.awt.GridBagConstraints(
           7,
           0,
           1,
           1,
           1,
           1,
           java.awt.GridBagConstraints.CENTER,
           java.awt.GridBagConstraints.BOTH,
           new java.awt.Insets(0, 0, 0, 0),
           0,
           0));
 }
  public void getHTML(StringBuffer toWriteTo, int colSpan, boolean useColor, boolean isDisabled) {
    int totalRows = 0;
    String colorString = "";
    String borderColorString = getHTMLColorString(java.awt.Color.lightGray);
    String styleString = "";
    String strikeStart = "";
    String strikeEnd = "";
    if (!isDisabled) {
      isDisabled = isDisabled();
    }
    if (useColor) {
      if (isDisabled) {
        colorString =
            " bgcolor=\""
                + getHTMLColorString(
                    edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                        "disabledHTML"))
                + "\"";
      } else {
        colorString = " bgcolor=\"" + getHTMLColorString(getCustomBackgroundColor()) + "\"";
      }
    }
    if (isDisabled) {
      strikeStart =
          "<strike><font color=\""
              + getHTMLColorString(
                  edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                      "disabledHTMLText"))
              + "\">";
      strikeEnd = "</font></strike>";
    }
    totalRows = getTotalHTMLRows(m_element);
    if (this
        instanceof
        edu.cmu.cs.stage3.alice.authoringtool.editors.questioneditor.MainCompositeQuestionPanel) {
      totalRows++;
    }
    styleString =
        " style=\"border-left: 1px solid "
            + borderColorString
            + "; border-top: 1px solid "
            + borderColorString
            + "; border-right: 1px solid "
            + borderColorString
            + "\"";
    toWriteTo.append(
        "<td colspan=\"" + colSpan + "\"" + colorString + styleString + ">&nbsp;&nbsp;");

    toWriteTo.append(strikeStart + getHeaderHTML() + strikeEnd);
    if (this instanceof IfElseElementPanel
        || edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
            .IS_JAVA) {
      styleString = " style=\"border-left: 1px solid " + borderColorString + "\"";
    } else {
      styleString =
          " style=\"border-left: 1px solid "
              + borderColorString
              + "; border-bottom: 1px solid "
              + borderColorString
              + "\"";
    }
    toWriteTo.append(
        "</td>\n</tr>\n<tr>\n<td width=\"20\" rowspan=\""
            + totalRows
            + "\""
            + colorString
            + styleString
            + ">&nbsp;&nbsp;&nbsp;&nbsp;</td>\n");
    for (int i = 0; i < componentElementPanel.getElementComponentCount(); i++) {
      if (i > 0) {
        toWriteTo.append("<tr>\n");
      }
      java.awt.Component currentComponent = componentElementPanel.getComponent(i);
      if (currentComponent instanceof CompositeElementPanel) {
        ((CompositeElementPanel) currentComponent)
            .getHTML(toWriteTo, colSpan - 1, useColor, isDisabled);
      } else {
        String componentColorString = "";
        String componentStrikeStart = "";
        String componentStrikeEnd = "";
        boolean isComponentDisabled =
            isDisabled || ((ComponentElementPanel) currentComponent).isDisabled();
        if (currentComponent instanceof ComponentElementPanel) {
          if (isComponentDisabled) {
            componentColorString =
                " bgcolor=\""
                    + getHTMLColorString(
                        edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                            "disabledHTML"))
                    + "\"";
            componentStrikeStart =
                "<strike><font color=\""
                    + getHTMLColorString(
                        edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                            "disabledHTMLText"))
                    + "\">";
            componentStrikeEnd = "</font></strike>";
          } else {
            componentColorString =
                " bgcolor=\""
                    + getHTMLColorString(
                        ((ComponentElementPanel) currentComponent).getCustomBackgroundColor())
                    + "\"";
          }
        }
        styleString =
            " style=\"border-bottom: 1px solid "
                + borderColorString
                + "; border-right: 1px solid "
                + borderColorString
                + "; border-left: 1px solid "
                + borderColorString
                + "; border-top: 1px solid "
                + borderColorString
                + "\"";
        toWriteTo.append(
            "<td width=\"100%\" colspan=\""
                + (colSpan - 1)
                + "\""
                + componentColorString
                + styleString
                + ">&nbsp;&nbsp;"
                + componentStrikeStart
                + edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getHTMLStringForComponent(
                    currentComponent)
                + componentStrikeEnd
                + "</td>\n");
      }
    }
    if (componentElementPanel.getElementComponentCount() == 0) {
      if (this instanceof IfElseElementPanel
          || edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
              .IS_JAVA) {
        styleString = " style=\"border-right: 1 solid " + borderColorString + "\"";
      } else {
        styleString =
            " style=\"border-right: 1 solid "
                + borderColorString
                + "; border-bottom: 1 solid "
                + borderColorString
                + "\"";
      }
      toWriteTo.append(
          "<td width=\"100%\" colspan=\""
              + (colSpan - 1)
              + "\""
              + colorString
              + styleString
              + ">"
              + strikeStart
              + "<i> Do Nothing </i>"
              + strikeEnd
              + "</td>\n</tr>\n");
    }
    if (this
        instanceof
        edu.cmu.cs.stage3.alice.authoringtool.editors.questioneditor.MainCompositeQuestionPanel) {
      edu.cmu.cs.stage3.alice.authoringtool.editors.questioneditor.MainCompositeQuestionPanel
          mainQuestion =
              (edu.cmu.cs.stage3.alice.authoringtool.editors.questioneditor
                      .MainCompositeQuestionPanel)
                  this;
      styleString =
          " style=\"border-bottom: 1 solid "
              + borderColorString
              + "; border-right: 1 solid "
              + borderColorString
              + "; border-left: 1 solid "
              + borderColorString
              + ";\"";
      colorString =
          " bgcolor=\""
              + getHTMLColorString(
                  edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor("Return"))
              + "\"";
      toWriteTo.append(
          "<tr>\n<td width=\"100%\" colspan=\""
              + colSpan
              + "\""
              + colorString
              + styleString
              + ">"
              + edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getHTMLStringForComponent(
                  mainQuestion.returnPanel)
              + "</td>\n</tr>\n");
    }
    if (this instanceof IfElseElementPanel) {
      IfElseElementPanel ifElse = (IfElseElementPanel) this;
      if (m_element instanceof edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) {
        totalRows =
            getTotalRowsToRenderForIfElse(
                m_element,
                ((edu.cmu.cs.stage3.alice.core.question.userdefined.IfElse) m_element)
                    .elseComponents);
      } else if (m_element instanceof edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) {
        totalRows =
            getTotalRowsToRenderForIfElse(
                m_element,
                ((edu.cmu.cs.stage3.alice.core.response.IfElseInOrder) m_element)
                    .elseComponentResponses);
      }
      styleString =
          " style=\"border-left: 1 solid "
              + borderColorString
              + "; border-right: 1 solid "
              + borderColorString
              + "\"";

      toWriteTo.append(
          "<tr>\n<td colspan=\""
              + colSpan
              + "\""
              + colorString
              + styleString
              + ">&nbsp;&nbsp;"
              + strikeStart
              + edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getHTMLStringForComponent(
                  ((IfElseElementPanel) this).elsePanel)
              + strikeEnd
              + "</td>\n");
      if (edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
          .IS_JAVA) {
        styleString = " style=\"border-left: 1 solid " + borderColorString + "\"";
      } else {
        styleString =
            " style=\"border-left: 1 solid "
                + borderColorString
                + "; border-bottom: 1 solid "
                + borderColorString
                + "\"";
      }
      toWriteTo.append(
          "</tr>\n<tr>\n<td width=\"20\" rowspan=\""
              + totalRows
              + "\""
              + colorString
              + styleString
              + ">&nbsp;</td>\n");
      for (int i = 0; i < ifElse.elseComponentPanel.getElementComponentCount(); i++) {
        if (i > 0) {
          toWriteTo.append("<tr>\n");
        }
        java.awt.Component currentComponent = ifElse.elseComponentPanel.getComponent(i);
        if (currentComponent instanceof CompositeElementPanel) {
          ((CompositeElementPanel) currentComponent)
              .getHTML(toWriteTo, colSpan - 1, useColor, isDisabled);
        } else {
          String componentColorString = "";
          String componentStrikeStart = "";
          String componentStrikeEnd = "";
          boolean isComponentDisabled =
              isDisabled || ((ComponentElementPanel) currentComponent).isDisabled();
          if (currentComponent instanceof ComponentElementPanel) {
            if (isComponentDisabled) {
              componentColorString =
                  " bgcolor=\""
                      + getHTMLColorString(
                          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                              "disabledHTML"))
                      + "\"";
              componentStrikeStart =
                  "<strike><font color=\""
                      + getHTMLColorString(
                          edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor(
                              "disabledHTMLText"))
                      + "\">";
              componentStrikeEnd = "</font></strike>";
            } else {
              componentColorString =
                  " bgcolor=\""
                      + getHTMLColorString(
                          ((ComponentElementPanel) currentComponent).getCustomBackgroundColor())
                      + "\"";
            }
          }
          styleString =
              " style=\"border-bottom: 1 solid "
                  + borderColorString
                  + "; border-right: 1 solid "
                  + borderColorString
                  + "; border-left: 1 solid "
                  + borderColorString
                  + "; border-top: 1 solid "
                  + borderColorString
                  + "\"";
          toWriteTo.append(
              "<td colspan=\""
                  + (colSpan - 1)
                  + "\""
                  + componentColorString
                  + styleString
                  + ">&nbsp;&nbsp;"
                  + componentStrikeStart
                  + edu.cmu.cs.stage3.alice.authoringtool.util.GUIFactory.getHTMLStringForComponent(
                      currentComponent)
                  + componentStrikeEnd
                  + "</td>\n");
        }
        toWriteTo.append("</tr>\n");
      }
      if (ifElse.elseComponentPanel.getElementComponentCount() == 0) {
        if (!edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
            .IS_JAVA) {
          styleString =
              " style=\"border-right: 1 solid "
                  + borderColorString
                  + "; border-bottom: 1 solid "
                  + borderColorString
                  + "\"";
        } else {
          styleString = " style=\"border-right: 1 solid " + borderColorString + "\"";
        }
        toWriteTo.append(
            "<td colspan=\""
                + (colSpan - 1)
                + "\""
                + colorString
                + styleString
                + ">"
                + strikeStart
                + "<i> Do Nothing </i>"
                + strikeEnd
                + "</td>\n</tr>\n");
      }
    }
    if (edu.cmu.cs.stage3.alice.authoringtool.editors.compositeeditor.CompositeElementEditor
        .IS_JAVA) {
      styleString =
          " style=\"border-left: 1 solid "
              + borderColorString
              + "; border-bottom: 1 solid "
              + borderColorString
              + "; border-right: 1 solid "
              + borderColorString
              + "\"";
      toWriteTo.append(
          "<tr><td colspan=\""
              + colSpan
              + "\""
              + colorString
              + styleString
              + ">"
              + strikeStart
              + "<b>&nbsp;&nbsp;}</b>"
              + strikeEnd
              + "</td></tr>");
    }
    // toWriteTo.append("</tr>\n");
  }
Exemple #10
0
 protected java.awt.Color getCustomBackgroundColor() {
   return edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getColor("LoopNInOrder");
 }
 protected void updateNativeComponent() {
   String text =
       edu.cmu.cs.stage3.alice.authoringtool.AuthoringToolResources.getReprForValue(
           property.get(), property, property.getOwner().data);
   styleLabel.setText(text);
 }