Example usage for java.awt GridBagLayout GridBagLayout

List of usage examples for java.awt GridBagLayout GridBagLayout

Introduction

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

Prototype

public GridBagLayout() 

Source Link

Document

Creates a grid bag layout manager.

Usage

From source file:de.uka.aifb.com.systemDynamics.gui.ModelExecutionChartPanel.java

/**
 * Creates panel.//from w  w w.ja v a2  s  .c o m
 */
private void createPanel() {
    setLayout(new BorderLayout());

    // CENTER: chart
    ChartPanel chartPanel = new ChartPanel(createChart());
    // no context menu
    chartPanel.setPopupMenu(null);
    // not zoomable
    chartPanel.setMouseZoomable(false);
    add(chartPanel, BorderLayout.CENTER);

    // LINE_END: series table
    JPanel tablePanel = new JPanel(new GridBagLayout());
    String[] columnNames = { messages.getString("ModelExecutionChartPanel.Table.ColumnNames.ExtraAxis"),
            messages.getString("ModelExecutionChartPanel.Table.ColumnNames.LevelNode") };
    final MyTableModel tableModel = new MyTableModel(columnNames, xySeriesArray.length);
    for (int i = 0; i < xySeriesArray.length; i++) {
        tableModel.addEntry((String) xySeriesArray[i].getKey());
    }
    JTable table = new JTable(tableModel);
    table.setRowSelectionAllowed(false);
    JScrollPane tableScrollPane = new JScrollPane(table);
    int width = (int) Math.min(300, table.getPreferredSize().getWidth());
    int height = (int) Math.min(200, table.getPreferredSize().getHeight());
    tableScrollPane.getViewport().setPreferredSize(new Dimension(width, height));
    tableScrollPane.setMaximumSize(tableScrollPane.getViewport().getPreferredSize());
    axesButton = new JButton(messages.getString("ModelExecutionChartPanel.AxesButton.Text"));
    axesButton.setToolTipText(messages.getString("ModelExecutionChartPanel.AxesButton.ToolTipText"));
    axesButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            // create XYSeriesCollections (and renderer)
            XYSeriesCollection standardData = new XYSeriesCollection();
            XYLineAndShapeRenderer standardRenderer = new XYLineAndShapeRenderer(true, false);
            LinkedList<XYSeriesCollection> extraDataList = new LinkedList<XYSeriesCollection>();
            LinkedList<XYLineAndShapeRenderer> extraRendererList = new LinkedList<XYLineAndShapeRenderer>();
            for (int i = 0; i < tableModel.getRowCount(); i++) {
                if (tableModel.getValueAt(i, 0).equals(Boolean.FALSE)) {
                    standardData.addSeries(xySeriesArray[i]);
                    standardRenderer.setSeriesPaint(standardData.getSeriesCount() - 1,
                            DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i
                                    % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]);
                } else {
                    // extra axis
                    XYSeriesCollection extraData = new XYSeriesCollection();
                    extraData.addSeries(xySeriesArray[i]);
                    extraDataList.add(extraData);
                    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer(true, false);
                    extraRendererList.add(renderer);
                    renderer.setSeriesPaint(0, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i
                            % DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE.length]);
                }
            }
            LinkedList<XYSeriesCollection> dataList = new LinkedList<XYSeriesCollection>();
            LinkedList<XYLineAndShapeRenderer> rendererList = new LinkedList<XYLineAndShapeRenderer>();
            if (!standardData.getSeries().isEmpty()) {
                dataList.add(standardData);
                rendererList.add(standardRenderer);
            }
            for (XYSeriesCollection data : extraDataList) {
                dataList.add(data);
            }
            for (XYLineAndShapeRenderer renderer : extraRendererList) {
                rendererList.add(renderer);
            }

            // creates axes
            LinkedList<NumberAxis> axesList = new LinkedList<NumberAxis>();
            if (!standardData.getSeries().isEmpty()) {
                NumberAxis axis = new NumberAxis(messages.getString("ModelExecutionChartPanel.Value"));
                axis.setNumberFormatOverride(NumberFormat.getInstance(locale));
                axesList.add(axis);
            }
            for (XYSeriesCollection data : extraDataList) {
                NumberAxis axis = new NumberAxis((String) data.getSeries(0).getKey());
                axis.setNumberFormatOverride(NumberFormat.getInstance(locale));
                axesList.add(axis);
            }

            // store data and axes in plot
            XYPlot plot = chart.getXYPlot();
            plot.clearRangeAxes();
            plot.setRangeAxes(axesList.toArray(new NumberAxis[0]));
            for (int i = 0; i < plot.getDatasetCount(); i++) {
                plot.setDataset(i, null);
            }
            int datasetIndex = 0;
            Iterator<XYSeriesCollection> datasetIterator = dataList.iterator();
            Iterator<XYLineAndShapeRenderer> rendererIterator = rendererList.iterator();
            while (datasetIterator.hasNext()) {
                plot.setDataset(datasetIndex, datasetIterator.next());
                plot.setRenderer(datasetIndex, rendererIterator.next());
                datasetIndex++;
            }
            for (int i = 0; i < plot.getDatasetCount(); i++) {
                plot.mapDatasetToRangeAxis(i, i);
            }
        }
    });
    GridBagConstraints c = new GridBagConstraints();
    c.anchor = GridBagConstraints.CENTER;
    c.gridx = 0;
    c.gridy = 0;
    c.insets = new Insets(0, 0, 10, 0);
    tablePanel.add(tableScrollPane, c);
    c.gridx = 0;
    c.gridy = 1;
    tablePanel.add(axesButton, c);
    add(tablePanel, BorderLayout.LINE_END);

    // PAGE_END: number of rounds and execution button
    JPanel commandPanel = new JPanel();
    commandPanel.add(new JLabel(messages.getString("ModelExecutionChartPanel.NumberRounds")));
    final JTextField numberRoundsField = new JTextField("1", 5);
    numberRoundsField.addFocusListener(this);
    commandPanel.add(numberRoundsField);
    executionButton = new JButton(messages.getString("ModelExecutionChartPanel.ExecutionButton.Text"));
    executionButton.setToolTipText(messages.getString("ModelExecutionChartPanel.ExecutionButton.ToolTipText"));
    executionButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            int numberRounds = 0;
            boolean correctNumber = false;
            try {
                numberRounds = integerNumberFormatter.parse(numberRoundsField.getText()).intValue();
            } catch (ParseException parseExcep) {
                // do nothing
            }

            if (numberRounds >= 1) {
                correctNumber = true;
            }

            if (correctNumber) {
                ModelExecutionThread executionThread = new ModelExecutionThread(numberRounds);
                executionThread.start();
            } else {
                JOptionPane.showMessageDialog(null,
                        messages.getString("ModelExecutionChartPanel.Error.Message"),
                        messages.getString("ModelExecutionChartPanel.Error.Title"), JOptionPane.ERROR_MESSAGE);
            }
        }
    });
    commandPanel.add(executionButton);
    add(commandPanel, BorderLayout.PAGE_END);
}

From source file:ca.uhn.hl7v2.testpanel.ui.AddMessageDialog.java

/**
 * Create the dialog./*from   ww w.j  av a 2s.com*/
 */
public AddMessageDialog(Controller theController) {
    myController = theController;

    setMinimumSize(new Dimension(450, 400));
    setPreferredSize(new Dimension(450, 400));
    setSize(new Dimension(450, 400));
    setResizable(false);
    setMaximumSize(new Dimension(450, 400));
    setTitle("Add Message");
    setBounds(100, 100, 450, 401);
    getContentPane().setLayout(new BorderLayout());
    mycontentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
    getContentPane().add(mycontentPanel, BorderLayout.CENTER);
    GridBagLayout gbl_contentPanel = new GridBagLayout();
    gbl_contentPanel.columnWidths = new int[] { 0, 0 };
    gbl_contentPanel.rowHeights = new int[] { 0, 0, 0 };
    gbl_contentPanel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
    gbl_contentPanel.rowWeights = new double[] { 1.0, 0.0, Double.MIN_VALUE };
    mycontentPanel.setLayout(gbl_contentPanel);
    {
        JPanel panel = new JPanel();
        panel.setBorder(
                new TitledBorder(null, "Message Type", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GridBagConstraints gbc_panel = new GridBagConstraints();
        gbc_panel.weighty = 1.0;
        gbc_panel.insets = new Insets(0, 0, 5, 0);
        gbc_panel.fill = GridBagConstraints.BOTH;
        gbc_panel.gridx = 0;
        gbc_panel.gridy = 0;
        mycontentPanel.add(panel, gbc_panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[] { 0, 0, 0 };
        gbl_panel.rowHeights = new int[] { 0, 0, 0 };
        gbl_panel.columnWeights = new double[] { 1.0, 1.0, Double.MIN_VALUE };
        gbl_panel.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
        panel.setLayout(gbl_panel);
        {
            JLabel lblVersion = new JLabel("Version");
            GridBagConstraints gbc_lblVersion = new GridBagConstraints();
            gbc_lblVersion.insets = new Insets(0, 0, 5, 5);
            gbc_lblVersion.gridx = 0;
            gbc_lblVersion.gridy = 0;
            panel.add(lblVersion, gbc_lblVersion);
        }
        {
            JLabel lblType = new JLabel("Type");
            GridBagConstraints gbc_lblType = new GridBagConstraints();
            gbc_lblType.insets = new Insets(0, 0, 5, 0);
            gbc_lblType.gridx = 1;
            gbc_lblType.gridy = 0;
            panel.add(lblType, gbc_lblType);
        }
        {
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportBorder(null);
            GridBagConstraints gbc_scrollPane = new GridBagConstraints();
            gbc_scrollPane.weighty = 1.0;
            gbc_scrollPane.insets = new Insets(0, 0, 0, 5);
            gbc_scrollPane.fill = GridBagConstraints.BOTH;
            gbc_scrollPane.gridx = 0;
            gbc_scrollPane.gridy = 1;
            panel.add(scrollPane, gbc_scrollPane);
            {
                myVersionList = new JList();
                myVersionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                scrollPane.setViewportView(myVersionList);
            }
        }
        {
            JScrollPane scrollPane = new JScrollPane();
            scrollPane.setViewportBorder(null);
            GridBagConstraints gbc_scrollPane = new GridBagConstraints();
            gbc_scrollPane.weighty = 1.0;
            gbc_scrollPane.weightx = 1.0;
            gbc_scrollPane.fill = GridBagConstraints.BOTH;
            gbc_scrollPane.gridx = 1;
            gbc_scrollPane.gridy = 1;
            panel.add(scrollPane, gbc_scrollPane);
            {
                myMessageTypeList = new JList();
                myMessageTypeList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
                scrollPane.setViewportView(myMessageTypeList);
            }
        }
    }
    {
        JPanel panel = new JPanel();
        panel.setBorder(new TitledBorder(null, "Options", TitledBorder.LEADING, TitledBorder.TOP, null, null));
        GridBagConstraints gbc_panel = new GridBagConstraints();
        gbc_panel.fill = GridBagConstraints.BOTH;
        gbc_panel.gridx = 0;
        gbc_panel.gridy = 1;
        mycontentPanel.add(panel, gbc_panel);
        GridBagLayout gbl_panel = new GridBagLayout();
        gbl_panel.columnWidths = new int[] { 0, 0, 0 };
        gbl_panel.rowHeights = new int[] { 0, 0 };
        gbl_panel.columnWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
        gbl_panel.rowWeights = new double[] { 0.0, Double.MIN_VALUE };
        panel.setLayout(gbl_panel);
        {
            JLabel lblEncoding = new JLabel("Encoding");
            GridBagConstraints gbc_lblEncoding = new GridBagConstraints();
            gbc_lblEncoding.insets = new Insets(0, 0, 0, 5);
            gbc_lblEncoding.gridx = 0;
            gbc_lblEncoding.gridy = 0;
            panel.add(lblEncoding, gbc_lblEncoding);
        }
        {
            JPanel panel_1 = new JPanel();
            panel_1.setBorder(null);
            GridBagConstraints gbc_panel_1 = new GridBagConstraints();
            gbc_panel_1.anchor = GridBagConstraints.WEST;
            gbc_panel_1.fill = GridBagConstraints.VERTICAL;
            gbc_panel_1.gridx = 1;
            gbc_panel_1.gridy = 0;
            panel.add(panel_1, gbc_panel_1);
            {
                myEr7Radio = new JRadioButton("ER7");
                myEr7Radio.setSelected(true);
                encodingButtonGroup.add(myEr7Radio);
                panel_1.add(myEr7Radio);
            }
            {
                JRadioButton myXmlRadio = new JRadioButton("XML");
                encodingButtonGroup.add(myXmlRadio);
                panel_1.add(myXmlRadio);
            }
        }
    }
    {
        JPanel buttonPane = new JPanel();
        buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
        getContentPane().add(buttonPane, BorderLayout.SOUTH);
        {
            JButton okButton = new JButton("OK");
            okButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    try {
                        String version = (String) myVersionList.getSelectedValue();
                        String fullType = (String) myMessageTypeList.getSelectedValue();
                        String structure = myTypesToStructures.get(fullType);
                        String[] fullTypeBits = fullType.split("\\^");
                        String type = fullTypeBits[0];
                        String trigger = fullTypeBits[1];

                        Hl7V2EncodingTypeEnum encoding = myEr7Radio.isSelected() ? Hl7V2EncodingTypeEnum.ER_7
                                : Hl7V2EncodingTypeEnum.XML;
                        myController.addMessage(version, type, trigger, structure, encoding);
                    } finally {
                        setVisible(false);
                    }
                }
            });
            okButton.setActionCommand("OK");
            buttonPane.add(okButton);
            getRootPane().setDefaultButton(okButton);
        }
        {
            JButton cancelButton = new JButton("Cancel");
            cancelButton.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    AddMessageDialog.this.setVisible(false);
                }
            });
            cancelButton.setActionCommand("Cancel");
            buttonPane.add(cancelButton);
        }
    }

    initLocal();
}

