mirror of
https://github.com/jneug/zeichenmaschine.git
synced 2026-04-14 14:43:33 +02:00
Methoden, um vorhandene Formen gezielt abzufragen
This commit is contained in:
@@ -2,7 +2,7 @@ package schule.ngb.zm.shapes;
|
|||||||
|
|
||||||
import schule.ngb.zm.Layer;
|
import schule.ngb.zm.Layer;
|
||||||
|
|
||||||
import java.awt.*;
|
import java.awt.Graphics2D;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
|
|
||||||
public class ShapesLayer extends Layer {
|
public class ShapesLayer extends Layer {
|
||||||
@@ -21,14 +21,53 @@ public class ShapesLayer extends Layer {
|
|||||||
shapes = new LinkedList<Shape>();
|
shapes = new LinkedList<Shape>();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void add( Shape... pFormen ) {
|
public Shape getShape( int index ) {
|
||||||
|
return shapes.get(index);
|
||||||
|
}
|
||||||
|
|
||||||
|
public <ST extends Shape> ST getShape( Class<ST> shapeClass ) {
|
||||||
|
for( Shape s : shapes ) {
|
||||||
|
if( shapeClass.isInstance(s) ) {
|
||||||
|
return (ST) s;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
public java.util.List<Shape> getShapes() {
|
||||||
|
return shapes;
|
||||||
|
}
|
||||||
|
|
||||||
|
public <ST extends Shape> java.util.List<ST> getShapes( Class<ST> shapeClass ) {
|
||||||
|
java.util.List<ST> result = new LinkedList<>();
|
||||||
|
for( Shape s : shapes ) {
|
||||||
|
if( shapeClass.isInstance(s) ) {
|
||||||
|
result.add((ST) s);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void add( Shape... shape ) {
|
||||||
synchronized( shapes ) {
|
synchronized( shapes ) {
|
||||||
for( Shape f : pFormen ) {
|
for( Shape f : shape ) {
|
||||||
shapes.add(f);
|
shapes.add(f);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void remove( Shape shape ) {
|
||||||
|
synchronized( shapes ) {
|
||||||
|
shapes.remove(shape);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeAll() {
|
||||||
|
synchronized( shapes ) {
|
||||||
|
shapes.clear();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public void showAll() {
|
public void showAll() {
|
||||||
synchronized( shapes ) {
|
synchronized( shapes ) {
|
||||||
for( Shape pShape : shapes ) {
|
for( Shape pShape : shapes ) {
|
||||||
@@ -45,10 +84,6 @@ public class ShapesLayer extends Layer {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public java.util.List<Shape> getShapes() {
|
|
||||||
return shapes;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void draw( Graphics2D pGraphics ) {
|
public void draw( Graphics2D pGraphics ) {
|
||||||
if( clearBeforeDraw ) {
|
if( clearBeforeDraw ) {
|
||||||
|
|||||||
Reference in New Issue
Block a user