Example usage for javax.swing InputMap put

List of usage examples for javax.swing InputMap put

Introduction

In this page you can find the example usage for javax.swing InputMap put.

Prototype

public void put(KeyStroke keyStroke, Object actionMapKey) 

Source Link

Document

Adds a binding for keyStroke to actionMapKey .

Usage

From source file:org.nuclos.client.genericobject.GenericObjectCollectController.java

private void setupKeyActionsForResultPanelVerticalScrollBar() {
    // maps the default key strokes for JTable to set the vertical scrollbar, so we can intervent:
    final InputMap inputmap = getResultTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_END, InputEvent.CTRL_MASK), "last");
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "nextrow");
    inputmap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "nextpage");

    final JScrollBar scrlbarVertical = getResultPanel().getResultTableScrollPane().getVerticalScrollBar();
    final DefaultBoundedRangeModel model = (DefaultBoundedRangeModel) scrlbarVertical.getModel();

    getResultTable().getActionMap().put("last", new AbstractAction() {

        @Override// w  ww . j a  v a  2  s . c  o m
        public void actionPerformed(ActionEvent ev) {
            final int iSupposedValue = model.getMaximum() - model.getExtent();
            model.setValue(iSupposedValue);
            // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
            LOG.debug("NOW it's time to select the row...");
            if (model.getValue() == iSupposedValue)
                getCollectNavigationModel().selectLastElement();
        }
    });

    getResultTable().getActionMap().put("nextrow", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            final int iSelectedRow = getResultTable().getSelectedRow();
            final int iLastVisibleRow = TableUtils.getLastVisibleRow(getResultTable());
            if (iSelectedRow + 1 < iLastVisibleRow) {
                // next row is still visible: just select it:
                if (!getCollectNavigationModel().isLastElementSelected())
                    getCollectNavigationModel().selectNextElement();
            } else {
                // we have to move the viewport before we can select the next row:
                final int iSupposedValue = Math.min(model.getValue() + getResultTable().getRowHeight(),
                        model.getMaximum() - model.getExtent());
                model.setValue(iSupposedValue);
                // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
                LOG.debug("NOW it's time to select the row...");
                if (model.getValue() == iSupposedValue)
                    if (!getCollectNavigationModel().isLastElementSelected())
                        getCollectNavigationModel().selectNextElement();
            }
        }
    });

    getResultTable().getActionMap().put("nextpage", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            final int iSupposedValue = Math.min(model.getValue() + model.getExtent(),
                    model.getMaximum() - model.getExtent());
            model.setValue(iSupposedValue);
            // this causes the necessary rows to be loaded. Loading may be cancelled by the user.
            LOG.debug("NOW it's time to select the row...");
            if (model.getValue() == iSupposedValue) {
                final int iShiftRowCount = (int) Math
                        .ceil((double) model.getExtent() / (double) getResultTable().getRowHeight());
                final int iRow = Math.min(
                        getResultTable().getSelectionModel().getAnchorSelectionIndex() + iShiftRowCount,
                        getResultTable().getRowCount() - 1);
                getResultTable().setRowSelectionInterval(iRow, iRow);
            }
        }
    });

    final Action actShowLogBook = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdShowLogBook();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_LOGBOOK, actShowLogBook,
            getDetailsPanel());

    final Action actShowStateHistory = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdShowStateHistory();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.SHOW_STATE_HISTORIE, actShowStateHistory,
            getDetailsPanel());

    final Action actPrintCurrentGenericObject = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            cmdPrintCurrentGenericObject();
            getDetailsPanel().grabFocus();
        }
    };
    KeyBindingProvider.bindActionToComponent(KeyBindingProvider.PRINT_LEASED_OBJECT,
            actPrintCurrentGenericObject, getDetailsPanel());
}

From source file:org.omegat.gui.shortcuts.PropertiesShortcutsTest.java

/**
 * Test of bindKeyStrokes method, of class PropertiesShortcuts.
 *///from ww  w.ja  va2 s . c o m