From source file:gov.loc.repository.bagger.ui.NewBagInPlaceFrame.java

private JPanel createComponents() {

    TitlePane titlePane = new TitlePane();
    initStandardCommands();/* w  ww .  j a  va  2  s .c o m*/
    JPanel pageControl = new JPanel(new BorderLayout());
    JPanel titlePaneContainer = new JPanel(new BorderLayout());
    titlePane.setTitle(bagView.getPropertyMessage("NewBagInPlace.title"));
    titlePane.setMessage(new DefaultMessage(bagView.getPropertyMessage("NewBagInPlace.description")));
    titlePaneContainer.add(titlePane.getControl());
    titlePaneContainer.add(new JSeparator(), BorderLayout.SOUTH);
    pageControl.add(titlePaneContainer, BorderLayout.NORTH);

    JPanel contentPanel = new JPanel(new GridBagLayout());
    contentPanel.setBorder(new EmptyBorder(10, 10, 10, 10));

    int row = 0;
    layoutSelectDataContent(contentPanel, row++);
    layoutBagVersionContent(contentPanel, row++);
    layoutProfileSelectionContent(contentPanel, row++);
    layoutAddKeepFilesToEmptyCheckBox(contentPanel, row++);
    layoutSpacer(contentPanel, row++);

    GuiStandardUtils.attachDialogBorder(contentPanel);
    pageControl.add(contentPanel);
    JComponent buttonBar = createButtonBar();
    pageControl.add(buttonBar, BorderLayout.SOUTH);

    this.pack();
    return pageControl;

}

