Example usage for javax.swing JDialog JDialog

List of usage examples for javax.swing JDialog JDialog

Introduction

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

Prototype

public JDialog(Window owner, String title, Dialog.ModalityType modalityType) 

Source Link

Document

Creates a dialog with the specified title, owner Window and modality.

Usage

From source file:net.sf.jabref.openoffice.CitationManager.java

public CitationManager(final JabRefFrame frame, OOBibBase ooBase)
        throws NoSuchElementException, WrappedTargetException, UnknownPropertyException {
    diag = new JDialog(frame, Localization.lang("Manage citations"), true);
    this.ooBase = ooBase;

    list = new BasicEventList<>();
    XNameAccess nameAccess = ooBase.getReferenceMarks();
    java.util.List<String> names = ooBase.getJabRefReferenceMarks(nameAccess);
    for (String name : names) {
        list.add(new CitEntry(name,
                "<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
                ooBase.getCustomProperty(name)));
    }/*www. j a v a  2s . c om*/
    tableModel = new DefaultEventTableModel<>(list, new CitEntryFormat());
    table = new JTable(tableModel);
    diag.add(new JScrollPane(table), BorderLayout.CENTER);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton ok = new JButton(Localization.lang("OK"));
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.add(bb.getPanel(), BorderLayout.SOUTH);

    diag.pack();
    diag.setSize(700, 400);

    ok.addActionListener(e -> {
        try {
            storeSettings();
        } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException
                | IllegalTypeException | IllegalArgumentException ex) {
            LOGGER.warn("Problem modifying citation", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation"));
        }
        diag.dispose();
    });

    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    bb.getPanel().getActionMap().put("close", cancelAction);

    table.getColumnModel().getColumn(0).setPreferredWidth(600);
    table.getColumnModel().getColumn(1).setPreferredWidth(90);
    table.setPreferredScrollableViewportSize(new Dimension(700, 500));
    table.addMouseListener(new TableClickListener());
}

From source file:net.sf.housekeeper.swing.FoodEditorView.java

/**
 * Initializes a new View. It will be shown centered on the
 * <code>owner</code>./*from www . j a v a2s.c om*/
 * 
 * @param owner The owner of this View.
 */
FoodEditorView(final Frame owner) {
    final String dialogTitle = LocalisationManager.INSTANCE.getText("gui.foodEditor.dialogTitle");
    dialog = new JDialog(owner, dialogTitle, true);

    nameField = new JTextField(20);
    quantityField = new JTextField(10);
    dateSpinner = createDateSpinner();
    checkbox = createExpiryEnabledCheckbox();

    final String okButtonText = LocalisationManager.INSTANCE.getText("gui.okButton");
    okButton = new JButton(okButtonText);
    okButton.setActionCommand("OK");

    final String cancelButtonText = LocalisationManager.INSTANCE.getText("gui.cancelButton");
    cancelButton = new JButton(cancelButtonText);
    cancelButton.setActionCommand("Cancel");

    initDialog();
}

From source file:net.sf.housekeeper.swing.FoodItemEditorView.java

/**
 * Initializes a new View. It will be shown centered on the
 * <code>owner</code>.//www  .  j  a  va  2  s . c  o  m
 * 
 * @param owner The owner of this View.
 */
FoodItemEditorView(final Frame owner) {
    final String dialogTitle = LocalisationManager.INSTANCE.getText("gui.foodItemEditor.dialogTitle");
    dialog = new JDialog(owner, dialogTitle, true);

    nameField = new JTextField(20);
    quantityField = new JTextField(10);
    dateSpinner = createDateSpinner();
    checkbox = createExpiryEnabledCheckbox();

    final String okButtonText = LocalisationManager.INSTANCE.getText("gui.okButton");
    okButton = new JButton(okButtonText);
    okButton.setActionCommand("OK");

    final String cancelButtonText = LocalisationManager.INSTANCE.getText("gui.cancelButton");
    cancelButton = new JButton(cancelButtonText);
    cancelButton.setActionCommand("Cancel");

    initDialog();
}

