Example usage for javax.swing JSplitPane setResizeWeight

List of usage examples for javax.swing JSplitPane setResizeWeight

Introduction

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

Prototype

@BeanProperty(description = "Specifies how to distribute extra space when the split pane resizes.")
public void setResizeWeight(double value) 

Source Link

Document

Specifies how to distribute extra space when the size of the split pane changes.

Usage

From source file:org.tinymediamanager.ui.movies.dialogs.MovieExporterDialog.java

/**
 * Create the dialog.//from  w w  w. ja  v  a 2  s  .c  o  m
 * 
 * @param moviesToExport
 *          the movies to export
 */
public MovieExporterDialog(List<Movie> moviesToExport) {
    super(BUNDLE.getString("movie.export"), "movieExporter"); //$NON-NLS-1$
    setBounds(5, 5, 600, 300);

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("300dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    getContentPane().add(splitPane, "2, 2, fill, fill");

    JScrollPane scrollPane = new JScrollPane();
    splitPane.setLeftComponent(scrollPane);

    list = new JList();
    scrollPane.setViewportView(list);

    JPanel panelExporterDetails = new JPanel();
    splitPane.setRightComponent(panelExporterDetails);
    panelExporterDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    lblTemplateName = new JLabel("");
    panelExporterDetails.add(lblTemplateName, "2, 2, 3, 1");

    lblUrl = new JLabel("");
    panelExporterDetails.add(lblUrl, "2, 4, 3, 1");

    chckbxTemplateWithDetail = new JCheckBox("");
    chckbxTemplateWithDetail.setEnabled(false);
    panelExporterDetails.add(chckbxTemplateWithDetail, "2, 6");

    JLabel lblDetails = new JLabel(BUNDLE.getString("export.detail")); //$NON-NLS-1$
    panelExporterDetails.add(lblDetails, "4, 6");

    JScrollPane scrollPaneDescription = new JScrollPane();
    panelExporterDetails.add(scrollPaneDescription, "2, 8, 3, 1, fill, fill");

    tpDescription = new JTextPane();
    scrollPaneDescription.setViewportView(tpDescription);
    splitPane.setDividerLocation(300);

    JPanel panelDestination = new JPanel();
    getContentPane().add(panelDestination, "2, 4, fill, fill");
    panelDestination
            .setLayout(
                    new FormLayout(
                            new ColumnSpec[] { ColumnSpec.decode("150dlu:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                                    FormSpecs.DEFAULT_COLSPEC, },
                            new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, }));

    tfExportDir = new JTextField();
    panelDestination.add(tfExportDir, "1, 1, fill, default");
    tfExportDir.setColumns(10);

    JButton btnSetDestination = new JButton(BUNDLE.getString("export.setdestination")); //$NON-NLS-1$
    panelDestination.add(btnSetDestination, "3, 1");
    btnSetDestination.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("export.selectdirectory")); //$NON-NLS-1$
            if (file != null) {
                tfExportDir.setText(file.toAbsolutePath().toString());
            }
        }
    });

    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new EqualsLayout(5));
    getContentPane().add(panelButtons, "2, 6, fill, fill");

    JButton btnExport = new JButton("Export");
    btnExport.setIcon(IconManager.EXPORT);
    btnExport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (StringUtils.isBlank(tfExportDir.getText())) {
                return;
            }
            // check selected template
            int index = list.getSelectedIndex();
            if (index < 0) {
                return;
            }

            ExportTemplate selectedTemplate = templatesFound.get(index);
            if (selectedTemplate != null) {
                try {
                    MovieExporter exporter = new MovieExporter(Paths.get(selectedTemplate.getPath()));
                    exporter.export(movies, Paths.get(tfExportDir.getText()));
                } catch (Exception e) {
                    LOGGER.error("Error exporting movies: ", e);
                }
                setVisible(false);
            }
        }
    });
    panelButtons.add(btnExport);

    JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    btnCancel.setIcon(IconManager.CANCEL);
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });
    panelButtons.add(btnCancel);

    movies = moviesToExport;
    templatesFound = MovieExporter.findTemplates(TemplateType.MOVIE);
    initDataBindings();
}

From source file:org.tinymediamanager.ui.moviesets.dialogs.MovieSetChooserDialog.java

/**
 * Instantiates a new movie set chooser panel.
 * /*from  w ww  . j a v  a 2s  .  c  o m*/
 * @param movieSet
 *          the movie set
 */
