Search in sources :

Example 16 with DefaultTableCellRenderer

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

the class XTable method getCellRenderer.

/**
     * This method sets read write rows to be blue, and other rows to be their
     * default rendered colour.
     */
@Override
public TableCellRenderer getCellRenderer(int row, int column) {
    DefaultTableCellRenderer tcr = (DefaultTableCellRenderer) super.getCellRenderer(row, column);
    tcr.setToolTipText(getToolTip(row, column));
    if (defaultColor == null) {
        defaultColor = tcr.getForeground();
        editableColor = Color.blue;
        errorColor = Color.red;
        // this sometimes happens for some reason
        if (defaultColor == null) {
            return tcr;
        }
    }
    if (column != VALUE_COLUMN) {
        tcr.setForeground(defaultColor);
        return tcr;
    }
    if (isCellError(row, column)) {
        tcr.setForeground(errorColor);
    } else if (isCellEditable(row, column)) {
        tcr.setForeground(editableColor);
    } else {
        tcr.setForeground(defaultColor);
    }
    return tcr;
}
Also used : DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 17 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project gitblit by gitblit.

the class RepositoriesPanel method initialize.

private void initialize() {
    final JButton browseRepository = new JButton(Translation.get("gb.browse"));
    browseRepository.setEnabled(false);
    browseRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            String url = gitblit.getURL("summary", model.name, null);
            Utils.browse(url);
        }
    });
    JButton refreshRepositories = new JButton(Translation.get("gb.refresh"));
    refreshRepositories.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            refreshRepositories();
        }
    });
    clearCache = new JButton(Translation.get("gb.clearCache"));
    clearCache.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            clearCache();
        }
    });
    createRepository = new JButton(Translation.get("gb.create"));
    createRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            createRepository();
        }
    });
    editRepository = new JButton(Translation.get("gb.edit"));
    editRepository.setEnabled(false);
    editRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            editRepository(getSelectedRepositories().get(0));
        }
    });
    delRepository = new JButton(Translation.get("gb.delete"));
    delRepository.setEnabled(false);
    delRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            deleteRepositories(getSelectedRepositories());
        }
    });
    final JButton subscribeRepository = new JButton(Translation.get("gb.subscribe") + "...");
    subscribeRepository.setEnabled(false);
    subscribeRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            List<FeedModel> feeds = gitblit.getAvailableFeeds(getSelectedRepositories().get(0));
            subscribeFeeds(feeds);
        }
    });
    final JButton logRepository = new JButton(Translation.get("gb.log") + "...");
    logRepository.setEnabled(false);
    logRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            showSearchDialog(false, model);
        }
    });
    final JButton searchRepository = new JButton(Translation.get("gb.search") + "...");
    searchRepository.setEnabled(false);
    searchRepository.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            RepositoryModel model = getSelectedRepositories().get(0);
            showSearchDialog(true, model);
        }
    });
    SubscribedRepositoryRenderer nameRenderer = new SubscribedRepositoryRenderer(gitblit);
    IndicatorsRenderer typeRenderer = new IndicatorsRenderer();
    DefaultTableCellRenderer sizeRenderer = new DefaultTableCellRenderer();
    sizeRenderer.setHorizontalAlignment(SwingConstants.RIGHT);
    sizeRenderer.setForeground(new Color(0, 0x80, 0));
    DefaultTableCellRenderer ownerRenderer = new DefaultTableCellRenderer();
    ownerRenderer.setForeground(Color.gray);
    ownerRenderer.setHorizontalAlignment(SwingConstants.CENTER);
    tableModel = new RepositoriesTableModel();
    defaultSorter = new TableRowSorter<RepositoriesTableModel>(tableModel);
    table = Utils.newTable(tableModel, Utils.DATE_FORMAT);
    table.setRowSorter(defaultSorter);
    table.getRowSorter().toggleSortOrder(RepositoriesTableModel.Columns.Name.ordinal());
    setRepositoryRenderer(RepositoriesTableModel.Columns.Name, nameRenderer, -1);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Indicators, typeRenderer, 100);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Owner, ownerRenderer, -1);
    setRepositoryRenderer(RepositoriesTableModel.Columns.Size, sizeRenderer, 60);
    table.getSelectionModel().addListSelectionListener(new ListSelectionListener() {

        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (e.getValueIsAdjusting()) {
                return;
            }
            boolean singleSelection = table.getSelectedRowCount() == 1;
            boolean selected = table.getSelectedRow() > -1;
            if (singleSelection) {
                RepositoryModel repository = getSelectedRepositories().get(0);
                browseRepository.setEnabled(repository.hasCommits);
                logRepository.setEnabled(repository.hasCommits);
                searchRepository.setEnabled(repository.hasCommits);
                subscribeRepository.setEnabled(repository.hasCommits);
            } else {
                browseRepository.setEnabled(false);
                logRepository.setEnabled(false);
                searchRepository.setEnabled(false);
                subscribeRepository.setEnabled(false);
            }
            delRepository.setEnabled(selected);
            if (selected) {
                int viewRow = table.getSelectedRow();
                int modelRow = table.convertRowIndexToModel(viewRow);
                RepositoryModel model = ((RepositoriesTableModel) table.getModel()).list.get(modelRow);
                editRepository.setEnabled(singleSelection && (gitblit.allowManagement() || gitblit.isOwner(model)));
            } else {
                editRepository.setEnabled(false);
            }
        }
    });
    table.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && gitblit.allowManagement()) {
                editRepository(getSelectedRepositories().get(0));
            }
        }
    });
    filterTextfield = new JTextField();
    filterTextfield.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            filterRepositories(filterTextfield.getText());
        }
    });
    filterTextfield.addKeyListener(new KeyAdapter() {

        @Override
        public void keyReleased(KeyEvent e) {
            filterRepositories(filterTextfield.getText());
        }
    });
    JPanel repositoryFilterPanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    repositoryFilterPanel.add(new JLabel(Translation.get("gb.filter")), BorderLayout.WEST);
    repositoryFilterPanel.add(filterTextfield, BorderLayout.CENTER);
    JPanel repositoryTablePanel = new JPanel(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    repositoryTablePanel.add(repositoryFilterPanel, BorderLayout.NORTH);
    repositoryTablePanel.add(new JScrollPane(table), BorderLayout.CENTER);
    JPanel repositoryControls = new JPanel(new FlowLayout(FlowLayout.CENTER, Utils.MARGIN, 0));
    repositoryControls.add(clearCache);
    repositoryControls.add(refreshRepositories);
    repositoryControls.add(browseRepository);
    repositoryControls.add(createRepository);
    repositoryControls.add(editRepository);
    repositoryControls.add(delRepository);
    repositoryControls.add(subscribeRepository);
    repositoryControls.add(logRepository);
    repositoryControls.add(searchRepository);
    setLayout(new BorderLayout(Utils.MARGIN, Utils.MARGIN));
    header = new HeaderPanel(Translation.get("gb.repositories"), "git-orange-16x16.png");
    add(header, BorderLayout.NORTH);
    add(repositoryTablePanel, BorderLayout.CENTER);
    add(repositoryControls, BorderLayout.SOUTH);
}
Also used : JPanel(javax.swing.JPanel) FlowLayout(java.awt.FlowLayout) ActionEvent(java.awt.event.ActionEvent) KeyAdapter(java.awt.event.KeyAdapter) JButton(javax.swing.JButton) ListSelectionEvent(javax.swing.event.ListSelectionEvent) RepositoryModel(com.gitblit.models.RepositoryModel) JTextField(javax.swing.JTextField) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) KeyEvent(java.awt.event.KeyEvent) BorderLayout(java.awt.BorderLayout) ArrayList(java.util.ArrayList) List(java.util.List) JScrollPane(javax.swing.JScrollPane) MouseEvent(java.awt.event.MouseEvent) Color(java.awt.Color) MouseAdapter(java.awt.event.MouseAdapter) JLabel(javax.swing.JLabel) ListSelectionListener(javax.swing.event.ListSelectionListener) ActionListener(java.awt.event.ActionListener)

Example 18 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project druid by alibaba.

the class GroupableTableHeaderUI method getHeaderHeight.

public int getHeaderHeight() {
    int height = 0;
    TableColumnModel columnModel = header.getColumnModel();
    for (int column = 0; column < columnModel.getColumnCount(); column++) {
        TableColumn aColumn = columnModel.getColumn(column);
        TableCellRenderer renderer = aColumn.getHeaderRenderer();
        if (renderer == null) {
            renderer = new DefaultTableCellRenderer() {

                private static final long serialVersionUID = 1L;

                @Override
                public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
                    JTableHeader header = table.getTableHeader();
                    if (header != null) {
                        setForeground(header.getForeground());
                        setBackground(header.getBackground());
                        setFont(header.getFont());
                    }
                    setHorizontalAlignment(JLabel.CENTER);
                    setText((value == null) ? "" : value.toString());
                    setBorder(UIManager.getBorder("TableHeader.cellBorder"));
                    return this;
                }
            };
        }
        Component comp = renderer.getTableCellRendererComponent(header.getTable(), aColumn.getHeaderValue(), false, false, -1, column);
        int cHeight = comp.getPreferredSize().height;
        Enumeration<ColumnGroup> enumeration = ((GroupableTableHeader) header).getColumnGroups(aColumn);
        if (enumeration != null) {
            while (enumeration.hasMoreElements()) {
                ColumnGroup cGroup = (ColumnGroup) enumeration.nextElement();
                cHeight += cGroup.getSize(header.getTable()).height;
            }
        }
        height = Math.max(height, cHeight);
    }
    height = Math.max(height, m_height);
    return height;
}
Also used : TableCellRenderer(javax.swing.table.TableCellRenderer) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) TableColumnModel(javax.swing.table.TableColumnModel) JTableHeader(javax.swing.table.JTableHeader) TableColumn(javax.swing.table.TableColumn) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JTable(javax.swing.JTable) JComponent(javax.swing.JComponent) Component(java.awt.Component)

Example 19 with DefaultTableCellRenderer

use of javax.swing.table.DefaultTableCellRenderer in project CoreNLP by stanfordnlp.

the class InputPanel method showHistory.

private void showHistory() {
    if (historyFrame == null) {
        historyFrame = new JFrame("Statistics History");
    } else {
        historyFrame.setVisible(false);
        historyFrame = new JFrame("Statistics History");
    }
    historyFrame.setLayout(new GridLayout(1, 0));
    Object[][] entries = new Object[historyList.size()][3];
    for (int i = 0; i < historyList.size(); i++) {
        entries[i] = historyList.get(i).toArray();
    }
    DefaultTableModel tableModel = new TregexGUITableModel(entries, HistoryEntry.columnNamesArray());
    JTable statTable = new JTable(tableModel);
    DefaultTableCellRenderer dtcr = (DefaultTableCellRenderer) statTable.getDefaultRenderer(String.class);
    dtcr.setHorizontalAlignment(DefaultTableCellRenderer.CENTER);
    JScrollPane scroller = new JScrollPane(statTable);
    historyFrame.add(scroller);
    historyFrame.pack();
    historyFrame.setLocationRelativeTo(TregexGUI.getInstance());
    historyFrame.setBackground(Color.WHITE);
    historyFrame.setVisible(true);
    historyFrame.repaint();
}
Also used : GridLayout(java.awt.GridLayout) DefaultTableModel(javax.swing.table.DefaultTableModel) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer)

Example 20 with DefaultTableCellRenderer

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

the class ParameterTablePanel method init.

