// SaveLoadManager.openLoadDialog();
}
+ @SuppressWarnings("unused") // Editor
public static void openNewEditor()
{
DeserializedSubmodelComponent toBeEdited = new DeserializedSubmodelComponent(new LogicModelModifiable(), null, null, null);
package net.mograsim.logic.model.editor;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.KeyEvent;
-import org.eclipse.swt.events.KeyListener;
-import org.eclipse.swt.events.MouseEvent;
-import org.eclipse.swt.events.MouseListener;
import net.haspamelodica.swt.helper.swtobjectwrappers.Point;
import net.mograsim.logic.model.editor.ui.EditorGUI;
public EditorUserInput(Editor editor)
{
this.gui = editor.gui;
- gui.logicCanvas.addMouseListener(new MouseListener()
+ gui.logicCanvas.addListener(SWT.MouseDown, e ->
{
- @Override
- public void mouseDoubleClick(MouseEvent e)
+ Point clicked = editor.gui.logicCanvas.canvasToWorldCoords(e.x, e.y);
+ switch (e.button)
{
- // TODO Auto-generated method stub
+ case 1:
+ editor.handleManager.click(clicked, e.stateMask);
+ break;
+ default:
+ // don't react
}
- @Override
- public void mouseDown(MouseEvent e)
- {
- Point clicked = editor.gui.logicCanvas.canvasToWorldCoords(e.x, e.y);
- switch (e.button)
- {
- case 1:
- editor.handleManager.click(clicked, e.stateMask);
- break;
- }
-
- }
-
- @Override
- public void mouseUp(MouseEvent e)
- {
- }
});
- gui.logicCanvas.addMouseMoveListener((e) ->
+ gui.logicCanvas.addMouseMoveListener(e ->
{
Point dest = editor.gui.logicCanvas.canvasToWorldCoords(e.x, e.y);
editor.stateManager.mouseMoved(dest.x, dest.y);
});
- gui.logicCanvas.addKeyListener(new KeyListener()
+ gui.logicCanvas.addListener(SWT.KeyDown, e ->
{
-
- @Override
- public void keyReleased(KeyEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void keyPressed(KeyEvent e)
+ switch (e.keyCode)
{
- switch (e.keyCode)
- {
- case 'c':
- if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
- editor.stateManager.copy();
- break;
- case 'v':
- if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
- editor.stateManager.paste();
- break;
- case 'd':
- if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT)
- editor.stateManager.duplicate();
- break;
- case 'g':
- editor.stateManager.grab();
- break;
- case 'r':
- editor.stateManager.delete();
- break;
- case 's':
- if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
- editor.save();
- break;
- case 'a':
- if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT)
- editor.stateManager.add();
- break;
- case 'h':
- editor.stateManager.boxSelect();
- break;
- }
-
+ case 'c':
+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
+ editor.stateManager.copy();
+ break;
+ case 'v':
+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
+ editor.stateManager.paste();
+ break;
+ case 'd':
+ if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT)
+ editor.stateManager.duplicate();
+ break;
+ case 'g':
+ editor.stateManager.grab();
+ break;
+ case 'r':
+ editor.stateManager.delete();
+ break;
+ case 's':
+ if ((e.stateMask & SWT.CTRL) == SWT.CTRL)
+ editor.save();
+ break;
+ case 'a':
+ if ((e.stateMask & SWT.SHIFT) == SWT.SHIFT)
+ editor.stateManager.add();
+ break;
+ case 'h':
+ editor.stateManager.boxSelect();
+ break;
+ default:
+ // don't react
}
});
}
}
}
+ @SuppressWarnings("unused") // Editor
public static void openLoadDialog() throws IOException
{
Shell fdShell = new Shell();
this.parent = parent;
Rectangle bounds = parent.getBounds();
setSize(bounds.width, bounds.height);
- parent.addComponentResizedListener((c) ->
+ parent.addComponentResizedListener(c ->
{
Rectangle pBounds = c.getBounds();
setSize(pBounds.width, pBounds.height);
return false;
}
+ // These methods are intended to be overridden
//@formatter:off
- public void reqMove(double x, double y) {}
- public void reqDelete() {}
- public Optional<ComponentInfo> reqCopy(Point refPoint) { return Optional.empty(); }
- public void onSelect() {}
- public void onDeselect() {}
+ @SuppressWarnings("unused") public void reqMove(double x, double y) {/**/}
+ public void reqDelete() {/**/}
+ @SuppressWarnings({ "unused", "static-method" }) public Optional<ComponentInfo> reqCopy(Point refPoint) {return Optional.empty();}
+ public void onSelect() {/**/}
+ public void onDeselect() {/**/}
//@formatter:on
public final int getPriority()
LogicModelModifiable model = editor.getSubmodel();
- model.addComponentAddedListener(c -> registerComponent(c));
+ model.addComponentAddedListener(this::registerComponent);
- model.addComponentRemovedListener(c ->
- {
- removeComponentHandle(c);
- });
+ model.addComponentRemovedListener(this::removeComponentHandle);
- model.addWireAddedListener(w ->
- {
- registerWire(w);
- });
+ model.addWireAddedListener(this::registerWire);
model.addWireRemovedListener(w ->
{
private void registerInterfaceComponent(ModelComponent c)
{
c.getPins().values().forEach(p -> addInterfacePinHandle(p));
- c.addPinAddedListener(p -> addInterfacePinHandle(p));
- c.addPinRemovedListener(p -> removeInterfacePinHandle(p));
+ c.addPinAddedListener(this::addInterfacePinHandle);
+ c.addPinRemovedListener(this::removeInterfacePinHandle);
}
private void registerComponent(ModelComponent c)
c.getPins().values().forEach(p -> addPinHandle(p));
- c.addPinAddedListener(p -> addPinHandle(p));
- c.addPinRemovedListener(p -> removePinHandle(p));
+ c.addPinAddedListener(this::addPinHandle);
+ c.addPinRemovedListener(this::removePinHandle);
}
private void registerWire(ModelWire wire)
super(1);
this.parent = parent;
setSize(CIRCLE_DIAM, CIRCLE_DIAM);
- parent.addPinMovedListener((p) -> updatePos());
+ parent.addPinMovedListener(p -> updatePos());
updatePos();
}
this.manager = manager;
}
+ // These methods are intended to be overridden
//@formatter:off
- public void add() {}
- public void delete() {}
- public void copy() {}
- public void paste() {}
- public void duplicate() {}
- public void grab() {}
- public void mouseMoved(double x, double y) {}
- public void select(Point pos, boolean additive) {}
- public void boxSelect() {}
- public void onEntry() {}
- public void onExit() {}
- public void clicked(InterfacePinHandle interfacePinHandle, int stateMask) {}
- public void clickedEmpty(Point clicked, int stateMask) {}
- public void clicked(Point clicked, int stateMask) {}
- public boolean clickedHandle(HandleClickInfo handleClickInfo) { return false; }
+ public void add() {/**/}
+ public void delete() {/**/}
+ public void copy() {/**/}
+ public void paste() {/**/}
+ public void duplicate() {/**/}
+ public void grab() {/**/}
+ @SuppressWarnings("unused") public void mouseMoved(double x, double y) {/**/}
+ @SuppressWarnings("unused") public void select(Point pos, boolean additive) {/**/}
+ public void boxSelect() {/**/}
+ public void onEntry() {/**/}
+ public void onExit() {/**/}
+ @SuppressWarnings("unused") public void clicked(InterfacePinHandle interfacePinHandle, int stateMask) {/**/}
+ @SuppressWarnings("unused") public void clickedEmpty(Point clicked, int stateMask) {/**/}
+ @SuppressWarnings("unused") public void clicked(Point clicked, int stateMask) {/**/}
+ @SuppressWarnings({ "unused", "static-method" }) public boolean clickedHandle(HandleClickInfo handleClickInfo) {return false;}
//@formatter:on
}
Integer.parseInt(result[1]), PinUsage.valueOf(result[2]), clicked.x, clicked.y));
editor.handleManager.getInterfacePinHandle(p).reqMove(clicked.x, clicked.y);
}
- catch (NumberFormatException e)
+ catch (@SuppressWarnings("unused") NumberFormatException e)
{
editor.dialogManager.openWarningDialog("Failed to create Pin!", "Bit width must be a number!");
}
- catch (IllegalArgumentException e)
+ catch (@SuppressWarnings("unused") IllegalArgumentException e)
{
editor.dialogManager.openWarningDialog("Failed to create Pin!", "Usage must be one of INPUT, OUTPUT, TRISTATE!");
}
manager.setState(new CreateWireState(editor, manager, (PinHandle) handleClickInfo.clicked));
break;
}
+ //$FALL-THROUGH$
case CORNER:
case COMPONENT:
case WIRE_POINT:
protected String[] result;
- public FlexibleInputsDialog(String title, String acceptLabel, String cancelLabel, String... inputs)
+ public FlexibleInputsDialog(String title, String acceptLabel, String cancelLabel)
{
- this(false, title, acceptLabel, cancelLabel, inputs);
+ this(false, title, acceptLabel, cancelLabel);
}
- public FlexibleInputsDialog(boolean resizable, String title, String acceptLabel, String cancelLabel, String... inputs)
+ public FlexibleInputsDialog(boolean resizable, String title, String acceptLabel, String cancelLabel)
{
super(new Shell(SWT.CLOSE | (resizable ? SWT.RESIZE | SWT.MAX : 0) | SWT.TITLE | SWT.MIN | SWT.ON_TOP | SWT.APPLICATION_MODAL));
this.title = title;
b1.setText(acceptLabel);
Button b2 = new Button(shell, SWT.PUSH);
- b2.addListener(SWT.Selection, e ->
- {
- shell.dispose();
- });
+ b2.addListener(SWT.Selection, e -> shell.dispose());
b2.setText(cancelLabel);
shell.pack();
import java.io.IOException;
import org.eclipse.swt.SWT;
-import org.eclipse.swt.events.SelectionEvent;
-import org.eclipse.swt.events.SelectionListener;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.graphics.Rectangle;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
-import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.List;
-import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Menu;
import org.eclipse.swt.widgets.MenuItem;
import org.eclipse.swt.widgets.Shell;
ToolItem file = new ToolItem(toolBar, SWT.DROP_DOWN);
// TODO
- DropDownEntry newEntry = new DropDownEntry("New", e -> Editor.openNewEditor());
- DropDownEntry loadEntry = new DropDownEntry("Load", e ->
+ DropDownEntry newEntry = new DropDownEntry("New", Editor::openNewEditor);
+ DropDownEntry loadEntry = new DropDownEntry("Load", () ->
{
try
{
SaveLoadManager.openLoadDialog();
}
- catch (IOException e1)
+ catch (IOException e)
{
- editor.dialogManager.openWarningDialog("Failed to load Component!", e1.getMessage());
+ editor.dialogManager.openWarningDialog("Failed to load Component!", e.getMessage());
}
});
- DropDownEntry saveEntry = new DropDownEntry("Save", e -> editor.save());
- DropDownEntry saveAsEntry = new DropDownEntry("Save as...", e -> editor.saveAs());
+ DropDownEntry saveEntry = new DropDownEntry("Save", editor::save);
+ DropDownEntry saveAsEntry = new DropDownEntry("Save as...", editor::saveAs);
DropDownEntry[] entries = new DropDownEntry[] { newEntry, loadEntry, saveEntry, saveAsEntry };
return toolBar;
}
+ @SuppressWarnings("unused") // ToolItem
private ToolBar setupBottomToolBar(Composite parent)
{
GridData d = new GridData();
int index = 0;
for (Editor.Snapping sn : Editor.Snapping.values())
{
- entries[index++] = new DropDownEntry(sn.toString(), e ->
+ entries[index++] = new DropDownEntry(sn.toString(), () ->
{
editor.setSnapping(sn);
snappSelect.setText(sn.toString());
for (DropDownEntry entry : entries)
{
MenuItem item = new MenuItem(menu, SWT.PUSH);
- item.addSelectionListener(new SelectionListener()
- {
- @Override
- public void widgetSelected(SelectionEvent e)
- {
- entry.listener.widgetSelected(e);
- }
-
- @Override
- public void widgetDefaultSelected(SelectionEvent e)
- {
- widgetSelected(e);
- }
- });
+ item.addListener(SWT.Selection, e -> entry.onSelected.run());
item.setText(entry.title);
}
- parent.addListener(SWT.Selection, new Listener()
+ parent.addListener(SWT.Selection, e ->
{
- public void handleEvent(Event event)
- {
- if (event.detail == SWT.ARROW)
- {
- Rectangle rect = parent.getBounds();
- Point pt = new Point(rect.x, rect.y + rect.height);
- pt = parent.getParent().toDisplay(pt);
- menu.setLocation(pt.x, pt.y);
- menu.setVisible(true);
- }
- }
+ Rectangle rect = parent.getBounds();
+ Point pt = new Point(rect.x, rect.y + rect.height);
+ pt = parent.getParent().toDisplay(pt);
+ menu.setLocation(pt.x, pt.y);
+ menu.setVisible(true);
});
}
private static class DropDownEntry
{
public final String title;
- public final EntrySelectedListener listener;
+ public final Runnable onSelected;
- public DropDownEntry(String title, EntrySelectedListener listener)
+ public DropDownEntry(String title, Runnable onSelected)
{
super();
this.title = title;
- this.listener = listener;
+ this.onSelected = onSelected;
}
}
- private static interface EntrySelectedListener
- {
- public void widgetSelected(SelectionEvent e);
- }
-
public void refreshAddList()
{
addList.setItems(IndirectModelComponentCreator.getStandardComponentIDs().keySet().stream().sorted().toArray(String[]::new));