public MovieSetChooserDialog(MovieSet movieSet, boolean inQueue) {
    super(BUNDLE.getString("movieset.search"), "movieSetChooser"); //$NON-NLS-1$
    setBounds(5, 5, 865, 578);

    movieSetToScrape = movieSet;

    getContentPane().setLayout(new BorderLayout(0, 0));

    JPanel panelHeader = new JPanel();
    getContentPane().add(panelHeader, BorderLayout.NORTH);
    panelHeader.setLayout(new FormLayout(
            new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("114px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("100px"), ColumnSpec.decode("2dlu"), },
            new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("25px"),
                    FormFactory.RELATED_GAP_ROWSPEC, }));
    {
        tfMovieSetName = new JTextField();
        panelHeader.add(tfMovieSetName, "2, 2, fill, fill");
        tfMovieSetName.setColumns(10);
    }
    {
        JButton btnSearch = new JButton("");
        btnSearch.setAction(actionSearch);
        panelHeader.add(btnSearch, "4, 2, fill, top");
    }
    {
        JSplitPane splitPane = new JSplitPane();
        splitPane.setContinuousLayout(true);
        splitPane.setResizeWeight(0.5);
        getContentPane().add(splitPane, BorderLayout.CENTER);
        {
            JPanel panelResults = new JPanel();
            panelResults.setLayout(new FormLayout(
                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("300px:grow"), },
                    new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, RowSpec.decode("fill:403px:grow"), }));
            JScrollPane panelSearchResults = new JScrollPane();
            panelResults.add(panelSearchResults, "2, 2, fill, fill");
            splitPane.setLeftComponent(panelResults);
            {
                tableMovieSets = new JTable();
                panelSearchResults.setViewportView(tableMovieSets);
                tableMovieSets.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                tableMovieSets.setBorder(new LineBorder(new Color(0, 0, 0)));
                ListSelectionModel rowSM = tableMovieSets.getSelectionModel();
                rowSM.addListSelectionListener(new ListSelectionListener() {
                    public void valueChanged(ListSelectionEvent e) {
                        // Ignore extra messages.
                        if (e.getValueIsAdjusting())
                            return;

                        ListSelectionModel lsm = (ListSelectionModel) e.getSource();
                        if (!lsm.isSelectionEmpty()) {
                            int selectedRow = lsm.getMinSelectionIndex();
                            selectedRow = tableMovieSets.convertRowIndexToModel(selectedRow);
                            try {
                                MovieSetChooserModel model = movieSetsFound.get(selectedRow);
                                if (model != MovieSetChooserModel.emptyResult && !model.isScraped()) {
                                    ScrapeTask task = new ScrapeTask(model);
                                    task.execute();

                                }
                            } catch (Exception ex) {
                                LOGGER.warn(ex.getMessage());
                            }
                        }
                    }
                });
            }
        }
        {
            JPanel panelSearchDetail = new JPanel();
            splitPane.setRightComponent(panelSearchDetail);
            panelSearchDetail.setLayout(new FormLayout(
                    new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("left:150px"),
                            FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("max(300px;default):grow"),
                            FormFactory.RELATED_GAP_COLSPEC, },
                    new RowSpec[] { FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC,
                            RowSpec.decode("250px"), FormFactory.PARAGRAPH_GAP_ROWSPEC,
                            RowSpec.decode("top:default:grow"), FormFactory.RELATED_GAP_ROWSPEC,
                            FormFactory.DEFAULT_ROWSPEC, FormFactory.RELATED_GAP_ROWSPEC }));
            {
                lblMovieSetName = new JTextArea("");
                lblMovieSetName.setLineWrap(true);
                lblMovieSetName.setOpaque(false);
                lblMovieSetName.setWrapStyleWord(true);
                TmmFontHelper.changeFont(lblMovieSetName, 1.166, Font.BOLD);
                panelSearchDetail.add(lblMovieSetName, "2, 1, 3, 1, fill, top");
            }
            {
                lblMovieSetPoster = new ImageLabel();
                lblMovieSetPoster.setAlternativeText(BUNDLE.getString("image.notfound.poster")); //$NON-NLS-1$
                panelSearchDetail.add(lblMovieSetPoster, "2, 3, fill, fill");
            }
            {
                JPanel panel = new JPanel();
                panelSearchDetail.add(panel, "4, 3, fill, fill");
                panel.setLayout(new FormLayout(
                        new ColumnSpec[] { FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC,
                                FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("default:grow"), },
                        new RowSpec[] { FormFactory.RELATED_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC, }));
            }
            {

                JScrollPane scrollPane = new JScrollPane();
                panelSearchDetail.add(scrollPane, "2, 5, 3, 1, fill, fill");
                {
                    tableMovies = new JTable();
                    scrollPane.setViewportView(tableMovies);
                }

            }
            {
                cbAssignMovies = new JCheckBox(BUNDLE.getString("movieset.movie.assign")); //$NON-NLS-1$
                cbAssignMovies.setSelected(true);
                panelSearchDetail.add(cbAssignMovies, "2, 7, 3, 1");
            }
        }
    }

    {
        JPanel bottomPane = new JPanel();
        getContentPane().add(bottomPane, BorderLayout.SOUTH);
        {
            bottomPane.setLayout(new FormLayout(new ColumnSpec[] { ColumnSpec.decode("2dlu"),
                    ColumnSpec.decode("185px"), FormFactory.RELATED_GAP_COLSPEC, ColumnSpec.decode("18px:grow"),
                    FormFactory.RELATED_GAP_COLSPEC, FormFactory.DEFAULT_COLSPEC, ColumnSpec.decode("2dlu"), },
                    new RowSpec[] { FormFactory.LINE_GAP_ROWSPEC, FormFactory.DEFAULT_ROWSPEC,
                            FormFactory.LINE_GAP_ROWSPEC }));
            {
                progressBar = new JProgressBar();
                bottomPane.add(progressBar, "2, 2, fill, center");
            }
            {
                lblProgressAction = new JLabel("");
                bottomPane.add(lblProgressAction, "4, 2, fill, center");
            }
            {
                JPanel buttonPane = new JPanel();
                bottomPane.add(buttonPane, "6, 2, fill, fill");
                EqualsLayout layout = new EqualsLayout(5);
                buttonPane.setBorder(new EmptyBorder(4, 4, 4, 4));
                layout.setMinWidth(100);
                buttonPane.setLayout(layout);

                btnOk = new JButton(BUNDLE.getString("Button.ok")); //$NON-NLS-1$
                btnOk.setActionCommand("Save");
                btnOk.setToolTipText(BUNDLE.getString("Button.ok")); //$NON-NLS-1$
                btnOk.setIcon(IconManager.APPLY);
                btnOk.addActionListener(this);
                buttonPane.add(btnOk);

                JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
                btnCancel.setActionCommand("Cancel");
                btnCancel.setToolTipText(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
                btnCancel.setIcon(IconManager.CANCEL);
                btnCancel.addActionListener(this);
                buttonPane.add(btnCancel);

                if (inQueue) {
                    JButton btnAbort = new JButton(BUNDLE.getString("Button.abortqueue")); //$NON-NLS-1$
                    btnAbort.setActionCommand("Abort");
                    btnAbort.setToolTipText(BUNDLE.getString("Button.abortqueue")); //$NON-NLS-1$
                    btnAbort.setIcon(IconManager.PROCESS_STOP);
                    btnAbort.addActionListener(this);
                    buttonPane.add(btnAbort, "6, 1, fill, top");
                }
            }
        }
    }
    initDataBindings();

    // adjust table columns
    tableMovies.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tableMovies.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);

    tableMovieSets.getColumnModel().getColumn(0).setHeaderValue(BUNDLE.getString("chooser.searchresult"));
    tfMovieSetName.setText(movieSet.getTitle());
    searchMovie();

}

From source file:org.tinymediamanager.ui.tvshows.dialogs.TvShowExporterDialog.java

/**
 * Create the dialog./* www . ja  va2  s  .c  o  m*/
 * 
 * @param tvShowsToExport
 *          the movies to export
 */
