Exemplo n.º 1
0
  public static void setEntity(Plan ent, Map attributes) {
    Map currentMap =
        (Map) RenderComponentManager.retrieveIDs("Plan", ent.getPrefs(attributes).getView());
    current = ent.getPrefs(attributes).getView();
    if (ent != null
        && currentMap.get("_attributes_") != null
        && currentMap.get("_attributes_") instanceof ingenias.editor.rendererxml.AttributesPanel) {

      ((ingenias.editor.rendererxml.AttributesPanel) currentMap.get("_attributes_")).setEntity(ent);
    }

    if (currentMap.get("Tasks") != null
        && currentMap.get("Tasks") instanceof ingenias.editor.rendererxml.CollectionPanel) {
      try {
        ((ingenias.editor.rendererxml.CollectionPanel) currentMap.get("Tasks"))
            .setCollection("Tasks", ent.Tasks, ent.Tasks.getType());
      } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
      } catch (IllegalAccessException ex) {
        ex.printStackTrace();
      }
    }

    if (currentMap.get("Tasks") != null
        && currentMap.get("Tasks") instanceof ingenias.editor.rendererxml.CollectionPanel) {
      try {
        ((ingenias.editor.rendererxml.CollectionPanel) currentMap.get("Tasks"))
            .setCollection("Tasks", ent.Tasks, ent.Tasks.getType());
      } catch (IllegalArgumentException ex) {
        ex.printStackTrace();
      } catch (IllegalAccessException ex) {
        ex.printStackTrace();
      }
    }

    if (currentMap.get("Tasks") != null) {
      if (ent != null && ent.getTasks() != null) {
        if (currentMap.get("Tasks") instanceof javax.swing.JLabel) {
          ((javax.swing.JLabel) (currentMap).get("Tasks")).setText(ent.getTasks().toString());
        } else {
          if (currentMap.get("Tasks") instanceof javax.swing.text.JTextComponent)
            ((javax.swing.text.JTextComponent) (currentMap).get("Tasks"))
                .setText(ent.getTasks().toString());
        }
      } else {
        if (currentMap.get("Tasks") instanceof javax.swing.JLabel)
          ((javax.swing.JLabel) (currentMap).get("Tasks")).setText("");
        else {
          if (!(currentMap.get("Tasks") instanceof ingenias.editor.rendererxml.CollectionPanel))
            ((javax.swing.text.JTextComponent) (currentMap).get("Tasks")).setText("");
        }
      }
    }

    if (currentMap.get("Id") != null) {
      if (ent != null && ent.getId() != null) {
        if (currentMap.get("Id") instanceof javax.swing.JLabel) {
          ((javax.swing.JLabel) (currentMap).get("Id")).setText(ent.getId().toString());
        } else {
          if (currentMap.get("Id") instanceof javax.swing.text.JTextComponent)
            ((javax.swing.text.JTextComponent) (currentMap).get("Id"))
                .setText(ent.getId().toString());
        }
      } else {
        if (currentMap.get("Id") instanceof javax.swing.JLabel)
          ((javax.swing.JLabel) (currentMap).get("Id")).setText("");
        else {
          if (!(currentMap.get("Id") instanceof ingenias.editor.rendererxml.CollectionPanel))
            ((javax.swing.text.JTextComponent) (currentMap).get("Id")).setText("");
        }
      }
    }
  }
  // ===========When a mouse is pressed=======
  public void mousePressed(MouseEvent e) {

    clickedX = e.getX();
    clickedY = e.getY();

    xPixelRelative = clickedX - xStartHoriz;
    yPixelRelative = clickedY - margin;

    float resultClicked;

    // Determinate the biggest and the smallest x value
    double smallestXvalue = abscissae[0];
    double biggestXvalue = abscissae[0];

    // Converting pixel values into expression values
    for (double xValue : abscissae) {
      if (xValue > biggestXvalue) biggestXvalue = xValue;
      if (xValue < smallestXvalue) smallestXvalue = xValue;
    }

    double xValueRange = biggestXvalue - smallestXvalue;
    double xPixelRange = 268; // =xAxisLength;	

    double xPixelPercent = (xPixelRelative - smallestXvalue) / xPixelRange;
    float xValueClicked = (float) (xValueRange * xPixelPercent);

    try {
      // Determine the corresponding y based on the given function and the x resulting from
      // pixel-to-value conversion
      resultClicked =
          ComplexExpressionCalculator.evaluateExpression(function, String.valueOf(xValueClicked));
    } catch (IllegalArgumentException iae) {
      JOptionPane.showMessageDialog(
          this, "" + iae.getMessage() + "", "Error", JOptionPane.ERROR_MESSAGE);
      return;
    }

    // Limit decimal points
    displayableX = String.format("%.02f", xValueClicked);
    displayableY = String.format("%.02f", resultClicked);

    if (e.getSource() == window) {
      if (clickedX >= 2 && xPixelRelative <= 270 && yPixelRelative >= 28 && yPixelRelative <= 340) {
        System.out.println(
            "The mouse clicked at pixel x="
                + xPixelRelative
                + " based on xy reference. Originally it's at pixel x= "
                + e.getX());
        System.out.println(
            "The mouse clicked at pixel y="
                + yPixelRelative
                + " based on xy reference. Originally it's at pixel y= "
                + e.getY());

        coordinatesLabel.setText("For x=" + displayableX + ", y=" + displayableY + " on the curve");
        popUpPanel.add(coordinatesLabel, "North");
        popUpWindow.getContentPane().add(popUpPanel, "Center");
        popUpWindow.setSize(300, 70);
        popUpWindow.setLocation(100 + clickedX, 200 + yPixelRelative);
        popUpWindow.setTitle("Figure Coordinates");
        popUpWindow.setVisible(true);
      } else System.out.println("Clicked outside the prescribed range.");
    }
  }