Example usage for javax.swing Box createHorizontalGlue

List of usage examples for javax.swing Box createHorizontalGlue

Introduction

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

Prototype

public static Component createHorizontalGlue() 

Source Link

Document

Creates a horizontal glue component.

Usage

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

protected void createUI(PhotoCollection collection) {
    window.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    tabPane = new JTabbedPane();
    queryPane = new QueryPane();
    PhotoFolderTreeController treeCtrl = new PhotoFolderTreeController(window, this);
    viewCtrl = new PhotoViewController(window, this);
    treePane = treeCtrl.folderTree;//from  ww  w .  j ava  2  s  .  c o  m
    viewPane = viewCtrl.getThumbPane();
    previewPane = viewCtrl.getPreviewPane();
    tabPane.addTab("Query", queryPane);
    tabPane.addTab("Folders", treePane);

    VolumeTreeController volTreeCtrl = new VolumeTreeController(this);
    JTree volumeTree = volTreeCtrl.getView();
    JScrollPane voltreeScrollPane = new JScrollPane(volumeTree);
    voltreeScrollPane.setPreferredSize(new Dimension(200, 500));
    tabPane.add("Volumes", voltreeScrollPane);

    // TODO: get rid of this!!!!
    EditSelectionColorsAction colorAction = (EditSelectionColorsAction) viewPane.getEditSelectionColorsAction();
    colorAction.setPreviewCtrl(previewPane);

    // Set listeners to both query and folder tree panes

    /*
    If an actionEvent comes from query pane, swich to query results.
     */
    queryPane.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setCollection(queryPane.getResultCollection());
        }
    });

    /*
    If the selected folder is changed in treePane, switch to that immediately
     */

    treeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() {

        public void handleEvent(DefaultEvent<PhotoCollection> event) {
            PhotoCollection c = event.getPayload();
            if (c != null) {
                viewCtrl.setCollection(c);
                if (c instanceof PhotoFolder) {
                    PhotoFolder f = (PhotoFolder) c;

                    if (f.getExternalDir() != null) {
                        ExternalDir ed = f.getExternalDir();
                        folderIndexer.updateDir(ed.getVolume(), ed.getPath());
                        viewCtrl.setIndexingOngoing(true);
                    }
                }
            }
        }
    });

    volTreeCtrl.registerEventListener(PhotoFolderTreeEvent.class, new DefaultEventListener<PhotoCollection>() {

        public void handleEvent(DefaultEvent<PhotoCollection> event) {
            PhotoCollection c = event.getPayload();
            if (c != null) {
                viewCtrl.setCollection(c);
                if (c instanceof ExtDirPhotos) {
                    ExtDirPhotos photos = (ExtDirPhotos) c;
                    ExternalVolume vol = (ExternalVolume) viewCtrl.getDAOFactory().getVolumeDAO()
                            .getVolume(photos.getVolId());
                    folderIndexer.updateDir(vol, photos.getDirPath());
                    viewCtrl.setIndexingOngoing(true);
                }
            }
        }
    });

    collectionPane = viewCtrl.getCollectionPane();

    JSplitPane split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, tabPane, collectionPane);
    split.putClientProperty(JSplitPane.ONE_TOUCH_EXPANDABLE_PROPERTY, new Boolean(true));
    Container cp = window.getContentPane();
    cp.setLayout(new BorderLayout());
    cp.add(split, BorderLayout.CENTER);

    statusBar = new StatusBar();
    cp.add(statusBar, BorderLayout.SOUTH);

    // Create actions for BrowserWindow UI

    ImageIcon indexDirIcon = getIcon("index_dir.png");
    DefaultAction indexDirAction = new DefaultAction("Index directory...", indexDirIcon) {

        public void actionPerformed(ActionEvent e) {
            indexDir();
        }
    };
    indexDirAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_D);
    indexDirAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Index all images in a directory");
    this.registerAction("new_ext_vol", indexDirAction);

    ImageIcon importIcon = getIcon("import.png");
    importAction = new AbstractAction("Import image...", importIcon) {

        public void actionPerformed(ActionEvent e) {
            importFile();
        }
    };
    importAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O);
    importAction.putValue(AbstractAction.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_O, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

    importAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Import new image into database");

    ImageIcon updateIcon = getIcon("update_indexed_dirs.png");
    UpdateIndexAction updateIndexAction = new UpdateIndexAction(viewCtrl, "Update indexed dirs", updateIcon,
            "Check for changes in previously indexed directories", KeyEvent.VK_U);
    this.registerAction("update_indexed_dirs", updateIndexAction);
    updateIndexAction.addStatusChangeListener(statusBar);

    ImageIcon previewTopIcon = getIcon("view_preview_top.png");
    DefaultAction previewTopAction = new DefaultAction("Preview on top", previewTopIcon) {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_HORIZONTAL_THUMBS);
        }
    };
    previewTopAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on top of thumbnails");
    previewTopAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_T);
    this.registerAction("view_preview_top", previewTopAction);

    ImageIcon previewRightIcon = getIcon("view_preview_right.png");
    DefaultAction previewRightAction = new DefaultAction("Preview on right", previewRightIcon) {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setLayout(PhotoViewController.Layout.PREVIEW_VERTICAL_THUMBS);
        }
    };
    previewRightAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show preview on right of thumbnails");
    previewRightAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_R);
    this.registerAction("view_preview_right", previewRightAction);

    ImageIcon previewNoneIcon = getIcon("view_no_preview.png");
    DefaultAction previewNoneAction = new DefaultAction("No preview", previewNoneIcon) {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setLayout(PhotoViewController.Layout.ONLY_THUMBS);
        }
    };
    previewNoneAction.putValue(AbstractAction.SHORT_DESCRIPTION, "Show no preview image");
    previewNoneAction.putValue(AbstractAction.MNEMONIC_KEY, KeyEvent.VK_O);
    this.registerAction("view_no_preview", previewNoneAction);

    DefaultAction previewLargeAction = new DefaultAction("Large", null) {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setPreviewSize(200);
        }
    };
    DefaultAction previewSmallAction = new DefaultAction("Small", null) {

        public void actionPerformed(ActionEvent e) {
            viewCtrl.setPreviewSize(100);
        }
    };

    JToolBar tb = createToolbar();
    cp.add(tb, BorderLayout.NORTH);

    // Create the menu bar & menus
    JMenuBar menuBar = new JMenuBar();
    window.setJMenuBar(menuBar);
    // File menu
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    menuBar.add(fileMenu);

    JMenuItem newWindowItem = new JMenuItem("New window", KeyEvent.VK_N);
    newWindowItem.setIcon(getIcon("window_new.png"));
    newWindowItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            BrowserWindow br = new BrowserWindow(getParentController(), null);
            //          br.setVisible( true );
        }
    });
    fileMenu.add(newWindowItem);

    JMenuItem importItem = new JMenuItem(importAction);
    fileMenu.add(importItem);

    JMenuItem indexDirItem = new JMenuItem(indexDirAction);
    fileMenu.add(indexDirItem);

    fileMenu.add(new JMenuItem(viewCtrl.getActionAdapter("update_indexed_dirs")));

    ExportSelectedAction exportAction = (ExportSelectedAction) viewPane.getExportSelectedAction();
    JMenuItem exportItem = new JMenuItem(exportAction);
    exportAction.addStatusChangeListener(statusBar);
    fileMenu.add(exportItem);

    JMenu dbMenu = new JMenu("Database");
    dbMenu.setMnemonic(KeyEvent.VK_B);
    dbMenu.setIcon(getIcon("empty_icon.png"));

    ExportMetadataAction exportMetadata = new ExportMetadataAction("Export as XML...", null,
            "Export whole database as XML file", KeyEvent.VK_E);
    dbMenu.add(new JMenuItem(exportMetadata));

    ImportXMLAction importMetadata = new ImportXMLAction("Import XML data...", null,
            "Import data from other Photovault database as XML", KeyEvent.VK_I);
    importMetadata.addStatusChangeListener(statusBar);
    dbMenu.add(new JMenuItem(importMetadata));

    fileMenu.add(dbMenu);

    JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_X);
    exitItem.setIcon(getIcon("exit.png"));
    exitItem.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    fileMenu.add(exitItem);

    JMenu viewMenu = new JMenu("View");
    viewMenu.setMnemonic(KeyEvent.VK_V);
    menuBar.add(viewMenu);

    JMenuItem vertIconsItem = new JMenuItem(previewRightAction);
    viewMenu.add(vertIconsItem);

    JMenuItem horzIconsItem = new JMenuItem(previewTopAction);
    viewMenu.add(horzIconsItem);

    JMenuItem noPreviewItem = new JMenuItem(previewNoneAction);
    viewMenu.add(noPreviewItem);

    JMenuItem nextPhotoItem = new JMenuItem(viewPane.getSelectNextAction());
    viewMenu.add(nextPhotoItem);

    JMenuItem prevPhotoItem = new JMenuItem(viewPane.getSelectPreviousAction());
    viewMenu.add(prevPhotoItem);

    viewMenu.add(new JMenuItem(previewSmallAction));
    viewMenu.add(new JMenuItem(previewLargeAction));

    JMenu sortMenu = new JMenu("Sort by");
    sortMenu.setMnemonic(KeyEvent.VK_S);
    sortMenu.setIcon(getIcon("empty_icon.png"));
    JMenuItem byDateItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingDateComparator(), "Date",
            null, "Order photos by date", KeyEvent.VK_D));
    sortMenu.add(byDateItem);
    JMenuItem byPlaceItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new ShootingPlaceComparator(),
            "Place", null, "Order photos by shooting place", KeyEvent.VK_P));
    sortMenu.add(byPlaceItem);
    JMenuItem byQualityItem = new JMenuItem(new SetPhotoOrderAction(viewCtrl, new QualityComparator(),
            "Quality", null, "Order photos by quality", KeyEvent.VK_Q));
    sortMenu.add(byQualityItem);
    viewMenu.add(sortMenu);

    // Set default ordering by date
    byDateItem.getAction().actionPerformed(new ActionEvent(this, 0, "Setting default"));
    JMenu imageMenu = new JMenu("Image");
    imageMenu.setMnemonic(KeyEvent.VK_I);
    menuBar.add(imageMenu);

    imageMenu.add(new JMenuItem(viewPane.getEditSelectionPropsAction()));
    imageMenu.add(new JMenuItem(viewPane.getShowSelectedPhotoAction()));
    imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_cw")));
    imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_ccw")));
    imageMenu.add(new JMenuItem(viewCtrl.getActionAdapter("rotate_180")));
    imageMenu.add(new JMenuItem(previewPane.getCropAction()));
    imageMenu.add(new JMenuItem(viewPane.getEditSelectionColorsAction()));
    imageMenu.add(new JMenuItem(viewPane.getDeleteSelectedAction()));

    // Create the Quality submenu
    JMenu qualityMenu = new JMenu("Quality");
    qualityMenu.setIcon(getIcon("empty_icon.png"));

    for (int n = 0; n < 6; n++) {
        Action qualityAction = viewCtrl.getActionAdapter("quality_" + n);
        JMenuItem qualityMenuItem = new JMenuItem(qualityAction);
        qualityMenu.add(qualityMenuItem);
    }
    imageMenu.add(qualityMenu);

    JMenu aboutMenu = new JMenu("About");
    aboutMenu.setMnemonic(KeyEvent.VK_A);
    aboutMenu.add(new JMenuItem(new ShowAboutDlgAction("About Photovault...", null, "", null)));

    menuBar.add(Box.createHorizontalGlue());
    menuBar.add(aboutMenu);
    window.pack();
    window.setVisible(true);
}

From source file:org.genedb.jogra.plugins.TermRationaliser.java

/**
 * Return a new JFrame which is the main interface to the Rationaliser.
 *//*  w ww  . j  a va2s .  c o m*/
public JFrame getMainPanel() {

    /* JFRAME */
    frame.setTitle(WINDOW_TITLE);
    frame.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE);
    frame.setLayout(new BorderLayout());

    /* MENU */
    JMenuBar menuBar = new JMenuBar();

    JMenu actions_menu = new JMenu("Actions");
    JMenuItem actions_mitem_1 = new JMenuItem("Refresh lists");
    actions_mitem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            initModels();
        }
    });
    actions_menu.add(actions_mitem_1);

    JMenu about_menu = new JMenu("About");
    JMenuItem about_mitem_1 = new JMenuItem("About");
    about_mitem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            JOptionPane.showMessageDialog(null,
                    "Term Rationaliser \n" + "Wellcome Trust Sanger Institute, UK \n" + "2009",
                    "Term Rationaliser", JOptionPane.PLAIN_MESSAGE);
        }
    });
    about_menu.add(about_mitem_1);

    menuBar.add(about_menu);
    menuBar.add(actions_menu);
    frame.add(menuBar, BorderLayout.NORTH);

    /* MAIN BOX */
    Box center = Box.createHorizontalBox(); //A box that displays contents from left to right
    center.add(Box.createHorizontalStrut(5)); //Invisible fixed-width component

    /* FROM LIST AND PANEL */
    fromList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION); //Allow multiple products to be selected 
    fromList.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_RIGHT) {
                synchroniseLists(fromList, toList); //synchronise from left to right
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });

    Box fromPanel = this.createRationaliserPanel(FROM_LIST_NAME, fromList); //Box on left hand side
    fromPanel.add(Box.createVerticalStrut(55)); //Add some space
    center.add(fromPanel); //Add to main box
    center.add(Box.createHorizontalStrut(3)); //Add some space

    /* MIDDLE PANE */
    Box middlePane = Box.createVerticalBox();

    ClassLoader classLoader = this.getClass().getClassLoader(); //Needed to access the images later on
    ImageIcon leftButtonIcon = new ImageIcon(classLoader.getResource("left_arrow.gif"));
    ImageIcon rightButtonIcon = new ImageIcon(classLoader.getResource("right_arrow.gif"));

    leftButtonIcon = new ImageIcon(leftButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon!
    rightButtonIcon = new ImageIcon(rightButtonIcon.getImage().getScaledInstance(20, 20, Image.SCALE_SMOOTH)); //TODO: Investigate simpler way to resize an icon!

    JButton rightSynch = new JButton(rightButtonIcon);
    rightSynch.setToolTipText("Synchronise TO list. \n Shortcut: Right-arrow key");

    rightSynch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            synchroniseLists(fromList, toList);
        }
    });

    JButton leftSynch = new JButton(leftButtonIcon);
    leftSynch.setToolTipText("Synchronise FROM list. \n Shortcut: Left-arrow key");

    leftSynch.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            synchroniseLists(toList, fromList);
        }
    });

    middlePane.add(rightSynch);
    middlePane.add(leftSynch);

    center.add(middlePane); //Add middle pane to main box
    center.add(Box.createHorizontalStrut(3));

    /* TO LIST AND PANEL */
    toList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); //Single product selection in TO list
    toList.addKeyListener(new KeyListener() {
        @Override
        public void keyPressed(KeyEvent arg0) {
            if (arg0.getKeyCode() == KeyEvent.VK_LEFT) {
                synchroniseLists(toList, fromList); //synchronise from right to left
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyTyped(KeyEvent arg0) {
        }
    });

    Box toPanel = this.createRationaliserPanel(TO_LIST_NAME, toList);

    Box newTerm = Box.createVerticalBox();

    textField = new JTextArea(1, 1); //textfield to let the user edit the name of an existing term
    textField.setMaximumSize(new Dimension(Toolkit.getDefaultToolkit().getScreenSize().height, 10));

    textField.setForeground(Color.BLUE);
    JScrollPane jsp = new JScrollPane(textField); //scroll pane so that there is a horizontal scrollbar
    jsp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);

    newTerm.add(jsp);
    TitledBorder editBorder = BorderFactory.createTitledBorder("Edit term name");
    editBorder.setTitleColor(Color.DARK_GRAY);
    newTerm.setBorder(editBorder);
    toPanel.add(newTerm); //add textfield to panel

    center.add(toPanel); //add panel to main box
    center.add(Box.createHorizontalStrut(5));

    frame.add(center); //add the main panel to the frame

    initModels(); //load the lists with data

    /* BOTTOM HALF OF FRAME */
    Box main = Box.createVerticalBox();
    TitledBorder border = BorderFactory.createTitledBorder("Information");
    border.setTitleColor(Color.DARK_GRAY);

    /* INFORMATION BOX */
    Box info = Box.createVerticalBox();

    Box scope = Box.createHorizontalBox();
    scope.add(Box.createHorizontalStrut(5));
    scope.add(scopeLabel); //label showing the scope of the terms
    scope.add(Box.createHorizontalGlue());

    Box productCount = Box.createHorizontalBox();
    productCount.add(Box.createHorizontalStrut(5));
    productCount.add(productCountLabel); //display the label showing the number of terms
    productCount.add(Box.createHorizontalGlue());

    info.add(scope);
    info.add(productCount);
    info.setBorder(border);

    /* ACTION BUTTONS */
    Box actionButtons = Box.createHorizontalBox();
    actionButtons.add(Box.createHorizontalGlue());
    actionButtons.add(Box.createHorizontalStrut(10));

    JButton findFix = new JButton(new FindClosestMatchAction());
    actionButtons.add(findFix);
    actionButtons.add(Box.createHorizontalStrut(10));

    RationaliserAction ra = new RationaliserAction();
    // RationaliserAction2 ra2 = new RationaliserAction2();
    JButton go = new JButton(ra);
    actionButtons.add(go);
    actionButtons.add(Box.createHorizontalGlue());

    /* MORE INFORMATION TOGGLE */
    Box buttonBox = Box.createHorizontalBox();
    final JButton toggle = new JButton("Hide information <<");

    buttonBox.add(Box.createHorizontalStrut(5));
    buttonBox.add(toggle);
    buttonBox.add(Box.createHorizontalGlue());

    Box textBox = Box.createHorizontalBox();

    final JScrollPane scrollPane = new JScrollPane(information);
    scrollPane.setPreferredSize(new Dimension(frame.getWidth(), 100));
    scrollPane.setVisible(true);
    textBox.add(Box.createHorizontalStrut(5));
    textBox.add(scrollPane);

    ActionListener actionListener = new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            if (toggle.getText().equals("Show information >>")) {
                scrollPane.setVisible(true);
                toggle.setText("Hide information <<");
                frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() + 100));
                frame.pack();
            } else if (toggle.getText().equals("Hide information <<")) {
                scrollPane.setVisible(false);
                toggle.setText("Show information >>");
                frame.setPreferredSize(new Dimension(frame.getWidth(), frame.getHeight() - 100));
                frame.pack();
            }
        }
    };
    toggle.addActionListener(actionListener);

    main.add(Box.createVerticalStrut(5));
    main.add(info);
    main.add(Box.createVerticalStrut(5));
    main.add(Box.createVerticalStrut(5));
    main.add(actionButtons);
    main.add(Box.createVerticalStrut(10));
    main.add(buttonBox);
    main.add(textBox);

    frame.add(main, BorderLayout.SOUTH);
    frame.pack();
    frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    frame.setVisible(true);
    //initModels();

    return frame;
}

From source file:com._17od.upm.gui.MainWindow.java

private void addComponentsToPane() {

    // Ensure the layout manager is a BorderLayout
    if (!(getContentPane().getLayout() instanceof GridBagLayout)) {
        getContentPane().setLayout(new GridBagLayout());
    }/*w  ww  .  j  a  v a2 s  .co m*/

    // Create the menubar
    setJMenuBar(createMenuBar());

    GridBagConstraints c = new GridBagConstraints();

    // The toolbar Row
    c.gridx = 0;
    c.gridy = 0;
    c.anchor = GridBagConstraints.FIRST_LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    Component toolbar = createToolBar();
    getContentPane().add(toolbar, c);

    // Keep the frame background color consistent
    getContentPane().setBackground(toolbar.getBackground());

    // The seperator Row
    c.gridx = 0;
    c.gridy = 1;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(0, 0, 0, 0);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    getContentPane().add(new JSeparator(), c);

    // The search field row
    searchIcon = new JLabel(Util.loadImage("search.gif"));
    searchIcon.setDisabledIcon(Util.loadImage("search_d.gif"));
    searchIcon.setEnabled(false);
    c.gridx = 0;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(searchIcon, c);

    searchField = new JTextField(15);
    searchField.setEnabled(false);
    searchField.setMinimumSize(searchField.getPreferredSize());
    searchField.getDocument().addDocumentListener(new DocumentListener() {
        public void changedUpdate(DocumentEvent e) {
            // This method never seems to be called
        }

        public void insertUpdate(DocumentEvent e) {
            dbActions.filter();
        }

        public void removeUpdate(DocumentEvent e) {
            dbActions.filter();
        }
    });
    searchField.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                dbActions.resetSearch();
            } else if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                // If the user hits the enter key in the search field and
                // there's only one item
                // in the listview then open that item (this code assumes
                // that the one item in
                // the listview has already been selected. this is done
                // automatically in the
                // DatabaseActions.filter() method)
                if (accountsListview.getModel().getSize() == 1) {
                    viewAccountMenuItem.doClick();
                }
            }
        }
    });
    c.gridx = 1;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(searchField, c);

    resetSearchButton = new JButton(Util.loadImage("stop.gif"));
    resetSearchButton.setDisabledIcon(Util.loadImage("stop_d.gif"));
    resetSearchButton.setEnabled(false);
    resetSearchButton.setToolTipText(Translator.translate(RESET_SEARCH_TXT));
    resetSearchButton.setActionCommand(RESET_SEARCH_TXT);
    resetSearchButton.addActionListener(this);
    resetSearchButton.setBorder(BorderFactory.createEmptyBorder());
    resetSearchButton.setFocusable(false);
    c.gridx = 2;
    c.gridy = 2;
    c.anchor = GridBagConstraints.LINE_START;
    c.insets = new Insets(5, 1, 5, 1);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 1;
    c.fill = GridBagConstraints.NONE;
    getContentPane().add(resetSearchButton, c);

    // The accounts listview row
    accountsListview = new JList();
    accountsListview.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    accountsListview.setSelectedIndex(0);
    accountsListview.setVisibleRowCount(10);
    accountsListview.setModel(new SortedListModel());
    JScrollPane accountsScrollList = new JScrollPane(accountsListview, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    accountsListview.addFocusListener(new FocusAdapter() {
        public void focusGained(FocusEvent e) {
            // If the listview gets focus, there is one ore more items in
            // the listview and there is nothing
            // already selected, then select the first item in the list
            if (accountsListview.getModel().getSize() > 0 && accountsListview.getSelectedIndex() == -1) {
                accountsListview.setSelectionInterval(0, 0);
            }
        }
    });
    accountsListview.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            dbActions.setButtonState();
        }
    });
    accountsListview.addMouseListener(new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {
                viewAccountMenuItem.doClick();
            }
        }
    });
    accountsListview.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ENTER) {
                viewAccountMenuItem.doClick();
            }
        }
    });
    // Create a shortcut to delete account functionality with DEL(delete)
    // key

    accountsListview.addKeyListener(new KeyAdapter() {
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_DELETE) {

                try {
                    dbActions.reloadDatabaseBefore(new DeleteAccountAction());
                } catch (InvalidPasswordException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (ProblemReadingDatabaseFile e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                } catch (IOException e1) {
                    // TODO Auto-generated catch block
                    e1.printStackTrace();
                }

            }
        }
    });

    c.gridx = 0;
    c.gridy = 3;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 1, 1);
    c.weightx = 1;
    c.weighty = 1;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    getContentPane().add(accountsScrollList, c);

    // The "File Changed" panel
    c.gridx = 0;
    c.gridy = 4;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 0, 1);
    c.ipadx = 3;
    c.ipady = 3;
    c.weightx = 0;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.BOTH;
    databaseFileChangedPanel = new JPanel();
    databaseFileChangedPanel.setLayout(new BoxLayout(databaseFileChangedPanel, BoxLayout.X_AXIS));
    databaseFileChangedPanel.setBackground(new Color(249, 172, 60));
    databaseFileChangedPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    JLabel fileChangedLabel = new JLabel("Database file changed");
    fileChangedLabel.setAlignmentX(LEFT_ALIGNMENT);
    databaseFileChangedPanel.add(fileChangedLabel);
    databaseFileChangedPanel.add(Box.createHorizontalGlue());
    JButton reloadButton = new JButton("Reload");
    reloadButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                dbActions.reloadDatabaseFromDisk();
            } catch (Exception ex) {
                dbActions.errorHandler(ex);
            }
        }
    });
    databaseFileChangedPanel.add(reloadButton);
    databaseFileChangedPanel.setVisible(false);
    getContentPane().add(databaseFileChangedPanel, c);

    // Add the statusbar
    c.gridx = 0;
    c.gridy = 5;
    c.anchor = GridBagConstraints.CENTER;
    c.insets = new Insets(0, 1, 1, 1);
    c.weightx = 1;
    c.weighty = 0;
    c.gridwidth = 3;
    c.fill = GridBagConstraints.HORIZONTAL;
    getContentPane().add(statusBar, c);

}

From source file:com.diversityarrays.kdxplore.trials.AddScoringSetDialog.java

private Box createWantSampleButtons(SampleGroup curatedSampleGroup) {
    Box result = null;/*from  ww  w .jav  a 2  s  . c  o m*/
    ActionListener rbListener = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            wantSampleValues = noSampleValuesButton != e.getSource();
        }
    };

    result = Box.createHorizontalBox();
    String noSampleValues = Msg.OPTION_NO_SAMPLE_VALUES();
    ButtonGroup bg = new ButtonGroup();
    for (String rbname : new String[] { noSampleValues, Msg.OPTION_CURATED_SAMPLE_VALUES() }) {
        JRadioButton rb = new JRadioButton(rbname);
        result.add(rb);
        bg.add(rb);
        rb.addActionListener(rbListener);
        if (noSampleValues.equals(rbname)) {
            noSampleValuesButton = rb;
        } else {
            rb.doClick();
        }
    }
    result.add(Box.createHorizontalGlue());

    return result;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.modules.querycreationtreepanel.QueryComponentExpressionPanel.java

/**
 * Creates the additional constraints table panel.
 *///from   w  ww.  j  a va2s .  co  m
private synchronized void createAdditionalConstraintsTablePanel() {

    constraintsTableModel = new ConstraintTableModel(constraints);
    constraintsTable = new JXTable(constraintsTableModel);
    constraintsTable.setPreferredScrollableViewportSize(new Dimension(400, 80));
    constraintsTable.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            // get row at click point
            int row = constraintsTable.rowAtPoint(e.getPoint());
            if (row > -1) {
                // check if double click
                if (e.getClickCount() == 2) {
                    // get term at row
                    Constraint constraint = constraintsTableModel.getConstraintAtRow(row);
                    // set as active constraint
                    activeAdditionalConstraint = constraint;
                    // show in active constraint dialog
                    constraintPanel.setConstraint(activeAdditionalConstraint);
                    // set editing tag to true
                    editingExisting = true;
                    constraintCollapsiblePane.setCollapsed(false);
                }
            }
        }
    });

    // add panel for editing excluded terms
    JideButton addConstraintButton = new JideButton(new AbstractAction("", addConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            constraintCollapsiblePane.setCollapsed(false);
            // disable editing tag
            editingExisting = false;
        }
    });
    addConstraintButton.setName("addConstraintButton");
    addConstraintButton.setBorderPainted(false);

    JideButton deleteConstraintButton = new JideButton(new AbstractAction("", deleteConstraintIcon) {

        public void actionPerformed(ActionEvent e) {
            final int row = constraintsTable.getSelectedRow();
            if (row > -1) {
                // get constraint at row
                Constraint cons = constraintsTableModel.getConstraintAtRow(row);
                // remove from subquery
                componentExpression.removeAdditionalConstraint(cons);
                Runnable runnable = new Runnable() {
                    public void run() {
                        // delete constraint at row
                        constraintsTableModel.deleteRow(row);
                        constraintsTable.revalidate();
                        QueryComponentExpressionPanel.this.revalidate();
                    }
                };
                SwingUtilities.invokeLater(runnable);
                // notify listeners of query change
                queryService.queryChanged(queryService.getActiveQuery(), QueryComponentExpressionPanel.this);
            }
        }
    });
    deleteConstraintButton.setName("deleteConstraintButton");
    deleteConstraintButton.setBorderPainted(false);

    JPanel buttonsPanel = new JPanel();
    buttonsPanel.setLayout(new BoxLayout(buttonsPanel, BoxLayout.LINE_AXIS));
    buttonsPanel.add(new JLabel("Edit constraints"));
    buttonsPanel.add(Box.createHorizontalGlue());
    buttonsPanel.add(addConstraintButton);
    buttonsPanel.add(deleteConstraintButton);

    additionalConstraintsPanel = new JPanel(new BorderLayout());
    additionalConstraintsPanel.setBorder(BorderFactory.createTitledBorder("Additional Constraints"));
    additionalConstraintsPanel.add(buttonsPanel, BorderLayout.NORTH);
    additionalConstraintsPanel.add(new JScrollPane(constraintsTable), BorderLayout.CENTER);
    additionalConstraintsPanel.add(constraintCollapsiblePane, BorderLayout.SOUTH);

}

From source file:ChiSquareCalculator.java

ChiSquareCalculator() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);//from   w  w  w  .j  av  a 2s  .  com
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.setResizable(false);

    // panel 1
    JPanel pn1 = new JPanel();
    pn1.setOpaque(true);
    pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2"));

    JLabel jlab1 = new JLabel("class 1");
    JLabel jlab2 = new JLabel("class 2");
    JLabel jlab3 = new JLabel("case");
    JLabel jlab4 = new JLabel("control");

    jtf1 = new JTextField();
    jtf2 = new JTextField();
    jtf3 = new JTextField();
    jtf4 = new JTextField();

    // pn1 layout all
    GridBagLayout CalLayout1 = new GridBagLayout();
    GridBagConstraints gbc1 = new GridBagConstraints();
    pn1.setLayout(CalLayout1);
    gbc1.weightx = 1.0; //default 0.0
    gbc1.weighty = 1.0; //default 0.0      
    gbc1.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc1.fill = GridBagConstraints.BOTH;

    gbc1.gridwidth = 1;

    gbc1.gridx = 1;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jlab3, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jlab4, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf3, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf4, gbc1);

    pn1.add(jlab1);
    pn1.add(jlab2);
    pn1.add(jlab3);
    pn1.add(jlab4);
    pn1.add(jtf1);
    pn1.add(jtf2);
    pn1.add(jtf3);
    pn1.add(jtf4);

    // panel 2
    JPanel pn2 = new JPanel();
    pn2.setOpaque(true);
    pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3"));

    JLabel jlab5 = new JLabel("class 1");
    JLabel jlab6 = new JLabel("class 2");
    JLabel jlab7 = new JLabel("class 3");
    JLabel jlab8 = new JLabel("case");
    JLabel jlab9 = new JLabel("control");

    jtf5 = new JTextField();
    jtf6 = new JTextField();
    jtf7 = new JTextField();
    jtf8 = new JTextField();
    jtf9 = new JTextField();
    jtf10 = new JTextField();

    // pn2 layout all
    GridBagLayout CalLayout2 = new GridBagLayout();
    GridBagConstraints gbc2 = new GridBagConstraints();
    pn2.setLayout(CalLayout2);
    gbc2.weightx = 1.0; //default 0.0
    gbc2.weighty = 1.0; //default 0.0      
    gbc2.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc2.fill = GridBagConstraints.BOTH;

    gbc2.gridwidth = 1;

    gbc2.gridx = 1;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jlab8, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jlab9, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf8, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf9, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf10, gbc2);

    pn2.add(jlab5);
    pn2.add(jlab6);
    pn2.add(jlab7);
    pn2.add(jlab8);
    pn2.add(jlab9);
    pn2.add(jtf5);
    pn2.add(jtf6);
    pn2.add(jtf7);
    pn2.add(jtf8);
    pn2.add(jtf9);
    pn2.add(jtf10);

    // panel 3      
    JPanel pn3 = new JPanel();
    pn3.setOpaque(true);
    pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic"));

    JLabel jlab10 = new JLabel("chi-square");
    JLabel jlab11 = new JLabel("degree of freedom");

    jtf11 = new JTextField();
    jtf12 = new JTextField();

    GridBagLayout CalLayout3 = new GridBagLayout();
    GridBagConstraints gbc3 = new GridBagConstraints();
    pn3.setLayout(CalLayout3);
    gbc3.weightx = 1.0; //default 0.0
    gbc3.weighty = 1.0; //default 0.0      
    gbc3.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc3.fill = GridBagConstraints.BOTH;

    gbc3.gridwidth = 1;

    gbc3.gridx = 0;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jlab10, gbc3);

    gbc3.gridwidth = 3;

    gbc3.gridx = 1;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jtf11, gbc3);

    gbc3.gridwidth = 2;

    gbc3.gridx = 0;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jlab11, gbc3);

    gbc3.gridx = 2;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jtf12, gbc3);

    pn3.add(jlab10);
    pn3.add(jlab11);
    pn3.add(jtf11);
    pn3.add(jtf12);

    JPanel pn4 = new JPanel();
    pn4.setOpaque(true);
    pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result"));

    JLabel jlab12 = new JLabel("p-value");
    final JLabel jlab13 = new JLabel("odds ratio");
    final JLabel jlab14 = new JLabel("standard error");
    final JLabel jlab15 = new JLabel("confidence interval 95%");

    jtf13 = new JTextField();
    jtf14 = new JTextField();
    jtf15 = new JTextField();
    jtf16 = new JTextField();
    jtf17 = new JTextField();

    jlab13.setEnabled(false);
    jlab14.setEnabled(false);
    jlab15.setEnabled(false);
    jtf14.setEnabled(false);
    jtf15.setEnabled(false);
    jtf16.setEnabled(false);
    jtf17.setEnabled(false);

    JButton jbtn1 = new JButton("Run 2x2");
    jbtn1.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4;
            try {
                number1 = Long.parseLong(jtf1.getText());
                number2 = Long.parseLong(jtf2.getText());
                number3 = Long.parseLong(jtf3.getText());
                number4 = Long.parseLong(jtf4.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][2];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[1][0] = number3;
            obs[1][1] = number4;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(1));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");

            jlab13.setEnabled(true);
            jlab14.setEnabled(true);
            jlab15.setEnabled(true);
            jtf14.setEnabled(true);
            jtf15.setEnabled(true);
            jtf16.setEnabled(true);
            jtf17.setEnabled(true);

            double or = (double) (number2 * number3) / (number1 * number4);
            double se = Math.sqrt(
                    (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4);
            double logOR = Math.log(or);
            double logU95 = logOR + 1.96 * se;
            double logL95 = logOR - 1.96 * se;
            double U95 = Math.exp(logU95);
            double L95 = Math.exp(logL95);

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.000000");

            jtf14.setText(String.valueOf(or));
            jtf15.setText(String.valueOf(se));
            jtf16.setText(String.valueOf(mydf.format(L95)));
            jtf17.setText(String.valueOf(mydf.format(U95)));

        }
    });

    JButton jbtn2 = new JButton("Run 2x3");
    jbtn2.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4, number5, number6;
            try {
                number1 = Long.parseLong(jtf5.getText());
                number2 = Long.parseLong(jtf6.getText());
                number3 = Long.parseLong(jtf7.getText());
                number4 = Long.parseLong(jtf8.getText());
                number5 = Long.parseLong(jtf9.getText());
                number6 = Long.parseLong(jtf10.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][3];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[0][2] = number3;
            obs[1][0] = number4;
            obs[1][1] = number5;
            obs[1][2] = number6;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(stats));
            jtf12.setText(String.valueOf(2));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);

        }
    });

    JButton jbtn3 = new JButton("Run Statistic");
    jbtn3.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            double stat, df;
            try {
                stat = Double.parseDouble(jtf11.getText());
                df = Double.parseDouble(jtf12.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!");
                return;
            }
            ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
            double pvalue = 1 - distribution.cumulativeProbability(stat);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    JButton jbtn4 = new JButton("clear");
    jbtn4.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf11.setText("");
            jtf12.setText("");
            jtf13.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    GridBagLayout CalLayout4 = new GridBagLayout();
    GridBagConstraints gbc4 = new GridBagConstraints();
    pn4.setLayout(CalLayout4);
    gbc4.weightx = 1.0; //default 0.0
    gbc4.weighty = 1.0; //default 0.0      
    gbc4.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc4.fill = GridBagConstraints.BOTH;

    gbc4.gridwidth = 1;

    gbc4.gridx = 0;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn1, gbc4);

    gbc4.gridx = 1;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn2, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn3, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn4, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jlab12, gbc4);

    gbc4.gridwidth = 3;

    gbc4.gridx = 1;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jtf13, gbc4);

    gbc4.gridwidth = 2;

    gbc4.gridx = 0;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jlab13, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jtf14, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jlab14, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jtf15, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jlab15, gbc4);

    gbc4.gridwidth = 1;

    gbc4.gridx = 2;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf16, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf17, gbc4);

    pn4.add(jlab12);
    pn4.add(jlab13);
    pn4.add(jlab14);
    pn4.add(jlab15);
    pn4.add(jtf13);
    pn4.add(jtf14);
    pn4.add(jtf15);
    pn4.add(jtf16);
    pn4.add(jtf17);
    pn4.add(jbtn1);
    pn4.add(jbtn2);
    pn4.add(jbtn3);
    pn4.add(jbtn4);

    // jfrm layout all
    GridBagLayout CalLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    jfrm.setLayout(CalLayout);

    gbc.weightx = 1.0; //default 0.0
    gbc.weighty = 1.0; //default 0.0

    gbc.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 4;

    gbc.gridx = 0;
    gbc.gridy = 0;
    CalLayout.setConstraints(pn1, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    CalLayout.setConstraints(pn2, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    CalLayout.setConstraints(pn3, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    CalLayout.setConstraints(pn4, gbc);

    jfrm.add(pn1);
    jfrm.add(pn2);
    jfrm.add(pn3);
    jfrm.add(pn4);

    // Help Menu Bar
    JMenuBar jmb = new JMenuBar();
    JMenu jmh = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmiAbout.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(jfrm,
                    "Name:          Chi Square Calculator\n" + "Version:       1.0\n"
                            + "Author:         Felix Yanhui Fan\n" + "EMail:           nolanfyh@gmail.com\n"
                            + "Website:     http://felixfan.github.io/ChiSquareCalculator\n");

        }
    });
    JMenuItem jmiLisence = new JMenuItem("Lisence");
    jmiLisence.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfrm,
                    "This program is licensed under the terms of \n"
                            + "the GNU General Public License version 3 \n" + "Available online under: \n"
                            + "http://www.gnu.org/licenses/gpl-3.0.html\n");

        }
    });

    jmh.add(jmiAbout);
    jmh.add(jmiLisence);

    jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar
    jmb.add(jmh);

    jfrm.setJMenuBar(jmb);

    jfrm.setVisible(true);
}

From source file:org.ohdsi.whiteRabbit.WhiteRabbitMain.java

private JPanel createScanPanel() {
    JPanel panel = new JPanel();
    panel.setLayout(new BorderLayout());

    JPanel tablePanel = new JPanel();
    tablePanel.setLayout(new BorderLayout());
    tablePanel.setBorder(new TitledBorder("Tables to scan"));
    tableList = new JList<String>();
    tableList.setToolTipText("Specify the tables (or CSV files) to be scanned here");
    tablePanel.add(new JScrollPane(tableList), BorderLayout.CENTER);

    JPanel tableButtonPanel = new JPanel();
    tableButtonPanel.setLayout(new GridLayout(3, 1));
    addAllButton = new JButton("Add all in DB");
    addAllButton.setToolTipText("Add all tables in the database");
    addAllButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            addAllTables();/*from   w  w  w . j ava2  s  .  co  m*/
        }
    });
    addAllButton.setEnabled(false);
    tableButtonPanel.add(addAllButton);
    JButton addButton = new JButton("Add");
    addButton.setToolTipText("Add tables to list");
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            pickTables();
        }
    });
    tableButtonPanel.add(addButton);
    JButton removeButton = new JButton("Remove");
    removeButton.setToolTipText("Remove tables from list");
    removeButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeTables();
        }
    });
    tableButtonPanel.add(removeButton);
    tablePanel.add(tableButtonPanel, BorderLayout.EAST);

    panel.add(tablePanel, BorderLayout.CENTER);

    JPanel southPanel = new JPanel();
    southPanel.setLayout(new BoxLayout(southPanel, BoxLayout.Y_AXIS));

    JPanel scanOptionsPanel = new JPanel();
    scanOptionsPanel.setLayout(new BoxLayout(scanOptionsPanel, BoxLayout.X_AXIS));

    scanValueScan = new JCheckBox("Scan field values", true);
    scanValueScan.setToolTipText("Include a frequency count of field values in the scan report");
    scanValueScan.addChangeListener(new ChangeListener() {

        @Override
        public void stateChanged(ChangeEvent arg0) {
            scanMinCellCount.setEnabled(((JCheckBox) arg0.getSource()).isSelected());
            scanRowCount.setEnabled(((JCheckBox) arg0.getSource()).isSelected());
            scanValuesCount.setEnabled(((JCheckBox) arg0.getSource()).isSelected());
        }
    });
    scanOptionsPanel.add(scanValueScan);
    scanOptionsPanel.add(Box.createHorizontalGlue());

    scanOptionsPanel.add(new JLabel("Min cell count "));
    scanMinCellCount = new JSpinner();
    scanMinCellCount.setValue(5);
    scanMinCellCount.setToolTipText("Minimum frequency for a field value to be included in the report");
    scanOptionsPanel.add(scanMinCellCount);
    scanOptionsPanel.add(Box.createHorizontalGlue());

    scanOptionsPanel.add(new JLabel("Max distinct values "));
    scanValuesCount = new JComboBox<String>(new String[] { "100", "1,000", "10,000" });
    scanValuesCount.setSelectedIndex(1);
    scanValuesCount.setToolTipText("Maximum number of distinct values per field to be reported");
    scanOptionsPanel.add(scanValuesCount);
    scanOptionsPanel.add(Box.createHorizontalGlue());

    scanOptionsPanel.add(new JLabel("Rows per table "));
    scanRowCount = new JComboBox<String>(new String[] { "100,000", "500,000", "1 million", "all" });
    scanRowCount.setSelectedIndex(0);
    scanRowCount.setToolTipText("Maximum number of rows per table to be scanned for field values");
    scanOptionsPanel.add(scanRowCount);

    southPanel.add(scanOptionsPanel);

    southPanel.add(Box.createVerticalStrut(3));

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

    JButton scanButton = new JButton("Scan tables");
    scanButton.setBackground(new Color(151, 220, 141));
    scanButton.setToolTipText("Scan the selected tables");
    scanButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            scanRun();
        }
    });
    componentsToDisableWhenRunning.add(scanButton);
    scanButtonPanel.add(scanButton);
    southPanel.add(scanButtonPanel);

    panel.add(southPanel, BorderLayout.SOUTH);

    return panel;
}

From source file:chisquarecalculator.ChisqCal.java

public ChisqCal() {
    final JFrame jfrm = new JFrame("Chi Square Calculator");
    jfrm.setSize(400, 550);//from   w ww.  j a  v  a  2  s  .  c o  m
    jfrm.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    jfrm.setResizable(false);

    // panel 1
    JPanel pn1 = new JPanel();
    pn1.setOpaque(true);
    pn1.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 2"));

    JLabel jlab1 = new JLabel("class 1");
    JLabel jlab2 = new JLabel("class 2");
    JLabel jlab3 = new JLabel("case");
    JLabel jlab4 = new JLabel("control");

    jtf1 = new JTextField();
    jtf2 = new JTextField();
    jtf3 = new JTextField();
    jtf4 = new JTextField();

    // pn1 layout all
    GridBagLayout CalLayout1 = new GridBagLayout();
    GridBagConstraints gbc1 = new GridBagConstraints();
    pn1.setLayout(CalLayout1);
    gbc1.weightx = 1.0; //default 0.0
    gbc1.weighty = 1.0; //default 0.0      
    gbc1.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc1.fill = GridBagConstraints.BOTH;

    gbc1.gridwidth = 1;

    gbc1.gridx = 1;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 0;
    CalLayout1.setConstraints(jlab2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jlab3, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf1, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 1;
    CalLayout1.setConstraints(jtf2, gbc1);

    gbc1.gridx = 0;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jlab4, gbc1);

    gbc1.gridx = 1;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf3, gbc1);

    gbc1.gridx = 2;
    gbc1.gridy = 2;
    CalLayout1.setConstraints(jtf4, gbc1);

    pn1.add(jlab1);
    pn1.add(jlab2);
    pn1.add(jlab3);
    pn1.add(jlab4);
    pn1.add(jtf1);
    pn1.add(jtf2);
    pn1.add(jtf3);
    pn1.add(jtf4);

    // panel 2
    JPanel pn2 = new JPanel();
    pn2.setOpaque(true);
    pn2.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "2 x 3"));

    JLabel jlab5 = new JLabel("class 1");
    JLabel jlab6 = new JLabel("class 2");
    JLabel jlab7 = new JLabel("class 3");
    JLabel jlab8 = new JLabel("case");
    JLabel jlab9 = new JLabel("control");

    jtf5 = new JTextField();
    jtf6 = new JTextField();
    jtf7 = new JTextField();
    jtf8 = new JTextField();
    jtf9 = new JTextField();
    jtf10 = new JTextField();

    // pn2 layout all
    GridBagLayout CalLayout2 = new GridBagLayout();
    GridBagConstraints gbc2 = new GridBagConstraints();
    pn2.setLayout(CalLayout2);
    gbc2.weightx = 1.0; //default 0.0
    gbc2.weighty = 1.0; //default 0.0      
    gbc2.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc2.fill = GridBagConstraints.BOTH;

    gbc2.gridwidth = 1;

    gbc2.gridx = 1;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 0;
    CalLayout2.setConstraints(jlab7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jlab8, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf5, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf6, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 1;
    CalLayout2.setConstraints(jtf7, gbc2);

    gbc2.gridx = 0;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jlab9, gbc2);

    gbc2.gridx = 1;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf8, gbc2);

    gbc2.gridx = 2;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf9, gbc2);

    gbc2.gridx = 3;
    gbc2.gridy = 2;
    CalLayout2.setConstraints(jtf10, gbc2);

    pn2.add(jlab5);
    pn2.add(jlab6);
    pn2.add(jlab7);
    pn2.add(jlab8);
    pn2.add(jlab9);
    pn2.add(jtf5);
    pn2.add(jtf6);
    pn2.add(jtf7);
    pn2.add(jtf8);
    pn2.add(jtf9);
    pn2.add(jtf10);

    // panel 3      
    JPanel pn3 = new JPanel();
    pn3.setOpaque(true);
    pn3.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "statistic"));

    JLabel jlab10 = new JLabel("chi-square");
    JLabel jlab11 = new JLabel("degree of freedom");

    jtf11 = new JTextField();
    jtf12 = new JTextField();

    GridBagLayout CalLayout3 = new GridBagLayout();
    GridBagConstraints gbc3 = new GridBagConstraints();
    pn3.setLayout(CalLayout3);
    gbc3.weightx = 1.0; //default 0.0
    gbc3.weighty = 1.0; //default 0.0      
    gbc3.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc3.fill = GridBagConstraints.BOTH;

    gbc3.gridwidth = 1;

    gbc3.gridx = 0;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jlab10, gbc3);

    gbc3.gridwidth = 3;

    gbc3.gridx = 1;
    gbc3.gridy = 0;
    CalLayout3.setConstraints(jtf11, gbc3);

    gbc3.gridwidth = 2;

    gbc3.gridx = 0;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jlab11, gbc3);

    gbc3.gridx = 2;
    gbc3.gridy = 1;
    CalLayout3.setConstraints(jtf12, gbc3);

    pn3.add(jlab10);
    pn3.add(jlab11);
    pn3.add(jtf11);
    pn3.add(jtf12);

    JPanel pn4 = new JPanel();
    pn4.setOpaque(true);
    pn4.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), "result"));

    JLabel jlab12 = new JLabel("p-value");
    final JLabel jlab13 = new JLabel("odds ratio");
    final JLabel jlab14 = new JLabel("standard error");
    final JLabel jlab15 = new JLabel("confidence interval 95%");

    jtf13 = new JTextField();
    jtf14 = new JTextField();
    jtf15 = new JTextField();
    jtf16 = new JTextField();
    jtf17 = new JTextField();

    jlab13.setEnabled(false);
    jlab14.setEnabled(false);
    jlab15.setEnabled(false);
    jtf14.setEnabled(false);
    jtf15.setEnabled(false);
    jtf16.setEnabled(false);
    jtf17.setEnabled(false);

    JButton jbtn1 = new JButton("Run 2x2");
    jbtn1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4;
            try {
                number1 = Long.parseLong(jtf1.getText());
                number2 = Long.parseLong(jtf2.getText());
                number3 = Long.parseLong(jtf3.getText());
                number4 = Long.parseLong(jtf4.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][2];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[1][0] = number3;
            obs[1][1] = number4;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000");

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(mydf.format(stats)));
            jtf12.setText(String.valueOf(1));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");

            jlab13.setEnabled(true);
            jlab14.setEnabled(true);
            jlab15.setEnabled(true);
            jtf14.setEnabled(true);
            jtf15.setEnabled(true);
            jtf16.setEnabled(true);
            jtf17.setEnabled(true);

            double or = (double) (number2 * number3) / (number1 * number4);
            double se = Math.sqrt(
                    (double) 1 / number1 + (double) 1 / number2 + (double) 1 / number3 + (double) 1 / number4);
            double logOR = Math.log(or);
            double logU95 = logOR + 1.96 * se;
            double logL95 = logOR - 1.96 * se;
            double U95 = Math.exp(logU95);
            double L95 = Math.exp(logL95);

            jtf14.setText(String.valueOf(mydf.format(or)));
            jtf15.setText(String.valueOf(mydf.format(se)));
            jtf16.setText(String.valueOf(mydf.format(L95)));
            jtf17.setText(String.valueOf(mydf.format(U95)));

        }
    });

    JButton jbtn2 = new JButton("Run 2x3");
    jbtn2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            long number1, number2, number3, number4, number5, number6;
            try {
                number1 = Long.parseLong(jtf5.getText());
                number2 = Long.parseLong(jtf6.getText());
                number3 = Long.parseLong(jtf7.getText());
                number4 = Long.parseLong(jtf8.getText());
                number5 = Long.parseLong(jtf9.getText());
                number6 = Long.parseLong(jtf10.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only integer is acceptable!");
                return;
            }

            long[][] obs = new long[2][3];

            obs[0][0] = number1;
            obs[0][1] = number2;
            obs[0][2] = number3;
            obs[1][0] = number4;
            obs[1][1] = number5;
            obs[1][2] = number6;

            ChiSquareTest mychiSquare = new ChiSquareTest();

            final java.text.DecimalFormat mydf = new java.text.DecimalFormat("0.0000");

            double stats = mychiSquare.chiSquare(obs);
            jtf11.setText(String.valueOf(mydf.format(stats)));
            jtf12.setText(String.valueOf(2));

            double pvalue = mychiSquare.chiSquareTest(obs);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);

        }
    });

    JButton jbtn3 = new JButton("Run Statistic");
    jbtn3.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            double stat, df;
            try {
                stat = Double.parseDouble(jtf11.getText());
                df = Double.parseDouble(jtf12.getText());
            } catch (Exception ne) {
                JOptionPane.showMessageDialog(jfrm, "Error: Bad input, only number is acceptable!");
                return;
            }
            ChiSquaredDistribution distribution = new ChiSquaredDistribution(df);
            double pvalue = 1 - distribution.cumulativeProbability(stat);
            jtf13.setText(String.valueOf(pvalue));

            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    JButton jbtn4 = new JButton("clear");
    jbtn4.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jtf1.setText("");
            jtf2.setText("");
            jtf3.setText("");
            jtf4.setText("");
            jtf5.setText("");
            jtf6.setText("");
            jtf7.setText("");
            jtf8.setText("");
            jtf9.setText("");
            jtf10.setText("");
            jtf11.setText("");
            jtf12.setText("");
            jtf13.setText("");
            jtf14.setText("");
            jtf15.setText("");
            jtf16.setText("");
            jtf17.setText("");

            jlab13.setEnabled(false);
            jlab14.setEnabled(false);
            jlab15.setEnabled(false);
            jtf14.setEnabled(false);
            jtf15.setEnabled(false);
            jtf16.setEnabled(false);
            jtf17.setEnabled(false);
        }
    });

    GridBagLayout CalLayout4 = new GridBagLayout();
    GridBagConstraints gbc4 = new GridBagConstraints();
    pn4.setLayout(CalLayout4);
    gbc4.weightx = 1.0; //default 0.0
    gbc4.weighty = 1.0; //default 0.0      
    // gbc4.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc4.insets = new Insets(1, 1, 1, 1);
    gbc4.fill = GridBagConstraints.BOTH;

    gbc4.gridwidth = 1;

    gbc4.gridx = 0;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn1, gbc4);

    gbc4.gridx = 1;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn2, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn3, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 0;
    CalLayout4.setConstraints(jbtn4, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jlab12, gbc4);

    gbc4.gridwidth = 3;

    gbc4.gridx = 1;
    gbc4.gridy = 1;
    CalLayout4.setConstraints(jtf13, gbc4);

    gbc4.gridwidth = 2;

    gbc4.gridx = 0;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jlab13, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 2;
    CalLayout4.setConstraints(jtf14, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jlab14, gbc4);

    gbc4.gridx = 2;
    gbc4.gridy = 3;
    CalLayout4.setConstraints(jtf15, gbc4);

    gbc4.gridx = 0;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jlab15, gbc4);

    gbc4.gridwidth = 1;

    gbc4.gridx = 2;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf16, gbc4);

    gbc4.gridx = 3;
    gbc4.gridy = 4;
    CalLayout4.setConstraints(jtf17, gbc4);

    pn4.add(jlab12);
    pn4.add(jlab13);
    pn4.add(jlab14);
    pn4.add(jlab15);
    pn4.add(jtf13);
    pn4.add(jtf14);
    pn4.add(jtf15);
    pn4.add(jtf16);
    pn4.add(jtf17);
    pn4.add(jbtn1);
    pn4.add(jbtn2);
    pn4.add(jbtn3);
    pn4.add(jbtn4);

    // jfrm layout all
    GridBagLayout CalLayout = new GridBagLayout();
    GridBagConstraints gbc = new GridBagConstraints();
    jfrm.setLayout(CalLayout);

    gbc.weightx = 1.0; //default 0.0
    gbc.weighty = 1.0; //default 0.0

    gbc.insets = new Insets(4, 4, 4, 4); // Add some space
    gbc.fill = GridBagConstraints.BOTH;

    gbc.gridwidth = 4;

    gbc.gridx = 0;
    gbc.gridy = 0;
    CalLayout.setConstraints(pn1, gbc);

    gbc.gridx = 0;
    gbc.gridy = 1;
    CalLayout.setConstraints(pn2, gbc);

    gbc.gridx = 0;
    gbc.gridy = 2;
    CalLayout.setConstraints(pn3, gbc);

    gbc.gridx = 0;
    gbc.gridy = 3;
    CalLayout.setConstraints(pn4, gbc);

    jfrm.add(pn1);
    jfrm.add(pn2);
    jfrm.add(pn3);
    jfrm.add(pn4);

    // Help Menu Bar
    JMenuBar jmb = new JMenuBar();
    JMenu jmh = new JMenu("Help");
    JMenuItem jmiAbout = new JMenuItem("About");
    jmiAbout.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent arg0) {
            JOptionPane.showMessageDialog(jfrm,
                    "Name:          Chi Square Calculator\n" + "Version:       1.0\n"
                            + "Author:         Felix Yanhui Fan\n" + "EMail:          felixfanyh@gmail.com\n"
                            + "Website:     http://felixfan.github.io/ChiSquareCalculator\n");
        }
    });
    JMenuItem jmiLisence = new JMenuItem("Lisence");
    jmiLisence.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            JOptionPane.showMessageDialog(jfrm,
                    "This program is licensed under the terms of \n"
                            + "the GNU General Public License version 3 \n" + "Available online under: \n"
                            + "http://www.gnu.org/licenses/gpl-3.0.html\n");
        }
    });

    jmh.add(jmiAbout);
    jmh.add(jmiLisence);

    jmb.add(Box.createHorizontalGlue()); // Aligning JMenu on the right corner of JMenuBar
    jmb.add(jmh);

    jfrm.setJMenuBar(jmb);

    jfrm.setVisible(true);
}

From source file:org.isatools.isacreatorconfigurator.ontologyconfigurationtool.OntologyConfigUI.java

private void createOntologySelectionPanel() {

    OntologyListRenderer listRenderer = new OntologyListRenderer();

    JPanel westPanel = new JPanel(new BorderLayout());

    JPanel selectedOntologiesContainer = new JPanel(new BorderLayout());
    selectedOntologiesContainer.setOpaque(false);

    // create List containing selected ontologies
    selectedOntologyListModel = new DefaultListModel();
    selectedOntologyList = new JList(selectedOntologyListModel);
    selectedOntologyList.setCellRenderer(new SelectedOntologyListRenderer());
    selectedOntologyList.setBackground(UIHelper.BG_COLOR);

    selectedOntologyList.addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent listSelectionEvent) {
            setOntologySelectionPanelPlaceholder(infoImage);

            setSelectedOntologyButtonVisibility(selectedOntologyList.isSelectionEmpty());
        }/*w w  w.  j ava  2 s  . c  o  m*/
    });

    JScrollPane selectedOntologiesScroller = new JScrollPane(selectedOntologyList,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    selectedOntologiesScroller.setPreferredSize(new Dimension(200, 255));
    selectedOntologiesScroller.setBackground(UIHelper.BG_COLOR);
    selectedOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR);

    IAppWidgetFactory.makeIAppScrollPane(selectedOntologiesScroller);

    selectedOntologiesContainer.setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7),
            "selected ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
            UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR));

    selectedOntologiesContainer.add(selectedOntologiesScroller, BorderLayout.CENTER);

    // ADD BUTTONS
    removeOntologyButton = new JLabel(removeOntologyButtonIcon);
    removeOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {

            if (!selectedOntologyList.isSelectionEmpty()) {
                String ontologyToRemove = selectedOntologyList.getSelectedValue().toString();
                System.out.println("Removing  " + ontologyToRemove);
                selectedOntologies.remove(ontologyToRemove);
                setOntologySelectionPanelPlaceholder(infoImage);

                updateSelectedOntologies();
            }

            removeOntologyButton.setIcon(removeOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeOntologyButton.setIcon(removeOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeOntologyButton.setIcon(removeOntologyButtonIcon);
        }
    });

    removeOntologyButton.setVisible(false);

    viewOntologyButton = new JLabel(browseOntologyButtonIcon);
    viewOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            performTransition();
            viewOntologyButton.setIcon(browseOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            viewOntologyButton.setIcon(browseOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            viewOntologyButton.setIcon(browseOntologyButtonIcon);
        }
    });

    viewOntologyButton.setVisible(false);

    removeRestrictionButton = new JLabel(removeRestrictionButtonIcon);
    removeRestrictionButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if (!selectedOntologyList.isSelectionEmpty()) {
                ((RecommendedOntology) selectedOntologyList.getSelectedValue()).setBranchToSearchUnder(null);
                removeRestrictionButton.setVisible(false);
                selectedOntologyList.repaint();
            }

            removeRestrictionButton.setIcon(removeRestrictionButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            removeRestrictionButton.setIcon(removeRestrictionButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            removeRestrictionButton.setIcon(removeRestrictionButtonIcon);
        }
    });

    removeRestrictionButton.setVisible(false);

    Box selectedOntologiesOptionContainer = Box.createHorizontalBox();
    selectedOntologiesOptionContainer.setOpaque(false);

    selectedOntologiesOptionContainer.add(removeOntologyButton);
    selectedOntologiesOptionContainer.add(viewOntologyButton);
    selectedOntologiesOptionContainer.add(removeRestrictionButton);

    selectedOntologiesContainer.add(selectedOntologiesOptionContainer, BorderLayout.SOUTH);

    // create panel populated with all available ontologies inside a filterable list!
    JPanel availableOntologiesListContainer = new JPanel(new BorderLayout());
    availableOntologiesListContainer
            .setBorder(new TitledBorder(new RoundedBorder(UIHelper.LIGHT_GREEN_COLOR, 7),
                    "available ontologies", TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
                    UIHelper.VER_11_BOLD, UIHelper.DARK_GREEN_COLOR));

    final ExtendedJList availableOntologies = new ExtendedJList(listRenderer);

    final JLabel addOntologyButton = new JLabel(addOntologyButtonIcon);
    addOntologyButton.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent mouseEvent) {
            if (!availableOntologies.isSelectionEmpty()) {
                Ontology ontology = (Ontology) availableOntologies.getSelectedValue();

                selectedOntologies.put(ontology.getOntologyDisplayLabel(), new RecommendedOntology(ontology));
                updateSelectedOntologies();

                setOntologySelectionPanelPlaceholder(infoImage);
            }

            addOntologyButton.setIcon(addOntologyButtonIcon);
        }

        @Override
        public void mouseEntered(MouseEvent mouseEvent) {
            addOntologyButton.setIcon(addOntologyButtonIconOver);
        }

        @Override
        public void mouseExited(MouseEvent mouseEvent) {
            addOntologyButton.setIcon(addOntologyButtonIcon);
        }
    });

    final JLabel info = UIHelper.createLabel("", UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR);

    availableOntologies.addPropertyChangeListener("update", new PropertyChangeListener() {
        public void propertyChange(PropertyChangeEvent propertyChangeEvent) {
            info.setText("<html>viewing <b>" + availableOntologies.getFilteredItems().size()
                    + "</b> ontologies</html>");
        }
    });

    Box optionsBox = Box.createVerticalBox();

    optionsBox.add(UIHelper.wrapComponentInPanel(info));

    Box availableOntologiesOptionBox = Box.createHorizontalBox();
    availableOntologiesOptionBox.add(addOntologyButton);
    availableOntologiesOptionBox.add(Box.createHorizontalGlue());

    optionsBox.add(availableOntologiesOptionBox);

    availableOntologiesListContainer.add(optionsBox, BorderLayout.SOUTH);

    if (ontologiesToBrowseOn == null) {
        ontologiesToBrowseOn = new ArrayList<Ontology>();
        List<Ontology> bioportalQueryResult = bioportalClient.getAllOntologies();
        if (bioportalQueryResult != null) {
            ontologiesToBrowseOn.addAll(bioportalQueryResult);
        }
        ontologiesToBrowseOn.addAll(olsClient.getAllOntologies());
    }

    // precautionary check in case of having no ontologies available to search on.
    if (ontologiesToBrowseOn != null) {
        for (Ontology o : ontologiesToBrowseOn) {
            availableOntologies.addItem(o);
        }
    }

    info.setText(
            "<html>viewing <b>" + availableOntologies.getFilteredItems().size() + "</b> ontologies</html>");

    // need to get ontologies available from bioportal and add them here.
    JScrollPane availableOntologiesScroller = new JScrollPane(availableOntologies,
            JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    availableOntologiesScroller.getViewport().setBackground(UIHelper.BG_COLOR);
    availableOntologiesScroller.setPreferredSize(new Dimension(200, 125));
    availableOntologiesScroller.setBorder(new EmptyBorder(0, 0, 0, 0));

    IAppWidgetFactory.makeIAppScrollPane(availableOntologiesScroller);

    availableOntologiesListContainer.add(availableOntologiesScroller);
    availableOntologiesListContainer.add(availableOntologies.getFilterField(), BorderLayout.NORTH);

    westPanel.add(selectedOntologiesContainer, BorderLayout.CENTER);
    westPanel.add(availableOntologiesListContainer, BorderLayout.SOUTH);

    add(westPanel, BorderLayout.WEST);
}

From source file:org.pdfsam.guiclient.commons.panels.JVisualPdfPageSelectionPanel.java

/**
 * panel initialization/* w  w w . j  a  v  a 2s.c o m*/
 */
private void init() {
    setLayout(new GridBagLayout());

    thumbnailList.setDrawDeletedItems(drawDeletedItems);
    if (dndSupport == DND_SUPPORT_FILES) {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(pdfLoader));
    } else if (dndSupport == DND_SUPPORT_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler());
    } else if (dndSupport == DND_SUPPORT_FILES_AND_JAVAOBJECTS) {
        thumbnailList.setTransferHandler(new VisualListTransferHandler(pdfLoader));
    } else {
        thumbnailList.setTransferHandler(new VisualListExportTransferHandler(null));
    }
    thumbnailList.setDragEnabled(true);
    thumbnailList.setDropMode(DropMode.INSERT);
    pagesWorker = new PagesWorker(thumbnailList);
    thumbnailList.addKeyListener(new VisualPdfSelectionKeyAdapter(pagesWorker));
    thumbnailList.addMouseListener(new PageOpenerMouseAdapter(thumbnailList));

    if (showButtonPanel) {
        initButtonPanel(pagesWorker);
        initKeyListener();
    }

    //JList orientation
    if (HORIZONTAL_ORIENTATION == orientation) {
        thumbnailList.setLayoutOrientation(JList.HORIZONTAL_WRAP);
    } else {
        if (wrap) {
            thumbnailList.setLayoutOrientation(JList.VERTICAL_WRAP);
        }
    }

    topPanel.setLayout(new BoxLayout(topPanel, BoxLayout.LINE_AXIS));
    topPanel.setPreferredSize(new Dimension(400, 30));

    pdfSelectionActionListener = new VisualPdfSelectionActionListener(this, pdfLoader);
    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        //load button
        loadFileButton.setMargin(new Insets(1, 1, 1, 1));
        loadFileButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Open"));
        loadFileButton.setPreferredSize(new Dimension(100, 30));
        loadFileButton
                .setToolTipText(GettextResource.gettext(config.getI18nResourceBundle(), "Load a pdf document"));
        loadFileButton.setIcon(new ImageIcon(this.getClass().getResource("/images/add.png")));
        loadFileButton.addKeyListener(new EnterDoClickListener(loadFileButton));
        loadFileButton.setAlignmentX(Component.CENTER_ALIGNMENT);
        loadFileButton.setAlignmentY(Component.CENTER_ALIGNMENT);
        loadFileButton.setActionCommand(VisualPdfSelectionActionListener.ADD);
        loadFileButton.addActionListener(pdfSelectionActionListener);
    }
    documentProperties.setIcon(new ImageIcon(this.getClass().getResource("/images/info.png")));
    documentProperties.setVisible(false);

    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        clearButton.setMargin(new Insets(1, 1, 1, 1));
        clearButton.setMinimumSize(new Dimension(30, 30));
        clearButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Clear"));
        clearButton.setIcon(new ImageIcon(this.getClass().getResource("/images/clear.png")));
        clearButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                resetPanel();
            }
        });
    }

    zoomInButton.setMargin(new Insets(1, 1, 1, 1));
    zoomInButton.setMinimumSize(new Dimension(30, 30));
    zoomInButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom in"));
    zoomInButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomin.png")));
    zoomInButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.incZoomLevel();
                zoomOutButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() >= JVisualSelectionList.MAX_ZOOM_LEVEL) {
                    zoomInButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    zoomOutButton.setMargin(new Insets(1, 1, 1, 1));
    zoomOutButton.setMinimumSize(new Dimension(30, 30));
    zoomOutButton.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Zoom out"));
    zoomOutButton.setIcon(new ImageIcon(this.getClass().getResource("/images/zoomout.png")));
    zoomOutButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                thumbnailList.deincZoomLevel();
                zoomInButton.setEnabled(true);
                if (thumbnailList.getCurrentZoomLevel() <= JVisualSelectionList.MIN_ZOOM_LEVEL) {
                    zoomOutButton.setEnabled(false);
                }
                ((VisualListModel) thumbnailList.getModel()).elementsChanged();
            } catch (Exception ex) {
                log.error(GettextResource.gettext(config.getI18nResourceBundle(), "Error setting zoom level."),
                        ex);
            }
        }
    });

    thumbnailList.setModel(new VisualListModel());
    thumbnailList.setCellRenderer(new VisualListRenderer());
    thumbnailList.setVisibleRowCount(-1);
    thumbnailList.setSelectionMode(selectionType);
    JScrollPane listScroller = new JScrollPane(thumbnailList);

    //preview item   
    menuItemPreview.setIcon(new ImageIcon(this.getClass().getResource("/images/preview-viewer.png")));
    menuItemPreview.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Preview"));
    menuItemPreview.addMouseListener(new MouseAdapter() {
        public void mouseReleased(MouseEvent e) {
            int[] selection = thumbnailList.getSelectedIndices();
            if (selection != null && selection.length == 1) {
                VisualPageListItem item = (VisualPageListItem) thumbnailList.getModel()
                        .getElementAt(selection[0]);
                PagePreviewOpener.getInstance().openPreview(item.getParentFileCanonicalPath(),
                        item.getDocumentPassword(), item.getPageNumber());
            }
        }
    });

    if (showContextMenu) {
        //popup
        final JMenuItem menuItemMoveUp = new JMenuItem();
        menuItemMoveUp.setIcon(new ImageIcon(this.getClass().getResource("/images/up.png")));
        menuItemMoveUp.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Up"));
        menuItemMoveUp.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_UP, pagesWorker));
        popupMenu.add(menuItemMoveUp);

        final JMenuItem menuItemMoveDown = new JMenuItem();
        menuItemMoveDown.setIcon(new ImageIcon(this.getClass().getResource("/images/down.png")));
        menuItemMoveDown.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Move Down"));
        menuItemMoveDown
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.MOVE_DOWN, pagesWorker));
        popupMenu.add(menuItemMoveDown);

        final JMenuItem menuItemRemove = new JMenuItem();
        menuItemRemove.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
        menuItemRemove.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Delete"));
        menuItemRemove.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REMOVE, pagesWorker));
        popupMenu.add(menuItemRemove);

        //if elements are physically deleted i don't need this item
        if (drawDeletedItems) {
            final JMenuItem menuItemUndelete = new JMenuItem();
            menuItemUndelete.setIcon(new ImageIcon(this.getClass().getResource("/images/remove.png")));
            menuItemUndelete.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Undelete"));
            menuItemUndelete
                    .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.UNDELETE, pagesWorker));
            popupMenu.add(menuItemUndelete);
        }

        //rotate item   
        final JMenuItem menuItemRotate = new JMenuItem();
        menuItemRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/clockwise.png")));
        menuItemRotate.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate clockwise"));
        menuItemRotate
                .addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_CLOCK, pagesWorker));
        popupMenu.add(menuItemRotate);

        //rotate anticlock item   
        final JMenuItem menuItemAntiRotate = new JMenuItem();
        menuItemAntiRotate.setIcon(new ImageIcon(this.getClass().getResource("/images/anticlockwise.png")));
        menuItemAntiRotate
                .setText(GettextResource.gettext(config.getI18nResourceBundle(), "Rotate anticlockwise"));
        menuItemAntiRotate.addMouseListener(
                new VisualPdfSelectionMouseAdapter(PagesWorker.ROTATE_ANTICLOCK, pagesWorker));
        popupMenu.add(menuItemAntiRotate);

        //reverse item   
        final JMenuItem menuItemReverse = new JMenuItem();
        menuItemReverse.setIcon(new ImageIcon(this.getClass().getResource("/images/reverse.png")));
        menuItemReverse.setText(GettextResource.gettext(config.getI18nResourceBundle(), "Reverse"));
        menuItemReverse.addMouseListener(new VisualPdfSelectionMouseAdapter(PagesWorker.REVERSE, pagesWorker));
        popupMenu.add(menuItemReverse);

        enableSetOutputPathMenuItem();

        addPopupShower();
    }

    popupMenu.add(menuItemPreview);

    if (topPanelStyle >= STYLE_TOP_PANEL_FULL) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(loadFileButton);
    }
    if (topPanelStyle >= STYLE_TOP_PANEL_MEDIUM) {
        topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
        topPanel.add(clearButton);
    }
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(documentProperties);
    topPanel.add(Box.createHorizontalGlue());
    topPanel.add(zoomInButton);
    topPanel.add(Box.createRigidArea(new Dimension(5, 0)));
    topPanel.add(zoomOutButton);

    GridBagConstraints topConstraints = new GridBagConstraints();
    topConstraints.fill = GridBagConstraints.BOTH;
    topConstraints.gridx = 0;
    topConstraints.gridy = 0;
    topConstraints.gridwidth = 3;
    topConstraints.gridheight = 1;
    topConstraints.insets = new Insets(5, 5, 5, 5);
    topConstraints.weightx = 1.0;
    topConstraints.weighty = 0.0;
    if (topPanelStyle > STYLE_TOP_PANEL_HIDE) {
        add(topPanel, topConstraints);
    }

    GridBagConstraints thumbConstraints = new GridBagConstraints();
    thumbConstraints.fill = GridBagConstraints.BOTH;
    thumbConstraints.gridx = 0;
    thumbConstraints.gridy = 1;
    thumbConstraints.gridwidth = (showButtonPanel ? 2 : 3);
    thumbConstraints.gridheight = 2;
    thumbConstraints.insets = new Insets(5, 5, 5, 5);
    thumbConstraints.weightx = 1.0;
    thumbConstraints.weighty = 1.0;
    add(listScroller, thumbConstraints);

    if (showButtonPanel) {
        GridBagConstraints buttonsConstraints = new GridBagConstraints();
        buttonsConstraints.fill = GridBagConstraints.BOTH;
        buttonsConstraints.gridx = 2;
        buttonsConstraints.gridy = 1;
        buttonsConstraints.gridwidth = 1;
        buttonsConstraints.gridheight = 2;
        buttonsConstraints.insets = new Insets(5, 5, 5, 5);
        buttonsConstraints.weightx = 0.0;
        buttonsConstraints.weighty = 1.0;
        add(buttonPanel, buttonsConstraints);
    }
}