Search in sources :

Example 1 with RoundedLineBorder

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

the class CommitMessageTableRenderer method addTagOrBranchLabel.

/**
 * Add Label to "Commit Message" column: tag or local/remote branch
 *
 * @param nameForLabelList List of tags or branches corresponding the commit.
 * @param constr           The constraints for tag / branch label when wrapping
 * @param backgroundColor  The background color.
 * @param foregroundColor  The foreground color.
 */
private void addTagOrBranchLabel(List<String> nameForLabelList, GridBagConstraints constr, Color backgroundColor, Color foregroundColor) {
    if (nameForLabelList != null && !nameForLabelList.isEmpty()) {
        Insets oldInsets = constr.insets;
        // No insets. We will impose space from the borders.
        constr.insets = new Insets(0, 0, 0, 0);
        int lineSize = 1;
        for (String name : nameForLabelList) {
            final RoundedLineBorder border = new RoundedLineBorder(null, lineSize, LABEL_BORDER_CORNER_SIZE, true);
            final JLabel label = new JLabel(name.length() > MAX_BRANCH_OR_TAG_NAME_LENGTH ? (name.substring(0, MAX_BRANCH_OR_TAG_NAME_LENGTH - "...".length()) + "...") : name) {

                @Override
                protected void paintComponent(Graphics g) {
                    border.fillBorder(this, g, 0, 0, getWidth(), getHeight());
                    super.paintComponent(g);
                }

                @Override
                public JToolTip createToolTip() {
                    return UIUtil.createMultilineTooltip(this).orElseGet(super::createToolTip);
                }
            };
            if (name.equals(currentBranchName)) {
                label.setFont(label.getFont().deriveFont(Font.BOLD));
            }
            label.setBackground(backgroundColor);
            label.setForeground(foregroundColor);
            label.setBorder(border);
            label.setToolTipText(name);
            constr.gridx++;
            add(label, constr);
        }
        // We added a label. Update the top insets of the initial insets.
        constr.insets = oldInsets;
    }
}
Also used : Graphics(java.awt.Graphics) Insets(java.awt.Insets) RoundedLineBorder(com.oxygenxml.git.view.RoundedLineBorder) JLabel(javax.swing.JLabel)

Example 2 with RoundedLineBorder

use of com.oxygenxml.git.view.RoundedLineBorder 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

RoundedLineBorder (com.oxygenxml.git.view.RoundedLineBorder)2 JLabel (javax.swing.JLabel)2 RenderingInfo (com.oxygenxml.git.view.util.RenderingInfo)1 Font (java.awt.Font)1 Graphics (java.awt.Graphics)1 Insets (java.awt.Insets)1 Icon (javax.swing.Icon)1 EmptyBorder (javax.swing.border.EmptyBorder)1