mirror of
https://github.com/hneemann/Digital.git
synced 2025-09-15 07:48:29 -04:00
open nested models by clicking right
This commit is contained in:
parent
59bc557fc1
commit
bd5f37fdf0
@ -33,7 +33,7 @@ public final class ShapeFactory {
|
||||
return InstanceHolder.INSTANCE;
|
||||
}
|
||||
|
||||
public HashMap<String, Creator> map = new HashMap<>();
|
||||
private HashMap<String, Creator> map = new HashMap<>();
|
||||
private ElementLibrary library;
|
||||
|
||||
private ShapeFactory() {
|
||||
|
@ -1,5 +1,6 @@
|
||||
package de.neemann.digital.gui;
|
||||
|
||||
import de.neemann.digital.core.element.ElementFactory;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
@ -13,6 +14,7 @@ import de.neemann.gui.ErrorMessage;
|
||||
import de.neemann.gui.ToolTipAction;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.filechooser.FileNameExtensionFilter;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
@ -22,7 +24,6 @@ import java.util.ArrayList;
|
||||
*/
|
||||
public class LibrarySelector implements ElementNotFoundNotification {
|
||||
private final ElementLibrary library;
|
||||
private File lastFile;
|
||||
private File filePath;
|
||||
private JMenu customMenu;
|
||||
private InsertHistory insertHistory;
|
||||
@ -46,7 +47,8 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
customMenu.add(new ToolTipAction(Lang.get("menu_import")) {
|
||||
@Override
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
JFileChooser fc = Main.getjFileChooser(lastFile);
|
||||
JFileChooser fc = new JFileChooser(filePath);
|
||||
fc.addChoosableFileFilter(new FileNameExtensionFilter("Circuit", "dig"));
|
||||
if (fc.showOpenDialog(null) == JFileChooser.APPROVE_OPTION) {
|
||||
importElement(fc.getSelectedFile());
|
||||
}
|
||||
@ -79,10 +81,6 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
return parts;
|
||||
}
|
||||
|
||||
public void setLastFile(File lastFile) {
|
||||
this.lastFile = lastFile;
|
||||
}
|
||||
|
||||
public void setFilePath(File filePath) {
|
||||
this.filePath = filePath;
|
||||
}
|
||||
@ -118,7 +116,7 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
System.out.println("load element " + file);
|
||||
Circuit circuit = Circuit.loadCircuit(file);
|
||||
ElementTypeDescription description =
|
||||
new ElementTypeDescription(file.getName(),
|
||||
new ElementTypeDescriptionCustom(file,
|
||||
attributes -> new CustomElement(circuit, library, file.getName()),
|
||||
circuit.getInputNames(library))
|
||||
.setShortName(createShortName(file));
|
||||
@ -150,4 +148,17 @@ public class LibrarySelector implements ElementNotFoundNotification {
|
||||
this.menuEntry = menuEntry;
|
||||
}
|
||||
}
|
||||
|
||||
public static class ElementTypeDescriptionCustom extends ElementTypeDescription {
|
||||
private final File file;
|
||||
|
||||
public ElementTypeDescriptionCustom(File file, ElementFactory elementFactory, String... inputNames) {
|
||||
super(file.getName(), elementFactory, inputNames);
|
||||
this.file = file;
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
return file;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -53,7 +53,11 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
private Model model;
|
||||
private ModelDescription modelDescription;
|
||||
|
||||
public Main(File fileToOpen) {
|
||||
public Main() {
|
||||
this(null, null);
|
||||
}
|
||||
|
||||
public Main(Component parent, File fileToOpen) {
|
||||
super(Lang.get("digital"));
|
||||
setDefaultCloseOperation(DO_NOTHING_ON_CLOSE);
|
||||
|
||||
@ -73,10 +77,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
|
||||
addWindowListener(new ClosingWindowListener(this, this));
|
||||
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
pack();
|
||||
setLocationRelativeTo(null);
|
||||
|
||||
JMenuBar bar = new JMenuBar();
|
||||
|
||||
|
||||
@ -108,7 +108,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
if (ClosingWindowListener.checkForSave(Main.this, Main.this)) {
|
||||
JFileChooser fc = getjFileChooser(lastFilename);
|
||||
if (fc.showOpenDialog(Main.this) == JFileChooser.APPROVE_OPTION) {
|
||||
Main m = new Main(fc.getSelectedFile());
|
||||
Main m = new Main(Main.this, fc.getSelectedFile());
|
||||
m.setLocationRelativeTo(Main.this);
|
||||
m.setVisible(true);
|
||||
}
|
||||
@ -261,10 +261,14 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
|
||||
setJMenuBar(bar);
|
||||
InfoDialog.getInstance().addToFrame(this, MESSAGE);
|
||||
|
||||
setPreferredSize(new Dimension(800, 600));
|
||||
pack();
|
||||
setLocationRelativeTo(parent);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
SwingUtilities.invokeLater(() -> new Main(null).setVisible(true));
|
||||
SwingUtilities.invokeLater(() -> new Main().setVisible(true));
|
||||
}
|
||||
|
||||
private void createAndStartModel(boolean runClock) {
|
||||
@ -309,7 +313,7 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
}
|
||||
}
|
||||
|
||||
public static JFileChooser getjFileChooser(File filename) {
|
||||
private static JFileChooser getjFileChooser(File filename) {
|
||||
JFileChooser fileChooser = new JFileChooser(filename == null ? null : filename.getParentFile());
|
||||
fileChooser.addChoosableFileFilter(new FileNameExtensionFilter("Circuit", "dig"));
|
||||
return fileChooser;
|
||||
@ -352,7 +356,6 @@ public class Main extends JFrame implements ClosingWindowListener.ConfirmSave {
|
||||
private void setFilename(File filename) {
|
||||
this.filename = filename;
|
||||
if (filename != null) {
|
||||
librarySelector.setLastFile(filename);
|
||||
this.lastFilename = filename;
|
||||
prefs.put("name", filename.getPath());
|
||||
setTitle(filename + " - " + Lang.get("digital"));
|
||||
|
@ -2,6 +2,7 @@ package de.neemann.digital.gui.components;
|
||||
|
||||
import de.neemann.digital.core.Observer;
|
||||
import de.neemann.digital.core.element.AttributeKey;
|
||||
import de.neemann.digital.core.element.ElementTypeDescription;
|
||||
import de.neemann.digital.draw.elements.Circuit;
|
||||
import de.neemann.digital.draw.elements.Moveable;
|
||||
import de.neemann.digital.draw.elements.VisualElement;
|
||||
@ -11,6 +12,8 @@ import de.neemann.digital.draw.graphics.Polygon;
|
||||
import de.neemann.digital.draw.library.ElementLibrary;
|
||||
import de.neemann.digital.draw.shapes.Drawable;
|
||||
import de.neemann.digital.draw.shapes.GenericShape;
|
||||
import de.neemann.digital.gui.LibrarySelector;
|
||||
import de.neemann.digital.gui.Main;
|
||||
|
||||
import javax.swing.*;
|
||||
import java.awt.*;
|
||||
@ -316,15 +319,20 @@ public class CircuitComponent extends JComponent implements Observer {
|
||||
VisualElement vp = circuit.getElementAt(getPosVector(e));
|
||||
if (vp != null) {
|
||||
String name = vp.getElementName();
|
||||
ArrayList<AttributeKey> list = library.getElementType(name).getAttributeList();
|
||||
if (list.size() > 0) {
|
||||
Point p = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||
if (new AttributeDialog(p, list, vp.getElementAttributes()).showDialog()) {
|
||||
circuit.modified();
|
||||
repaint();
|
||||
ElementTypeDescription elementType = library.getElementType(name);
|
||||
if (elementType instanceof LibrarySelector.ElementTypeDescriptionCustom) {
|
||||
new Main(this, ((LibrarySelector.ElementTypeDescriptionCustom) elementType).getFile()).setVisible(true);
|
||||
} else {
|
||||
ArrayList<AttributeKey> list = elementType.getAttributeList();
|
||||
if (list.size() > 0) {
|
||||
Point p = new Point(e.getX(), e.getY());
|
||||
SwingUtilities.convertPointToScreen(p, CircuitComponent.this);
|
||||
if (new AttributeDialog(p, list, vp.getElementAttributes()).showDialog()) {
|
||||
circuit.modified();
|
||||
repaint();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
|
Loading…
x
Reference in New Issue
Block a user