mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-10-12 09:56:33 +02:00
Zeichenleinwand wird nur noch mit ColorLayer initialisiert
This commit is contained in:
@@ -29,6 +29,7 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Erstellt eine neue Zeichenleinwand mit einer festen Größe.
|
* Erstellt eine neue Zeichenleinwand mit einer festen Größe.
|
||||||
|
*
|
||||||
* @param width Breite der Zeichenleinwand.
|
* @param width Breite der Zeichenleinwand.
|
||||||
* @param height Höhe der Zeichenleinwand.
|
* @param height Höhe der Zeichenleinwand.
|
||||||
*/
|
*/
|
||||||
@@ -42,8 +43,6 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
layers = new LinkedList<>();
|
layers = new LinkedList<>();
|
||||||
synchronized( layers ) {
|
synchronized( layers ) {
|
||||||
layers.add(new ColorLayer(width, height, Constants.STD_BACKGROUND));
|
layers.add(new ColorLayer(width, height, Constants.STD_BACKGROUND));
|
||||||
layers.add(new DrawingLayer(width, height));
|
|
||||||
layers.add(new ShapesLayer(width, height));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -85,7 +84,11 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Fügt der Zeichenleinwand eine Ebene an einer bestimmten Stelle hinzu.
|
* Fügt der Zeichenleinwand eine Ebene an einem bestimmten Index hinzu. Wenn
|
||||||
|
* der Index noch nicht existiert (also größer als die
|
||||||
|
* {@link #getLayerCount() Anzahl der Ebenen} ist, dann wird die neue Ebene
|
||||||
|
* als letzte eingefügt. Die aufrufende Methode kann also nicht sicher sein,
|
||||||
|
* dass die neue Ebene am Ende wirklich am Index {@code i} steht.
|
||||||
*
|
*
|
||||||
* @param i Index der Ebene, beginnend mit <code>0</code>.
|
* @param i Index der Ebene, beginnend mit <code>0</code>.
|
||||||
* @param layer Die neue Ebene.
|
* @param layer Die neue Ebene.
|
||||||
@@ -94,10 +97,14 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
if( layer != null ) {
|
if( layer != null ) {
|
||||||
synchronized( layers ) {
|
synchronized( layers ) {
|
||||||
layer.setSize(getWidth(), getHeight());
|
layer.setSize(getWidth(), getHeight());
|
||||||
|
if( i > layers.size() ) {
|
||||||
|
layers.add(layer);
|
||||||
|
} else {
|
||||||
layers.add(i, layer);
|
layers.add(i, layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Gibt die Anzahl der {@link Layer Ebenen} in dieser Leinwand zurück.
|
* Gibt die Anzahl der {@link Layer Ebenen} in dieser Leinwand zurück.
|
||||||
@@ -173,7 +180,7 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void removeLayers( Layer... pLayers ) {
|
public void removeLayers( Layer... pLayers ) {
|
||||||
for( Layer layer: pLayers ) {
|
for( Layer layer : pLayers ) {
|
||||||
layers.remove(layer);
|
layers.remove(layer);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -207,6 +214,7 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Zeichnet den Inhalt aller {@link Layer Ebenen} in den Grafik-Kontext.
|
* Zeichnet den Inhalt aller {@link Layer Ebenen} in den Grafik-Kontext.
|
||||||
|
*
|
||||||
* @param graphics
|
* @param graphics
|
||||||
*/
|
*/
|
||||||
public void draw( Graphics graphics ) {
|
public void draw( Graphics graphics ) {
|
||||||
|
|||||||
@@ -687,7 +687,7 @@ public class Zeichenmaschine extends Constants implements MouseInputListener, Ke
|
|||||||
ShapesLayer layer = canvas.getLayer(ShapesLayer.class);
|
ShapesLayer layer = canvas.getLayer(ShapesLayer.class);
|
||||||
if( layer == null ) {
|
if( layer == null ) {
|
||||||
layer = new ShapesLayer(getWidth(), getHeight());
|
layer = new ShapesLayer(getWidth(), getHeight());
|
||||||
canvas.addLayer(layer);
|
canvas.addLayer(2, layer);
|
||||||
}
|
}
|
||||||
return layer;
|
return layer;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user