Example usage for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

List of usage examples for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION

Introduction

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

Prototype

int MULTIPLE_INTERVAL_SELECTION

To view the source code for javax.swing ListSelectionModel MULTIPLE_INTERVAL_SELECTION.

Click Source Link

Document

A value for the selectionMode property: select one or more contiguous ranges of indices at a time.

Usage

From source file:de.whiledo.iliasdownloader2.swing.service.MainController.java

public JTableX<FileObject> generateFileObjectTable(final FileObjectTableModel tableModel) {
    val table = new JTableX<FileObject>();
    table.addMouseListener(new MouseAdapter() {

        @Override/*  w  ww  .  ja v a 2 s  .  co m*/
        public void mouseClicked(MouseEvent e) {
            fileTableClicked(tableModel, table, e);
        }
    });
    table.setRowSelectionAllowed(true);
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);

    table.setModelAndRenderer(tableModel);
    table.getColumnModel().getColumn(0).setMaxWidth(250);
    table.getColumnModel().getColumn(0).setPreferredWidth(150);
    table.getColumnModel().getColumn(3).setPreferredWidth(150);
    table.getColumnModel().getColumn(3).setMaxWidth(250);
    table.getColumnModel().getColumn(4).setMaxWidth(150);
    table.getColumnModel().getColumn(5).setMaxWidth(150);

    return table;
}

From source file:org.fhcrc.cpl.viewer.gui.ProteinMatcherFrame.java

/**
 * initial setup of UI and class variables
 *//*from w  w  w .j a v  a2 s.  c o m*/
public void initialize() {
    _ms1Features = getMS1Features();
    if (_ms1Features == null) {
        ApplicationContext.infoMessage(TextProvider.getText("AMT_REQUIRES_DISPLAYED_FEATURES"));
        this.setVisible(false);
        this.dispose();
        return;
    }
    this.setVisible(true);

    //graphical stuff
    try {
        JMenuBar jmenu = (JMenuBar) Localizer.getSwingEngine(this)
                .render("org/fhcrc/cpl/viewer/gui/ProteinMatcherMenu.xml");
        for (int i = 0; i < jmenu.getMenuCount(); i++)
            jmenu.getMenu(i).getPopupMenu().setLightWeightPopupEnabled(false);
        this.setJMenuBar(jmenu);
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_LOADING_MENUS"), x);
        throw new RuntimeException(x);
    }

    Container contentPanel;
    try {
        contentPanel = Localizer.renderSwixml("org/fhcrc/cpl/viewer/gui/ProteinMatcherFrame.xml", this);
        setContentPane(contentPanel);
        pack();
    } catch (Exception x) {
        ApplicationContext.errorMessage(TextProvider.getText("ERROR_CREATING_DIALOG"), x);
        throw new RuntimeException(x);
    }

    Dimension d = contentPanel.getPreferredSize();
    setBounds(600, 100, (int) d.getWidth(), (int) d.getHeight());

    ListenerHelper helper = new ListenerHelper(this);
    helper.addListener(tblProteins.getSelectionModel(), "tblProteinsModel_valueChanged");
    helper.addListener(buttonFilterProteins, "buttonFilterProteins_actionPerformed");
    //hitting enter in the text field should act the same as hitting the filter button.  Hack, focus, whatever
    helper.addListener(textProteinPrefix, "buttonFilterProteins_actionPerformed");
    helper.addListener(tblFeatures.getSelectionModel(), "tblFeaturesModel_valueChanged");

    _proteinTableModel = new ProteinTableModel();
    tblProteins.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    tblProteins.setAutoCreateColumnsFromModel(false);
    tblProteins.setModel(_proteinTableModel);
    tblProteins.setColumnModel(_proteinTableModel.columnModel);

    if (null != displayMatchedUnmatchedComboBox) {
        //TODO: should really use TextProvider here, and use an internal value for determining state
        displayMatchedUnmatchedComboBox.addItem("matched");
        displayMatchedUnmatchedComboBox.addItem("unmatched peptides");
        displayMatchedUnmatchedComboBox.addItem("unmatched ms2");
        helper.addListener(displayMatchedUnmatchedComboBox, "displayMatchedUnmatchedComboBox_actionPerformed");
    }

    _featureTableModel = new FeatureTableModel();
    tblFeatures.setModel(_featureTableModel);

    tblFeatures.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    tblFeatures.setAutoCreateColumnsFromModel(false);

    ProteinTablePopupMenu proteinPopup = new ProteinTablePopupMenu();

    tblProteins.setComponentPopupMenu(proteinPopup);
    proteinLabel.setComponentPopupMenu(proteinPopup);
}

From source file:forge.itemmanager.views.ItemListView.java

@Override
public void setAllowMultipleSelections(final boolean allowMultipleSelections) {
    this.table.setSelectionMode(allowMultipleSelections ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
            : ListSelectionModel.SINGLE_SELECTION);
}

From source file:de.mprengemann.intellij.plugin.androidicons.dialogs.AndroidBatchScaleImporter.java

private void initRowSelection() {
    table.getColumnModel().setColumnSelectionAllowed(false);
    table.getSelectionModel().setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override/*  w  ww .  j av a  2s.  com*/
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            int selectedRow = table.getSelectedRow();
            if (table.getSelectedRowCount() == 1) {
                updateImage(controller.getImage(selectedRow));
            } else {
                updateImage(null);
            }
        }
    });
}

From source file:com.github.fritaly.dualcommander.DirectoryBrowser.java

public DirectoryBrowser(UserPreferences preferences, File directory) {
    Validate.notNull(preferences, "The given user preferences are null");
    Validate.notNull(directory, "The given directory is null");
    Validate.isTrue(directory.exists(),/* w  w w. j av  a2 s. c  om*/
            String.format("The given directory '%s' doesn't exist", directory.getAbsolutePath()));
    Validate.isTrue(directory.isDirectory(),
            String.format("The given path '%s' doesn't denote a directory", directory.getAbsolutePath()));

    this.preferences = preferences;

    // Layout, columns & rows
    setLayout(new MigLayout("insets 0px", "[grow]", "[]1[grow]1[]"));

    this.tableModel = new FileTableModel(this);

    this.table = new JTable(tableModel);
    this.table.setBackground(Utils.getDefaultBackgroundColor());
    this.table.addKeyListener(this);
    this.table.addMouseListener(this);
    this.table.addFocusListener(this);
    this.table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    this.table.getSelectionModel().addListSelectionListener(this);

    // Listen to column event resize events
    final ColumnEventHelper eventHelper = new ColumnEventHelper(this);

    this.table.getColumnModel().addColumnModelListener(eventHelper);
    this.table.getTableHeader().addMouseListener(eventHelper);

    // Render the table headers with a bold font
    this.table.getTableHeader().setFont(Utils.getBoldFont(this.table.getTableHeader().getFont()));
    this.table.getTableHeader().setBackground(Utils.getDefaultBackgroundColor());
    this.table.getTableHeader().setDefaultRenderer(new TableHeaderRenderer());
    this.table.getTableHeader().addMouseListener(this);

    final TableColumn typeColumn = this.table.getColumn(FileTableModel.COLUMN_TYPE);
    typeColumn.setCellRenderer(new FileTypeRenderer());
    typeColumn.setResizable(false);
    typeColumn.setHeaderValue("");
    typeColumn.setMaxWidth(Icons.FOLDER_ICON.getIconWidth() + 5);

    final TableColumn fileColumn = this.table.getColumn(FileTableModel.COLUMN_NAME);
    fileColumn.setCellRenderer(new FileNameRenderer());
    fileColumn.setResizable(true);

    final TableColumn sizeColumn = this.table.getColumn(FileTableModel.COLUMN_SIZE);
    sizeColumn.setCellRenderer(new FileSizeRenderer());
    sizeColumn.setResizable(true);

    // Dynamically set the column to the correct size
    final TableColumn lastUpdateColumn = this.table.getColumn(FileTableModel.COLUMN_LAST_UPDATE);
    lastUpdateColumn.setCellRenderer(new LastUpdateRenderer());
    lastUpdateColumn.setResizable(false);
    lastUpdateColumn.setMaxWidth(Utils.getTimestampRenderWidth() + 5);
    lastUpdateColumn.setMinWidth(Utils.getTimestampRenderWidth() + 5);

    // Use a square border (not one with rounded corners)
    this.directoryButton.setBorder(Utils.createRaisedBevelBorder());
    this.directoryButton.setFont(Utils.getDefaultFont());
    this.directoryButton.setFocusable(false);
    this.directoryButton.setHorizontalAlignment(SwingConstants.LEFT);

    this.summary = new JLabel(" ");
    this.summary.setBorder(Utils.createRaisedBevelBorder());

    add(directoryButton, "grow, wrap");
    add(new JScrollPane(table), "grow, wrap");
    add(summary, "grow");

    // Set the directory (this will populate the table)
    setDirectory(directory);
}

From source file:de.codesourcery.eve.skills.ui.components.impl.MarketPriceEditorComponent.java

@Override
protected JPanel createPanel() {

    // add search textfield
    final JPanel inputPanel = new JPanel();
    inputPanel.setBorder(lineBorder(Color.black));
    inputPanel.setLayout(new GridBagLayout());

    inputPanel.add(itemNameFilter.getPanel(), constraints(0, 0).anchorWest().noResizing().end());

    importMarketLogButton.addActionListener(new ActionListener() {

        @Override//from ww w .j a v a2  s  .  c  om
        public void actionPerformed(ActionEvent e) {
            importMarketLogs();
        }

    });

    inputPanel.add(importMarketLogButton, constraints(0, 1).anchorWest().noResizing().end());

    // add item description text area
    selectedItemDescription.setEditable(false);
    selectedItemDescription.setWrapStyleWord(true);
    selectedItemDescription.setLineWrap(true);

    final JScrollPane selectedItemDescPanel = new JScrollPane(selectedItemDescription);
    selectedItemDescPanel.setBorder(BorderFactory.createTitledBorder("Selected item"));

    // setup table
    tableModel.setViewFilter(this.itemNameFilter.getViewFilter());
    table.setModel(tableModel);
    table.setRowSorter(tableModel.getRowSorter());
    table.setDefaultRenderer(String.class, new StalePriceInfoHighlighter());
    table.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {

            if (!e.getValueIsAdjusting()) {
                final int viewRow = table.getSelectedRow();
                if (viewRow != -1) {
                    final int modelRow = table.convertRowIndexToModel(viewRow);
                    updateItemDescriptionDisplay(modelRow);
                }
            }
        }

    });

    table.setFillsViewportHeight(true);
    table.addMouseListener(popupListener);

    table.setFillsViewportHeight(true);

    // setup split pane
    final JPanel result = new JPanel();

    final JPanel topPanel = new JPanel();

    new GridLayoutBuilder().add(new GridLayoutBuilder.HorizontalGroup(new GridLayoutBuilder.Cell(inputPanel),
            new GridLayoutBuilder.Cell(selectedItemDescPanel))).addTo(topPanel);

    final JSplitPane pane = new ImprovedSplitPane(JSplitPane.VERTICAL_SPLIT, topPanel, tablePane);

    pane.setDividerLocation(0.3d); // only works because of the splitpane
    // hack
    pane.setContinuousLayout(true);

    result.setLayout(new GridBagLayout());
    result.add(pane, constraints().resizeBoth().useRemainingSpace().end());

    return result;
}

From source file:edu.ku.brc.ui.ChooseFromListDlg.java

/**
 * Create the UI for the dialog./*  ww w.ja v  a2 s  .  co m*/
 * 
 * @param altName title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn  indicates whether to create and display a cancel btn
 * @param includeHelpBtn indicates whether to create and display a help btn
 * @param helpContext help context identifier
 * @param titleArg title for dialog
 * @param desc the list to be selected from
 * @param includeCancelBtn indicates whether to create and display a cancel btn
 */
public void createUI() {
    setTitle(title);

    boolean hasDesc = StringUtils.isNotEmpty(desc);
    PanelBuilder builder = new PanelBuilder(
            new FormLayout("f:max(300px;p):g", "p," + (hasDesc ? "2px,p," : "") + "5px,p"));
    CellConstraints cc = new CellConstraints();
    //builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 10));
    builder.setDefaultDialogBorder();

    int y = 1;
    if (hasDesc) {
        JLabel lbl = createLabel(desc, SwingConstants.CENTER);
        builder.add(lbl, cc.xy(1, y));
        y += 2;
    }

    try {
        ListModel listModel = new AbstractListModel() {
            public int getSize() {
                return items.size();
            }

            public Object getElementAt(int index) {
                return items.get(index).toString();
            }
        };

        list = new JList(listModel);
        if (icon != null) {
            list.setCellRenderer(getListCellRenderer()); // icon comes from the base
            // class (it's probably size
            // 16)
        }
        list.setSelectionMode(isMultiSelect ? ListSelectionModel.MULTIPLE_INTERVAL_SELECTION
                : ListSelectionModel.SINGLE_SELECTION);
        list.setVisibleRowCount(10);

        if (selectedIndices != null) {
            list.setSelectedIndices(selectedIndices);
        }

        list.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getClickCount() == 2) {
                    okBtn.doClick(); // emulate button click
                }
            }
        });
        list.addListSelectionListener(new ListSelectionListener() {
            public void valueChanged(ListSelectionEvent e) {
                if (!e.getValueIsAdjusting()) {
                    updateUIState();
                }
            }
        });
        JScrollPane listScroller = new JScrollPane(list);
        builder.add(listScroller, cc.xy(1, y));
        y += 2;

        // Bottom Button UI
        okBtn = createButton(StringUtils.isNotEmpty(okLabel) ? okLabel : getResourceString("OK"));
        okBtn.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                isCancelled = false;
                btnPressed = OK_BTN;
                setVisible(false);
            }
        });
        getRootPane().setDefaultButton(okBtn);

        if ((whichBtns & CANCEL_BTN) == CANCEL_BTN) {
            cancelBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("CANCEL"));
            cancelBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    isCancelled = true;
                    btnPressed = CANCEL_BTN;
                    setVisible(false);
                }
            });
        }

        if ((whichBtns & HELP_BTN) == HELP_BTN) {
            helpBtn = createButton(
                    StringUtils.isNotEmpty(cancelLabel) ? cancelLabel : getResourceString("HELP"));
            if (StringUtils.isNotEmpty(helpContext)) {
                HelpMgr.registerComponent(helpBtn, helpContext);
            } else {
                helpBtn.addActionListener(new ActionListener() {
                    public void actionPerformed(ActionEvent ae) {
                        btnPressed = HELP_BTN;
                    }
                });
            }
        }

        if ((whichBtns & APPLY_BTN) == APPLY_BTN) {
            applyBtn = createButton(
                    StringUtils.isNotEmpty(applyLabel) ? applyLabel : getResourceString("Apply"));
            applyBtn.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent ae) {
                    btnPressed = APPLY_BTN;
                    if (isCloseOnApply) {
                        isCancelled = false;
                        setVisible(false);
                    }
                }
            });
        }

        JPanel bb;
        if (whichBtns == OK_BTN) {
            bb = ButtonBarFactory.buildOKBar(okBtn);

        } else if (whichBtns == OKCANCEL) {
            bb = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn);

        } else if (whichBtns == OKCANCELAPPLY) {
            bb = ButtonBarFactory.buildOKCancelApplyBar(okBtn, cancelBtn, applyBtn);

        } else if (whichBtns == OKHELP) {
            bb = ButtonBarFactory.buildOKHelpBar(okBtn, helpBtn);

        } else if (whichBtns == OKCANCELHELP) {
            bb = ButtonBarFactory.buildOKCancelHelpBar(okBtn, cancelBtn, helpBtn);

        } else if (whichBtns == OKCANCELAPPLYHELP) {
            bb = ButtonBarFactory.buildOKCancelApplyHelpBar(okBtn, cancelBtn, applyBtn, helpBtn);

        } else {
            bb = ButtonBarFactory.buildOKBar(okBtn);
        }

        builder.add(bb, cc.xy(1, y));
        y += 2;

        updateUIState();

    } catch (Exception ex) {
        edu.ku.brc.af.core.UsageTracker.incrHandledUsageCount();
        edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(ChooseFromListDlg.class, ex);
        log.error(ex);
    }

    setContentPane(builder.getPanel());
    pack();
    // setLocationRelativeTo(locationComp);
}

From source file:com.mirth.connect.client.ui.DashboardPanel.java

/**
 * Makes the status table with all current server information.
 */// w  ww  .j av a  2s. c  o  m
public void makeStatusTable() {
    List<String> columns = new ArrayList<String>();

    for (DashboardColumnPlugin plugin : LoadedExtensions.getInstance().getDashboardColumnPlugins().values()) {
        if (plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    columns.addAll(Arrays.asList(defaultColumns));

    for (DashboardColumnPlugin plugin : LoadedExtensions.getInstance().getDashboardColumnPlugins().values()) {
        if (!plugin.isDisplayFirst()) {
            columns.add(plugin.getColumnHeader());
        }
    }

    DashboardTreeTableModel model = new DashboardTreeTableModel();
    model.setColumnIdentifiers(columns);
    model.setNodeFactory(new DefaultDashboardTableNodeFactory());

    for (DashboardTablePlugin plugin : LoadedExtensions.getInstance().getDashboardTablePlugins().values()) {
        dashboardTable = plugin.getTable();

        if (dashboardTable != null) {
            break;
        }
    }

    defaultVisibleColumns.addAll(columns);

    if (dashboardTable == null) {
        dashboardTable = new MirthTreeTable("dashboardPanel", defaultVisibleColumns);
    }

    dashboardTable.setColumnFactory(new DashboardTableColumnFactory());
    dashboardTable.setTreeTableModel(model);
    dashboardTable.setDoubleBuffered(true);
    dashboardTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    dashboardTable.setHorizontalScrollEnabled(true);
    dashboardTable.packTable(UIConstants.COL_MARGIN);
    dashboardTable.setRowHeight(UIConstants.ROW_HEIGHT);
    dashboardTable.setOpaque(true);
    dashboardTable.setRowSelectionAllowed(true);
    dashboardTable.setSortable(true);
    dashboardTable.putClientProperty("JTree.lineStyle", "Horizontal");
    dashboardTable.setAutoCreateColumnsFromModel(false);
    dashboardTable.setShowGrid(true, true);
    dashboardTable.restoreColumnPreferences();
    dashboardTable.setMirthColumnControlEnabled(true);

    dashboardTable.setTreeCellRenderer(new DefaultTreeCellRenderer() {
        @Override
        public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded,
                boolean leaf, int row, boolean hasFocus) {
            JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row,
                    hasFocus);

            TreePath path = dashboardTable.getPathForRow(row);
            if (path != null) {
                AbstractDashboardTableNode node = ((AbstractDashboardTableNode) path.getLastPathComponent());
                if (node.isGroupNode()) {
                    setIcon(UIConstants.ICON_GROUP);
                } else {
                    DashboardStatus status = node.getDashboardStatus();
                    if (status.getStatusType() == StatusType.CHANNEL) {
                        setIcon(UIConstants.ICON_CHANNEL);
                    } else {
                        setIcon(UIConstants.ICON_CONNECTOR);
                    }
                }
            }

            return label;
        }
    });
    dashboardTable.setLeafIcon(UIConstants.ICON_CONNECTOR);
    dashboardTable.setOpenIcon(UIConstants.ICON_CHANNEL);
    dashboardTable.setClosedIcon(UIConstants.ICON_CHANNEL);

    dashboardTableScrollPane.setViewportView(dashboardTable);

    dashboardTable.addMouseListener(new MouseAdapter() {
        @Override
        public void mousePressed(MouseEvent event) {
            checkSelectionAndPopupMenu(event);
        }

        @Override
        public void mouseReleased(MouseEvent event) {
            checkSelectionAndPopupMenu(event);
        }

        @Override
        public void mouseClicked(MouseEvent event) {
            int clickedRow = dashboardTable.rowAtPoint(new Point(event.getX(), event.getY()));
            if (clickedRow == -1) {
                return;
            }

            TreePath path = dashboardTable.getPathForRow(clickedRow);
            if (path != null && ((AbstractDashboardTableNode) path.getLastPathComponent()).isGroupNode()) {
                return;
            }

            if (event.getClickCount() >= 2 && dashboardTable.getSelectedRowCount() == 1
                    && dashboardTable.getSelectedRow() == clickedRow) {
                parent.doShowMessages();
            }
        }
    });

    dashboardTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent event) {
            /*
             * MIRTH-3199: Only update the panel plugin if the selection is finished. This does
             * mean that the logs aren't updated live when adding to or removing from a
             * currently adjusting selection, but it's much more efficient when it comes to the
             * number of requests being done from the client. Plus, it actually will still
             * update while a selection is adjusting if the refresh interval on the dashboard
             * elapses. We can change this so that plugins are updated during a selection
             * adjustment, but it would first require a major rewrite of the connection log /
             * status column plugin.
             */
            updatePopupMenu(!event.getValueIsAdjusting());
        }
    });
}

From source file:com.vgi.mafscaling.MafCompare.java

/**
 * Initialize the contents of the frame.
 *///from   ww  w  .j  a  v  a 2  s  .c  o m
private void initialize() {
    try {
        ImageIcon tableImage = new ImageIcon(getClass().getResource("/table.jpg"));
        setTitle(Title);
        setIconImage(tableImage.getImage());
        setBounds(100, 100, 621, 372);
        setDefaultCloseOperation(JFrame.HIDE_ON_CLOSE);
        setSize(Config.getCompWindowSize());
        setLocation(Config.getCompWindowLocation());
        setLocationRelativeTo(null);
        setVisible(false);
        addWindowListener(new WindowAdapter() {
            public void windowClosing(WindowEvent e) {
                Utils.clearTable(origMafTable);
                Utils.clearTable(newMafTable);
                Utils.clearTable(compMafTable);
                Config.setCompWindowSize(getSize());
                Config.setCompWindowLocation(getLocation());
                origMafData.clear();
                newMafData.clear();
            }
        });

        JPanel dataPanel = new JPanel();
        GridBagLayout gbl_dataPanel = new GridBagLayout();
        gbl_dataPanel.columnWidths = new int[] { 0, 0, 0 };
        gbl_dataPanel.rowHeights = new int[] { RowHeight, RowHeight, RowHeight, RowHeight, RowHeight, 0 };
        gbl_dataPanel.columnWeights = new double[] { 0.0, 0.0, 0.0 };
        gbl_dataPanel.rowWeights = new double[] { 0.0, 0.0, 0.0, 0.0, 0.0, 1.0 };
        dataPanel.setLayout(gbl_dataPanel);
        getContentPane().add(dataPanel);

        JLabel origLabel = new JLabel(origMaf);
        GridBagConstraints gbc_origLabel = new GridBagConstraints();
        gbc_origLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origLabel.weightx = 0;
        gbc_origLabel.weighty = 0;
        gbc_origLabel.gridx = 0;
        gbc_origLabel.gridy = 0;
        gbc_origLabel.gridheight = 2;
        dataPanel.add(origLabel, gbc_origLabel);

        JLabel newLabel = new JLabel(newMaf);
        GridBagConstraints gbc_newLabel = new GridBagConstraints();
        gbc_newLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newLabel.weightx = 0;
        gbc_newLabel.weighty = 0;
        gbc_newLabel.gridx = 0;
        gbc_newLabel.gridy = 2;
        gbc_newLabel.gridheight = 2;
        dataPanel.add(newLabel, gbc_newLabel);

        JLabel compLabel = new JLabel("Change");
        GridBagConstraints gbc_compLabel = new GridBagConstraints();
        gbc_compLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compLabel.weightx = 0;
        gbc_compLabel.weighty = 0;
        gbc_compLabel.gridx = 0;
        gbc_compLabel.gridy = 4;
        dataPanel.add(compLabel, gbc_compLabel);

        JLabel origVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_origVoltLabel = new GridBagConstraints();
        gbc_origVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origVoltLabel.weightx = 0;
        gbc_origVoltLabel.weighty = 0;
        gbc_origVoltLabel.gridx = 1;
        gbc_origVoltLabel.gridy = 0;
        dataPanel.add(origVoltLabel, gbc_origVoltLabel);

        JLabel origGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_origGsLabel = new GridBagConstraints();
        gbc_origGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_origGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_origGsLabel.weightx = 0;
        gbc_origGsLabel.weighty = 0;
        gbc_origGsLabel.gridx = 1;
        gbc_origGsLabel.gridy = 1;
        dataPanel.add(origGsLabel, gbc_origGsLabel);

        JLabel newVoltLabel = new JLabel("volt");
        GridBagConstraints gbc_newVoltLabel = new GridBagConstraints();
        gbc_newVoltLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newVoltLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newVoltLabel.weightx = 0;
        gbc_newVoltLabel.weighty = 0;
        gbc_newVoltLabel.gridx = 1;
        gbc_newVoltLabel.gridy = 2;
        dataPanel.add(newVoltLabel, gbc_newVoltLabel);

        JLabel newGsLabel = new JLabel(" g/s");
        GridBagConstraints gbc_newGsLabel = new GridBagConstraints();
        gbc_newGsLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_newGsLabel.insets = new Insets(1, 1, 1, 5);
        gbc_newGsLabel.weightx = 0;
        gbc_newGsLabel.weighty = 0;
        gbc_newGsLabel.gridx = 1;
        gbc_newGsLabel.gridy = 3;
        dataPanel.add(newGsLabel, gbc_newGsLabel);

        JLabel compPctLabel = new JLabel(" %  ");
        GridBagConstraints gbc_compPctLabel = new GridBagConstraints();
        gbc_compPctLabel.anchor = GridBagConstraints.PAGE_START;
        gbc_compPctLabel.insets = new Insets(1, 1, 1, 5);
        gbc_compPctLabel.weightx = 0;
        gbc_compPctLabel.weighty = 0;
        gbc_compPctLabel.gridx = 1;
        gbc_compPctLabel.gridy = 4;
        dataPanel.add(compPctLabel, gbc_compPctLabel);

        JPanel tablesPanel = new JPanel();
        GridBagLayout gbl_tablesPanel = new GridBagLayout();
        gbl_tablesPanel.columnWidths = new int[] { 0 };
        gbl_tablesPanel.rowHeights = new int[] { 0, 0, 0 };
        gbl_tablesPanel.columnWeights = new double[] { 0.0 };
        gbl_tablesPanel.rowWeights = new double[] { 0.0, 0.0, 1.0 };
        tablesPanel.setLayout(gbl_tablesPanel);

        JScrollPane mafScrollPane = new JScrollPane(tablesPanel);
        mafScrollPane.setMinimumSize(new Dimension(1600, 107));
        mafScrollPane.getHorizontalScrollBar().setMaximumSize(new Dimension(20, 20));
        mafScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER);
        mafScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);
        GridBagConstraints gbc_mafScrollPane = new GridBagConstraints();
        gbc_mafScrollPane.weightx = 1.0;
        gbc_mafScrollPane.anchor = GridBagConstraints.PAGE_START;
        gbc_mafScrollPane.fill = GridBagConstraints.HORIZONTAL;
        gbc_mafScrollPane.gridx = 2;
        gbc_mafScrollPane.gridy = 0;
        gbc_mafScrollPane.gridheight = 5;
        dataPanel.add(mafScrollPane, gbc_mafScrollPane);

        origMafTable = new JTable();
        origMafTable.setColumnSelectionAllowed(true);
        origMafTable.setCellSelectionEnabled(true);
        origMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        origMafTable.setRowHeight(RowHeight);
        origMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        origMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        origMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        origMafTable.setTableHeader(null);
        Utils.initializeTable(origMafTable, ColumnWidth);
        GridBagConstraints gbc_origMafTable = new GridBagConstraints();
        gbc_origMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_origMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_origMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_origMafTable.weightx = 1.0;
        gbc_origMafTable.weighty = 0;
        gbc_origMafTable.gridx = 0;
        gbc_origMafTable.gridy = 0;
        tablesPanel.add(origMafTable, gbc_origMafTable);
        excelAdapter.addTable(origMafTable, false, false, false, false, true, false, true, false, true);

        newMafTable = new JTable();
        newMafTable.setColumnSelectionAllowed(true);
        newMafTable.setCellSelectionEnabled(true);
        newMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        newMafTable.setRowHeight(RowHeight);
        newMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        newMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        newMafTable.setModel(new DefaultTableModel(2, MafTableColumnCount));
        newMafTable.setTableHeader(null);
        Utils.initializeTable(newMafTable, ColumnWidth);
        GridBagConstraints gbc_newMafTable = new GridBagConstraints();
        gbc_newMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_newMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_newMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_newMafTable.weightx = 1.0;
        gbc_newMafTable.weighty = 0;
        gbc_newMafTable.gridx = 0;
        gbc_newMafTable.gridy = 1;
        tablesPanel.add(newMafTable, gbc_newMafTable);
        excelAdapter.addTable(newMafTable, false, false, false, false, false, false, false, false, true);

        compMafTable = new JTable();
        compMafTable.setColumnSelectionAllowed(true);
        compMafTable.setCellSelectionEnabled(true);
        compMafTable.setBorder(new LineBorder(new Color(0, 0, 0)));
        compMafTable.setRowHeight(RowHeight);
        compMafTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
        compMafTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
        compMafTable.setModel(new DefaultTableModel(1, MafTableColumnCount));
        compMafTable.setTableHeader(null);
        Utils.initializeTable(compMafTable, ColumnWidth);
        NumberFormatRenderer numericRenderer = new NumberFormatRenderer();
        numericRenderer.setFormatter(new DecimalFormat("0.000"));
        compMafTable.setDefaultRenderer(Object.class, numericRenderer);
        GridBagConstraints gbc_compMafTable = new GridBagConstraints();
        gbc_compMafTable.anchor = GridBagConstraints.PAGE_START;
        gbc_compMafTable.insets = new Insets(0, 0, 0, 0);
        gbc_compMafTable.fill = GridBagConstraints.HORIZONTAL;
        gbc_compMafTable.weightx = 1.0;
        gbc_compMafTable.weighty = 0;
        gbc_compMafTable.gridx = 0;
        gbc_compMafTable.gridy = 2;
        tablesPanel.add(compMafTable, gbc_compMafTable);
        compExcelAdapter.addTable(compMafTable, false, true, false, false, false, true, true, false, true);

        TableModelListener origTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = origMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, newMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    origMafData.clear();
                    String origY, origX, newY;
                    for (int i = 0; i < colCount; ++i) {
                        origY = origMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, origY)) {
                            origX = origMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origX))
                                origMafData.add(Double.valueOf(origX), Double.valueOf(origY), false);
                            newY = newMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    origMafData.fireSeriesChanged();
                }
            }
        };

        TableModelListener newTableListener = new TableModelListener() {
            public void tableChanged(TableModelEvent tme) {
                if (tme.getType() == TableModelEvent.UPDATE) {
                    int colCount = newMafTable.getColumnCount();
                    Utils.ensureColumnCount(colCount, origMafTable);
                    Utils.ensureColumnCount(colCount, compMafTable);
                    newMafData.clear();
                    String newY, newX, origY;
                    for (int i = 0; i < colCount; ++i) {
                        newY = newMafTable.getValueAt(1, i).toString();
                        if (Pattern.matches(Utils.fpRegex, newY)) {
                            newX = newMafTable.getValueAt(0, i).toString();
                            if (Pattern.matches(Utils.fpRegex, newX))
                                newMafData.add(Double.valueOf(newX), Double.valueOf(newY), false);
                            origY = origMafTable.getValueAt(1, i).toString();
                            if (Pattern.matches(Utils.fpRegex, origY))
                                compMafTable.setValueAt(
                                        ((Double.valueOf(newY) / Double.valueOf(origY)) - 1.0) * 100.0, 0, i);
                        } else
                            break;
                    }
                    newMafData.fireSeriesChanged();
                }
            }
        };

        origMafTable.getModel().addTableModelListener(origTableListener);
        newMafTable.getModel().addTableModelListener(newTableListener);

        Action action = new AbstractAction() {
            private static final long serialVersionUID = 8148393537657380215L;

            public void actionPerformed(ActionEvent e) {
                TableCellListener tcl = (TableCellListener) e.getSource();
                if (Pattern.matches(Utils.fpRegex, compMafTable.getValueAt(0, tcl.getColumn()).toString())) {
                    if (Pattern.matches(Utils.fpRegex,
                            origMafTable.getValueAt(1, tcl.getColumn()).toString())) {
                        double corr = Double.valueOf(compMafTable.getValueAt(0, tcl.getColumn()).toString())
                                / 100.0 + 1.0;
                        newMafTable.setValueAt(
                                Double.valueOf(origMafTable.getValueAt(1, tcl.getColumn()).toString()) * corr,
                                1, tcl.getColumn());
                    }
                } else
                    compMafTable.setValueAt(tcl.getOldValue(), 0, tcl.getColumn());
            }
        };

        setCompMafCellListener(new TableCellListener(compMafTable, action));

        // CHART

        JFreeChart chart = ChartFactory.createXYLineChart(null, null, null, null, PlotOrientation.VERTICAL,
                false, true, false);
        chart.setBorderVisible(true);
        chartPanel = new ChartPanel(chart, true, true, true, true, true);
        chartPanel.setAutoscrolls(true);

        GridBagConstraints gbl_chartPanel = new GridBagConstraints();
        gbl_chartPanel.anchor = GridBagConstraints.PAGE_START;
        gbl_chartPanel.fill = GridBagConstraints.BOTH;
        gbl_chartPanel.insets = new Insets(1, 1, 1, 1);
        gbl_chartPanel.weightx = 1.0;
        gbl_chartPanel.weighty = 1.0;
        gbl_chartPanel.gridx = 0;
        gbl_chartPanel.gridy = 5;
        gbl_chartPanel.gridheight = 1;
        gbl_chartPanel.gridwidth = 3;
        dataPanel.add(chartPanel, gbl_chartPanel);

        XYSplineRenderer lineRenderer = new XYSplineRenderer(3);
        lineRenderer.setUseFillPaint(true);
        lineRenderer.setBaseToolTipGenerator(
                new StandardXYToolTipGenerator(StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT,
                        new DecimalFormat("0.00"), new DecimalFormat("0.00")));

        Stroke stroke = new BasicStroke(2.0f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1.0f, null, 0.0f);
        lineRenderer.setSeriesStroke(0, stroke);
        lineRenderer.setSeriesStroke(1, stroke);
        lineRenderer.setSeriesPaint(0, new Color(201, 0, 0));
        lineRenderer.setSeriesPaint(1, new Color(0, 0, 255));
        lineRenderer.setSeriesShape(0, ShapeUtilities.createDiamond((float) 2.5));
        lineRenderer.setSeriesShape(1, ShapeUtilities.createDownTriangle((float) 2.5));
        lineRenderer.setLegendItemLabelGenerator(new StandardXYSeriesLabelGenerator() {
            private static final long serialVersionUID = -4045338273187150888L;

            public String generateLabel(XYDataset dataset, int series) {
                XYSeries xys = ((XYSeriesCollection) dataset).getSeries(series);
                return xys.getDescription();
            }
        });

        NumberAxis mafvDomain = new NumberAxis(XAxisName);
        mafvDomain.setAutoRangeIncludesZero(false);
        mafvDomain.setAutoRange(true);
        mafvDomain.setAutoRangeStickyZero(false);
        NumberAxis mafgsRange = new NumberAxis(YAxisName);
        mafgsRange.setAutoRangeIncludesZero(false);
        mafgsRange.setAutoRange(true);
        mafgsRange.setAutoRangeStickyZero(false);

        XYSeriesCollection lineDataset = new XYSeriesCollection();
        origMafData.setDescription(origMaf);
        newMafData.setDescription(newMaf);
        lineDataset.addSeries(origMafData);
        lineDataset.addSeries(newMafData);

        XYPlot plot = chart.getXYPlot();
        plot.setRangePannable(true);
        plot.setDomainPannable(true);
        plot.setDomainGridlinePaint(Color.DARK_GRAY);
        plot.setRangeGridlinePaint(Color.DARK_GRAY);
        plot.setBackgroundPaint(new Color(224, 224, 224));

        plot.setDataset(0, lineDataset);
        plot.setRenderer(0, lineRenderer);
        plot.setDomainAxis(0, mafvDomain);
        plot.setRangeAxis(0, mafgsRange);
        plot.mapDatasetToDomainAxis(0, 0);
        plot.mapDatasetToRangeAxis(0, 0);

        LegendTitle legend = new LegendTitle(plot.getRenderer());
        legend.setItemFont(new Font("Arial", 0, 10));
        legend.setPosition(RectangleEdge.TOP);
        chart.addLegend(legend);

    } catch (Exception e) {
        logger.error(e);
    }
}

From source file:com.vgi.mafscaling.ClosedLoop.java

private JTable createAfrDataTable(JPanel panel, String tableName, int gridy) {
    final JTable afrTable = new JTable() {
        private static final long serialVersionUID = 6526901361175099297L;

        public boolean isCellEditable(int row, int column) {
            return false;
        };//from  ww w  .j ava  2s . c  om
    };
    DefaultTableColumnModel afrModel = new DefaultTableColumnModel();
    final TableColumn afrColumn = new TableColumn(0, 250);
    afrColumn.setHeaderValue(tableName);
    afrModel.addColumn(afrColumn);
    JTableHeader lblAfrTableName = afrTable.getTableHeader();
    lblAfrTableName.setColumnModel(afrModel);
    lblAfrTableName.setReorderingAllowed(false);
    DefaultTableCellRenderer headerRenderer = (DefaultTableCellRenderer) lblAfrTableName.getDefaultRenderer();
    headerRenderer.setHorizontalAlignment(SwingConstants.LEFT);

    GridBagConstraints gbc_lblAfrTableName = new GridBagConstraints();
    gbc_lblAfrTableName.insets = new Insets((gridy == 0 ? 0 : 5), 0, 0, 0);
    gbc_lblAfrTableName.anchor = GridBagConstraints.PAGE_START;
    gbc_lblAfrTableName.fill = GridBagConstraints.HORIZONTAL;
    gbc_lblAfrTableName.gridx = 0;
    gbc_lblAfrTableName.gridy = gridy;
    panel.add(lblAfrTableName, gbc_lblAfrTableName);

    afrTable.addComponentListener(new ComponentAdapter() {
        @Override
        public void componentResized(ComponentEvent e) {
            afrColumn.setWidth(afrTable.getWidth());
        }
    });
    afrTable.getTableHeader().setReorderingAllowed(false);
    afrTable.setColumnSelectionAllowed(true);
    afrTable.setCellSelectionEnabled(true);
    afrTable.setBorder(new LineBorder(new Color(0, 0, 0)));
    afrTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    afrTable.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
    afrTable.setModel(new DefaultTableModel(AfrTableRowCount, AfrTableColumnCount));
    Utils.initializeTable(afrTable, ColumnWidth);

    if (tableName.equals(Afr1TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    } else if (tableName.equals(Afr2TableName)) {
        Format[][] formatMatrix = { { new DecimalFormat("#"), new DecimalFormat("0.00") },
                { new DecimalFormat("#"), new DecimalFormat("#") } };
        NumberFormatRenderer renderer = (NumberFormatRenderer) afrTable.getDefaultRenderer(Object.class);
        renderer.setFormats(formatMatrix);
    }

    GridBagConstraints gbc_afrTable = new GridBagConstraints();
    gbc_afrTable.insets = new Insets(0, 0, 0, 0);
    gbc_afrTable.anchor = GridBagConstraints.PAGE_START;
    gbc_afrTable.gridx = 0;
    gbc_afrTable.gridy = gridy + 1;
    panel.add(afrTable, gbc_afrTable);

    excelAdapter.addTable(afrTable, true, false);

    return afrTable;
}