forked from fanruan/design
方磊
3 years ago
4 changed files with 211 additions and 146 deletions
@ -0,0 +1,51 @@ |
|||||||
|
package com.fr.design.mainframe; |
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
public abstract class AbstractFormParallelLine { |
||||||
|
protected int parallelValue; |
||||||
|
protected int startPosition; |
||||||
|
protected int endPosition; |
||||||
|
|
||||||
|
public AbstractFormParallelLine(int parallelValue, int startPosition, int endPosition) { |
||||||
|
this.parallelValue = parallelValue; |
||||||
|
this.startPosition = startPosition; |
||||||
|
this.endPosition = endPosition; |
||||||
|
} |
||||||
|
|
||||||
|
public int getCenterPosition() { |
||||||
|
return (startPosition + endPosition) / 2; |
||||||
|
} |
||||||
|
|
||||||
|
abstract public Point getCenterPoint(); |
||||||
|
|
||||||
|
abstract public Point getPerpendicularPoint(int parallelValue); |
||||||
|
|
||||||
|
public boolean isBeforeParallelLine(AbstractFormParallelLine parallelLine) { |
||||||
|
return this.getCenterPosition() < parallelLine.getStartPosition(); |
||||||
|
} |
||||||
|
|
||||||
|
public boolean isBehindParallelLine(AbstractFormParallelLine parallelLine) { |
||||||
|
return this.getCenterPosition() > parallelLine.getEndPosition(); |
||||||
|
} |
||||||
|
|
||||||
|
abstract public Point getExtendedLineStartPoint(AbstractFormParallelLine parallelLine); |
||||||
|
|
||||||
|
abstract public Point getExtendedLineEndPoint(AbstractFormParallelLine parallelLine); |
||||||
|
|
||||||
|
public int getDistanceWithLine(AbstractFormParallelLine parallelLine) { |
||||||
|
return Math.abs(this.getParallelValue() - parallelLine.getParallelValue()); |
||||||
|
} |
||||||
|
|
||||||
|
public int getParallelValue() { |
||||||
|
return parallelValue; |
||||||
|
} |
||||||
|
|
||||||
|
public int getStartPosition() { |
||||||
|
return startPosition; |
||||||
|
} |
||||||
|
|
||||||
|
public int getEndPosition() { |
||||||
|
return endPosition; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.mainframe; |
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
public class FormHorizontalParallelLine extends AbstractFormParallelLine { |
||||||
|
public FormHorizontalParallelLine(int parallelValue, int startPosition, int endPosition) { |
||||||
|
super(parallelValue, startPosition, endPosition); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getCenterPoint() { |
||||||
|
Point point = new Point(); |
||||||
|
point.setLocation(getCenterPosition(), parallelValue); |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getPerpendicularPoint(int parallelValue) { |
||||||
|
Point point = new Point(); |
||||||
|
point.setLocation(getCenterPosition(), parallelValue); |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getExtendedLineStartPoint(AbstractFormParallelLine parallelLine) { |
||||||
|
Point point = new Point(); |
||||||
|
if (isBeforeParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getStartPosition(), parallelLine.getParallelValue()); |
||||||
|
} else if (isBehindParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getEndPosition(), parallelLine.getParallelValue()); |
||||||
|
} |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getExtendedLineEndPoint(AbstractFormParallelLine parallelLine) { |
||||||
|
Point point = new Point(); |
||||||
|
if (isBeforeParallelLine(parallelLine)) { |
||||||
|
point.setLocation(getStartPosition(), parallelLine.getParallelValue()); |
||||||
|
} else if (isBehindParallelLine(parallelLine)) { |
||||||
|
point.setLocation(getEndPosition(), parallelLine.getParallelValue()); |
||||||
|
} |
||||||
|
return point; |
||||||
|
} |
||||||
|
} |
@ -0,0 +1,45 @@ |
|||||||
|
package com.fr.design.mainframe; |
||||||
|
|
||||||
|
import java.awt.Point; |
||||||
|
|
||||||
|
public class FormVerticalParallelLine extends AbstractFormParallelLine { |
||||||
|
public FormVerticalParallelLine(int parallelValue, int startPosition, int endPosition) { |
||||||
|
super(parallelValue, startPosition, endPosition); |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getCenterPoint() { |
||||||
|
Point point = new Point(); |
||||||
|
point.setLocation(parallelValue, getCenterPosition()); |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getPerpendicularPoint(int parallelValue) { |
||||||
|
Point point = new Point(); |
||||||
|
point.setLocation(parallelValue, getCenterPosition()); |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getExtendedLineStartPoint(AbstractFormParallelLine parallelLine) { |
||||||
|
Point point = new Point(); |
||||||
|
if (isBeforeParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getParallelValue(), parallelLine.getStartPosition()); |
||||||
|
} else if (isBehindParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getParallelValue(), parallelLine.getEndPosition()); |
||||||
|
} |
||||||
|
return point; |
||||||
|
} |
||||||
|
|
||||||
|
@Override |
||||||
|
public Point getExtendedLineEndPoint(AbstractFormParallelLine parallelLine) { |
||||||
|
Point point = new Point(); |
||||||
|
if (isBeforeParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getParallelValue(), getStartPosition()); |
||||||
|
} else if (isBehindParallelLine(parallelLine)) { |
||||||
|
point.setLocation(parallelLine.getParallelValue(), getEndPosition()); |
||||||
|
} |
||||||
|
return point; |
||||||
|
} |
||||||
|
} |
Loading…
Reference in new issue