1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
/**
* Equipment resize state. This states manages the resizing of a equipment.
*/
private class EquipmentResizeState extends ControllerState {
private float deltaXToResizeVertex;
private float deltaYToResizeVertex;
private SlipEquipment selectedPiece;
private float oldX;
private float oldY;
private float oldWidth;
private float oldHeight;
private String centimerResizeToolTipFeedback;
private String inchResizeToolTipFeedback;
@Override
public Mode getMode() {
return Mode.SELECTION;
}
@Override
public void enter() {
this.centimerResizeToolTipFeedback = resource.getString("centimerResizeToolTipFeedback");
this.inchResizeToolTipFeedback = resource.getString("inchResizeToolTipFeedback");
this.selectedPiece = (SlipEquipment)slip.getSelectedItems().get(0);
float [] resizePoint = this.selectedPiece.getGraphicEquipment().getPoints() [2];
this.deltaXToResizeVertex = getXLastMousePress() - resizePoint [0];
this.deltaYToResizeVertex = getYLastMousePress() - resizePoint [1];
this.oldX = this.selectedPiece.getX();
this.oldY = this.selectedPiece.getY();
this.oldWidth = this.selectedPiece.getWidth();
this.oldHeight = this.selectedPiece.getHeight();
PlanComponent planView = (PlanComponent)getView();
planView.setResizeIndicatorVisible(true);
planView.setToolTipFeedback(getToolTipFeedbackText(this.oldWidth, this.oldHeight),
getXLastMousePress(), getYLastMousePress());
}
@Override
public void moveMouse(float x, float y) {
// Compute the new location and dimension of the piece to let
// its bottom right point be at mouse location
float angle = this.selectedPiece.getAngle();
double cos = Math.cos(angle);
double sin = Math.sin(angle);
float [] topLeftPoint = this.selectedPiece.getGraphicEquipment().getPoints() [0];
float deltaX = x - this.deltaXToResizeVertex - topLeftPoint[0];
float deltaY = y - this.deltaYToResizeVertex - topLeftPoint[1];
float newWidth = (float)(deltaY * sin + deltaX * cos);
float newHeight = (float)(deltaY * cos - deltaX * sin);
newWidth = Math.max(Math.round(newWidth * 10f) / 10f, 0.1f);
newHeight = Math.max(Math.round(newHeight * 10f) / 10f, 0.1f);
// Update piece new location
float newX = (float)(topLeftPoint [0] + (newWidth * cos - newHeight * sin) / 2f);
float newY = (float)(topLeftPoint [1] + (newWidth * sin + newHeight * cos) / 2f);
slip.setEquipmentLocation(this.selectedPiece, newX, newY);
// Update piece new dimension
slip.setEquipmentDimension(this.selectedPiece, newWidth, newHeight);
PlanComponent planView = (PlanComponent)getView();
// Ensure point at (x,y) is visible
planView.makePointVisible(x, y);
planView.setToolTipFeedback(getToolTipFeedbackText(newWidth, newHeight), x, y);
}
@Override
public void releaseMouse(float x, float y) {
postEquipmentResize(this.selectedPiece, this.oldX, this.oldY,
this.oldWidth, this.oldHeight);
setState(getSelectionState());
}
@Override
public void escape() {
slip.setEquipmentLocation(this.selectedPiece, this.oldX, this.oldY);
slip.setEquipmentDimension(this.selectedPiece,
this.oldWidth, this.oldHeight);
setState(getSelectionState());
}
@Override
public void exit() {
PlanComponent planView = (PlanComponent)getView();
planView.setResizeIndicatorVisible(false);
planView.deleteToolTipFeedback();
this.selectedPiece = null;
}
} |