Example usage for javax.swing JLayeredPane JLayeredPane

List of usage examples for javax.swing JLayeredPane JLayeredPane

Introduction

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

Prototype

public JLayeredPane() 

Source Link

Document

Create a new JLayeredPane

Usage

From source file:components.LayeredPaneDemo2.java

public LayeredPaneDemo2() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    //Create and load the duke icon.
    final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif");

    //Create and set up the layered pane.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(300, 310));
    layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
    layeredPane.addMouseMotionListener(this);

    //Add several labels to the layered pane.
    layeredPane.setLayout(new GridLayout(2, 3));
    for (int i = 0; i < layerStrings.length; i++) {
        JLabel label = createColoredLabel(layerStrings[i], layerColors[i]);
        layeredPane.add(label, new Integer(i));
    }/* w w w  . j av a 2 s . c  o  m*/

    //Create and add the Duke label to the layered pane.
    dukeLabel = new JLabel(icon);
    if (icon == null) {
        System.err.println("Duke icon not found; using black rectangle instead.");
        dukeLabel.setOpaque(true);
        dukeLabel.setBackground(Color.BLACK);
    }
    layeredPane.add(dukeLabel, new Integer(2), 0);

    //Add control pane and layered pane to this JPanel.
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(createControlPanel());
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(layeredPane);
}

From source file:components.LayeredPaneDemo.java

public LayeredPaneDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    //Create and load the duke icon.
    final ImageIcon icon = createImageIcon("images/dukeWaveRed.gif");

    //Create and set up the layered pane.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(300, 310));
    layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
    layeredPane.addMouseMotionListener(this);

    //This is the origin of the first label added.
    Point origin = new Point(10, 20);

    //This is the offset for computing the origin for the next label.
    int offset = 35;

    //Add several overlapping, colored labels to the layered pane
    //using absolute positioning/sizing.
    for (int i = 0; i < layerStrings.length; i++) {
        JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin);
        layeredPane.add(label, new Integer(i));
        origin.x += offset;//from w  w w.  jav a  2  s  . c  o m
        origin.y += offset;
    }

    //Create and add the Duke label to the layered pane.
    dukeLabel = new JLabel(icon);
    if (icon != null) {
        dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight());
    } else {
        System.err.println("Duke icon not found; using black square instead.");
        dukeLabel.setBounds(15, 225, 30, 30);
        dukeLabel.setOpaque(true);
        dukeLabel.setBackground(Color.BLACK);
    }
    layeredPane.add(dukeLabel, new Integer(2), 0);

    //Add control pane and layered pane to this JPanel.
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(createControlPanel());
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(layeredPane);
}

From source file:grafix.telas.JanelaGraficos.java

private void configurarJanela() {
    this.setBorder(BorderFactory.createEtchedBorder());
    this.setClosable(true);
    this.setIconifiable(false);
    this.setMaximizable(true);
    this.setResizable(true);
    this.setBounds(0, 0, 500, 500);
    this.setVisible(true);
    this.setTitle(getAcao().getCodAcao() + " - " + getAcao().getNomeAcao());
    this.setFrameIcon(new ImageIcon("resource/icones/grafix4.gif"));
    layersPane = new JLayeredPane();
    layersPane.setLayout(new OverlayLayout(layersPane));
    layersPane.add(getPanelGraficos(), JLayeredPane.FRAME_CONTENT_LAYER);
    layersPane.add(getPanelMolduras(), JLayeredPane.DRAG_LAYER);
    this.add(layersPane);
    this.addInternalFrameListener(new InternalFrameListener() {
        public void internalFrameActivated(InternalFrameEvent evt) {
            janelaAtivada();/*  w  ww . j ava  2 s.c o m*/
        }

        public void internalFrameClosed(InternalFrameEvent evt) {
            janelaFechada();
        }

        public void internalFrameClosing(InternalFrameEvent evt) {
        }

        public void internalFrameDeactivated(InternalFrameEvent evt) {
        }

        public void internalFrameDeiconified(InternalFrameEvent evt) {
        }

        public void internalFrameIconified(InternalFrameEvent evt) {
        }

        public void internalFrameOpened(InternalFrameEvent evt) {
        }
    });
}

From source file:LayeredPaneDemo.java

