Search in sources :

Example 16 with JBTable

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;
}
Also used : AbstractTableModel(javax.swing.table.AbstractTableModel) JBTable(com.intellij.ui.table.JBTable) AbstractTableModel(javax.swing.table.AbstractTableModel) TableModel(javax.swing.table.TableModel)

Example 17 with JBTable

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();
}
Also used : EmptyIcon(com.intellij.util.ui.EmptyIcon) Arrays(java.util.Arrays) DefaultTableModel(javax.swing.table.DefaultTableModel) Enumeration(java.util.Enumeration) StringUtil(com.intellij.openapi.util.text.StringUtil) AnAction(com.intellij.openapi.actionSystem.AnAction) ColorUIResource(javax.swing.plaf.ColorUIResource) MouseEvent(java.awt.event.MouseEvent) JBScrollPane(com.intellij.ui.components.JBScrollPane) Border(javax.swing.border.Border) EventObject(java.util.EventObject) java.awt(java.awt) JBTable(com.intellij.ui.table.JBTable) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) PairFunction(com.intellij.util.PairFunction) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) AnActionEvent(com.intellij.openapi.actionSystem.AnActionEvent) Project(com.intellij.openapi.project.Project) DumbAware(com.intellij.openapi.project.DumbAware) Comparator(java.util.Comparator) javax.swing(javax.swing) DefaultTableModel(javax.swing.table.DefaultTableModel) JBTable(com.intellij.ui.table.JBTable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Enumeration(java.util.Enumeration) MouseEvent(java.awt.event.MouseEvent) ColorUIResource(javax.swing.plaf.ColorUIResource) DialogWrapper(com.intellij.openapi.ui.DialogWrapper) EventObject(java.util.EventObject) Project(com.intellij.openapi.project.Project) EventObject(java.util.EventObject) EmptyIcon(com.intellij.util.ui.EmptyIcon) Border(javax.swing.border.Border) Nullable(org.jetbrains.annotations.Nullable) JBScrollPane(com.intellij.ui.components.JBScrollPane)

Example 18 with JBTable

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));
}
Also used : Splitter(com.intellij.openapi.ui.Splitter) JBTable(com.intellij.ui.table.JBTable)

Example 19 with JBTable

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;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) JBTable(com.intellij.ui.table.JBTable) ComponentAdapter(java.awt.event.ComponentAdapter) NotNull(org.jetbrains.annotations.NotNull)

Example 20 with JBTable

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;
}
Also used : ComponentEvent(java.awt.event.ComponentEvent) JBTable(com.intellij.ui.table.JBTable) ComponentAdapter(java.awt.event.ComponentAdapter) NotNull(org.jetbrains.annotations.NotNull)

Aggregations

JBTable (com.intellij.ui.table.JBTable)41 VirtualFile (com.intellij.openapi.vfs.VirtualFile)9 AnActionEvent (com.intellij.openapi.actionSystem.AnActionEvent)8 DefaultTableModel (javax.swing.table.DefaultTableModel)8 NotNull (org.jetbrains.annotations.NotNull)7 FileChooserDescriptor (com.intellij.openapi.fileChooser.FileChooserDescriptor)6 Nullable (org.jetbrains.annotations.Nullable)6 JBLabel (com.intellij.ui.components.JBLabel)5 ActionEvent (java.awt.event.ActionEvent)5 AbstractTableModel (javax.swing.table.AbstractTableModel)5 TableColumn (javax.swing.table.TableColumn)5 TableColumnModel (javax.swing.table.TableColumnModel)5 DumbAwareAction (com.intellij.openapi.project.DumbAwareAction)4 Project (com.intellij.openapi.project.Project)4 JBScrollPane (com.intellij.ui.components.JBScrollPane)4 MouseEvent (java.awt.event.MouseEvent)4 List (java.util.List)4 StringUtil (com.intellij.openapi.util.text.StringUtil)3 JavaCodeFragmentTableCellEditor (com.intellij.refactoring.ui.JavaCodeFragmentTableCellEditor)3 UsageInfo (com.intellij.usageView.UsageInfo)3