mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 06:33:34 +02:00
Made access to layers synchronized
This commit is contained in:
@@ -29,9 +29,11 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
|
|
||||||
// Liste der Ebenen initialisieren und die Standardebenen einfügen
|
// Liste der Ebenen initialisieren und die Standardebenen einfügen
|
||||||
layers = new LinkedList<>();
|
layers = new LinkedList<>();
|
||||||
layers.add(new ColorLayer(Constants.STD_BACKGROUND));
|
synchronized( layers ) {
|
||||||
layers.add(new DrawingLayer());
|
layers.add(new ColorLayer(Constants.STD_BACKGROUND));
|
||||||
layers.add(new ShapesLayer());
|
layers.add(new DrawingLayer());
|
||||||
|
layers.add(new ShapesLayer());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -47,8 +49,10 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
this.setPreferredSize(this.getSize());
|
this.setPreferredSize(this.getSize());
|
||||||
this.setMinimumSize(this.getSize());
|
this.setMinimumSize(this.getSize());
|
||||||
|
|
||||||
for( Layer layer : layers ) {
|
synchronized( layers ) {
|
||||||
layer.setSize(width, height);
|
for( Layer layer : layers ) {
|
||||||
|
layer.setSize(width, height);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -59,8 +63,10 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void addLayer( Layer layer ) {
|
public void addLayer( Layer layer ) {
|
||||||
if( layer != null ) {
|
if( layer != null ) {
|
||||||
layer.setSize(getWidth(), getHeight());
|
synchronized( layers ) {
|
||||||
layers.add(layer);
|
layer.setSize(getWidth(), getHeight());
|
||||||
|
layers.add(layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,8 +77,10 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
*/
|
*/
|
||||||
public void addLayer( int i, Layer layer ) {
|
public void addLayer( int i, Layer layer ) {
|
||||||
if( layer != null ) {
|
if( layer != null ) {
|
||||||
layer.setSize(getWidth(), getHeight());
|
synchronized( layers ) {
|
||||||
layers.add(i, layer);
|
layer.setSize(getWidth(), getHeight());
|
||||||
|
layers.add(i, layer);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -140,8 +148,10 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void dispose() {
|
public void dispose() {
|
||||||
for( Layer layer : layers ) {
|
synchronized( layers ) {
|
||||||
layer.dispose();
|
for( Layer layer : layers ) {
|
||||||
|
layer.dispose();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -163,8 +173,10 @@ public class Zeichenleinwand extends Canvas {
|
|||||||
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
|
Graphics2D g2d = (Graphics2D) strategy.getDrawGraphics();
|
||||||
g2d.clearRect(0, 0, getWidth(), getHeight());
|
g2d.clearRect(0, 0, getWidth(), getHeight());
|
||||||
|
|
||||||
for( Layer layer : layers ) {
|
synchronized( layers ) {
|
||||||
layer.draw(g2d);
|
for( Layer layer : layers ) {
|
||||||
|
layer.draw(g2d);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
g2d.dispose();
|
g2d.dispose();
|
||||||
|
|||||||
Reference in New Issue
Block a user