Example usage for javax.swing JPanel revalidate

List of usage examples for javax.swing JPanel revalidate

Introduction

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

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:at.becast.youploader.gui.FrmMain.java

public void initMainTab() {
    cmbCategory = new JComboBox<Categories>();
    cmbCategory.setModel(new DefaultComboBoxModel<Categories>(Categories.values()));
    SideBar sideBar = new SideBar(SideBar.SideBarMode.TOP_LEVEL, true, 300, true);
    ss1 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Settings"), new EditPanel(this),
            new ImageIcon(getClass().getResource("/pencil.png")));
    ss2 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Playlists"), new PlaylistPanel(this),
            new ImageIcon(getClass().getResource("/layers.png")));
    ss3 = new SidebarSection(sideBar, LANG.getString("frmMain.Sidebar.Monetisation"), new MonetPanel(),
            new ImageIcon(getClass().getResource("/money.png")));
    sideBar.addSection(ss1, false);//from   www .  j  a  v a 2  s . c o m
    sideBar.addSection(ss2);
    sideBar.addSection(ss3);
    JPanel mainTab = new JPanel();
    JPanel panel = new JPanel();
    GroupLayout mainTabLayout = new GroupLayout(mainTab);
    mainTabLayout.setHorizontalGroup(mainTabLayout.createParallelGroup(Alignment.TRAILING)
            .addGroup(mainTabLayout.createSequentialGroup()
                    .addComponent(panel, GroupLayout.DEFAULT_SIZE, 465, Short.MAX_VALUE)
                    .addPreferredGap(ComponentPlacement.RELATED)
                    .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)));
    mainTabLayout.setVerticalGroup(mainTabLayout.createParallelGroup(Alignment.LEADING)
            .addComponent(panel, GroupLayout.DEFAULT_SIZE, 492, Short.MAX_VALUE)
            .addGroup(mainTabLayout.createSequentialGroup()
                    .addComponent(sideBar, GroupLayout.DEFAULT_SIZE, 469, Short.MAX_VALUE).addContainerGap()));
    panel.setLayout(new FormLayout(
            new ColumnSpec[] { ColumnSpec.decode("2px"), FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("20px:grow"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC,
                    ColumnSpec.decode("23px"), ColumnSpec.decode("33px"), FormSpecs.UNRELATED_GAP_COLSPEC,
                    ColumnSpec.decode("61px"), FormSpecs.DEFAULT_COLSPEC, FormSpecs.RELATED_GAP_COLSPEC,
                    ColumnSpec.decode("24px"), ColumnSpec.decode("28px"), ColumnSpec.decode("40px"),
                    ColumnSpec.decode("36px"), FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("28px"),
                    FormSpecs.LABEL_COMPONENT_GAP_COLSPEC, ColumnSpec.decode("58px"), },
            new RowSpec[] { RowSpec.decode("2px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.LINE_GAP_ROWSPEC, RowSpec.decode("14px"),
                    RowSpec.decode("25px"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    RowSpec.decode("64dlu:grow"), FormSpecs.RELATED_GAP_ROWSPEC, FormSpecs.DEFAULT_ROWSPEC,
                    RowSpec.decode("max(64dlu;default)"), FormSpecs.RELATED_GAP_ROWSPEC,
                    FormSpecs.DEFAULT_ROWSPEC, RowSpec.decode("25px"), FormSpecs.PARAGRAPH_GAP_ROWSPEC,
                    RowSpec.decode("24px"), RowSpec.decode("23px"), }));

    lbltitlelenght = new JLabel("(0/100)");
    panel.add(lbltitlelenght, "14, 6, 3, 1, right, top");

    txtTitle = new JTextField();
    contextMenu.add(txtTitle);
    panel.add(txtTitle, "3, 7, 14, 1, fill, fill");
    txtTitle.setColumns(10);
    txtTitle.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblCategory = new JLabel(LANG.getString("frmMain.Category"));
    panel.add(lblCategory, "3, 9, 4, 1, left, bottom");
    panel.add(cmbCategory, "3, 10, 14, 1, fill, fill");

    JLabel lblDescription = new JLabel(LANG.getString("frmMain.Description"));
    panel.add(lblDescription, "3, 12, 4, 1, left, bottom");

    lblDesclenght = new JLabel("(0/5000)");
    panel.add(lblDesclenght, "14, 12, 3, 1, right, bottom");

    JScrollPane DescriptionScrollPane = new JScrollPane();
    panel.add(DescriptionScrollPane, "3, 13, 14, 1, fill, fill");

    txtDescription = new JTextArea();
    contextMenu.add(txtDescription);
    txtDescription.setFont(new Font("SansSerif", Font.PLAIN, 13));
    DescriptionScrollPane.setViewportView(txtDescription);
    txtDescription.setWrapStyleWord(true);
    txtDescription.setLineWrap(true);
    txtDescription.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblTags = new JLabel(LANG.getString("frmMain.Tags"));
    panel.add(lblTags, "3, 15, 4, 1, left, bottom");

    lblTagslenght = new JLabel("(0/500)");
    panel.add(lblTagslenght, "14, 15, 3, 1, right, top");

    JScrollPane TagScrollPane = new JScrollPane();
    panel.add(TagScrollPane, "3, 16, 14, 1, fill, fill");

    txtTags = new JTextArea();
    contextMenu.add(txtTags);
    txtTags.setFont(new Font("SansSerif", Font.PLAIN, 13));
    TagScrollPane.setViewportView(txtTags);
    txtTags.setWrapStyleWord(true);
    txtTags.setLineWrap(true);
    txtTags.setBorder(BorderFactory.createEtchedBorder());
    txtTags.addKeyListener(new KeyAdapter() {
        @Override
        public void keyReleased(KeyEvent e) {
            calcNotifies();
        }
    });

    JLabel lblAccount = new JLabel(LANG.getString("frmMain.Account"));
    panel.add(lblAccount, "3, 18, 4, 1, left, bottom");
    cmbAccount = new JComboBox<AccountType>();
    panel.add(getCmbAccount(), "3, 19, 14, 1, fill, fill");
    cmbAccount.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            changeUser();
        }
    });
    btnAddToQueue = new JButton(LANG.getString("frmMain.addtoQueue"));
    btnAddToQueue.setEnabled(false);
    panel.add(btnAddToQueue, "3, 21, 6, 1, fill, fill");
    btnAddToQueue.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            queueButton();
        }
    });
    JLabel lblSelectVideo = new JLabel();
    panel.add(lblSelectVideo, "3, 3, 4, 1, left, bottom");

    lblSelectVideo.setText(LANG.getString("frmMain.selectVideoFile"));
    cmbFile = new JComboBox<String>();
    cmbFile.setDropTarget(new DropTarget() {
        private static final long serialVersionUID = 8809983794742040683L;

        public synchronized void drop(DropTargetDropEvent evt) {
            try {
                evt.acceptDrop(DnDConstants.ACTION_COPY);
                @SuppressWarnings("unchecked")
                List<File> droppedFiles = (List<File>) evt.getTransferable()
                        .getTransferData(DataFlavor.javaFileListFlavor);
                for (File file : droppedFiles) {
                    cmbFile.removeAllItems();
                    cmbFile.addItem(file.getAbsolutePath());
                }
            } catch (Exception ex) {
                LOG.error("Error dropping video file", ex);
            }
        }
    });
    panel.add(cmbFile, "3, 4, 14, 1, fill, fill");
    JButton btnSelectMovie = new JButton();
    btnSelectMovie.setToolTipText("Select Video File");
    panel.add(btnSelectMovie, "18, 4, center, top");
    btnSelectMovie.setIcon(new ImageIcon(getClass().getResource("/film_add.png")));

    JLabel lblTitle = new JLabel(LANG.getString("frmMain.Title"));
    panel.add(lblTitle, "3, 6, 4, 1, left, bottom");

    JButton btnReset = new JButton(LANG.getString("frmMain.Reset"));
    btnReset.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            resetEdit();
        }
    });
    panel.add(btnReset, "11, 21, 6, 1, fill, fill");
    btnSelectMovie.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            EditPanel edit = (EditPanel) ss1.contentPane;
            NativeJFileChooser chooser;
            if (edit.getTxtStartDir() != null && !edit.getTxtStartDir().equals("")) {
                chooser = new NativeJFileChooser(edit.getTxtStartDir().getText().trim());
            } else {
                chooser = new NativeJFileChooser();
            }
            int returnVal = chooser.showOpenDialog((Component) self);
            if (returnVal == JFileChooser.APPROVE_OPTION) {
                cmbFile.removeAllItems();
                cmbFile.addItem(chooser.getSelectedFile().getAbsolutePath().toString());
            }
        }
    });
    mainTab.setLayout(mainTabLayout);
    mainTab.revalidate();
    mainTab.repaint();
    TabbedPane.addTab(LANG.getString("frmMain.Tabs.VideoSettings"), mainTab);
}

From source file:org.isatools.isacreator.filechooser.FileChooserUI.java

private JPanel createTopPanel() {

    final JTextField uri = new RoundedJTextField(20);
    final JTextField username = new RoundedJTextField(20);
    final JPasswordField password = new RoundedJPasswordField(20);

    final JPanel topContainer = new JPanel();
    topContainer.setLayout(new BoxLayout(topContainer, BoxLayout.PAGE_AXIS));
    topContainer.setBackground(UIHelper.BG_COLOR);

    HUDTitleBar titlePanel = new HUDTitleBar(null, null, true);
    add(titlePanel, BorderLayout.NORTH);
    titlePanel.installListeners();/*from  w  w  w .ja v  a2  s  .  c o  m*/

    topContainer.add(titlePanel);

    JPanel buttonPanel = new JPanel(new GridLayout(1, 1));
    buttonPanel.setOpaque(false);

    JPanel fileSystemPanel = new JPanel();
    fileSystemPanel.setLayout(new BoxLayout(fileSystemPanel, BoxLayout.LINE_AXIS));
    fileSystemPanel.setBackground(UIHelper.BG_COLOR);

    localFsChoice = new JLabel(localFileSystemIcon, JLabel.LEFT);
    localFsChoice.setBackground(UIHelper.BG_COLOR);
    localFsChoice.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    localFsChoice.setIcon(localFileSystemIconOver);
                    remoteFsChoice.setIcon(remoteFileSystemIcon);
                    ftpConnectionContainer.setVisible(false);
                    topContainer.revalidate();
                    status.setText("");
                    fileBrowser = new LocalBrowser();
                    try {
                        updateTree(fileBrowser.getHomeDirectory());
                    } catch (IOException e) {
                        FileBrowserTreeNode defaultFTPNode = new FileBrowserTreeNode("problem occurred!", false,
                                FileBrowserTreeNode.DIRECTORY);
                        updateTree(defaultFTPNode);
                    }

                }
            });

        }
    });

    fileSystemPanel.add(localFsChoice);
    fileSystemPanel.add(Box.createHorizontalStrut(5));

    remoteFsChoice = new JLabel(remoteFileSystemIcon, JLabel.LEFT);
    remoteFsChoice.setBackground(UIHelper.BG_COLOR);
    remoteFsChoice.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {

            SwingUtilities.invokeLater(new Runnable() {
                public void run() {
                    localFsChoice.setIcon(localFileSystemIcon);
                    remoteFsChoice.setIcon(remoteFileSystemIconOver);
                    ftpConnectionContainer.setVisible(true);
                    topContainer.revalidate();
                }
            });
            // immediately try to call FTP manager to get last sessions details
            final FTPAuthentication lastSession;
            if ((lastSession = ftpManager.getLastSession()) != null) {
                Thread remoteConnector = new Thread(new Runnable() {
                    public void run() {
                        connectToFTP(lastSession.getUri(), lastSession.getUsername(),
                                lastSession.getPassword());
                    }
                });
                remoteConnector.start();
            } else {
                errorAction("no ftp location");
            }

        }
    });

    fileSystemPanel.add(remoteFsChoice);
    fileSystemPanel.add(Box.createHorizontalStrut(5));

    status = UIHelper.createLabel("", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR);
    status.setHorizontalAlignment(JLabel.RIGHT);

    fileSystemPanel.add(status);

    buttonPanel.add(fileSystemPanel);

    topContainer.add(buttonPanel);

    // now create panel to configure the FTP site
    ftpConnectionContainer = new JPanel(new GridLayout(1, 1));
    ftpConnectionContainer.setBackground(UIHelper.BG_COLOR);

    JPanel userAuthFTP = new JPanel();
    userAuthFTP.setLayout(new BoxLayout(userAuthFTP, BoxLayout.LINE_AXIS));
    userAuthFTP.setOpaque(false);

    // add field to add URI
    JPanel uriPanel = new JPanel(new GridLayout(1, 2));
    uriPanel.setBackground(UIHelper.BG_COLOR);

    JLabel uriLab = UIHelper.createLabel("FTP URI: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR);
    UIHelper.renderComponent(uri, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    uriPanel.add(uriLab);
    uriPanel.add(uri);

    userAuthFTP.add(uriPanel);

    // add field to add username
    JPanel usernamePanel = new JPanel(new GridLayout(1, 2));
    usernamePanel.setBackground(UIHelper.BG_COLOR);

    JLabel usernameLab = UIHelper.createLabel("Username: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR);

    UIHelper.renderComponent(username, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    uriPanel.add(usernameLab);
    uriPanel.add(username);

    userAuthFTP.add(usernamePanel);

    // add field to add password
    JPanel passwordPanel = new JPanel(new GridLayout(1, 2));
    passwordPanel.setBackground(UIHelper.BG_COLOR);

    JLabel passwordLab = UIHelper.createLabel("Password: ", UIHelper.VER_10_BOLD, UIHelper.DARK_GREEN_COLOR);

    UIHelper.renderComponent(password, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false);

    passwordPanel.add(passwordLab);
    passwordPanel.add(password);

    userAuthFTP.add(passwordPanel);

    JLabel connectLab = new JLabel(connectIcon);
    connectLab.setOpaque(false);
    connectLab.setToolTipText("<html><b>Connect</b><p>Connect to the FTP source defined!</p></html>");

    connectLab.addMouseListener(new CommonMouseAdapter() {
        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            if (uri.getText() != null && !uri.getText().trim().equals("")) {
                String user = (username.getText() != null) ? username.getText() : "";
                String pass = (password.getPassword() != null) ? new String(password.getPassword()) : "";

                final FTPAuthentication newFTPLocation = new FTPAuthentication(uri.getText(), user, pass);

                Thread remoteConnector = new Thread(new Runnable() {
                    public void run() {
                        connectToFTP(newFTPLocation.getUri(), newFTPLocation.getUsername(),
                                newFTPLocation.getPassword());
                    }
                });
                remoteConnector.start();
            }
        }

    });

    userAuthFTP.add(connectLab);

    JLabel historyLab = new JLabel(viewHistoryIcon);
    historyLab.setOpaque(false);
    historyLab.setToolTipText(
            "<html><b>Search previously connected to FTP locations</b><p>Connect to a previously defined FTP location</p></html>");
    historyLab.addMouseListener(new CommonMouseAdapter() {

        public void mousePressed(MouseEvent event) {
            super.mousePressed(event);
            SelectFromFTPHistory selectFTP = new SelectFromFTPHistory();
            selectFTP.addPropertyChangeListener("locationSelected", new PropertyChangeListener() {
                public void propertyChange(PropertyChangeEvent event) {

                    if (event.getNewValue() != null) {
                        final FTPAuthentication ftpRecord = ftpManager
                                .retrieveFTPAuthenticationObject(event.getNewValue().toString());
                        Thread remoteConnector = new Thread(new Runnable() {
                            public void run() {
                                connectToFTP(ftpRecord.getUri(), ftpRecord.getUsername(),
                                        ftpRecord.getPassword());
                            }
                        });
                        remoteConnector.start();
                    }

                }
            });
            selectFTP.createGUI();
            showJDialogAsSheet(selectFTP);
        }

    });

    userAuthFTP.add(historyLab);

    ftpConnectionContainer.add(userAuthFTP);

    ftpConnectionContainer.setVisible(false);

    topContainer.add(ftpConnectionContainer);

    return topContainer;
}

From source file:org.isatools.isacreator.wizard.GeneralCreationAlgorithm.java

public JPanel instantiatePanel() {
    final JPanel generalQuestionCont = new JPanel();
    generalQuestionCont.setLayout(new BoxLayout(generalQuestionCont, BoxLayout.PAGE_AXIS));
    generalQuestionCont.setBackground(UIHelper.BG_COLOR);

    JLabel info = new JLabel("<html><b>" + assay.getMeasurementEndpoint() + "</b> using <b>"
            + assay.getTechnologyType() + "</b></html>", JLabel.LEFT);
    UIHelper.renderComponent(info, UIHelper.VER_12_PLAIN, UIHelper.GREY_COLOR, false);

    if (assay.getTechnologyType().equals("")) {
        info.setText("<html><b>" + assay.getMeasurementEndpoint() + "</html>");
    }/* w w w.  j av  a 2  s .  c  o  m*/

    info.setPreferredSize(new Dimension(300, 40));

    JPanel infoPanel = new JPanel(new GridLayout(1, 1));
    infoPanel.setBackground(UIHelper.BG_COLOR);

    infoPanel.add(info);

    generalQuestionCont.add(infoPanel);

    JPanel labelPanel = new JPanel(new GridLayout(1, 2));
    labelPanel.setBackground(UIHelper.BG_COLOR);

    labelCapture = new LabelCapture("Label");
    labelCapture.setVisible(false);

    labelUsed = new JCheckBox("Label used?", false);
    UIHelper.renderComponent(labelUsed, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, UIHelper.BG_COLOR);

    labelUsed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            labelCapture.setVisible(labelUsed.isSelected());

        }
    });

    labelPanel.add(labelUsed);
    labelPanel.add(labelCapture);

    generalQuestionCont.add(labelPanel);

    final JPanel extractPanel = new JPanel(new GridLayout(2, 2));
    extractPanel.setBackground(UIHelper.BG_COLOR);

    extractDetails.clear();

    JLabel extractsUsedLab = UIHelper.createLabel("Sample(s) used *");
    extractsUsedLab.setHorizontalAlignment(JLabel.LEFT);
    extractsUsedLab.setVerticalAlignment(JLabel.TOP);

    final JPanel extractNameContainer = new JPanel();
    extractNameContainer.setLayout(new BoxLayout(extractNameContainer, BoxLayout.PAGE_AXIS));
    extractNameContainer.setBackground(UIHelper.BG_COLOR);

    extract = new ExtractDetailsCapture("Sample " + (extractDetails.size() + 1),
            ApplicationManager.getUserInterfaceForISASection(study).getDataEntryEnvironment());

    extractDetails.add(extract);
    extractNameContainer.add(extract);

    JLabel addButton = new JLabel("add sample", addRecordIcon, JLabel.RIGHT);
    UIHelper.renderComponent(addButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    addButton.setVerticalAlignment(JLabel.TOP);
    addButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            extract = new ExtractDetailsCapture("Sample " + (extractDetails.size() + 1),
                    ApplicationManager.getUserInterfaceForISASection(study).getDataEntryEnvironment());
            extractDetails.add(extract);
            extractNameContainer.add(extract);

            extractNameContainer.revalidate();
            generalQuestionCont.revalidate();
        }

    });

    addButton.setToolTipText(
            "<html><b>add new sample</b><p>add another sample (e.g. Liver, Heart, Urine, Blood)</p></html>");

    JLabel removeButton = new JLabel("remove sample", removeIcon, JLabel.RIGHT);
    removeButton.setVerticalAlignment(JLabel.TOP);
    UIHelper.renderComponent(removeButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    removeButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            if (extractDetails.size() > 1) {
                extract = extractDetails.get(extractDetails.size() - 1);
                extractDetails.remove(extract);
                extractNameContainer.remove(extract);
                generalQuestionCont.revalidate();
            }
        }

    });
    removeButton.setToolTipText(
            "<html><b>remove previously added sample</b><p>remove the sample field last added</p></html>");

    extractPanel.add(extractsUsedLab);
    extractPanel.add(extractNameContainer);

    JPanel buttonContainer = new JPanel(new GridLayout(1, 2));
    buttonContainer.setBackground(UIHelper.BG_COLOR);

    buttonContainer.add(addButton);
    buttonContainer.add(removeButton);

    extractPanel.add(new JLabel());
    extractPanel.add(buttonContainer);

    generalQuestionCont.add(extractPanel);

    generalQuestionCont.add(Box.createVerticalStrut(5));
    generalQuestionCont.add(Box.createHorizontalGlue());

    generalQuestionCont.setBorder(new TitledBorder(new RoundedBorder(UIHelper.DARK_GREEN_COLOR, 9),
            assay.getAssayReference(), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
            UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    return generalQuestionCont;
}

From source file:org.isatools.isacreator.wizard.MicroarrayCreationAlgorithm.java

private JPanel instantiatePanel() {
    final JPanel microArrayQuestionCont = new JPanel();
    microArrayQuestionCont.setLayout(new BoxLayout(microArrayQuestionCont, BoxLayout.PAGE_AXIS));
    microArrayQuestionCont.setOpaque(false);

    StringBuilder text = new StringBuilder("<html><b>" + assay.getMeasurementEndpoint() + "</b> using <b>"
            + assay.getTechnologyType() + "</b>");

    if (!StringUtils.isEmpty(assay.getAssayPlatform())) {
        text.append(" on <b>").append(assay.getAssayPlatform()).append("</b>");
    }/*from   w w  w .  j  a  v a  2 s.co  m*/

    JLabel info = new JLabel(text.append("</html>").toString(), JLabel.LEFT);

    UIHelper.renderComponent(info, UIHelper.VER_12_PLAIN, UIHelper.GREY_COLOR, false);
    info.setPreferredSize(new Dimension(300, 40));

    JPanel infoPanel = new JPanel(new GridLayout(1, 1));
    infoPanel.setOpaque(false);

    infoPanel.add(info);

    microArrayQuestionCont.add(infoPanel);

    // create reference sample used checkbox

    JPanel labelPanel = new JPanel(new GridLayout(2, 2));
    labelPanel.setBackground(UIHelper.BG_COLOR);

    final DataEntryForm studyUISection = ApplicationManager.getUserInterfaceForISASection(study);
    System.out.println("Study user interface is null? " + (studyUISection == null));
    System.out
            .println("Study user interface dep is null? " + (studyUISection.getDataEntryEnvironment() == null));

    label1Capture = new LabelCapture("Label (e.g. Cy3)");
    label2Capture = new LabelCapture("Label (e.g. Cy5)");
    label2Capture.setVisible(false);

    // create dye swap check box
    dyeSwapUsed = new JCheckBox("dye-swap performed?", false);
    UIHelper.renderComponent(dyeSwapUsed, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    dyeSwapUsed.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent event) {
            label2Capture.setVisible(dyeSwapUsed.isSelected());

        }
    });

    labelPanel.add(UIHelper.createLabel("Label(s) used"));
    labelPanel.add(label1Capture);
    labelPanel.add(dyeSwapUsed);
    labelPanel.add(label2Capture);

    microArrayQuestionCont.add(labelPanel);

    final JPanel extractPanel = new JPanel(new GridLayout(2, 2));
    extractPanel.setOpaque(false);

    extractDetails.clear();

    JLabel extractsUsedLab = UIHelper.createLabel("sample(s) used *");
    extractsUsedLab.setHorizontalAlignment(JLabel.LEFT);
    extractsUsedLab.setVerticalAlignment(JLabel.TOP);

    final JPanel extractNameContainer = new JPanel();
    extractNameContainer.setLayout(new BoxLayout(extractNameContainer, BoxLayout.PAGE_AXIS));
    extractNameContainer.setOpaque(false);

    extract = new ExtractDetailsCapture("Sample " + (extractDetails.size() + 1),
            studyUISection.getDataEntryEnvironment());

    extractDetails.add(extract);
    extractNameContainer.add(extract);

    JLabel addExtractButton = new JLabel("add sample", addRecordIcon, JLabel.RIGHT);
    UIHelper.renderComponent(addExtractButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);

    addExtractButton.setVerticalAlignment(JLabel.TOP);
    addExtractButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            extract = new ExtractDetailsCapture("Sample " + (extractDetails.size() + 1),
                    studyUISection.getDataEntryEnvironment());
            extractDetails.add(extract);
            extractNameContainer.add(extract);

            extractNameContainer.revalidate();
            microArrayQuestionCont.revalidate();
        }
    });

    addExtractButton.setToolTipText(
            "<html><b>add new sample</b><p>add another sample (e.g. Liver, Heart, Urine, Blood)</p></html>");

    JLabel removeExtractButton = new JLabel("remove sample", removeIcon, JLabel.RIGHT);
    removeExtractButton.setVerticalAlignment(JLabel.TOP);
    UIHelper.renderComponent(removeExtractButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    removeExtractButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            if (extractDetails.size() > 1) {
                extract = extractDetails.get(extractDetails.size() - 1);
                extractDetails.remove(extract);
                extractNameContainer.remove(extract);
                microArrayQuestionCont.revalidate();
            }
        }
    });
    removeExtractButton.setToolTipText(
            "<html><b>remove previously added sample</b><p>remove the array design field last added</p></html>");

    extractPanel.add(extractsUsedLab);
    extractPanel.add(extractNameContainer);

    JPanel extractButtonContainer = new JPanel(new GridLayout(1, 2));
    extractButtonContainer.setOpaque(false);

    extractButtonContainer.add(addExtractButton);
    extractButtonContainer.add(removeExtractButton);

    extractPanel.add(new JLabel());
    extractPanel.add(extractButtonContainer);

    microArrayQuestionCont.add(extractPanel);

    // ask for array designs used...
    // create array designs panel
    final JPanel arrayDesignPanel = new JPanel(new GridLayout(2, 2));
    arrayDesignPanel.setOpaque(false);

    arrayDesignsUsed.clear();

    JLabel arrayDesignLab = UIHelper.createLabel("array design(s) used *");
    arrayDesignLab.setVerticalAlignment(JLabel.TOP);
    // the array designs container must adjust to an unknown number of fields. therefore, a JPanel with a BoxLayout
    // will be used since it is flexible!
    final JPanel arrayDesignsContainer = new JPanel();
    arrayDesignsContainer.setLayout(new BoxLayout(arrayDesignsContainer, BoxLayout.PAGE_AXIS));
    arrayDesignsContainer.setOpaque(false);

    newArrayDesign = new AutoFilterCombo(arrayDesigns, true);

    UIHelper.renderComponent(newArrayDesign, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);
    newArrayDesign.setPreferredSize(new Dimension(70, 30));

    arrayDesignsContainer.add(newArrayDesign);
    arrayDesignsUsed.add(newArrayDesign);

    JLabel addButton = new JLabel("add design", addRecordIcon, JLabel.RIGHT);

    UIHelper.renderComponent(addButton, UIHelper.VER_10_PLAIN, UIHelper.DARK_GREEN_COLOR, false);
    addButton.setVerticalAlignment(JLabel.TOP);
    addButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            newArrayDesign = new AutoFilterCombo(arrayDesigns, true);
            UIHelper.renderComponent(newArrayDesign, UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, false);
            newArrayDesign.setPreferredSize(new Dimension(70, 30));
            arrayDesignsUsed.add(newArrayDesign);
            arrayDesignsContainer.add(newArrayDesign);
            arrayDesignsContainer.revalidate();
            microArrayQuestionCont.revalidate();
        }

    });
    addButton.setToolTipText("<html><b>add new array design</b><p>add another array design</p></html>");

    JLabel removeButton = new JLabel("remove design", removeIcon, JLabel.RIGHT);
    removeButton.setVerticalAlignment(JLabel.TOP);
    UIHelper.renderComponent(removeButton, UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR, false);
    removeButton.addMouseListener(new MouseAdapter() {

        public void mousePressed(MouseEvent event) {
            if (arrayDesignsUsed.size() > 1) {
                newArrayDesign = arrayDesignsUsed.get(arrayDesignsUsed.size() - 1);
                arrayDesignsUsed.remove(newArrayDesign);
                arrayDesignsContainer.remove(newArrayDesign);
                arrayDesignPanel.revalidate();
                microArrayQuestionCont.validate();
            }
        }

    });
    removeButton.setToolTipText(
            "<html><b>remove previously added array design</b><p>remove the array design field last added</p></html>");

    arrayDesignPanel.add(arrayDesignLab);
    arrayDesignPanel.add(arrayDesignsContainer);

    JPanel buttonContainer = new JPanel(new GridLayout(1, 2));
    buttonContainer.setOpaque(false);

    buttonContainer.add(addButton);
    buttonContainer.add(removeButton);

    arrayDesignPanel.add(new JLabel());
    arrayDesignPanel.add(buttonContainer);

    microArrayQuestionCont.add(arrayDesignPanel);

    microArrayQuestionCont.add(Box.createVerticalStrut(5));
    microArrayQuestionCont.add(Box.createHorizontalGlue());

    microArrayQuestionCont.setBorder(new TitledBorder(new RoundedBorder(UIHelper.DARK_GREEN_COLOR, 9),
            assay.getAssayReference(), TitledBorder.DEFAULT_JUSTIFICATION, TitledBorder.DEFAULT_POSITION,
            UIHelper.VER_12_BOLD, UIHelper.DARK_GREEN_COLOR));

    return microArrayQuestionCont;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.EtatJournauxPanel.java

private JPanel creerJournalMoisPanel(final Date date, long debit, long credit, final Journal jrnl) {

    final JPanel panelMoisCompte = new JPanel();
    panelMoisCompte.setLayout(new GridBagLayout());
    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.HORIZONTAL;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = 0;/*  w w w  .j a v  a 2s .c  o m*/
    c.gridy = 0;
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    panelMoisCompte.setBorder(BorderFactory.createTitledBorder(dateFormat.format(date)));

    // Date du mois
    panelMoisCompte.add(new JLabel(dateFormat.format(date)), c);

    // Totaux du mois
    c.gridx++;
    panelMoisCompte.add(new JLabel(" dbit : " + GestionDevise.currencyToString(debit)), c);
    c.gridx++;
    panelMoisCompte.add(new JLabel(" crdit : " + GestionDevise.currencyToString(credit)), c);

    // Bouton dtails
    JButton boutonShow = new JButton("+/-");
    boutonShow.setOpaque(false);
    boutonShow.setHorizontalAlignment(SwingConstants.LEFT);

    c.weightx = 0;
    c.gridx++;
    panelMoisCompte.add(boutonShow, c);

    boutonShow.addActionListener(new ActionListener() {
        private boolean isShow = false;
        private ListPanelEcritures listEcriture;

        public void actionPerformed(ActionEvent e) {

            System.err.println(this.isShow);

            // Afficher la JTable du compte
            if (!this.isShow) {
                final SQLElement element = Configuration.getInstance().getDirectory().getElement("ECRITURE");
                final SQLTable ecrTable = element.getTable();

                Calendar cal = Calendar.getInstance();

                cal.setTime(date);
                cal.set(Calendar.DATE, 1);
                Date inf = cal.getTime();

                cal.set(Calendar.DATE, cal.getActualMaximum(Calendar.DATE));
                Date sup = cal.getTime();

                System.out.println("Inf : " + inf + " Sup : " + sup);
                Where w = new Where(ecrTable.getField("ID_JOURNAL"), "=", jrnl.getId());
                Where w2 = new Where(ecrTable.getField("DATE"), inf, sup);

                if (!UserManager.getInstance().getCurrentUser().getRights()
                        .haveRight(ComptaUserRight.ACCES_NOT_RESCTRICTED_TO_411)) {
                    // TODO Show Restricted acces in UI
                    w = w.and(new Where(ecrTable.getField("COMPTE_NUMERO"), "LIKE", "411%"));
                }

                this.listEcriture = new ListPanelEcritures(element, w.and(w2));
                this.listEcriture.setModificationVisible(false);
                this.listEcriture.setAjoutVisible(false);
                this.listEcriture.setSuppressionVisible(false);
                this.listEcriture.getListe().setSQLEditable(false);

                Dimension d;
                // Taille limite  200 maximum
                if (this.listEcriture.getListe().getPreferredSize().height > 200) {
                    d = new Dimension(this.listEcriture.getListe().getPreferredSize().width, 200);
                } else {
                    d = new Dimension(this.listEcriture.getListe().getPreferredSize().width,
                            this.listEcriture.getListe().getPreferredSize().height + 30);
                }
                this.listEcriture.getListe().setPreferredSize(d);

                // c.gridy = 2;
                c.gridx = 0;
                c.gridy = 1;

                c.gridwidth = 4;
                c.weightx = 1;
                c.weighty = 1;
                c.fill = GridBagConstraints.BOTH;

                this.listEcriture.getListe().setSQLEditable(false);

                panelMoisCompte.add(this.listEcriture, c);
                this.listEcriture.getListe().getJTable().addMouseListener(new MouseAdapter() {
                    public void mousePressed(MouseEvent e) {
                        if (e.getButton() == MouseEvent.BUTTON3) {
                            JPopupMenu menu = new JPopupMenu();
                            menu.add(new AbstractAction("Voir la source") {
                                public void actionPerformed(ActionEvent e) {

                                    SQLRow row = base.getTable("ECRITURE")
                                            .getRow(listEcriture.getListe().getSelectedId());

                                    MouvementSQLElement.showSource(row.getInt("ID_MOUVEMENT"));
                                }
                            });

                            menu.show(e.getComponent(), e.getPoint().x, e.getPoint().y);

                        }
                    }
                });

            } else {

                panelMoisCompte.remove(this.listEcriture);
                System.out.println("Hide ListEcriture");

                panelMoisCompte.repaint();
                panelMoisCompte.revalidate();
            }

            this.isShow = !this.isShow;
            SwingUtilities.getRoot(panelMoisCompte).repaint();
        }
    });

    return panelMoisCompte;
}

From source file:org.openconcerto.erp.core.finance.accounting.ui.GrandLivrePanel.java

private JPanel creerComptePanel(final Compte compte) {

    final GridBagConstraints c = new GridBagConstraints();
    c.insets = new Insets(2, 2, 1, 2);
    c.fill = GridBagConstraints.NONE;
    c.anchor = GridBagConstraints.NORTHWEST;
    c.gridx = GridBagConstraints.RELATIVE;
    c.gridy = 0;/*from  w  ww .j  a v a 2 s.co  m*/
    c.gridwidth = 1;
    c.gridheight = 1;
    c.weightx = 1;
    c.weighty = 0;

    // Intitul du compte
    final JPanel panelCompte = new JPanel();
    panelCompte.setOpaque(false);
    panelCompte.setLayout(new GridBagLayout());
    panelCompte.setBorder(BorderFactory.createTitledBorder(compte.getNumero() + " " + compte.getNom()));

    // Bouton Dtails +/- du compte
    JButton boutonShow = new JButton("+/-");
    boutonShow.setOpaque(false);
    boutonShow.setHorizontalAlignment(SwingConstants.RIGHT);

    // Total du Compte
    JLabel labelCompteDebit = new JLabel(
            "Total Debit : " + GestionDevise.currencyToString(compte.getTotalDebit()));
    JLabel labelCompteCredit = new JLabel(
            " Credit : " + GestionDevise.currencyToString(compte.getTotalCredit()));
    // labelCompte.setFont(new Font(labelCompte.getFont().getFontName(), Font.BOLD, 12));
    labelCompteDebit.setHorizontalAlignment(SwingUtilities.LEFT);
    labelCompteCredit.setHorizontalAlignment(SwingUtilities.LEFT);

    JLabel labelTmp = new JLabel(compte.getNumero() + " " + compte.getNom());
    labelTmp.setHorizontalAlignment(SwingUtilities.LEFT);

    panelCompte.add(labelTmp, c);
    panelCompte.add(labelCompteDebit, c);
    panelCompte.add(labelCompteCredit, c);
    c.weightx = 1;
    c.anchor = GridBagConstraints.NORTHEAST;
    panelCompte.add(boutonShow, c);

    boutonShow.addActionListener(new ActionListener() {
        private boolean isShow = false;
        private JScrollPane scroll = null;

        public void actionPerformed(ActionEvent e) {

            System.err.println(this.isShow);
            // Afficher la JTable du compte
            if (!this.isShow) {
                // if (this.scroll == null) {
                System.err.println(compte);
                JTable tableCpt = createJTableCompte(compte);

                this.scroll = new JScrollPane(tableCpt);

                // calcul de la taille du JScrollPane
                Dimension d;
                System.err.println(tableCpt);
                if (tableCpt.getPreferredSize().height > 200) {
                    d = new Dimension(this.scroll.getPreferredSize().width, 200);
                } else {
                    d = new Dimension(this.scroll.getPreferredSize().width,
                            tableCpt.getPreferredSize().height + 30);
                }
                this.scroll.setPreferredSize(d);

                c.gridy++;
                c.gridwidth = 4;
                c.weightx = 1;
                c.fill = GridBagConstraints.HORIZONTAL;
                c.anchor = GridBagConstraints.NORTHWEST;
                panelCompte.add(this.scroll, c);
                /*
                 * } else { this.scroll.setVisible(true); }
                 */

            } else {
                // if (this.scroll != null) {
                panelCompte.remove(this.scroll);
                System.out.println("Hide scrollPane");
                // this.scroll.setVisible(false);

                // this.scroll.repaint();
                panelCompte.repaint();
                panelCompte.revalidate();
                // }
            }

            this.isShow = !this.isShow;
            SwingUtilities.getRoot(panelCompte).repaint();
        }
    });

    return panelCompte;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        leftSide.removeAll();

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

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

                        leftSide.add(closeButtonPanel);

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

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

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

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

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

From source file:org.ut.biolab.medsavant.client.view.genetics.variantinfo.OtherIndividualsGeneSubInspector.java

@Override
protected JPanel getIndividualSummaryPanel(String dnaID) {
    JPanel outerPanel = new JPanel();
    outerPanel.setLayout(new BoxLayout(outerPanel, BoxLayout.Y_AXIS));

    //dnaIDVariantMap.get(DNAId) -- all variants within gene corresponding to individual
    Set<VariantRecord> variantRecords = getVariantRecords(dnaID);

    Map<Long, Set<VariantRecord>> positionVariantMap = new TreeMap<Long, Set<VariantRecord>>();
    for (VariantRecord variantRecord : variantRecords) {
        //Get all variants at that overlap at that position, regardless of individual.
        Set<VariantRecord> variantsAtPosition = positionVariantMap.get(variantRecord.getStartPosition());
        if (variantsAtPosition == null) {
            variantsAtPosition = new HashSet<VariantRecord>();
        }//  w  w  w  .  ja v  a 2 s.  c om
        variantsAtPosition.add(variantRecord);
        positionVariantMap.put(variantRecord.getStartPosition(), variantsAtPosition);
    }

    for (Map.Entry<Long, Set<VariantRecord>> e : positionVariantMap.entrySet()) {
        Long pos = e.getKey();
        Set<VariantRecord> variantsAtPosition = e.getValue();
        for (final VariantRecord variantRecord : variantsAtPosition) {
            final JPanel rowContainer = new JPanel();
            rowContainer.setLayout(new BoxLayout(rowContainer, BoxLayout.Y_AXIS));
            final JPanel row = new JPanel();
            row.setLayout(new BoxLayout(row, BoxLayout.X_AXIS));
            row.setBorder(new EmptyBorder(0, MIDDLE_LEVEL_INDENT, 0, 0));
            final JLabel showDetailsButton = ViewUtil
                    .createIconButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.EXPAND));
            String posStr = NumberFormat.getNumberInstance().format(pos);
            JLabel rowTitle = new JLabel(
                    " " + variantRecord.getZygosity().name() + " " + variantRecord.getType() + " @ " + posStr);
            row.add(showDetailsButton);
            row.add(rowTitle);
            row.add(Box.createHorizontalGlue());
            rowContainer.add(row);
            outerPanel.add(rowContainer);

            showDetailsButton.addMouseListener(new MouseAdapter() {
                private boolean expanded = true;

                @Override
                public void mousePressed(MouseEvent me) {
                    if (expanded) {
                        showDetailsButton
                                .setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.COLLAPSE));
                        int last_level_indent = MIDDLE_LEVEL_INDENT
                                + IconFactory.getInstance().getIcon(IconFactory.StandardIcon.EXPAND)
                                        .getIconWidth()
                                + rowContainer.getFontMetrics(rowContainer.getFont()).charWidth(' ');
                        JPanel p = new JPanel();
                        p.setLayout(new BoxLayout(p, BoxLayout.Y_AXIS));
                        p.setBorder(new EmptyBorder(0, last_level_indent, 0, 0));
                        JPanel textPanel = new JPanel();
                        textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
                        textPanel.add(new JLabel("Ref: " + variantRecord.getRef()));
                        textPanel.add(Box.createHorizontalGlue());
                        p.add(textPanel);

                        textPanel = new JPanel();
                        textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
                        textPanel.add(new JLabel("Alt: " + variantRecord.getAlt()));
                        textPanel.add(Box.createHorizontalGlue());
                        p.add(textPanel);

                        rowContainer.add(p);
                    } else {
                        showDetailsButton
                                .setIcon(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.EXPAND));
                        rowContainer.removeAll();
                        rowContainer.add(row);
                    }
                    rowContainer.revalidate();
                    rowContainer.repaint();
                    expanded = !expanded;
                }
            });

        }
    }
    return outerPanel;
}

From source file:projectresurrection.Music.java

public void subMenu(int menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);//  w w w.j a va 2s.  c  o  m
    JLabel header = (JLabel) pnlSub.getComponent(1);
    JLabel label;
    panel.removeAll();
    int y = 10;
    switch (menu) {
    case 0:
        header.setText("Artists");
        panel.setPreferredSize(new Dimension(349, (55 + (artists.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenu(ALBUMS);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        List artistList = new ArrayList(artists.keySet());
        Collections.sort(artistList);
        for (int i = 0; i < artistList.size(); i++) {
            String artist = artistList.get(i).toString();
            label = new JLabel(artist);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ARTISTS, artist);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 1:
        header.setText("Albums");
        panel.setPreferredSize(new Dimension(349, (55 + (albums.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenu(SONGS);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        List albumList = new ArrayList(albums.keySet());
        Collections.sort(albumList);
        for (int i = 0; i < albumList.size(); i++) {
            String album = albumList.get(i).toString();
            label = new JLabel(album);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ALBUMS, album);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 2:
        header.setText("Songs");
        panel.setPreferredSize(new Dimension(349, (20 + (songs.size() * 35))));
        List songList = new ArrayList(songs.keySet());
        Collections.sort(songList);
        List fileList = new ArrayList();
        for (int i = 0; i < songList.size(); i++) {
            fileList.add(((List) songs.get(songList.get(i))).get(0));
        }
        for (int i = 0; i < songList.size(); i++) {
            int num = i;
            String song = songList.get(i).toString();
            label = new JLabel(song);
            label.setOpaque(true);
            if (i % 2 == 0) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    player.setPlaylist(fileList, num);
                    pnlSub.setVisible(false);
                    pnlPlayer.setVisible(true);
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                    }
                    if (player.isPlaying() == false) {
                        player.toggle();
                    }
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    }
    pnlMenu.setVisible(false);
    pnlSub.setVisible(true);
}

From source file:projectresurrection.Music.java

public void subMenu(int type, String menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);/*ww  w . j a va2  s. com*/
    JLabel header = (JLabel) pnlSub.getComponent(1);
    JLabel label;
    header.setText(menu);
    panel.removeAll();
    int y = 10;
    switch (type) {
    case 0:
        List albumList = new ArrayList(((Map) artists.get(menu)).keySet());
        Collections.sort(albumList);
        panel.setPreferredSize(new Dimension(349, (55 + (albumList.size() * 35))));
        label = new JLabel("All");
        label.setOpaque(true);
        label.setBackground(new Color(245, 245, 245));
        label.setFont(new Font("Tahoma", Font.PLAIN, 20));
        label.setBounds(10, y, 339, 35);
        label.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent arg0) {
                subMenuAll(ARTISTS, menu);
                panel.revalidate();
                panel.repaint();
            }
        });
        panel.add(label);
        y += 35;
        for (int i = 0; i < albumList.size(); i++) {
            String album = albumList.get(i).toString();
            label = new JLabel(album);
            label.setOpaque(true);
            if (i % 2 == 1) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    subMenu(ALBUMS, album);
                    panel.revalidate();
                    panel.repaint();
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    case 1:
        List songList = new ArrayList();
        List albumSongs = new ArrayList(((Map) albums.get(menu)).keySet());
        Collections.sort(albumSongs);
        Map tracks = new HashMap();
        for (int i = 0; i < albumSongs.size(); i++) {
            String track = ((List) songs.get(albumSongs.get(i))).get(1).toString();
            if (tracks.containsKey(track)) {
                track = track + "(1)";
                int j = 2;
                while (tracks.containsKey(track)) {
                    track = track + "(" + j + ")";
                }
            }
            tracks.put(track, albumSongs.get(i));
        }
        List nums = new ArrayList(tracks.keySet());
        Collections.sort(nums);
        List hasTrack = new ArrayList();
        List noTrack = new ArrayList();
        for (int i = 0; i < nums.size(); i++) {
            if (nums.get(i).equals("-1")) {
                noTrack.add(tracks.get(nums.get(i)));
            } else {
                hasTrack.add(tracks.get(nums.get(i)));
            }
        }
        Collections.sort(noTrack);
        for (int i = 0; i < hasTrack.size(); i++) {
            songList.add(hasTrack.get(i));
        }
        for (int i = 0; i < noTrack.size(); i++) {
            songList.add(noTrack.get(i));
        }
        panel.setPreferredSize(new Dimension(349, (20 + (albumSongs.size() * 35))));
        List fileList = new ArrayList();
        for (int i = 0; i < songList.size(); i++) {
            fileList.add(((List) songs.get(songList.get(i))).get(0));
        }
        for (int i = 0; i < songList.size(); i++) {
            int num = i;
            String song = songList.get(i).toString();
            label = new JLabel(song);
            label.setOpaque(true);
            if (i % 2 == 0) {
                label.setBackground(new Color(245, 245, 245));
            }
            label.setFont(new Font("Tahoma", Font.PLAIN, 20));
            label.setBounds(10, y, 339, 35);
            label.addMouseListener(new MouseAdapter() {
                @Override
                public void mouseClicked(MouseEvent arg0) {
                    player.setPlaylist(fileList, num);
                    pnlSub.setVisible(false);
                    pnlPlayer.setVisible(true);
                    try {
                        Thread.sleep(200);
                    } catch (Exception e) {
                    }
                    if (player.isPlaying() == false) {
                        player.toggle();
                    }
                }
            });
            panel.add(label);
            y += 35;
        }
        break;
    }
    panel.revalidate();
    panel.repaint();
}