From: Fabian Stemmler Date: Mon, 15 Jul 2019 15:00:57 +0000 (+0200) Subject: Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim... X-Git-Url: https://mograsim.net/gitweb/?a=commitdiff_plain;h=9e9a77976efe36de6ae82e74a013cd07a17dd352;hp=-c;p=Mograsim.git Merge branch 'development' of https://gitlab.lrz.de/lrr-tum/students/eragp-misim-2019 into development --- 9e9a77976efe36de6ae82e74a013cd07a17dd352 diff --combined net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java index e213d1f3,e4c92928..2b7d4401 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/Editor.java @@@ -1,5 -1,6 +1,6 @@@ package net.mograsim.logic.model.editor; + import java.io.IOException; import java.util.HashMap; import java.util.HashSet; import java.util.Map; @@@ -134,11 -135,6 +135,11 @@@ public final class Edito { saveManager.save(); } + + public void saveAs() + { + saveManager.openSaveAsDialog(); + } public void addComponent(double x, double y) { @@@ -230,7 -226,7 +231,7 @@@ } } - public static void main(String[] args) + public static void main(String[] args) throws IOException { SaveLoadManager.openLoadDialog(); } diff --combined net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java index 06f9f4b7,2827f249..28e28554 --- a/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java +++ b/net.mograsim.logic.model.editor/src/net/mograsim/logic/model/editor/ui/EditorGUI.java @@@ -1,5 -1,5 +1,7 @@@ package net.mograsim.logic.model.editor.ui; ++import java.io.IOException; ++ import org.eclipse.swt.SWT; import org.eclipse.swt.events.SelectionEvent; import org.eclipse.swt.events.SelectionListener; @@@ -7,7 -7,6 +9,7 @@@ 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; @@@ -21,7 -20,6 +23,7 @@@ import org.eclipse.swt.widgets.ToolItem import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasOverlay; import net.haspamelodica.swt.helper.zoomablecanvas.helper.ZoomableCanvasUserInput; import net.mograsim.logic.model.editor.Editor; +import net.mograsim.logic.model.editor.SaveLoadManager; import net.mograsim.logic.model.serializing.IndirectGUIComponentCreator; public class EditorGUI @@@ -38,41 -36,29 +40,41 @@@ display = Display.getDefault(); shell = new Shell(display); - // Layout GridLayout layout = new GridLayout(); + layout.numColumns = 1; shell.setLayout(layout); - layout.numColumns = 2; - GridData d = new GridData(); - d.grabExcessVerticalSpace = true; - d.verticalAlignment = SWT.FILL; - d.verticalSpan = 2; - addList = new List(shell, SWT.V_SCROLL); - addList.setLayoutData(d); - refreshAddList(); + setupTopToolBar(shell); + Composite innerComp = new Composite(shell, SWT.NONE); + GridData innerCompData = new GridData(); + innerCompData.grabExcessHorizontalSpace = true; + innerCompData.grabExcessVerticalSpace = true; + innerCompData.horizontalAlignment = SWT.FILL; + innerCompData.verticalAlignment = SWT.FILL; + innerComp.setLayoutData(innerCompData); + + GridLayout innerLayout = new GridLayout(); + innerComp.setLayout(innerLayout); + innerLayout.numColumns = 2; - d = new GridData(); + GridData d = new GridData(); d.grabExcessHorizontalSpace = true; d.horizontalAlignment = SWT.FILL; d.grabExcessVerticalSpace = true; d.verticalAlignment = SWT.FILL; - logicCanvas = new EditorCanvas(shell, SWT.TRAIL, editor); + logicCanvas = new EditorCanvas(innerComp, SWT.TRAIL, editor); logicCanvas.setLayoutData(d); - - setupToolBar(); + + d = new GridData(); + d.grabExcessVerticalSpace = true; + d.verticalAlignment = SWT.FILL; + d.verticalSpan = 2; + addList = new List(innerComp, SWT.V_SCROLL); + addList.setLayoutData(d); + refreshAddList(); + + setupBottomToolBar(innerComp); ZoomableCanvasUserInput userInput = new ZoomableCanvasUserInput(logicCanvas); userInput.buttonDrag = 3; @@@ -81,120 -67,59 +83,128 @@@ new ZoomableCanvasOverlay(logicCanvas, null).enableScale(); } - private ToolBar setupToolBar() + private ToolBar setupTopToolBar(Composite parent) + { + GridData d = new GridData(); + d.grabExcessHorizontalSpace = true; + d.horizontalAlignment = SWT.FILL; + + ToolBar toolBar = new ToolBar(parent, SWT.BORDER); + toolBar.setLayoutData(d); + + ToolItem file = new ToolItem(toolBar, SWT.DROP_DOWN); + + //TODO +// DropDownEntry newEntry = new DropDownEntry("New", e -> { +// }); - DropDownEntry loadEntry = new DropDownEntry("Load", e -> SaveLoadManager.openLoadDialog()); ++ DropDownEntry loadEntry = new DropDownEntry("Load", e -> { ++ try ++ { ++ SaveLoadManager.openLoadDialog(); ++ } catch (IOException e1) ++ { ++ editor.dialogManager.openWarningDialog("Failed to load Component!", e1.getMessage()); ++ } ++ }); + DropDownEntry saveEntry = new DropDownEntry("Save", e -> editor.save()); + DropDownEntry saveAsEntry = new DropDownEntry("Save as...", e -> editor.saveAs()); + + DropDownEntry[] entries = new DropDownEntry[] { loadEntry, saveEntry, saveAsEntry}; + + setupDrowpDownMenu(file, entries); + + file.setText("File"); + return toolBar; + } + + private ToolBar setupBottomToolBar(Composite parent) { GridData d = new GridData(); d.grabExcessHorizontalSpace = true; d.horizontalAlignment = SWT.FILL; - ToolBar toolBar = new ToolBar(shell, SWT.BORDER); + ToolBar toolBar = new ToolBar(parent, SWT.BORDER); toolBar.setLayoutData(d); ToolItem snappingLabel = new ToolItem(toolBar, SWT.NONE); snappingLabel.setText("Snapping:"); - - Menu menu = new Menu(shell, SWT.POP_UP); + ToolItem snappSelect = new ToolItem(toolBar, SWT.DROP_DOWN); + DropDownEntry[] entries = new DropDownEntry[Editor.Snapping.values().length]; + int index = 0; for (Editor.Snapping sn : Editor.Snapping.values()) + { + entries[index++] = new DropDownEntry(sn.toString(), e -> + { + editor.setSnapping(sn); + snappSelect.setText(sn.toString()); + }); + } + snappSelect.setText(editor.getSnapping().toString()); + setupDrowpDownMenu(snappSelect, entries); + + new ToolItem(toolBar, SWT.SEPARATOR); + + toolBar.pack(); + + return toolBar; + } + + private void setupDrowpDownMenu(ToolItem parent, DropDownEntry[] entries) + { + Menu menu = new Menu(shell, SWT.POP_UP); + for (DropDownEntry entry : entries) { MenuItem item = new MenuItem(menu, SWT.PUSH); item.addSelectionListener(new SelectionListener() { @Override - public void widgetSelected(SelectionEvent arg0) + public void widgetSelected(SelectionEvent e) { - editor.setSnapping(sn); - snappSelect.setText(sn.toString()); + entry.listener.widgetSelected(e); } - + @Override - public void widgetDefaultSelected(SelectionEvent arg0) {} + public void widgetDefaultSelected(SelectionEvent e) + { + widgetSelected(e); + } }); - item.setText(sn.toString()); + item.setText(entry.title); } - - snappSelect.setText(editor.getSnapping().toString()); - snappSelect.addListener(SWT.Selection, new Listener() + + parent.addListener(SWT.Selection, new Listener() { public void handleEvent(Event event) { if (event.detail == SWT.ARROW) { - Rectangle rect = snappSelect.getBounds(); + Rectangle rect = parent.getBounds(); Point pt = new Point(rect.x, rect.y + rect.height); - pt = toolBar.toDisplay(pt); + pt = parent.getParent().toDisplay(pt); menu.setLocation(pt.x, pt.y); menu.setVisible(true); } } }); - - new ToolItem(toolBar, SWT.SEPARATOR); - - toolBar.pack(); + } - return toolBar; + private static class DropDownEntry + { + public final String title; + public final EntrySelectedListener listener; + + public DropDownEntry(String title, EntrySelectedListener listener) + { + super(); + this.title = title; + this.listener = listener; + } + } + + private static interface EntrySelectedListener + { + public void widgetSelected(SelectionEvent e); } public void refreshAddList()