From source file:net.sf.jabref.gui.openoffice.CitationManager.java

public CitationManager(final JabRefFrame frame, OOBibBase ooBase)
        throws NoSuchElementException, WrappedTargetException, UnknownPropertyException {
    diag = new JDialog(frame, Localization.lang("Manage citations"), true);
    this.ooBase = ooBase;

    list = new BasicEventList<>();
    XNameAccess nameAccess = ooBase.getReferenceMarks();
    List<String> names = ooBase.getJabRefReferenceMarks(nameAccess);
    for (String name : names) {
        list.add(new CitationEntry(name,
                "<html>..." + ooBase.getCitationContext(nameAccess, name, 30, 30, true) + "...</html>",
                ooBase.getCustomProperty(name)));
    }//from   ww w.  j  av  a  2  s . com
    tableModel = new DefaultEventTableModel<>(list, new CitationEntryFormat());
    table = new JTable(tableModel);
    diag.add(new JScrollPane(table), BorderLayout.CENTER);

    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton ok = new JButton(Localization.lang("OK"));
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    diag.add(bb.getPanel(), BorderLayout.SOUTH);

    diag.pack();
    diag.setSize(700, 400);

    ok.addActionListener(e -> {
        try {
            storeSettings();
        } catch (UnknownPropertyException | NotRemoveableException | PropertyExistException
                | IllegalTypeException | IllegalArgumentException ex) {
            LOGGER.warn("Problem modifying citation", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Problem modifying citation"));
        }
        diag.dispose();
    });

    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            diag.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    bb.getPanel().getActionMap().put("close", cancelAction);

    table.getColumnModel().getColumn(0).setPreferredWidth(580);
    table.getColumnModel().getColumn(1).setPreferredWidth(110);
    table.setPreferredScrollableViewportSize(new Dimension(700, 500));
    table.addMouseListener(new TableClickListener());
}

From source file:de.tudarmstadt.ukp.clarin.webanno.webapp.standalone.StandaloneShutdownDialog.java

private void displayShutdownDialog() {
    String serverId = ServerDetector.getServerId();
    log.info("Running in: " + (serverId != null ? serverId : "unknown server"));
    log.info("Console: " + ((System.console() != null) ? "available" : "not available"));
    log.info("Headless: " + (GraphicsEnvironment.isHeadless() ? "yes" : "no"));

    // Show this only when run from the standalone JAR via a double-click
    if (System.console() == null && !GraphicsEnvironment.isHeadless() && ServerDetector.isWinstone()) {
        log.info("If you are running WebAnno in a server environment, please use '-Djava.awt.headless=true'");

        EventQueue.invokeLater(new Runnable() {
            @Override//from  w w w  . j  av  a 2s  .c o  m
            public void run() {
                final JOptionPane optionPane = new JOptionPane(new JLabel(
                        "<HTML>WebAnno is running now and can be accessed via <a href=\"http://localhost:8080\">http://localhost:8080</a>.<br>"
                                + "WebAnno works best with the browsers Google Chrome or Safari.<br>"
                                + "Use this dialog to shut WebAnno down.</HTML>"),
                        JOptionPane.INFORMATION_MESSAGE, JOptionPane.OK_OPTION, null,
                        new String[] { "Shutdown" });

                final JDialog dialog = new JDialog((JFrame) null, "WebAnno", true);
                dialog.setContentPane(optionPane);
                dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
                dialog.addWindowListener(new WindowAdapter() {
                    @Override
                    public void windowClosing(WindowEvent we) {
                        // Avoid closing window by other means than button
                    }
                });
                optionPane.addPropertyChangeListener(new PropertyChangeListener() {
                    @Override
                    public void propertyChange(PropertyChangeEvent aEvt) {
                        if (dialog.isVisible() && (aEvt.getSource() == optionPane)
                                && (aEvt.getPropertyName().equals(JOptionPane.VALUE_PROPERTY))) {
                            System.exit(0);
                        }
                    }
                });
                dialog.pack();
                dialog.setVisible(true);
            }
        });
    } else {
        log.info("Running in server environment or from command line: disabling interactive shutdown dialog.");
    }
}

From source file:fr.vdl.android.holocolors.HoloColorsDialog.java

/**
 * @param project/* w  w  w  .j  a va2  s.  c  o m*/
 */
public HoloColorsDialog(@Nullable final Project project) {
    super(project, true);

    loadingDialog = new JDialog(getWindow(), "Downloading, please wait...", Dialog.ModalityType.MODELESS);
    loadingDialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
    loadingDialog.setSize(300, 20);
    loadingDialog.setLocationRelativeTo(ahcPanel);

    this.project = project;

    checkLicence();

    setTitle("Android Holo Colors Generator");
    setResizable(true);

    FileChooserDescriptor workingDirectoryChooserDescriptor = FileChooserDescriptorFactory
            .createSingleFolderDescriptor();
    String title = "Select res directory";
    workingDirectoryChooserDescriptor.setTitle(title);
    resPathTextField.addBrowseFolderListener(title, null, project, workingDirectoryChooserDescriptor);

    colorTextField.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Color color = ColorChooser.chooseColor(WindowManager.getInstance().suggestParentWindow(project),
                    "Select color", null);
            if (color != null) {
                colorTextField.setText('#' + ColorUtil.toHex(color));
                colorTextField.setForeground(color);
            }
        }
    });

    // select appcompat by default
    compatComboBox.setSelectedIndex(2);
    oldSdkRadio.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            compatComboBox.setEnabled(oldSdkRadio.isSelected());
        }
    });

    init();
}

From source file:org.yccheok.jstock.gui.charting.DynamicChart.java

public void showNewJDialog(java.awt.Frame parent, String title) {
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(this.price);

    JFreeChart freeChart = ChartFactory.createTimeSeriesChart(title, GUIBundle.getString("DynamicChart_Date"),
            GUIBundle.getString("DynamicChart_Price"), dataset, true, true, false);

    freeChart.setAntiAlias(true);//from   w  w  w. j av  a2s  .c om

    XYPlot plot = freeChart.getXYPlot();
    NumberAxis rangeAxis1 = (NumberAxis) plot.getRangeAxis();
    DecimalFormat format = new DecimalFormat("00.00");
    rangeAxis1.setNumberFormatOverride(format);

    XYItemRenderer renderer1 = plot.getRenderer();
    renderer1.setBaseToolTipGenerator(
            new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                    new SimpleDateFormat("h:mm:ss a"), new DecimalFormat("0.00#")));

    org.yccheok.jstock.charting.Utils.applyChartTheme(freeChart);

    ChartPanel _chartPanel = new ChartPanel(freeChart, true, true, true, true, true);
    JDialog dialog = new JDialog(parent, title, false);
    dialog.getContentPane().add(_chartPanel, java.awt.BorderLayout.CENTER);
    dialog.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
    final java.awt.Dimension screenSize = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
    dialog.setBounds((screenSize.width - 750) >> 1, (screenSize.height - 600) >> 1, 750, 600);
    dialog.setVisible(true);
}

From source file:de.codesourcery.gittimelapse.MyFrame.java

