mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Javadoc
This commit is contained in:
@@ -18,7 +18,7 @@ public interface Drawable {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Wird aufgerufen, um das Objekt auf die Zeichenfläche <var>graphics</var>
|
* Wird aufgerufen, um das Objekt auf die Zeichenfläche <var>graphics</var>
|
||||||
* zu draw.
|
* zu zeichnen.
|
||||||
* <p>
|
* <p>
|
||||||
* Das Objekt muss dafür Sorge tragen, dass der Zustand der Zeichenfläche
|
* Das Objekt muss dafür Sorge tragen, dass der Zustand der Zeichenfläche
|
||||||
* (Transformationsmatrix, Farbe, ...) erhalten bleibt. Das Objekt sollte
|
* (Transformationsmatrix, Farbe, ...) erhalten bleibt. Das Objekt sollte
|
||||||
|
|||||||
@@ -39,7 +39,7 @@ public abstract class FilledShape extends StrokedShape {
|
|||||||
* Setzt die Füllfarbe auf die angegebene Farbe.
|
* Setzt die Füllfarbe auf die angegebene Farbe.
|
||||||
*
|
*
|
||||||
* @param color Die neue Füllfarbe oder {@code null}.
|
* @param color Die neue Füllfarbe oder {@code null}.
|
||||||
* @see Color#Color(Color)
|
* @see Color
|
||||||
*/
|
*/
|
||||||
public void setFillColor( Color color ) {
|
public void setFillColor( Color color ) {
|
||||||
fillColor = color;
|
fillColor = color;
|
||||||
@@ -50,7 +50,7 @@ public abstract class FilledShape extends StrokedShape {
|
|||||||
* auf den angegebenen Wert. 0 is komplett durchsichtig und 255 komplett
|
* auf den angegebenen Wert. 0 is komplett durchsichtig und 255 komplett
|
||||||
* deckend.
|
* deckend.
|
||||||
*
|
*
|
||||||
* @param color Die neue Füllfarbe oder {@null}.
|
* @param color Die neue Füllfarbe oder {@code null}.
|
||||||
* @param alpha Ein Transparenzwert zwischen 0 und 255.
|
* @param alpha Ein Transparenzwert zwischen 0 und 255.
|
||||||
* @see Color#Color(Color, int)
|
* @see Color#Color(Color, int)
|
||||||
*/
|
*/
|
||||||
@@ -136,12 +136,12 @@ public abstract class FilledShape extends StrokedShape {
|
|||||||
* ({@code fromX}, {@code fromY}) mit der Farbe {@code from} startet und am
|
* ({@code fromX}, {@code fromY}) mit der Farbe {@code from} startet und am
|
||||||
* Punkt (({@code toX}, {@code toY}) mit der Farbe {@code to} endet.
|
* Punkt (({@code toX}, {@code toY}) mit der Farbe {@code to} endet.
|
||||||
*
|
*
|
||||||
* @param fromX
|
* @param fromX x-Koordinate des Startpunktes.
|
||||||
* @param fromY
|
* @param fromY y-Koordinate des Startpunktes.
|
||||||
* @param from
|
* @param from Farbe am Startpunkt.
|
||||||
* @param toX
|
* @param toX x-Koordinate des Endpunktes.
|
||||||
* @param toY
|
* @param toY y-Koordinate des Endpunktes.
|
||||||
* @param to
|
* @param to Farbe am Endpunkt.
|
||||||
*/
|
*/
|
||||||
public void setGradient( double fromX, double fromY, Color from, double toX, double toY, Color to ) {
|
public void setGradient( double fromX, double fromY, Color from, double toX, double toY, Color to ) {
|
||||||
setFillColor(from);
|
setFillColor(from);
|
||||||
@@ -158,11 +158,11 @@ public abstract class FilledShape extends StrokedShape {
|
|||||||
* endet am Rand des durch den Radius beschriebenen Kreises mit der Farbe
|
* endet am Rand des durch den Radius beschriebenen Kreises mit der Farbe
|
||||||
* {@code to}.
|
* {@code to}.
|
||||||
*
|
*
|
||||||
* @param centerX
|
* @param centerX x-Koordinate des Kreismittelpunktes.
|
||||||
* @param centerY
|
* @param centerY y-Koordinate des Kreismittelpunktes.
|
||||||
* @param radius
|
* @param radius Radius des Kreises.
|
||||||
* @param from
|
* @param from Farbe im Zentrum des Kreises.
|
||||||
* @param to
|
* @param to Farbe am Rand des Kreises.
|
||||||
*/
|
*/
|
||||||
public void setGradient( double centerX, double centerY, double radius, Color from, Color to ) {
|
public void setGradient( double centerX, double centerY, double radius, Color from, Color to ) {
|
||||||
setFillColor(from);
|
setFillColor(from);
|
||||||
@@ -180,11 +180,11 @@ public abstract class FilledShape extends StrokedShape {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Hilfsmethode für Unterklassen, um die angegebene Form mit der gesetzten
|
* Hilfsmethode für Unterklassen, um die angegebene Form mit der aktuellen
|
||||||
* Füllung auf den Grafik-Kontext zu zeichnen. Die Methode verändert
|
* Füllung auf den Grafik-Kontext zu zeichnen. Die Methode verändert
|
||||||
* gegebenenfalls die aktuelle Farbe des Grafikobjekts und setzt sie nicht
|
* gegebenenfalls die aktuelle Farbe des Grafikobjekts und setzt sie nicht
|
||||||
* auf den Ursprungswert zurück. Dies sollte die aufrufende Unterklasse
|
* auf den Ursprungswert zurück, wie von {@link #draw(Graphics2D)}
|
||||||
* übernehmen.
|
* gefordert. Dies sollte die aufrufende Unterklasse übernehmen.
|
||||||
*
|
*
|
||||||
* @param shape Die zu zeichnende Java-AWT Form
|
* @param shape Die zu zeichnende Java-AWT Form
|
||||||
* @param graphics Das Grafikobjekt.
|
* @param graphics Das Grafikobjekt.
|
||||||
|
|||||||
@@ -226,7 +226,6 @@ public abstract class Shape extends FilledShape {
|
|||||||
* Unterklasse. In {@link Rectangle} sieht die Umsetzung beispielsweise so
|
* Unterklasse. In {@link Rectangle} sieht die Umsetzung beispielsweise so
|
||||||
* aus:
|
* aus:
|
||||||
* <pre><code>
|
* <pre><code>
|
||||||
* @Override
|
|
||||||
* public Rectangle copy() {
|
* public Rectangle copy() {
|
||||||
* return new Rectangle(this);
|
* return new Rectangle(this);
|
||||||
* }
|
* }
|
||||||
|
|||||||
@@ -15,55 +15,162 @@ import java.awt.Stroke;
|
|||||||
*/
|
*/
|
||||||
public abstract class StrokedShape extends Constants implements Drawable {
|
public abstract class StrokedShape extends Constants implements Drawable {
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Aktuelle Farbe der Konturlinie oder {@code null}, wenn die Form ohne
|
||||||
|
* kontur dargestellt werden soll.
|
||||||
|
*/
|
||||||
protected Color strokeColor = DEFAULT_STROKECOLOR;
|
protected Color strokeColor = DEFAULT_STROKECOLOR;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Dicke der Konturlinie. Wird nicht kleiner als 0.
|
||||||
|
*/
|
||||||
protected double strokeWeight = DEFAULT_STROKEWEIGHT;
|
protected double strokeWeight = DEFAULT_STROKEWEIGHT;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Die Art der Konturlinie.
|
||||||
|
*/
|
||||||
protected Options.StrokeType strokeType = SOLID;
|
protected Options.StrokeType strokeType = SOLID;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Cache für den aktuellen {@code Stroke} der Kontur. Wird nach Änderung
|
||||||
|
* einer der Kontureigenschaften auf {@code null} gesetzt und beim nächsten
|
||||||
|
* Zeichnen neu erstellt.
|
||||||
|
*/
|
||||||
protected Stroke stroke = null;
|
protected Stroke stroke = null;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die aktuelle Farbe der Konturlinie zurück.
|
||||||
|
*
|
||||||
|
* @return Die Konturfarbe oder {@code null}.
|
||||||
|
*/
|
||||||
public Color getStrokeColor() {
|
public Color getStrokeColor() {
|
||||||
return strokeColor;
|
return strokeColor;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf die angegebene Farbe.
|
||||||
|
*
|
||||||
|
* @param color Die neue Farbe der Konturlinie.
|
||||||
|
* @see Color
|
||||||
|
*/
|
||||||
public void setStrokeColor( Color color ) {
|
public void setStrokeColor( Color color ) {
|
||||||
this.strokeColor = color;
|
this.strokeColor = color;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf die angegebene Farbe und setzt die
|
||||||
|
* Transparenz auf den angegebenen Wert. 0 is komplett durchsichtig und 255
|
||||||
|
* komplett deckend.
|
||||||
|
*
|
||||||
|
* @param color Die neue Farbe der Konturlinie oder {@code null}.
|
||||||
|
* @param alpha Ein Transparenzwert zwischen 0 und 255.
|
||||||
|
* @see Color#Color(Color, int)
|
||||||
|
*/
|
||||||
public void setStrokeColor( Color color, int alpha ) {
|
public void setStrokeColor( Color color, int alpha ) {
|
||||||
setStrokeColor(new Color(color, alpha));
|
setStrokeColor(new Color(color, alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf einen Grauwert mit der angegebenen
|
||||||
|
* Intensität. 0 entspricht schwarz, 255 entspricht weiß.
|
||||||
|
*
|
||||||
|
* @param gray Ein Grauwert zwischen 0 und 255.
|
||||||
|
* @see Color#Color(int)
|
||||||
|
*/
|
||||||
public void setStrokeColor( int gray ) {
|
public void setStrokeColor( int gray ) {
|
||||||
setStrokeColor(gray, gray, gray, 255);
|
setStrokeColor(gray, gray, gray, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void noStroke() {
|
/**
|
||||||
setStrokeColor(null);
|
* Setzt die Farbe der Konturlinie auf einen Grauwert mit der angegebenen
|
||||||
}
|
* Intensität und dem angegebenen Transparenzwert. Der Grauwert 0 entspricht
|
||||||
|
* schwarz, 255 entspricht weiß.
|
||||||
|
*
|
||||||
|
* @param gray Ein Grauwert zwischen 0 und 255.
|
||||||
|
* @param alpha Ein Transparenzwert zwischen 0 und 255.
|
||||||
|
* @see Color#Color(int, int)
|
||||||
|
*/
|
||||||
public void setStrokeColor( int gray, int alpha ) {
|
public void setStrokeColor( int gray, int alpha ) {
|
||||||
setStrokeColor(gray, gray, gray, alpha);
|
setStrokeColor(gray, gray, gray, alpha);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf die Farbe mit den angegebenen Rot-,
|
||||||
|
* Grün- und Blauanteilen.
|
||||||
|
*
|
||||||
|
* @param red Der Rotanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @param green Der Grünanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @param blue Der Blauanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @see Color#Color(int, int, int)
|
||||||
|
* @see <a
|
||||||
|
* href="https://de.wikipedia.org/wiki/RGB-Farbraum">https://de.wikipedia.org/wiki/RGB-Farbraum</a>
|
||||||
|
*/
|
||||||
public void setStrokeColor( int red, int green, int blue ) {
|
public void setStrokeColor( int red, int green, int blue ) {
|
||||||
setStrokeColor(red, green, blue, 255);
|
setStrokeColor(red, green, blue, 255);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf die Farbe mit den angegebenen Rot-,
|
||||||
|
* Grün- und Blauanteilen und dem angegebenen Transparenzwert.
|
||||||
|
*
|
||||||
|
* @param red Der Rotanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @param green Der Grünanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @param blue Der Blauanteil der Farbe zwischen 0 und 255.
|
||||||
|
* @param alpha Ein Transparenzwert zwischen 0 und 25
|
||||||
|
* @see Color#Color(int, int, int, int)
|
||||||
|
* @see <a
|
||||||
|
* href="https://de.wikipedia.org/wiki/RGB-Farbraum">https://de.wikipedia.org/wiki/RGB-Farbraum</a>
|
||||||
|
*/
|
||||||
public void setStrokeColor( int red, int green, int blue, int alpha ) {
|
public void setStrokeColor( int red, int green, int blue, int alpha ) {
|
||||||
setStrokeColor(new Color(red, green, blue, alpha));
|
setStrokeColor(new Color(red, green, blue, alpha));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Entfernt die Kontur der Form.
|
||||||
|
*/
|
||||||
|
public void noStroke() {
|
||||||
|
setStrokeColor(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Farbe der Konturlinie auf die Standardwerte zurück.
|
||||||
|
*
|
||||||
|
* @see schule.ngb.zm.Constants#DEFAULT_STROKECOLOR
|
||||||
|
* @see schule.ngb.zm.Constants#DEFAULT_STROKEWEIGHT
|
||||||
|
* @see schule.ngb.zm.Constants#SOLID
|
||||||
|
*/
|
||||||
|
public void resetStroke() {
|
||||||
|
setStrokeColor(DEFAULT_STROKECOLOR);
|
||||||
|
setStrokeWeight(DEFAULT_STROKEWEIGHT);
|
||||||
|
setStrokeType(SOLID);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Dicke der Konturlinie zurück.
|
||||||
|
*
|
||||||
|
* @return Die aktuelle Dicke der Linie.
|
||||||
|
*/
|
||||||
public double getStrokeWeight() {
|
public double getStrokeWeight() {
|
||||||
return strokeWeight;
|
return strokeWeight;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Setzt die Dicke der Konturlinie. Die Dicke muss größer 0 sein. Wird 0
|
||||||
|
* übergeben, dann wird keine Kontur mehr angezeigt.
|
||||||
|
*
|
||||||
|
* @param weight Die Dicke der Konturlinie.
|
||||||
|
*/
|
||||||
public void setStrokeWeight( double weight ) {
|
public void setStrokeWeight( double weight ) {
|
||||||
this.strokeWeight = weight;
|
this.strokeWeight = max(0.0, weight);
|
||||||
this.stroke = null;
|
this.stroke = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gibt die Art der Konturlinie zurück.
|
||||||
|
*
|
||||||
|
* @return Die aktuelle Art der Konturlinie.
|
||||||
|
* @see Options.StrokeType
|
||||||
|
*/
|
||||||
public Options.StrokeType getStrokeType() {
|
public Options.StrokeType getStrokeType() {
|
||||||
return strokeType;
|
return strokeType;
|
||||||
}
|
}
|
||||||
@@ -72,26 +179,23 @@ public abstract class StrokedShape extends Constants implements Drawable {
|
|||||||
* Setzt den Typ der Kontur. Erlaubte Werte sind {@link #DASHED},
|
* Setzt den Typ der Kontur. Erlaubte Werte sind {@link #DASHED},
|
||||||
* {@link #DOTTED} und {@link #SOLID}.
|
* {@link #DOTTED} und {@link #SOLID}.
|
||||||
*
|
*
|
||||||
* @param type
|
* @param type Eine der möglichen Konturarten.
|
||||||
|
* @see Options.StrokeType
|
||||||
*/
|
*/
|
||||||
public void setStrokeType( Options.StrokeType type ) {
|
public void setStrokeType( Options.StrokeType type ) {
|
||||||
this.strokeType = type;
|
this.strokeType = type;
|
||||||
this.stroke = null;
|
this.stroke = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void resetStroke() {
|
|
||||||
setStrokeColor(DEFAULT_STROKECOLOR);
|
|
||||||
setStrokeWeight(DEFAULT_STROKEWEIGHT);
|
|
||||||
setStrokeType(SOLID);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public abstract void draw( Graphics2D graphics );
|
public abstract void draw( Graphics2D graphics );
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Erstellt ein {@link Stroke} Objekt für den Konturtyp.
|
* Hilfsmethode, um ein {@link Stroke} Objekt mit den aktuellen
|
||||||
|
* Kontureigenschaften zu erstellen. Der aktuelle {@code Stroke} wird
|
||||||
|
* zwischengespeichert.
|
||||||
*
|
*
|
||||||
* @return
|
* @return Ein {@code Stroke} mit den passenden Kontureigenschaften.
|
||||||
*/
|
*/
|
||||||
protected Stroke createStroke() {
|
protected Stroke createStroke() {
|
||||||
// TODO: Used global cached Stroke Objects?
|
// TODO: Used global cached Stroke Objects?
|
||||||
@@ -123,6 +227,16 @@ public abstract class StrokedShape extends Constants implements Drawable {
|
|||||||
return stroke;
|
return stroke;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Hilfsmethode für Unterklassen, um die angegebene Form mit den aktuellen
|
||||||
|
* Kontureigenschaften auf den Grafik-Kontext zu zeichnen. Die Methode
|
||||||
|
* verändert gegebenenfalls die aktuelle Farbe des Grafikobjekts und setzt
|
||||||
|
* sie nicht auf den Ursprungswert zurück, wie von {@link #draw(Graphics2D)}
|
||||||
|
* gefordert. Dies sollte die aufrufende Unterklasse übernehmen.
|
||||||
|
*
|
||||||
|
* @param shape Die zu zeichnende Java-AWT Form
|
||||||
|
* @param graphics Das Grafikobjekt.
|
||||||
|
*/
|
||||||
protected void strokeShape( java.awt.Shape shape, Graphics2D graphics ) {
|
protected void strokeShape( java.awt.Shape shape, Graphics2D graphics ) {
|
||||||
if( strokeColor != null && strokeColor.getAlpha() > 0
|
if( strokeColor != null && strokeColor.getAlpha() > 0
|
||||||
&& strokeWeight > 0.0 ) {
|
&& strokeWeight > 0.0 ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user