public TvShowExporterDialog(List<TvShow> tvShowsToExport) {
    super(BUNDLE.getString("tvshow.export"), "tvShowExporter"); //$NON-NLS-1$
    setBounds(5, 5, 600, 300);

    getContentPane().setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, ColumnSpec.decode("300dlu:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("100dlu:grow"),
                    FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC, FormSpecs.UNRELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, }));

    JSplitPane splitPane = new JSplitPane();
    splitPane.setResizeWeight(0.7);
    getContentPane().add(splitPane, "2, 2, fill, fill");

    JScrollPane scrollPane = new JScrollPane();
    splitPane.setLeftComponent(scrollPane);

    list = new JList();
    scrollPane.setViewportView(list);

    JPanel panelExporterDetails = new JPanel();
    splitPane.setRightComponent(panelExporterDetails);
    panelExporterDetails.setLayout(new FormLayout(
            new ColumnSpec[] { FormSpecs.RELATED_GAP_COLSPEC, FormSpecs.DEFAULT_COLSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("default:grow"),
                    FormSpecs.RELATED_GAP_COLSPEC, },
            new RowSpec[] { FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    FormSpecs.LABEL_COMPONENT_GAP_ROWSPEC, RowSpec.decode("default:grow"), }));

    lblTemplateName = new JLabel("");
    panelExporterDetails.add(lblTemplateName, "2, 2, 3, 1");

    lblUrl = new JLabel("");
    panelExporterDetails.add(lblUrl, "2, 4, 3, 1");

    chckbxTemplateWithDetail = new JCheckBox("");
    chckbxTemplateWithDetail.setEnabled(false);
    panelExporterDetails.add(chckbxTemplateWithDetail, "2, 6");

    JLabel lblDetails = new JLabel(BUNDLE.getString("export.detail")); //$NON-NLS-1$
    panelExporterDetails.add(lblDetails, "4, 6");

    JScrollPane scrollPaneDescription = new JScrollPane();
    panelExporterDetails.add(scrollPaneDescription, "2, 8, 3, 1, fill, fill");

    tpDescription = new JTextPane();
    scrollPaneDescription.setViewportView(tpDescription);
    splitPane.setDividerLocation(300);

    JPanel panel = new JPanel();
    getContentPane().add(panel, "2, 4, fill, fill");
    panel.setLayout(
            new FormLayout(new ColumnSpec[] { ColumnSpec.decode("default:grow"), FormSpecs.RELATED_GAP_COLSPEC,
                    FormSpecs.DEFAULT_COLSPEC, }, new RowSpec[] { FormSpecs.DEFAULT_ROWSPEC, }));

    tfExportDir = new JTextField();
    panel.add(tfExportDir, "1, 1, fill, default");
    tfExportDir.setColumns(10);

    JButton btnSetDestination = new JButton(BUNDLE.getString("export.setdestination")); //$NON-NLS-1$
    panel.add(btnSetDestination, "3, 1");
    btnSetDestination.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            Path file = TmmUIHelper.selectDirectory(BUNDLE.getString("export.selectdirectory")); //$NON-NLS-1$
            if (file != null) {
                tfExportDir.setText(file.toAbsolutePath().toString());
            }
        }
    });

    JPanel panelButtons = new JPanel();
    panelButtons.setLayout(new EqualsLayout(5));
    getContentPane().add(panelButtons, "2, 6, fill, fill");

    JButton btnExport = new JButton("Export");
    btnExport.setIcon(IconManager.EXPORT);
    btnExport.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            if (StringUtils.isBlank(tfExportDir.getText())) {
                return;
            }
            // check selected template
            int index = list.getSelectedIndex();
            if (index < 0) {
                return;
            }

            ExportTemplate selectedTemplate = templatesFound.get(index);
            if (selectedTemplate != null) {
                try {
                    TvShowExporter exporter = new TvShowExporter(Paths.get(selectedTemplate.getPath()));
                    exporter.export(tvShows, Paths.get(tfExportDir.getText()));
                } catch (Exception e) {
                    LOGGER.error("Error exporting tv shows: ", e);
                }
                setVisible(false);
            }
        }
    });
    panelButtons.add(btnExport);

    JButton btnCancel = new JButton(BUNDLE.getString("Button.cancel")); //$NON-NLS-1$
    btnCancel.setIcon(IconManager.CANCEL);
    btnCancel.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            setVisible(false);
        }
    });
    panelButtons.add(btnCancel);

    tvShows = tvShowsToExport;
    templatesFound = TvShowExporter.findTemplates(TemplateType.TV_SHOW);
    initDataBindings();
}

From source file:org.ut.biolab.medsavant.client.region.RegionWizard.java

