diff --git a/src/main/java/de/neemann/digital/gui/Main.java b/src/main/java/de/neemann/digital/gui/Main.java index 89c4ba47d..618598680 100644 --- a/src/main/java/de/neemann/digital/gui/Main.java +++ b/src/main/java/de/neemann/digital/gui/Main.java @@ -19,6 +19,7 @@ import de.neemann.digital.draw.library.ElementLibrary; import de.neemann.digital.draw.library.ElementNotFoundException; import de.neemann.digital.draw.model.ModelCreator; import de.neemann.digital.draw.model.RealTimeClock; +import de.neemann.digital.draw.shapes.Drawable; import de.neemann.digital.draw.shapes.ShapeFactory; import de.neemann.digital.gui.components.*; import de.neemann.digital.gui.components.data.DataSetDialog; @@ -570,6 +571,7 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS edit.add(orderInputs.createJMenuItem()); edit.add(orderOutputs.createJMenuItem()); edit.add(orderMeasurements.createJMenuItem()); + edit.add(createSpecialEditMenu()); edit.addSeparator(); JMenuItem copyItem = new JMenuItem(circuitComponent.getCopyAction()); @@ -586,6 +588,40 @@ public final class Main extends JFrame implements ClosingWindowListener.ConfirmS edit.add(editSettings.createJMenuItem()); } + private JMenu createSpecialEditMenu() { + JMenu special = new JMenu(Lang.get("menu_special")); + special.add(new ToolTipAction(Lang.get("menu_addPrefix")) { + @Override + public void actionPerformed(ActionEvent actionEvent) { + String prefix = JOptionPane.showInputDialog(Lang.get("menu_addPrefix")); + + if (prefix != null && prefix.length() > 0) { + boolean modified=false; + for (Drawable d : circuitComponent.getHighLighted()) { + if (d instanceof VisualElement) { + VisualElement v = (VisualElement) d; + if (v.equalsDescription(In.DESCRIPTION) || v.equalsDescription(Out.DESCRIPTION)) { + ElementAttributes attr = v.getElementAttributes(); + String l = prefix + attr.getLabel(); + attr.set(Keys.LABEL, l); + modified=true; + } + } + } + if (modified) + circuitComponent.hasChanged(); + } + } + }.setToolTip(Lang.get("menu_addPrefix_tt")).createJMenuItem()); + special.add(new ToolTipAction(Lang.get("menu_numbering")) { + @Override + public void actionPerformed(ActionEvent actionEvent) { + new NumberingWizard(Main.this, circuitComponent).start(); + } + }.setToolTip(Lang.get("menu_numbering_tt")).createJMenuItem()); + return special; + } + /** * Creates the start menu * diff --git a/src/main/java/de/neemann/digital/gui/NumberingWizard.java b/src/main/java/de/neemann/digital/gui/NumberingWizard.java new file mode 100644 index 000000000..ce20eb09d --- /dev/null +++ b/src/main/java/de/neemann/digital/gui/NumberingWizard.java @@ -0,0 +1,74 @@ +package de.neemann.digital.gui; + +import de.neemann.digital.core.element.Keys; +import de.neemann.digital.core.io.In; +import de.neemann.digital.core.io.Out; +import de.neemann.digital.draw.elements.VisualElement; +import de.neemann.digital.gui.components.CircuitComponent; +import de.neemann.digital.lang.Lang; + +import javax.swing.*; +import java.awt.event.WindowAdapter; +import java.awt.event.WindowEvent; + +/** + * Wizard for pin numbering + * Created by hneemann on 14.05.17. + */ +public class NumberingWizard extends JDialog implements CircuitComponent.WizardNotification { + private final CircuitComponent circuitComponent; + private final JLabel label; + private int pinNumber; + + /** + * Creates a new instance + * @param parent the parent frame + * @param circuitComponent the component used to select the inputs and outputs + */ + public NumberingWizard(JFrame parent, CircuitComponent circuitComponent) { + super(parent, Lang.get("msg_numberingWizard"), false); + setDefaultCloseOperation(DISPOSE_ON_CLOSE); + this.circuitComponent = circuitComponent; + pinNumber = 0; + label = new JLabel("________________"); + getContentPane().add(label); + + addWindowListener(new WindowAdapter() { + @Override + public void windowClosed(WindowEvent windowEvent) { + circuitComponent.deactivateWizard(); + } + }); + pack(); + incPinNumber(); + setAlwaysOnTop(true); + setLocation(parent.getLocation()); + } + + private void incPinNumber() { + pinNumber++; + label.setText(Lang.get("msg_pin_N", pinNumber)); + } + + /** + * Start the wizard + */ + public void start() { + setVisible(true); + circuitComponent.activateWizard(this); + } + + @Override + public void notify(VisualElement clicked) { + if (clicked.equalsDescription(In.DESCRIPTION) || clicked.equalsDescription(Out.DESCRIPTION)) { + clicked.getElementAttributes().set(Keys.PINNUMBER, pinNumber); + incPinNumber(); + circuitComponent.hasChanged(); + } + } + + @Override + public void closed() { + dispose(); + } +} 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 39dde4fab..fad6f80c8 100644 --- a/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java +++ b/src/main/java/de/neemann/digital/gui/components/CircuitComponent.java @@ -763,6 +763,20 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe public void escapePressed() { } } + + + private VisualElement getVisualElement(Vector pos, boolean includeText) { + VisualElement vp = null; + List list = circuit.getElementListAt(pos, includeText); + if (list.size() == 1) + vp = list.get(0); + else if (list.size() > 1) { + ItemPicker picker = new ItemPicker<>(CircuitComponent.this, list); + vp = picker.select(); + } + return vp; + } + //CHECKSTYLE.ON: FinalClass private final class MouseControllerNormal extends MouseController { @@ -773,18 +787,6 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe super(cursor); } - private VisualElement getVisualElement(Vector pos, boolean includeText) { - VisualElement vp = null; - List list = circuit.getElementListAt(pos, includeText); - if (list.size() == 1) - vp = list.get(0); - else if (list.size() > 1) { - ItemPicker picker = new ItemPicker<>(CircuitComponent.this, list); - vp = picker.select(); - } - return vp; - } - @Override void clicked(MouseEvent e) { Vector pos = getPosVector(e); @@ -1400,4 +1402,65 @@ public class CircuitComponent extends JComponent implements Circuit.ChangedListe } } + /** + * Activate a wizard + * + * @param wizardNotification the wizard notification + */ + public void activateWizard(WizardNotification wizardNotification) { + new MouseControllerWizard(wizardNotification).activate(); + } + + /** + * Deactivate a wizard + */ + public void deactivateWizard() { + if (activeMouseController instanceof MouseControllerWizard) { + MouseControllerWizard mcw = (MouseControllerWizard) activeMouseController; + mcw.wizardNotification.closed(); + } + mouseNormal.activate(); + } + + private final class MouseControllerWizard extends MouseController { + + private final WizardNotification wizardNotification; + + private MouseControllerWizard(WizardNotification wizardNotification) { + super(new Cursor(Cursor.CROSSHAIR_CURSOR)); + this.wizardNotification = wizardNotification; + } + + @Override + void clicked(MouseEvent e) { + Vector pos = getPosVector(e); + VisualElement vp = getVisualElement(pos, true); + if (vp != null) + wizardNotification.notify(vp); + } + + @Override + public void escapePressed() { + wizardNotification.closed(); + mouseNormal.activate(); + } + } + + /** + * Interface to interact with wizards + */ + public interface WizardNotification { + /** + * Called if an element is clicked + * + * @param clicked the element clicked + */ + void notify(VisualElement clicked); + + /** + * Called if the wizard is to close + */ + void closed(); + } + } diff --git a/src/main/java/de/neemann/gui/LineBreaker.java b/src/main/java/de/neemann/gui/LineBreaker.java index 6a997d4cf..c619efc3a 100644 --- a/src/main/java/de/neemann/gui/LineBreaker.java +++ b/src/main/java/de/neemann/gui/LineBreaker.java @@ -58,6 +58,9 @@ public class LineBreaker { if (text == null) return null; + if (text.startsWith("")) + return text; + for (int i = 0; i < indent - label.length(); i++) outText.append(" "); diff --git a/src/main/java/de/neemann/gui/ToolTipAction.java b/src/main/java/de/neemann/gui/ToolTipAction.java index 947bdf1c8..ddde53148 100644 --- a/src/main/java/de/neemann/gui/ToolTipAction.java +++ b/src/main/java/de/neemann/gui/ToolTipAction.java @@ -55,7 +55,7 @@ public abstract class ToolTipAction extends AbstractAction { * @return this for call chaining */ public ToolTipAction setToolTip(String text) { - this.toolTipText = text; + this.toolTipText = new LineBreaker().toHTML().breakLines(text); return this; } diff --git a/src/main/resources/lang/lang_de.xml b/src/main/resources/lang/lang_de.xml index 256b00590..f8864e170 100644 --- a/src/main/resources/lang/lang_de.xml +++ b/src/main/resources/lang/lang_de.xml @@ -774,6 +774,14 @@ Sind evtl. die Namen der Variablen nicht eindeutig? Baumansicht der Bauteile Zeigt am linken Rand des Fensters eine Baumansicht der verfügbaren Bauteile. + Sonderfunktionen 74xx + IO-Präfix + Alle selektierten Eingänge und Ausgänge mit einem Präfix versehen. + Kann verwendet werden um die Bezeichnung der Ein- und Ausgänge nach dem Kopieren anzupassen. + Dies vereinfacht die Erzeugung von 74xx Schaltungen. + Pinnummerierung + Wizard zur einfachen Nummerierung der Pins. + Digital Ein einfacher Simulator für digitale Schaltkreise. @@ -827,6 +835,7 @@ Die Icons stammen aus dem Tango Desktop Project. Das kopieren von Elementen und die Konfiguration von Dioden und FG-FETs mit der Taste [P] ist auch im gesperrten Zustand möglich. Fehler bei der Ausführung des Geschwindigkeitstests! Pin {0} + Nummerierungshilfe Ok diff --git a/src/main/resources/lang/lang_en.xml b/src/main/resources/lang/lang_en.xml index eab375a34..4b0c091fe 100644 --- a/src/main/resources/lang/lang_en.xml +++ b/src/main/resources/lang/lang_en.xml @@ -765,6 +765,14 @@ The names of the variables may not be unique. Component Tree View Shows a tree view of available components at the left side. + Special 74xx Funtions + Add IO-Prefix + A prefix is added to all selected inputs and outputs. + Is used to simplify the doubling of circuits within a 74xx circuit. + Pin Numbering + Wizard to apply pin numbers to the inputs and outputs. + + Digital A simple simulator for digital circuits. @@ -817,6 +825,7 @@ The icons are taken from the Tango Desktop Project. However, copying of components and the configuration of diodes and FG-FETs with the [P] key is also possible in the locked mode. Error during speed test! Pin {0} + Numbering Wizard Ok