package org.workcraft.plugins.circuit.tools;

import info.clearthought.layout.TableLayout;
import org.workcraft.dom.visual.SizeHelper;
import org.workcraft.utils.GuiUtils;

import javax.swing.*;
import java.awt.*;
import java.awt.event.KeyEvent;

@SuppressWarnings("serial")
public class ScanDialog extends JDialog {

    private boolean modalResult;

    public ScanDialog(Window owner) {
        super(owner, "Scan insertion", ModalityType.DOCUMENT_MODAL);

        JPanel outputOptions = new JPanel();
        outputOptions.setLayout(new BoxLayout(outputOptions, BoxLayout.Y_AXIS));
        outputOptions.setBorder(SizeHelper.getTitledBorder("Shared signals"));

        JPanel buttonsPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT));
        JButton okButton = GuiUtils.createDialogButton("OK");
        okButton.addActionListener(event -> actionOk());

        JButton cancelButton = GuiUtils.createDialogButton("Cancel");
        cancelButton.addActionListener(event -> actionCancel());

        buttonsPanel.add(okButton);
        buttonsPanel.add(cancelButton);

        getRootPane().registerKeyboardAction(event -> actionOk(),
                KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);

        getRootPane().registerKeyboardAction(event -> actionCancel(),
                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
                JComponent.WHEN_IN_FOCUSED_WINDOW);

        int buttonPanelHeight = buttonsPanel.getPreferredSize().height;
        double[][] sizes = new double[][] {
                {TableLayout.FILL},
                {TableLayout.PREFERRED, TableLayout.FILL, buttonPanelHeight},
        };
        final JPanel contentPanel = new JPanel(new TableLayout(sizes));
        contentPanel.setBorder(SizeHelper.getEmptyBorder());

        contentPanel.add(buttonsPanel, "0 2");

        setContentPane(contentPanel);
        setMinimumSize(new Dimension(600, 400));
        pack();
        setLocationRelativeTo(owner);
    }

    private void actionOk() {
        modalResult = true;
        setVisible(false);
    }

    private void actionCancel() {
        modalResult = false;
        setVisible(false);
    }

    public boolean reveal() {
        setVisible(true);
        return modalResult;
    }

}

@@ -50,88 +50,97 @@
 ort 
-info.clearthought.layout.TableLayout;%0Aimport org.workcraft.dom.visual.SizeHelper
+org.workcraft.dom.visual.SizeHelper;%0Aimport org.workcraft.plugins.circuit.CircuitSettings
 ;%0Aim
@@ -477,29 +477,26 @@
  JPanel 
-outputOptions
+inputPanel
  = new J
@@ -501,27 +501,46 @@
  JPanel(
+new BorderLayout()
 );%0A
+%0A
         
 outputOp
@@ -535,89 +535,196 @@
     
-outputOptions.setLayout(new BoxLayout(outputOptions, BoxLayout.Y_AXIS)
+JTextField portsText = new JTextField(CircuitSettings.getScanPorts());%0A        inputPanel.add(GuiUtils.createWideLabeledComponent(portsText, %22Scan ports: %22), BorderLayout.NORTH
 );%0A
+%0A
         
 outp
@@ -723,76 +723,181 @@
     
-outputOptions.setBorder(SizeHelper.getTitledBorder(%22Shared signals%22)
+JTextField pinsText = new JTextField(CircuitSettings.getScanPins());%0A        inputPanel.add(GuiUtils.createWideLabeledComponent(pinsText, %22Scan pins: %22), BorderLayout.CENTER
 );%0A%0A
@@ -967,13 +967,70 @@
 out.
-RIGHT
+CENTER, SizeHelper.getLayoutHGap(), SizeHelper.getLayoutVGap()
 ));%0A
@@ -1741,255 +1741,8 @@
     
-int buttonPanelHeight = buttonsPanel.getPreferredSize().height;%0A        double%5B%5D%5B%5D sizes = new double%5B%5D%5B%5D %7B%0A                %7BTableLayout.FILL%7D,%0A                %7BTableLayout.PREFERRED, TableLayout.FILL, buttonPanelHeight%7D,%0A        %7D;%0A        final 
 JPan
@@ -1778,25 +1778,21 @@
 new 
-Table
+Border
 Layout(
-sizes
 ));%0A
@@ -1816,49 +1816,46 @@
 nel.
-setBorder(SizeHelper.getEmptyBorder()
+add(inputPanel, BorderLayout.CENTER
 );%0A
-%0A
     
@@ -1893,13 +1893,26 @@
 el, 
-%220 2%22
+BorderLayout.SOUTH
 );%0A%0A
@@ -1995,9 +1995,9 @@
 00, 
-4
+2
 00))

Add dialog for scan insertion parameters