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

📄 sdagrid.java

📁 很好的UI界面源码..还有自己的输入法,可以更换风格.可以学习和使用
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
        }        public int getRowIndex() {            return rowIndex;        }    }    public SDAGrid() {        super();        internalSDAGrid();    }    private void internalSDAGrid() {        setVisible(true);        //各列        ColumnsList = new Vector();        setLeft(0);        setTop(0);        setBorderStyle(SDAConsts.bsFixedSingle);        super.setWidth(60);        //高度根据字体高度来        setHeight(getFont().getHeight() + 4);        super.setBackColor(SDAConsts.clWhite);        //单元格        cell = new Cell();        this.onPointerPressed = new PointerEvent() {            public void Event(SDABaseControl ctrl, int x, int y) {                doPointerPressed(x, y);            }        };        this.onPointerReleased = new PointerEvent() {            public void Event(SDABaseControl ctrl, int x, int y) {                doPointerReleased(x, y);            }        };        this.onKeyUp = new KeybordEvent() {            public void Event(SDABaseControl ctrl, int keyCode) {                doKeyUp(keyCode);            }        };    }    //画    public void paint() {        internalPaint();        PaintChilds();    }    private void internalPaint() {        if (!IsCanPaint()) {            return;        }        Graphics g = form.getGraphics();        //可视下才画        if (isVisible()) {            //初始化引用变量            int thisWidth = getWidth();            int thisHeight = getHeight();            int HBarWidth = getHBarWidth();            int VBarHeight = getVBarHeight();            int rowHeight = getRowHeight();            maxLineLenght = getAllWidth();            //对齐方式处理后,画组件            //设置字体            g.setFont(getFont());            SetClip(g);            //外框            if (!isTransparent()) {                g.setColor(backColor);                fillRect(g, 0, 0, thisWidth, thisHeight);            }            //fixed                       g.setColor(FixedColor);            fillRect(g, 0, 0, FixedWidth, thisHeight);            fillRect(g, 0, 0, thisWidth, rowHeight);            g.setColor(borderColor);            drawRect(g, 0, 0, FixedWidth, thisHeight);            drawRect(g, 0, 0, thisWidth, rowHeight);            //是否显示统计行            int footheight = showFootRow ? rowHeight : 0;            //画横线,结合行高            int H = rowHeight;            if (DataSet != null) {                while (H < thisHeight - RowHeight - footheight) {                    H += rowHeight;                    drawLine(g, 0, 0 + H, thisWidth, H);                }            }            //画统计行            if (showFootRow) {                g.setColor(FixedColor);                fillRect(g, 0, thisHeight - barwidth - rowHeight, FixedWidth, rowHeight);                g.setColor(footRowColor);                fillRect(g, FixedWidth + 1, thisHeight - barwidth - rowHeight, thisWidth, rowHeight);                g.setColor(borderColor);                drawRect(g, 0, thisHeight - barwidth - rowHeight, thisWidth, rowHeight);                drawRect(g, 0, thisHeight - barwidth - rowHeight, FixedWidth, rowHeight);            }            //边框            if (borderStyle == SDAConsts.bsFixed3D) {                g.setColor(SDAConsts.clGray);                drawLine(g, 0, 0, thisWidth, 0);                drawLine(g, 0, 0, 0, thisHeight);                g.setColor(SDAConsts.clBlack);                drawLine(g, 1, 1, thisWidth - 1, 1);                drawLine(g, 1, 1, 1, thisHeight - 1);                g.setColor(SDAConsts.clBtnFace);                drawLine(g, 2, thisHeight - 1, thisWidth - 2, thisHeight - 1);                drawLine(g, thisWidth - 1, 2, thisWidth - 1, thisHeight - 1);                g.setColor(SDAConsts.clWhite);                drawLine(g, 1, thisHeight, thisWidth, thisHeight);                drawLine(g, thisWidth, 1, thisWidth, thisHeight);            }            if (borderStyle == SDAConsts.bsFixedSingle) {                //边框                g.setColor(this.getBorderColor());                drawRect(g, 0, 0, thisWidth, thisHeight);            }            //如果没数据就停止            if (DataSet.getRecordCount() == 0) {                DataSet.RecNo = 0;            }            //Title            int V = FixedWidth;            Column ct;            //输出区域            int sWidth = 0;            int sHeight = 0;            if (DataSet != null) {                Cursor = DataSet.RecNo;                if (StartRow > Cursor) {                    StartRow = Cursor;                }                int maxRowCount = getMaxRowsNum();                if (StartRow + maxRowCount - 1 < Cursor) {                    StartRow = Cursor - maxRowCount + 1;                }                for (int i = StartCol; i < getColumnsCount(); i++) {                    ct = getColumn(i);                    if (V + ct.ColWidth > thisWidth) {                        int imwidth = thisWidth - V;                        sWidth = imwidth - 1;                        sHeight = rowHeight - 1;                    } else {                        sWidth = ct.ColWidth - 1;                        sHeight = rowHeight - 1;                    }                    g.setColor(FixedColor);                    SetClip(g, V + 1, 1, sWidth, sHeight);                    fillRect(g, V + 1, 1, sWidth, sHeight);                    g.setColor(foreColor);                    if (ct.titleAlignType == SDAConsts.alignLeft) {                        drawString(g, ct.Title, V + 1, 1);                    } else if (ct.titleAlignType == SDAConsts.alignCenter) {                        drawString(g, ct.Title, V + 1 + (sWidth - getFont().stringWidth(ct.Title)) / 2, 1);                    } else {                        drawString(g, ct.Title, V + 1 + sWidth - getFont().stringWidth(ct.Title), 1);                    }                    //画排序符号                    if (ct.FieldName.equals(sortFieldName)) {                        g.setColor(borderColor);                        if (sortType == SDADataSet.sortAsc) {                            //升序                            fillTriangle(g, V + ct.ColWidth - 5, rowHeight / 2 - 2,                                    V + ct.ColWidth - 9, rowHeight / 2 + 2,                                    V + ct.ColWidth - 1, rowHeight / 2 + 2);                        } else {                            fillTriangle(g, V + ct.ColWidth - 9, rowHeight / 2 - 2,                                    V + ct.ColWidth - 1, rowHeight / 2 - 2, V + ct.ColWidth - 5, rowHeight / 2 + 2);                        }                    }                    //统计字段                    if (showFootRow) {                        //列统计信息                        SetClip(g, V + 1, thisHeight - barwidth - rowHeight, sWidth, sHeight);                        switch (ct.footType) {                            case Column.ftNone: {                                //不显示任何内容                                ct.footValue = "";                                break;                            }                            case Column.ftCount: {                                //行数统计                                if (!ct.footDisplayFormat.equals("")) {                                    ct.footValue = SDATools.formatFloat(ct.footDisplayFormat, DataSet.getRecordCount());                                } else {                                    ct.footValue = String.valueOf(DataSet.getRecordCount());                                }                                break;                            }                            case Column.ftStaticText: {                                //显示已经设置的内容                                break;                            }                            case Column.ftFieldValue: {                                //显示当前行的内容                                if (!ct.footDisplayFormat.equals("")) {                                    ct.footValue = SDATools.formatFloat(ct.footDisplayFormat, Double.parseDouble(DataSet.getRow().getValueByFieldName(ct.FieldName)));                                } else {                                    ct.footValue = DataSet.getRow().getValueByFieldName(ct.FieldName);                                }                                break;                            }                            case Column.ftAvg: {                                //计算平均值                                double avg = 0.0;                                String st;                                for (int j = 0; j < DataSet.getRecordCount(); j++) {                                    st = DataSet.getRow(j).getValueByFieldName(ct.FieldName);                                    if ((st == null) || (st.equals(""))) {                                        st = "0";                                    }                                    avg += Double.parseDouble(st);                                }                                if (!ct.footDisplayFormat.equals("")) {                                    if (DataSet.getRecordCount() > 0) {                                        ct.footValue = SDATools.formatFloat(ct.footDisplayFormat, avg / DataSet.getRecordCount());                                    } else {                                        ct.footValue = "";                                    }                                } else {                                    ct.footValue = String.valueOf(avg / DataSet.getRecordCount());                                }                                break;                            }                            case Column.ftSum: {                                //汇总                                double sum = 0.0;                                String st;                                for (int j = 0; j < DataSet.getRecordCount(); j++) {                                    st = DataSet.getRow(j).getValueByFieldName(ct.FieldName);                                    if (st == null) {                                        st = "0";                                    }                                    sum += Double.parseDouble(st);                                }                                if (!ct.footDisplayFormat.equals("")) {                                    ct.footValue = SDATools.formatFloat(ct.footDisplayFormat, sum);                                } else {                                    ct.footValue = String.valueOf(sum);                                }                                break;                            }                        }                        if (ct.footAlignType == SDAConsts.alignLeft) {                            drawString(g, ct.footValue, V + 1, thisHeight - barwidth - rowHeight + 1);                        } else if (ct.footAlignType == SDAConsts.alignCenter) {                            drawString(g, ct.footValue, V + 1 + (sWidth - getFont().stringWidth(ct.footValue)) / 2, thisHeight - barwidth - rowHeight + 1);                        } else {                            drawString(g, ct.footValue, V + 1 + sWidth - getFont().stringWidth(ct.footValue), thisHeight - barwidth - rowHeight + 1);                        }                    }                    SetClip(g);                    V += ct.ColWidth;                    //画线                    drawLine(g, V, 0, V, thisHeight);                    if (V > thisWidth) {                        IsEndCol = false;                        break;                    } else {                        IsEndCol = true;                    }                }                //绘数据                SDADataSet.Row row;                for (int i = StartRow;                        i < DataSet.getRecordCount();                        i++) {                    V = FixedWidth;                    row = DataSet.getRow(i);                    SetClip(g, V, (i - StartRow + 1) * rowHeight, thisWidth - V, rowHeight);                    if (Cursor == i) {                        g.setColor(selectedBackColor);                    } else {                        g.setColor(backColor);                    }                    fillRect(g, V, (i - StartRow + 1) * rowHeight, thisWidth - V, rowHeight);                    g.setColor(borderColor);                    drawRect(g, V, (i - StartRow + 1) * rowHeight, thisWidth - V, rowHeight);                    for (int j = StartCol;                            j < getColumnsCount();                            j++) {                        ct = getColumn(j);                        //从当前起始列开始画                        int imw;                        int imh;                        if (V + ct.ColWidth > thisWidth) {                            imw = thisWidth - V;                        } else {                            imw = ct.ColWidth;                        }                        imh = rowHeight;                        String drawstr = row.getValueByFieldName(ct.FieldName);                        if (drawstr == null) {                            drawstr = "";                        }                        //格式化                        if (!ct.DisplayFormat.equals("")) {                            if (drawstr.equals("")) {                                drawstr = "0";                            }                            drawstr = SDATools.formatFloat(ct.DisplayFormat, Double.parseDouble(drawstr));                        }                        cell.fieldValue = drawstr;                        cell.fieldName = ct.FieldName;                        cell.rowIndex = i;                        //cell.backColor                        if (Cursor == i) {                            if (isFoucsed()) {                                cell.backColor = selectedBackColor;                                cell.foreColor = selectedFontColor;                            } else {                                cell.backColor = lostFocusSelectedBackColor;                                cell.foreColor = selectedFontColor;                            }                        } else {                            cell.backColor = backColor;                            cell.foreColor = foreColor;                            //////////事件                            if (this.onDrawGridCell != null) {                                onDrawGridCell.Event(cell);                            }                        }                        g.setColor(cell.backColor);                        fillRect(g, V, (i - StartRow + 1) * rowHeight, imw, imh);                        g.setColor(borderColor);                        drawRect(g, V, (i - StartRow + 1) * rowHeight, imw, imh);                        ///////////////                        g.setColor(cell.foreColor);                        if (ct.dataAlignType == SDAConsts.alignLeft) {                            drawString(g, drawstr, V + 2, (i - StartRow + 1) * rowHeight + 1);                        } else if (ct.dataAlignType == SDAConsts.alignCenter) {                            drawString(g, drawstr, V + 1 + (ct.ColWidth - getFont().stringWidth(drawstr)) / 2, (i - StartRow + 1) * rowHeight + 1);                        } else {                            drawString(g, drawstr, V + 1 + ct.ColWidth - getFont().stringWidth(drawstr) - 1, (i - StartRow + 1) * rowHeight + 1);                        }                        //向后移动                        V += ct.ColWidth;                        //判断                        if (V > thisWidth) {                            break;                        }                    }                    if ((i - StartRow + 2) * rowHeight > thisHeight - barwidth - footheight - rowHeight) {                        if (i == DataSet.getRecordCount() - 1) {                            IsEndRow = true;                            EndRow = i;                        } else {                            IsEndRow = false;                            EndRow = i;                            break;                        }                    } else {                        IsEndRow = true;                        EndRow = i;                    }                }                //调整指针                if (Cursor < StartRow) {                    Cursor = StartRow;                    DataSet.doDataChangeScroll(Cursor);

⌨️ 快捷键说明

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