mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 00:44:40 -04:00
added fit, zoom in and zoom out
This commit is contained in:
parent
4e83d6d01e
commit
cc798f48f5
@ -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 = IconCreator.create("Save24.gif");
|
||||||
private static final Icon ICON_SAVE_AS = IconCreator.create("SaveAs24.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_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 CircuitComponent circuitComponent;
|
||||||
private final ToolTipAction save;
|
private final ToolTipAction save;
|
||||||
private ToolTipAction doStep;
|
private ToolTipAction doStep;
|
||||||
@ -180,6 +183,10 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
save = createFileMenu(menuBar, toolBar, normalMode);
|
save = createFileMenu(menuBar, toolBar, normalMode);
|
||||||
toolBar.addSeparator();
|
toolBar.addSeparator();
|
||||||
|
|
||||||
|
createViewMenu(menuBar, toolBar);
|
||||||
|
|
||||||
|
toolBar.addSeparator();
|
||||||
|
|
||||||
ToolTipAction elementStateAction = elementState.createToolTipAction(Lang.get("menu_element"), ICON_ELEMENT).setToolTip(Lang.get("menu_element_tt"));
|
ToolTipAction elementStateAction = elementState.createToolTipAction(Lang.get("menu_element"), ICON_ELEMENT).setToolTip(Lang.get("menu_element_tt"));
|
||||||
|
|
||||||
createEditMenu(menuBar, elementStateAction);
|
createEditMenu(menuBar, elementStateAction);
|
||||||
@ -207,6 +214,30 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave, E
|
|||||||
setLocationRelativeTo(parent);
|
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
|
* Creates the file menu and adds it to menu and toolbar
|
||||||
*
|
*
|
||||||
|
@ -271,7 +271,14 @@ public class CircuitComponent extends JComponent {
|
|||||||
*/
|
*/
|
||||||
public void setCircuit(Circuit circuit) {
|
public void setCircuit(Circuit circuit) {
|
||||||
this.circuit = circuit;
|
this.circuit = circuit;
|
||||||
|
fitCircuit();
|
||||||
|
setModeAndReset(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* maximizes the circuit shown
|
||||||
|
*/
|
||||||
|
public void fitCircuit() {
|
||||||
GraphicMinMax gr = new GraphicMinMax();
|
GraphicMinMax gr = new GraphicMinMax();
|
||||||
circuit.drawTo(gr);
|
circuit.drawTo(gr);
|
||||||
if (gr.getMin() != null && getWidth() != 0 && getHeight() != 0) {
|
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
|
transform.translate(dif.x / s, dif.y / s); // move drawing center to frame center
|
||||||
} else
|
} else
|
||||||
transform = new AffineTransform();
|
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) {
|
private void editAttributes(VisualElement vp, MouseEvent e) {
|
||||||
@ -336,7 +361,7 @@ public class CircuitComponent extends JComponent {
|
|||||||
@Override
|
@Override
|
||||||
public void mouseReleased(MouseEvent e) {
|
public void mouseReleased(MouseEvent e) {
|
||||||
activeMouseController.released(e);
|
activeMouseController.released(e);
|
||||||
if (!wasMoved(e))
|
if (!(wasMoved(e) || isMoved))
|
||||||
activeMouseController.clicked(e);
|
activeMouseController.clicked(e);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -270,6 +270,11 @@ menu_analyse=Analyse
|
|||||||
menu_analyse_tt=Analyse der aktuellen Schaltung
|
menu_analyse_tt=Analyse der aktuellen Schaltung
|
||||||
menu_synthesise=Synthese
|
menu_synthesise=Synthese
|
||||||
menu_synthesise_tt=Erzeugt minimale boolsche Ausdr\u00FCcke, welche durch eine Wahrheitstabelle beschrieben werden.
|
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_size=Gr\u00F6\u00DFe
|
||||||
menu_table_N_variables={0} Variablen
|
menu_table_N_variables={0} Variablen
|
||||||
menu_table_reorder=Umsortieren
|
menu_table_reorder=Umsortieren
|
||||||
|
@ -249,6 +249,11 @@ menu_analyse=Analyse
|
|||||||
menu_analyse_tt=Analyses the actual circuit
|
menu_analyse_tt=Analyses the actual circuit
|
||||||
menu_synthesise=Synthesise
|
menu_synthesise=Synthesise
|
||||||
menu_synthesise_tt=Generates the minimal bool expressions described by a truth table.
|
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_size=Size
|
||||||
menu_table_N_variables={0} Variables
|
menu_table_N_variables={0} Variables
|
||||||
menu_table_reorder=Reorder
|
menu_table_reorder=Reorder
|
||||||
|
Loading…
x
Reference in New Issue
Block a user