|
@@ -0,0 +1,74 @@
|
|
|
+package model;
|
|
|
+
|
|
|
+import java.awt.*;
|
|
|
+
|
|
|
+
|
|
|
+ * @author duh
|
|
|
+ * @create 2018/7/18 18:58
|
|
|
+ * @email duh@elab-plus.com
|
|
|
+ **/
|
|
|
+public class Axis extends ModuleInAxis {
|
|
|
+ private int xLength;
|
|
|
+ private int yLength;
|
|
|
+ private int xSpacing;
|
|
|
+ private int ySpacing;
|
|
|
+ private int spacingLength = 5;
|
|
|
+ @Override
|
|
|
+ public void drawSelf(Graphics g) {
|
|
|
+ System.out.println("begin to draw axis");
|
|
|
+ Graphics2D g2d = (Graphics2D) g.create();
|
|
|
+ g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
|
|
+ g2d.setColor(Color.RED);
|
|
|
+ int axisX = x;
|
|
|
+ int axisY = y;
|
|
|
+ g2d.drawString("0",axisX,axisY+10);
|
|
|
+ drawXAxis(axisX,axisY,xLength,g2d);
|
|
|
+ drawYAxis(axisX,axisY,yLength,g2d);
|
|
|
+ g2d.dispose();
|
|
|
+ }
|
|
|
+ private void drawXAxis(int x1, int y1, int length, Graphics2D g2d){
|
|
|
+ g2d.drawLine(x1,y1,x1+length,y1);
|
|
|
+ int xNumber = length/xSpacing;
|
|
|
+ for(int i = 1;i<xNumber;i++){
|
|
|
+ g2d.drawLine(x1+i*xSpacing,y1,x1+i*xSpacing,y1+spacingLength);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ private void drawYAxis(int x1, int y1, int length, Graphics2D g2d){
|
|
|
+ g2d.drawLine(x1,y1,x1,y1-length);
|
|
|
+ int yNumber = length/ySpacing;
|
|
|
+ for(int i = 1;i<yNumber;i++){
|
|
|
+ g2d.drawLine(x1,y1-i*ySpacing,x1-spacingLength,y1-i*ySpacing);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ public int getxLength() {
|
|
|
+ return xLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setxLength(int xLength) {
|
|
|
+ this.xLength = xLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getyLength() {
|
|
|
+ return yLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setyLength(int yLength) {
|
|
|
+ this.yLength = yLength;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getxSpacing() {
|
|
|
+ return xSpacing;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setxSpacing(int xSpacing) {
|
|
|
+ this.xSpacing = xSpacing;
|
|
|
+ }
|
|
|
+
|
|
|
+ public int getySpacing() {
|
|
|
+ return ySpacing;
|
|
|
+ }
|
|
|
+
|
|
|
+ public void setySpacing(int ySpacing) {
|
|
|
+ this.ySpacing = ySpacing;
|
|
|
+ }
|
|
|
+}
|