public LayeredPaneDemo() {
    setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));

    // Create and load the duke icon.
    final ImageIcon icon = new ImageIcon("yourFile.gif");

    // Create and set up the layered pane.
    layeredPane = new JLayeredPane();
    layeredPane.setPreferredSize(new Dimension(300, 310));
    layeredPane.setBorder(BorderFactory.createTitledBorder("Move the Mouse to Move Duke"));
    layeredPane.addMouseMotionListener(this);

    // This is the origin of the first label added.
    Point origin = new Point(10, 20);

    // This is the offset for computing the origin for the next label.
    int offset = 35;

    // Add several overlapping, colored labels to the layered pane
    // using absolute positioning/sizing.
    for (int i = 0; i < layerStrings.length; i++) {
        JLabel label = createColoredLabel(layerStrings[i], layerColors[i], origin);
        layeredPane.add(label, new Integer(i));
        origin.x += offset;//from ww  w. jav  a  2 s . c  om
        origin.y += offset;
    }

    // Create and add the Duke label to the layered pane.
    dukeLabel = new JLabel(icon);
    if (icon != null) {
        dukeLabel.setBounds(15, 225, icon.getIconWidth(), icon.getIconHeight());
    } else {
        System.err.println("Duke icon not found; using black square instead.");
        dukeLabel.setBounds(15, 225, 30, 30);
        dukeLabel.setOpaque(true);
        dukeLabel.setBackground(Color.BLACK);
    }
    layeredPane.add(dukeLabel, new Integer(2), 0);

    // Add control pane and layered pane to this JPanel.
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(createControlPanel());
    add(Box.createRigidArea(new Dimension(0, 10)));
    add(layeredPane);
}

From source file:au.com.jwatmuff.eventmanager.gui.scoreboard.ScoreboardDisplayPanel.java

protected ScoreboardDisplayPanel(ScoreboardLayout scoreboardLayout) {
    this.scoreboardLayout = scoreboardLayout;

    ScalableAbsoluteLayout layout;//from   ww w  . ja v a  2s  .  co  m

    setLayout(new GridLayout(1, 1));

    layeredPane = new JLayeredPane();
    layeredPane.setLayout(new OverlayLayout(layeredPane));
    add(layeredPane);

    /*
     * Image screen layer
     */
    imageLayer = new JXImagePanel();
    imageLayer.setVisible(false);
    imageLayer.setStyle(JXImagePanel.Style.SCALED_KEEP_ASPECT_RATIO);
    imageLayer.setBackground(Color.BLACK);
    layeredPane.add(imageLayer, new Integer(13));

    /*
     * No fight screen layer
     */
    noFightLayer = new JPanel();
    noFightLayer.setOpaque(true);
    noFightLayer.setVisible(false);
    layeredPane.add(noFightLayer, new Integer(12));
    layout = new ScalableAbsoluteLayout(noFightLayer, 16, 12);
    noFightLayer.setLayout(layout);

    layout.addComponent(new ScalableLabel("No Fight"), 4, 4, 8, 4);
    /*
     * Player vs Player layer
     */
    vsLayer = new JPanel();
    vsLayer.setOpaque(true);
    vsLayer.setVisible(false);
    layeredPane.add(vsLayer, new Integer(11));
    layout = new ScalableAbsoluteLayout(vsLayer, 16, 12);
    vsLayer.setLayout(layout);
    vsPlayer = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    vs = new ScalableLabel("vs");
    vsDivision = new ScalableLabel(" ");
    layout.addComponent(vsPlayer[0], 1, 1, 11, 3);
    layout.addComponent(vsPlayer[1], 4, 8, 11, 3);
    layout.addComponent(vs, 7, 5, 2, 2);
    layout.addComponent(vsDivision, scoreboardLayout.getDivisionRect());

    /*
     * Pending fight layer
     */
    pendingFightLayer = new JPanel();
    pendingFightLayer.setOpaque(true);
    pendingFightLayer.setVisible(false);
    layeredPane.add(pendingFightLayer, new Integer(10));
    layout = new ScalableAbsoluteLayout(pendingFightLayer, 16, 12);
    pendingFightLayer.setLayout(layout);
    pendingPlayer = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    pendingFightTimer = new ScalableLabel[] { new ScalableLabel("0:00"), new ScalableLabel("0:00") };
    pendingDivision = new ScalableLabel(" ");
    layout.addComponent(pendingPlayer[0], 1, 2.5, 6, 1.5);
    layout.addComponent(pendingPlayer[1], 9, 2.5, 6, 1.5);
    layout.addComponent(pendingFightTimer[0], 2, 5, 4, 2);
    layout.addComponent(pendingFightTimer[1], 10, 5, 4, 2);
    layout.addComponent(pendingDivision, scoreboardLayout.getDivisionRect());

    /*
     * Winning result layer
     */
    resultLayer = new JPanel();
    resultLayer.setOpaque(false);
    layeredPane.add(resultLayer, new Integer(9));
    layout = new ScalableAbsoluteLayout(resultLayer, 16, 12);
    resultLayer.setLayout(layout);

    result = new ScalableLabel("");
    result.setVisible(false);
    layout.addComponent(result, scoreboardLayout.getResultRect());

    goldenScore = new ScalableLabel("Golden Score");
    goldenScore.setVisible(false);
    layout.addComponent(goldenScore, scoreboardLayout.getGoldenScoreRect());

    goldenScoreApprove = new ScalableLabel("Golden Score");
    goldenScoreApprove.setVisible(false);
    layout.addComponent(goldenScoreApprove, scoreboardLayout.getGoldenScoreApproveRect());

    /*
     * Pending score layers
     */
    JPanel[] psLayer = new JPanel[3];
    pendingScores = new ScalableLabel[2][3];
    for (int i = 0; i < 3; i++) {
        psLayer[i] = new JPanel();
        psLayer[i].setOpaque(false);
        layeredPane.add(psLayer[i], new Integer(8 - i));
        layout = new ScalableAbsoluteLayout(psLayer[i], 16, 12);
        psLayer[i].setLayout(layout);

        for (int j = 0; j < 2; j++) {
            ScalableLabel label = new ScalableLabel("");
            label.setVisible(false);

            layout.addComponent(label, scoreboardLayout.getHolddownScoreRect(j, i));
            pendingScores[j][i] = label;
        }
    }

    /*
     * Holddown layer
     */
    JPanel hdLayer = new JPanel();
    hdLayer.setOpaque(false);
    layeredPane.add(hdLayer, new Integer(3));
    layout = new ScalableAbsoluteLayout(hdLayer, 16, 12);
    hdLayer.setLayout(layout);

    holddownTimer = new ScalableLabel(" ");
    holddownTimer.setVisible(false);
    layout.addComponent(holddownTimer, scoreboardLayout.getHolddownRect());

    /*
     * Bottom layer - background and core elements such as timer, player
     *                names and scores
     */
    bottomLayer = new JPanel();
    layeredPane.add(bottomLayer, new Integer(1));
    layout = new ScalableAbsoluteLayout(bottomLayer, 16, 12);
    bottomLayer.setLayout(layout);
    bottomLayer.setOpaque(false);

    timer = new ScalableLabel("5:00");
    player = new ScalableLabel[] { new ScalableLabel("Player 1"), new ScalableLabel("Player 2") };
    team = new ScalableLabel[] { new ScalableLabel("Team A"), new ScalableLabel("Team B") };

    if (scoreboardLayout instanceof IJFScoreboardLayout) {
        player[0].setHorizontalAlignment(JLabel.LEFT);
        player[1].setHorizontalAlignment(JLabel.LEFT);
        team[0].setHorizontalAlignment(JLabel.LEFT);
        team[1].setHorizontalAlignment(JLabel.LEFT);
    }

    layout.addComponent(timer, scoreboardLayout.getTimerRect());
    for (int i = 0; i < 2; i++) {
        layout.addComponent(player[i], scoreboardLayout.getPlayerLabelRect(i));
        layout.addComponent(team[i], scoreboardLayout.getTeamLabelRect(i));
    }

    scoreLabels = new ScalableLabel[2][2];
    score = new ScalableLabel[2][2];
    String[] iwyk = new String[] { "I", "W" };
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 2; j++) {
            Score s = Score.values()[j];
            scoreLabels[i][j] = new ScalableLabel(iwyk[j]);
            Rect rect = scoreboardLayout.getScoreLabelRect(i, s);
            if (rect != null)
                layout.addComponent(scoreLabels[i][j], rect);

            score[i][j] = new ScalableLabel("0");
            layout.addComponent(score[i][j], scoreboardLayout.getScoreRect(i, s));
        }
    }

    shido = new ScalableLabel[2][4];
    for (int i = 0; i < 2; i++) {
        for (int j = 0; j < 4; j++) {
            shido[i][j] = new ScalableLabel("");
            shido[i][j].setVisible(false);
            // shidos get laid out dynamically in updateShidos
            //                layout.addComponent(shido[i][j], scoreboardLayout.getShidoRect(i, index, s, model));
        }
    }
    division = new ScalableLabel(" ");
    layout.addComponent(division, scoreboardLayout.getDivisionRect());

    // IJF Scoreboard has no borders on core components
    if (scoreboardLayout instanceof IJFScoreboardLayout) {
        // Remove borders
        for (Component c : bottomLayer.getComponents()) {
            if (c instanceof ScalableLabel) {
                ScalableLabel l = (ScalableLabel) c;
                l.setBorder(new EmptyBorder(0, 0, 0, 0));
            }
        }
    }

    /*
     * Background layer - purely for background colours as used by IJF
     *                    scoreboard
     */
    backgroundLayer = new JPanel();
    layeredPane.add(backgroundLayer, new Integer(0));
    layout = new ScalableAbsoluteLayout(backgroundLayer, 16, 12);
    backgroundLayer.setLayout(layout);
    backgroundLayer.setOpaque(false);

    // Add background last
    playerBackground = new ScalableLabel[2];
    for (int i = 0; i < 2; i++) {
        playerBackground[i] = new ScalableLabel("");
        playerBackground[i].setBorder(new EmptyBorder(0, 0, 0, 0));
        Rect r = scoreboardLayout.getPlayerBackgroundRect(i);
        if (r != null)
            layout.addComponent(playerBackground[i], r);
    }

    {
        Rect r = scoreboardLayout.getTimerBackgroundRect();
        timerBackground = new ScalableLabel("");
        timerBackground.setBorder(new EmptyBorder(0, 0, 0, 0));
        if (r != null)
            layout.addComponent(timerBackground, r);
    }
}

From source file:org.esa.snap.rcp.statistics.StatisticsPanel.java

@Override
protected void initComponents() {
    init = true;/*from w ww  . ja  v  a2  s  . c o  m*/

    computePanel = new MultipleRoiComputePanel(this, getRaster());
    exportButton = getExportButton();

    final JPanel exportAndHelpPanel = GridBagUtils.createPanel();
    GridBagConstraints helpPanelConstraints = GridBagUtils
            .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1,ipadx=0");
    GridBagUtils.addToPanel(exportAndHelpPanel, new JSeparator(), helpPanelConstraints,
            "fill=HORIZONTAL,gridwidth=2,insets.left=5,insets.right=5");
    GridBagUtils.addToPanel(exportAndHelpPanel, exportButton, helpPanelConstraints,
            "gridy=1,anchor=WEST,fill=NONE");
    GridBagUtils.addToPanel(exportAndHelpPanel, getHelpButton(), helpPanelConstraints,
            "gridx=1,gridy=1,anchor=EAST,fill=NONE");

    final JPanel rightPanel = GridBagUtils.createPanel();
    GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils
            .createConstraints("anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1,insets.right=-2");
    GridBagUtils.addToPanel(rightPanel, computePanel, extendedOptionsPanelConstraints,
            "gridy=0,fill=BOTH,weighty=1");
    GridBagUtils.addToPanel(rightPanel, createAccuracyPanel(), extendedOptionsPanelConstraints,
            "gridy=1,fill=BOTH,weighty=1");
    GridBagUtils.addToPanel(rightPanel, exportAndHelpPanel, extendedOptionsPanelConstraints,
            "gridy=2,anchor=SOUTHWEST,fill=HORIZONTAL,weighty=0");

    final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
    final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
    final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
    final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);

    hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
    hideAndShowButton.setToolTipText("Collapse Options Panel");
    hideAndShowButton.setName("switchToChartButton");
    hideAndShowButton.addActionListener(new ActionListener() {

        public boolean rightPanelShown;

        @Override
        public void actionPerformed(ActionEvent e) {
            rightPanel.setVisible(rightPanelShown);
            if (rightPanelShown) {
                hideAndShowButton.setIcon(collapseIcon);
                hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
                hideAndShowButton.setToolTipText("Collapse Options Panel");
            } else {
                hideAndShowButton.setIcon(expandIcon);
                hideAndShowButton.setRolloverIcon(expandRolloverIcon);
                hideAndShowButton.setToolTipText("Expand Options Panel");
            }
            rightPanelShown = !rightPanelShown;
        }
    });

    contentPanel = new JPanel(new GridLayout(-1, 1));
    contentPanel.setBackground(Color.WHITE);
    contentPanel.addMouseListener(popupHandler);

    final JScrollPane contentScrollPane = new JScrollPane(contentPanel);
    contentScrollPane.setBorder(null);
    contentScrollPane.setBackground(Color.WHITE);

    backgroundPanel = new JPanel(new GridBagLayout());
    GridBagConstraints gbc = new GridBagConstraints();
    GridBagUtils.addToPanel(backgroundPanel, contentScrollPane, gbc,
            "fill=BOTH, weightx=1.0, weighty=1.0, anchor=NORTH");
    GridBagUtils.addToPanel(backgroundPanel, rightPanel, gbc, "gridx=1, fill=VERTICAL, weightx=0.0");

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.add(backgroundPanel);
    layeredPane.add(hideAndShowButton);
    add(layeredPane);
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the text pane.
 *
 *  @return A JLayeredPane containing the text pane.
 *//*from   w  w w  .jav a 2 s.c o m*/
