Example usage for javax.swing.table TableModel getValueAt

List of usage examples for javax.swing.table TableModel getValueAt

Introduction

In this page you can find the example usage for javax.swing.table TableModel getValueAt.

Prototype

public Object getValueAt(int rowIndex, int columnIndex);

Source Link

Document

Returns the value for the cell at columnIndex and rowIndex.

Usage

From source file:org.pentaho.reporting.engine.classic.extensions.modules.mailer.MailProcessor.java

private static DataRow createReportParameterDataRow(final TableModel burstingData, final int row) {
    final int columnCount = burstingData.getColumnCount();
    final String[] columnNames = new String[columnCount];
    final Object[] columnValues = new Object[columnCount];
    for (int i = 0; i < columnCount; i++) {
        columnValues[i] = burstingData.getValueAt(row, i);
        columnNames[i] = burstingData.getColumnName(i);
    }/* w w w  .  ja v  a  2  s.  c o m*/
    return new StaticDataRow(columnNames, columnValues);
}

From source file:org.quackbot.gui.InfoPlugins.java

public InfoPlugins(final Controller controller) {
    super();//from   ww w  .j  a v a  2 s  .c o  m
    setBorder(BorderFactory.createTitledBorder("Active plugins"));

    //Configure the table model
    pluginTableModel = new DefaultTableModel() {
        @Override
        public Class getColumnClass(int c) {
            return getValueAt(0, c).getClass();
        }
    };
    pluginTableModel.addColumn("Name");
    pluginTableModel.addColumn("Type");
    pluginTableModel.addColumn("Enabled");
    pluginTableModel.addColumn("Admin Only");
    pluginTableModel.addColumn("Required");
    pluginTableModel.addColumn("Optional");
    pluginTableModel.addColumn("Help");

    //Toggle command enabled status when changed on the table
    pluginTableModel.addTableModelListener(new TableModelListener() {
        @Override
        public void tableChanged(TableModelEvent e) {
            if (e.getType() != TableModelEvent.UPDATE)
                return;
            TableModel model = ((TableModel) e.getSource());
            String plugin = StringUtils
                    .trimToNull((String) ((TableModel) e.getSource()).getValueAt(e.getFirstRow(), 0));
            Command command = controller.getHookManager().getCommand(plugin);
            if (command != null) {
                command.setEnabled((Boolean) model.getValueAt(e.getFirstRow(), 1));
                log.debug((command.isEnabled() ? "Enabled" : "Disabled") + " command " + command.getName());
            }
        }
    });

    //Configure the table
    pluginTable = new JTable(pluginTableModel) {
        @Override
        public String getToolTipText(MouseEvent e) {
            Point p = e.getPoint();
            int rowIndex = pluginTable.rowAtPoint(p);
            int colIndex = pluginTable.columnAtPoint(p);
            if ((colIndex == 0 || colIndex == 5 || colIndex == 6) && getValueAt(rowIndex, colIndex) != null)
                return getValueAt(rowIndex, colIndex).toString();
            return "";
        }
    };
    pluginTable.setRowSelectionAllowed(false);
    pluginTable.setColumnSelectionAllowed(false);
    pluginTable.setCellSelectionEnabled(false);
    pluginTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);

    //Configure the default column widths
    TableColumnModel columnModel = pluginTable.getColumnModel();
    columnModel.getColumn(0).setPreferredWidth(120);
    columnModel.getColumn(1).setPreferredWidth(50);
    columnModel.getColumn(2).setPreferredWidth(75);
    columnModel.getColumn(3).setPreferredWidth(50);
    columnModel.getColumn(4).setPreferredWidth(40);
    columnModel.getColumn(5).setPreferredWidth(520);

    //Add the table to the scroll pane
    add(pluginTable);

    //Get notified of hook changes
    controller.getHookManager().addHook(new QListener("QBGuiPluginPanel") {
        @Override
        public void onHookLoad(HookLoadEvent event) {
            //TODO: Inform user about exception
            if (event.getException() != null)
                return;
            QListener hook = event.getHook();
            if (hook instanceof Command) {
                Command command = (Command) hook;
                pluginTableModel.addRow(
                        new Object[] { command.getName(), "Command", command.isEnabled(), command.isAdmin(),
                                command.getRequiredParams(), command.getOptionalParams(), command.getHelp() });
            } else {
                pluginTableModel.addRow(new Object[] { hook.getName(), "Hook", null, null, null, null, null });
            }
        }

        @Override
        public void onHookLoadStart(HookLoadStartEvent event) {
            pluginTableModel.setRowCount(0);
        }
    });
}

From source file:org.simmi.GeneSetHead.java

License:asdf