From source file:mekhq.gui.FinancesTab.java

@Override
public void initTab() {
    resourceMap = ResourceBundle.getBundle("mekhq.resources.FinancesTab", new EncodeControl()); //$NON-NLS-1$

    GridBagConstraints gridBagConstraints;

    setLayout(new GridBagLayout());
    ChartPanel financeAmountPanel = (ChartPanel) createGraphPanel(GraphType.BALANCE_AMOUNT);
    ChartPanel financeMonthlyPanel = (ChartPanel) createGraphPanel(GraphType.MONTHLY_FINANCES);

    financeModel = new FinanceTableModel();
    financeTable = new JTable(financeModel);
    financeTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    financeTable.addMouseListener(new FinanceTableMouseAdapter(getCampaignGui(), financeTable, financeModel));
    financeTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    TableColumn column = null;//from w  w  w  . j  a  va2  s.c  o  m
    for (int i = 0; i < FinanceTableModel.N_COL; i++) {
        column = financeTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(financeModel.getColumnWidth(i));
        column.setCellRenderer(financeModel.getRenderer());
    }
    financeTable.setIntercellSpacing(new Dimension(0, 0));
    financeTable.setShowGrid(false);

    loanModel = new LoanTableModel();
    loanTable = new JTable(loanModel);
    loanTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    loanTable.addMouseListener(new LoanTableMouseAdapter(getCampaignGui(), loanTable, loanModel));
    loanTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS);
    column = null;
    for (int i = 0; i < LoanTableModel.N_COL; i++) {
        column = loanTable.getColumnModel().getColumn(i);
        column.setPreferredWidth(loanModel.getColumnWidth(i));
        column.setCellRenderer(loanModel.getRenderer());
    }
    loanTable.setIntercellSpacing(new Dimension(0, 0));
    loanTable.setShowGrid(false);
    JScrollPane scrollLoanTable = new JScrollPane(loanTable);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    JPanel panBalance = new JPanel(new GridBagLayout());
    panBalance.add(new JScrollPane(financeTable), gridBagConstraints);
    panBalance.setMinimumSize(new java.awt.Dimension(350, 100));
    panBalance.setBorder(BorderFactory.createTitledBorder("Balance Sheet"));
    JPanel panLoan = new JPanel(new GridBagLayout());
    panLoan.add(scrollLoanTable, gridBagConstraints);

    JTabbedPane financeTab = new JTabbedPane();
    financeTab.setMinimumSize(new java.awt.Dimension(450, 300));
    financeTab.setPreferredSize(new java.awt.Dimension(450, 300));

    JSplitPane splitFinances = new JSplitPane(JSplitPane.VERTICAL_SPLIT, panBalance, financeTab);
    splitFinances.setOneTouchExpandable(true);
    splitFinances.setContinuousLayout(true);
    splitFinances.setResizeWeight(1.0);
    splitFinances.setName("splitFinances");

    financeTab.addTab(resourceMap.getString("activeLoans.text"), panLoan);
    financeTab.addTab(resourceMap.getString("cbillsBalanceTime.text"), financeAmountPanel);
    financeTab.addTab(resourceMap.getString("monthlyRevenueExpenditures.text"), financeMonthlyPanel);

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 0;
    gridBagConstraints.gridy = 1;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHWEST;
    gridBagConstraints.weightx = 1.0;
    gridBagConstraints.weighty = 1.0;
    add(splitFinances, gridBagConstraints);

    JPanel panelFinanceRight = new JPanel(new BorderLayout());

    JPanel pnlFinanceBtns = new JPanel(new GridLayout(2, 2));
    btnAddFunds = new JButton("Add Funds (GM)");
    btnAddFunds.addActionListener(ev -> addFundsActionPerformed());
    btnAddFunds.setEnabled(getCampaign().isGM());
    pnlFinanceBtns.add(btnAddFunds);
    JButton btnGetLoan = new JButton("Get Loan");
    btnGetLoan.addActionListener(e -> showNewLoanDialog());
    pnlFinanceBtns.add(btnGetLoan);

    btnManageAssets = new JButton("Manage Assets (GM)");
    btnManageAssets.addActionListener(e -> manageAssets());
    btnManageAssets.setEnabled(getCampaign().isGM());
    pnlFinanceBtns.add(btnManageAssets);

    panelFinanceRight.add(pnlFinanceBtns, BorderLayout.NORTH);

    areaNetWorth = new JTextArea();
    areaNetWorth.setLineWrap(true);
    areaNetWorth.setWrapStyleWord(true);
    areaNetWorth.setFont(new Font("Courier New", Font.PLAIN, 12));
    areaNetWorth.setText(getCampaign().getFinancialReport());
    areaNetWorth.setEditable(false);

    JScrollPane descriptionScroll = new JScrollPane(areaNetWorth);
    panelFinanceRight.add(descriptionScroll, BorderLayout.CENTER);
    areaNetWorth.setCaretPosition(0);
    descriptionScroll.setMinimumSize(new Dimension(300, 200));

    gridBagConstraints = new java.awt.GridBagConstraints();
    gridBagConstraints.gridx = 1;
    gridBagConstraints.gridy = 0;
    gridBagConstraints.gridheight = 2;
    gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
    gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
    gridBagConstraints.weightx = 0.0;
    gridBagConstraints.weighty = 1.0;
    add(panelFinanceRight, gridBagConstraints);
}