private JLayeredPane makeTextPane() {
    final String ls = System.getProperty("line.separator");
    final String fmt = "Outgroup: %s" + ls + "Number: %,d" + ls + "Length: %,d" + ls + "Diversity: %.2f" + ls;

    final JLayeredPane pane = new JLayeredPane();
    final JTextArea summaryTextArea = new JTextArea(String.format(fmt, summary.getOutgroup(), summary.getNu(),
            summary.getLength(), summary.getDiversity()));
    summaryTextArea.setBackground(getBackground());
    pane.setBorder(BorderFactory.createTitledBorder("Sequences"));
    pane.setLayout(new FlowLayout(0));
    pane.add(summaryTextArea);
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            summaryTextArea
                    .setText(String.format(fmt, s.getOutgroup(), s.getNu(), s.getLength(), s.getDiversity()));
            pane.repaint();
        }
    });
    return pane;
}

From source file:org.esa.snap.rcp.statistics.ChartPagePanel.java

protected void createUI(final ChartPanel chartPanel, final JPanel optionsPanel, BindingContext bindingContext) {
    roiMaskSelector = new RoiMaskSelector(bindingContext);

    final JPanel extendedOptionsPanel = GridBagUtils.createPanel();
    GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils.createConstraints(
            "insets.left=4,insets.right=2,anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "gridy=0");
    GridBagUtils.addToPanel(extendedOptionsPanel, roiMaskSelector.createPanel(),
            extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JPanel(), extendedOptionsPanelConstraints,
            "gridy=1,insets.left=-4");
    GridBagUtils.addToPanel(extendedOptionsPanel, optionsPanel, extendedOptionsPanelConstraints,
            "insets.left=0,insets.right=0,gridy=2,fill=VERTICAL,fill=HORIZONTAL,weighty=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints,
            "insets.left=4,insets.right=2,gridy=5,anchor=SOUTHWEST");

    final SimpleScrollPane optionsScrollPane = new SimpleScrollPane(extendedOptionsPanel,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    optionsScrollPane.setBorder(null);/*from   ww w  . j a va2  s  .  c  om*/
    optionsScrollPane.getVerticalScrollBar().setUnitIncrement(20);

    final JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.add(createTopPanel(), BorderLayout.NORTH);
    rightPanel.add(optionsScrollPane, BorderLayout.CENTER);
    rightPanel.add(createChartBottomPanel(chartPanel), BorderLayout.SOUTH);

    final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
    final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
    final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
    final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);

    hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
    hideAndShowButton.setToolTipText("Collapse Options Panel");
    hideAndShowButton.setName("switchToChartButton");
    hideAndShowButton.addActionListener(new ActionListener() {

        public boolean rightPanelShown;

        @Override
        public void actionPerformed(ActionEvent e) {
            rightPanel.setVisible(rightPanelShown);
            if (rightPanelShown) {
                hideAndShowButton.setIcon(collapseIcon);
                hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
                hideAndShowButton.setToolTipText("Collapse Options Panel");
            } else {
                hideAndShowButton.setIcon(expandIcon);
                hideAndShowButton.setRolloverIcon(expandRolloverIcon);
                hideAndShowButton.setToolTipText("Expand Options Panel");
            }
            rightPanelShown = !rightPanelShown;
        }
    });

    backgroundPanel = new JPanel(new BorderLayout());
    backgroundPanel.add(chartPanel, BorderLayout.CENTER);
    backgroundPanel.add(rightPanel, BorderLayout.EAST);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.add(backgroundPanel, new Integer(0));
    layeredPane.add(hideAndShowButton, new Integer(1));
    add(layeredPane);
}

From source file:ecosim.gui.SummaryPane.java

/**
 *  Private method to build the table pane.
 *
 *  @return A JLayeredPane containing the table pane.
 *//* w  ww .j a  v  a 2 s.c  o  m*/
private JLayeredPane makeTablePane() {
    String[] columnNames = { "", "Estimate", "Hillclimbing", "Low", "High" };
    Integer[] columnWidths = { 250, 60, 60, 60, 60 };
    Object[][] rowData = { { "Number of putative ecotypes (npop)", null, null, null, null },
            { "Rate of ecotype formation (omega)", null, null, null, null },
            { "Rate of periodic selection (sigma)", null, null, null, null } };
    final JLayeredPane pane = new JLayeredPane();
    final JTable table = new JTable(rowData, columnNames) {
        public boolean isCellEditable(int row, int column) {
            return false;
        }
    };
    final JTableHeader header = table.getTableHeader();
    pane.setLayout(new BorderLayout());
    header.setReorderingAllowed(false);
    TableColumnModel cm = table.getColumnModel();
    for (int i = 0; i < columnWidths.length; i++) {
        TableColumn column = cm.getColumn(i);
        column.setMinWidth(columnWidths[i]);
        if (i == 0) {
            column.setCellRenderer(new DefaultTableCellRenderer() {
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected,
                        boolean hasFocus, int row, int column) {
                    Component cell = super.getTableCellRendererComponent(table, value, isSelected, hasFocus,
                            row, column);
                    cell.setBackground(header.getBackground());
                    cell.setForeground(header.getForeground());
                    return cell;
                }
            });
        }
    }
    pane.add(table.getTableHeader(), "North");
    pane.add(table, "Center");
    // Watch for changes to the Summary object.
    summary.addObserver(new Observer() {
        public void update(Observable o, Object obj) {
            Summary s = (Summary) obj;
            ParameterEstimate estimate = s.getEstimate();
            ParameterSet hillclimbing = s.getHillclimbing();
            ParameterSet[] ci = s.getConfidenceInterval();
            if (estimate != null) {
                ParameterSet e = estimate.getResult();
                table.setValueAt(e.getNpop(), 0, 1);
                table.setValueAt(String.format("%.4f", e.getOmega()), 1, 1);
                table.setValueAt(String.format("%.4f", e.getSigma()), 2, 1);
            }
            if (hillclimbing != null) {
                table.setValueAt(hillclimbing.getNpop(), 0, 2);
                table.setValueAt(String.format("%.4f", hillclimbing.getOmega()), 1, 2);
                table.setValueAt(String.format("%.4f", hillclimbing.getSigma()), 2, 2);
            }
            if (ci[0].getNpop() != null) {
                table.setValueAt(ci[0].getNpop(), 0, 3);
                table.setValueAt(ci[1].getNpop(), 0, 4);
            }
            if (ci[1].getOmega() != null) {
                table.setValueAt(String.format("%.4f", ci[0].getOmega()), 1, 3);

                String fmt = "%.4f";
                if (ci[1].getOmega() > 10.0D) {
                    fmt = "%.1f";
                } else if (ci[1].getOmega() > 1.0D) {
                    fmt = "%.2f";
                }
                table.setValueAt(String.format(fmt, ci[1].getOmega()), 1, 4);
            }
            if (ci[1].getSigma() != null) {
                table.setValueAt(String.format("%.4f", ci[0].getSigma()), 2, 3);
                if (ci[1].getSigma() > 100.0D - MasterVariables.EPSILON) {
                    table.setValueAt("100", 2, 4);
                } else {
                    String fmt = "%.4f";
                    if (ci[1].getSigma() > 10.0D) {
                        fmt = "%.1f";
                    } else if (ci[1].getSigma() > 1.0D) {
                        fmt = "%.2f";
                    }
                    table.setValueAt(String.format(fmt, ci[1].getSigma()), 2, 4);
                }
            }
            pane.repaint();
        }
    });
    return pane;
}

