Search in sources :

Example 1 with RenderingInfo

use of com.oxygenxml.git.view.util.RenderingInfo in project oxygen-git-client-addon by oxygenxml.

the class StagingResourcesTableCellRenderer method getTableCellRendererComponent.

/**
 * @see javax.swing.table.TableCellRenderer.getTableCellRendererComponent(JTable, Object, boolean, boolean, int, int)
 */
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
    Icon icon = null;
    String tooltipText = null;
    String labelText = "";
    JLabel tableCellRendererComponent = (JLabel) super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
    String location = "";
    if (value instanceof GitChangeType) {
        RenderingInfo renderingInfo = RendererUtil.getChangeRenderingInfo((GitChangeType) value);
        setBorder(BorderFactory.createCompoundBorder(getBorder(), PADDING));
        if (renderingInfo != null) {
            icon = renderingInfo.getIcon();
            tooltipText = renderingInfo.getTooltip();
        }
    } else if (value instanceof FileStatus) {
        location = ((FileStatus) value).getFileLocation();
        setBorder(BorderFactory.createCompoundBorder(getBorder(), PADDING));
        FontMetrics metrics = getFontMetrics(getFont());
        labelText = FileUtil.truncateText(location, metrics, table.getWidth() - table.getColumnModel().getColumn(0).getWidth());
        String description = ((FileStatus) value).getDescription();
        if (description != null) {
            tooltipText = description;
        } else {
            tooltipText = location;
            String fileName = tooltipText.substring(tooltipText.lastIndexOf('/') + 1);
            if (!fileName.equals(tooltipText)) {
                tooltipText = tooltipText.replace("/" + fileName, "");
                tooltipText = fileName + " - " + tooltipText;
            }
        }
    }
    if (isSelected) {
        tableCellRendererComponent.setForeground(table.getSelectionForeground());
    } else {
        updateForegroundText(tableCellRendererComponent);
    }
    tableCellRendererComponent.setIcon(icon);
    tableCellRendererComponent.setToolTipText(tooltipText);
    tableCellRendererComponent.setText(labelText);
    // Active/inactive table selection
    if (table.isRowSelected(row)) {
        if (table.hasFocus()) {
            tableCellRendererComponent.setBackground(table.getSelectionBackground());
        } else if (!contextMenuShowing.getAsBoolean()) {
            Color defaultColor = table.getSelectionBackground();
            tableCellRendererComponent.setBackground(RendererUtil.getInactiveSelectionColor(table, defaultColor));
        }
    } else {
        tableCellRendererComponent.setBackground(table.getBackground());
    }
    return tableCellRendererComponent;
}
Also used : RenderingInfo(com.oxygenxml.git.view.util.RenderingInfo) FileStatus(com.oxygenxml.git.service.entities.FileStatus) FontMetrics(java.awt.FontMetrics) Color(java.awt.Color) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon)

Example 2 with RenderingInfo

use of com.oxygenxml.git.view.util.RenderingInfo in project oxygen-git-client-addon by oxygenxml.

the class ChangesTreeCellRenderer method getTreeCellRendererComponent.

/**
 * @see javax.swing.tree.DefaultTreeCellRenderer.getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean)
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    Icon icon = Icons.getIcon(Icons.FOLDER_TREE_ICON);
    String toolTip = null;
    StagingResourcesTreeModel model = (StagingResourcesTreeModel) tree.getModel();
    TreePath treePath = tree.getPathForRow(row);
    if (treePath != null) {
        String path = TreeUtil.getStringPath(treePath);
        if (!"".equals(path) && model.isLeaf(TreeUtil.getTreeNodeFromString(model, path))) {
            FileStatus file = model.getFileByPath(path);
            if (file != null) {
                GitChangeType changeType = file.getChangeType();
                RenderingInfo renderingInfo = RendererUtil.getChangeRenderingInfo(changeType);
                if (renderingInfo != null) {
                    icon = renderingInfo.getIcon();
                    toolTip = renderingInfo.getTooltip();
                }
                if (file.getDescription() != null) {
                    toolTip = file.getDescription();
                }
            } else {
                label = null;
            }
        }
    }
    if (label != null) {
        label.setIcon(icon);
        label.setToolTipText(toolTip);
        if (sel) {
            setBackgroundSelectionColor(tree);
        }
    }
    return label;
}
Also used : RenderingInfo(com.oxygenxml.git.view.util.RenderingInfo) FileStatus(com.oxygenxml.git.service.entities.FileStatus) TreePath(javax.swing.tree.TreePath) GitChangeType(com.oxygenxml.git.service.entities.GitChangeType) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon)

Example 3 with RenderingInfo

use of com.oxygenxml.git.view.util.RenderingInfo in project oxygen-git-client-addon by oxygenxml.

the class BranchesTreeCellRenderer method getTreeCellRendererComponent.

/**
 * @see DefaultTreeCellRenderer.getTreeCellRendererComponent(JTree, Object, boolean, boolean, boolean, int, boolean)
 */
@Override
public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) {
    JLabel label = (JLabel) super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
    if (label == null) {
        return null;
    }
    Icon icon = null;
    branchName = "";
    this.isLeaf = leaf;
    path = value.toString();
    if (((DefaultMutableTreeNode) value).getParent() == null) {
        icon = Icons.getIcon(Icons.LOCAL_REPO);
    } else {
        RenderingInfo renderingInfo = getRenderingInfo(path);
        icon = renderingInfo.getIcon();
        branchName = renderingInfo.getTooltip();
    }
    this.setIcon(icon);
    if (!branchName.isEmpty()) {
        this.setText(branchName);
    }
    Font font = label.getFont();
    this.setFont(font.deriveFont(Font.PLAIN));
    this.setBorder(new EmptyBorder(0, 5, 0, 0));
    if (path.equals(Constants.R_HEADS + currentBranchNameSupplier.get())) {
        // Mark the current branch
        this.setFont(font.deriveFont(Font.BOLD));
        this.setBorder(new RoundedLineBorder(label.getForeground(), 1, CURRENT_BRANCH_BORDER_CRONER_SIZE, true));
    }
    // Active/inactive table selection
    if (sel) {
        setSelectionColors(tree);
    }
    return this;
}
Also used : RenderingInfo(com.oxygenxml.git.view.util.RenderingInfo) RoundedLineBorder(com.oxygenxml.git.view.RoundedLineBorder) JLabel(javax.swing.JLabel) Icon(javax.swing.Icon) EmptyBorder(javax.swing.border.EmptyBorder) Font(java.awt.Font)

Aggregations

RenderingInfo (com.oxygenxml.git.view.util.RenderingInfo)3 Icon (javax.swing.Icon)3 JLabel (javax.swing.JLabel)3 FileStatus (com.oxygenxml.git.service.entities.FileStatus)2 GitChangeType (com.oxygenxml.git.service.entities.GitChangeType)2 RoundedLineBorder (com.oxygenxml.git.view.RoundedLineBorder)1 Color (java.awt.Color)1 Font (java.awt.Font)1 FontMetrics (java.awt.FontMetrics)1 EmptyBorder (javax.swing.border.EmptyBorder)1 TreePath (javax.swing.tree.TreePath)1