Example usage for javax.swing.event TableColumnModelEvent getToIndex

List of usage examples for javax.swing.event TableColumnModelEvent getToIndex

Introduction

In this page you can find the example usage for javax.swing.event TableColumnModelEvent getToIndex.

Prototype

public int getToIndex() 

Source Link

Document

Returns the toIndex.

Usage

From source file:Main.java

public void columnAdded(TableColumnModelEvent e) {
    int fromIndex = e.getFromIndex();
    int toIndex = e.getToIndex();
    System.out.println(fromIndex);
    System.out.println(toIndex);// w  ww  . j a  v  a 2 s  .c  o  m
}

From source file:Main.java

public void columnRemoved(TableColumnModelEvent e) {
    int fromIndex = e.getFromIndex();
    int toIndex = e.getToIndex();
    System.out.println(fromIndex);
    System.out.println(toIndex);// w ww .ja va  2 s. c  om
}

From source file:Main.java

public void columnMoved(TableColumnModelEvent e) {
    int fromIndex = e.getFromIndex();
    int toIndex = e.getToIndex();
    System.out.println(fromIndex);
    System.out.println(toIndex);/*  w ww .j ava2  s  . c  o m*/
}

From source file:edu.ku.brc.specify.plugins.sgr.SGRResultsDisplay.java

@Override
public void columnMoved(TableColumnModelEvent e) {
    int from = e.getFromIndex();
    int to = e.getToIndex();
    if (from == to)
        return;//  w  w w.j  av  a 2 s . c  om
    System.out.println(e.getSource() + " " + from + " " + to);
    SGRColumnOrdering.getInstance().moveColumn(from, to);
}

From source file:org.isatools.isacreator.spreadsheet.Spreadsheet.java

public void columnMoved(TableColumnModelEvent event) {
    if (event.getFromIndex() != event.getToIndex()) {
        undoManager.discardAllEdits();/*  w  w w .  j  av  a 2  s.c o  m*/
    }
}

From source file:org.nuclos.client.ui.collect.result.ResultController.java

/**
 * change column ordering in table model when table columns
 * are reordered by dragging a column with the mouse
 *//*from www.java2s.c  o m*/
private TableColumnModelListener newColumnModelListener() {
    return new TableColumnModelListener() {
        @Override
        public void columnMoved(TableColumnModelEvent ev) {
            final int iFromColumn = ev.getFromIndex();
            final int iToColumn = ev.getToIndex();
            if (iFromColumn != iToColumn) {
                //log.debug("column moved from " + iFromColumn + " to " + iToColumn);
                // Sync the "selected fields" with the table column model:
                getResultPanel().columnMovedInHeader(clctctl.getFields());

                // Note that the columns of the result table model are not adjusted here.
                // That means, the table column model and the table model are not 1:1 -
                // use JTable.convertColumnIndexToModel to convert between the two.
            }
        }

        @Override
        public void columnAdded(TableColumnModelEvent ev) {
        }

        @Override
        public void columnRemoved(TableColumnModelEvent ev) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent ev) {
        }

        @Override
        public void columnSelectionChanged(ListSelectionEvent ev) {
        }
    };
}

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

public void setVariantRecords(Set<VariantRecord> records) {
    innerPanel.removeAll();// ww  w  . j a v  a  2s. c  o m
    //This function executes quickly, no need for waitPanel.
    //innerPanel.add(new WaitPanel("Loading DNA Ids..."));
    tableModel.setValues(records);
    aggregateTable = new AggregateTable(tableModel) {
        @Override
        //Necessary to enable buttons within the table.
        public boolean isCellEditable(int rowIndex, int colIndex) {
            return colIndex == buttonIndex;
        }

        //"Disables" selection within the aggregateTable.
        @Override
        public TableCellRenderer getCellRenderer(final int rowIndex, final int columnIndex) {
            final TableCellRenderer renderer = super.getCellRenderer(rowIndex, columnIndex);
            return new TableCellRenderer() {
                @Override
                public Component getTableCellRendererComponent(JTable jtable, final Object o, boolean bln,
                        boolean bln1, int i, int i1) {
                    return renderer.getTableCellRendererComponent(jtable, o, false, false, i, i1);
                }
            };
        }

        //This overridden method, together with the custom mouse listener on the 
        //AggregateTable header, disallows moving the first column, and columns
        //>= dnaIDIndex                    
        @Override
        protected AggregateTable.DraggingHandler createDraggingColumnPropertyChangeListener() {
            return new AggregateTable.DraggingHandler() {
                @Override
                public void columnMoved(TableColumnModelEvent e) {
                    if (fromColumnIndex == -1) {
                        fromColumnIndex = e.getFromIndex();
                    }
                    toColumnIndex = e.getToIndex();
                }

            };
        }
    };

    header = new AggregateTableHeader(aggregateTable);
    header.addMouseListener(new MouseAdapter() {
        //Disable moving the first column, or columns with index
        //>=dnaIDIndex
        @Override
        public void mouseReleased(MouseEvent e) {
            if (toColumnIndex != -1 && ((toColumnIndex == 0 || fromColumnIndex == 0)
                    || (toColumnIndex >= dnaIDIndex || fromColumnIndex >= dnaIDIndex))) {
                aggregateTable.moveColumn(toColumnIndex, fromColumnIndex);
                String msg = "This column cannot be moved.";
                DialogUtils.displayMessage(msg);
            } else {
                for (int columnHeaderIndex = 0; columnHeaderIndex < header.getColumnModel().getColumnCount()
                        - 2; columnHeaderIndex++) {
                    String columnTitle = (String) header.getColumnModel().getColumn(columnHeaderIndex)
                            .getHeaderValue();
                    aggregateColumns[columnHeaderIndex] = columnTitle;
                }
                reaggregate();
            }
            //aggregateTable.aggregate(this.aggregateColumns);
            fromColumnIndex = -1;
            toColumnIndex = -1;
            //expandAllButLast();
        }
    });

    header.setAutoFilterEnabled(false);
    header.setReorderingAllowed(true);
    header.setFont(TABLE_FONT_LARGE);
    aggregateTable.setTableHeader(header);
    aggregateTable.setAutoResizeMode(AggregateTable.AUTO_RESIZE_ALL_COLUMNS);
    aggregateTable.setFont(TABLE_FONT_LARGE);

    //Setup a custom "summary".  This is what calculates frequencies when cells are
    //collapsed
    PivotField f = aggregateTable.getAggregateTableModel().getField(BasicVariantColumns.DNA_ID.getAlias());
    f.setSummaryType(PivotConstants.SUMMARY_RESERVED_MAX + 1);
    aggregateTable.getAggregateTableModel().setSummaryCalculator(new SummaryCalculator() {
        private Set<String> collapsedDNAIDs = new HashSet<String>();
        private Values lastRowValues;
        private int valueCount = 0;
        private final int SUMMARY_FREQ = PivotConstants.SUMMARY_RESERVED_MAX + 1;

        @Override
        public void addValue(PivotValueProvider dataModel, PivotField field, Values rowValues,
                Values columnValues, Object object) {
            //this gets called multiple times for all the cells that disappear when 
            //something is collapsed.  
            // row[0] is the value of the corresponding first column: e.g. a Cohort or Family. 
            // columnValues can be ignored (blank)
            // Object is the value of the item in the cell that disappeared. (i.e. those cells which are being summarized)
            // field.getName() is the column name corresponding to Object

            // Useful Debugging code:                      
            //if(field.getName().equals(BasicVariantColumns.DNA_ID.getAlias())){

            /*
             System.out.println("==========");
             System.out.println("Field : " + field.getName());
             System.out.println("Row values: ");
                    
             for (int i = 0; i < rowValues.getCount(); ++i) {
             System.out.println("\trow[" + i + "] = " + rowValues.getValueAt(i).getValue());
                    
             }
                    
             System.out.println("Column values: ");
             for (int i = 0; i < columnValues.getCount(); ++i) {
             System.out.println("\tcol[" + i + "] = " + columnValues.getValueAt(i).getValue());
             }
                    
             System.out.println("Object: ");
             System.out.println("\t" + object);
             System.out.println("==========");
             */

            // }
            if (field.getName().equals(BasicVariantColumns.DNA_ID.getAlias())) {
                collapsedDNAIDs.add((String) object);
                lastRowValues = rowValues;
            } else {
                lastRowValues = null;
            }
            valueCount++;
        }

        //Should never be called
        @Override
        public void addValue(Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (1)");
        }

        //Should never be called
        @Override
        public void addValue(IPivotDataModel ipdm, PivotField pf, int i, int i1, Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (2)");
        }

        //Should never be called
        @Override
        public void addValue(PivotValueProvider pvp, PivotField pf, Object o) {
            LOG.error("Unexpected method invocation in OtherIndividualsSubInspector (3)");
        }

        @Override
        public void clear() {
            collapsedDNAIDs.clear();
            valueCount = 0;
            lastRowValues = null;
        }

        @Override
        public Object getSummaryResult(int type) {
            //if null, then we're not in the DNAId column.  Return null
            //to show a blank in this cell
            if (lastRowValues == null) {
                return null;
            }

            int numIndividuals = getNumberOfIndividualsInGroup(lastRowValues.getValueAt(0));

            return new Frequency(collapsedDNAIDs.size(), numIndividuals);
        }

        private int getNumberOfIndividualsInGroup(Value v) {
            if (aggregateColumns[0].equals("Cohort")) {
                //LOG.debug("Getting number of individuals in group " + v.getValue());
                Set<String> dnaIds = cohortDNAIDMap.get((Cohort) v.getValue());
                //for (String id : dnaIds) {
                //LOG.debug("\tGot id " + id);
                //}
                return cohortDNAIDMap.get((Cohort) v.getValue()).size();
            } else if (aggregateColumns[0].equals(BasicPatientColumns.FAMILY_ID.getAlias())) {
                return familyIDdnaIDMap.get((String) v.getValue()).size();
            } else {
                LOG.error("Invalid first column");
                return -1;
            }
        }

        @Override
        public long getCount() {
            return valueCount;
        }

        @Override
        public int getNumberOfSummaries() {
            return 1;
        }

        @Override
        public String getSummaryName(Locale locale, int i) {
            return "Frequency";
        }

        @Override
        public int[] getAllowedSummaries(Class<?> type) {
            return new int[] { SUMMARY_FREQ };
        }

        @Override
        public int[] getAllowedSummaries(Class<?> type, ConverterContext cc) {
            return new int[] { SUMMARY_FREQ };
        }
    });

    //Sets up the context menu for clicking column headers.  This will probably not be used
    //frequently.  Limit the available operations to collapsing, expanding, and grouping.
    TableHeaderPopupMenuInstaller installer = new TableHeaderPopupMenuInstaller(aggregateTable);
    installer.addTableHeaderPopupMenuCustomizer(new AggregateTablePopupMenuCustomizer() {
        @Override
        public void customizePopupMenu(JTableHeader header, JPopupMenu popup, int clickingColumn) {
            super.customizePopupMenu(header, popup, clickingColumn);
            for (int i = 0; i < popup.getComponentCount(); i++) {
                String menuItemName = popup.getComponent(i).getName();
                if (!(CONTEXT_MENU_COLLAPSE.equals(menuItemName)
                        || CONTEXT_MENU_COLLAPSE_ALL.equals(menuItemName)
                        || CONTEXT_MENU_EXPAND.equals(menuItemName)
                        || CONTEXT_MENU_EXPAND_ALL.equals(menuItemName)
                        || CONTEXT_MENU_GROUP.equals(menuItemName)
                        || CONTEXT_MENU_UNGROUP.equals(menuItemName))) {

                    popup.remove(popup.getComponent(i));

                }
            }
        }
    });

    aggregateTable.getAggregateTableModel().setSummaryMode(true);

    aggregateTable.aggregate(aggregateColumns);
    aggregateTable.setShowContextMenu(false);

    expandAllButLast();
    setupButtonColumn();

    JScrollPane jsp = new JScrollPane(aggregateTable);
    jsp.setPreferredSize(PREFERRED_SIZE);

    JPanel bp = new JPanel();

    bp.setLayout(new BoxLayout(bp, BoxLayout.X_AXIS));
    JButton closeButton = new JButton(IconFactory.getInstance().getIcon(IconFactory.StandardIcon.CLOSE));
    closeButton.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            unsplitScreen();
        }
    });
    bp.add(Box.createHorizontalGlue());
    bp.add(title);
    bp.add(Box.createHorizontalGlue());
    bp.add(closeButton);
    innerPanel.add(bp);
    innerPanel.add(jsp);
    reaggregate();
    innerPanel.revalidate();
    innerPanel.repaint();
}

From source file:pipeline.GUI_utils.JXTablePerColumnFiltering.java

@Override
public void columnMoved(TableColumnModelEvent e) {
    super.columnMoved(e);
    if (e.getFromIndex() == e.getToIndex()) {
        return;//ww  w  .j a v  a2 s . c  o  m
    }
    try {
        filteringTable.editingCanceled(null);
        if (e.getFromIndex() != -1 && e.getFromIndex() < getColumns(true).size()) {
            filteringTable.moveColumn(e.getFromIndex(), e.getToIndex());
            tableForColumnDescriptions.moveColumn(e.getFromIndex(), e.getToIndex());
        }
    } catch (ArrayIndexOutOfBoundsException ex) {
        //Changes in column counts apparently occur when hiding/unhiding columns,
        //which generate column move events
        Utils.printStack(ex, LogLevel.DEBUG);
    }
    updateFilteringTableSetup();
}