Search in sources :

Example 1 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.

the class PropertiesComponent method setFile.

public void setFile(SvnVcs vcs, File file) {
    final Map<String, String> props = new TreeMap<>();
    boolean firstTime = myFile == null;
    if (file != null) {
        myFile = file;
        myVcs = vcs;
        collectProperties(vcs, file, props);
    }
    DefaultTableModel model = (DefaultTableModel) myTable.getModel();
    model.setDataVector(createTableModel(props), new Object[] { "Name", "Value" });
    myTable.getColumnModel().setColumnSelectionAllowed(false);
    myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {

        protected void setValue(Object value) {
            if (value != null) {
                if (value.toString().indexOf('\r') >= 0) {
                    value = value.toString().substring(0, value.toString().indexOf('\r')) + " [...]";
                }
                if (value.toString().indexOf('\n') >= 0) {
                    value = value.toString().substring(0, value.toString().indexOf('\n')) + " [...]";
                }
            }
            super.setValue(value);
        }
    });
    if (firstTime) {
        mySplitPane.setDividerLocation(.5);
    }
    if (myTable.getRowCount() > 0) {
        myTable.getSelectionModel().setSelectionInterval(0, 0);
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TreeMap(java.util.TreeMap) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 2 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.

the class CompoundRendererConfigurable method createChildrenListEditor.

private JComponent createChildrenListEditor(JavaDebuggerEditorsProvider editorsProvider) {
    final MyTableModel tableModel = new MyTableModel();
    myTable = new JBTable(tableModel);
    myListChildrenEditor = new XDebuggerExpressionEditor(myProject, editorsProvider, "NamedChildrenConfigurable", null, XExpressionImpl.EMPTY_EXPRESSION, false, false, false);
    JComponent editorComponent = myListChildrenEditor.getComponent();
    AbstractTableCellEditor editor = new AbstractTableCellEditor() {

        @Override
        public Object getCellEditorValue() {
            return TextWithImportsImpl.fromXExpression(myListChildrenEditor.getExpression());
        }

        @Override
        public Component getTableCellEditorComponent(JTable table, Object value, boolean isSelected, int row, int column) {
            myListChildrenEditor.setExpression(TextWithImportsImpl.toXExpression((TextWithImports) value));
            return editorComponent;
        }
    };
    editorComponent.registerKeyboardAction(e -> editor.stopCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    editorComponent.registerKeyboardAction(e -> editor.cancelCellEditing(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    TableColumn exprColumn = myTable.getColumnModel().getColumn(EXPRESSION_TABLE_COLUMN);
    exprColumn.setCellEditor(editor);
    exprColumn.setCellRenderer(new DefaultTableCellRenderer() {

        @NotNull
        @Override
        public Component getTableCellRendererComponent(@NotNull JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            final TextWithImports textWithImports = (TextWithImports) value;
            final String text = (textWithImports != null) ? textWithImports.getText() : "";
            return super.getTableCellRendererComponent(table, text, isSelected, hasFocus, row, column);
        }
    });
    return ToolbarDecorator.createDecorator(myTable).setAddAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            tableModel.addRow("", DebuggerUtils.getInstance().createExpressionWithImports(""));
        }
    }).setRemoveAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            int selectedRow = myTable.getSelectedRow();
            if (selectedRow >= 0 && selectedRow < myTable.getRowCount()) {
                getTableModel().removeRow(selectedRow);
            }
        }
    }).setMoveUpAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsUp(myTable);
        }
    }).setMoveDownAction(new AnActionButtonRunnable() {

        @Override
        public void run(AnActionButton button) {
            TableUtil.moveSelectedItemsDown(myTable);
        }
    }).createPanel();
}
Also used : XDebuggerExpressionEditor(com.intellij.xdebugger.impl.ui.XDebuggerExpressionEditor) JBTable(com.intellij.ui.table.JBTable) TableColumn(javax.swing.table.TableColumn) NotNull(org.jetbrains.annotations.NotNull) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TextWithImports(com.intellij.debugger.engine.evaluation.TextWithImports)

Example 3 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer 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 4 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project android by JetBrains.

the class ThemeEditorTable method setRenderersAndEditors.

private void setRenderersAndEditors(@NotNull AndroidThemePreviewPanel previewPanel, @NotNull ParentRendererEditor.ThemeParentChangedListener themeParentChangedListener) {
    Project project = myContext.getProject();
    ResourcesCompletionProvider completionProvider = new ResourcesCompletionProvider(myContext);
    final AttributeReferenceRendererEditor styleEditor = new AttributeReferenceRendererEditor(project, completionProvider);
    setDefaultRenderer(Color.class, new DelegatingCellRenderer(new ColorRendererEditor(myContext, previewPanel, false)));
    setDefaultRenderer(EditedStyleItem.class, new DelegatingCellRenderer(new AttributeReferenceRendererEditor(project, completionProvider)));
    setDefaultRenderer(ConfiguredThemeEditorStyle.class, new DelegatingCellRenderer(new AttributeReferenceRendererEditor(project, completionProvider)));
    setDefaultRenderer(String.class, new DelegatingCellRenderer(getDefaultRenderer(String.class)));
    setDefaultRenderer(Integer.class, new DelegatingCellRenderer(new IntegerRenderer()));
    setDefaultRenderer(Boolean.class, new DelegatingCellRenderer(new BooleanRendererEditor(myContext)));
    setDefaultRenderer(Enum.class, new DelegatingCellRenderer(new EnumRendererEditor()));
    setDefaultRenderer(Flag.class, new DelegatingCellRenderer(new FlagRendererEditor()));
    setDefaultRenderer(AttributesTableModel.ParentAttribute.class, new DelegatingCellRenderer(new ParentRendererEditor(myContext, themeParentChangedListener)));
    setDefaultRenderer(DrawableDomElement.class, new DelegatingCellRenderer(new DrawableRendererEditor(myContext, previewPanel, false)));
    setDefaultRenderer(TableLabel.class, new DefaultTableCellRenderer() {

        @Override
        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
            Font regularFont = UIUtil.getLabelFont();
            int regularFontSize = getFontMetrics(regularFont).getHeight();
            Font headerFont = regularFont.deriveFont(regularFontSize * ThemeEditorConstants.ATTRIBUTES_HEADER_FONT_SCALE);
            this.setFont(headerFont);
            return this;
        }
    });
    setDefaultEditor(Color.class, new DelegatingCellEditor(false, new ColorRendererEditor(myContext, previewPanel, true)));
    setDefaultEditor(EditedStyleItem.class, new DelegatingCellEditor(false, new AttributeReferenceRendererEditor(project, completionProvider)));
    setDefaultEditor(String.class, new DelegatingCellEditor(false, getDefaultEditor(String.class)));
    setDefaultEditor(Integer.class, new DelegatingCellEditor(getDefaultEditor(Integer.class)));
    setDefaultEditor(Boolean.class, new DelegatingCellEditor(false, new BooleanRendererEditor(myContext)));
    setDefaultEditor(Enum.class, new DelegatingCellEditor(false, new EnumRendererEditor()));
    setDefaultEditor(Flag.class, new DelegatingCellEditor(false, new FlagRendererEditor()));
    setDefaultEditor(AttributesTableModel.ParentAttribute.class, new DelegatingCellEditor(false, new ParentRendererEditor(myContext, themeParentChangedListener)));
    // We allow to edit style pointers as Strings.
    setDefaultEditor(ConfiguredThemeEditorStyle.class, new DelegatingCellEditor(false, styleEditor));
    setDefaultEditor(DrawableDomElement.class, new DelegatingCellEditor(false, new DrawableRendererEditor(myContext, previewPanel, true)));
}
Also used : AttributesTableModel(com.android.tools.idea.editors.theme.attributes.AttributesTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Project(com.intellij.openapi.project.Project)

Example 5 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project intellij-community by JetBrains.

the class TaskExecutionTreeTable method getCellRenderer.

@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    if (column == 0) {
        final TableCellRenderer cellRenderer = super.getCellRenderer(row, column);
        return new TableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component component = cellRenderer.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                final Color bg = isSelected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground();
                component.setBackground(bg);
                return component;
            }
        };
    } else if (column == 1) {
        return new DefaultTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                setHorizontalAlignment(SwingConstants.RIGHT);
                final Color fg = isSelected ? UIUtil.getTreeSelectionForeground() : SimpleTextAttributes.GRAY_ATTRIBUTES.getFgColor();
                setForeground(fg);
                return this;
            }
        };
    }
    return super.getCellRenderer(row, column);
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)85 JTable (javax.swing.JTable)30 TableColumn (javax.swing.table.TableColumn)27 Component (java.awt.Component)21 JScrollPane (javax.swing.JScrollPane)20 DefaultTableModel (javax.swing.table.DefaultTableModel)17 TableCellRenderer (javax.swing.table.TableCellRenderer)17 JLabel (javax.swing.JLabel)14 MouseEvent (java.awt.event.MouseEvent)12 JComponent (javax.swing.JComponent)12 Dimension (java.awt.Dimension)11 Font (java.awt.Font)11 JTableHeader (javax.swing.table.JTableHeader)11 BorderLayout (java.awt.BorderLayout)9 Color (java.awt.Color)9 GridBagConstraints (java.awt.GridBagConstraints)9 Insets (java.awt.Insets)9 JPanel (javax.swing.JPanel)9 GridBagLayout (java.awt.GridBagLayout)7 Point (java.awt.Point)7