Search in sources :

Example 1 with LibraryTreeModel

use of de.neemann.digital.gui.components.tree.LibraryTreeModel in project Digital by hneemann.

the class Main method createViewMenu.

private void createViewMenu(JMenuBar menuBar, JToolBar toolBar) {
    ToolTipAction maximize = new ToolTipAction(Lang.get("menu_maximize"), ICON_EXPAND) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.fitCircuit();
        }
    }.setAccelerator("F1");
    ToolTipAction zoomIn = new ToolTipAction(Lang.get("menu_zoomIn"), ICON_ZOOM_IN) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.scaleCircuit(1 / 0.9);
        }
    }.setAccelerator("control PLUS");
    // enable [+] which is SHIFT+[=] on english keyboard layout
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_EQUALS, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ADD, KeyEvent.CTRL_DOWN_MASK, false), zoomIn);
    circuitComponent.getActionMap().put(zoomIn, zoomIn);
    ToolTipAction zoomOut = new ToolTipAction(Lang.get("menu_zoomOut"), ICON_ZOOM_OUT) {

        @Override
        public void actionPerformed(ActionEvent e) {
            circuitComponent.scaleCircuit(0.9);
        }
    }.setAccelerator("control MINUS");
    // enable [+] which is SHIFT+[=] on english keyboard layout
    circuitComponent.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SUBTRACT, KeyEvent.CTRL_DOWN_MASK, false), zoomOut);
    circuitComponent.getActionMap().put(zoomOut, zoomOut);
    ToolTipAction viewHelp = new ToolTipAction(Lang.get("menu_viewHelp"), ICON_HELP) {

        @Override
        public void actionPerformed(ActionEvent e) {
            final Circuit circuit = circuitComponent.getCircuit();
            final String name = Lang.get("msg_actualCircuit");
            File file = filename;
            if (file == null)
                file = new File(name);
            try {
                ElementLibrary.ElementTypeDescriptionCustom description = new ElementLibrary.ElementTypeDescriptionCustom(file, attributes -> new CustomElement(circuit, library), circuit);
                description.setShortName(name);
                description.setDescription(circuit.getAttributes().get(Keys.DESCRIPTION));
                new ElementHelpDialog(Main.this, description, circuit.getAttributes()).setVisible(true);
            } catch (PinException | NodeException e1) {
                new ErrorMessage(Lang.get("msg_creatingHelp")).addCause(e1).show(Main.this);
            }
        }
    }.setToolTip(Lang.get("menu_viewHelp_tt"));
    JCheckBoxMenuItem treeCheckBox = new JCheckBoxMenuItem(Lang.get("menu_treeSelect"));
    treeCheckBox.setToolTipText(Lang.get("menu_treeSelect_tt"));
    treeCheckBox.addActionListener(actionEvent -> {
        getContentPane().remove(componentOnPane);
        if (treeCheckBox.isSelected()) {
            JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
            treeModel = new LibraryTreeModel(library);
            split.setLeftComponent(new JScrollPane(new SelectTree(treeModel, circuitComponent, shapeFactory, insertHistory)));
            split.setRightComponent(circuitComponent);
            getContentPane().add(split);
            componentOnPane = split;
        } else {
            if (treeModel != null) {
                library.removeListener(treeModel);
                treeModel = null;
            }
            getContentPane().add(circuitComponent);
            componentOnPane = circuitComponent;
        }
        revalidate();
    });
    treeCheckBox.setAccelerator(KeyStroke.getKeyStroke("F5"));
    if (Settings.getInstance().get(Keys.SETTINGS_DEFAULT_TREESELECT))
        SwingUtilities.invokeLater(treeCheckBox::doClick);
    toolBar.add(viewHelp.createJButtonNoText());
    toolBar.add(zoomIn.createJButtonNoText());
    toolBar.add(zoomOut.createJButtonNoText());
    toolBar.add(maximize.createJButtonNoText());
    JMenu view = new JMenu(Lang.get("menu_view"));
    menuBar.add(view);
    view.add(maximize.createJMenuItem());
    view.add(zoomOut.createJMenuItem());
    view.add(zoomIn.createJMenuItem());
    view.addSeparator();
    view.add(treeCheckBox);
    view.addSeparator();
    view.add(viewHelp.createJMenuItem());
}
Also used : de.neemann.digital.draw.graphics(de.neemann.digital.draw.graphics) URL(java.net.URL) Sync(de.neemann.digital.gui.sync.Sync) LoggerFactory(org.slf4j.LoggerFactory) de.neemann.digital.gui.components(de.neemann.digital.gui.components) TestingDataException(de.neemann.digital.testing.TestingDataException) TestCaseElement(de.neemann.digital.testing.TestCaseElement) VHDLGenerator(de.neemann.digital.hdl.vhdl2.VHDLGenerator) CheckForNewRelease(de.neemann.digital.gui.release.CheckForNewRelease) TableDialog(de.neemann.digital.gui.components.table.TableDialog) ElementAttributes(de.neemann.digital.core.element.ElementAttributes) ModelCreator(de.neemann.digital.draw.model.ModelCreator) Clipboard(java.awt.datatransfer.Clipboard) FormatToExpression(de.neemann.digital.analyse.expression.format.FormatToExpression) GifExporter(de.neemann.digital.draw.gif.GifExporter) ElementNotFoundException(de.neemann.digital.draw.library.ElementNotFoundException) LockSync(de.neemann.digital.gui.sync.LockSync) CodePrinter(de.neemann.digital.hdl.printer.CodePrinter) ScheduledThreadPoolExecutor(java.util.concurrent.ScheduledThreadPoolExecutor) SelectTree(de.neemann.digital.gui.components.tree.SelectTree) Lang(de.neemann.digital.lang.Lang) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) InvocationTargetException(java.lang.reflect.InvocationTargetException) de.neemann.digital.core(de.neemann.digital.core) State(de.neemann.digital.gui.state.State) ValueTableDialog(de.neemann.digital.gui.components.testing.ValueTableDialog) List(java.util.List) de.neemann.gui(de.neemann.gui) de.neemann.digital.draw.elements(de.neemann.digital.draw.elements) java.awt.event(java.awt.event) Drawable(de.neemann.digital.draw.shapes.Drawable) NoSync(de.neemann.digital.gui.sync.NoSync) CustomElement(de.neemann.digital.draw.library.CustomElement) RealTimeClock(de.neemann.digital.draw.model.RealTimeClock) Clock(de.neemann.digital.core.wiring.Clock) ExpressionDialog(de.neemann.digital.gui.components.expression.ExpressionDialog) DataFlavor(java.awt.datatransfer.DataFlavor) FileNameExtensionFilter(javax.swing.filechooser.FileNameExtensionFilter) RemoteSever(de.neemann.digital.gui.remote.RemoteSever) SIZE(de.neemann.digital.draw.shapes.GenericShape.SIZE) NumberFormat(java.text.NumberFormat) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) ModifyAttribute(de.neemann.digital.gui.components.modification.ModifyAttribute) ModelAnalyser(de.neemann.digital.analyse.ModelAnalyser) Button(de.neemann.digital.core.io.Button) Modifications(de.neemann.digital.gui.components.modification.Modifications) JOptionPane.showInputDialog(javax.swing.JOptionPane.showInputDialog) GraphDialog(de.neemann.digital.gui.components.data.GraphDialog) Keys(de.neemann.digital.core.element.Keys) OutputStream(java.io.OutputStream) Logger(org.slf4j.Logger) TruthTable(de.neemann.digital.analyse.TruthTable) DecimalFormat(java.text.DecimalFormat) FileOutputStream(java.io.FileOutputStream) ROM(de.neemann.digital.core.memory.ROM) IOException(java.io.IOException) DigitalHandler(de.neemann.digital.gui.remote.DigitalHandler) File(java.io.File) java.awt(java.awt) AnalyseException(de.neemann.digital.analyse.AnalyseException) de.neemann.digital.core.io(de.neemann.digital.core.io) RemoteException(de.neemann.digital.gui.remote.RemoteException) StateManager(de.neemann.digital.gui.state.StateManager) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) ModifyMeasurementOrdering(de.neemann.digital.gui.components.modification.ModifyMeasurementOrdering) ShapeFactory(de.neemann.digital.draw.shapes.ShapeFactory) javax.swing(javax.swing) SelectTree(de.neemann.digital.gui.components.tree.SelectTree) CustomElement(de.neemann.digital.draw.library.CustomElement) ElementLibrary(de.neemann.digital.draw.library.ElementLibrary) LibraryTreeModel(de.neemann.digital.gui.components.tree.LibraryTreeModel) File(java.io.File)

