Search in sources :

Example 11 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)

Example 12 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 13 with DefaultTableCellRenderer

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

the class ResourceTablePanel method select.

public void select(@Nullable ResourceChooserItem item) {
    if (item != null) {
        myTable.setModel(new ResourceTableModel(item));
        // Pick a font that can display the various translations
        TableColumn valueColumn = myTable.getColumnModel().getColumn(1);
        valueColumn.setCellRenderer(new DefaultTableCellRenderer() {

            @Override
            public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
                if (column == 1) {
                    String s = value.toString();
                    component.setFont(FontUtil.getFontAbleToDisplay(s, table.getFont()));
                } else {
                    component.setFont(table.getFont());
                }
                return component;
            }
        });
        myNameLabel.setText(item.getName());
        myTable.setRowHeight(ChooseResourceDialog.TABLE_CELL_HEIGHT);
        myEditTranslationsLink.setVisible(item.getType() == ResourceType.STRING && !item.isFramework());
    } else {
        myNameLabel.setText("");
        myTable.setModel(new DefaultTableModel(0, 2));
        myEditTranslationsLink.setVisible(false);
    }
}
Also used : DefaultTableModel(javax.swing.table.DefaultTableModel) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 14 with DefaultTableCellRenderer

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

the class DownloadStatusColumnInfo method getRenderer.

@Nullable
@Override
public TableCellRenderer getRenderer(UpdaterTreeNode node) {
    DefaultTableCellRenderer renderer = new DefaultTableCellRenderer() {

        @Override
        public void setText(String text) {
        }
    };
    IconInfo info = getIconInfo(node);
    renderer.setIcon(info.getIcon());
    renderer.getAccessibleContext().setAccessibleName(info.getName());
    return renderer;
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) Nullable(org.jetbrains.annotations.Nullable)

Example 15 with DefaultTableCellRenderer

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

the class XMBeanAttributes method getCellRenderer.

@Override
public synchronized TableCellRenderer getCellRenderer(int row, int column) {
    //It can happen when MBean selection is switched at a very quick rate
    if (row >= getRowCount()) {
        return null;
    } else {
        if (column == VALUE_COLUMN) {
            Object obj = getModel().getValueAt(row, column);
            if (obj instanceof ZoomedCell) {
                ZoomedCell cell = (ZoomedCell) obj;
                if (cell.isInited()) {
                    DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) cell.getRenderer();
                    renderer.setToolTipText(getToolTip(row, column));
                    return renderer;
                }
            }
        }
        DefaultTableCellRenderer renderer = (DefaultTableCellRenderer) super.getCellRenderer(row, column);
        if (!isCellError(row, column)) {
            if (!(isColumnEditable(column) && isWritable(row) && Utils.isEditableType(getClassName(row)))) {
                renderer.setForeground(getDefaultColor());
            }
        }
        return renderer;
    }
}
Also used : EventObject(java.util.EventObject) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Aggregations

DefaultTableCellRenderer (javax.swing.table.DefaultTableCellRenderer)27 TableCellRenderer (javax.swing.table.TableCellRenderer)12 Component (java.awt.Component)10 TableColumn (javax.swing.table.TableColumn)10 JComponent (javax.swing.JComponent)7 DefaultTableModel (javax.swing.table.DefaultTableModel)7 Project (com.intellij.openapi.project.Project)3 JTable (javax.swing.JTable)3 JTableHeader (javax.swing.table.JTableHeader)3 JBTable (com.intellij.ui.table.JBTable)2 AbstractTableCellEditor (com.intellij.util.ui.AbstractTableCellEditor)2 java.awt (java.awt)2 MouseEvent (java.awt.event.MouseEvent)2 ArrayList (java.util.ArrayList)2 EventObject (java.util.EventObject)2 javax.swing (javax.swing)2 TableColumnModel (javax.swing.table.TableColumnModel)2 TableModel (javax.swing.table.TableModel)2 Nullable (org.jetbrains.annotations.Nullable)2 AttributesTableModel (com.android.tools.idea.editors.theme.attributes.AttributesTableModel)1