📄 browsingcelleditor.java
字号:
} // ---------------------------------- protected class RendererbasePanel extends JPanel { public RendererbasePanel() { super(new BorderLayout()); setBorder(BorderFactory.createEmptyBorder(0,2,0,0)); } public void paintComponent(Graphics g) { super.paintComponent(g); // check for a selection border if (hasFocusOnLabel && focusBorderColor != null) { g.setColor(focusBorderColor); g.drawRect(0, 0, getWidth() - 1, getHeight() - 1); } } } /* protected static class MyBoundedRangeModel extends DefaultBoundedRangeModel { public MyBoundedRangeModel() { super(); } public void setExtent(int newExtent) { newExtent -= 500; super.setExtent(newExtent); } public void setRangeProperties(int newValue, int newExtent, int newMin, int newMax, boolean adjusting) { newExtent -= 500; super.setRangeProperties(newValue, newExtent, newMin, newMax, adjusting); Log.debug(this); } }*/ protected static class CellTextField extends JTextField { //MyBoundedRangeModel myModel; public CellTextField() { /* myModel = new MyBoundedRangeModel(); myModel.addChangeListener(new ScrollRepainter()); */ } /* public BoundedRangeModel getHorizontalVisibility() { return myModel; } */ /** * Gets the scroll offset, in pixels. * * @return the offset >= 0 */ /* public int getScrollOffset() { return myModel.getValue(); } */ /** * Sets the scroll offset, in pixels. * * @param scrollOffset the offset >= 0 */ /* public void setScrollOffset(int scrollOffset) { myModel.setValue(scrollOffset); } **/ /** * Scrolls the field left or right. * * @param r the region to scroll */ /* public void scrollRectToVisible(Rectangle r) { //BoundedRangeModel visibility = super.getHorizontalVisibility(); //visibility.setExtent(100); // convert to coordinate system of the bounded range BoundedRangeModel visibility = getHorizontalVisibility(); Insets i = getInsets(); int x0 = r.x + visibility.getValue() - i.left; int x1 = x0 + r.width; if (x0 < visibility.getValue()) { // Scroll to the left visibility.setValue(x0); } else if(x1 > visibility.getValue() + visibility.getExtent()) { // Scroll to the right visibility.setValue(x1 - visibility.getExtent()); } } */ public void paintComponent(Graphics g) { super.paintComponent(g); // check for a selection border if (hasFocusOnLabel && focusBorderColor != null) { int width = getWidth() - 1; int height = getHeight() - 1; g.setColor(focusBorderColor); g.drawLine(0, 0, width, 0); // top g.drawLine(0, height, width, height); // bottom //g.drawLine(0, 0, 0, height); // left } } } /* static class ScrollRepainter implements ChangeListener, Serializable { public void stateChanged(ChangeEvent e) { textField.repaint(); } } */ // ---------------------------------- private int BUTTON_WIDTH = 16; protected class BrowseButton extends JButton implements MouseListener { public BrowseButton() { setFocusPainted(false); setBorderPainted(false); setOpaque(true); //addMouseListener(this); try { setUI(new javax.swing.plaf.basic.BasicButtonUI()); } catch (NullPointerException nullExc) {} } public void paintComponent(Graphics g) { int width = getWidth(); int height = getHeight(); g.setColor(buttonBackground); g.fillRect(1, 1, width - 2, height - 1); g.setColor(iconColor); g.drawRect(2, 3, width - 5, height - 5); int y = height - 5; int x = ((width - (width - 4)) / 2) + 4; g.setColor(Color.BLACK); g.drawLine(x, y, x, y); g.drawLine(x + 3, y, x + 3, y); g.drawLine(x + 6, y, x + 6, y); } public boolean isFocusTraversable() { return false; } public void requestFocus() {}; public int getHeight() { return super.getHeight() - 2; } public Dimension getMaximumSize() { return getPreferredSize(); } public Dimension getPreferredSize() { return new Dimension(BUTTON_WIDTH + 2, getHeight()); } public void mouseReleased(MouseEvent e) { actionPerformed(new ActionEvent(this, -1, Constants.EMPTY)); } public void mouseClicked(MouseEvent e) {} public void mousePressed(MouseEvent e) {} public void mouseEntered(MouseEvent e) {} public void mouseExited(MouseEvent e) {} } // borrowed from javax.swing.DefaultCellEditor.EditorDelegate private class EditorDelegate implements ActionListener, ItemListener, Serializable { /** The value of this cell. */ protected Object value; /** * Returns the value of this cell. * @return the value of this cell */ public Object getCellEditorValue() { return textField.getText(); //return value; } /** * Sets the value of this cell. * @param value the new value of this cell */ public void setValue(Object value) { this.value = value; textField.setText((value != null) ? value.toString() : Constants.EMPTY); } /** * Returns true if <code>anEvent</code> is <b>not</b> a * <code>MouseEvent</code>. Otherwise, it returns true * if the necessary number of clicks have occurred, and * returns false otherwise. * * @param anEvent the event * @return true if cell is ready for editing, false otherwise * @see #setClickCountToStart * @see #shouldSelectCell */ public boolean isCellEditable(EventObject anEvent) { if (anEvent instanceof MouseEvent) { MouseEvent mEvent = (MouseEvent)anEvent; Point point = mEvent.getPoint(); JTable table = (JTable)mEvent.getSource(); Rectangle cellRect = table.getCellRect(table.rowAtPoint(point), table.columnAtPoint(point), true); if (mEvent.getX() >= (cellRect.x + cellRect.width - BUTTON_WIDTH)) { return true; } return mEvent.getClickCount() >= 2; } return true; } /** * Returns true to indicate that the editing cell may * be selected. * * @param anEvent the event * @return true * @see #isCellEditable */ public boolean shouldSelectCell(EventObject anEvent) { return true; } /** * Returns true to indicate that editing has begun. * * @param anEvent the event */ public boolean startCellEditing(EventObject anEvent) { return true; } /** * Stops editing and * returns true to indicate that editing has stopped. * This method calls <code>fireEditingStopped</code>. * * @return true */ public boolean stopCellEditing() { fireEditingStopped(); return true; } /** * Cancels editing. This method calls <code>fireEditingCanceled</code>. */ public void cancelCellEditing() { fireEditingCanceled(); } /** * When an action is performed, editing is ended. * @param e the action event * @see #stopCellEditing */ public void actionPerformed(ActionEvent e) { BrowsingCellEditor.this.stopCellEditing(); } /** * When an item's state changes, editing is ended. * @param e the action event * @see #stopCellEditing */ public void itemStateChanged(ItemEvent e) { BrowsingCellEditor.this.stopCellEditing(); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -