feat: implement SText shape
This commit is contained in:
@@ -8,7 +8,6 @@ import ovh.gasser.newshapes.shapes.Shape;
|
||||
import ovh.gasser.newshapes.ui.ShapesView;
|
||||
import ovh.gasser.newshapes.ui.listeners.MenuAddListener;
|
||||
import ovh.gasser.newshapes.ui.listeners.MenuEditListener;
|
||||
import ovh.gasser.newshapes.ui.listeners.SelectionListener;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@@ -39,12 +38,7 @@ public class App {
|
||||
|
||||
this.buildMenuBar(frame, view);
|
||||
|
||||
view.addSelectionChangeListener(new SelectionListener() {
|
||||
@Override
|
||||
public void onSelectionChanged(Iterable<Shape> selectedShapes) {
|
||||
updateMenuState(selectedShapes);
|
||||
}
|
||||
});
|
||||
view.addSelectionChangeListener(this::updateMenuState);
|
||||
}
|
||||
|
||||
private void buildModel() {
|
||||
@@ -79,11 +73,13 @@ public class App {
|
||||
JMenu menuFile = new JMenu("File");
|
||||
JMenuItem addRectItem = new JMenuItem("Add SRectangle");
|
||||
JMenuItem addCircleItem = new JMenuItem("Add SCircle");
|
||||
JMenuItem addTextItem = new JMenuItem("Add Text");
|
||||
JMenuItem htmlExportItem = new JMenuItem("Export to HTML");
|
||||
JMenuItem svgExportItem = new JMenuItem("Export to SVG");
|
||||
JMenuItem exitItem = new JMenuItem("Exit");
|
||||
addRectItem.addActionListener(new MenuAddListener("SRectangle", model, sview));
|
||||
addCircleItem.addActionListener(new MenuAddListener("SCircle", model, sview));
|
||||
addTextItem.addActionListener(evt -> sview.getController().enterTextMode());
|
||||
htmlExportItem.addActionListener(evt -> {
|
||||
try {
|
||||
new HTMLExporter(model).export();
|
||||
@@ -101,6 +97,7 @@ public class App {
|
||||
exitItem.addActionListener(evt -> System.exit(0));
|
||||
menuFile.add(addRectItem);
|
||||
menuFile.add(addCircleItem);
|
||||
menuFile.add(addTextItem);
|
||||
menuFile.addSeparator();
|
||||
menuFile.add(htmlExportItem);
|
||||
menuFile.add(svgExportItem);
|
||||
@@ -132,21 +129,24 @@ public class App {
|
||||
}
|
||||
|
||||
private void updateMenuState(Iterable<Shape> selectedShapes) {
|
||||
boolean hasAttributes = false;
|
||||
boolean hasToggleableShapes = false;
|
||||
boolean allFilled = true;
|
||||
boolean allStroked = true;
|
||||
|
||||
for (Shape s : selectedShapes) {
|
||||
if (s instanceof SText) {
|
||||
continue;
|
||||
}
|
||||
ColorAttributes attrs = (ColorAttributes) s.getAttributes(ColorAttributes.ID);
|
||||
if (attrs != null) {
|
||||
hasAttributes = true;
|
||||
hasToggleableShapes = true;
|
||||
allFilled = allFilled && attrs.filled;
|
||||
allStroked = allStroked && attrs.stroked;
|
||||
}
|
||||
}
|
||||
|
||||
updateMenuItem(editFill, hasAttributes, allFilled);
|
||||
updateMenuItem(editBorder, hasAttributes, allStroked);
|
||||
updateMenuItem(editFill, hasToggleableShapes, allFilled);
|
||||
updateMenuItem(editBorder, hasToggleableShapes, allStroked);
|
||||
}
|
||||
|
||||
private void updateMenuItem(JCheckBoxMenuItem menuItem, boolean hasAttributes, boolean allSelected) {
|
||||
|
||||
Reference in New Issue
Block a user