📄 lwgrid.java
字号:
*/ public void setCellInsets (int t, int l, int b, int r) { Insets i = new Insets ((t<0)?cellInsets.top:t, (l<0)?cellInsets.left:l, (b<0)?cellInsets.bottom:b, (r<0)?cellInsets.right:r); if (!i.equals (cellInsets)) { cellInsets = i; iMetric(); repaint(); } } /** * Sets the grid lines color. * @param <code>c</code> the grid lines color. */ public void setNetColor (Color c) { if (!c.equals(netColor)) { netColor = c; repaint(); } } public void matrixResized(MatrixEvent e) { iMetric(); if (controller != null && controller.getCurrentLine() >= getGridRows()) controller.clearPos(); } public void cellModified (MatrixEvent e) { if (isUsePsMetric()) iMetric(); } public /*C#override*/ void paint(Graphics g) { vVisibility(); if (visibility.hasVisibleCells()) { paintData (g); paintNet (g); } } public /*C#override*/ void paintOnTop(Graphics g) { vVisibility(); if (visibility.hasVisibleCells()) paintMarker(g); } public /*C#override*/ void validate () { vMetric(); super.validate(); } public /*C#override*/ void invalidate() { super.invalidate(); iColVisibility(); iRowVisibility(); } public /*C#virtual*/ void setRowHeight (int row, int h) { if (!isUsePsMetric()) { vMetric(); if (rowHeight(row) != h) { stopEditing(false); int dy = h - rowHeight(row); rowHeights[row] = h; psSize.height += dy; updateCashedPs(-1, psSize.height); if (man != null) man.scrollObjResized (psSize.width, psSize.height); vrp(); } } } public /*C#virtual*/ void setColWidth (int col, int w) { if (!isUsePsMetric()) { vMetric(); if (colWidth(col) != w) { stopEditing(false); int dx = w - colWidth(col); colWidths[col] = w; psSize.width += dx; updateCashedPs(psSize.width, -1); if (man != null) man.scrollObjResized (psSize.width, psSize.height); vrp(); } } } public /*C#override*/ Point getOrigin () { return new Point (dx, dy); } public /*C#virtual*/ Point getSOLocation() { return getOrigin (); } public /*C#virtual*/ void setSOLocation(int x, int y) { if (x != dx || y != dy) { int offx = x - dx, offy = y - dy; dx = x; dy = y; if (offx != 0) iColVisibility(); if (offy != 0) iRowVisibility(); rVisibility(offx, offy); stopEditing(false); repaint(); } } public /*C#virtual*/ Dimension getSOSize() { return getPreferredSize(); } public boolean moveContent() { return true; } public void setScrollMan (ScrollMan m) { man = m; } public /*C#virtual*/ void mouseClicked (LwMouseEvent e) {} public /*C#virtual*/ void mouseEntered (LwMouseEvent e) {} public /*C#virtual*/ void mouseExited (LwMouseEvent e) {} public /*C#virtual*/ void mouseReleased(LwMouseEvent e) {} public /*C#virtual*/ void mousePressed (LwMouseEvent e) { if (visibility.hasVisibleCells()) { stopEditing(true); if (LwToolkit.isActionMask(e.getMask())) { Point p = cellByLocation(e.getX(), e.getY()); if (p != null) { if (controller != null) { int off = controller.getCurrentLine(); if (off == p.x) calcOrigin(off, getRowY(off)); else controller.setOffset (p.x); } if (editors != null && editors.shouldStartEdit(p.x, p.y, e)) startEditing(p.x, p.y); } } } } public int getLines() { return getGridRows(); } public int getLineSize(int line) { return 1; } public int getMaxOffset() { return getGridRows()-1; } public /*C#virtual*/ void posChanged(PosEvent e) { int off = controller.getCurrentLine(); if (off >= 0) { int y = getRowY(off); Point o = calcOrigin(off, y); int poff = e.getPrevOffset(); if (poff >= 0) { int yy = getRowY(poff); repaint (0, Math.min(yy, y) + dy, width, Math.abs(yy - y) + rowHeight(Math.max(off, poff))); } else repaint (); } } public /*C#virtual*/ void keyPressed(LwKeyEvent e) { if (controller != null) { boolean ctrl = (e.getMask() & KeyEvent.CTRL_MASK) > 0; switch (e.getKeyCode()) { case KeyEvent.VK_LEFT : controller.seek(-1); break; case KeyEvent.VK_UP : controller.seekLineTo(PosController.UP); break; case KeyEvent.VK_RIGHT : controller.seek(1); break; case KeyEvent.VK_DOWN : controller.seekLineTo(PosController.DOWN); break; case KeyEvent.VK_PAGE_UP : controller.seekLineTo(PosController.UP, pageSize(-1)); break; case KeyEvent.VK_PAGE_DOWN: controller.seekLineTo(PosController.DOWN, pageSize(1)); break; case KeyEvent.VK_END : if (ctrl) controller.setOffset(getLines()-1); break; case KeyEvent.VK_HOME : if (ctrl) controller.setOffset(0); break; } } } public /*C#virtual*/ void keyReleased(LwKeyEvent e) {} public /*C#virtual*/ void keyTyped (LwKeyEvent e) {} public /*C#virtual*/ void focusGained(LwFocusEvent e) {} public /*C#virtual*/ void focusLost (LwFocusEvent e) {} public /*C#virtual*/ void layout(LayoutContainer target) { if (topCaption != null && topCaption.isVisible()) { Insets i = getInsets(); topCaption.setLocation (i.left, i.top); Dimension d = topCaption.getPreferredSize(); topCaption.setSize(Math.min(target.getWidth() - i.left - i.right, psSize.width), d.height); } if (editors != null && editor != null && editor.isVisible()) { int w = getColWidth(editingCol), h = getRowHeight(editingRow); int x = getColX(editingCol), y = getRowY(editingRow); if (isUsePsMetric()) { x += cellInsets.left; y += cellInsets.top; w -= (cellInsets.left + cellInsets.right); h -= (cellInsets.top + cellInsets.bottom); } editor.setLocation(x + dx, y + dy); editor.setSize(w, h); LwFocusManager.manager.requestFocus((LwComponent)editor); } } public /*C#virtual*/ void componentAdded(Object id, Layoutable lw, int index) { if (id != null) { if (id.equals(TOP_CAPTION_EL)) topCaption = (LwComponent)lw; else if (id.equals(EDITOR_EL)) editor = (LwComponent)lw; } } public /*C#virtual*/ void componentRemoved(Layoutable lw, int index) { if (lw == editor) editor = null; else if (lw == topCaption) topCaption = null; } public /*C#virtual*/ Dimension calcPreferredSize(LayoutContainer target) { return new Dimension (psSize.width, psSize.height + getTopCaptionHeight()); } public /*C#virtual*/ int getGridRows() { return data.getRows(); } public /*C#virtual*/ int getGridCols() { return data.getCols(); } public /*C#virtual*/ int getRowHeight(int row) { vMetric(); return rowHeight(row); } public /*C#virtual*/ int getColWidth (int col) { vMetric(); return colWidth(col); } public CellsVisibility getCellsVisibility() { vVisibility(); return visibility; } public int getNetGap() { return netSize; } public /*C#virtual*/ int getColX (int col) { vVisibility(); int start = 0, d = 1; int x = getInsets().left + netSize; if (visibility.hasVisibleCells()) { start = visibility.fc.x; x = visibility.fc.y; d = (col > visibility.fc.x)?1:-1; } for (int i=start; i != col; x += ((colWidth(i) + netSize)*d), i+=d); return x; } public /*C#virtual*/ int getRowY (int row) { vVisibility(); int start = 0, d = 1; int y = getInsets().top + getTopCaptionHeight() + netSize; if (visibility.hasVisibleCells()) { start = visibility.fr.x; y = visibility.fr.y; d = (row > visibility.fr.x)?1:-1; } for (int i=start; i != row; y += ((rowHeight(i) + netSize)*d), i+=d); return y; } public void childPerformed(LwAWTEvent e) { if (e.getID() == LwKeyEvent.KEY_PRESSED && ((LwKeyEvent)e).getKeyCode() == KeyEvent.VK_ESCAPE) stopEditing(false); } /** * Starts editing of the specified grid cell. The method initiates editing process if * the editor provider has been defined for the grid component and the editor component * exists. * @param <code>row</code> the specified cell row. * @param <code>col</code> the specified cell column. */ public /*C#virtual*/ void startEditing (int row, int col) { stopEditing (true); if (editors != null) { LwComponent editor = editors.getEditor(row, col, getDataToEdit(row, col)); if (editor != null) { editingRow = row; editingCol = col; add(EDITOR_EL, editor); repaint(); } } } /** * Stops the cell editing. The method has effect if the editing process has been initiated * before. * @param <code>applyData</code> use <code>true</code> value if the edited data should be * applied to data model, use <code>false</code> otherwise. */ public /*C#virtual*/ void stopEditing (boolean applyData) { if (editors != null && editingRow >= 0 && editingCol >= 0) { try { Object v = editors.fetchEditedValue (editingRow, editingCol, (LwComponent)editor); if (applyData) setEditedData(editingRow, editingCol, v); } finally { editingRow = -1; editingCol = -1; int index = indexOf((LwComponent)editor); if (index >= 0) remove(index); repaint(); } } } /** * Gets the grid top caption component. * @return a grid top caption component. */ public LwComponent getTopCaption() { return topCaption; } /** * Returns the specified column width. The method is used by all other methods * (except recalculation) to get the actual column width. * @param <code>col</code> the specified column. * @return the specified column width. */ protected /*C#virtual*/ int colWidth (int col) { return colWidths[col]; } /** * Returns the specified row height. The method is used by all other methods * (except recalculation) to get the actual row height. * @param <code>row</code> the specified row. * @return the specified row height. */ protected /*C#virtual*/ int rowHeight (int row) { return rowHeights[row]; } /** * Invoked whenever the component wants fetch data from the data model for * the specified cell editing. * @param <code>row</code> the specified row. * @param <code>col</code> the specified column. * @return data model value to edit. */ protected /*C#virtual*/ Object getDataToEdit (int row, int col) { return data.get(row, col); } /** * Invoked whenever the component wants applies the edited value (for the specified cell) * to the grid data model. * @param <code>row</code> the specified row. * @param <code>col</code> the specified column. * @param <code>value</code> the specified edited value. */ protected /*C#virtual*/ void setEditedData (int row, int col, Object value) { data.put (row, col, value); } /** * Checks if the grid metric is valid. * @return <code>true</code> if the grid metric is valid; <code>false</code> otherwise. */ protected /*C#virtual*/ boolean isMetricValid() { return MathBox.checkBit(bits, METRIC_VALID); } /** * Invoked whenever the component paints the specified cell to fetch data from the * grid data model. * @param <code>row</code> the specified row. * @param <code>col</code> the specified column.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -