Example usage for javax.swing JPanel repaint

List of usage examples for javax.swing JPanel repaint

Introduction

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

Prototype

public void repaint() 

Source Link

Document

Repaints this component.

Usage

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   w  w  w .  j  av a 2s. 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.component.KeyValuePairPanel.java

public void setValue(String key, JComponent value) {
    JPanel p = keyValueComponentMap.get(key);
    p.removeAll();/* w w w .ja v a  2  s . c  o  m*/
    p.add(value);
    p.add(Box.createHorizontalGlue());
    p.repaint();
    p.getParent().repaint();
}

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 .j a 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:projectresurrection.Music.java

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

From source file:savant.chromatogram.ChromatogramPlugin.java

private void updateChromatogram() {
    if (chromatogram != null) {
        if (GenomeUtils.isGenomeLoaded() && GenomeUtils.getGenome().isSequenceSet()) {
            TrackAdapter sequenceTrack = GenomeUtils.getGenome().getSequenceTrack();
            JPanel layerCanvas = sequenceTrack.getLayerCanvas(this);
            if (canvas == null) {
                layerCanvas.setOpaque(false);
                layerCanvas.setLayout(new BorderLayout());
                canvas = new ChromatogramCanvas(chromatogram, sequenceTrack);
                layerCanvas.add(canvas, BorderLayout.CENTER);
            }//w  ww.  j  av  a 2  s. c  o m
            layerCanvas.revalidate();
            layerCanvas.repaint();
        }
    }
}

From source file:semgen.extraction.RadialGraph.Clusterer.java

public void setUpView() throws IOException {
    setTitle(SemGenTab.formatTabName(extractor.semsimmodel.getName()));
    layout = new AggregateLayout<String, Number>(new SemGenFRLayout<String, Number>(mygraph));

    vv = new VisualizationViewer<String, Number>(layout);
    // this class will provide both label drawing and vertex shapes
    VertexLabelAsShapeRenderer<String, Number> vlasr = new VertexLabelAsShapeRenderer<String, Number>(
            vv.getRenderContext());/*www  .  j a  va 2s .co  m*/

    // customize the render context
    vv.getRenderContext().setVertexLabelTransformer(
            // this chains together Transformers so that the html tags
            // are prepended to the toString method output
            new ChainedTransformer<String, String>(
                    new Transformer[] { new ToStringLabeller<String>(), new Transformer<String, String>() {
                        public String transform(String input) {
                            return input;
                        }
                    } }));
    vv.getRenderContext().setVertexShapeTransformer(vlasr);
    vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.red));
    vv.getRenderContext().setEdgeDrawPaintTransformer(new ConstantTransformer(Color.yellow));
    vv.getRenderContext().setEdgeStrokeTransformer(new ConstantTransformer(new BasicStroke(2.5f)));

    // customize the renderer
    vv.getRenderer().setVertexLabelRenderer(vlasr);

    vv.setBackground(Color.white);
    // Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<String, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<String, Paint>() {
        public Paint transform(String v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                if (selectioncheckbox != null) {
                    extractor.clusterpanel.remove(selectioncheckbox);
                }
                Set<DataStructure> dsuris = new HashSet<DataStructure>();
                for (String dsname : vv.getPickedVertexState().getPicked()) {
                    dsuris.add(extractor.semsimmodel.getDataStructure(dsname));
                }
                Component[] clusters = extractor.clusterpanel.checkboxpanel.getComponents();
                extractor.clusterpanel.checkboxpanel.removeAll();
                for (int x = -1; x < clusters.length; x++) {
                    if (x == -1 && selectioncheckbox == null) {
                        selectioncheckbox = new ExtractorJCheckBox("Selected node(s)", dsuris);
                        selectioncheckbox.addItemListener(extractor);
                        extractor.clusterpanel.checkboxpanel.add(selectioncheckbox);
                    } else if (x > -1) {
                        extractor.clusterpanel.checkboxpanel.add(clusters[x]);
                    }
                }
                refreshModulePanel();
                return Color.cyan;
            } else {
                if (vv.getPickedVertexState().getPicked().isEmpty()) {
                    if (selectioncheckbox != null) {
                        extractor.clusterpanel.checkboxpanel.remove(selectioncheckbox);
                        selectioncheckbox = null;
                    }
                }
                refreshModulePanel();
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY)
                return THIN;
            else
                return THICK;
        }
    });

    // add restart button
    JButton scramble = new JButton("Shake");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout<String, Number> layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }
    });

    DefaultModalGraphMouse<Object, Object> gm = new DefaultModalGraphMouse<Object, Object>();
    vv.setGraphMouse(gm);

    groupVertices = new JToggleButton("Group Clusters");

    // Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(350, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(mygraph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    if (mygraph.getEdgeCount() > 10) {
        edgeBetweennessSlider.setMajorTickSpacing(mygraph.getEdgeCount() / 10);
    } else {
        edgeBetweennessSlider.setMajorTickSpacing(1);
    }
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    // I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    eastControls.setOpaque(true);
    eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
    eastControls.add(Box.createVerticalGlue());
    eastControls.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    eastControls.setBorder(sliderBorder);
    eastControls.add(Box.createVerticalGlue());

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors,
                    e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                vv.validate();
                vv.repaint();
            }
        }
    });

    clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    clusterpanel = new JPanel();
    clusterpanel.setLayout(new BoxLayout(clusterpanel, BoxLayout.Y_AXIS));
    GraphZoomScrollPane gzsp = new GraphZoomScrollPane(vv);
    clusterpanel.add(gzsp);
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    grid.add(scramble);
    grid.add(groupVertices);
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    p.add(gm.getModeComboBox());
    south.add(p);
    clusterpanel.add(south);
    clusterpanel.add(Box.createGlue());
    semscroller = new SemGenScrollPane(sempanel);
    splitpane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, semscroller, clusterpanel);
    splitpane.setDividerLocation(initsempanelwidth);
    splitpane.setDividerLocation(initsempanelwidth + 10);
    this.add(splitpane);
    this.setPreferredSize(new Dimension(950, 800));
    this.pack();
    this.setLocationRelativeTo(null);
    this.setVisible(true);
}

