Search in sources :

Example 6 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class LineObjectGUI method drawMathObject.

public void drawMathObject(LineObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(sap.getLineThickness()));
    GridPoint[] points = object.getAdjustedVertices();
    for (int i = 0; i < points.length; i++) {
        points[i] = new GridPoint((int) (points[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (points[i].gety() * sap.getHeight()) + sap.getyOrigin());
    }
    // TODO - Implements snapping to vertical or horizontal, this should probably be in the back-end
    if (Math.abs(points[0].getx() - points[1].getx()) < 5) {
        points[0].setx(points[1].getx());
    } else if (Math.abs(points[0].gety() - points[1].gety()) < 5) {
        points[0].sety(points[1].gety());
    }
    if (object.getLineColor() == null) {
        g.setColor(Color.BLACK);
    } else {
        g.setColor(object.getLineColor());
    }
    g2d.drawLine((int) points[0].getx(), (int) points[0].gety(), (int) points[1].getx(), (int) points[1].gety());
    g2d.setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) GridPoint(doc.GridPoint) GridPoint(doc.GridPoint) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 7 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class PolygonObjectGUI method drawMathObject.

public void drawMathObject(PolygonObject object, Graphics g, Point pageOrigin, float zoomLevel) {
    g.setColor(Color.BLACK);
    ScaledSizeAndPosition sap = getSizeAndPositionWithLineThickness(object, pageOrigin, zoomLevel, object.getThickness());
    Graphics2D g2d = (Graphics2D) g;
    g2d.setStroke(new BasicStroke(sap.getLineThickness()));
    Polygon p = new Polygon();
    GridPoint[] points = object.getAdjustedVertices();
    for (int i = 0; i < points.length; i++) {
        p.addPoint((int) (points[i].getx() * sap.getWidth()) + sap.getxOrigin(), (int) (points[i].gety() * sap.getHeight()) + sap.getyOrigin());
    }
    if (object.getColor() != null) {
        g2d.setColor(object.getColor());
        g2d.fillPolygon(p);
        g2d.setColor(Color.BLACK);
    }
    g2d.drawPolygon(p);
    g2d.setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) GridPoint(doc.GridPoint) Polygon(java.awt.Polygon) GridPoint(doc.GridPoint) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Example 8 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class LineGraph method draw.

@Override
public void draw(Graphics g) {
    //used to temporarily store the value stored in the independent and dependent vars,
    //this will allow it to be restored after graphing, so that if in the terminal a
    //value was assigned to x, it will not be overriden by the action of graphing
    //		Number xVal = getIndependentVar().getValue();
    //		Number yVal = getDependentVar().getValue();
    super.clearPts();
    Graphics2D g2d = ((Graphics2D) g);
    g.setColor(getColor());
    if (hasFocus()) {
        graph.LINE_SIZE = 3;
    } else {
        graph.LINE_SIZE = 2;
    }
    double lastX = 0, lastY = 0, currX = 0, currY = 0;
    if (!linePoints.isEmpty()) {
        lastX = linePoints.get(0).getx();
        lastY = linePoints.get(0).gety();
    }
    for (GridPoint pt : linePoints) {
        currX = pt.getx();
        currY = pt.gety();
        if (gridxToScreen(currX) <= graph.X_SIZE + graph.X_PIC_ORIGIN && gridxToScreen(currX) >= graph.X_PIC_ORIGIN && gridyToScreen(currY) <= graph.Y_SIZE + graph.Y_PIC_ORIGIN && gridyToScreen(currY) >= graph.Y_PIC_ORIGIN) {
            //if the current point is on the screen, add it to the list of points
            if (lastY <= graph.Y_MIN) {
                addPt(gridxToScreen(lastX), graph.Y_SIZE + graph.Y_PIC_ORIGIN);
            }
            if (lastY >= graph.Y_MAX) {
                addPt(gridxToScreen(lastX), 0 + graph.Y_PIC_ORIGIN);
            }
            addPt(gridxToScreen(currX), gridyToScreen(currY));
        } else if (gridxToScreen(lastX) <= graph.X_SIZE + graph.X_PIC_ORIGIN && gridxToScreen(lastX) >= graph.X_PIC_ORIGIN && gridyToScreen(lastY) <= graph.Y_SIZE + graph.Y_PIC_ORIGIN && gridyToScreen(lastY) >= graph.Y_PIC_ORIGIN) {
            //if the last point is on the screen, add the correct boundary for this point to the list
            addPt(gridxToScreen(lastX), gridyToScreen(lastY));
            if (currY <= graph.Y_MIN) {
                addPt(gridxToScreen(currX), graph.Y_SIZE + graph.Y_PIC_ORIGIN);
            }
            if (currY >= graph.Y_MAX) {
                addPt(gridxToScreen(currX), 0 + graph.Y_PIC_ORIGIN);
            }
        } else if (lastY >= graph.Y_MAX && currY <= graph.Y_MIN) {
            //if the last point was off the the top of the screen, and this one is off
            //the bottom, add the two to the list of points
            addPt(gridxToScreen(lastX), graph.Y_SIZE + graph.Y_PIC_ORIGIN);
            addPt(gridxToScreen(currX), 0 + graph.Y_PIC_ORIGIN);
        } else if (currY >= graph.Y_MAX && lastY <= graph.Y_MIN) {
            //if the last point was off the the bottom of the screen, and this one is off
            //the top, add the two to the list of points
            addPt(gridxToScreen(lastX), 0 + graph.Y_PIC_ORIGIN);
            addPt(gridxToScreen(currX), graph.Y_SIZE + graph.Y_PIC_ORIGIN);
        }
        drawLineSeg(lastX, lastY, currX, currY, getColor(), g);
        lastX = currX;
        lastY = currY;
    }
    //		g2d.setStroke(new BasicStroke(graph.LINE_SIZE * graph.DOC_ZOOM_LEVEL,
    //				BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND));
    //		if ( this.getxVals().size() > 0){
    //			GeneralPath polyline = 
    //					new GeneralPath(GeneralPath.WIND_EVEN_ODD, this.getxVals().size());
    //			polyline.moveTo (this.getxVals().get(0), this.getyVals().get(0));
    //			for (int i = 1; i < this.getxVals().size(); i++) {
    //				polyline.lineTo( getxVals().get(i), getyVals().get(i));
    //			};
    //			g2d.draw(polyline);
    //		}
    graph.LINE_SIZE = 2;
    g2d.setStroke(new BasicStroke(1));
}
Also used : BasicStroke(java.awt.BasicStroke) GridPoint(doc.GridPoint) Graphics2D(java.awt.Graphics2D)

Example 9 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class MathObject method flipVertically.

protected GridPoint[] flipVertically(GridPoint[] points) {
    GridPoint[] flipped = new GridPoint[points.length];
    int i = 0;
    for (GridPoint p : points) {
        flipped[i] = flipPointVertically(p);
        i++;
    }
    return flipped;
}
Also used : GridPoint(doc.GridPoint) GridPoint(doc.GridPoint)

Example 10 with GridPoint

use of doc.GridPoint in project OpenNotebook by jaltekruse.

the class PolygonObjectGUI method getCollisionAndSelectionPolygon.

public Polygon getCollisionAndSelectionPolygon(PolygonObject pObject, Point pageOrigin, float zoomLevel) {
    ScaledSizeAndPosition sap = getSizeAndPosition(pObject, pageOrigin, zoomLevel);
    GridPoint[] pts = pObject.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);
}
Also used : GridPoint(doc.GridPoint) Polygon(java.awt.Polygon) GridPoint(doc.GridPoint) Point(java.awt.Point)

Aggregations

GridPoint (doc.GridPoint)15 Point (java.awt.Point)8 BasicStroke (java.awt.BasicStroke)5 Graphics2D (java.awt.Graphics2D)5 Polygon (java.awt.Polygon)5 GridPointAttribute (doc.attributes.GridPointAttribute)2 Color (java.awt.Color)2 DoubleAttribute (doc.attributes.DoubleAttribute)1 StringAttribute (doc.attributes.StringAttribute)1 GraphedCartFunction (doc_gui.graph.GraphedCartFunction)1 Selection (doc_gui.graph.Selection)1 NodeException (expression.NodeException)1 FontMetrics (java.awt.FontMetrics)1 StringTokenizer (java.util.StringTokenizer)1