Example usage for java.awt GridLayout setRows

List of usage examples for java.awt GridLayout setRows

Introduction

In this page you can find the example usage for java.awt GridLayout setRows.

Prototype

public void setRows(int rows) 

Source Link

Document

Sets the number of rows in this layout to the specified value.

Usage

From source file:FirstForm.java

private void initPanels() {
    GridLayout gL = new GridLayout();
    gL.setColumns(1);//ww w  .java 2  s . c o  m
    gL.setRows(1);
    portadoraPanel.setLayout(gL);
    portadoraPanel.setPreferredSize(new Dimension(60, 50));
    moduladoraPanel.setLayout(gL);
    moduladoraPanel.setPreferredSize(new Dimension(60, 50));
    moduladaPanel.setLayout(gL);
    moduladaPanel.setPreferredSize(new Dimension(60, 140));
    portadoraPanel.add(portadoraChart);
    moduladoraPanel.add(moduladoraChart);
    moduladaPanel.add(moduladaChart);
}

From source file:edu.purdue.cc.bionet.ui.ClusteringDisplayPanel.java

public void setSampleGroups(Collection<SampleGroup> sampleGroups) {
    Component frame = this;
    while (!(frame instanceof Frame) && frame != null) {
        frame = frame.getParent();//from  w  w w . j a v a  2 s  .co m
    }
    ClusterSelectionDialog dialog = new ClusterSelectionDialog((Frame) frame,
            Settings.getLanguage().get("Choose Clustering Method"), this.getSampleGroups() != null);

    if (dialog.getReturnValue() == null) {
        return;
    }
    super.setSampleGroups(sampleGroups);
    Collection<Molecule> molecules;
    try {
        ClusterSelectorTreePanel clusterPanel = (ClusterSelectorTreePanel) this.selectorPanel.getComponent(0);
        molecules = clusterPanel.getCheckedMolecules();
    } catch (ArrayIndexOutOfBoundsException e) {
        molecules = this.molecules;
    } catch (ClassCastException e) {
        molecules = this.molecules;
        Logger.getLogger(this.getClass()).error(e, e);
    }
    // clear the panels and set new layouts based on the new groups.
    this.selectorPanel.removeAll();
    this.clusterGraphPanel.removeAll();
    int rows = (int) Math.ceil(Math.sqrt(sampleGroups.size()));
    int cols = (int) Math.ceil(sampleGroups.size() / rows);
    GridLayout layout = (GridLayout) this.selectorPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);
    layout = (GridLayout) this.clusterGraphPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);

    // start the clusterer(s) in parallel.
    Map<Thread, RunnableClusterer> clusterers = new HashMap<Thread, RunnableClusterer>();
    for (SampleGroup group : sampleGroups) {
        RunnableClusterer clusterer = new RunnableClusterer(dialog.getReturnValue());
        SampleGroup filteredGroup = new SampleGroup(group);
        filteredGroup.retainAll(this.sampleSelectorTree.getSamples());
        clusterer.setDataset(this.getDataset(molecules, filteredGroup));
        Thread thread = new Thread(clusterer);
        thread.start();
        clusterers.put(thread, clusterer);
    }

    // iterate through each group and join the threads
    Iterator<SampleGroup> groupIter = sampleGroups.iterator();
    Collection<ClusterSelectorTreePanel> clusterTreeList = new ArrayList<ClusterSelectorTreePanel>();
    this.clusterGraphPanel.removeAll();
    for (Map.Entry<Thread, RunnableClusterer> clusterer : clusterers.entrySet()) {
        try {
            clusterer.getKey().join();
            Dataset[] result = clusterer.getValue().getResult();
            Collection<Collection<Molecule>> clusters = new TreeSet<Collection<Molecule>>(
                    new DatasetComparator());
            Collection<Molecule> unclustered = new ArrayList<Molecule>(this.molecules);
            for (Dataset dataset : result) {
                Collection<Molecule> cluster = this.getMoleculesForDataset(dataset);
                clusters.add(cluster);
                unclustered.removeAll(cluster);
            }

            // create a new clustertree and add the appropriate listeners
            ClusterSelectorTreePanel clusterTree = new ClusterSelectorTreePanel(clusters);
            if (unclustered.size() > 0) {
                clusterTree.add(unclustered,
                        String.format(Settings.getLanguage().get("Unclustered") + " (%d)", unclustered.size()),
                        false);
            }
            for (ClusterSelectorTreePanel tree : clusterTreeList) {
                tree.addTreeCheckingListener(clusterTree);
                clusterTree.addTreeCheckingListener(tree);
            }
            clusterTreeList.add(clusterTree);

            this.selectorPanel.add(clusterTree);
            ClusterGraph graph = new ClusterGraph(this.sampleSelectorTree, clusterTree, groupIter.next());
            this.clusterGraphPanel.add(graph);
            graph.setMeanGraph(clusterTree.getRoot());
        } catch (InterruptedException e) {
            Logger.getLogger(this.getClass()).debug(e, e);
        }
    }
    this.removeSampleGroupsMenuItem.setEnabled(sampleGroups.size() > 1);
    this.validate();
}

