public void actionPerformed(ActionEvent e) { int row = getSelectedRow(); int col = getSelectedColumn(); if (col == 0) { col = 1; } editCellAt(row, col, null); }
/** Sets x position. */ public void setPositionX(int x) { if (x == positionX || !treeHScrollingEnabled) return; int old = positionX; positionX = x; firePropertyChange("positionX", old, x); if (isEditing() && getEditingColumn() == getTreeColumnIndex()) { CellEditor editor = getCellEditor(); if (ignoreScrolling && editor instanceof TreeTableCellEditor) { ((TreeTableCellEditor)editor).revalidateTextField(); } else { removeEditor(); } } repaint(); }
/** Overridden to manually draw the focused rectangle for the tree column */ @Override public void paintComponent(Graphics g) { super.paintComponent(g); if (hasFocus() && (getSelectedColumn() == 0) && (getSelectedRow() > 0)) { Color bdr = UIManager.getColor("Tree.selectionBorderColor"); //NOI18N if (bdr == null) { //Button focus color doesn't work on win classic - better to //get the color from a value we know will work - Tim if (getForeground().equals(Color.BLACK)) { //typical bdr = getBackground().darker(); } else { bdr = getForeground().darker(); } } g.setColor(bdr); Rectangle r = getCellRect(getSelectedRow(), getSelectedColumn(), false); g.drawRect(r.x + 1, r.y + 1, r.width - 3, r.height - 3); } }
public void actionPerformed(java.awt.event.ActionEvent e) { if (lastRow != -1) { editCellAt(lastRow, getTreeColumnIndex(), new EventObject( timer )); } }
public TreeTable(NodeTreeModel treeModel, NodeTableModel tableModel) { super(); setSurrendersFocusOnKeystroke(true); this.tree = new TreeTableCellRenderer(treeModel); this.tableModel = new TreeTableModelAdapter(tree, tableModel); tree.setCellRenderer(new NodeRenderer()); // Install a tableModel representing the visible rows in the tree. setModel(this.tableModel); // Force the JTable and JTree to share their row selection models. selectionWrapper = new ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); getTableHeader().setReorderingAllowed(false); // Install the tree editor renderer and editor. setDefaultRenderer(TreeTableModelAdapter.class, tree); // Install property renderer and editor. tableCell = new TableSheetCell(this.tableModel); tableCell.setFlat(true); setDefaultRenderer(Property.class, tableCell); setDefaultEditor(Property.class, tableCell); getTableHeader().setDefaultRenderer(tableCell); getAccessibleContext().setAccessibleName(NbBundle.getMessage(TreeTable.class, "ACSN_TreeTable")); // NOI18N getAccessibleContext().setAccessibleDescription( // NOI18N NbBundle.getMessage(TreeTable.class, "ACSD_TreeTable")); // NOI18N setFocusCycleRoot(true); setFocusTraversalPolicy(new STPolicy()); putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); initKeysAndActions(); }
public void actionPerformed(ActionEvent e) { if (isEditing()) { removeEditor(); if (getSelectedColumn() == (getColumnCount() - 1)) { targetColumn = 0; targetRow = getSelectedRow() + 1; } else { targetColumn = getSelectedColumn() + 1; targetRow = getSelectedRow(); if (getSelectedColumn() <= 0) { targetColumn = getColumnCount() - 1; targetRow = getSelectedRow() - 1; } else { targetRow = getSelectedRow(); targetColumn = getSelectedColumn() - 1; if ((targetRow >= getRowCount()) || (targetRow < 0)) { Container ancestor = getFocusCycleRootAncestor(); ? ancestor.getFocusTraversalPolicy().getComponentAfter(ancestor, TreeTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, TreeTable.this); JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); changeSelection( direction ? 0 : (getRowCount() - 1), direction ? 0 : (getColumnCount() - 1), false, false
if ((row >= getRowCount()) || (row < 0) || (column > getColumnCount()) || (column < 0)) { if ((editingRow == row) && (editingColumn == column) && isEditing()) { if (isEditing()) { inEditorChangeRequest = true; removeEditor(); changeSelection(row, column, false, false); } finally { inEditorChangeRequest = false; boolean editable = getModel().isCellEditable(row, column); for (int i = column; i < getColumnCount(); i++) { if (getModel().isCellEditable(row, i)) { columnShifted = i != column; column = i; changeSelection(row, column, false, false); final Rectangle r = getCellRect(row, column, true); Object o = getValueAt(row, column); repaint(r.x, r.y, r.width, r.height); if (column == getTreeColumnIndex()) { ignoreScrolling = true; tree.scrollRectToVisible(tree.getRowBounds(row));
/** Repaint the selected row */ private void repaintSelection(boolean focused) { int start = getSelectionModel().getMinSelectionIndex(); int end = getSelectionModel().getMaxSelectionIndex(); if (end != -1) { if (end != start) { Rectangle begin = getCellRect(start, 0, false); Rectangle r = getCellRect(end, 0, false); r.y =begin.y; r.x = 0; r.width = getWidth(); r.height = r.y + r.height - begin.y; repaint (r.x, r.y, r.width, r.height); } else { Rectangle r = getCellRect(start, 0, false); r.width = getWidth(); r.x = 0; repaint (r.x, r.y, r.width, r.height); } } if (isEditing() && editorComp != null) { editorComp.setBackground(focused ? getSelectionBackground() : getUnfocusedSelectedBackground()); editorComp.setForeground(focused ? getSelectionForeground() : getUnfocusedSelectedForeground()); } }
@Override public void tableChanged(TableModelEvent e) { // update tree column name int modelColumn = getTreeColumnIndex(); if ((e.getFirstRow() <= 0) && (modelColumn != -1) && (getColumnCount() > 0)) { String columnName = getModel().getColumnName(modelColumn); TableColumn aColumn = getColumnModel().getColumn(modelColumn); aColumn.setHeaderValue(columnName); } ignoreClearSelection = true; try { super.tableChanged(e); //#61728 - force update of tree's horizontal scrollbar if( null != getTree() ) { firePropertyChange( "positionX", -1, getPositionX() ); } } finally { ignoreClearSelection = false; } }
private void initKeysAndActions() { setFocusTraversalKeys(KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet()); setFocusTraversalKeys(KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS, Collections.<AWTKeyStroke>emptySet()); unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)); unregisterKeyboardAction(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, Event.SHIFT_MASK)); InputMap imp = getInputMap(WHEN_FOCUSED); InputMap imp2 = getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); ActionMap am = getActionMap(); getActionMap().put( "selectNextColumn", // NOI18N new TreeTableAction( tree.getActionMap().get("selectChild"), // NOI18N getActionMap().get("selectNextColumn") "selectPreviousColumn", // NOI18N new TreeTableAction( tree.getActionMap().get("selectParent"), // NOI18N getActionMap().get("selectPreviousColumn") getAccessibleContext().setAccessibleName(NbBundle.getMessage(TreeTable.class, "ACSN_TreeTable")); // NOI18N getAccessibleContext().setAccessibleDescription( // NOI18N NbBundle.getMessage(TreeTable.class, "ACSD_TreeTable")); // NOI18N getActionMap().put("beginEdit", new EditAction()); getActionMap().put("cancelEdit", new CancelEditAction());
private void revalidateTextField() { int row = TreeTable.this.editingRow; if (row == -1) { offset = 0; return; } determineOffset(tree.getPathForRow(row).getLastPathComponent(), TreeTable.this.isRowSelected(row), row); ((TreeTableTextField) super.getComponent()).offset = offset; getComponent().setBounds(TreeTable.this.getCellRect(row, getTreeColumnIndex(), false)); }
int column = getTreeColumnIndex(); TreePath path = tree.getPathForRow(TreeTable.this.rowAtPoint(me.getPoint())); Rectangle r = tree.getPathBounds(path); me.getX() - getCellRect(0, column, true).x + positionX, me.getY(), me.getClickCount(), me.isPopupTrigger() );
public TreetableWithoutSelectionBackground() { TreeTable treeTable = new TreeTable(); treeTable.setSelectable(true); treeTable.setItemCaptionMode(AbstractSelect.ItemCaptionMode.ID); treeTable.setItemCaptionPropertyId("caption"); treeTable.setCellStyleGenerator((source, itemId, propertyId) -> ((MyBean) itemId).shouldHaveBackground() ? null : "no-background"); treeTable.setContainerDataSource(container);
TreeTable tt = new TreeTable(treeModel, tableModel); treeTable = tt; tree = ((TreeTable) treeTable).getTree(); TableQuickSearchSupport tqss = new TableQuickSearchSupport(tt, tt.getQuickSearchTableFilter(), tt.getQuickSearchSettings()); quickSearch = QuickSearch.attach(this, searchConstraints, tqss, tqss.createSearchPopupMenu()); tt.addKeyListener(new KeyListener() { @Override public void keyTyped(KeyEvent e) {
public void columnMoved(TableColumnModelEvent e) { super.columnMoved(e); updateTreeColumnIndex(); int from = e.getFromIndex(); int to = e.getToIndex(); if ( from != to ) firePropertyChange( "column_moved", from, to ); // NOI18N }
/** * Sets tree column index and fires property change. */ void setTreeColumnIndex(int index) { if (treeColumnIndex == index) { return; } int old = treeColumnIndex; treeColumnIndex = index; firePropertyChange("treeColumnIndex", old, treeColumnIndex); }
public void paintImpl(Graphics g) { if (needCalcRowHeight) { calcRowHeight(g); return; } /* long time = perf.highResCounter(); */ super.paint(g); /* double dur = perf.highResCounter()-time; total += dur; System.err.println("Paint time: " + total + " ticks = " + (total / perf.highResFrequency()) + " ms. "); */ }
public TreeTable(NodeTreeModel treeModel, NodeTableModel tableModel) { super(); setSurrendersFocusOnKeystroke(true); setModel(this.tableModel); ListToTreeSelectionModelWrapper(); tree.setSelectionModel(selectionWrapper); setSelectionModel(selectionWrapper.getListSelectionModel()); getTableHeader().setReorderingAllowed(false); setDefaultRenderer(TreeTableModelAdapter.class, tree); setDefaultRenderer(Property.class, tableCell); setDefaultEditor(Property.class, tableCell); getTableHeader().setDefaultRenderer(tableCell); getAccessibleContext().setAccessibleName( NbBundle.getBundle(TreeTable.class).getString("ACSN_TreeTable")); // NOI18N getAccessibleContext().setAccessibleDescription( // NOI18N NbBundle.getBundle(TreeTable.class).getString("ACSD_TreeTable")); // NOI18N setFocusCycleRoot(true); setFocusTraversalPolicy(new STPolicy()); putClientProperty("terminateEditOnFocusLost", Boolean.TRUE); putClientProperty("JTable.autoStartsEdit", Boolean.FALSE); initKeysAndActions();
public void actionPerformed(ActionEvent e) { if (isEditing()) { removeEditor(); if (getSelectedColumn() == getColumnCount()-1) { targetColumn=0; targetRow = getSelectedRow()+1; } else { targetColumn = getSelectedColumn()+1; targetRow = getSelectedRow(); if (getSelectedColumn() == 0) { targetColumn = getColumnCount()-1; targetRow = getSelectedRow()-1; } else { targetRow = getSelectedRow(); targetColumn = getSelectedColumn() -1; if (targetRow >= getRowCount() || targetRow < 0) { Container ancestor = getFocusCycleRootAncestor(); TreeTable.this.getParent()) : ancestor.getFocusTraversalPolicy().getComponentBefore(ancestor, TreeTable.this); JRootPane rp = getRootPane(); JButton jb = rp.getDefaultButton(); if (jb != null) {