From source file:at.ac.tuwien.ibk.biqini.pep.gui.PEPGUI.java

public PEPGUI(String arg0, Vector<IBandwidthTracer> qosRules) {
    super(arg0);//www  .  j a  v a2s. c o m

    // initiate all collections
    tsc = new TimeSeriesCollection[MAXCHARTS];
    charts = new JFreeChart[MAXCHARTS];
    positions = new Vector<Integer>();
    chartPosition = new Hashtable<String, Integer>();
    for (int i = 0; i < MAXCHARTS; i++)
        positions.add(i);
    allSessions = new Hashtable<String, IBandwidthTracer>();

    // fill the BandwidthGenerator with the ongoing QoSRules
    bandwidthGenerator = new BandwidthGenerator();
    Enumeration<IBandwidthTracer> enbandwidth = qosRules.elements();
    while (enbandwidth.hasMoreElements()) {
        IBandwidthTracer b = enbandwidth.nextElement();
        allSessions.put(b.getName(), b);
        bandwidthGenerator.add(b);
    }

    gridBagLayout = new GridBagLayout();

    //insert the list with all QoS rules
    GridBagConstraints c = new GridBagConstraints();
    c.weighty = 9;
    c.weightx = 2.0;
    c.gridheight = MAXCHARTS;
    c.fill = GridBagConstraints.BOTH;
    content = new JPanel(gridBagLayout);
    qoSRuleList = new JList(allSessions.keySet().toArray());
    qoSRuleList.setPreferredSize(new java.awt.Dimension(200, 600));
    qoSRuleList.setBorder(BorderFactory.createRaisedBevelBorder());

    // set a MouseListner on the List
    MouseListener mouseListener = new MouseAdapter() {
        public void mouseClicked(MouseEvent e) {

            if (e.getButton() == MouseEvent.BUTTON1) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                addStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
            if (e.getButton() == MouseEvent.BUTTON3) {
                int index = qoSRuleList.locationToIndex(e.getPoint());
                removeStream(allSessions.get(allSessions.keySet().toArray()[index]));
            }
        }
    };
    qoSRuleList.addMouseListener(mouseListener);

    // place all parts at the content pane
    gridBagLayout.setConstraints(qoSRuleList, c);
    content.add(qoSRuleList);
    setContentPane(content);
    content.setSize(1000, 800);

    //create all GUI aspects for our Charts
    insertAllCharts();

    //Start the thread that fills up our time series
    periodicBandwidthReader = new Thread(bandwidthGenerator);
    periodicBandwidthReader.setName("data-collector");
    periodicBandwidthReader.start();
}

