1 package com.calipso.reportgenerator.userinterface; 2 3 import com.calipso.reportgenerator.userinterface.PivotTable; 4 import com.calipso.reportgenerator.common.HeaderTableModel; 5 6 import javax.swing.*; 7 import java.awt.*; 8 9 13 14 public class DimensionValuesSearcher { 15 16 private PivotTable pivotTable; 17 18 22 public DimensionValuesSearcher(PivotTable pivotTable) { 23 this.pivotTable = pivotTable; 24 } 25 26 34 public int searchDimensionValues(int searchLastIndex, String value, int index, boolean byRow) { 35 JTable dataTable = pivotTable.getDatajTable(); 36 if(byRow) { 37 HeaderTableModel rowModel = (HeaderTableModel) pivotTable.getRowHeaderjTable().getModel(); 38 int selectedColumn = dataTable.getSelectedColumn(); 39 for(int i = searchLastIndex ; i < dataTable.getRowCount() ; i++) { 40 Object [] values = rowModel.getValueFrom(i); 41 if(values[index] != null) { 42 if(values[index].toString().indexOf(value)>=0) { 43 dataTable.setRowSelectionInterval(i, i); 44 dataTable.setColumnSelectionInterval(selectedColumn, selectedColumn); 45 Rectangle cellBounds = dataTable.getCellRect(i, selectedColumn, true); 46 JViewport viewport = (JViewport) dataTable.getParent().getParent(); 47 JScrollPane scrollPane = (JScrollPane) viewport.getParent(); 48 scrollPane.getVerticalScrollBar().setValue(cellBounds.y); 49 return i + 1; 50 } 51 } 52 } 53 } else { 54 HeaderTableModel columnModel = (HeaderTableModel) pivotTable.getColumnHeaderjTable().getModel(); 55 int selectedRow = dataTable.getSelectedRow(); 56 for(int i = searchLastIndex ; i < dataTable.getColumnCount() ; i++) { 57 Object [] values = columnModel.getValueFrom(i); 58 if(values[index] != null) { 59 if(values[index].toString().indexOf(value)>=0) { 60 dataTable.setRowSelectionInterval(selectedRow, selectedRow); 61 dataTable.setColumnSelectionInterval(i, i); 62 Rectangle cellBounds = dataTable.getCellRect(selectedRow, i, true); 63 JViewport viewport = (JViewport) dataTable.getParent().getParent(); 64 JScrollPane scrollPane = (JScrollPane) viewport.getParent(); 65 scrollPane.getHorizontalScrollBar().setValue(cellBounds.x); 66 return i + 1; 67 } 68 } 69 } 70 } 71 return -1; 72 } 73 } 74 | Popular Tags |