u12
This commit is contained in:
parent
153773b5a3
commit
4b7f4dfd52
|
@ -0,0 +1,12 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-17">
|
||||
<attributes>
|
||||
<attribute name="module" value="true"/>
|
||||
</attributes>
|
||||
</classpathentry>
|
||||
<classpathentry kind="lib" path="/home/stud/p8q-yhw-u1/Downloads/liblocline.jar"/>
|
||||
<classpathentry kind="lib" path="/home/stud/p8q-yhw-u1/Downloads/DrawingPanel(1).jar"/>
|
||||
<classpathentry kind="output" path="bin"/>
|
||||
</classpath>
|
|
@ -0,0 +1 @@
|
|||
/bin/
|
|
@ -0,0 +1,17 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>u12</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
|
@ -0,0 +1,14 @@
|
|||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=17
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=17
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.enablePreviewFeatures=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.reportPreviewFeatures=warning
|
||||
org.eclipse.jdt.core.compiler.release=enabled
|
||||
org.eclipse.jdt.core.compiler.source=17
|
|
@ -0,0 +1,79 @@
|
|||
package de.hsh.prog.klassedashedline;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.util.Arrays;
|
||||
|
||||
/**
|
||||
* Klasse zum speichern und Zeichnen einer gestrichelten Linie
|
||||
* @author p8q-yhw-u1
|
||||
*
|
||||
*/
|
||||
public class DashedLine extends Line {
|
||||
|
||||
private int[] dashes;
|
||||
|
||||
/**
|
||||
* Erstellt ein DashedLine Objekt
|
||||
* @param l1 Startpunkt der Linie
|
||||
* @param l2 Endpunkt der Linie
|
||||
* @param dashes Zeichenmuster, ein Integer Array von Pixel-Längen.
|
||||
* Geradzahlige Indexe => Strich, Ungradzahlige Indexe => Lücke
|
||||
*/
|
||||
public DashedLine(Loc l1, Loc l2, int[] dashes) {
|
||||
super(l1, l2);
|
||||
|
||||
if (dashes.length <= 0) {
|
||||
throw new IllegalArgumentException("dashes muss mindestens ein Element enthalten");
|
||||
}
|
||||
|
||||
this.dashes = dashes;
|
||||
}
|
||||
|
||||
/**
|
||||
* Zeichnet die gestrichelt Linie mit einem Graphics Objekt
|
||||
*/
|
||||
@Override
|
||||
public void draw(Graphics g) {
|
||||
double x = this.getP1().getX();
|
||||
double y = this.getP1().getY();
|
||||
|
||||
double totalLen = this.getP1().distance(this.getP2());
|
||||
|
||||
double dx = this.getP2().getX() - x;
|
||||
double dy = this.getP2().getY() - y;
|
||||
|
||||
double currLen = 0;
|
||||
int currDash = 0;
|
||||
|
||||
while (currLen < totalLen) {
|
||||
|
||||
double dashLen = dashes[currDash];
|
||||
|
||||
if (dashLen + currLen > totalLen) {
|
||||
dashLen = totalLen - currLen;
|
||||
}
|
||||
|
||||
double nextx = x + dx * dashLen / totalLen;
|
||||
double nexty = y + dy * dashLen / totalLen;
|
||||
|
||||
if (currDash % 2 == 0) {
|
||||
new Line((int) x, (int) y, (int) nextx, (int) nexty).draw(g);
|
||||
}
|
||||
|
||||
x = nextx;
|
||||
y = nexty;
|
||||
|
||||
currLen += dashLen;
|
||||
currDash = (currDash + 1) % this.dashes.length;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Gibt die Linie in String-Form aus
|
||||
*/
|
||||
@Override
|
||||
public String toString() {
|
||||
return "[" + super.toString() + ", dashes=" + Arrays.toString(dashes) + "]";
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue