⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ktable.java

📁 ktable 是一个由java开发的,对控制报表的项目,它最大的特点是使用独特的算法,能支持巨大的报表(千万以上?).
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
            
            left=right;
        }
        
        return -1;
        
    }

    /* gibt die Nummer einer Zeile der Ansicht(!) zur�ck */
    protected int getRowForResize(int x, int y) {
        
    	if ( m_Model == null || x <= 0 || x >= getHeaderWidth() ) {
            return -1;
        }

       if ( y < m_Model.getRowHeight(0) + m_ResizeAreaSize / 2 ) {
    	   
           // allow first row height resize?
    	   
           	if ( Math.abs(m_Model.getRowHeight(0) - y) < m_ResizeAreaSize / 2 &&
           	     m_Model.isRowResizable(0) ) {
           		
           	    return 0;
           	    
           	}
           	
            return -1;
            
       }

        int row        = getRowForY(y);
        int row_y      = getYforRow(row);
        int next_row_y = getYforRow(row+1);

        if ( ( Math.abs(y - next_row_y) < m_ResizeAreaSize / 2 ) &&
        	 m_Model.isRowResizable(row) ) {
            return row;
        } else if ( ( Math.abs(y - row_y) < m_ResizeAreaSize / 2 ) &&
        		    m_Model.isRowResizable(row-1) ) {
        	return row-1;
        }
        
        return -1;
        
    }
    
    /**
     * Returns the number of the column that is present at position x or -1, if
     * out of area. When cells are spanned, returns the address of the spanned cell.
     * @param x the x location of an event in table coordinates
     * @param y The y location of an event in table coordinates
     * @return Returns the point where x is the column index, y is the row index.
     */
    public Point calcColumnNum(int x, int y) {
        if (m_Model == null)
            return new Point(-1, -1);
        
        Point toFind = new Point(x, y);
        Point valid = getValidCell(m_LeftColumn, m_TopRow);
        
        // at first iterate over the fixed columns, that are always shown:
        Point found = checkIfMatchesInColumns(0, getFixedRowCount(), 
                0, getFixedColumnCount(), toFind, true);
        if (found!=null) return found;
        found = checkIfMatchesInColumns(valid.y, m_TopRow + m_RowsVisible, 
                0, getFixedColumnCount(), toFind, true);
        if (found!=null) return found;

        found = checkIfMatchesInColumns(0, getFixedRowCount(), 
                valid.x, m_LeftColumn+m_ColumnsVisible, toFind, true);
        if (found!=null) return found;
        found = checkIfMatchesInColumns(valid.y, m_TopRow + m_RowsVisible, 
                valid.x, m_LeftColumn+m_ColumnsVisible, toFind, true);
        if (found!=null) return found;
        
        return new Point(-1, -1);
        
    }
    
    protected Point calcNonSpanColumnNum(int x, int y) {
        if (m_Model == null)
            return new Point(-1, -1);
        
        Point toFind = new Point(x, y);
        Point valid = new Point(m_LeftColumn, m_TopRow);
        
        // at first iterate over the fixed columns, that are always shown:
        Point found = checkIfMatchesInColumns(0, getFixedRowCount(), 
                0, getFixedColumnCount(), toFind, false);
        if (found!=null) return found;
        found = checkIfMatchesInColumns(valid.y, m_TopRow + m_RowsVisible, 
                0, getFixedColumnCount(), toFind, false);
        if (found!=null) return found;

        found = checkIfMatchesInColumns(0, getFixedRowCount(), 
                valid.x, m_LeftColumn+m_ColumnsVisible, toFind, false);
        if (found!=null) return found;
        found = checkIfMatchesInColumns(valid.y, m_TopRow + m_RowsVisible, 
                valid.x, m_LeftColumn+m_ColumnsVisible, toFind, false);
        if (found!=null) return found;
        
        return new Point(-1, -1);
    }
    
    /**
     * Checks for the event location in table coordinates within the region covered
     * by the columns beginning by startCol and ending by endCol.
     * @param span Set to true if for spanning cells we just want to have the left-upper-most cell.
     */
    protected Point checkIfMatchesInColumns(int startRow, int endRow, int startCol, int endCol, Point toFind, boolean span) {
        
        for (int row = startRow; row < endRow; row++) {
            for (int col = startCol; col < endCol; col++) {
                
                Rectangle rect = getCellRectIgnoreSpan(col, row);
                // take into account the 1px right and bottom border
                rect.width+=1;
                rect.height+=1;
                if (rect.contains(toFind))
                    if (span)
                    // take into account the spanning when reporting a match:
                        return getValidCell(col, row);
                    else
                        return new Point(col, row);
            }
        }
        return null;
    }

    public boolean isCellVisible(int col, int row) {
        checkWidget();
        if (m_Model == null)
            return false;
        return ((col >= m_LeftColumn && col < m_LeftColumn + m_ColumnsVisible
                && row >= m_TopRow && row < m_TopRow + m_RowsVisible)

        || (col < getFixedColumnCount() && 
                row < getFixedRowCount()));
    }

    public boolean isCellFullyVisible(int col, int row) {
        checkWidget();
        if (m_Model == null)
            return false;
        return ((col >= m_LeftColumn
                && col < m_LeftColumn + m_ColumnsFullyVisible
                && row >= m_TopRow && row < m_TopRow + m_RowsFullyVisible)

        || (col < getFixedColumnCount() && 
                row < getFixedRowCount()));
    }

    /**
     * @param row The row index AS SEEN BY KTABLE. If you use a sorted model, don't forget
     * to map the index.
     * @return Returns true if the row is visible.
     */
    public boolean isRowVisible(int row) {
        checkWidget();
        if (m_Model == null)
            return false;
        return ((row >= m_TopRow && row < m_TopRow + m_RowsVisible) || 
                row < (getFixedRowCount()));

    }

    /**
     * @param row the row index to check - as seen by ktable. If you use a 
     * sorted model, don't forget to map.
     * @return Returns true if the row is fully visible.
     */
    public boolean isRowFullyVisible(int row) {
        checkWidget();
        if (m_Model == null)
            return false;
        return ((row >= m_TopRow && row < m_TopRow + m_RowsFullyVisible) 
                || row <getFixedRowCount());
    }

    /*
     * Focusses the given Cell. Assumes that the given cell is in the viewable
     * area. Does all neccessary redraws.
     */
    protected void focusCell(int col, int row, int stateMask) {
        // assure it is a valid cell:
        Point orig = new Point(col, row);
        Point valid = getValidCell(col, row);
        if (valid!=null) {
            col = valid.x;
            row = valid.y;
        }
        
        GC gc = new GC(this);
        
        // close cell editor if active
        if (m_CellEditor != null)
            m_CellEditor.close(true);

        /* Special rule: in row selection mode the selection
		 * if a fixed cell in a non-fixed row is allowed and
		 * handled as a selection of a non-fixed cell.
		 */
		if (row >= m_Model.getFixedHeaderRowCount()
				&& (col >= m_Model.getFixedHeaderColumnCount() || 
						isRowSelectMode()))
		{

            if ((stateMask & SWT.CTRL) == 0 && (stateMask & SWT.SHIFT) == 0) {
                // case: no modifier key
                boolean redrawAll
                = (m_Selection.size() > 1);
                int oldFocusRow = m_FocusRow;
                int oldFocusCol = m_FocusCol;
                
                clearSelectionWithoutRedraw();
                addToSelectionWithoutRedraw(col, row);
                m_FocusRow = row;
                m_FocusCol = col;
                m_MainFocusRow = row;
                m_MainFocusCol = col;

                if (redrawAll)
                    redraw();
                else if (isRowSelectMode()) {
                    drawRow(gc, oldFocusRow);
                    drawRow(gc, m_FocusRow);
                } else {
                    Rectangle origClipping = null;
                    if (!isFixedCell(oldFocusCol, oldFocusRow) )
                        origClipping = setContentAreaClipping(gc);
                    drawCell(gc, oldFocusCol, oldFocusRow);
                    if (origClipping!=null)
                        gc.setClipping(origClipping);
                    
                    if (!isFixedCell(m_FocusCol, m_FocusRow))
                        origClipping = setContentAreaClipping(gc);
                    drawCell(gc, m_FocusCol, m_FocusRow);
                }
                // notify non-fixed cell listeners
                fireCellSelection(orig.x, orig.y, stateMask);
            }

            else if ((stateMask & SWT.CTRL) != 0) {
                // case: CTRL key pressed
                boolean success = toggleSelection(col, row);  
                if (success) {
                    m_FocusCol = col;
                    m_FocusRow = row;
                }

                if (isRowSelectMode()) 
                    drawRow(gc, row);
                else
                    drawCell(gc, col, row);
                // notify non-fixed cell listeners
                if (success)
                    fireCellSelection(m_FocusCol, m_FocusRow, stateMask);
            }

            else if ((stateMask & SWT.SHIFT) != 0) {
                // Ignore when not a multi-selection table.
                if (!isMultiSelectMode()) {
                    if (isRowSelectMode()) 
                        drawRow(gc, row);
                    else
                        drawCell(gc, col, row);
                    return;
                }
                // case: SHIFT key pressed
                if (isRowSelectMode()) {
                	HashMap oldSelection = new HashMap(m_Selection);
                    if (row < m_FocusRow) {
                        // backword selection
                        while (row != m_FocusRow)
                            addToSelectionWithoutRedraw(0, --m_FocusRow);
                    } else {
                        // foreward selection
                        while (row != m_FocusRow)
                            addToSelectionWithoutRedraw(0, ++m_FocusRow);
                    }
                    if (!oldSelection.equals(m_Selection)) {
                    	oldSelection.putAll(m_Selection);
                    	Iterator rowIt = oldSelection.entrySet().iterator();
                    	int min=0, max=0;
                    	if (rowIt.hasNext()) {
                    		min = ((Integer)((Entry)rowIt.next()).getValue()).intValue();
                    		max = min;
                    	}                    		
                    	while (rowIt.hasNext()) {
                    		 int r = ((Integer)((Entry)rowIt.next()).getValue()).intValue();
                    		 if (r<min) min=r;
                    		 if (r>max) max=r;
                    	}
                    	redraw(0, min, m_Model.getColumnCount(), max-min+1);
                    	
                    	// notify non-fixed cell listeners
                        fireCellSelection(orig.x, orig.y, stateMask);
                    }
                } else {// cell selection mode

                	Point[] sel = getCellSelection();
                	Point min= new Point(Integer.MAX_VALUE, Integer.MAX_VALUE);
                	Point max = new Point(-1,-1);
                	boolean containsCell = false;
                	for (int i=0; i<sel.length; i++) {
                		if (sel[i].x>max.x) max.x=sel[i].x;
                		if (sel[i].y>max.y) max.y=sel[i].y;
                		if (sel[i].x<min.x) min.x=sel[i].x;
                		if (sel[i].y<min.y) min.y=sel[i].y;
                		if (!containsCell && sel[i].x==col && sel[i].y==row)
                			containsCell = true;
                	}
                	
                	if (col<m_MainFocusCol && max.x>m_MainFocusCol) {
        				min.x=col; max.x=m_MainFocusCol;
        			} else if (col>m_MainFocusCol && min.x<m_MainFocusCol) {
        				min.x=m_MainFocusCol; max.x=col;
        			}
        			if (row<m_MainFocusRow && max.y>m_MainFocusRow) {
        				min.y=row; max.y=m_MainFocusRow;
        			} else if (row>m_MainFocusRow && min.y<m_MainFocusRow) {
        				min.y=m_MainFocusRow; max.y=row;
        			}
        			
                	HashMap oldSelection = new HashMap(m_Selection);
            		if (containsCell) {
            			clearSelectionWithoutRedraw();
            			                        			
            			if (max.x==m_FocusCol) max.x=col;
            			if (max.y==m_FocusRow) max.y=row;
            			if (min.x==m_FocusCol) min.x=col;
            			if (min.y==m_FocusRow) min.y=row;
            			
            			// set selection:
            			for (int r=min.y; r<=max.y; r++)
            				for (int c=min.x; c<=max.x; c++)
            					addToSelectionWithoutRedraw(c, r);
            			if (!old

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -