Example usage for javax.swing JPanel removeAll

List of usage examples for javax.swing JPanel removeAll

Introduction

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

Prototype

public void removeAll() 

Source Link

Document

Removes all the components from this container.

Usage

From source file:org.ut.biolab.medsavant.client.project.ProjectWizard.java

private void refreshReferencePanel(JPanel p) throws SQLException, RemoteException {
    try {/*from w  w  w.j  av  a  2s.  c o m*/
        Reference[] references = MedSavantClient.ReferenceManager.getReferences(LoginController.getSessionID());
        Annotation[] annotations = MedSavantClient.AnnotationManagerAdapter
                .getAnnotations(LoginController.getSessionID());

        p.removeAll();
        checkListItems.clear();
        for (Reference r : references) {
            CheckListItem cli = new CheckListItem(r, annotations);
            checkListItems.add(cli);
            p.add(cli);
        }
        // By default, select the last check-box.  It's either the one they just added, or hg19.
        if (checkListItems.size() > 0) {
            checkListItems.get(checkListItems.size() - 1).setSelected(true);
        }
        p.add(Box.createVerticalGlue());

        p.updateUI();
        p.repaint();
    } catch (SessionExpiredException ex) {
        MedSavantExceptionHandler.handleSessionExpiredException(ex);
        return;
    }
}

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

                        leftSide.removeAll();

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

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

                        leftSide.add(closeButtonPanel);

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

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

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

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

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

From source file:org.ut.biolab.medsavant.client.view.component.KeyValuePairPanel.java

public void setValue(String key, JComponent value) {
    JPanel p = keyValueComponentMap.get(key);
    p.removeAll();
    p.add(value);//from   w w w .  j  av  a2  s . c o  m
    p.add(Box.createHorizontalGlue());
    p.repaint();
    p.getParent().repaint();
}

From source file:org.ut.biolab.medsavant.client.view.component.KeyValuePairPanel.java

public void setDetailComponent(String key, JComponent c) {
    JPanel p = keyDetailComponentMap.get(key);
    p.removeAll();
    p.setLayout(new BorderLayout());
    p.add(c, BorderLayout.CENTER);

}

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>();
        }//from   w ww. ja  v  a  2 s  . c o m
        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:org.ut.biolab.medsavant.client.view.Menu.java

/**
 * Refreshes the given content pane with content from the subsection view.
 *//*from ww  w . j  a  va 2  s .c o  m*/
public void refreshSubSection(JPanel contentPanel, SubSectionView v) {
    contentPanel.removeAll();
    contentPanel.add(v.getDockedView(), BorderLayout.CENTER);
    contentPanel.updateUI();
    tertiaryMenuPanelVisibilityContainer.removeAll();
    tertiaryMenuPanelAccessoryContainer.removeAll();

    if (v.getParent().getPersistentPanels() != null && v.getParent().getPersistentPanels().length > 0) {
        JComponent box = PeekingPanel.getToggleButtonForPanel(
                ViewController.getInstance().getPersistencePanel(),
                v.getParent().getPersistentPanels()[0].getName());
        tertiaryMenuPanelVisibilityContainer.add(box);
    }

    if (v.getSubSectionMenuComponents() != null) {
        for (Component c : v.getSubSectionMenuComponents()) {
            if (c instanceof JToggleButton) {
                tertiaryMenuPanelVisibilityContainer.add(c);
            } else {
                tertiaryMenuPanelAccessoryContainer.add(c);
            }
        }
    }

    if (v.getParent().getSectionMenuComponents() != null) {
        for (Component c : v.getParent().getSectionMenuComponents()) {
            if (c instanceof JToggleButton) {
                tertiaryMenuPanelVisibilityContainer.add(c);
            } else {
                tertiaryMenuPanelAccessoryContainer.add(c);
            }
        }
    }

    v.setUpdateRequired(false);
    ViewController.getInstance().changeSubSectionTo(v);
}

From source file:org.ut.biolab.medsavant.client.view.variants.BrowserPage.java

