use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class EditMigrationDialog method createTable.
private JBTable createTable() {
final String[] names = { RefactoringBundle.message("migration.type.column.header"), RefactoringBundle.message("migration.old.name.column.header"), RefactoringBundle.message("migration.new.name.column.header") };
// Create a model of the data.
TableModel dataModel = new AbstractTableModel() {
public int getColumnCount() {
return 3;
}
public int getRowCount() {
return myMigrationMap.getEntryCount();
}
public Object getValueAt(int row, int col) {
MigrationMapEntry entry = myMigrationMap.getEntryAt(row);
if (col == 0) {
if (entry.getType() == MigrationMapEntry.PACKAGE && entry.isRecursive()) {
return RefactoringBundle.message("migration.package.with.subpackages");
} else if (entry.getType() == MigrationMapEntry.PACKAGE && !entry.isRecursive()) {
return RefactoringBundle.message("migration.package");
} else {
return RefactoringBundle.message("migration.class");
}
}
String suffix = (entry.getType() == MigrationMapEntry.PACKAGE ? ".*" : "");
if (col == 1) {
return entry.getOldName() + suffix;
} else {
return entry.getNewName() + suffix;
}
}
public String getColumnName(int column) {
return names[column];
}
public Class getColumnClass(int c) {
return String.class;
}
public boolean isCellEditable(int row, int col) {
return false;
}
public void setValueAt(Object aValue, int row, int column) {
}
};
// Create the table
myTable = new JBTable(dataModel);
myTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
myTable.setPreferredScrollableViewportSize(new Dimension(300, myTable.getRowHeight() * 10));
return myTable;
}
use of com.intellij.ui.table.JBTable in project intellij-community by JetBrains.
the class ShowUIDefaultsAction method actionPerformed.
@Override
public void actionPerformed(AnActionEvent e) {
final UIDefaults defaults = UIManager.getDefaults();
Enumeration keys = defaults.keys();
final Object[][] data = new Object[defaults.size()][2];
int i = 0;
while (keys.hasMoreElements()) {
Object key = keys.nextElement();
data[i][0] = key;
data[i][1] = defaults.get(key);
i++;
}
Arrays.sort(data, (o1, o2) -> StringUtil.naturalCompare(o1[0].toString(), o2[0].toString()));
final Project project = getEventProject(e);
new DialogWrapper(project) {
{
setTitle("Edit LaF Defaults");
setModal(false);
init();
}
public JBTable myTable;
@Nullable
@Override
public JComponent getPreferredFocusedComponent() {
return myTable;
}
@Nullable
@Override
protected String getDimensionServiceKey() {
return project == null ? null : "UI.Defaults.Dialog";
}
@Override
protected JComponent createCenterPanel() {
final JBTable table = new JBTable(new DefaultTableModel(data, new Object[] { "Name", "Value" }) {
@Override
public boolean isCellEditable(int row, int column) {
return column == 1 && getValueAt(row, column) instanceof Color;
}
}) {
@Override
public boolean editCellAt(int row, int column, EventObject e) {
if (isCellEditable(row, column) && e instanceof MouseEvent) {
final Object color = getValueAt(row, column);
final Color newColor = ColorPicker.showDialog(this, "Choose Color", (Color) color, true, null, true);
if (newColor != null) {
final ColorUIResource colorUIResource = new ColorUIResource(newColor);
final Object key = getValueAt(row, 0);
UIManager.put(key, colorUIResource);
setValueAt(colorUIResource, row, column);
}
}
return false;
}
};
table.setDefaultRenderer(Object.class, new DefaultTableCellRenderer() {
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
final JPanel panel = new JPanel(new BorderLayout());
final JLabel label = new JLabel(value == null ? "" : value.toString());
panel.add(label, BorderLayout.CENTER);
if (value instanceof Color) {
final Color c = (Color) value;
label.setText(String.format("[r=%d,g=%d,b=%d] hex=0x%s", c.getRed(), c.getGreen(), c.getBlue(), ColorUtil.toHex(c)));
label.setForeground(ColorUtil.isDark(c) ? Color.white : Color.black);
panel.setBackground(c);
return panel;
} else if (value instanceof Icon) {
try {
final Icon icon = new IconWrap((Icon) value);
if (icon.getIconHeight() <= 20) {
label.setIcon(icon);
}
label.setText(String.format("(%dx%d) %s)", icon.getIconWidth(), icon.getIconHeight(), label.getText()));
} catch (Throwable e1) {
//
}
return panel;
} else if (value instanceof Border) {
try {
final Insets i = ((Border) value).getBorderInsets(null);
label.setText(String.format("[%d, %d, %d, %d] %s", i.top, i.left, i.bottom, i.right, label.getText()));
return panel;
} catch (Exception ignore) {
}
}
return super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
}
});
final JBScrollPane pane = new JBScrollPane(table);
new TableSpeedSearch(table, (o, cell) -> cell.column == 1 ? null : String.valueOf(o));
table.setShowGrid(false);
final JPanel panel = new JPanel(new BorderLayout());
panel.add(pane, BorderLayout.CENTER);
myTable = table;
TableUtil.ensureSelectionExists(myTable);
return panel;
}
}.show();
}
use of com.intellij.ui.table.JBTable in project android by JetBrains.
the class SdkComponentsStep method createUIComponents.
private void createUIComponents() {
Splitter splitter = new Splitter(false, 0.5f, 0.2f, 0.8f);
myBody = splitter;
myComponentsTable = new JBTable();
myComponentDescription = new JTextPane();
splitter.setShowDividerIcon(false);
splitter.setShowDividerControls(false);
splitter.setFirstComponent(ScrollPaneFactory.createScrollPane(myComponentsTable, false));
splitter.setSecondComponent(ScrollPaneFactory.createScrollPane(myComponentDescription, false));
myComponentDescription.setFont(UIUtil.getLabelFont());
myComponentDescription.setEditable(false);
myComponentDescription.setBorder(BorderFactory.createEmptyBorder(WizardConstants.STUDIO_WIZARD_INSET_SIZE, WizardConstants.STUDIO_WIZARD_INSET_SIZE, WizardConstants.STUDIO_WIZARD_INSET_SIZE, WizardConstants.STUDIO_WIZARD_INSET_SIZE));
}
use of com.intellij.ui.table.JBTable in project android by JetBrains.
the class NetworkCaptureSegment method createCaptureTable.
@NotNull
private JTable createCaptureTable() {
JBTable table = new JBTable(new NetworkCaptureTableModel());
table.setDefaultRenderer(StateChart.class, (t, value, isSelected, hasFocus, row, column) -> myCharts.get(row));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(e -> {
if (table.getSelectedRow() < myDataList.size()) {
myDetailedViewListener.showDetailedConnection(myDataList.get(table.getSelectedRow()));
}
});
table.setFont(AdtUiUtils.DEFAULT_FONT);
table.setRowHeight(myRowHeight);
table.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
table.getColumnModel().getColumn(Column.TIMELINE.ordinal()).setPreferredWidth(myCaptureTable.getWidth() / 2);
}
});
return table;
}
use of com.intellij.ui.table.JBTable in project android by JetBrains.
the class ConnectionsView method createRequestsTable.
@NotNull
private JTable createRequestsTable() {
JTable table = new JBTable(myTableModel);
table.setAutoCreateRowSorter(true);
table.getColumnModel().getColumn(Column.SIZE.ordinal()).setCellRenderer(new SizeRenderer());
table.getColumnModel().getColumn(Column.STATUS.ordinal()).setCellRenderer(new StatusRenderer());
table.getColumnModel().getColumn(Column.TIME.ordinal()).setCellRenderer(new TimeRenderer());
table.getColumnModel().getColumn(Column.TIMELINE.ordinal()).setCellRenderer(new TimelineRenderer(table, myStageView.getTimeline().getSelectionRange()));
table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
table.getSelectionModel().addListSelectionListener(e -> {
int selectedRow = table.getSelectedRow();
if (0 <= selectedRow && selectedRow < myTableModel.getRowCount()) {
int modelRow = myConnectionsTable.convertRowIndexToModel(selectedRow);
myDetailedViewListener.showDetailedConnection(myTableModel.getHttpData(modelRow));
}
});
table.setFont(AdtUiUtils.DEFAULT_FONT);
int defaultFontHeight = table.getFontMetrics(AdtUiUtils.DEFAULT_FONT).getHeight();
table.setRowHeight(defaultFontHeight + ROW_HEIGHT_PADDING);
table.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(ComponentEvent e) {
for (int i = 0; i < Column.values().length; ++i) {
Column column = Column.values()[i];
table.getColumnModel().getColumn(i).setPreferredWidth((int) (table.getWidth() * column.getWidthPercentage()));
}
}
});
// Keep the previously selected row selected if it's still there
myTableModel.addTableModelListener(e -> ApplicationManager.getApplication().invokeLater(() -> {
HttpData selectedData = myStageView.getStage().getConnection();
if (selectedData != null) {
for (int i = 0; i < myTableModel.getRowCount(); ++i) {
if (myTableModel.getHttpData(i).getId() == selectedData.getId()) {
int row = table.convertRowIndexToView(i);
table.setRowSelectionInterval(row, row);
break;
}
}
}
}));
return table;
}
Aggregations