private AbstractWizardPage getGenesPage() {
    return new DefaultWizardPage(PAGENAME_GENES) {
        private static final int GENE_SELECTION_PANE_WIDTH = 350;
        private JPanel leftSide;
        private GeneSelectionPanel geneManiaResultsPanel;
        private Set<String> geneManiaGeneNames = null;

        {//from ww  w  . j  a  v  a 2  s . c  o  m
            selectedGenesPanel = new GeneSelectionPanel(true, true);
            sourceGenesPanel = new GeneSelectionPanel(true, true);
            geneManiaResultsPanel = new GeneSelectionPanel(true, true) {
                @Override
                protected void dragAndDropAddGenes(Set<Gene> geneSet) {
                    Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                    genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                    selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                    selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                }

                @Override
                protected void dragAndDropRemoveKeys(Set<Object> keySet) {
                    Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                    geneManiaResultsPanel.removeRows(keys);
                    sourceGenesPanel.removeRows(keys);
                }
            };
            geneManiaResultsPanel.setOddRowColor(new Color(242, 249, 245));

            runGeneManiaButton = new JButton("Run GeneMANIA");
            runGeneManiaButton.setEnabled(!DirectorySettings.isGeneManiaInstalled());

            ListSelectionListener selectionListener = new ListSelectionListener() {
                @Override
                public void valueChanged(ListSelectionEvent lse) {
                    int numSel = sourceGenesPanel.getNumSelected() + selectedGenesPanel.getNumSelected();
                    if (geneManiaGeneNames != null) {
                        numSel += geneManiaResultsPanel.getNumSelected();
                    }
                    if (GenemaniaInfoRetriever.isGeneManiaDownloading()) {
                        runGeneManiaButton.setEnabled(false);
                    } else {
                        runGeneManiaButton.setEnabled(numSel > 0 || !DirectorySettings.isGeneManiaInstalled());
                    }
                }
            };

            sourceGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener);
            selectedGenesPanel.getTable().getSelectionModel().addListSelectionListener(selectionListener);
            selectedGenesPanel.getTable().getModel().addTableModelListener(new TableModelListener() {
                @Override
                public void tableChanged(TableModelEvent tme) {
                    if (selectedGenesPanel.getData().length > 0) {
                        fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
                    } else {
                        fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT);
                    }
                }
            });

            selectedGenesPanel.setPreferredSize(
                    new Dimension(GENE_SELECTION_PANE_WIDTH, selectedGenesPanel.getPreferredSize().height));

            final JPanel outerLeftSide = new JPanel();
            outerLeftSide.setLayout(new BoxLayout(outerLeftSide, BoxLayout.X_AXIS));

            leftSide = new JPanel();
            leftSide.setLayout(new BoxLayout(leftSide, BoxLayout.Y_AXIS));
            leftSide.add(sourceGenesPanel);
            outerLeftSide.add(leftSide);
            final JPanel bg = new JPanel();
            bg.setLayout(new BoxLayout(bg, BoxLayout.Y_AXIS));

            JButton addButton = new JButton("Add ");
            JButton removeButton = new JButton("? Remove");

            sourceGenesPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        sourceGenesPanel.moveSelectedItems(selectedGenesPanel);
                    }
                }
            });

            selectedGenesPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        if (geneManiaGeneNames != null) {
                            Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                            genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                            selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                        }
                        selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                    }
                }
            });

            geneManiaResultsPanel.getTable().addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent me) {
                    if (me.getClickCount() == 2) {
                        Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                        geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel);
                        sourceGenesPanel.moveItems(selectedGenesPanel, keys);
                    }
                }
            });

            addButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    if (geneManiaGeneNames != null) {
                        Set<Object> keys = geneManiaResultsPanel.getSelectedKeys();
                        geneManiaResultsPanel.moveSelectedItems(selectedGenesPanel);
                        sourceGenesPanel.moveItems(selectedGenesPanel, keys);
                    } else {
                        sourceGenesPanel.moveSelectedItems(selectedGenesPanel);
                    }
                }
            });

            removeButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {
                    if (geneManiaGeneNames != null) {
                        Set<Object> genesToMoveToGeneManiaPanel = new HashSet<Object>(geneManiaGeneNames);
                        genesToMoveToGeneManiaPanel.retainAll(selectedGenesPanel.getSelectedKeys());
                        selectedGenesPanel.copyItems(geneManiaResultsPanel, genesToMoveToGeneManiaPanel);
                    }
                    selectedGenesPanel.moveSelectedItems(sourceGenesPanel);
                }
            });

            bg.add(Box.createVerticalGlue());
            bg.add(addButton);
            bg.add(removeButton);
            bg.add(Box.createVerticalGlue());
            outerLeftSide.add(bg);

            JPanel rightSide = new JPanel();
            rightSide.setLayout(new BoxLayout(rightSide, BoxLayout.Y_AXIS));
            rightSide.add(selectedGenesPanel);
            rightSide.add(runGeneManiaButton);

            final JSplitPane hsplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, outerLeftSide, rightSide);
            hsplitPane.setResizeWeight(1);
            addComponent(hsplitPane, true);

            if (!DirectorySettings.isGeneManiaInstalled()) {
                runGeneManiaButton.setText("Download GeneMANIA");
                if (GenemaniaInfoRetriever.isGeneManiaDownloading()) {
                    runGeneManiaButton.setEnabled(false);
                    registerDownloadListener();
                }
            }

            runGeneManiaButton.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent ae) {

                    if (!DirectorySettings.isGeneManiaInstalled()) {
                        int response = DialogUtils.askYesNo("Download GeneMANIA?",
                                "GeneMANIA is not yet installed.  Do you want to download and install it now?");
                        try {
                            if (response == DialogUtils.OK) {
                                runGeneManiaButton.setText("Run GeneMANIA");
                                runGeneManiaButton.setEnabled(false);
                                registerDownloadListener();

                                /*
                                 DownloadTask dt = GenemaniaInfoRetriever.getGeneManiaDownloadTask();
                                 dt.addPropertyChangeListener(new PropertyChangeListener() {
                                 @Override
                                 public void propertyChange(PropertyChangeEvent evt) {
                                 if (evt.getPropertyName().equals("downloadState")) {
                                 DownloadTask.DownloadState ds = (DownloadTask.DownloadState) evt.getNewValue();
                                 if (ds == DownloadTask.DownloadState.CANCELLED
                                 || ds == DownloadTask.DownloadState.FINISHED) {
                                        
                                 runGeneManiaButton.setEnabled(
                                 (selectedGenesPanel.getNumSelected() + sourceGenesPanel.getNumSelected()) > 0);
                                 }
                                 }
                                 }
                                 });
                                 */
                                GenemaniaInfoRetriever.getGeneManiaDownloadTask().execute();
                            }
                        } catch (IOException e) {
                            DialogUtils.displayMessage("Error downloading GeneMANIA files");
                            LOG.error(e);
                        }
                    } else {

                        final List<String> selectedGenes = new LinkedList<String>();
                        for (Gene g : selectedGenesPanel.getSelectedGenes()) {
                            selectedGenes.add(g.getName());
                        }
                        for (Gene g : sourceGenesPanel.getSelectedGenes()) {
                            selectedGenes.add(g.getName());
                        }
                        if (geneManiaGeneNames != null) {
                            for (Gene g : geneManiaResultsPanel.getSelectedGenes()) {
                                selectedGenes.add(g.getName());
                            }
                        }
                        final JButton closeGeneManiaButton = new JButton("? Close GeneMANIA results");
                        closeGeneManiaButton.setEnabled(false);
                        final JPanel geneManiaContainingPanel = new JPanel();
                        geneManiaContainingPanel
                                .setLayout(new BoxLayout(geneManiaContainingPanel, BoxLayout.Y_AXIS));

                        final SwingWorker geneManiaWorker = new SwingWorker() {
                            private List<Object[]> results;

                            @Override
                            public void done() {
                                Object[][] newdata = new Object[results.size()][4];
                                results.toArray(newdata);
                                geneManiaResultsPanel.updateData(newdata);
                                geneManiaResultsPanel.updateView();
                                geneManiaContainingPanel.removeAll();
                                geneManiaContainingPanel.add(geneManiaResultsPanel);
                                geneManiaContainingPanel.revalidate();
                                geneManiaContainingPanel.repaint();
                                closeGeneManiaButton.setEnabled(true);
                            }

                            @Override
                            public Object doInBackground() {
                                try {
                                    GenemaniaInfoRetriever genemania = new GenemaniaInfoRetriever();
                                    genemania.setGenes(selectedGenes);
                                    List<String> geneNameList = genemania.getRelatedGeneNamesByScore();
                                    geneManiaGeneNames = new HashSet<String>();
                                    geneManiaGeneNames.addAll(geneNameList);
                                    LOG.debug("Found " + geneNameList.size() + " related genes");

                                    results = new ArrayList<Object[]>(geneNameList.size());

                                    int i = 0;
                                    for (String gene : geneNameList) {
                                        if (isCancelled()) {
                                            return null;
                                        }
                                        Gene g = GeneSetFetcher.getInstance().getGeneDictionary().get(gene);
                                        if (g == null) {
                                            LOG.warn("No gene found for " + gene);
                                        } else if (!selectedGenesPanel.hasKey(g.getName())) {
                                            results.add(new Object[] { g.getName(), g.getChrom(), g.getStart(),
                                                    g.getEnd() });
                                        }
                                    }
                                } catch (IOException e) {
                                    LOG.error(e);
                                } catch (ApplicationException e) {
                                    LOG.error(e);
                                } catch (DataStoreException e) {
                                    LOG.error(e);
                                } catch (NoRelatedGenesInfoException e) {
                                    LOG.error(e);
                                }
                                return null;
                            }
                        };

                        leftSide.removeAll();

                        closeGeneManiaButton.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent ae) {
                                try {
                                    geneManiaWorker.cancel(true);
                                } catch (Exception e) {
                                    //genemania throws exceptions when cancelled
                                }
                                leftSide.removeAll();
                                leftSide.add(sourceGenesPanel);
                                leftSide.validate();
                                leftSide.repaint();
                                geneManiaGeneNames = null;
                            }
                        });

                        JPanel closeButtonPanel = new JPanel();
                        closeButtonPanel.setLayout(new BoxLayout(closeButtonPanel, BoxLayout.X_AXIS));
                        closeButtonPanel.add(closeGeneManiaButton);
                        closeButtonPanel.add(Box.createHorizontalGlue());

                        leftSide.add(closeButtonPanel);

                        geneManiaContainingPanel.add(new WaitPanel("Querying GeneMANIA for related genes"));

                        leftSide.add(geneManiaContainingPanel);
                        leftSide.validate();
                        leftSide.repaint();
                        geneManiaWorker.execute();

                    } //end else
                }//end actionPerformed
            });//end ActionListener
        }

        @Override
        public void setupWizardButtons() {
            fireButtonEvent(ButtonEvent.HIDE_BUTTON, ButtonNames.FINISH);
            fireButtonEvent(ButtonEvent.SHOW_BUTTON, ButtonNames.BACK);

            if (selectedGenesPanel.getNumSelected() > 0) {
                fireButtonEvent(ButtonEvent.ENABLE_BUTTON, ButtonNames.NEXT);
            } else {
                fireButtonEvent(ButtonEvent.DISABLE_BUTTON, ButtonNames.NEXT);
            }
        }
    };
}