From source file:edu.purdue.cc.bionet.ui.DistributionAnalysisDisplayPanel.java

/**
 * Sets the SampleGroups for this panel.
 * //from www.  j  av a 2s .c om
 * @param sampleGroups The new set of groups
 */
public void setSampleGroups(Collection<SampleGroup> sampleGroups) {

    super.setSampleGroups(sampleGroups);

    // clear the listeners
    CheckboxTree tree = this.selectorTree.getTree();
    for (TreeSelectionListener t : tree.getTreeSelectionListeners()) {
        tree.removeTreeSelectionListener(t);
        // CheckboxTree doesn't have a method for getting TreeCheckingListeners,
        // so we'll try this and catch any exceptions.
        try {
            tree.removeTreeCheckingListener((TreeCheckingListener) t);
        } catch (ClassCastException e) {
        }
    }
    for (ItemListener i : this.noFitButton.getItemListeners()) {
        this.noFitButton.removeItemListener(i);
    }
    for (ItemListener i : this.robustFitButton.getItemListeners()) {
        this.robustFitButton.removeItemListener(i);
    }
    for (ItemListener i : this.chiSquareFitButton.getItemListeners()) {
        this.chiSquareFitButton.removeItemListener(i);
    }

    this.experimentGraphPanel.removeAll();
    this.bottomPanel.removeAll();
    int cols = (int) Math.ceil(Math.sqrt(sampleGroups.size()));
    int rows = (int) Math.ceil(sampleGroups.size() / cols);
    GridLayout layout = (GridLayout) this.experimentGraphPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);
    layout = (GridLayout) this.bottomPanel.getLayout();
    layout.setRows(rows);
    layout.setColumns(cols);

    TreePath path = selectorTree.getTree().getSelectionPath();
    int level = path.getPathCount();
    DefaultMutableTreeNode selectedNode = null;
    if (level > MOLECULE) {
        selectedNode = (DefaultMutableTreeNode) path.getPathComponent(MOLECULE);
    }

    for (SampleGroup sampleGroup : sampleGroups) {
        SampleGraph sampleGraph = new SampleGraph(experiments, sampleGroup);
        ExperimentGraph experimentGraph = new ExperimentGraph(experiments, sampleGroup);
        this.bottomPanel.add(sampleGraph);
        this.selectorTree.getTree().addTreeSelectionListener(sampleGraph);
        this.experimentGraphPanel.add(experimentGraph, BorderLayout.CENTER);
        // add the listeners
        this.selectorTree.getTree().addTreeCheckingListener(sampleGraph);
        this.selectorTree.getTree().addTreeSelectionListener(experimentGraph);
        this.selectorTree.getTree().addTreeCheckingListener(experimentGraph);
        this.noFitButton.addItemListener(experimentGraph);
        this.robustFitButton.addItemListener(experimentGraph);
        this.chiSquareFitButton.addItemListener(experimentGraph);
        if (selectedNode != null) {
            sampleGraph.setGraph(selectedNode);
            experimentGraph.setGraph(selectedNode);
        }
    }
    this.removeSampleGroupsMenuItem.setEnabled(sampleGroups != null && sampleGroups.size() > 1);
    this.experimentGraphPanel.validate();
    this.bottomPanel.validate();
}

From source file:org.biojava.bio.view.MotifAnalyzer.java

/**
 * /*from www  .  j  av a2 s.c  om*/
 * @param f1 sequence file
 * @param motifs list of motifs to display
 */
