mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-27 06:51:37 -04:00
added helper function to create 74xx circuits
This commit is contained in:
parent
e6d50cc87d
commit
6ffa8d560a
@ -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
|
||||
*
|
||||
|
74
src/main/java/de/neemann/digital/gui/NumberingWizard.java
Normal file
74
src/main/java/de/neemann/digital/gui/NumberingWizard.java
Normal file
@ -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();
|
||||
}
|
||||
}
|
@ -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<VisualElement> list = circuit.getElementListAt(pos, includeText);
|
||||
if (list.size() == 1)
|
||||
vp = list.get(0);
|
||||
else if (list.size() > 1) {
|
||||
ItemPicker<VisualElement> 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<VisualElement> list = circuit.getElementListAt(pos, includeText);
|
||||
if (list.size() == 1)
|
||||
vp = list.get(0);
|
||||
else if (list.size() > 1) {
|
||||
ItemPicker<VisualElement> 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();
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -58,6 +58,9 @@ public class LineBreaker {
|
||||
if (text == null)
|
||||
return null;
|
||||
|
||||
if (text.startsWith("<html>"))
|
||||
return text;
|
||||
|
||||
for (int i = 0; i < indent - label.length(); i++)
|
||||
outText.append(" ");
|
||||
|
||||
|
@ -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;
|
||||
}
|
||||
|
||||
|
@ -774,6 +774,14 @@ Sind evtl. die Namen der Variablen nicht eindeutig?</string>
|
||||
<string name="menu_treeSelect">Baumansicht der Bauteile</string>
|
||||
<string name="menu_treeSelect_tt">Zeigt am linken Rand des Fensters eine Baumansicht der verfügbaren Bauteile.</string>
|
||||
|
||||
<string name="menu_special">Sonderfunktionen 74xx</string>
|
||||
<string name="menu_addPrefix">IO-Präfix</string>
|
||||
<string name="menu_addPrefix_tt">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.</string>
|
||||
<string name="menu_numbering">Pinnummerierung</string>
|
||||
<string name="menu_numbering_tt">Wizard zur einfachen Nummerierung der Pins.</string>
|
||||
|
||||
<string name="message">Digital
|
||||
|
||||
Ein einfacher Simulator für digitale Schaltkreise.
|
||||
@ -827,6 +835,7 @@ Die Icons stammen aus dem Tango Desktop Project.</string>
|
||||
Das kopieren von Elementen und die Konfiguration von Dioden und FG-FETs mit der Taste [P] ist auch im gesperrten Zustand möglich.</string>
|
||||
<string name="msg_speedTestError">Fehler bei der Ausführung des Geschwindigkeitstests!</string>
|
||||
<string name="msg_pin_N">Pin {0}</string>
|
||||
<string name="msg_numberingWizard">Nummerierungshilfe</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
@ -765,6 +765,14 @@ The names of the variables may not be unique.</string>
|
||||
<string name="menu_treeSelect">Component Tree View</string>
|
||||
<string name="menu_treeSelect_tt">Shows a tree view of available components at the left side.</string>
|
||||
|
||||
<string name="menu_special">Special 74xx Funtions</string>
|
||||
<string name="menu_addPrefix">Add IO-Prefix</string>
|
||||
<string name="menu_addPrefix_tt">A prefix is added to all selected inputs and outputs.
|
||||
Is used to simplify the doubling of circuits within a 74xx circuit.</string>
|
||||
<string name="menu_numbering">Pin Numbering</string>
|
||||
<string name="menu_numbering_tt">Wizard to apply pin numbers to the inputs and outputs.</string>
|
||||
|
||||
|
||||
<string name="message">Digital
|
||||
|
||||
A simple simulator for digital circuits.
|
||||
@ -817,6 +825,7 @@ The icons are taken from the Tango Desktop Project.</string>
|
||||
However, copying of components and the configuration of diodes and FG-FETs with the [P] key is also possible in the locked mode.</string>
|
||||
<string name="msg_speedTestError">Error during speed test!</string>
|
||||
<string name="msg_pin_N">Pin {0}</string>
|
||||
<string name="msg_numberingWizard">Numbering Wizard</string>
|
||||
|
||||
<string name="ok">Ok</string>
|
||||
<string name="rot_0">0°</string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user