mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-16 00:15:01 -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))
|
||||
setDescription(attributes.get(Keys.DESCRIPTION));
|
||||
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.lang.Lang;
|
||||
import de.neemann.gui.ErrorMessage;
|
||||
import de.neemann.gui.ToolTipAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -16,6 +17,8 @@ import java.util.ArrayList;
|
||||
public class AttributeDialog extends JDialog {
|
||||
|
||||
private final java.util.List<EditorHolder> editors;
|
||||
private final JPanel panel;
|
||||
private final Point pos;
|
||||
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) {
|
||||
super(SwingUtilities.getWindowAncestor(parent), Lang.get("attr_dialogTitle"), ModalityType.APPLICATION_MODAL);
|
||||
this.pos = pos;
|
||||
setDefaultCloseOperation(DISPOSE_ON_CLOSE);
|
||||
|
||||
JPanel panel = new JPanel(new DialogLayout());
|
||||
panel = new JPanel(new DialogLayout());
|
||||
|
||||
getContentPane().add(new JScrollPane(panel));
|
||||
|
||||
@ -68,13 +72,19 @@ public class AttributeDialog extends JDialog {
|
||||
getContentPane().add(okButton, BorderLayout.SOUTH);
|
||||
|
||||
getRootPane().setDefaultButton(okButton);
|
||||
}
|
||||
|
||||
pack();
|
||||
|
||||
if (pos == null)
|
||||
setLocationRelativeTo(null);
|
||||
else
|
||||
setLocation(pos.x, pos.y);
|
||||
/**
|
||||
* Adds a button to this dialog
|
||||
*
|
||||
* @param label a label
|
||||
* @param action the action
|
||||
* @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) {
|
||||
@ -88,6 +98,13 @@ public class AttributeDialog extends JDialog {
|
||||
* @return true if data was changed
|
||||
*/
|
||||
public boolean showDialog() {
|
||||
pack();
|
||||
|
||||
if (pos == null)
|
||||
setLocationRelativeTo(null);
|
||||
else
|
||||
setLocation(pos.x, pos.y);
|
||||
|
||||
setVisible(true);
|
||||
return changed;
|
||||
}
|
||||
|
@ -366,26 +366,39 @@ public class CircuitComponent extends JComponent {
|
||||
private void editAttributes(VisualElement vp, MouseEvent e) {
|
||||
String name = vp.getElementName();
|
||||
ElementTypeDescription elementType = library.getElementType(name);
|
||||
if (elementType instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
||||
new Main(this, ((LibrarySelector.ElementTypeDescriptionCustom) elementType).getFile(), new SavedListener() {
|
||||
@Override
|
||||
public void saved(File filename) {
|
||||
if (parentsSavedListener != null)
|
||||
parentsSavedListener.saved(filename);
|
||||
library.removeElement(filename);
|
||||
circuit.clearState();
|
||||
repaint();
|
||||
}
|
||||
}).setVisible(true);
|
||||
} else {
|
||||
ArrayList<Key> list = elementType.getAttributeList();
|
||||
if (list.size() > 0) {
|
||||
Point p = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||
if (new AttributeDialog(this, p, list, vp.getElementAttributes()).showDialog()) {
|
||||
circuit.modified();
|
||||
repaint();
|
||||
}
|
||||
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) {
|
||||
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
|
||||
public void saved(File filename) {
|
||||
if (parentsSavedListener != null)
|
||||
parentsSavedListener.saved(filename);
|
||||
library.removeElement(filename);
|
||||
circuit.clearState();
|
||||
repaint();
|
||||
}
|
||||
}).setVisible(true);
|
||||
}
|
||||
});
|
||||
}
|
||||
}.setToolTip(Lang.get("attr_openCircuit_tt")));
|
||||
}
|
||||
if (attributeDialog.showDialog()) {
|
||||
circuit.modified();
|
||||
repaint();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -57,6 +57,10 @@ key_intFormat_dec=Dezimal
|
||||
key_intFormat_hex=Hexadezimal
|
||||
key_intFormat_bin=Bin\u00E4r
|
||||
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_NAnd=Nicht Und
|
||||
|
@ -51,6 +51,9 @@ key_intFormat_dec=decimal
|
||||
key_intFormat_hex=hex
|
||||
key_intFormat_bin=bin
|
||||
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_NAnd=NAnd
|
||||
|
Loading…
x
Reference in New Issue
Block a user