From source file:test.visualization.ClusteringDemo.java

private void setUpView(BufferedReader br) throws IOException {

    Factory<Number> vertexFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }/*from  w ww.j av  a2s  . c  om*/
    };
    Factory<Number> edgeFactory = new Factory<Number>() {
        int n = 0;

        public Number create() {
            return n++;
        }
    };

    PajekNetReader<Graph<Number, Number>, Number, Number> pnr = new PajekNetReader<Graph<Number, Number>, Number, Number>(
            vertexFactory, edgeFactory);

    final Graph<Number, Number> graph = new SparseMultigraph<Number, Number>();

    pnr.load(br, graph);

    //Create a simple layout frame
    //specify the Fruchterman-Rheingold layout algorithm
    final AggregateLayout<Number, Number> layout = new AggregateLayout<Number, Number>(
            new FRLayout<Number, Number>(graph));

    vv = new VisualizationViewer<Number, Number>(layout);
    vv.setBackground(Color.white);
    //Tell the renderer to use our own customized color rendering
    vv.getRenderContext()
            .setVertexFillPaintTransformer(MapTransformer.<Number, Paint>getInstance(vertexPaints));
    vv.getRenderContext().setVertexDrawPaintTransformer(new Transformer<Number, Paint>() {
        public Paint transform(Number v) {
            if (vv.getPickedVertexState().isPicked(v)) {
                return Color.cyan;
            } else {
                return Color.BLACK;
            }
        }
    });

    vv.getRenderContext().setEdgeDrawPaintTransformer(MapTransformer.<Number, Paint>getInstance(edgePaints));

    vv.getRenderContext().setEdgeStrokeTransformer(new Transformer<Number, Stroke>() {
        protected final Stroke THIN = new BasicStroke(1);
        protected final Stroke THICK = new BasicStroke(2);

        public Stroke transform(Number e) {
            Paint c = edgePaints.get(e);
            if (c == Color.LIGHT_GRAY)
                return THIN;
            else
                return THICK;
        }
    });

    //add restart button
    JButton scramble = new JButton("Restart");
    scramble.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            Layout layout = vv.getGraphLayout();
            layout.initialize();
            Relaxer relaxer = vv.getModel().getRelaxer();
            if (relaxer != null) {
                relaxer.stop();
                relaxer.prerelax();
                relaxer.relax();
            }
        }

    });

    DefaultModalGraphMouse gm = new DefaultModalGraphMouse();
    vv.setGraphMouse(gm);

    final JToggleButton groupVertices = new JToggleButton("Group Clusters");

    //Create slider to adjust the number of edges to remove when clustering
    final JSlider edgeBetweennessSlider = new JSlider(JSlider.HORIZONTAL);
    edgeBetweennessSlider.setBackground(Color.WHITE);
    edgeBetweennessSlider.setPreferredSize(new Dimension(210, 50));
    edgeBetweennessSlider.setPaintTicks(true);
    edgeBetweennessSlider.setMaximum(graph.getEdgeCount());
    edgeBetweennessSlider.setMinimum(0);
    edgeBetweennessSlider.setValue(0);
    edgeBetweennessSlider.setMajorTickSpacing(10);
    edgeBetweennessSlider.setPaintLabels(true);
    edgeBetweennessSlider.setPaintTicks(true);

    //      edgeBetweennessSlider.setBorder(BorderFactory.createLineBorder(Color.black));
    //TO DO: edgeBetweennessSlider.add(new JLabel("Node Size (PageRank With Priors):"));
    //I also want the slider value to appear
    final JPanel eastControls = new JPanel();
    eastControls.setOpaque(true);
    eastControls.setLayout(new BoxLayout(eastControls, BoxLayout.Y_AXIS));
    eastControls.add(Box.createVerticalGlue());
    eastControls.add(edgeBetweennessSlider);

    final String COMMANDSTRING = "Edges removed for clusters: ";
    final String eastSize = COMMANDSTRING + edgeBetweennessSlider.getValue();

    final TitledBorder sliderBorder = BorderFactory.createTitledBorder(eastSize);
    eastControls.setBorder(sliderBorder);
    //eastControls.add(eastSize);
    eastControls.add(Box.createVerticalGlue());

    groupVertices.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            clusterAndRecolor(layout, edgeBetweennessSlider.getValue(), similarColors,
                    e.getStateChange() == ItemEvent.SELECTED);
            vv.repaint();
        }
    });

    clusterAndRecolor(layout, 0, similarColors, groupVertices.isSelected());

    edgeBetweennessSlider.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent e) {
            JSlider source = (JSlider) e.getSource();
            if (!source.getValueIsAdjusting()) {
                int numEdgesToRemove = source.getValue();
                clusterAndRecolor(layout, numEdgesToRemove, similarColors, groupVertices.isSelected());
                sliderBorder.setTitle(COMMANDSTRING + edgeBetweennessSlider.getValue());
                eastControls.repaint();
                //vv.validate();
                //vv.repaint();
            }
        }
    });

    Container content = getContentPane();
    content.add(new GraphZoomScrollPane(vv));
    JPanel south = new JPanel();
    JPanel grid = new JPanel(new GridLayout(2, 1));
    grid.add(scramble);
    grid.add(groupVertices);
    south.add(grid);
    south.add(eastControls);
    JPanel p = new JPanel();
    p.setBorder(BorderFactory.createTitledBorder("Mouse Mode"));
    p.add(gm.getModeComboBox());
    south.add(p);
    content.add(south, BorderLayout.SOUTH);
}

From source file:tvbrowser.ui.mainframe.MainFrame.java

/**
 * Makes the StatusBar visible/* w w w  .  j a  va  2 s . co  m*/
 *
 * @param visible
 *          true if Statusbar should be visible
 */
public void setShowStatusbar(boolean visible) {
    JPanel contentPane = (JPanel) getContentPane();

    Settings.propIsStatusbarVisible.setBoolean(visible);

    if (visible && !contentPane.isAncestorOf(mStatusBar)) {
        jcontentPane.add(mStatusBar, BorderLayout.SOUTH);
    } else if (contentPane.isAncestorOf(mStatusBar)) {
        jcontentPane.remove(mStatusBar);
    }

    contentPane.invalidate();
    contentPane.repaint();
}