public void init(VariableData[] variableData, Project project, PsiElement... scopeElements) {
    super.init(variableData);
    myParameterTypeSelectors = new TypeSelector[getVariableData().length];
    for (int i = 0; i < myParameterTypeSelectors.length; i++) {
        final VariableData data = variableData[i];
        final TypeSelector selector = createSelector(project, data, scopeElements);
        myParameterTypeSelectors[i] = selector;
        //reverse order
        getVariableData()[i].type = myParameterTypeSelectors[i].getSelectedType();
    }
    myTypeRendererCombo = new ComboBox<>(getVariableData());
    myTypeRendererCombo.setOpaque(true);
    myTypeRendererCombo.setBorder(null);
    myTypeRendererCombo.setRenderer(new ListCellRendererWrapper<VariableData>() {

        @Override
        public void customize(JList list, VariableData value, int index, boolean selected, boolean hasFocus) {
            if (value != null) {
                setText(value.type.getPresentableText());
            }
        }
    });
    final TableColumn typeColumn = myTable.getColumnModel().getColumn(1);
    typeColumn.setCellEditor(new AbstractTableCellEditor() {

        TypeSelector myCurrentSelector;

        final JBComboBoxTableCellEditorComponent myEditorComponent = new JBComboBoxTableCellEditorComponent();

        final JLabel myTypeLabel = new JLabel();

        @Nullable
        public Object getCellEditorValue() {
            if (myCurrentSelector.getComponent() instanceof JLabel) {
                return myCurrentSelector.getSelectedType();
            }
            return myEditorComponent.getEditorValue();
        }

        public Component getTableCellEditorComponent(final JTable table, final Object value, final boolean isSelected, final int row, final int column) {
            myCurrentSelector = myParameterTypeSelectors[row];
            if (myParameterTypeSelectors[row].getComponent() instanceof JLabel) {
                PsiType selectedType = myCurrentSelector.getSelectedType();
                if (selectedType != null) {
                    myTypeLabel.setText(selectedType.getPresentableText());
                }
                return myTypeLabel;
            }
            myEditorComponent.setCell(table, row, column);
            myEditorComponent.setOptions(myCurrentSelector.getTypes());
            myEditorComponent.setDefaultValue(getVariableData()[row].type);
            myEditorComponent.setToString(o -> ((PsiType) o).getPresentableText());
            return myEditorComponent;
        }
    });
    myTable.getColumnModel().getColumn(1).setCellRenderer(new DefaultTableCellRenderer() {

        private final JBComboBoxLabel myLabel = new JBComboBoxLabel();

        public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
            if (value != null) {
                myLabel.setText(((PsiType) value).getPresentableText());
                myLabel.setBackground(isSelected ? table.getSelectionBackground() : table.getBackground());
                myLabel.setForeground(isSelected ? table.getSelectionForeground() : table.getForeground());
                if (isSelected) {
                    myLabel.setSelectionIcon();
                } else {
                    myLabel.setRegularIcon();
                }
            }
            return myLabel;
        }
    });
}
Also used : ComboBox(com.intellij.openapi.ui.ComboBox) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) TypeSelectorManagerImpl(com.intellij.refactoring.ui.TypeSelectorManagerImpl) TableColumn(javax.swing.table.TableColumn) Predicate(java.util.function.Predicate) TypeSelector(com.intellij.refactoring.ui.TypeSelector) ColumnInfo(com.intellij.util.ui.ColumnInfo) TypeSelectorManager(com.intellij.refactoring.ui.TypeSelectorManager) ListCellRendererWrapper(com.intellij.ui.ListCellRendererWrapper) LanguageNamesValidation(com.intellij.lang.LanguageNamesValidation) ArrayList(java.util.ArrayList) java.awt(java.awt) Nullable(org.jetbrains.annotations.Nullable) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) Project(com.intellij.openapi.project.Project) com.intellij.psi(com.intellij.psi) JavaLanguage(com.intellij.lang.java.JavaLanguage) javax.swing(javax.swing) JBComboBoxLabel(com.intellij.ui.components.JBComboBoxLabel) TableColumn(javax.swing.table.TableColumn) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) DefaultTableCellRenderer(javax.swing.table.DefaultTableCellRenderer) AbstractTableCellEditor(com.intellij.util.ui.AbstractTableCellEditor) JBComboBoxTableCellEditorComponent(com.intellij.ui.components.editors.JBComboBoxTableCellEditorComponent) TypeSelector(com.intellij.refactoring.ui.TypeSelector) Nullable(org.jetbrains.annotations.Nullable)

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