From source file:com.polivoto.vistas.AnalistaLocal.java

private void setPreguntasText() {
    JSONArray js = accionesConsultor.getPreguntas();
    for (int i = 0; i < js.length(); i++) {
        try {//w w  w  . j a v  a 2s.c  om
            JPanel panel = new JPanel(new GridBagLayout());
            panel.setBackground(new Color(255, 255, 255));
            panelPreguntas.add(panel, "Pregunta " + (i + 1));
            JLabel lab1 = new JLabel(
                    "Pregunta " + (i + 1) + ": " + ((JSONObject) js.get(i)).getString("pregunta"),
                    JLabel.CENTER);
            lab1.setFont(new Font("Roboto", 1, 18));
            lab1.setForeground(new Color(134, 36, 31));
            GridBagConstraints gridBagConstraints = new java.awt.GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = 0;
            gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 0.1;
            gridBagConstraints.weighty = 0.2;
            gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
            panel.add(lab1, gridBagConstraints);
            JSONArray jarr = ((JSONObject) js.get(i)).getJSONArray("opciones");
            for (int j = 0; j < jarr.length(); j++) {
                JLabel lab2 = new JLabel("Opcin " + (j + 1) + ": " + jarr.getString(j), JLabel.CENTER);
                lab2.setFont(new Font("Roboto", 1, 15));
                lab2.setForeground(new Color(0, 0, 0));
                gridBagConstraints = new java.awt.GridBagConstraints();
                gridBagConstraints.gridx = 0;
                gridBagConstraints.gridy = j + 1;
                gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
                gridBagConstraints.weightx = 0.1;
                gridBagConstraints.weighty = 0.1;
                gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
                panel.add(lab2, gridBagConstraints);
            }

            JPanel panelRelleno = new JPanel(new BorderLayout(20, 20));
            panelRelleno.setBackground(Color.white);
            gridBagConstraints = new GridBagConstraints();
            gridBagConstraints.gridx = 0;
            gridBagConstraints.gridy = jarr.length() + 1;
            gridBagConstraints.fill = GridBagConstraints.BOTH;
            gridBagConstraints.weightx = 0.1;
            gridBagConstraints.weighty = 0.9;
            gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 5);
            panel.add(panelRelleno, gridBagConstraints);
        } catch (JSONException ex) {
            Logger.getLogger(AnalistaLocal.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
    cardsPreguntas.show(panelPreguntas, "Pregunta " + 1);
}

From source file:com.googlecode.vfsjfilechooser2.accessories.connection.ConnectionDialog.java

private void initCenterPanelComponents() {
    // create the panel
    this.centerPanel = new JPanel(new GridBagLayout());
    this.centerPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    // create the components
    this.hostnameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.hostnameLabelText"));
    this.hostnameLabel.setForeground(Color.RED);
    this.hostnameTextField = new JTextField(25);

    this.portLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.portLabelText"));
    this.portTextField = new JFormattedTextField(NumberFormat.getInstance());
    this.isPortTextFieldDirty = false;

    this.protocolLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.protocolLabelText"));
    this.protocolModel = new DefaultComboBoxModel(Protocol.values());
    this.protocolList = new JComboBox(protocolModel);
    this.protocolList.setRenderer(new ProtocolRenderer());

    this.usernameLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.usernameLabelText"));
    this.usernameTextField = new JTextField(20);

    this.passwordLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.passwordLabelText"));
    this.passwordTextField = new JPasswordField(12);

    this.defaultRemotePathLabel = new JLabel(VFSResources.getMessage("VFSJFileChooser.pathLabelText"));
    this.defaultRemotePathTextField = new JTextField(20);

    // Add the components to the panel
    makeGridPanel(new Component[] { hostnameLabel, hostnameTextField, portLabel, portTextField, protocolLabel,
            protocolList, usernameLabel, usernameTextField, passwordLabel, passwordTextField,
            defaultRemotePathLabel, defaultRemotePathTextField });
}

From source file:org.peerfact.impl.service.aggregation.skyeye.visualization.SkyNetVisualization.java

private SkyNetVisualization() {
    super("Metric-Visualization");
    createLookAndFeel();/*ww w .ja  va2 s .  c  o m*/
    displayedMetrics = new LinkedHashMap<String, MetricsPlot>();
    setLayout(new GridLayout(1, 1));
    addWindowListener(this);
    graphix = new JPanel(new GridBagLayout());
    graphix.setLayout(new BoxLayout(graphix, BoxLayout.PAGE_AXIS));
    mb = new JMenuBar();
    JScrollPane scroller = new JScrollPane(graphix, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    // calculating the size of the application-window as well as of all
    // components, that depend on the size of the window
    Toolkit kit = Toolkit.getDefaultToolkit();
    int appWidth = kit.getScreenSize().width * 3 / 4;
    int appHeight = kit.getScreenSize().height * 3 / 4;
    scroller.setPreferredSize(new Dimension(appWidth, appHeight));
    getContentPane().add(scroller);
    maxPlotsPerRow = 1;
    while ((maxPlotsPerRow + 1) * PLOT_WIDTH < appWidth) {
        maxPlotsPerRow++;
    }
    log.warn("Creating the visualization...");
    mb.add(new JMenu("File"));
    JMenu met = new JMenu("Available Metrics");
    met.setEnabled(false);
    mb.add(met);
    setJMenuBar(mb);
}

From source file:com.att.aro.ui.view.videotab.VideoTab.java

/**
 * Create the panel./*from w  ww . j ava2  s .  co  m*/
 */
public VideoTab(MainFrame aroView, IARODiagnosticsOverviewRoute overviewRoute) {
    super();
    this.aroView = aroView;
    this.overviewRoute = overviewRoute;

    bpObservable = new AROModelObserver();

    container = new JPanel(new BorderLayout());

    String headerTitle = MessageFormat.format(ResourceBundleHelper.getMessageString("videoTab.title"),
            ApplicationConfig.getInstance().getAppBrandName(),
            ApplicationConfig.getInstance().getAppShortName());

    container.add(UIComponent.getInstance().getLogoHeader(headerTitle), BorderLayout.NORTH);

    // Summaries, Manifest, Requests
    ImagePanel panel = new ImagePanel(null);
    panel.setLayout(new GridBagLayout());
    panel.add(layoutDataPanel(), new GridBagConstraints(0, 0, 1, 1, 1.0, 0.0, GridBagConstraints.WEST,
            GridBagConstraints.HORIZONTAL, new Insets(10, 10, 0, 10), 0, 0));
    container.add(panel, BorderLayout.CENTER);

    setViewportView(container);
    getVerticalScrollBar().setUnitIncrement(10);
    getHorizontalScrollBar().setUnitIncrement(10);
}

From source file:biomine.bmvis2.pipeline.BestPathHiderOperation.java

public JComponent getSettingsComponent(final SettingsChangeCallback settingsChangeCallback,
        final VisualGraph graph) {
    long nodeCount = graph.getAllNodes().size();

    if (oldCount != 0) {
        long newTarget = (target * nodeCount) / oldCount;
        this.target = Math.max(newTarget, target);
    } else//from   w  ww. j a v  a 2 s  .  co m
        this.target = nodeCount;

    this.oldCount = nodeCount;

    JPanel ret = new JPanel();

    // if int overflows, we're fucked
    final JSlider sl = new JSlider(0, (int) nodeCount, (int) Math.min(target, nodeCount));
    sl.addChangeListener(new ChangeListener() {
        public void stateChanged(ChangeEvent arg0) {
            if (target == sl.getValue())
                return;
            target = sl.getValue();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.setLayout(new GridBagLayout());
    GridBagConstraints c = new GridBagConstraints();
    c.weightx = 1;
    c.weighty = 0;
    c.fill = GridBagConstraints.HORIZONTAL;
    c.gridx = 0;
    c.gridy = 0;
    //c.gridwidth=2;

    ret.add(sl, c);
    c.gridy++;

    int choices = graph.getNodesOfInterest().size() + 1;

    Object[] items = new Object[choices];
    items[0] = "All PoIs";

    for (int i = 1; i < choices; i++) {
        items[i] = i + " nearest";
    }
    final JComboBox pathTypeBox = new JComboBox(items);
    pathTypeBox.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent arg0) {
            int i = pathTypeBox.getSelectedIndex();
            grader.setPathK(i);
            settingsChangeCallback.settingsChanged(false);
        }
    });

    ret.add(new JLabel("hide by best path quality to:"), c);
    c.gridy++;
    ret.add(pathTypeBox, c);
    c.gridy++;

    System.out.println("new confpane nodeCount = " + nodeCount);

    final JCheckBox useMatchingColoring = new JCheckBox();
    ret.add(useMatchingColoring, c);

    useMatchingColoring.setAction(new AbstractAction("Use matching coloring") {
        public void actionPerformed(ActionEvent arg0) {
            matchColoring = useMatchingColoring.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    useMatchingColoring.setAlignmentX(JComponent.CENTER_ALIGNMENT);

    c.gridy++;

    final JCheckBox labelsBox = new JCheckBox();
    ret.add(labelsBox, c);

    labelsBox.setAction(new AbstractAction("Show goodness in node labels") {
        public void actionPerformed(ActionEvent arg0) {
            showLabel = labelsBox.isSelected();
            settingsChangeCallback.settingsChanged(false);
        }
    });

    return ret;
}