Package simplesheet.model

Examples of simplesheet.model.SheetModel


            }
            sm.setSelectionInterval(ankor, lead);
        }

        private CellPosition getNextLead(KeyEvent e, CellPosition lead) {
            SheetModel model = table.getModel();
            lead = model.getOrigin(lead);
            switch(e.getKeyCode()) {
                case KeyEvent.VK_DOWN : {
                    Dimension size = model.getSize(lead);
                    if(lead.row + size.height < model.getRowCount()) {
                        return model.getOrigin(new CellPosition(lead.row+size.height, lead.col));
                    }
                    break;
                }
                case KeyEvent.VK_UP : {
                    if(lead.row -1 >= 0) {
                        return model.getOrigin(new CellPosition(lead.row-1, lead.col));
                    }
                    break;
                }
                case KeyEvent.VK_RIGHT : {
                    Dimension size = model.getSize(lead);
                    if(lead.col + size.width < model.getColumnCount()) {
                        return model.getOrigin(new CellPosition(lead.row, lead.col+size.width));
                    }
                    break;
                }
                case KeyEvent.VK_LEFT : {
                    if(lead.col - 1 >= 0) {
                        return model.getOrigin(new CellPosition(lead.row, lead.col-1));
                    }
                    break;
                }
            }
            return null;
View Full Code Here


        return table;
    }

    public void setTable(SheetTable table) {
        this.table = table;
        SheetModel model = table.getModel();
        for(int i=0; i<model.getRowCount(); i++) {
            model.getRow(i).addRowListener(localRowsListener);
        }
        for(int i=0; i<model.getColumnCount(); i++) {
            model.getColumn(i).addColumnListener(localColumnsListener);
        }
    }
View Full Code Here

            borderInsets = new Insets(0, 0, 0, 0);
        }
        Rectangle clipRc = fixRectangle(oldRc, borderInsets);

        //calc rectangle
        SheetModel model = table.getModel();
        CellPosition origin0 = getTopLeft(clipRc);
        CellPosition originN = getBottomRight(clipRc);
        if(origin0 == null || originN == null) {
            //no cells
            return;
        }
       
        int yBase = borderInsets.top;
        for (int iRow = 0; iRow < origin0.row; iRow++) {
            yBase += model.getRow(iRow).getHeight();
        }
        int xBase = borderInsets.left;
        for (int iCol = 0; iCol < origin0.col; iCol++) {
            xBase += model.getColumn(iCol).getWidth();
        }

        Spanned spanned[] = new Spanned[originN.col - origin0.col + 1];

        for (int iRow = origin0.row; iRow <= originN.row; iRow++) {
            int xLocalBase = xBase;
            for (int iCol = origin0.col; iCol <= originN.col; ) { /// increment at end
                //check if spanned
                int index = iCol - origin0.col;
                if(spanned[index] != null) {
                   spanned[index].rows--;
                   iCol += spanned[index].cols;
                   xLocalBase += spanned[index].width;

                   if(spanned[index].rows == 0) {
                       spanned[index] = null;
                   }
                   continue;
                }
               
                //define dimensions
                CellPosition origin = model.getOrigin(new CellPosition(iRow, iCol));
                Dimension size = model.getSize(origin);
                Rectangle rc = new Rectangle();
                //y offset for spanned cells may be > 0
                rc.y = yBase;
                for(int i=0; i < iRow-origin.row; i++) {
                    rc.y -= model.getRow(origin.row + i).getHeight();
                }
                //x offset for spanned cells may be > 0
                rc.x = xLocalBase;
                for(int i=0; i < iCol-origin.col; i++) {
                    rc.x -= model.getColumn(origin.col + i).getWidth();
                }
                //define cell width
                rc.width = 0;
                for (int i = 0; i < size.width; i++) {
                    rc.width += model.getColumn(origin.col + i).getWidth();
                }
                //define  cell height
                rc.height = 0;
                for (int i = 0; i < size.height; i++) {
                    rc.height += model.getRow(origin.row + i).getHeight();
                }

                if(clipRc.intersects(rc)) {
                    //paint cell
                    g.setClip(clipRc.createIntersection(rc));
                    paintCell(g, rc, origin);

                    //update span info
                    int yLeft = (origin.row + size.height) - iRow;
                    if(yLeft > 1) {
                        int xLeft = (origin.col + size.width) - iCol;
                        spanned[index] = new Spanned(yLeft-1, xLeft, rc.width);
                    }
                }
                //update current position
                iCol += size.width;
                xLocalBase += rc.width;
            }
            //update current position
            yBase += model.getRow(iRow).getHeight();
        }
        g.setColor(oldColor);
        g.setClip(oldRc);
    }
View Full Code Here

        Point bottomLeft = new Point(rc.x + rc.width, rc.y + rc.height);
        CellPosition pos = table.getCellAtPoint(bottomLeft);
        if(pos == null) {
            return null;
        }
        SheetModel model = table.getModel();
        CellPosition originN = model.getOrigin(pos);
        Dimension sizeN = model.getSize(originN);
        return new CellPosition(originN.row + sizeN.height-1, originN.col + sizeN.width-1);
    }
View Full Code Here

        g.setColor(c);
    }


    private void recalcDimension(Graphics g) {
        SheetModel model = table.getModel();
        Iterator<Integer> it = recalcCols.iterator();
        while(it.hasNext()) {
            int index = it.next();
            Column col = model.getColumn(index);
            if(col.isForceRecalcWidth()) {
                recalcColWidth(g, index);
            }
        }
        recalcCols.clear();
        it = recalcRows.iterator();
        while(it.hasNext()) {
            int index = it.next();
            Row row = model.getRow(index);
            if(row.isForceRecalcHeight()) {
                recalcRowHeight(g, index);
            }
        }
        recalcRows.clear();
View Full Code Here

     * @param g
     * @param iCol
     */
    private void recalcColWidth(Graphics g, int iCol) {
        int maxWidth = 0;
        SheetModel model = table.getModel();
        CellRenderer renderer = table.getDefaultRenderer();
        for(int iRow=0; iRow<model.getRowCount(); /* ath the end*/) {
            CellPosition pos = model.getOrigin(new CellPosition(iRow, iCol));
            Dimension size = model.getSize(pos);
            if(size.height > 1 || size.width > 1) {
                iRow += size.height;
                continue;
            }
            int iWidth = renderer.getPreferredWidth(table, g, model.getValueAt(pos));
            if(iWidth > maxWidth) {
                maxWidth = iWidth;
            }
            iRow++;
        }
        Column column = model.getColumn(iCol);
        if(maxWidth < column.getMinWidth()) {
            column.setWidth(column.getMinWidth());
        } else if(maxWidth  == 0) {
            //min width may be zero
            column.setDefaultWidth();
View Full Code Here

        }
    }

    private void recalcRowHeight(Graphics g, int iRow) {
        int maxHeight = 0;
        SheetModel model = table.getModel();
        CellRenderer renderer = table.getDefaultRenderer();
        for(int iCol=0; iCol<model.getColumnCount(); /* ath the end*/) {
            CellPosition pos = model.getOrigin(new CellPosition(iRow, iCol));
            Dimension size = model.getSize(pos);
            if(size.height > 1 || size.width > 1) {
                iCol += size.width;
                continue;
            }
            int width = model.getColumn(iCol).getWidth();
            int iHeight = renderer.getPreferredHeight(table, g, model.getValueAt(pos), width);
            if(iHeight > maxHeight) {
                maxHeight = iHeight;
            }
            iCol++;
        }
        Row row = model.getRow(iRow);
        if(maxHeight < row.getMinHeight()) {
            row.setHeight(row.getMinHeight());
        } else if(maxHeight  == 0) {
            //min width may be zero
            row.setDefaultHeight();
View Full Code Here

     * @param c
     * @return
     */
    @Override
    public Dimension getMinimumSize(JComponent c) {
        SheetModel model = table.getModel();
        Dimension res = getBorderedDimensions(c);
        for(int i=0; i<model.getRowCount(); i++) {
            res.height += model.getRow(i).getMinHeight();
        }
        for(int i=0; i<model.getColumnCount(); i++) {
            res.width += model.getColumn(i).getMinWidth();
        }
        return res;
    }
View Full Code Here

        return res;
    }

    @Override
    public Dimension getPreferredSize(JComponent c) {
        SheetModel model = table.getModel();
        Dimension res = getBorderedDimensions(c);
        for(int i=0; i<model.getRowCount(); i++) {
            res.height += model.getRow(i).getHeight();
        }
        for(int i=0; i<model.getColumnCount(); i++) {
            res.width += model.getColumn(i).getWidth();
        }
        return res;
    }
View Full Code Here

TOP

Related Classes of simplesheet.model.SheetModel

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.