public void showMotifs(SequenceIterator seqItr, List<Motif> motifs) {
    seqViewerTab.removeAll();
    seqViewerTab.setLayout(new BorderLayout());

    try {
        Vector<Sequence> seqs = new Vector<Sequence>();
        Set<MotifFinder> finders = new HashSet<MotifFinder>();

        while (seqItr.hasNext())
            seqs.add(seqItr.nextSequence());

        // labels panel

        JPanel labelPanel = new JPanel();
        seqViewerTab.add(labelPanel, BorderLayout.NORTH);

        // Sequence panels array
        JPanel seqViewer = new JPanel(new GridLayout(seqs.size(), 1));
        seqViewerTab.add(seqViewer, BorderLayout.CENTER);

        SequencePanel[] seqPanel = new SequencePanel[seqs.size()];
        GridLayout seqPanelLayout = new GridLayout(2, 1);
        seqPanelLayout.setColumns(1);
        seqPanelLayout.setHgap(5);
        seqPanelLayout.setVgap(5);
        seqPanelLayout.setRows(2);
        int i = 0;

        for (Iterator<Sequence> itr = seqs.iterator(); itr.hasNext(); i++) {
            Sequence sourceSeq = itr.next();
            String name = sourceSeq.getName().substring(sourceSeq.getName().indexOf("_") + 1);
            seqPanel[i] = new SequencePanel();
            seqPanel[i].setLayout(seqPanelLayout);
            int num = 0;
            String[] f = new String[motifs.size()];
            for (Iterator<Motif> m = motifs.iterator(); m.hasNext();) {
                Motif motif = m.next();
                if (motif.getSites().get(name) == null)
                    continue;
                for (Iterator<Site> itr2 = motif.getSites().get(name).iterator(); itr2.hasNext();) {
                    Site seq = itr2.next();
                    finders.add(motif.getFinder());
                    seq.location = new RangeLocation(sourceSeq.length() + seq.location.getMin(),
                            sourceSeq.length() + seq.location.getMax());
                    seq.type = motif.getFinder().name() + "_" + num;
                    sourceSeq.createFeature(seq);
                }
                f[num] = motif.getFinder().name() + "_" + num;
                num++;
            }

            seqPanel[i].setSequence(sourceSeq);
            seqPanel[i].setRange(new RangeLocation(1, sourceSeq.length()));
            // Magic number from EmblViewer
            seqPanel[i].setScale(Math.exp(-INITIAL_SCALE / 7.0) * 20.0);
            seqPanel[i].setDirection(SequencePanel.HORIZONTAL);

            OptimizableFilter[] optFilter = new OptimizableFilter[num];//MotifFinder.values().length];
            FeatureBlockSequenceRenderer[] renderer = new FeatureBlockSequenceRenderer[num];//MotifFinder.values().length];

            for (int k = 0; k < num; k++)//MotifFinder.values().length; k++)
            {
                optFilter[k] = new FeatureFilter.ByType(f[k]);//MotifFinder.values()[k].name());
                renderer[k] = new FeatureBlockSequenceRenderer(new RectangularBeadRenderer(10.0f, 5.0f,
                        Color.black, MotifFinder.valueOf(f[k].substring(0, f[k].indexOf('_'))).color,
                        new BasicStroke()));
            }

            MultiLineRenderer multi = new MultiLineRenderer();

            for (int k = 0; k < renderer.length; k++)
                multi.addRenderer(new FilteringRenderer(renderer[k], optFilter[k], false));

            multi.addRenderer(new SymbolSequenceRenderer());
            multi.addRenderer(new RulerRenderer());

            seqPanel[i].setRenderer(multi);
            seqPanel[i].setEnabled(false);

            JScrollPane seqScroll = new JScrollPane(seqPanel[i]);

            JPanel temp = new JPanel(new BorderLayout());

            temp.add(getControlBox(seqPanel[i], sourceSeq.getName()), BorderLayout.NORTH);
            temp.add(seqScroll, BorderLayout.CENTER);

            seqViewer.add(temp);
        }

        for (Iterator<MotifFinder> itr = finders.iterator(); itr.hasNext();) {
            MotifFinder finder = itr.next();
            // Add label of this MotifFinder
            labelPanel.add(new JLabel(finder.name()));
            JLabel l = new JLabel("      ");
            l.setOpaque(true);
            l.setBackground(finder.color);
            l.setBorder(BorderFactory.createLineBorder(Color.black));
            labelPanel.add(l);
        }
        mainFrame.setVisible(true);

    } catch (Exception e) {
        e.printStackTrace();
    }
}