@Test
public void testBindKeyStrokes_InputMap_ObjectArr() {
    // bind
    InputMap inputMap = new InputMap();
    shotcuts.bindKeyStrokes(inputMap, TEST_SAVE, TEST_CUT, TEST_USER_1);

    // test map size
    long expSize = 3;
    long size = inputMap.size();
    assertEquals(expSize, size);

    // test keys
    KeyStroke[] expResults = new KeyStroke[] { CTRL_S, CTRL_X, CTRL_P };
    KeyStroke[] results = inputMap.keys();
    assertArrayEquals(expResults, results);

    // test entry1 exists
    Object expResult = TEST_SAVE;
    Object result = inputMap.get(CTRL_S);
    assertEquals(expResult, result);

    // test entry2 exists
    expResult = TEST_CUT;
    result = inputMap.get(CTRL_X);
    assertEquals(expResult, result);

    // test entry3 exists
    expResult = TEST_USER_1;
    result = inputMap.get(CTRL_P);
    assertEquals(expResult, result);

    // test remove entry with null shortcut
    inputMap.put(CTRL_D, TEST_DELETE); // put target
    expResult = TEST_DELETE;
    result = inputMap.get(CTRL_D);
    assertEquals(expResult, result); // target exists before remove
    shotcuts.bindKeyStrokes(inputMap, TEST_DELETE); // key to be removed as null
    result = inputMap.get(CTRL_D);
    assertNull(result); // target will be null after removed

    // test map size again
    expSize = 3;
    size = inputMap.size();
    assertEquals(expSize, size);

    // ensure no affect for entry1 after removing
    expResult = TEST_SAVE;
    result = inputMap.get(CTRL_S);
    assertEquals(expResult, result);

    // ensure no affect for entry2 after removing
    expResult = TEST_CUT;
    result = inputMap.get(CTRL_X);
    assertEquals(expResult, result);

    // ensure no affect for entry3 after removing
    expResult = TEST_USER_1;
    result = inputMap.get(CTRL_P);
    assertEquals(expResult, result);
}

From source file:org.owasp.jbrofuzz.ui.viewers.WindowViewerFrame.java

/**
 * <p>//w ww. jav a  2 s .  com
 * The window viewer that gets launched for each request within the
 * corresponding panel.
 * </p>
 * 
 * @param parent The parent panel that the frame will belong to
 * @param name The full file name of the file location to be opened
 * 
 * @author subere@uncon.org
 * @version 2.0
 * @since 2.0
 */
public WindowViewerFrame(final AbstractPanel parent, final String name) {

    super("JBroFuzz - File Viewer - " + name);

    setIconImage(ImageCreator.IMG_FRAME.getImage());

    // The container pane
    final Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    // Define the Panel
    final JPanel listPanel = new JPanel();
    listPanel.setBorder(BorderFactory.createCompoundBorder(BorderFactory.createTitledBorder(name),
            BorderFactory.createEmptyBorder(1, 1, 1, 1)));
    listPanel.setLayout(new BorderLayout());

    // Get the preferences for wrapping lines of text
    final boolean wrapText = JBroFuzz.PREFS.getBoolean(JBroFuzzPrefs.FUZZING[3].getId(), false);

    if (wrapText) {

        listTextArea = new JTextPane();

    } else {

        listTextArea = new NonWrappingTextPane();

    }

    // Refine the Text Area
    listTextArea.setFont(new Font("Monospaced", Font.PLAIN, 12));
    listTextArea.setEditable(false);

    // Define the search area
    entry = new JTextField(10);
    status = new JLabel("Enter text to search:");

    // Initialise the highlighter on the text area
    hilit = new DefaultHighlighter();
    painter = new DefaultHighlighter.DefaultHighlightPainter(HILIT_COLOR);
    listTextArea.setHighlighter(hilit);

    entryBg = entry.getBackground();
    entry.getDocument().addDocumentListener(this);

    final InputMap im = entry.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    final ActionMap am = entry.getActionMap();
    im.put(KeyStroke.getKeyStroke("ESCAPE"), CANCEL_ACTION);
    am.put(CANCEL_ACTION, new CancelAction());

    // Right click: Cut, Copy, Paste, Select All
    AbstractPanel.popupText(listTextArea, false, true, false, true);

    // Define the Scroll Pane for the Text Area
    final JScrollPane listTextScrollPane = new JScrollPane(listTextArea);
    listTextScrollPane.setVerticalScrollBarPolicy(20);
    listTextScrollPane.setHorizontalScrollBarPolicy(30);

    // Define the progress bar
    final JProgressBar progressBar = new JProgressBar();
    progressBar.setString("   ");
    progressBar.setStringPainted(true);

    // Define the bottom panel with the progress bar
    final JPanel bottomPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 15, 15));
    bottomPanel.add(status);
    bottomPanel.add(entry);
    bottomPanel.add(progressBar);

    listTextArea.setCaretPosition(0);
    // doSyntaxHighlight();
    /*      listTextArea.setEditorKit(new StyledEditorKit() {
            
             private static final long serialVersionUID = -6085642347022880064L;
            
             @Override
             public Document createDefaultDocument() {
    return new TextHighlighter();
             }
            
          });
    */

    listPanel.add(listTextScrollPane);

    // Global Frame Issues
    pane.add(listPanel, BorderLayout.CENTER);
    pane.add(bottomPanel, BorderLayout.SOUTH);

    this.setLocation(parent.getLocationOnScreen().x + 100, parent.getLocationOnScreen().y + 20);
    this.setSize(SIZE_X, SIZE_Y);

    setResizable(true);
    setVisible(true);
    setMinimumSize(new Dimension(SIZE_X, SIZE_Y));
    setDefaultCloseOperation(2);

    listTextArea.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent ke) {
            if (ke.getKeyCode() == 27) {
                WindowViewerFrame.this.dispose();
            }
            if (ke.getKeyCode() == 10) {
                search();
            }
        }
    });

    entry.addKeyListener(new KeyAdapter() {
        @Override
        public void keyPressed(final KeyEvent ke) {
            if (ke.getKeyCode() == 10) {
                search();
            }
        }
    });

    class FileLoader extends SwingWorker<String, Object> { // NO_UCD

        @Override
        public String doInBackground() {

            progressBar.setIndeterminate(true);

            String dbType = JBroFuzz.PREFS.get(JBroFuzzPrefs.DBSETTINGS[11].getId(), "-1");

            if (dbType.equals("SQLite") || dbType.equals("CouchDB")) {

                String sessionId = parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing()
                        .getSessionName();

                if (sessionId == null || sessionId.equals("null")) {
                    sessionId = JBroFuzz.PREFS.get("sessionId", "");
                }

                Logger.log("Reading Session: " + sessionId + " with name: " + name, 3);

                MessageContainer mc = parent.getFrame().getJBroFuzz().getStorageHandler()
                        .readFuzzFile(name, sessionId, parent.getFrame().getJBroFuzz().getWindow()).get(0);

                listTextArea.setText("Date: " + mc.getEndDateFull() + "\n" + "FileName: " + mc.getFileName()
                        + "\n" + "URL: " + mc.getTextURL() + "\n" + "Payload: " + mc.getPayload() + "\n"
                        + "EncodedPayload: " + mc.getEncodedPayload() + "\n" + "TextRequest:"
                        + mc.getTextRequest() + "\n" + "Message: " + mc.getMessage() + "\n" + "Status: "
                        + mc.getStatus() + "\n"

                );

            } else {
                Logger.log("Loading data from file", 3);
                final File inputFile = new File(parent.getFrame().getJBroFuzz().getWindow().getPanelFuzzing()
                        .getFrame().getJBroFuzz().getStorageHandler().getLocationURIString(), name + ".html");

                listTextArea.setText(

                        FileHandler.readFile(inputFile)

                );
            }
            return "done";
        }

        @Override
        protected void done() {
            progressBar.setIndeterminate(false);
            progressBar.setValue(100);
            listTextArea.repaint();
        }
    }

    (new FileLoader()).execute();

}

From source file:org.pentaho.reporting.engine.classic.core.modules.gui.base.PreviewParametersDialog.java

private void initialize(final MasterReport report) {
    if (report == null) {
        throw new NullPointerException();
    }/* w w  w  .j a va 2s  .  co  m*/

    masterReport = report;
    messages = new ResourceBundleSupport(Locale.getDefault(), SwingPreviewModule.BUNDLE_NAME,
            ObjectUtilities.getClassLoader(PreviewParametersDialog.class));
    confirmAction = new OkAction();

    setTitle(messages.getString("PreviewParametersDialog.Title"));
    setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(createParametersPanel(), BorderLayout.CENTER);
    contentPane.add(createButtonsPanel(), BorderLayout.SOUTH);
    setContentPane(contentPane);

    final InputMap inputMap = contentPane.getInputMap();
    final ActionMap actionMap = contentPane.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "confirm"); // NON-NLS
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NON-NLS
    actionMap.put("confirm", new OkAction()); // NON-NLS
    actionMap.put("cancel", new CancelAction()); // NON-NLS

    setModal(true);
    pack();
    LibSwingUtil.centerDialogInParent(this);
}

From source file:org.photovault.swingui.JAIPhotoViewer.java

public void createUI() {
    setLayout(new BorderLayout());
    addComponentListener(this);
    imageView = new JAIPhotoView();
    imageView.addCropAreaChangeListener(this);
    scrollPane = new JScrollPane(imageView);
    scrollPane.setPreferredSize(new Dimension(500, 500));
    add(scrollPane, BorderLayout.CENTER);
    // Get the crop icon
    ImageIcon cropIcon = null;/*  w  w w  .jav  a  2  s  . co m*/
    java.net.URL cropIconURL = JAIPhotoViewer.class.getClassLoader().getResource("crop_icon.png");
    if (cropIconURL != null) {
        cropIcon = new ImageIcon(cropIconURL);
    }

    cropPhotoAction = new CropPhotoAction(imageView, "Crop photo", cropIcon,
            "Crop or rotate the selected photo", KeyEvent.VK_O, null);
    InputMap inputMap = getInputMap(WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "hide_fullwindow_preview");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0), "move_next");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), "move_next");
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), "move_prev");

}

From source file:org.rdv.ui.channel.LocalChannelDialog.java

/**
 * Initialize the UI components./* www .  j  a  v a2s. c o m*/
 */
private void initComponents() {
    RDV rdv = RDV.getInstance(RDV.class);

    JPanel container = new JPanel();
    setContentPane(container);

    container.setLayout(new GridBagLayout());
    GridBagConstraints c = createDefaultGridBagConstraints();

    JLabel nameLabel = new JLabel();
    nameLabel.setName("nameLabel");
    nameLabel.setText(PROPERTY_REPO.getValue(NAME_KEY));

    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(10, 10, 10, 5);
    container.add(nameLabel, c);

    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(10, 0, 10, 10);
    container.add(nameTextField, c);
    if (isChannelUpdateOperation()) {
        nameTextField.setEnabled(false);
    }
    JLabel unitLabel = new JLabel();
    unitLabel.setName("unitLabel");
    unitLabel.setText(PROPERTY_REPO.getValue(UNIT_KEY));
    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 5);
    container.add(unitLabel, c);

    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 0, 10, 10);
    container.add(unitTextField, c);

    JLabel variablesLabel = new JLabel();
    variablesLabel.setName("variablesLabel");
    variablesLabel.setText(PROPERTY_REPO.getValue(VARIABLES_KEY));
    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(variablesLabel, c);

    JPanel variablesPanel = buildVariablesPanel();

    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    c.weightx = 1;
    c.weighty = 1;
    container.add(variablesPanel, c);

    JLabel formulaLabel = new JLabel();
    formulaLabel.setName("formulaLabel");
    formulaLabel.setText(PROPERTY_REPO.getValue(FORMULA_KEY));
    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(formulaLabel, c);

    JScrollPane formulaScrollPane = new JScrollPane(formulaTextArea);
    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 1;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(formulaScrollPane, c);

    JPanel footerPanel = buildFooterPanel();

    c = createDefaultGridBagConstraints();
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.5;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 7;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.LINE_END;
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(footerPanel, c);

    // bind keystrokes
    InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), "addChannel");
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel");

    // initially disable buttons
    removeVariableButton.setEnabled(false);

    pack();

    setLocationByPlatform(true);
    setVisible(true);
}

From source file:org.rdv.ui.ConsoleDialog.java

