use of javax.swing.table.TableModel in project intellij-community by JetBrains.
the class TableUtil method moveSelectedItemsUp.
public static int moveSelectedItemsUp(@NotNull JTable table) {
if (table.isEditing()) {
table.getCellEditor().stopCellEditing();
}
TableModel model = table.getModel();
ListSelectionModel selectionModel = table.getSelectionModel();
int counter = 0;
for (int row = 0; row < model.getRowCount(); row++) {
if (selectionModel.isSelectedIndex(row)) {
counter++;
for (int column = 0; column < model.getColumnCount(); column++) {
Object temp = model.getValueAt(row, column);
model.setValueAt(model.getValueAt(row - 1, column), row, column);
model.setValueAt(temp, row - 1, column);
}
selectionModel.removeSelectionInterval(row, row);
selectionModel.addSelectionInterval(row - 1, row - 1);
}
}
Rectangle cellRect = table.getCellRect(selectionModel.getMinSelectionIndex(), 0, true);
if (cellRect != null) {
table.scrollRectToVisible(cellRect);
}
table.repaint();
return counter;
}
use of javax.swing.table.TableModel in project android by JetBrains.
the class ThemeEditorTable method updateRowHeights.
public void updateRowHeights() {
TableModel rawModel = getModel();
if (!(rawModel instanceof CellSpanModel)) {
return;
}
CellSpanModel myModel = (CellSpanModel) rawModel;
int defaultRowHeight = myClassHeights.get(Object.class);
setRowHeight(defaultRowHeight);
for (int row = 0; row < myModel.getRowCount(); row++) {
// Find the maximum row height
int maxRowHeight = -1;
for (int col = 0; col < myModel.getColumnCount(); col += myModel.getColumnSpan(row, col)) {
Class<?> cellClass = myModel.getCellClass(row, col);
Integer rowHeight = myClassHeights.get(cellClass);
if (rowHeight != null) {
maxRowHeight = Math.max(maxRowHeight, rowHeight);
}
}
if (maxRowHeight == -1) {
// Leave the default size
continue;
}
int viewRow = convertRowIndexToView(row);
if (viewRow != -1) {
setRowHeight(viewRow, maxRowHeight);
}
}
}
use of javax.swing.table.TableModel in project android by JetBrains.
the class ThemeEditorTable method getPopupMenuAtCell.
private JPopupMenu getPopupMenuAtCell(final int row, final int column) {
if (row < 0 || column < 0) {
return null;
}
TableModel rawModel = getModel();
if (!(rawModel instanceof AttributesTableModel)) {
return null;
}
final AttributesTableModel model = (AttributesTableModel) rawModel;
AttributesTableModel.RowContents contents = model.getRowContents(this.convertRowIndexToModel(row));
if (contents instanceof AttributesTableModel.AttributeContents) {
final AttributesTableModel.AttributeContents attribute = (AttributesTableModel.AttributeContents) contents;
final EditedStyleItem item = attribute.getValue();
if (item == null) {
return null;
}
final JBPopupMenu popupMenu = new JBPopupMenu();
if (attribute.getCellClass(1) == ConfiguredThemeEditorStyle.class) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goTo(item);
}
});
} else {
final ResourceResolver resolver = myContext.getResourceResolver();
assert resolver != null;
final Project project = myContext.getProject();
final ResourceValue resourceValue = resolver.resolveResValue(item.getSelectedValue());
final File file = new File(resourceValue.getValue());
final VirtualFileManager manager = VirtualFileManager.getInstance();
final VirtualFile virtualFile = file.exists() ? manager.findFileByUrl("file://" + file.getAbsolutePath()) : null;
if (virtualFile != null) {
popupMenu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
final OpenFileDescriptor descriptor = new OpenFileDescriptor(project, virtualFile);
FileEditorManager.getInstance(project).openEditor(descriptor, true);
}
});
}
}
myJavadocAction.setCurrentItem(item);
popupMenu.add(myJavadocAction);
final ConfiguredThemeEditorStyle selectedStyle = model.getSelectedStyle();
if (!selectedStyle.isReadOnly() && selectedStyle.hasItem(item)) {
popupMenu.add(new AbstractAction("Reset value") {
@Override
public void actionPerformed(ActionEvent e) {
selectedStyle.removeAttribute(item.getQualifiedName());
model.fireTableCellUpdated(attribute.getRowIndex(), 0);
}
});
}
return popupMenu;
} else if (contents instanceof AttributesTableModel.ParentAttribute) {
final ConfiguredThemeEditorStyle parentStyle = model.getSelectedStyle().getParent();
if (parentStyle == null) {
return null;
}
final JBPopupMenu menu = new JBPopupMenu();
menu.add(new AbstractAction(GO_TO_DECLARATION) {
@Override
public void actionPerformed(ActionEvent e) {
myGoToListener.goToParent();
}
});
return menu;
}
return null;
}
use of javax.swing.table.TableModel in project android by JetBrains.
the class ParentRendererEditor method getRendererComponent.
@Override
public Component getRendererComponent(JTable table, ConfiguredThemeEditorStyle value, boolean isSelected, boolean hasFocus, int row, int column) {
final TableModel model = table.getModel();
final ConfiguredThemeEditorStyle parent = value.getParent();
Font font = table.getFont();
Font scaledFont = ThemeEditorUtils.scaleFontForAttribute(font);
myParentComboBox.setFont(scaledFont);
myLabel.setFont(scaledFont);
myParentComboBox.setEnabled(model.isCellEditable(row, column));
if (parent == null) {
myParentComboBox.setModel(NO_PARENT_MODEL);
myItem = null;
} else {
ImmutableList<String> defaultThemeNames = ThemeEditorUtils.getDefaultThemeNames(myContext.getThemeResolver());
myParentComboBox.setModel(new ParentThemesListModel(defaultThemeNames, parent.getQualifiedName()));
myItem = value;
}
updateVariantsCombo();
return myPanel;
}
use of javax.swing.table.TableModel in project JMRI by JMRI.
the class PaneProgPane method makeCvTable.
void makeCvTable(GridBagConstraints cs, GridBagLayout g, JPanel c) {
log.debug("starting to build CvTable pane");
TableRowSorter<TableModel> sorter = new TableRowSorter<>(_cvModel);
JTable cvTable = new JTable(_cvModel);
sorter.setComparator(CvTableModel.NUMCOLUMN, new jmri.util.PreferNumericComparator());
List<RowSorter.SortKey> sortKeys = new ArrayList<>();
sortKeys.add(new RowSorter.SortKey(0, SortOrder.ASCENDING));
sorter.setSortKeys(sortKeys);
cvTable.setRowSorter(sorter);
cvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
cvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
cvTable.setDefaultEditor(JTextField.class, new ValueEditor());
cvTable.setDefaultEditor(JButton.class, new ValueEditor());
cvTable.setRowHeight(new JButton("X").getPreferredSize().height);
// have to shut off autoResizeMode to get horizontal scroll to work (JavaSwing p 541)
// instead of forcing the columns to fill the frame (and only fill)
cvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
JScrollPane cvScroll = new JScrollPane(cvTable);
cvScroll.setColumnHeaderView(cvTable.getTableHeader());
cs.gridheight = GridBagConstraints.REMAINDER;
g.setConstraints(cvScroll, cs);
c.add(cvScroll);
cs.gridheight = 1;
// remember which CVs to read/write
isCvTablePane = true;
setCvListFromTable();
_cvTable = true;
log.debug("end of building CvTable pane");
}
Aggregations