Aggregations

AnalyseException (de.neemann.digital.analyse.AnalyseException)1 ModelAnalyser (de.neemann.digital.analyse.ModelAnalyser)1 TruthTable (de.neemann.digital.analyse.TruthTable)1 FormatToExpression (de.neemann.digital.analyse.expression.format.FormatToExpression)1 de.neemann.digital.core (de.neemann.digital.core)1 ElementAttributes (de.neemann.digital.core.element.ElementAttributes)1 Keys (de.neemann.digital.core.element.Keys)1 de.neemann.digital.core.io (de.neemann.digital.core.io)1 Button (de.neemann.digital.core.io.Button)1 ROM (de.neemann.digital.core.memory.ROM)1 Clock (de.neemann.digital.core.wiring.Clock)1 de.neemann.digital.draw.elements (de.neemann.digital.draw.elements)1 GifExporter (de.neemann.digital.draw.gif.GifExporter)1 de.neemann.digital.draw.graphics (de.neemann.digital.draw.graphics)1 CustomElement (de.neemann.digital.draw.library.CustomElement)1 ElementLibrary (de.neemann.digital.draw.library.ElementLibrary)1 ElementNotFoundException (de.neemann.digital.draw.library.ElementNotFoundException)1 ModelCreator (de.neemann.digital.draw.model.ModelCreator)1 RealTimeClock (de.neemann.digital.draw.model.RealTimeClock)1 Drawable (de.neemann.digital.draw.shapes.Drawable)1