public ConsoleDialog(JDialog owner) {
    super(owner);

    setName("consoleDialog");

    setDefaultCloseOperation(AboutDialog.DISPOSE_ON_CLOSE);

    JPanel container = new JPanel();
    container.setLayout(new BorderLayout());
    container.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
    setContentPane(container);//from   w  w  w . jav  a  2  s  .c o  m

    InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = container.getActionMap();

    Action disposeAction = new AbstractAction() {
        /** serialized version identifier */
        private static final long serialVersionUID = 4380189911762232261L;

        public void actionPerformed(ActionEvent ae) {
            dispose();
        }
    };

    Action copyAction = new AbstractAction() {

        /** serialized version identifier */
        private static final long serialVersionUID = 2596081241883913660L;

        public void actionPerformed(ActionEvent e) {
            textArea.selectAll();
            textArea.copy();
        }
    };

    //    Action scrollLockAction = new AbstractAction() {
    //      /** serialized version identifier */
    //      private static final long serialVersionUID = -8089076016097529064L;
    //
    //      public void actionPerformed(ActionEvent e) {
    //        //toggle scroll lock
    //        scrollLock_=!scrollLock_;
    //      }
    //    };

    disposeAction.putValue(Action.NAME, "OK");
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), "dispose");
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "dispose");
    actionMap.put("dispose", disposeAction);
    copyAction.putValue(Action.NAME, "Copy");
    actionMap.put("copy", copyAction);
    //    actionMap.put("scroll lock", scrollLockAction);
    //    scrollLockAction.putValue(Action.NAME, "Scroll Lock");

    textArea = new JTextArea();
    textArea.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    textArea.setBackground(Color.WHITE);
    textArea.setForeground(Color.BLACK);
    textArea.setEditable(false);
    textArea.setLineWrap(false);

    Iterator<String> msgIt = messageBuffer.getMessages().iterator();

    //add all the messages in the buffer to this point
    while (msgIt.hasNext()) {
        addMessage(msgIt.next());
    }

    JScrollPane scrollPane = new JScrollPane(textArea, ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
    scrollPane.setPreferredSize(new Dimension(640, 480));
    container.add(scrollPane, BorderLayout.CENTER);

    JPanel buttonPanel = new JPanel();
    buttonPanel.setLayout(new BorderLayout());
    buttonPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    JButton okButton = new JButton(disposeAction);
    buttonPanel.add(okButton, BorderLayout.EAST);

    JPanel leftBtnsPanel = new JPanel();
    leftBtnsPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
    buttonPanel.add(leftBtnsPanel, BorderLayout.WEST);

    JButton copyButton = new JButton(copyAction);
    leftBtnsPanel.add(copyButton);

    //    JButton scrollLockButton = new JButton(scrollLockAction);
    //    leftBtnsPanel.add(scrollLockButton);

    container.add(buttonPanel, BorderLayout.SOUTH);

    // inject resources from the properties for this component
    ResourceMap resourceMap = RDV.getInstance().getContext().getResourceMap(getClass());
    resourceMap.injectComponents(this);

    pack();
    okButton.requestFocusInWindow();
    setLocationByPlatform(true);
    setVisible(true);

    messageBuffer.addObserver(this);
}

From source file:org.rdv.ui.ExportDialog.java

