use of doc.GridPoint in project OpenNotebook by jaltekruse.
the class PolygonObjectGUI method drawInteractiveComponents.
public void drawInteractiveComponents(PolygonObject object, Graphics g, Point pageOrigin, float zoomLevel) {
drawMathObject(object, g, pageOrigin, zoomLevel);
// This is currently unused, this is an alternative to commenting out the code that makes sure it keeps compiling
if (false) {
ScaledSizeAndPosition sap = getSizeAndPosition(object, pageOrigin, zoomLevel);
GridPoint[] pts = object.getAdjustedVertices();
for (int i = 0; i < pts.length; i++) {
g.setColor(Color.YELLOW);
g.fillOval((int) (pts[i].getx() * sap.getWidth()) + sap.getxOrigin() - dotRadius, (int) (pts[i].gety() * sap.getWidth()) + sap.getyOrigin() - dotRadius, 2 * dotRadius, 2 * dotRadius);
g.setColor(Color.BLACK);
g.drawOval((int) (pts[i].getx() * sap.getWidth()) + sap.getxOrigin() - dotRadius, (int) (pts[i].gety() * sap.getHeight()) + sap.getyOrigin() - dotRadius, 2 * dotRadius, 2 * dotRadius);
}
}
}
use of doc.GridPoint in project OpenNotebook by jaltekruse.
the class ConeObjectGUI method drawMathObject.
public void drawMathObject(ConeObject object, Graphics g, Point pageOrigin, float zoomLevel) {
g.setColor(Color.BLACK);
ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
Graphics2D g2d = (Graphics2D) g;
Color fillColor = object.getColor();
Polygon fillShape;
GridPoint[] translated = new GridPoint[3];
int i = 0;
for (GridPoint p : object.getTrianglePts()) {
if (object.isFlippedVertically()) {
translated[i] = object.flipPointVertically(p);
} else {
translated[i] = p.clone();
}
i++;
}
if (fillColor != null) {
fillShape = new Polygon();
fillShape.addPoint((int) (translated[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[0].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin());
fillShape.addPoint((int) (translated[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[2].gety() * sap.getHeight()) + sap.getyOrigin());
g2d.setColor(fillColor);
g2d.fillPolygon(fillShape);
g2d.setColor(MathObjectGUI.brightenColor(fillColor));
if (object.isFlippedVertically()) {
g2d.fillOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getInsideEdgeOfDisk().gety() * sap.getHeight()));
} else {
g2d.fillOval(sap.getxOrigin(), (int) (object.getPointBehindCone().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
}
}
g2d.setStroke(new BasicStroke(sap.getLineThickness(), BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
g2d.setColor(Color.BLACK);
g.drawLine((int) (translated[0].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[0].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin());
g.drawLine((int) (translated[1].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[1].gety() * sap.getHeight()) + sap.getyOrigin(), (int) (translated[2].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (translated[2].gety() * sap.getHeight()) + sap.getyOrigin());
if (object.isFlippedVertically()) {
g.drawOval(sap.getxOrigin(), sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
} else {
g.drawOval(sap.getxOrigin(), (int) (object.getPointBehindCone().gety() * sap.getHeight()) + sap.getyOrigin(), sap.getWidth(), (int) (object.getHalfDiskHeight() * sap.getHeight()));
}
g2d.setStroke(new BasicStroke(1));
}
use of doc.GridPoint in project OpenNotebook by jaltekruse.
the class GraphObjectGUI method drawMathObject.
public void drawMathObject(GraphObject object, Graphics g, Point pageOrigin, float zoomLevel) {
ScaledSizeAndPosition sap = getSizeAndPosition(object, pageOrigin, zoomLevel);
graph.removeAllSingleGraphs();
graph.removeAllPoints();
int colorIndex = 0;
boolean hadError = false;
for (StringAttribute ex : object.getExpressions()) {
if (!ex.getValue().equals("")) {
try {
graph.AddGraph(new GraphedCartFunction(graph, "y=" + ex.getValue(), "x", "y", true, graphColors[colorIndex]));
} catch (NodeException e) {
// TODO Auto-generated catch block
hadError = true;
}
}
colorIndex++;
}
//graph.lineGraph.linePoints = object.getPoints();
graph.lineGraph.linePoints.removeAllElements();
graph.removeAllPoints();
for (GridPointAttribute pt : object.getPoints()) {
if (pt != null) {
graph.addPoint(pt.getValue().getx(), pt.getValue().gety());
}
}
graph.barGraph.values.removeAllElements();
for (DoubleAttribute d : object.getBarGraphValues().getValues()) {
graph.barGraph.values.add(d.getValue());
}
graph.barGraph.labels.removeAllElements();
for (StringAttribute strAttr : object.getBarGraphLabels().getValues()) {
graph.barGraph.labels.add(strAttr.getValue());
}
graph.barGraph.groupSize = object.getBarGraphGroupSize();
graph.lineGraph.setColor(object.getLineGraphColor());
synchronized (object.getLineGraphPoints().getValues()) {
for (GridPointAttribute pt : object.getLineGraphPoints().getValues()) {
if (pt != null) {
graph.lineGraph.linePoints.add(new GridPoint(pt.getValue().getx(), pt.getValue().gety()));
}
}
}
graph.repaint(g, sap.getWidth(), sap.getHeight(), zoomLevel, sap.getxOrigin(), sap.getyOrigin(), object);
if (hadError) {
FontMetrics fm = g.getFontMetrics();
int errorWidth = fm.stringWidth("error");
g.setColor(Color.WHITE);
g.fillRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
g.setColor(Color.BLACK);
g.drawRect((sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2, (sap.getyOrigin() + sap.getHeight() / 2) - fm.getHeight() / 2, errorWidth + 4, fm.getHeight() + 4);
g.setColor(Color.RED);
g.drawString("error", (sap.getxOrigin() + sap.getWidth() / 2) - errorWidth / 2 + 2, (sap.getyOrigin() + sap.getHeight() / 2) + fm.getHeight() / 2);
}
}
use of doc.GridPoint in project OpenNotebook by jaltekruse.
the class GraphObjectGUI method mouseClicked.
public void mouseClicked(GraphObject gObj, int x, int y, float zoomLevel) {
// and cannot be removed
if (false) {
// deliberately disabled, but this makes sure this code is still compiling (as commenting out would not do
//add a point to the graph
gObj.getPoints().add(new GridPointAttribute("", new GridPoint(graph.screenxToGrid(x), -1 * graph.screenyToGrid(y))));
// add a single x value "selection"
graph.pullVarsFromGraphObject(gObj, (int) (gObj.getWidth() * zoomLevel), (int) (gObj.getHeight() * zoomLevel));
((Selection) gObj.getAttributeWithName(GraphObject.SELECTION).getValue()).setStart(graph.screenxToGrid(x));
}
return;
}
use of doc.GridPoint in project OpenNotebook by jaltekruse.
the class LineObjectGUI method getCollisionAndSelectionPolygon.
public Polygon getCollisionAndSelectionPolygon(LineObject line, Point pageOrigin, float zoomLevel) {
ScaledSizeAndPosition sap = getSizeAndPosition(line, pageOrigin, zoomLevel);
GridPoint[] pts = line.getAdjustedVertices();
int[] xVals = new int[pts.length];
int[] yVals = new int[pts.length];
int i = 0;
for (GridPoint pt : pts) {
xVals[i] = (int) (pt.getx() * sap.getWidth()) + sap.getxOrigin();
yVals[i] = (int) (pt.gety() * sap.getHeight()) + sap.getyOrigin();
i++;
}
return new Polygon(xVals, yVals, pts.length);
}
Aggregations