Пример #1
0
  void saveShape() {
    String nameStr;
    // Make sure the shape has a name
    if (name.getText().equals("")) {
      nameStr =
          javax.swing.JOptionPane.showInputDialog(
              this, "Name:", "Name Shape", javax.swing.JOptionPane.PLAIN_MESSAGE);
      if (nameStr == null) {
        return;
      }
    } else {
      nameStr = name.getText();
    }

    nameStr = nameStr.toLowerCase();

    shape.setName(nameStr);

    String originalName = originalShape.getName();
    // If this is an attempt to overwrite a shape, prompt for
    // permission to do it
    if (list.exists(nameStr)
        && !nameStr.equals(originalName)
        && javax.swing.JOptionPane.YES_OPTION
            != javax.swing.JOptionPane.showConfirmDialog(
                this,
                "A shape with this name already exists. Do you want to replace it?",
                "Confirm Overwrite",
                javax.swing.JOptionPane.YES_NO_OPTION)) {
      return;
    }

    double cv = 0;
    String str = curviness.getText();

    while (str != null) {
      try {
        cv = Double.parseDouble(str);
        str = null;
      } catch (NumberFormatException e) {
        str =
            javax.swing.JOptionPane.showInputDialog(
                this, "Curviness:", "Enter a number", javax.swing.JOptionPane.PLAIN_MESSAGE);
      }
    }

    shape.curviness(cv);
    for (int i = 0; i < dashes.length; i++) {
      int index = dashes[i].getSelectedIndex();
      shape.setLineVisible(i, index != 0);
      shape.setDashiness(i, org.nlogo.shape.LinkLine.dashChoices[index]);
    }

    list.update(originalShape, shape);
    dispose();
  }
Пример #2
0
 private LinkShape getCurrentShape() {
   LinkShape currentShape = (LinkShape) shape.clone();
   currentShape.setName(name.getText());
   currentShape.curviness(Double.parseDouble(curviness.getText()));
   for (int i = 0; i < dashes.length; i++) {
     int index = dashes[i].getSelectedIndex();
     currentShape.setLineVisible(i, index != 0);
     currentShape.setDashiness(i, org.nlogo.shape.LinkLine.dashChoices[index]);
   }
   return currentShape;
 }