@Override public void mouseMoved(MouseEvent e) { Point pt = e.getPoint(); int prevRow = row; int prevCol = col; row = table.rowAtPoint(pt); col = table.columnAtPoint(pt); if (row < 0 || col < 0) { row = -1; col = -1; } // >>>> HyperlinkCellRenderer.java // @see // http://java.net/projects/swingset3/sources/svn/content/trunk/SwingSet3/src/com/sun/swingset3/demos/table/HyperlinkCellRenderer.java if (row == prevRow && col == prevCol) { return; } Rectangle repaintRect; if (row >= 0 && col >= 0) { Rectangle r = table.getCellRect(row, col, false); if (prevRow >= 0 && prevCol >= 0) { repaintRect = r.union(table.getCellRect(prevRow, prevCol, false)); } else { repaintRect = r; } } else { repaintRect = table.getCellRect(prevRow, prevCol, false); } table.repaint(repaintRect); // <<<< // table.repaint(); }
protected void customizeCellRenderer( final JTable table, final Object value, final boolean selected, final boolean hasFocus, final int row, final int column) { if (myListener == null) { myListener = new MergeSourceDetailsLinkListener(MERGE_SOURCE_DETAILS_TAG, myFile); myListener.install(table); } if (!(value instanceof SvnFileRevision)) { append("", SimpleTextAttributes.REGULAR_ATTRIBUTES); return; } final SvnFileRevision revision = (SvnFileRevision) value; final String text = getText(revision); if (text.length() == 0) { append("", SimpleTextAttributes.REGULAR_ATTRIBUTES); return; } append( cutString(text, table.getCellRect(row, column, false).getWidth()), SimpleTextAttributes.REGULAR_ATTRIBUTES); }
/** Sets the call stack with the given vector of method names. */ public void setContents(Vector newMethodNames) { methodNames = (Vector) newMethodNames.clone(); callStackTable.revalidate(); Rectangle r = callStackTable.getCellRect(newMethodNames.size() - 1, 0, true); callStackTable.scrollRectToVisible(r); repaint(); }
@Override public void mouseExited(MouseEvent e) { if (row >= 0 && col >= 0) { table.repaint(table.getCellRect(row, col, false)); } row = -1; col = -1; }
/** Returns the coordinates of the top left corner of the value at the given index. */ public Point getCoordinates(int index) { JScrollBar bar = scrollPane.getVerticalScrollBar(); Rectangle r = segmentTable.getCellRect(index, 1, true); segmentTable.scrollRectToVisible(r); setTopLevelLocation(); return new Point( (int) (r.getX() + topLevelLocation.getX()), (int) (r.getY() + topLevelLocation.getY())); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { setFont(font); setBackground(isSelected ? selBackground : background); setForeground(isSelected ? selForeground : foreground); Rectangle rect = table.getCellRect(row, column, true); setSize(rect.width, rect.height); setText(value != null ? value.toString() : ""); return this; }
private void appendMergeSourceText(JTable table, int row, int column, @Nullable String text) { if (StringUtil.isEmpty(text)) { append("", SimpleTextAttributes.REGULAR_ATTRIBUTES); } else { append( cutString(text, table.getCellRect(row, column, false).getWidth()), SimpleTextAttributes.REGULAR_ATTRIBUTES, MERGE_SOURCE_DETAILS_TAG); } }
private int getResizingRow(Point p, int row) { if (row == -1) { return -1; } int col = table.columnAtPoint(p); if (col == -1) return -1; Rectangle r = table.getCellRect(row, col, true); r.grow(0, -3); if (r.contains(p)) return -1; int midPoint = r.y + r.height / 2; int rowIndex = (p.y < midPoint) ? row - 1 : row; return rowIndex; }
public void scrollToColumnLocation(int colIndex) { JTable scrollTable = transposedSpreadsheetSubform.getScrollTable(); scrollTable.setColumnSelectionInterval(colIndex, colIndex); JViewport scrollPane = transposedSpreadsheetSubform.getFrozenTable().getViewport(); Rectangle rect = scrollTable.getCellRect(1, colIndex, true); Point p = scrollPane.getViewPosition(); rect.setLocation(rect.x - p.x, rect.y - p.y); scrollPane.scrollRectToVisible(rect); Map<Integer, Color> columnToColor = new HashMap<Integer, Color>(); columnToColor.put(colIndex, new Color(28, 117, 188, 70)); transposedSpreadsheetSubform.changeTableRenderer( transposedSpreadsheetSubform.getScrollTable(), new SubFormCellRenderer( UIHelper.VER_11_PLAIN, UIHelper.DARK_GREEN_COLOR, null, columnToColor)); transposedSpreadsheetSubform.validate(); transposedSpreadsheetSubform.repaint(); }
@NotNull @Override public RelativePoint guessBestPopupLocation(@NotNull final JComponent component) { Point popupMenuPoint = null; final Rectangle visibleRect = component.getVisibleRect(); if (component instanceof JList) { // JList JList list = (JList) component; int firstVisibleIndex = list.getFirstVisibleIndex(); int lastVisibleIndex = list.getLastVisibleIndex(); int[] selectedIndices = list.getSelectedIndices(); for (int index : selectedIndices) { if (firstVisibleIndex <= index && index <= lastVisibleIndex) { Rectangle cellBounds = list.getCellBounds(index, index); popupMenuPoint = new Point(visibleRect.x + visibleRect.width / 4, cellBounds.y + cellBounds.height); break; } } } else if (component instanceof JTree) { // JTree JTree tree = (JTree) component; int[] selectionRows = tree.getSelectionRows(); if (selectionRows != null) { Arrays.sort(selectionRows); for (int i = 0; i < selectionRows.length; i++) { int row = selectionRows[i]; Rectangle rowBounds = tree.getRowBounds(row); if (visibleRect.contains(rowBounds)) { popupMenuPoint = new Point(rowBounds.x + 2, rowBounds.y + rowBounds.height - 1); break; } } if (popupMenuPoint == null) { // All selected rows are out of visible rect Point visibleCenter = new Point( visibleRect.x + visibleRect.width / 2, visibleRect.y + visibleRect.height / 2); double minDistance = Double.POSITIVE_INFINITY; int bestRow = -1; Point rowCenter; double distance; for (int i = 0; i < selectionRows.length; i++) { int row = selectionRows[i]; Rectangle rowBounds = tree.getRowBounds(row); rowCenter = new Point(rowBounds.x + rowBounds.width / 2, rowBounds.y + rowBounds.height / 2); distance = visibleCenter.distance(rowCenter); if (minDistance > distance) { minDistance = distance; bestRow = row; } } if (bestRow != -1) { Rectangle rowBounds = tree.getRowBounds(bestRow); tree.scrollRectToVisible( new Rectangle( rowBounds.x, rowBounds.y, Math.min(visibleRect.width, rowBounds.width), rowBounds.height)); popupMenuPoint = new Point(rowBounds.x + 2, rowBounds.y + rowBounds.height - 1); } } } } else if (component instanceof JTable) { JTable table = (JTable) component; int column = table.getColumnModel().getSelectionModel().getLeadSelectionIndex(); int row = Math.max( table.getSelectionModel().getLeadSelectionIndex(), table.getSelectionModel().getAnchorSelectionIndex()); Rectangle rect = table.getCellRect(row, column, false); if (!visibleRect.intersects(rect)) { table.scrollRectToVisible(rect); } popupMenuPoint = new Point(rect.x, rect.y + rect.height); } else if (component instanceof PopupOwner) { popupMenuPoint = ((PopupOwner) component).getBestPopupPosition(); } if (popupMenuPoint == null) { popupMenuPoint = new Point(visibleRect.x + visibleRect.width / 2, visibleRect.y + visibleRect.height / 2); } return new RelativePoint(component, popupMenuPoint); }
/** * Sets the starting address with the given address. This should display the relevant memory * segment (the data should be taken from the main memory gui). */ public void setValueAt(int index, short value) { Rectangle r = segmentTable.getCellRect(index, 0, true); segmentTable.scrollRectToVisible(r); repaint(); }