From source file:pcgen.gui2.dialog.ChooserDialog.java

private void initComponents() {
    setTitle(chooser.getName());/*from   w ww.  jav a 2  s.  c om*/
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosed(WindowEvent e) {
            //detach listeners from the chooser
            treeViewModel.setDelegate(null);
            listModel.setListFacade(null);
            chooser.getRemainingSelections().removeReferenceListener(ChooserDialog.this);
        }

    });
    Container pane = getContentPane();
    pane.setLayout(new BorderLayout());

    JSplitPane split = new JSplitPane();
    JPanel leftPane = new JPanel(new BorderLayout());
    if (availTable != null) {
        availTable.setAutoCreateRowSorter(true);
        availTable.setTreeViewModel(treeViewModel);
        availTable.getRowSorter().toggleSortOrder(0);
        availTable.addActionListener(this);
        leftPane.add(new JScrollPane(availTable), BorderLayout.CENTER);
    } else {
        availInput.addActionListener(this);
        Dimension maxDim = new Dimension(Integer.MAX_VALUE, availInput.getPreferredSize().height);
        availInput.setMaximumSize(maxDim);
        JPanel availPanel = new JPanel();
        availPanel.setLayout(new BoxLayout(availPanel, BoxLayout.PAGE_AXIS));
        availPanel.add(Box.createRigidArea(new Dimension(10, 30)));
        availPanel.add(Box.createVerticalGlue());
        availPanel.add(new JLabel(LanguageBundle.getString("in_uichooser_value")));
        availPanel.add(availInput);
        availPanel.add(Box.createVerticalGlue());
        leftPane.add(availPanel, BorderLayout.WEST);
    }

    JPanel buttonPane1 = new JPanel(new FlowLayout());
    JButton addButton = new JButton(chooser.getAddButtonName());
    addButton.setActionCommand("ADD");
    addButton.addActionListener(this);
    buttonPane1.add(addButton);
    buttonPane1.add(new JLabel(Icons.Forward16.getImageIcon()));
    leftPane.add(buttonPane1, BorderLayout.SOUTH);

    split.setLeftComponent(leftPane);

    JPanel rightPane = new JPanel(new BorderLayout());
    JPanel labelPane = new JPanel(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridwidth = GridBagConstraints.REMAINDER;
    labelPane.add(new JLabel(chooser.getSelectionCountName()), new GridBagConstraints());
    remainingLabel.setText(chooser.getRemainingSelections().get().toString());
    labelPane.add(remainingLabel, gbc);
    labelPane.add(new JLabel(chooser.getSelectedTableTitle()), gbc);
    rightPane.add(labelPane, BorderLayout.NORTH);

    list.setModel(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.addActionListener(this);
    rightPane.add(new JScrollPane(list), BorderLayout.CENTER);

    JPanel buttonPane2 = new JPanel(new FlowLayout());
    buttonPane2.add(new JLabel(Icons.Back16.getImageIcon()));
    JButton removeButton = new JButton(chooser.getRemoveButtonName());
    removeButton.setActionCommand("REMOVE");
    removeButton.addActionListener(this);
    buttonPane2.add(removeButton);
    rightPane.add(buttonPane2, BorderLayout.SOUTH);

    split.setRightComponent(rightPane);

    if (chooser.isInfoAvailable()) {
        JSplitPane infoSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
        infoSplit.setTopComponent(split);
        infoSplit.setBottomComponent(infoPane);
        infoSplit.setResizeWeight(0.8);
        pane.add(infoSplit, BorderLayout.CENTER);
        if (availTable != null) {
            availTable.getSelectionModel().addListSelectionListener(this);
        }
    } else {
        pane.add(split, BorderLayout.CENTER);
    }
    JPanel bottomPane = new JPanel(new FlowLayout());
    JButton button = new JButton(LanguageBundle.getString("in_ok")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_ok")); //$NON-NLS-1$
    button.setActionCommand("OK");
    button.addActionListener(this);
    bottomPane.add(button);
    button = new JButton(LanguageBundle.getString("in_cancel")); //$NON-NLS-1$
    button.setMnemonic(LanguageBundle.getMnemonic("in_mn_cancel")); //$NON-NLS-1$
    button.setActionCommand("CANCEL");
    button.addActionListener(this);
    bottomPane.add(button);
    pane.add(bottomPane, BorderLayout.SOUTH);
}

From source file:ro.nextreports.designer.querybuilder.QueryBuilderPanel.java

private void initUI() {
    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
    split.setDividerLocation(250);/*w  w w.  j a v  a2s.c o m*/
    split.setOneTouchExpandable(true);

    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar.setBorderPainted(false);

    // add refresh action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("refresh");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.refresh");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            try {
                if (Globals.getConnection() == null) {
                    return;
                }

                // refresh tables, views, procedures
                TreeUtil.refreshDatabase();

                // add new queries to tree
                TreeUtil.refreshQueries();

                // add new reports to tree
                TreeUtil.refreshReports();

                // add new charts to tree
                TreeUtil.refreshCharts();

            } catch (Exception ex) {
                Show.error(ex);
            }
        }

    });

    // add expand action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("expandall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.expand.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.expandAll(dbBrowserTree);
        }

    });

    // add collapse action
    toolBar.add(new AbstractAction() {

        public Object getValue(String key) {
            if (AbstractAction.SMALL_ICON.equals(key)) {
                return ImageUtil.getImageIcon("collapseall");
            } else if (AbstractAction.SHORT_DESCRIPTION.equals(key)) {
                return I18NSupport.getString("querybuilder.collapse.all");
            }

            return super.getValue(key);
        }

        public void actionPerformed(ActionEvent e) {
            TreeUtil.collapseAll(dbBrowserTree);
        }

    });

    // add properties button
    /*
      JButton propButton = new MagicButton(new AbstractAction() {
            
      public Object getValue(String key) {
          if (AbstractAction.SMALL_ICON.equals(key)) {
              return ImageUtil.getImageIcon("properties");
          }
            
          return super.getValue(key);
      }
            
      public void actionPerformed(ActionEvent e) {
          DBBrowserPropertiesPanel joinPanel = new DBBrowserPropertiesPanel();
          JDialog dlg = new DBBrowserPropertiesDialog(joinPanel);
          dlg.pack();
          dlg.setResizable(false);
          Show.centrateComponent(Globals.getMainFrame(), dlg);
          dlg.setVisible(true);
      }
            
      });
      propButton.setToolTipText(I18NSupport.getString("querybuilder.properties"));
      */
    //browserButtonsPanel.add(propButton);

    //        ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(browserButtonsPanel);

    browserPanel = new JXPanel(new BorderLayout());
    browserPanel.add(toolBar, BorderLayout.NORTH);

    // browser tree
    JScrollPane scroll = new JScrollPane(dbBrowserTree);
    browserPanel.add(scroll, BorderLayout.CENTER);
    split.setLeftComponent(browserPanel);

    tabbedPane = new JTabbedPane(JTabbedPane.BOTTOM);
    //        tabbedPane.putClientProperty(Options.EMBEDDED_TABS_KEY, Boolean.TRUE); // look like eclipse

    JSplitPane split2 = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split2.setResizeWeight(0.66);
    split2.setOneTouchExpandable(true);

    // desktop pane
    desktop.setDragMode(JDesktopPane.OUTLINE_DRAG_MODE);
    desktop.setDropTarget(
            new DropTarget(desktop, DnDConstants.ACTION_MOVE, new DesktopPaneDropTargetListener(), true));

    // create the toolbar
    JToolBar toolBar2 = new JToolBar();
    toolBar2.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar2.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar2.setBorderPainted(false);

    Action distinctAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            if (distinctButton.isSelected()) {
                selectQuery.setDistinct(true);
            } else {
                selectQuery.setDistinct(false);
            }
        }

    };
    distinctAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.distinct"));
    distinctAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.distinct"));
    toolBar2.add(distinctButton = new JToggleButton(distinctAction));

    Action groupByAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            groupBy = groupByButton.isSelected();
            Globals.getEventBus().publish(new GroupByEvent(QueryBuilderPanel.this.desktop, groupBy));
        }

    };
    groupByAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("query.group_by"));
    groupByAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.group.by"));
    toolBar2.add(groupByButton = new JToggleButton(groupByAction));

    Action clearAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            clear(false);
        }

    };
    clearAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("clear"));
    clearAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("querybuilder.clear"));
    toolBar2.add(clearAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar2);

    // add run button
    Action runQueryAction = new AbstractAction() {

        public void actionPerformed(ActionEvent e) {
            selectSQLViewTab();
            sqlView.doRun();
        }

    };
    runQueryAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run"));
    KeyStroke ks = KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4"));
    runQueryAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " ("
            + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")");
    runQueryAction.putValue(Action.ACCELERATOR_KEY, ks);
    toolBar2.add(runQueryAction);
    // register run query shortcut
    GlobalHotkeyManager hotkeyManager = GlobalHotkeyManager.getInstance();
    InputMap inputMap = hotkeyManager.getInputMap();
    ActionMap actionMap = hotkeyManager.getActionMap();
    inputMap.put((KeyStroke) runQueryAction.getValue(Action.ACCELERATOR_KEY), "runQueryAction");
    actionMap.put("runQueryAction", runQueryAction);

    JScrollPane scroll2 = new JScrollPane(desktop, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    scroll2.setPreferredSize(DBTablesDesktopPane.PREFFERED_SIZE);
    DecoratedScrollPane.decorate(scroll2);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.add(toolBar2, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    topPanel.add(scroll2, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    split2.setTopComponent(topPanel);
    designPanel = new DesignerTablePanel(selectQuery);
    split2.setBottomComponent(designPanel);
    split2.setDividerLocation(400);

    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.designer"), ImageUtil.getImageIcon("designer"),
            split2);
    tabbedPane.setMnemonicAt(0, 'D');

    sqlView = new SQLViewPanel();
    sqlView.getEditorPane().setDropTarget(new DropTarget(sqlView.getEditorPane(), DnDConstants.ACTION_MOVE,
            new SQLViewDropTargetListener(), true));
    tabbedPane.addTab(I18NSupport.getString("querybuilder.query.editor"), ImageUtil.getImageIcon("sql"),
            sqlView);
    tabbedPane.setMnemonicAt(1, 'E');

    split.setRightComponent(tabbedPane);

    // register a change listener
    tabbedPane.addChangeListener(new ChangeListener() {

        // this method is called whenever the selected tab changes
        public void stateChanged(ChangeEvent ev) {
            if (ev.getSource() == QueryBuilderPanel.this.tabbedPane) {
                // get current tab
                int sel = QueryBuilderPanel.this.tabbedPane.getSelectedIndex();
                if (sel == 1) { // sql view
                    String query;
                    if (!synchronizedPanels) {
                        query = sqlView.getQueryString();
                        synchronizedPanels = true;
                    } else {
                        if (Globals.getConnection() != null) {
                            query = getSelectQuery().toString();
                        } else {
                            query = "";
                        }
                        //                     if (query.equals("")) {
                        //                        query = sqlView.getQueryString();
                        //                     }
                    }
                    if (resetTable) {
                        sqlView.clear();
                        resetTable = false;
                    }
                    //System.out.println("query="+query);
                    sqlView.setQueryString(query);
                } else if (sel == 0) { // design view
                    if (queryWasModified(false)) {
                        Object[] options = { I18NSupport.getString("optionpanel.yes"),
                                I18NSupport.getString("optionpanel.no") };
                        String m1 = I18NSupport.getString("querybuilder.lost");
                        String m2 = I18NSupport.getString("querybuilder.continue");
                        int option = JOptionPane.showOptionDialog(Globals.getMainFrame(),
                                "<HTML>" + m1 + "<BR>" + m2 + "</HTML>",
                                I18NSupport.getString("querybuilder.confirm"), JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE, null, options, options[1]);

                        if (option != JOptionPane.YES_OPTION) {
                            synchronizedPanels = false;
                            tabbedPane.setSelectedIndex(1);
                        } else {
                            resetTable = true;
                        }
                    }
                } else if (sel == 2) { // report view

                }
            }
        }

    });

    //        this.add(split, BorderLayout.CENTER);

    parametersPanel = new ParametersPanel();
}

From source file:ro.nextreports.designer.querybuilder.SQLViewPanel.java

private void initUI() {
    sqlEditor = new Editor() {
        public void afterCaretMove() {
            removeHighlightErrorLine();/*from www.j av a 2  s  .com*/
        }
    };
    this.queryArea = sqlEditor.getEditorPanel().getEditorPane();
    queryArea.setText(DEFAULT_QUERY);

    errorPainter = new javax.swing.text.Highlighter.HighlightPainter() {
        @Override
        public void paint(Graphics g, int p0, int p1, Shape bounds, JTextComponent c) {
            try {
                Rectangle r = c.modelToView(c.getCaretPosition());
                g.setColor(Color.RED.brighter().brighter());
                g.fillRect(0, r.y, c.getWidth(), r.height);
            } catch (BadLocationException e) {
                // ignore
            }
        }
    };

    ActionMap actionMap = sqlEditor.getEditorPanel().getEditorPane().getActionMap();

    // create the toolbar
    JToolBar toolBar = new JToolBar();
    toolBar.putClientProperty("JToolBar.isRollover", Boolean.TRUE); // hide buttons borders
    toolBar.putClientProperty(Options.HEADER_STYLE_KEY, HeaderStyle.BOTH);
    toolBar.setBorderPainted(false);

    // add cut action
    Action cutAction = actionMap.get(BaseEditorKit.cutAction);
    cutAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("cut"));
    cutAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.cut"));
    toolBar.add(cutAction);

    // add copy action
    Action copyAction = actionMap.get(BaseEditorKit.copyAction);
    copyAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("copy"));
    copyAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.copy"));
    toolBar.add(copyAction);

    // add paste action
    Action pasteAction = actionMap.get(BaseEditorKit.pasteAction);
    pasteAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("paste"));
    pasteAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("sqlviewpanel.paste"));
    toolBar.add(pasteAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add undo action
    Action undoAction = actionMap.get(BaseEditorKit.undoAction);
    undoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("undo"));
    undoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("undo"));
    toolBar.add(undoAction);

    // add redo action
    Action redoAction = actionMap.get(BaseEditorKit.redoAction);
    redoAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("redo"));
    redoAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("redo"));
    toolBar.add(redoAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add find action
    Action findReplaceAction = actionMap.get(BaseEditorKit.findReplaceAction);
    findReplaceAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("find"));
    findReplaceAction.putValue(Action.SHORT_DESCRIPTION,
            I18NSupport.getString("sqleditor.findReplaceActionName"));
    toolBar.add(findReplaceAction);

    // add separator
    SwingUtil.addCustomSeparator(toolBar);

    // add run action
    runAction = new SQLRunAction();
    runAction.putValue(Action.SMALL_ICON, ImageUtil.getImageIcon("run"));
    runAction.putValue(Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(ShortcutsUtil.getShortcut("query.run.accelerator", "control 4")));
    runAction.putValue(Action.SHORT_DESCRIPTION, I18NSupport.getString("run.query") + " ("
            + ShortcutsUtil.getShortcut("query.run.accelerator.display", "Ctrl 4") + ")");
    // runAction is globally registered in QueryBuilderPanel !
    toolBar.add(runAction);

    //        ro.nextreports.designer.util.SwingUtil.registerButtonsForFocus(buttonsPanel);

    // create the table
    resultTable = new JXTable();
    resultTable.setDefaultRenderer(Integer.class, new ToStringRenderer()); // to remove thousand separators
    resultTable.setDefaultRenderer(Long.class, new ToStringRenderer());
    resultTable.setDefaultRenderer(Date.class, new DateRenderer());
    resultTable.setDefaultRenderer(Double.class, new DoubleRenderer());
    resultTable.addMouseListener(new CopyTableMouseAdapter(resultTable));
    TableUtil.setRowHeader(resultTable);
    resultTable.setColumnControlVisible(true);
    //        resultTable.getTableHeader().setReorderingAllowed(false);
    resultTable.setHorizontalScrollEnabled(true);

    // highlight table
    Highlighter alternateHighlighter = HighlighterFactory.createAlternateStriping(Color.WHITE,
            ColorUtil.PANEL_BACKROUND_COLOR);
    Highlighter nullHighlighter = new TextHighlighter(ResultSetTableModel.NULL_VALUE, Color.YELLOW.brighter());
    Highlighter blobHighlighter = new TextHighlighter(ResultSetTableModel.BLOB_VALUE, Color.GRAY.brighter());
    Highlighter clobHighlighter = new TextHighlighter(ResultSetTableModel.CLOB_VALUE, Color.GRAY.brighter());
    resultTable.setHighlighters(alternateHighlighter, nullHighlighter, blobHighlighter, clobHighlighter);
    resultTable.setBackground(ColorUtil.PANEL_BACKROUND_COLOR);
    resultTable.setGridColor(Color.LIGHT_GRAY);

    resultTable.setRolloverEnabled(true);
    resultTable.addHighlighter(new ColorHighlighter(HighlightPredicate.ROLLOVER_ROW, null, Color.RED));

    JSplitPane split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
    split.setResizeWeight(0.66);
    split.setOneTouchExpandable(true);

    JPanel topPanel = new JPanel();
    topPanel.setLayout(new GridBagLayout());
    topPanel.add(toolBar, new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(0, 0, 0, 0), 0, 0));
    topPanel.add(sqlEditor, new GridBagConstraints(0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));

    JPanel bottomPanel = new JPanel();
    bottomPanel.setLayout(new GridBagLayout());
    JScrollPane scrPanel = new JScrollPane(resultTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
            JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
    statusPanel = new SQLStatusPanel();
    bottomPanel.add(scrPanel, new GridBagConstraints(0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.WEST,
            GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
    bottomPanel.add(statusPanel, new GridBagConstraints(0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0));

    split.setTopComponent(topPanel);
    split.setBottomComponent(bottomPanel);
    split.setDividerLocation(400);

    setLayout(new BorderLayout());
    this.add(split, BorderLayout.CENTER);
}

From source file:simplesqlformatter.formatter.SQLFormatterEditor.java

/**
 * Creates a new instance of a Simple SQL Formatter editor main
 * window.//from w  w w  . j  av  a 2  s. co  m
 * 
 * @param debug
 *        Whether to show the debug window
 */
public SQLFormatterEditor(final boolean debug) {

    setTitle("Simple SQL Formatter");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    setIconImage(new ImageIcon(SQLFormatterEditor.class.getResource("/sf.png")) //$NON-NLS-1$
            .getImage());

    panel = getContentPane();
    panel.setLayout(new BorderLayout());

    // Create menus and toolbars
    final JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);
    final JToolBar toolBar = new JToolBar();
    toolBar.setRollover(true);
    add(toolBar, BorderLayout.NORTH);

    createFileMenu(menuBar, toolBar);
    createEditMenu(menuBar, toolBar);
    createHelpMenu(menuBar, toolBar);

    final Font font = new Font("Monospaced", Font.PLAIN, 12);

    // create text area
    textArea.setFont(font);

    // create debug area
    debugArea.setFont(font);
    debugArea.setEditable(false);
    final JLabel debugTitle = new JLabel("Simple SQL Formatter Debug");
    debugTitle.setBorder(BorderFactory.createEtchedBorder());
    final JPanel debugPanel = new JPanel(new BorderLayout());
    debugPanel.add(debugTitle, BorderLayout.NORTH);
    debugPanel.add(new JScrollPane(debugArea), BorderLayout.CENTER);

    if (debug) {
        // create split pane
        final JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, new JScrollPane(textArea),
                debugPanel);
        splitPane.setOneTouchExpandable(true);
        splitPane.setResizeWeight(SPLITPANEWEIGHT);

        panel.add(splitPane, BorderLayout.CENTER);
    } else {
        panel.add(new JScrollPane(textArea), BorderLayout.CENTER);
    }

    statusBar.setBorder(BorderFactory.createEtchedBorder());
    panel.add(statusBar, BorderLayout.SOUTH);

    pack();

}

From source file:tpp.TPPFrame.java

/** Set the model that this window is used to visualise */
void setData(Instances in) {
    try {//from   w  w w.  j  ava  2 s .  c  o m
        model = new ScatterPlotModel(2);
        model.setInstances(in);
        viewPanel = new ScatterPlotViewPanel();
        controlPanel = new ScatterPlotControlPanel();
        controlPanel.setModel(model);
        viewPanel.setModel(model);
        ScatterPlotViewPanelMouseListener l = new ScatterPlotViewPanelMouseListener(viewPanel, model);
        viewPanel.addMouseListener(l);
        viewPanel.addMouseMotionListener(l);
        setTitle(model.getInstances().relationName());
        enableViewMenuItems();
        JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, viewPanel, controlPanel);
        split.setResizeWeight(0.8);
        setContentPane(split);
        setVisible(true);
        split.setDividerLocation(split.getSize().width - 250);
        Dimension minimumSize = new Dimension(0, 0);
        viewPanel.setMinimumSize(minimumSize);
        controlPanel.setMinimumSize(minimumSize);
        viewPanel.repaint();
    } catch (Exception e) {
        e.printStackTrace();
        JOptionPane.showMessageDialog(this, "There was a problem reading that data: " + e.getMessage());
    }
}