private void initComponents(List<String> channels, List<String> fileFormats) {
    channelModel = new DefaultListModel();

    for (int i = 0; i < channels.size(); i++) {
        String channelName = (String) channels.get(i);
        Channel channel = RBNBController.getInstance().getChannel(channelName);

        String mime = channel.getMetadata("mime");

        if (mime.equals("application/octet-stream")) {
            channelModel.addElement(new ExportChannel(channelName));
        }//from   w  ww .j a v a 2 s  .  c o  m
    }

    JPanel container = new JPanel();
    setContentPane(container);

    InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = container.getActionMap();

    container.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;

    JLabel headerLabel = new JLabel("Select the time range and data channels to export.");
    headerLabel.setBackground(Color.white);
    headerLabel.setOpaque(true);
    headerLabel.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 0, 0, 0);
    container.add(headerLabel, c);

    JPanel timeButtonPanel = new JPanel();
    timeButtonPanel.setLayout(new BorderLayout());

    MouseListener hoverMouseListener = new MouseAdapter() {
        public void mouseEntered(MouseEvent e) {
            e.getComponent().setForeground(Color.red);
        }

        public void mouseExited(MouseEvent e) {
            e.getComponent().setForeground(Color.blue);
        }
    };

    startTimeButton = new JButton();
    startTimeButton.setBorder(null);
    startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    startTimeButton.setForeground(Color.blue);
    startTimeButton.addMouseListener(hoverMouseListener);
    startTimeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            double startTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getStart(),
                    timeSlider.getMinimum(), timeSlider.getEnd());
            if (startTime >= 0) {
                timeSlider.setStart(startTime);
            }
        }
    });
    timeButtonPanel.add(startTimeButton, BorderLayout.WEST);

    durationLabel = new JLabel();
    durationLabel.setHorizontalAlignment(JLabel.CENTER);
    timeButtonPanel.add(durationLabel, BorderLayout.CENTER);

    endTimeButton = new JButton();
    endTimeButton.setBorder(null);
    endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    endTimeButton.setForeground(Color.blue);
    endTimeButton.addMouseListener(hoverMouseListener);
    endTimeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            double endTime = DateTimeDialog.showDialog(ExportDialog.this, timeSlider.getEnd(),
                    timeSlider.getStart(), timeSlider.getMaximum());
            if (endTime >= 0) {
                timeSlider.setEnd(endTime);
            }
        }
    });
    timeButtonPanel.add(endTimeButton, BorderLayout.EAST);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(10, 10, 10, 10);
    container.add(timeButtonPanel, c);

    timeSlider = new TimeSlider();
    timeSlider.setValueChangeable(false);
    timeSlider.setValueVisible(false);
    timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() {
        public void timeChanged(TimeEvent event) {
        }

        public void rangeChanged(TimeEvent event) {
            updateTimeRangeLabel();
        }

        public void boundsChanged(TimeEvent event) {
        }
    });
    updateTimeRangeLabel();
    updateTimeBounds();

    List<EventMarker> markers = RBNBController.getInstance().getMarkerManager().getMarkers();
    for (EventMarker marker : markers) {
        timeSlider.addMarker(marker);
    }

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(timeSlider, c);

    JLabel numericHeaderLabel = new JLabel("Data Channels:");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(numericHeaderLabel, c);

    numericChannelList = new JList(channelModel);
    numericChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    numericChannelList.setCellRenderer(new CheckListRenderer());
    numericChannelList.setVisibleRowCount(10);
    numericChannelList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            int index = numericChannelList.locationToIndex(e.getPoint());
            ExportChannel item = (ExportChannel) numericChannelList.getModel().getElementAt(index);
            item.setSelected(!item.isSelected());
            Rectangle rect = numericChannelList.getCellBounds(index, index);
            numericChannelList.repaint(rect);

            checkSelectedChannels();

            updateTimeBounds();
        }
    });
    JScrollPane scrollPane = new JScrollPane(numericChannelList);
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(scrollPane, c);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 5);
    container.add(new JLabel("Data file: "), c);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    dataFileTextField = new JTextField(20);
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(dataFileTextField, c);

    dataFileTextField
            .setText(UIUtilities.getCurrentDirectory().getAbsolutePath() + File.separator + "data.dat");
    dataFileButton = new JButton("Browse");
    dataFileButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            File selectedFile = new File(dataFileTextField.getText());
            selectedFile = UIUtilities.getFile("OK", "Select export file", selectedFile);
            if (selectedFile != null) {
                dataFileTextField.setText(selectedFile.getAbsolutePath());
            }
        }
    });
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 2;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 0, 10, 10);
    container.add(dataFileButton, c);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 5);
    container.add(new JLabel("File format: "), c);

    fileFormatComboBox = new JComboBox(fileFormats.toArray());
    fileFormatComboBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            fileFormatUpdated();
        }
    });
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 6;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 0, 10, 10);
    container.add(fileFormatComboBox, c);

    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());

    Action exportAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = -5356258138620428023L;

        public void actionPerformed(ActionEvent e) {
            ok();
        }
    };
    exportAction.putValue(Action.NAME, "Export");
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export");
    actionMap.put("export", exportAction);
    exportButton = new JButton(exportAction);
    panel.add(exportButton);

    Action cancelAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = -5868609501314154642L;

        public void actionPerformed(ActionEvent e) {
            cancel();
        }
    };
    cancelAction.putValue(Action.NAME, "Cancel");
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel");
    actionMap.put("cancel", cancelAction);
    cancelButton = new JButton(cancelAction);
    panel.add(cancelButton);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 7;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.LINE_END;
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(panel, c);

    pack();
    if (getWidth() < 600) {
        setSize(600, getHeight());
    }

    dataFileTextField.requestFocusInWindow();

    setLocationByPlatform(true);
}

From source file:org.rdv.ui.ExportVideoDialog.java

private void initComponents() {

    JPanel container = new JPanel();
    setContentPane(container);/*from   w ww  .ja v a  2  s  .com*/

    InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = container.getActionMap();

    container.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;

    JLabel headerLabel = new JLabel("Select the time range and video channels to export.");
    headerLabel.setBackground(Color.white);
    headerLabel.setOpaque(true);
    headerLabel.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 0, 0, 0);
    container.add(headerLabel, c);

    JPanel timeButtonPanel = new JPanel();
    timeButtonPanel.setLayout(new BorderLayout());

    MouseListener hoverMouseListener = new MouseAdapter() {
        public void mouseEntered(MouseEvent e) {
            e.getComponent().setForeground(Color.red);
        }

        public void mouseExited(MouseEvent e) {
            e.getComponent().setForeground(Color.blue);
        }
    };

    startTimeButton = new JButton();
    startTimeButton.setBorder(null);
    startTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    startTimeButton.setForeground(Color.blue);
    startTimeButton.addMouseListener(hoverMouseListener);
    startTimeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            double startTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getStart(),
                    timeSlider.getMinimum(), timeSlider.getEnd());
            if (startTime >= 0) {
                timeSlider.setStart(startTime);
            }
        }
    });
    timeButtonPanel.add(startTimeButton, BorderLayout.WEST);

    durationLabel = new JLabel();
    durationLabel.setHorizontalAlignment(JLabel.CENTER);
    timeButtonPanel.add(durationLabel, BorderLayout.CENTER);

    endTimeButton = new JButton();
    endTimeButton.setBorder(null);
    endTimeButton.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
    endTimeButton.setForeground(Color.blue);
    endTimeButton.addMouseListener(hoverMouseListener);
    endTimeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            double endTime = DateTimeDialog.showDialog(ExportVideoDialog.this, timeSlider.getEnd(),
                    timeSlider.getStart(), timeSlider.getMaximum());
            if (endTime >= 0) {
                timeSlider.setEnd(endTime);
            }
        }
    });
    timeButtonPanel.add(endTimeButton, BorderLayout.EAST);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(10, 10, 10, 10);
    container.add(timeButtonPanel, c);

    timeSlider = new TimeSlider();
    timeSlider.setValueChangeable(false);
    timeSlider.setValueVisible(false);
    timeSlider.addTimeAdjustmentListener(new TimeAdjustmentListener() {
        public void timeChanged(TimeEvent event) {
        }

        public void rangeChanged(TimeEvent event) {
            updateTimeRangeLabel();
        }

        public void boundsChanged(TimeEvent event) {
        }
    });
    updateTimeRangeLabel();
    updateTimeBounds();

    List<EventMarker> markers = rbnb.getMarkerManager().getMarkers();
    for (EventMarker marker : markers) {
        timeSlider.addMarker(marker);
    }

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(timeSlider, c);

    JLabel numericHeaderLabel = new JLabel("Video Channels:");
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(numericHeaderLabel, c);

    videoChannelList = new JList(videoChannelModel);
    videoChannelList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    videoChannelList.setCellRenderer(new CheckListRenderer());
    videoChannelList.setVisibleRowCount(10);
    videoChannelList.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            int index = videoChannelList.locationToIndex(e.getPoint());
            ExportChannel item = (ExportChannel) videoChannelList.getModel().getElementAt(index);
            item.setSelected(!item.isSelected());
            Rectangle rect = videoChannelList.getCellBounds(index, index);
            videoChannelList.repaint(rect);

            updateTimeBounds();
        }
    });
    JScrollPane scrollPane = new JScrollPane(videoChannelList);
    c.fill = GridBagConstraints.BOTH;
    c.weightx = 0;
    c.weighty = 1;
    c.gridx = 0;
    c.gridy = 4;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(scrollPane, c);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.weighty = 0;
    c.gridx = 0;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 10, 10, 5);
    container.add(new JLabel("Choose Directory: "), c);

    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    directoryTextField = new JTextField(20);
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(directoryTextField, c);

    directoryTextField.setText(UIUtilities.getCurrentDirectory().getAbsolutePath());
    directoryButton = new JButton("Browse");
    directoryButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            File selectedDirectory = UIUtilities.getDirectory("Select export directory");
            if (selectedDirectory != null) {
                directoryTextField.setText(selectedDirectory.getAbsolutePath());
            }
        }
    });
    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 2;
    c.gridy = 5;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(0, 0, 10, 10);
    container.add(directoryButton, c);

    exportProgressBar = new JProgressBar(0, 100000);
    exportProgressBar.setStringPainted(true);
    exportProgressBar.setValue(0);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 6;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(exportProgressBar, c);

    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());

    Action exportAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = 1547500154252213911L;

        public void actionPerformed(ActionEvent e) {
            exportVideo();
        }
    };
    exportAction.putValue(Action.NAME, "Export");
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), "export");
    actionMap.put("export", exportAction);
    exportButton = new JButton(exportAction);
    panel.add(exportButton);

    Action cancelAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = -7440298547807878651L;

        public void actionPerformed(ActionEvent e) {
            cancel();
        }
    };
    cancelAction.putValue(Action.NAME, "Cancel");
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel");
    actionMap.put("cancel", cancelAction);
    cancelButton = new JButton(cancelAction);
    panel.add(cancelButton);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 7;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.LINE_END;
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(panel, c);

    pack();
    if (getWidth() < 600) {
        setSize(600, getHeight());
    }

    directoryTextField.requestFocusInWindow();

    setLocationByPlatform(true);
    setVisible(true);
}

From source file:org.rdv.ui.ImportDialog.java

private void initComponents() {
    JPanel container = new JPanel();
    setContentPane(container);/*from  www  . j a  v a 2 s  .co  m*/

    InputMap inputMap = container.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    ActionMap actionMap = container.getActionMap();

    container.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 1;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.ipadx = 0;
    c.ipady = 0;

    JLabel headerLabel = new JLabel("Please specify the desired source name for the data.");
    headerLabel.setBackground(Color.white);
    headerLabel.setOpaque(true);
    headerLabel.setBorder(
            BorderFactory.createCompoundBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray),
                    BorderFactory.createEmptyBorder(10, 10, 10, 10)));
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 0;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(0, 0, 0, 0);
    container.add(headerLabel, c);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0;
    c.gridx = 0;
    c.gridy = 1;
    c.gridwidth = 1;
    c.anchor = GridBagConstraints.NORTHEAST;
    c.insets = new java.awt.Insets(10, 10, 10, 5);
    container.add(new JLabel("Source name: "), c);

    sourceNameTextField = new JTextField();
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 1;
    c.gridx = 1;
    c.gridy = 1;
    c.gridwidth = GridBagConstraints.REMAINDER;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.insets = new java.awt.Insets(10, 0, 10, 10);
    container.add(sourceNameTextField, c);

    importProgressBar = new JProgressBar(0, 100000);
    importProgressBar.setStringPainted(true);
    importProgressBar.setValue(0);
    importProgressBar.setVisible(false);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 2;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new java.awt.Insets(0, 10, 10, 10);
    container.add(importProgressBar, c);

    JPanel panel = new JPanel();
    panel.setLayout(new FlowLayout());

    Action importAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = -4719316285523193555L;

        public void actionPerformed(ActionEvent e) {
            importData();
        }
    };
    importAction.putValue(Action.NAME, "Import");
    inputMap.put(KeyStroke.getKeyStroke("ENTER"), "import");
    actionMap.put("export", importAction);
    importButton = new JButton(importAction);
    getRootPane().setDefaultButton(importButton);
    panel.add(importButton);

    Action cancelAction = new AbstractAction() {
        /** serialization version identifier */
        private static final long serialVersionUID = 7909429022904810958L;

        public void actionPerformed(ActionEvent e) {
            cancel();
        }
    };
    cancelAction.putValue(Action.NAME, "Cancel");
    inputMap.put(KeyStroke.getKeyStroke("ESCAPE"), "cancel");
    actionMap.put("cancel", cancelAction);
    cancelButton = new JButton(cancelAction);
    panel.add(cancelButton);

    c.fill = GridBagConstraints.NONE;
    c.weightx = 0.5;
    c.gridx = 0;
    c.gridy = 3;
    c.gridwidth = GridBagConstraints.REMAINDER;
    ;
    c.anchor = GridBagConstraints.LINE_END;
    c.insets = new java.awt.Insets(0, 0, 10, 5);
    container.add(panel, c);

    pack();

    sourceNameTextField.requestFocusInWindow();

    setLocationByPlatform(true);
    setVisible(true);
}