From source file:org.esa.beam.visat.toolviews.stat.ChartPagePanel.java

protected void createUI(final ChartPanel chartPanel, final JPanel optionsPanel, BindingContext bindingContext) {
    roiMaskSelector = new RoiMaskSelector(bindingContext);

    final JPanel extendedOptionsPanel = GridBagUtils.createPanel();
    GridBagConstraints extendedOptionsPanelConstraints = GridBagUtils.createConstraints(
            "insets.left=4,insets.right=2,anchor=NORTHWEST,fill=HORIZONTAL,insets.top=2,weightx=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints, "gridy=0");
    GridBagUtils.addToPanel(extendedOptionsPanel, roiMaskSelector.createPanel(),
            extendedOptionsPanelConstraints, "gridy=1,insets.left=-4");
    GridBagUtils.addToPanel(extendedOptionsPanel, optionsPanel, extendedOptionsPanelConstraints,
            "insets.left=0,insets.right=0,gridy=2,fill=VERTICAL,fill=HORIZONTAL,weighty=1");
    GridBagUtils.addToPanel(extendedOptionsPanel, new JSeparator(), extendedOptionsPanelConstraints,
            "insets.left=4,insets.right=2,gridy=5,anchor=SOUTHWEST");

    final JScrollPane optionsScrollPane = new SimpleScrollPane(extendedOptionsPanel,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    optionsScrollPane.setBorder(null);//from  ww w.jav  a2 s .  co  m

    final JPanel rightPanel = new JPanel(new BorderLayout());
    rightPanel.add(createTopPanel(), BorderLayout.NORTH);
    rightPanel.add(optionsScrollPane, BorderLayout.CENTER);
    rightPanel.add(createChartBottomPanel(chartPanel), BorderLayout.SOUTH);

    final ImageIcon collapseIcon = UIUtils.loadImageIcon("icons/PanelRight12.png");
    final ImageIcon collapseRolloverIcon = ToolButtonFactory.createRolloverIcon(collapseIcon);
    final ImageIcon expandIcon = UIUtils.loadImageIcon("icons/PanelLeft12.png");
    final ImageIcon expandRolloverIcon = ToolButtonFactory.createRolloverIcon(expandIcon);

    hideAndShowButton = ToolButtonFactory.createButton(collapseIcon, false);
    hideAndShowButton.setToolTipText("Collapse Options Panel");
    hideAndShowButton.setName("switchToChartButton");
    hideAndShowButton.addActionListener(new ActionListener() {

        public boolean rightPanelShown;

        @Override
        public void actionPerformed(ActionEvent e) {
            rightPanel.setVisible(rightPanelShown);
            if (rightPanelShown) {
                hideAndShowButton.setIcon(collapseIcon);
                hideAndShowButton.setRolloverIcon(collapseRolloverIcon);
                hideAndShowButton.setToolTipText("Collapse Options Panel");
            } else {
                hideAndShowButton.setIcon(expandIcon);
                hideAndShowButton.setRolloverIcon(expandRolloverIcon);
                hideAndShowButton.setToolTipText("Expand Options Panel");
            }
            rightPanelShown = !rightPanelShown;
        }
    });

    backgroundPanel = new JPanel(new BorderLayout());
    backgroundPanel.add(chartPanel, BorderLayout.CENTER);
    backgroundPanel.add(rightPanel, BorderLayout.EAST);

    JLayeredPane layeredPane = new JLayeredPane();
    layeredPane.add(backgroundPanel, new Integer(0));
    layeredPane.add(hideAndShowButton, new Integer(1));
    add(layeredPane);
}