diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index 3325823bc..910175ed4 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -76,6 +76,9 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E private static final Icon ICON_SAVE = IconCreator.create("Save24.gif"); private static final Icon ICON_SAVE_AS = IconCreator.create("SaveAs24.gif"); private static final Icon ICON_FAST = IconCreator.create("FastForward24.gif"); + private static final Icon ICON_EXPAND = IconCreator.create("Expand24.gif"); + private static final Icon ICON_ZOOMIN = IconCreator.create("ZoomIn24.gif"); + private static final Icon ICON_ZOOMOUT = IconCreator.create("ZoomOut24.gif"); private final CircuitComponent circuitComponent; private final ToolTipAction save; private ToolTipAction doStep; @@ -180,6 +183,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E save = createFileMenu(menuBar, toolBar, normalMode); toolBar.addSeparator(); + createViewMenu(menuBar, toolBar); + + toolBar.addSeparator(); + ToolTipAction elementStateAction = elementState.createToolTipAction(Lang.get("menu_element"), ICON_ELEMENT).setToolTip(Lang.get("menu_element_tt")); createEditMenu(menuBar, elementStateAction); @@ -207,6 +214,30 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E setLocationRelativeTo(parent); } + private void createViewMenu(JMenuBar menuBar, JToolBar toolBar) { + ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) { + @Override + public void actionPerformed(ActionEvent e) { + circuitComponent.fitCircuit(); + } + }; + ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOMIN) { + @Override + public void actionPerformed(ActionEvent e) { + circuitComponent.scaleCircuit(1.2); + } + }; + ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOMOUT) { + @Override + public void actionPerformed(ActionEvent e) { + circuitComponent.scaleCircuit(0.8); + } + }; + toolBar.add(zoomIn.createJButtonNoText()); + toolBar.add(zoomOut.createJButtonNoText()); + toolBar.add(maximize.createJButtonNoText()); + } + /** * Creates the file menu and adds it to menu and toolbar * diff --git a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java index ea9106a9e..1563403d9 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -271,7 +271,14 @@ public class CircuitComponent extends JComponent { */ public void setCircuit(Circuit circuit) { this.circuit = circuit; + fitCircuit(); + setModeAndReset(false); + } + /** + * maximizes the circuit shown + */ + public void fitCircuit() { GraphicMinMax gr = new GraphicMinMax(); circuit.drawTo(gr); if (gr.getMin() != null && getWidth() != 0 && getHeight() != 0) { @@ -290,8 +297,26 @@ public class CircuitComponent extends JComponent { transform.translate(dif.x / s, dif.y / s); // move drawing center to frame center } else transform = new AffineTransform(); + repaint(); + } - setModeAndReset(false); + /** + * scales the circuit + * + * @param f factor to scale + */ + public void scaleCircuit(double f) { + try { + Point2D.Double p = new Point2D.Double(); + transform.inverseTransform(new Point(getWidth() / 2, getHeight() / 2), p); + Vector dif = new Vector((int) Math.round(p.getX()), (int) Math.round(p.getY())); + transform.translate(dif.x, dif.y); + transform.scale(f, f); + transform.translate(-dif.x, -dif.y); + repaint(); + } catch (NoninvertibleTransformException e1) { + throw new RuntimeException(e1); + } } private void editAttributes(VisualElement vp, MouseEvent e) { @@ -336,7 +361,7 @@ public class CircuitComponent extends JComponent { @Override public void mouseReleased(MouseEvent e) { activeMouseController.released(e); - if (!wasMoved(e)) + if (!(wasMoved(e) || isMoved)) activeMouseController.clicked(e); } diff --git a/src/main/resources/lang/lang_de.properties b/src/main/resources/lang/lang_de.properties index ea85b8094..4998ee661 100644 --- a/src/main/resources/lang/lang_de.properties +++ b/src/main/resources/lang/lang_de.properties @@ -270,6 +270,11 @@ menu_analyse=Analyse menu_analyse_tt=Analyse der aktuellen Schaltung menu_synthesise=Synthese menu_synthesise_tt=Erzeugt minimale boolsche Ausdr\u00FCcke, welche durch eine Wahrheitstabelle beschrieben werden. +menu_maximize=maximieren +menu_zoomIn=vergr\u00F6\u00DFern +menu_zoomOut=verkleinern + + menu_table_size=Gr\u00F6\u00DFe menu_table_N_variables={0} Variablen menu_table_reorder=Umsortieren diff --git a/src/main/resources/lang/lang_en.properties b/src/main/resources/lang/lang_en.properties index 0f045a12b..6c63c5ad9 100644 --- a/src/main/resources/lang/lang_en.properties +++ b/src/main/resources/lang/lang_en.properties @@ -249,6 +249,11 @@ menu_analyse=Analyse menu_analyse_tt=Analyses the actual circuit menu_synthesise=Synthesise menu_synthesise_tt=Generates the minimal bool expressions described by a truth table. +menu_maximize=Maximize +menu_zoomIn=zoom in +menu_zoomOut=zoom out + + menu_table_size=Size menu_table_N_variables={0} Variables menu_table_reorder=Reorder