mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-17 00:44:40 -04:00
also custom elements can have a label or an orientation
This commit is contained in:
parent
cc461277c3
commit
06ec31bafc
@ -267,6 +267,8 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
|||||||
if (attributes.contains(Keys.DESCRIPTION))
|
if (attributes.contains(Keys.DESCRIPTION))
|
||||||
setDescription(attributes.get(Keys.DESCRIPTION));
|
setDescription(attributes.get(Keys.DESCRIPTION));
|
||||||
setShortName(file.getName());
|
setShortName(file.getName());
|
||||||
|
addAttribute(Keys.ROTATE);
|
||||||
|
addAttribute(Keys.LABEL);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -4,6 +4,7 @@ import de.neemann.digital.core.element.ElementAttributes;
|
|||||||
import de.neemann.digital.core.element.Key;
|
import de.neemann.digital.core.element.Key;
|
||||||
import de.neemann.digital.lang.Lang;
|
import de.neemann.digital.lang.Lang;
|
||||||
import de.neemann.gui.ErrorMessage;
|
import de.neemann.gui.ErrorMessage;
|
||||||
|
import de.neemann.gui.ToolTipAction;
|
||||||
|
|
||||||
import javax.swing.*;
|
import javax.swing.*;
|
||||||
import java.awt.*;
|
import java.awt.*;
|
||||||
@ -16,6 +17,8 @@ import java.util.ArrayList;
|
|||||||
public class AttributeDialog extends JDialog {
|
public class AttributeDialog extends JDialog {
|
||||||
|
|
||||||
private final java.util.List<EditorHolder> editors;
|
private final java.util.List<EditorHolder> editors;
|
||||||
|
private final JPanel panel;
|
||||||
|
private final Point pos;
|
||||||
private boolean changed = false;
|
private boolean changed = false;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -39,9 +42,10 @@ public class AttributeDialog extends JDialog {
|
|||||||
*/
|
*/
|
||||||
public AttributeDialog(Component parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes) {
|
public AttributeDialog(Component parent, Point pos, java.util.List<Key> list, ElementAttributes elementAttributes) {
|
||||||
super(SwingUtilities.getWindowAncestor(parent), Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
|
super(SwingUtilities.getWindowAncestor(parent), Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
|
||||||
|
this.pos = pos;
|
||||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||||
|
|
||||||
JPanel panel = new JPanel(new DialogLayout());
|
panel = new JPanel(new DialogLayout());
|
||||||
|
|
||||||
getContentPane().add(new JScrollPane(panel));
|
getContentPane().add(new JScrollPane(panel));
|
||||||
|
|
||||||
@ -68,13 +72,19 @@ public class AttributeDialog extends JDialog {
|
|||||||
getContentPane().add(okButton, BorderLayout.SOUTH);
|
getContentPane().add(okButton, BorderLayout.SOUTH);
|
||||||
|
|
||||||
getRootPane().setDefaultButton(okButton);
|
getRootPane().setDefaultButton(okButton);
|
||||||
|
}
|
||||||
|
|
||||||
pack();
|
/**
|
||||||
|
* Adds a button to this dialog
|
||||||
if (pos == null)
|
*
|
||||||
setLocationRelativeTo(null);
|
* @param label a label
|
||||||
else
|
* @param action the action
|
||||||
setLocation(pos.x, pos.y);
|
* @return this for chained calls
|
||||||
|
*/
|
||||||
|
public AttributeDialog addButton(String label, ToolTipAction action) {
|
||||||
|
panel.add(new JLabel(label), DialogLayout.LABEL);
|
||||||
|
panel.add(action.createJButton(), DialogLayout.INPUT);
|
||||||
|
return this;
|
||||||
}
|
}
|
||||||
|
|
||||||
private void setEditedValues(ElementAttributes attr) {
|
private void setEditedValues(ElementAttributes attr) {
|
||||||
@ -88,6 +98,13 @@ public class AttributeDialog extends JDialog {
|
|||||||
* @return true if data was changed
|
* @return true if data was changed
|
||||||
*/
|
*/
|
||||||
public boolean showDialog() {
|
public boolean showDialog() {
|
||||||
|
pack();
|
||||||
|
|
||||||
|
if (pos == null)
|
||||||
|
setLocationRelativeTo(null);
|
||||||
|
else
|
||||||
|
setLocation(pos.x, pos.y);
|
||||||
|
|
||||||
setVisible(true);
|
setVisible(true);
|
||||||
return changed;
|
return changed;
|
||||||
}
|
}
|
||||||
|
@ -366,8 +366,22 @@ public class CircuitComponent extends JComponent {
|
|||||||
private void editAttributes(VisualElement vp, MouseEvent e) {
|
private void editAttributes(VisualElement vp, MouseEvent e) {
|
||||||
String name = vp.getElementName();
|
String name = vp.getElementName();
|
||||||
ElementTypeDescription elementType = library.getElementType(name);
|
ElementTypeDescription elementType = library.getElementType(name);
|
||||||
|
ArrayList<Key> list = elementType.getAttributeList();
|
||||||
|
if (list.size() > 0) {
|
||||||
|
Point p = new Point(e.getX(), e.getY());
|
||||||
|
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||||
|
AttributeDialog attributeDialog = new AttributeDialog(this, p, list, vp.getElementAttributes());
|
||||||
if (elementType instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
if (elementType instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
||||||
new Main(this, ((LibrarySelector.ElementTypeDescriptionCustom) elementType).getFile(), new SavedListener() {
|
attributeDialog.addButton(Lang.get("attr_openCircuitLabel"), new ToolTipAction(Lang.get("attr_openCircuit")) {
|
||||||
|
@Override
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
attributeDialog.dispose();
|
||||||
|
SwingUtilities.invokeLater(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
new Main(CircuitComponent.this,
|
||||||
|
((LibrarySelector.ElementTypeDescriptionCustom) elementType).getFile(),
|
||||||
|
new SavedListener() {
|
||||||
@Override
|
@Override
|
||||||
public void saved(File filename) {
|
public void saved(File filename) {
|
||||||
if (parentsSavedListener != null)
|
if (parentsSavedListener != null)
|
||||||
@ -377,18 +391,17 @@ public class CircuitComponent extends JComponent {
|
|||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}).setVisible(true);
|
}).setVisible(true);
|
||||||
} else {
|
}
|
||||||
ArrayList<Key> list = elementType.getAttributeList();
|
});
|
||||||
if (list.size() > 0) {
|
}
|
||||||
Point p = new Point(e.getX(), e.getY());
|
}.setToolTip(Lang.get("attr_openCircuit_tt")));
|
||||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
}
|
||||||
if (new AttributeDialog(this, p, list, vp.getElementAttributes()).showDialog()) {
|
if (attributeDialog.showDialog()) {
|
||||||
circuit.modified();
|
circuit.modified();
|
||||||
repaint();
|
repaint();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
private class MouseDispatcher extends MouseAdapter implements MouseMotionListener {
|
private class MouseDispatcher extends MouseAdapter implements MouseMotionListener {
|
||||||
private Vector pos;
|
private Vector pos;
|
||||||
|
@ -57,6 +57,10 @@ key_intFormat_dec=Dezimal
|
|||||||
key_intFormat_hex=Hexadezimal
|
key_intFormat_hex=Hexadezimal
|
||||||
key_intFormat_bin=Bin\u00E4r
|
key_intFormat_bin=Bin\u00E4r
|
||||||
key_intFormat_ascii=ASCII
|
key_intFormat_ascii=ASCII
|
||||||
|
attr_openCircuitLabel=Schaltung anzeigen:
|
||||||
|
attr_openCircuit=Anzeigen
|
||||||
|
attr_openCircuit_tt=\u00D6ffnet die Schaltung in einem neuen Fenster.
|
||||||
|
|
||||||
|
|
||||||
elem_And=Und
|
elem_And=Und
|
||||||
elem_NAnd=Nicht Und
|
elem_NAnd=Nicht Und
|
||||||
|
@ -51,6 +51,9 @@ key_intFormat_dec=decimal
|
|||||||
key_intFormat_hex=hex
|
key_intFormat_hex=hex
|
||||||
key_intFormat_bin=bin
|
key_intFormat_bin=bin
|
||||||
key_intFormat_ascii=ascii
|
key_intFormat_ascii=ascii
|
||||||
|
attr_openCircuitLabel=Opens the circuit:
|
||||||
|
attr_openCircuit=Open
|
||||||
|
attr_openCircuit_tt=Opens the circuit in a new window.
|
||||||
|
|
||||||
elem_And=And
|
elem_And=And
|
||||||
elem_NAnd=NAnd
|
elem_NAnd=NAnd
|
||||||
|
Loading…
x
Reference in New Issue
Block a user