Package org.nlogo.api

Examples of org.nlogo.api.Shape


    }
  }

  // Import shapes from another model
  private void importSelectedShapes() {
    Shape shape;
    String name;
    Object[] choices = {"Replace", "Rename", I18N.guiJ().get("common.buttons.cancel")};
    int[] selected = list.getSelectedIndices();
    ArrayList<Shape> shapesToAdd = new ArrayList<Shape>();

    // For each selected shape, add it to the current model's file and the turtledrawer,
    for (int i = 0; i < selected.length; ++i) {
      shape = list.getShape(selected[i]);

      // If the shape exists, give the user the chance to overwrite or rename
      while (manager.shapesList().exists(shape.getName())) {
        int choice = javax.swing.JOptionPane.showOptionDialog
            (this,
                "A shape with the name \"" + shape.getName() + "\" already exists in this model.\n" +
                    "Do you want to replace the existing shape or rename the imported one?",
                "Import",
                javax.swing.JOptionPane.YES_NO_CANCEL_OPTION,
                javax.swing.JOptionPane.WARNING_MESSAGE, null,
                choices, choices[0]);

        if (choice == 0) // overwrite
        {
          shapesToAdd.add(shape);
          break;
        } else if (choice == 1) // rename
        {
          name = javax.swing.JOptionPane.showInputDialog
              (this, "Import shape as:", "Import Shapes", javax.swing.JOptionPane.PLAIN_MESSAGE);
          // if the user cancels the inputdialog, then name could
          // be null causing a nullpointerexception later on
          if (name != null) {
            shape.setName(name);
          }
        } else {
          return;
        }
      }
View Full Code Here


    for (int i = 0; i < selected.length; ++i)      // Remove the selected shapes from the model
    {
      // Don't delete the default turtle
      if (!ShapeList.isDefaultShapeName(shapes.get(selected[i]).getName())) {
        Shape shape = shapes.get(selected[i]);
        deletedShapes.add(shape);
        removeShape(shape);
      }
    }
View Full Code Here

    return deletedShapes;
  }

  void addShape(Shape shape) {
    if (shape != null) {
      Shape replacedShape = shapeList.add(shape);
      if (shapeChangeListener != null) {
        shapeChangeListener.shapeChanged
            (replacedShape == null ? shape : replacedShape);
      }
    }
View Full Code Here

      }
    }
  }

  void removeShape(Shape shape) {
    Shape removedShape = shapeList.removeShape(shape);
    if (removedShape != null && shapeChangeListener != null) {
      shapeChangeListener.shapeRemoved(shape);
      shapeChangeListener.shapeChanged(removedShape);
    }
  }
View Full Code Here

TOP

Related Classes of org.nlogo.api.Shape

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.