@Override
public JPanel getView() {
    try {//from   w  w  w  .  java  2  s. c om
        if (view == null) {
            trackAdditionLock.acquire();
            view = new JPanel();
            view.setLayout(new BorderLayout());
            view.add(new WaitPanel("Starting Genome Browser"));

            Chromosome[] chroms = MedSavantClient.ReferenceManager.getChromosomes(
                    LoginController.getSessionID(), ReferenceController.getInstance().getCurrentReferenceID());
            genomeContainer = new GenomeContainer(pageName, chroms);
            genomeView = new PeekingPanel("Genome", BorderLayout.SOUTH, genomeContainer, false, 225);

            final JPanel variationPlaceHolder = new JPanel();
            variationPlaceHolder.setLayout(new BorderLayout());
            variationPlaceHolder.add(new WaitPanel("Initializing variant views..."), BorderLayout.CENTER);
            variationPanel = new PeekingPanel("Variations", BorderLayout.WEST, variationPlaceHolder, false,
                    325);
            variationPanel.setToggleBarVisible(false);

            Runnable prepareBrowserThread = new Runnable() {
                @Override
                public void run() {
                    try {
                        final JPanel tmpView = new JPanel();
                        tmpView.setLayout(new BorderLayout());

                        genomeView.setToggleBarVisible(false);

                        tmpView.add(genomeView, BorderLayout.NORTH);

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

                        Savant savantInstance = Savant.getInstance(false, false);
                        setupToolbarButtons(savantInstance);

                        PersistentSettings.getInstance().setColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM,
                                Color.white);
                        PersistentSettings.getInstance().setColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP,
                                Color.white);
                        PersistentSettings.getInstance().setColor(ColourKey.AXIS_GRID,
                                new Color(240, 240, 240));

                        savantInstance.setStartPageVisible(false);
                        savantInstance.setTrackBackground(new Color(210, 210, 210));
                        savantInstance.setBookmarksVisibile(false);
                        savantInstance.setVariantsVisibile(false);

                        variationPlaceHolder.removeAll();
                        variationPlaceHolder.add(VariationController.getInstance().getModule(),
                                BorderLayout.CENTER);

                        GenomeController.getInstance().setGenome(null);

                        String referenceName = ReferenceController.getInstance().getCurrentReferenceName();
                        final String urlOfTrack = getTrackURL(referenceName, "sequence");

                        browserPanel.add(savantInstance.getBrowserPanel(), BorderLayout.CENTER);

                        tmpView.add(browserPanel, BorderLayout.CENTER);
                        tmpView.add(variationPanel, BorderLayout.EAST);

                        SwingUtilities.invokeLater(new Runnable() {
                            @Override
                            public void run() {
                                view.removeAll();
                                view.add(tmpView, BorderLayout.CENTER);
                                view.updateUI();
                            }
                        });

                        Thread t = new Thread(new Runnable() {
                            @Override
                            public void run() {
                                addTrackFromURLString(urlOfTrack, DataFormat.SEQUENCE);
                                trackAdditionLock.release();
                            }
                        });
                        t.start();

                    } catch (Exception ex) {
                        LOG.error("Got exception: " + ex);
                    }
                }
            };

            new Thread(prepareBrowserThread).start();

        } else {
            if (genomeContainer != null) {
                genomeContainer.updateIfRequired();
            }
        }
    } catch (Exception ex) {
        ClientMiscUtils.reportError("Error generating genome view: %s", ex);
    }
    return view;
}

From source file:projectresurrection.Music.java

public void subMenu(int menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);/*www.java  2s  .  co  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);/*from   ww w  .  jav a2  s .  c o m*/
    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();
}

From source file:projectresurrection.Music.java

public void subMenuAll(int type, String menu) {
    JPanel panel = (JPanel) ((JViewport) ((JScrollPane) pnlSub.getComponent(3)).getComponent(0))
            .getComponent(0);//from www  .  j a  va 2s .c o m
    JLabel header = (JLabel) pnlSub.getComponent(1);
    header.setText(menu + " - All");
    panel.removeAll();
    int y = 10;
    switch (type) {
    case 0:
        List songList = new ArrayList();
        List albumList = new ArrayList(((Map) artists.get(menu)).keySet());
        Collections.sort(albumList);
        for (int i = 0; i < albumList.size(); i++) {
            List albumSongs = new ArrayList(((Map) albums.get(albumList.get(i))).keySet());
            Map tracks = new HashMap();
            for (int j = 0; j < albumSongs.size(); j++) {
                String track = ((List) songs.get(albumSongs.get(j))).get(1).toString();
                tracks.put(track, albumSongs.get(j));
            }
            List nums = new ArrayList(tracks.keySet());
            Collections.sort(nums);
            List hasTrack = new ArrayList();
            List noTrack = new ArrayList();
            for (int j = 0; j < nums.size(); j++) {
                if (nums.get(j).equals("-1")) {
                    noTrack.add(tracks.get(nums.get(j)));
                } else {
                    hasTrack.add(tracks.get(nums.get(j)));
                }
            }
            for (int j = 0; j < hasTrack.size(); j++) {
                songList.add(hasTrack.get(j));
            }
            for (int j = 0; j < noTrack.size(); j++) {
                songList.add(noTrack.get(j));
            }
        }
        panel.setPreferredSize(new Dimension(349, (20 + (songList.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();
            JLabel 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();
}