Package cranks.geom

Examples of cranks.geom.GeometricalObject


    DefaultMutableTreeNode object = null;
    DefaultMutableTreeNode field = null;
    DefaultMutableTreeNode subField = null;
    Vector<GeometricalObject> assocObjects;
    for (int i = 0; i<objects.size(); i++) {
      GeometricalObject o = objects.elementAt(i);
      if (o.getType() == type) {//should be added to top
        object = new DefaultMutableTreeNode(String.valueOf(o.getNumber()));
        top.add(object);

        switch (type) {
          case 2: //point
            Point p = ((Point)o);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("X Co-ordinate", p.getX()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Y Co-ordinate", p.getY()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Visibility", p.isVisible()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("AssociatedObjects", "Empty"));
            object.add(field);
            assocObjects = p.getAssocObjects();
            for (int j = 0; j<assocObjects.size(); j++) {
              GeometricalObject ob = assocObjects.elementAt(j);
              subField = new DefaultMutableTreeNode(
                new FieldInfo(Integer.toString(ob.getNumber()), ob));
              field.add(subField);
            }
          break;
          case 3: //line
            Line l = ((Line)o);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Start Point", l.getStart()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("End Point", l.getEnd()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Slope (Degrees)",
                                    Math.toDegrees(l.getSlope().getAngle())));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Length", l.getLength()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("Visibility", l.isVisible()));
            object.add(field);
            field = new DefaultMutableTreeNode(
                      new FieldInfo("AssociatedObjects", "Empty"));
            object.add(field);
            assocObjects = l.getAssocObjects();
            for (int j = 0; j<assocObjects.size(); j++) {
              GeometricalObject ob = assocObjects.elementAt(j);
              subField = new DefaultMutableTreeNode(
                new FieldInfo(Integer.toString(ob.getNumber()), ob));
              field.add(subField);
            }
          break;
          case 4:
            Circle c = ((Circle)o);
View Full Code Here


      Point tempPoint = (Point)step.getInputs()[2];
      tempPoint.setCoordinates(((Double)step.getInputs()[3]).doubleValue(),
                         ((Double)step.getInputs()[4]).doubleValue());
      Vector<GeometricalObject> assocObjects = tempPoint.getAssocObjects();
      for (int i = 0; i<assocObjects.size(); i++) {
        GeometricalObject o = assocObjects.elementAt(i);
        if (o.getType() == Line.TYPE)
          ((Line)o).setLengthAndSlope();
      }
      clearAndHide();
      step.setOutputs(new Object[]{tempPoint});
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
View Full Code Here

      Point tempPoint = (Point)step.getInputs()[2];
      tempPoint.setCoordinates(((Double)step.getInputs()[0]).doubleValue(),
                         ((Double)step.getInputs()[1]).doubleValue());
      Vector<GeometricalObject> assocObjects = tempPoint.getAssocObjects();
      for (int i = 0; i<assocObjects.size(); i++) {
        GeometricalObject o = assocObjects.elementAt(i);
        if (o.getType() == Line.TYPE)
          ((Line)o).setLengthAndSlope();
      }
    }
    else {
      System.err.println("Bad construction type");
View Full Code Here

      Point tempPoint = (Point)step.getInputs()[2];
      tempPoint.setCoordinates(((Double)step.getInputs()[3]).doubleValue(),
                         ((Double)step.getInputs()[4]).doubleValue());
      Vector<GeometricalObject> assocObjects = tempPoint.getAssocObjects();
      for (int i = 0; i<assocObjects.size(); i++) {
        GeometricalObject o = assocObjects.elementAt(i);
        if (o.getType() == Line.TYPE)
          ((Line)o).setLengthAndSlope();
      }
    }
    else {
      System.err.println("Bad construction type");
View Full Code Here

      ConstructionStep step = new ConstructionStep(this, visibilityToggled,
                                                    HIDE_OBJECT);
      doConstruction(step);
    }
    if (tabbedPane.getSelectedComponent() == pRemoveObject) {
      GeometricalObject ob = (GeometricalObject)cRemoveObject.getSelectedItem();
      ConstructionStep step = new ConstructionStep(this, new Object[]{ob},
                                                    REMOVE_OBJECT);
      doConstruction(step);
    }
  }
View Full Code Here

      clearAndHide();
      step.setOutputs(visibilityToggled);
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
    }
    else if (step.getConstructionType() == REMOVE_OBJECT) {
      GeometricalObject ob = (GeometricalObject)step.getInputs()[0];
      ob.removeFromObjects(objects);
      for (int i = 0; i<objects.size(); i++)
        objects.elementAt(i).setNumber(i+1);
      clearAndHide();
      step.setOutputs(new Object[]{});
      fireIrreversibleEditUpdate();
View Full Code Here

    //check if the point is over an object
    clickable = false;
    String toolTipText = "<HTML>";
    if (getMode(OPERATION) == OPERATING_MODE_DRAWING) {
      for (int i = 0; i<objects.size(); i++) {
        GeometricalObject ob = objects.elementAt(i);
        if (ob.isVisible() && mousePosition.canClick(ob))
          toolTipText += (ob.toString() + "<P>");
      }
    }
    if (toolTipText.equalsIgnoreCase("<HTML>"))
      toolTipText = null;
    else
View Full Code Here

            mousePosition = new cranks.geom.Point();
            //check if num of clicks so far is equal to num of points
            //needed to draw object of type specified in mouseMode
            if (mouseClickCounter == mouseMode) {
              //create the object and add it to objects vector
              GeometricalObject objectToBeAdded = null;
              ConstructionStep step = null;
              switch (mouseMode) {
                case MOUSE_MODE_POINT:
                  objectToBeAdded = mouseClicks[0];
                  step = new ConstructionStep(this,
                              new Object[]{objectToBeAdded}, POINT);
                break;

                case MOUSE_MODE_LINE:
                  objectToBeAdded = new Line(mouseClicks[0], mouseClicks[1]);
                  step = new ConstructionStep(this,
                              new Object[]{objectToBeAdded}, LINE);
                break;

                case MOUSE_MODE_TRIANGLE:
                  objectToBeAdded = new Triangle(mouseClicks[0], mouseClicks[1],
                                                 mouseClicks[2]);
                  step = new ConstructionStep(this,
                              new Object[]{objectToBeAdded}, TRIANGLE);
                break;
                default :
              }
              doConstruction(step);
              mouseClickCounter = 0;
            }
          }
        }
        //check for right clicks and bring up popup menu
        if ((getMode(OPERATION) == OPERATING_MODE_DRAWING)
            && (e.getButton()==3) && allowRightClicks) {
          for(int i = 0; i < popMenu.getComponentCount(); i++)
            if (i >= 4)
              popMenu.remove(i);
         
          boolean[] selectedTypes = new boolean[4];
          Arrays.fill(selectedTypes, false);
          //check if the point is over an object
          if (clickable) {
            for (int i = 0; i<objects.size(); i++) {
              GeometricalObject ob = objects.elementAt(i);
              if (mousePosition.canClick(ob)) {
                selectedTypes[ob.getType() - 2] = true;
              }
            }
            for (int i = 0; i<4; i++) {
              if (selectedTypes[i]) {
                popMenu.add(popSubMenu[i]);
View Full Code Here

  public void enablePopupMenu(boolean value) {
    allowRightClicks = value;
  }

  public void doConstruction(ConstructionStep step) {
    GeometricalObject objectToBeAdded = (GeometricalObject)step.getInputs()[0];
    objectToBeAdded.addToObjects(objects);
    if (step.getConstructionType() == POINT) {
      cranks.geom.Point p = (cranks.geom.Point)objectToBeAdded;
      step.setOutputs(new Object[]{p});
      fireUndoableEditUpdate(new UndoableEditEvent(this, step));
    }
View Full Code Here

  public void clearAndHide() {
    dispose();
  }

  private void intersectObjects() {
    GeometricalObject object1 = (GeometricalObject)cObject1.getSelectedItem();
    GeometricalObject object2 = (GeometricalObject)cObject2.getSelectedItem();
    ConstructionStep step;
    if ((object1 instanceof Line) && (object2 instanceof Line))
      step = new ConstructionStep(this, new Object[]{object1,
                                                    object2}, INTERSECT_ONE_POINT);
    else
View Full Code Here

TOP

Related Classes of cranks.geom.GeometricalObject

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.