- Selection: add addAll() method for bulk shape addition - Controller: box selection with mouse drag on empty space - ShapeDraftman: drawSelectionBox() for rubber-band rendering - ShapesView: currentSelectionBox field and setter
48 lines
1.3 KiB
Java
48 lines
1.3 KiB
Java
package ovh.gasser.newshapes.ui;
|
|
|
|
import ovh.gasser.newshapes.ShapeVisitor;
|
|
import ovh.gasser.newshapes.shapes.SCollection;
|
|
import ovh.gasser.newshapes.shapes.Shape;
|
|
import ovh.gasser.newshapes.ui.listeners.SelectionListener;
|
|
|
|
import javax.swing.*;
|
|
import java.awt.*;
|
|
|
|
public class ShapesView extends JPanel {
|
|
private final Shape model;
|
|
private final Controller controller;
|
|
private ShapeVisitor draftman;
|
|
private boolean resizeMode;
|
|
private Rectangle currentSelectionBox;
|
|
|
|
public ShapesView(SCollection model) {
|
|
this.model = model;
|
|
this.controller = new Controller(this, model);
|
|
}
|
|
|
|
@Override
|
|
protected void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
this.draftman = new ShapeDraftman(g);
|
|
((ShapeDraftman) this.draftman).setResizeMode(resizeMode);
|
|
model.accept(draftman);
|
|
((ShapeDraftman) this.draftman).drawSelectionBox(currentSelectionBox);
|
|
}
|
|
|
|
public Controller getController() {
|
|
return controller;
|
|
}
|
|
|
|
public void addSelectionChangeListener(SelectionListener listener) {
|
|
controller.addSelectionChangeListener(listener);
|
|
}
|
|
|
|
public void setResizeMode(boolean resizeMode) {
|
|
this.resizeMode = resizeMode;
|
|
}
|
|
|
|
public void setCurrentSelectionBox(Rectangle box) {
|
|
this.currentSelectionBox = box;
|
|
}
|
|
}
|