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

📄 sdagrid.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        DataSet.RecNo = 0;        DataSet.doDataChangeScroll(DataSet.RecNo);        paint();    }    private int getHBarWidth() {        int swidth = 0;        if (scrollBars == SDAConsts.srHorizontal) {            swidth = getWidth();        }        if (scrollBars == SDAConsts.srBoth) {            swidth = getWidth() - barwidth;        }        return swidth;    }    private int getVBarHeight() {        int sheight = 0;        if (scrollBars == SDAConsts.srVertical) {            sheight = getHeight();        }        if (scrollBars == SDAConsts.srBoth) {            sheight = getHeight() - barwidth;        }        return sheight;    }    //处理事件的执行    //点箭头滚动内容    private void doPointerPressed(int x, int y) {        if ((DataSet == null) || (DataSet.getRecordCount() == 0)) {            return;        }        int posx = screenXToClient(x);        int posy = screenYToClient(y);        int thisWidth = getWidth();        int thisHeight = getHeight();        int VBarHeight = getVBarHeight();        int HBarWidth = getHBarWidth();        int fontHeight = getFont().getHeight() + 2;        int rowHeight = getRowHeight();        //如果点了外面        if (!InClientRect(posx, posy, 0, 0, thisWidth, thisHeight)) {        //popVisible = false;        }        //确定点击了滚动条区域        if ((scrollBars == SDAConsts.srHorizontal) || (scrollBars == SDAConsts.srBoth)) {            //判断是否点击了左箭头            if (InClientRect(posx, posy, 0, thisHeight - barwidth, barwidth, barwidth)) {                //向右滚动                if (StartCol > 0) {                    StartCol -= 1;                }            } else //右箭头            if (InClientRect(posx, posy, HBarWidth - barwidth, thisHeight - barwidth, barwidth, barwidth)) {                if (!IsEndCol) {                    StartCol += 1;                }            } else //滚动条            if (InClientRect(posx, posy, HSLeft, HSTop, HSWidth, HSHeight)) {                //记录点击的滚动条位置                oldScrollPointx = posx;                oldScrollPointy = posy;                isscrollbarpointdown = true;                scrollbardownHV = 0;                oldStartLeft = startLeft;            } else {                if (InClientRect(posx, posy, 0, thisHeight - barwidth, HBarWidth, barwidth)) {                    //计算滚动块要到位置                    int tpos = posx > HSLeft ? (posx - HSWidth) : (posx);                    int oldcol = StartCol;                    //计算StartLeft                                        startLeft = ((tpos - barwidth) * (maxLineLenght)) / (HBarWidth - 2 * barwidth);                    int len = 0;                    int index = 0;                    while (startLeft > len) {                        len += getColumn(index).ColWidth;                        index++;                    }                    StartCol = index;                    if (oldcol == StartCol) {                        StartCol = posx > HSLeft ? StartCol + 1 : StartCol - 1;                    }                }            }        }        if ((scrollBars == SDAConsts.srVertical) || (scrollBars == SDAConsts.srBoth)) {            //只有垂直滚动条            //判断是否点击了上箭头            if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, barwidth)) {                //向下滚动                if (Cursor > StartRow) {                    Cursor -= 1;                    DataSet.RecNo = Cursor;                    DataSet.doDataChangeScroll(DataSet.RecNo);                    return;                }                //向上滚动                if (StartRow > 0) {                    StartRow -= 1;                    Cursor = StartRow;                    DataSet.RecNo = Cursor;                    DataSet.doDataChangeScroll(DataSet.RecNo);                }            } else //下箭头            if (InClientRect(posx, posy, thisWidth - barwidth, VBarHeight - barwidth, barwidth, barwidth)) {                //向上滚动                if (Cursor < EndRow) {                    Cursor += 1;                    DataSet.RecNo = Cursor;                    DataSet.doDataChangeScroll(DataSet.RecNo);                    return;                }                if (!IsEndRow) {                    StartRow += 1;                    Cursor = EndRow + 1;                    DataSet.RecNo = Cursor;                } else {                    Cursor = EndRow;                    DataSet.RecNo = Cursor;                }                DataSet.doDataChangeScroll(DataSet.RecNo);            } else //滚动条            if (InClientRect(posx, posy, VSLeft, VSTop, VSWidth, VSHeight)) {                //记录位置                oldScrollPointx = posx;                oldScrollPointy = posy;                isscrollbarpointdown = true;                scrollbardownHV = 1;                oldStartLine = StartRow;            } else {                if (InClientRect(posx, posy, thisWidth - barwidth, 0, barwidth, VBarHeight)) {                    //空白的                    //计算滚动块要到位置                    int tpos = posy > VSTop ? (posy - VSHeight) : (posy);                    //计算StartLine                    int oldline = StartRow;                    StartRow = ((tpos - barwidth) * (getAllHeight())) / (VBarHeight - 2 * barwidth) / fontHeight;                    if (oldline == StartRow) {                        StartRow = posy > VSTop ? StartRow + 1 : StartRow - 1;                    }                    if (DataSet.RecNo < StartRow) {                        DataSet.RecNo = StartRow;                    }                    int maxRowsNum = getMaxRowsNum();                    if (DataSet.RecNo > StartRow + maxRowsNum - 1) {                        DataSet.RecNo = StartRow + maxRowsNum - 1;                    }                }            }        }        //点了滚动条外               if (InClientRect(posx, posy, 0, rowHeight, HBarWidth, VBarHeight - rowHeight - (showFootRow ? rowHeight : 0))) {            //计算y位置计算Cursor位置            Cursor = posy / rowHeight - 1 + StartRow;            if (Cursor < StartRow) {                Cursor = StartRow;            }            if (Cursor > EndRow) {                Cursor = EndRow;            }            DataSet.RecNo = Cursor;            DataSet.doDataChangeScroll(Cursor);            //触发点击cell事件            if (OnGridCellClick != null) {                OnGridCellClick.Event(DataSet.getRow(Cursor));            }        }        //点了标题条,判断排序的        if (InClientRect(posx, posy, FixedWidth, 0, thisWidth - barwidth - FixedWidth, rowHeight)) {            int pos = 0;            int id = StartCol;            Column cl = null;            while (pos < posx - FixedWidth) {                cl = getColumn(id);                id++;                pos += cl.ColWidth;            }            if (DataSet.getField(cl.FieldName).getFiledType() != SDADataSet.FieldAudoID) {                if (sortType == SDADataSet.sortAsc) {                    sortType = SDADataSet.sortDesc;                } else {                    sortType = SDADataSet.sortAsc;                }                sortFieldName = cl.FieldName;                DataSet.sortDataSet(cl.FieldName, sortType);            }        }    }    //拖动事件处理    private void doPointerReleased(int x, int y) {        int posx = screenXToClient(x);        int posy = screenYToClient(y);        int VBarHeight = getVBarHeight();        int HBarWidth = getHBarWidth();        //根据点击的位置,判断滚动的多少        if ((scrollBars == SDAConsts.srHorizontal) || ((scrollBars == SDAConsts.srBoth) && (scrollbardownHV == 0))) {            if (isscrollbarpointdown) {                int stepx = posx - oldScrollPointx;                //根据滚动多少来重新定位                //计算滚动块要到位置                int tpos = HSLeft + stepx;                HSLeft = tpos < barwidth ? barwidth : tpos;                HSLeft = HSLeft + HSWidth > HBarWidth - barwidth ? HBarWidth - barwidth - HSWidth : HSLeft;                //计算StartLeft                startLeft = ((HSLeft - barwidth) * (maxLineLenght)) / (HBarWidth - 2 * barwidth);                if (oldStartLeft != startLeft) {                    oldScrollPointx = posx;                    oldStartLeft = startLeft;                }                int oldcol = StartCol;                int len = 0;                int index = 0;                while (startLeft > len) {                    len += getColumn(index).ColWidth;                    index++;                }                StartCol = index;                if (oldcol == StartCol) {                    if (!IsEndCol) {                        StartCol = stepx > 0 ? StartCol + 1 : StartCol - 1;                    }                }                if (StartCol < 0) {                    StartCol = 0;                }            }        }        if ((scrollBars == SDAConsts.srVertical) || ((scrollBars == SDAConsts.srBoth) && (scrollbardownHV == 1))) {            if (isscrollbarpointdown) {                int stepy = posy - oldScrollPointy;                //根据滚动多少来重新定位                //计算滚动块要到位置                int tpos = VSTop + stepy;                VSTop = tpos < barwidth ? barwidth : tpos;                VSTop = VSTop + VSHeight > VBarHeight - barwidth ? VBarHeight - barwidth - VSHeight : VSTop;                //计算StartLine                StartRow = ((VSTop - barwidth) * (getAllHeight())) / (VBarHeight - 2 * barwidth) / getFont().getHeight();                if (oldStartLine == StartRow) {                    if (!IsEndRow) {                        StartRow = stepy > 0 ? StartRow + 1 : StartRow - 1;                    }                    oldStartLine = StartRow;                } else {                    if ((stepy > 0) && (StartRow < oldStartLine)) {                        StartRow = oldStartLine;                    }                    oldStartLine = StartRow;                }                if (StartRow < 0) {                    StartRow = 0;                }                if (DataSet.RecNo < StartRow) {                    DataSet.RecNo = StartRow;                }                int maxRowsNum = getMaxRowsNum();                if (DataSet.RecNo > StartRow + maxRowsNum - 1) {                    DataSet.RecNo = StartRow + maxRowsNum - 1;                }            }        }        isscrollbarpointdown = false;    }    //键盘事件处理    private void doKeyUp(int keyCode) {        String key = form.getKeyName(keyCode).toUpperCase();        try {            if (key.equals(SDAConsts.KEY_UP)) {                if (DataSet != null) {                    if (Cursor > StartRow) {                        Cursor -= 1;                        DataSet.RecNo = Cursor;                        DataSet.doDataChangeScroll(DataSet.RecNo);                        return;                    }                    //向上滚动                    if (StartRow > 0) {                        StartRow -= 1;                        Cursor = StartRow;                        DataSet.RecNo = Cursor;                        DataSet.doDataChangeScroll(DataSet.RecNo);                    }                }            }            if (key.equals(SDAConsts.KEY_DOWN)) {                if (DataSet != null) {                    if (Cursor < EndRow) {                        Cursor += 1;                        DataSet.RecNo = Cursor;                        DataSet.doDataChangeScroll(DataSet.RecNo);                        return;                    }                    if (!IsEndRow) {                        StartRow += 1;                        Cursor = EndRow + 1;                        DataSet.RecNo = Cursor;                    } else {                        Cursor = EndRow;                        DataSet.RecNo = Cursor;                    }                    DataSet.doDataChangeScroll(DataSet.RecNo);                }            }            if (key.equals(SDAConsts.KEY_LEFT)) {                if (StartCol > 0) {                    StartCol -= 1;                }            }            if (key.equals(SDAConsts.KEY_RIGHT)) {                if (!IsEndCol) {                    StartCol += 1;                }            }        } finally {            repaintControl();        }    }    //点击单元格事件处理       public void setOnGridCellClick(GridCellClickEvent OnGridCellClick) {        this.OnGridCellClick = OnGridCellClick;    }    public void setOnDrawGridCell(DrawGridCellEvent onDrawGridCell) {        this.onDrawGridCell = onDrawGridCell;    }    protected boolean canDownTabNext() {        boolean result = false;        if (DataSet != null) {            if (DataSet.RecNo == DataSet.getRecordCount() - 1) {                result = true;            }        } else {            result = false;        }        return result;    }    protected boolean canLeftTabPrior() {        return false;    }    protected boolean canRightTabNext() {        return false;    }    protected boolean canUpTabPrior() {        boolean result = false;        if (DataSet != null) {            if (DataSet.RecNo == 0 || DataSet.RecNo == -1) {                result = true;            }        } else {            result = false;        }        return result;    }    //焦点}

⌨️ 快捷键说明

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