public void updateFilter(int val, String ustr, JTable table, RowFilter filter, Set<Integer> filterset,
        Label label, int... ind) {
    filterset.clear();/* w  w  w.j av a  2s  .c om*/
    TableModel model = table.getModel();
    for (int r = 0; r < model.getRowCount(); r++) {
        for (int i = 0; i < ind.length; i++) {
            String vstr = (String) model.getValueAt(r, ind[i]);
            String s = vstr != null ? vstr.toLowerCase() : null;

            if ((s != null && s.contains(ustr))) {
                filterset.add(r);
                break;
            }
        }
    }

    if (filterset.isEmpty()) {
        int i = 0;
        if (table.getModel() == groupModel) {
            for (GeneGroup gg : geneset.allgenegroups) {
                for (Gene g : gg.genes) {
                    if (g.refid.toLowerCase().contains(ustr)) {
                        filterset.add(i);
                        break;
                    }
                }
                i++;
            }
        } else {
            for (Gene g : geneset.genelist) {
                if (g.refid.toLowerCase().contains(ustr)) {
                    filterset.add(i);
                }
                i++;
            }
        }
    }

    updateFilter(table, filter, label);
}

From source file:org.tinymediamanager.ui.movies.MoviePanel.java

private void addKeyListener() {
    table.addKeyListener(new KeyListener() {
        private long lastKeypress = 0;
        private String searchTerm = "";

        @Override/*from   w  w  w .j  a va 2 s  . c o  m*/
        public void keyTyped(KeyEvent arg0) {
            long now = System.currentTimeMillis();
            if (now - lastKeypress > 500) {
                searchTerm = "";
            }
            lastKeypress = now;

            if (arg0.getKeyChar() != KeyEvent.CHAR_UNDEFINED) {
                searchTerm += arg0.getKeyChar();
            }

            if (StringUtils.isNotBlank(searchTerm)) {
                TableModel model = table.getModel();
                for (int i = 0; i < model.getRowCount(); i++) {
                    if (model.getValueAt(i, 0) instanceof Movie) {
                        String title = ((Movie) model.getValueAt(i, 0)).getTitleSortable()
                                .toLowerCase(Locale.ROOT);
                        if (title.startsWith(searchTerm)) {
                            ListSelectionModel selectionModel = table.getSelectionModel();
                            selectionModel.setSelectionInterval(i, i);
                            table.scrollRectToVisible(new Rectangle(table.getCellRect(i, 0, true)));
                            break;
                        }
                    }
                }
            }
        }

        @Override
        public void keyReleased(KeyEvent arg0) {
        }

        @Override
        public void keyPressed(KeyEvent arg0) {
        }
    });
}

From source file:org.ut.biolab.medsavant.client.view.genetics.TablePanel.java

private JPopupMenu createPopupSingle() {

    JPopupMenu menu = new JPopupMenu();

    TableModel model = searchableTablePanel.getTable().getModel();
    int r = TableModelWrapperUtils.getActualRowAt(model, searchableTablePanel.getTable().getSelectedRow());

    final String chrom = (String) model.getValueAt(r, INDEX_OF_CHROM);
    final int startpos = (Integer) model.getValueAt(r, INDEX_OF_START_POSITION);
    final int endpos = (Integer) model.getValueAt(r, INDEX_OF_END_POSITION);
    final String alt = (String) model.getValueAt(r, INDEX_OF_ALT);

    //Filter by position
    JMenuItem posItem = new JMenuItem("Filter by Position");

    posItem.addActionListener(new ActionListener() {
        @Override/* w w w . j  ava  2  s  .co m*/
        public void actionPerformed(ActionEvent ae) {
            //QueryUtils.addQueryOnChromPosition(chrom,pos);

            List<GenomicRegion> gr = new ArrayList<GenomicRegion>(1);
            gr.add(new GenomicRegion(null, chrom, startpos, endpos));

            QueryUtils.addQueryOnRegions(gr, null);
        }
    });

    menu.add(posItem);

    //Filter by position and alt
    JMenuItem posAndAltItem = new JMenuItem("Filter by Position and Alt");
    posAndAltItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            QueryUtils.addQueryOnRegionWithAlt(new GenomicRegion(null, chrom, startpos, endpos), alt);
        }
    });
    menu.add(posAndAltItem);

    return menu;
}

From source file:org.ut.biolab.medsavant.client.view.genetics.TablePanel.java

private JPopupMenu createPopupMultiple() {
    JPopupMenu menu = new JPopupMenu();

    JMenuItem posItem = new JMenuItem("Filter by Selected Positions");
    posItem.addActionListener(new ActionListener() {
        @Override//from   w  w  w .  jav  a2  s .co  m
        public void actionPerformed(ActionEvent ae) {
            ThreadController.getInstance().cancelWorkers(pageName);

            //QueryViewController qvc = SearchBar.getInstance().getQueryViewController();
            List<GenomicRegion> regions = new ArrayList<GenomicRegion>();
            TableModel model = searchableTablePanel.getTable().getModel();
            int[] selRows = TableModelWrapperUtils.getActualRowsAt(model,
                    searchableTablePanel.getTable().getSelectedRows(), false);
            List<SearchConditionItem> sciList = new ArrayList<SearchConditionItem>(selRows.length);

            for (int r : selRows) {

                String chrom = (String) model.getValueAt(r, INDEX_OF_CHROM);
                int startpos = (Integer) model.getValueAt(r, INDEX_OF_START_POSITION);
                int endpos = (Integer) model.getValueAt(r, INDEX_OF_END_POSITION);
                regions.add(new GenomicRegion(null, chrom, startpos, endpos));

                /*
                 SearchConditionGroupItem posGroup = new SearchConditionGroupItem(SearchConditionGroupItem.QueryRelation.OR, null, null);
                 posGroup.setDescription("Chromosome "+chrom+", Pos. "+pos);
                        
                 SearchConditionItem chromItem = new SearchConditionItem(BasicVariantColumns.CHROM.getAlias(), SearchConditionGroupItem.QueryRelation.AND, posGroup);
                 chromItem.setDescription(chrom);
                 chromItem.setSearchConditionEncoding(StringConditionEncoder.encodeConditions(Arrays.asList(new String[]{chrom})));
                        
                 SearchConditionItem startPosItem = new SearchConditionItem(BasicVariantColumns.POSITION.getAlias(), SearchConditionGroupItem.QueryRelation.AND, posGroup);
                 startPosItem.setDescription(Integer.toString(pos));
                 startPosItem.setSearchConditionEncoding(NumericConditionEncoder.encodeConditions(pos, pos));
                        
                        
                 qvc.generateItemViewAndAddToGroup(chromItem, posGroup);
                 qvc.generateItemViewAndAddToGroup(startPosItem, posGroup);
                        
                 sciList.add(posGroup);                    */
            }
            //qvc.replaceFirstLevelGroup("Selected Position(s)", sciList, QueryRelation.OR, false);
            //qvc.refreshView();
            QueryUtils.addQueryOnRegions(regions, null);

        }
    });
    menu.add(posItem);

    return menu;
}

From source file:org.yccheok.jstock.file.Statements.java

/**
 * Construct Statements based on given TableModel.
 *
 * @param tableModel given TableModel//from   www  . ja v  a 2 s.co m
 * @return the constructed Statements. UNKNOWN_STATEMENTS if fail
 */
public static Statements newInstanceFromTableModel(TableModel tableModel, boolean languageIndependent) {
    final CSVHelper csvHelper = (CSVHelper) tableModel;
    final GUIBundleWrapper guiBundleWrapper = GUIBundleWrapper.newInstance(
            languageIndependent ? GUIBundleWrapper.Language.INDEPENDENT : GUIBundleWrapper.Language.DEFAULT);

    final int column = tableModel.getColumnCount();
    final int row = tableModel.getRowCount();

    List<String> strings = new ArrayList<String>();
    for (int i = 0; i < column; i++) {
        final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(i)
                : tableModel.getColumnName(i);
        final Class c = tableModel.getColumnClass(i);
        if (c.equals(Stock.class)) {
            final String code_string = guiBundleWrapper.getString("MainFrame_Code");
            final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");
            strings.add(code_string);
            strings.add(symbol_string);
        }
        if (c.equals(StockInfo.class)) {
            final String code_string = guiBundleWrapper.getString("MainFrame_Code");
            final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");
            strings.add(code_string);
            strings.add(symbol_string);
        } else {
            strings.add(type);
        }

    }

    // Comment handling.
    CommentableContainer commentableContainer = null;
    if (tableModel instanceof CommentableContainer) {
        commentableContainer = (CommentableContainer) tableModel;
    }

    Statement.What what = Statement.what(strings);
    final Statements s = new Statements(what.type, what.guiBundleWrapper);

    for (int i = 0; i < row; i++) {
        final List<Atom> atoms = new ArrayList<Atom>();
        for (int j = 0; j < column; j++) {
            final String type = languageIndependent ? csvHelper.getLanguageIndependentColumnName(j)
                    : tableModel.getColumnName(j);
            final Object object = tableModel.getValueAt(i, j);
            final Class c = tableModel.getColumnClass(j);
            if (c.equals(Stock.class)) {
                final Stock stock = (Stock) object;
                // There are no way to represent Stock in text form. We
                // will represent them in Code and Symbol.
                // Code first. Follow by symbol.

                final String code_string = guiBundleWrapper.getString("MainFrame_Code");
                final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");

                atoms.add(new Atom(stock.code.toString(), code_string));
                atoms.add(new Atom(stock.symbol.toString(), symbol_string));
            } else if (c.equals(StockInfo.class)) {
                final StockInfo stockInfo = (StockInfo) object;

                final String code_string = guiBundleWrapper.getString("MainFrame_Code");
                final String symbol_string = guiBundleWrapper.getString("MainFrame_Symbol");

                atoms.add(new Atom(stockInfo.code.toString(), code_string));
                atoms.add(new Atom(stockInfo.symbol.toString(), symbol_string));
            } else if (c.equals(Date.class)) {
                atoms.add(new Atom(object != null
                        ? org.yccheok.jstock.gui.Utils.commonDateFormat(((Date) object).getTime())
                        : "", type));
            } else {
                // For fall below and rise above, null value is permitted.
                // Use empty string to represent null value.
                atoms.add(new Atom(object != null ? object : "", type));
            }
        }

        // Comment handling.
        if (commentableContainer != null) {
            atoms.add(new Atom(commentableContainer.getCommentable(i).getComment(),
                    guiBundleWrapper.getString("PortfolioManagementJPanel_Comment")));
        }

        final Statement statement = new Statement(atoms);

        if (s.getType() != statement.getType()) {
            // Doesn't not match. Return UNKNOWN_STATEMENTS to indicate we fail to
            // construct Statements from TableModel.
            return UNKNOWN_STATEMENTS;
        }

        s.statements.add(statement);
    }

    // Any metadata? This is special hack since Android introduction.
    if (tableModel instanceof StockTableModel) {
        s.metadatas.put("timestamp", Long.toString(((StockTableModel) tableModel).getTimestamp()));
    }

    return s;
}

From source file:org.yccheok.jstock.gui.portfolio.DividendSummaryJDialog.java

/** Creates new form DividendSummaryJDialog */
public DividendSummaryJDialog(java.awt.Frame parent, boolean modal, DividendSummary dividendSummary,
        PortfolioManagementJPanel portfolioManagementJPanel) {
    super(parent, modal);
    this.portfolioManagementJPanel = portfolioManagementJPanel;
    // Clone another copy to avoid original copy from being corrupted.
    this.dividendSummary = new DividendSummary(dividendSummary);
    this.dividendSummaryAfterPressingOK = null;
    initComponents();/*  ww  w .  j  a v a 2  s .  c  om*/

    // Hackish way to make Mac works.
    pack();
    setSize(new java.awt.Dimension(339, 373));
    setLocationRelativeTo(null);

    ((TableRowSorter) this.jTable1.getRowSorter()).setStringConverter(new TableStringConverter() {

        @Override
        public String toString(TableModel model, int row, int column) {
            if (model.getColumnClass(column) == StockInfo.class) {
                return ((StockInfo) model.getValueAt(row, column)).symbol.toString();
            }

            return model.getValueAt(row, column).toString();
        }
    });

    // Sort by date, with latest comes first.
    final RowSorter<? extends TableModel> rowSorter = this.jTable1.getRowSorter();
    if (rowSorter != null) {
        rowSorter.toggleSortOrder(0);
        final List<? extends SortKey> sortKeys = rowSorter.getSortKeys();
        if (sortKeys.size() > 0) {
            if (sortKeys.get(0).getSortOrder() != javax.swing.SortOrder.DESCENDING) {
                rowSorter.toggleSortOrder(0);
            }
        }
    }

    addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosed(WindowEvent e) {
            AutoDividendTask autoDividendTask = DividendSummaryJDialog.this.autoDividendTask;
            if (autoDividendTask != null) {
                autoDividendTask.cancel(true);
            }
        }
    });
}

From source file:pkgnew.line.PluginDialog.java

private void enablePluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enablePluginActionPerformed
    List<Plugin> plugins = PluginManager.getInstance().getPlugins();
    TableModel model = TablePlugins.getModel();
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        boolean isSelected = (boolean) model.getValueAt(i, 0);
        if (isSelected) {
            plugins.get(i).resume();//  w w w. ja  v a 2 s. c om
        }
    }
    listPlugins();
}

From source file:pkgnew.line.PluginDialog.java

private void disablePluginActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_disablePluginActionPerformed
    List<Plugin> plugins = PluginManager.getInstance().getPlugins();
    TableModel model = TablePlugins.getModel();
    int rowCount = model.getRowCount();

    for (int i = 0; i < rowCount; i++) {
        boolean isSelected = (boolean) model.getValueAt(i, 0);
        if (isSelected) {
            plugins.get(i).suspend();//w w w . ja  v  a 2s .com
        }
    }
    listPlugins();
}