public MyFrame(File file, GitHelper gitHelper) throws RevisionSyntaxException, MissingObjectException,
        IncorrectObjectTypeException, AmbiguousObjectException, IOException, GitAPIException {
    super("GIT timelapse: " + file.getAbsolutePath());
    if (gitHelper == null) {
        throw new IllegalArgumentException("gitHelper must not be NULL");
    }//from www .j a  v  a  2 s  . c om

    this.gitHelper = gitHelper;
    this.file = file;
    this.diffPanel = new DiffPanel();

    final JDialog dialog = new JDialog((Frame) null, "Please wait...", false);
    dialog.getContentPane().setLayout(new BorderLayout());
    dialog.getContentPane().add(new JLabel("Please wait, locating revisions..."), BorderLayout.CENTER);
    dialog.pack();
    dialog.setVisible(true);

    final IProgressCallback callback = new IProgressCallback() {

        @Override
        public void foundCommit(ObjectId commitId) {
            System.out.println("*** Found commit " + commitId);
        }
    };

    System.out.println("Locating commits...");
    commitList = gitHelper.findCommits(file, callback);

    dialog.setVisible(false);

    if (commitList.isEmpty()) {
        throw new RuntimeException("Found no commits");
    }
    setMenuBar(createMenuBar());

    diffModeChooser.setModel(new DefaultComboBoxModel<MyFrame.DiffDisplayMode>(DiffDisplayMode.values()));
    diffModeChooser.setSelectedItem(DiffDisplayMode.ALIGN_CHANGES);
    diffModeChooser.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1);
            try {
                diffPanel.showRevision(commit);
            } catch (IOException | PatchApplyException e1) {
                e1.printStackTrace();
            }
        }
    });

    diffModeChooser.setRenderer(new DefaultListCellRenderer() {

        @Override
        public Component getListCellRendererComponent(JList<?> list, Object value, int index,
                boolean isSelected, boolean cellHasFocus) {
            Component result = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
            DiffDisplayMode mode = (DiffDisplayMode) value;
            switch (mode) {
            case ALIGN_CHANGES:
                setText("Align changes");
                break;
            case REGULAR:
                setText("Regular");
                break;
            default:
                setText(mode.toString());
            }
            return result;
        }
    });

    revisionSlider = new JSlider(1, commitList.size());

    revisionSlider.setPaintLabels(true);
    revisionSlider.setPaintTicks(true);

    addKeyListener(keyListener);
    getContentPane().addKeyListener(keyListener);

    if (commitList.size() < 10) {
        revisionSlider.setMajorTickSpacing(1);
        revisionSlider.setMinorTickSpacing(1);
    } else {
        revisionSlider.setMajorTickSpacing(5);
        revisionSlider.setMinorTickSpacing(1);
    }

    final ObjectId latestCommit = commitList.getLatestCommit();
    if (latestCommit != null) {
        revisionSlider.setValue(1 + commitList.indexOf(latestCommit));
        revisionSlider.setToolTipText(latestCommit.getName());
    }

    revisionSlider.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent e) {
            if (!revisionSlider.getValueIsAdjusting()) {
                final ObjectId commit = commitList.getCommit(revisionSlider.getValue() - 1);
                long time = -System.currentTimeMillis();
                try {
                    diffPanel.showRevision(commit);
                } catch (IOException | PatchApplyException e1) {
                    e1.printStackTrace();
                } finally {
                    time += System.currentTimeMillis();
                }
                if (Main.DEBUG_MODE) {
                    System.out.println("Rendering time: " + time);
                }
            }
        }
    });

    getContentPane().setLayout(new GridBagLayout());

    GridBagConstraints cnstrs = new GridBagConstraints();
    cnstrs.gridx = 0;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.NONE;

    getContentPane().add(new JLabel("Diff display mode:"), cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 1;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.NONE;

    getContentPane().add(diffModeChooser, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 2;
    cnstrs.gridy = 0;
    cnstrs.gridwidth = 1;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 1.0;
    cnstrs.weighty = 0;
    cnstrs.fill = GridBagConstraints.HORIZONTAL;

    getContentPane().add(revisionSlider, cnstrs);

    cnstrs = new GridBagConstraints();
    cnstrs.gridx = 0;
    cnstrs.gridy = 1;
    cnstrs.gridwidth = 3;
    cnstrs.gridheight = 1;
    cnstrs.weightx = 1;
    cnstrs.weighty = 1;
    cnstrs.fill = GridBagConstraints.BOTH;

    getContentPane().add(diffPanel, cnstrs);

    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    if (latestCommit != null) {
        diffPanel.showRevision(latestCommit);
    }
}

From source file:com.sshtools.common.ui.SshToolsConnectionPanel.java

/**
 *
 *
 * @param parent/*from www  .j  a  v  a 2s  . c om*/
 * @param profile
 * @param optionalTabs
 *
 * @return
 */
public static SshToolsConnectionProfile showConnectionDialog(Component parent,
        SshToolsConnectionProfile profile, SshToolsConnectionTab[] optionalTabs) {
    //  If no properties are provided, then use the default
    if (profile == null) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile = new SshToolsConnectionProfile();
        profile.setHost(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_HOST, ""));
        profile.setPort(PreferencesStore.getInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, port));
        profile.setUsername(PreferencesStore.get(SshToolsApplication.PREF_CONNECTION_LAST_USER, ""));

    }

    final SshToolsConnectionPanel conx = new SshToolsConnectionPanel(true);

    if (optionalTabs != null) {
        for (int i = 0; i < optionalTabs.length; i++) {
            conx.addTab(optionalTabs[i]);
        }
    }

    conx.setConnectionProfile(profile);

    JDialog d = null;
    Window w = (Window) SwingUtilities.getAncestorOfClass(Window.class, parent);

    if (w instanceof JDialog) {
        d = new JDialog((JDialog) w, "Connection Profile", true);
    } else if (w instanceof JFrame) {
        d = new JDialog((JFrame) w, "Connection Profile", true);
    } else {
        d = new JDialog((JFrame) null, "Connection Profile", true);
    }

    final JDialog dialog = d;

    class UserAction {
        boolean connect;
    }

    final UserAction userAction = new UserAction();

    //  Create the bottom button panel
    final JButton cancel = new JButton("Cancel");
    cancel.setMnemonic('c');
    cancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            userAction.connect = false;
            dialog.setVisible(false);
        }
    });

    final JButton connect = new JButton("Connect");
    connect.setMnemonic('t');
    connect.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (conx.validateTabs()) {
                userAction.connect = true;
                dialog.setVisible(false);
            }
        }
    });
    dialog.getRootPane().setDefaultButton(connect);

    JPanel buttonPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    gbc.fill = GridBagConstraints.HORIZONTAL;
    gbc.anchor = GridBagConstraints.CENTER;
    gbc.insets = new Insets(6, 6, 0, 0);
    gbc.weighty = 1.0;
    UIUtil.jGridBagAdd(buttonPanel, connect, gbc, GridBagConstraints.RELATIVE);
    UIUtil.jGridBagAdd(buttonPanel, cancel, gbc, GridBagConstraints.REMAINDER);

    JPanel southPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT, 0, 0));
    southPanel.add(buttonPanel);

    //
    JPanel mainPanel = new JPanel(new BorderLayout());
    mainPanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    mainPanel.add(conx, BorderLayout.CENTER);
    mainPanel.add(southPanel, BorderLayout.SOUTH);

    // Show the dialog
    dialog.getContentPane().setLayout(new GridLayout(1, 1));
    dialog.getContentPane().add(mainPanel);
    dialog.pack();
    dialog.setResizable(false);
    UIUtil.positionComponent(SwingConstants.CENTER, dialog);

    //show the simple box and act on the answer.
    SshToolsSimpleConnectionPrompt stscp = SshToolsSimpleConnectionPrompt.getInstance();
    StringBuffer sb = new StringBuffer();
    userAction.connect = !stscp.getHostname(sb, profile.getHost());

    boolean advanced = stscp.getAdvanced();

    if (advanced) {
        userAction.connect = false;
        profile.setHost(sb.toString());
        conx.hosttab.setConnectionProfile(profile);
        dialog.setVisible(true);
    }

    // Make sure we didn't cancel
    if (!userAction.connect) {
        return null;
    }

    conx.applyTabs();
    if (!advanced)
        profile.setHost(sb.toString());
    if (!advanced) {
        int port = DEFAULT_PORT;
        String port_S = Integer.toString(DEFAULT_PORT);
        port_S = PreferencesStore.get(SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT, port_S);
        try {
            port = Integer.parseInt(port_S);
        } catch (NumberFormatException e) {
            log.warn("Could not parse the port number from defaults file (property name"
                    + SshTerminalPanel.PREF_DEFAULT_SIMPLE_PORT + ", property value= " + port_S + ").");
        }
        profile.setPort(port);
    }
    if (!advanced)
        profile.setUsername("");

    PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_HOST, profile.getHost());
    // only save user inputed configuration
    if (advanced) {
        PreferencesStore.put(SshToolsApplication.PREF_CONNECTION_LAST_USER, profile.getUsername());
        PreferencesStore.putInt(SshToolsApplication.PREF_CONNECTION_LAST_PORT, profile.getPort());
    }
    // Return the connection properties
    return profile;
}

From source file:net.sf.jabref.gui.search.SearchResultsDialog.java

private void init(String title) {
    diag = new JDialog(frame, title, false);

    int activePreview = Globals.prefs.getInt(JabRefPreferences.ACTIVE_PREVIEW);
    String layoutFile = activePreview == 0 ? Globals.prefs.get(JabRefPreferences.PREVIEW_0)
            : Globals.prefs.get(JabRefPreferences.PREVIEW_1);
    preview = new PreviewPanel(null, null, layoutFile);

    sortedEntries = new SortedList<>(entries, new EntryComparator(false, true, FieldName.AUTHOR));
    model = (DefaultEventTableModel<BibEntry>) GlazedListsSwing
            .eventTableModelWithThreadProxyList(sortedEntries, new EntryTableFormat());
    entryTable = new JTable(model);
    GeneralRenderer renderer = new GeneralRenderer(Color.white);
    entryTable.setDefaultRenderer(JLabel.class, renderer);
    entryTable.setDefaultRenderer(String.class, renderer);
    setWidths();/*from ww w .  j a  va  2  s .  co  m*/
    TableComparatorChooser<BibEntry> tableSorter = TableComparatorChooser.install(entryTable, sortedEntries,
            AbstractTableComparatorChooser.MULTIPLE_COLUMN_KEYBOARD);
    setupComparatorChooser(tableSorter);
    JScrollPane sp = new JScrollPane(entryTable);

    final DefaultEventSelectionModel<BibEntry> selectionModel = (DefaultEventSelectionModel<BibEntry>) GlazedListsSwing
            .eventSelectionModelWithThreadProxyList(sortedEntries);
    entryTable.setSelectionModel(selectionModel);
    selectionModel.getSelected().addListEventListener(new EntrySelectionListener());
    entryTable.addMouseListener(new TableClickListener());

    contentPane.setTopComponent(sp);
    contentPane.setBottomComponent(preview);

    // Key bindings:
    AbstractAction closeAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            diag.dispose();
        }
    };
    ActionMap am = contentPane.getActionMap();
    InputMap im = contentPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", closeAction);

    entryTable.getActionMap().put("copy", new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            if (!selectionModel.getSelected().isEmpty()) {
                List<BibEntry> bes = selectionModel.getSelected();
                TransferableBibtexEntry trbe = new TransferableBibtexEntry(bes);
                // ! look at ClipBoardManager
                Toolkit.getDefaultToolkit().getSystemClipboard().setContents(trbe, frame.getCurrentBasePanel());
                frame.output(Localization.lang("Copied") + ' '
                        + (bes.size() > 1 ? bes.size() + " " + Localization.lang("entries")
                                : "1 " + Localization.lang("entry") + '.'));
            }
        }
    });

    diag.addWindowListener(new WindowAdapter() {

        @Override
        public void windowOpened(WindowEvent e) {
            contentPane.setDividerLocation(0.5f);
        }

        @Override
        public void windowClosing(WindowEvent event) {
            Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_WIDTH, diag.getSize().width);
            Globals.prefs.putInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT, diag.getSize().height);
        }
    });

    diag.getContentPane().add(contentPane, BorderLayout.CENTER);
    // Remember and default to last size:
    diag.setSize(new Dimension(Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_WIDTH),
            Globals.prefs.getInt(JabRefPreferences.SEARCH_DIALOG_HEIGHT)));
    diag.setLocationRelativeTo(frame);
}