/** * Paints selection for the specified <code>component</code>. */ public static void paintSelectionDecoration(@NotNull RadComponent component, Graphics g, boolean focused) { if (component.isSelected()) { if (focused) { g.setColor(PlatformColors.BLUE); } else { g.setColor(Color.GRAY); } final Point[] points = getPoints(component.getWidth(), component.getHeight()); for (final Point point : points) { g.fillRect(point.x - R, point.y - R, 2 * R + 1, 2 * R + 1); } } else if (component.getWidth() < FormEditingUtil.EMPTY_COMPONENT_SIZE || component.getHeight() < FormEditingUtil.EMPTY_COMPONENT_SIZE) { Graphics2D g2d = (Graphics2D)g; Composite oldComposite = g2d.getComposite(); Stroke oldStroke = g2d.getStroke(); Color oldColor = g2d.getColor(); g2d.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_ATOP, 0.5f)); g2d.setStroke(new BasicStroke(0.7f)); g2d.setColor(Color.black); g2d.drawRect(0, 0, Math.max(component.getWidth(), FormEditingUtil.EMPTY_COMPONENT_SIZE), Math.max(component.getHeight(), FormEditingUtil.EMPTY_COMPONENT_SIZE)); g2d.setComposite(oldComposite); g2d.setStroke(oldStroke); g2d.setColor(oldColor); } }
public void addAction(final Action action) { action.addPropertyChangeListener(this); final LinkLabel label = new LinkLabel(null, null, new LinkListener() { @Override public void linkSelected(final LinkLabel aSource, final Object aLinkData) { action.actionPerformed(new ActionEvent(Banner.this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY)); } }) { @Override protected Color getTextColor() { return PlatformColors.BLUE; } }; label.setFont(label.getFont().deriveFont(Font.BOLD)); myActions.put(action, label); myActionsPanel.add(label); updateAction(action); }
static JComponent createComponentForTitle(@Nullable String title, @Nullable final LineSeparator sep1, @Nullable final LineSeparator sep2, boolean left) { if (sep1 != null && sep2 != null && !sep1.equals(sep2)) { LineSeparator separator = left ? sep1 : sep2; JPanel bottomPanel = new JPanel(new BorderLayout()); JLabel sepLabel = new JLabel(separator.name()); sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE); bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(title == null ? "" : title)); panel.add(bottomPanel, BorderLayout.SOUTH); return panel; } else { return new JBLabel(title == null ? "" : title); } }
@Override protected void update(PresentationData presentation) { String name = myBlock.getClass().getSimpleName(); if (myBlock instanceof DataLanguageBlockWrapper) { name += " (" + ((DataLanguageBlockWrapper)myBlock).getOriginal().getClass().getSimpleName() + ")"; } presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES); if (myBlock.getIndent() != null) { presentation.addText(" " + String.valueOf(myBlock.getIndent()).replaceAll("[<>]", " "), SimpleTextAttributes.GRAY_ATTRIBUTES); } else { presentation.addText(" Indent: null", SimpleTextAttributes.GRAY_ATTRIBUTES); } if (myBlock.getAlignment() != null) { presentation .addText(" " + String.valueOf(myBlock.getAlignment()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, JBColor.darkGray)); } if (myBlock.getWrap() != null) { presentation .addText(" " + String.valueOf(myBlock.getWrap()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, PlatformColors.BLUE)); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if (myDropTargetIndex >= 0) { int dropLineY; Rectangle rc; if (myDropTargetIndex == myGroup.getItems().length) { rc = getCellBounds(myDropTargetIndex-1, myDropTargetIndex-1); dropLineY = (int)rc.getMaxY()-1; } else { rc = getCellBounds(myDropTargetIndex, myDropTargetIndex); dropLineY = rc.y; } Graphics2D g2d = (Graphics2D) g; g2d.setColor(PlatformColors.BLUE); g2d.setStroke(new BasicStroke(2.0f)); g2d.drawLine(rc.x, dropLineY, rc.x+rc.width, dropLineY); g2d.drawLine(rc.x, dropLineY-2, rc.x, dropLineY+2); g2d.drawLine(rc.x+rc.width, dropLineY-2, rc.x+rc.width, dropLineY+2); } }
public Component getTableCellRendererComponent(JTable table, Object _value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, _value, isSelected, hasFocus, row, column); setForeground(table.getForeground()); setToolTipText(null); for (int i = 0; i < myVariables.size(); i++) { Variable variable = myVariables.get(i); if (i != row && variable.getName().equals(_value)) { setForeground(Color.RED); setToolTipText("Duplicate Variable"); } else if (variable.getExpression().length() == 0) { setForeground(PlatformColors.BLUE); setToolTipText("Empty expression. Variable will evaluate to empty nodeset."); } } return this; }
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) { super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column); setForeground(table.getForeground()); final String prefix = myNamespaces.get(row).getPrefix(); if (column == 1 && prefix == null || prefix.length() == 0) { setForeground(PlatformColors.BLUE); } else if (column == 0) { for (int i = 0; i < myNamespaces.size(); i++) { Namespace namespace = myNamespaces.get(i); if (i != row && namespace.getPrefix().equals(value)) { setForeground(Color.RED); break; } } } return this; }
public void addAction(final Action action) { action.addPropertyChangeListener(this); final LinkLabel label = new LinkLabel(null, null, new LinkListener() { public void linkSelected(final LinkLabel aSource, final Object aLinkData) { action.actionPerformed(new ActionEvent(Banner.this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY)); } }) { @Override protected Color getTextColor() { return PlatformColors.BLUE; } }; label.setFont(label.getFont().deriveFont(Font.BOLD)); myActions.put(action, label); myActionsPanel.add(label); updateAction(action); }
@Override protected void update(PresentationData presentation) { String name = myBlock.getClass().getSimpleName(); if (myBlock instanceof DataLanguageBlockWrapper) { name += " (" + ((DataLanguageBlockWrapper)myBlock).getOriginal().getClass().getSimpleName() + ")"; } presentation.addText(name, SimpleTextAttributes.REGULAR_ATTRIBUTES); if (myBlock.getIndent() != null) { presentation.addText(" " + String.valueOf(myBlock.getIndent()).replaceAll("[<>]", " "), SimpleTextAttributes.GRAY_ATTRIBUTES); } else { presentation.addText(" Indent: null", SimpleTextAttributes.GRAY_ATTRIBUTES); } if (myBlock.getAlignment() != null) { presentation .addText(" " + String.valueOf(myBlock.getAlignment()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_BOLD, Color.darkGray)); } if (myBlock.getWrap() != null) { presentation .addText(" " + String.valueOf(myBlock.getWrap()), new SimpleTextAttributes(SimpleTextAttributes.STYLE_ITALIC, PlatformColors.BLUE)); } }
@Override protected void paintComponent(Graphics g) { super.paintComponent(g); if(myDropTargetIndex >= 0) { int dropLineY; Rectangle rc; if(myDropTargetIndex == myGroup.getItems().length) { rc = getCellBounds(myDropTargetIndex - 1, myDropTargetIndex - 1); dropLineY = (int) rc.getMaxY() - 1; } else { rc = getCellBounds(myDropTargetIndex, myDropTargetIndex); dropLineY = rc.y; } Graphics2D g2d = (Graphics2D) g; g2d.setColor(PlatformColors.BLUE); g2d.setStroke(new BasicStroke(2.0f)); g2d.drawLine(rc.x, dropLineY, rc.x + rc.width, dropLineY); g2d.drawLine(rc.x, dropLineY - 2, rc.x, dropLineY + 2); g2d.drawLine(rc.x + rc.width, dropLineY - 2, rc.x + rc.width, dropLineY + 2); } }
public HyperlinkLabel(String text) { this(text, PlatformColors.BLUE, new JBColor(new NotNullProducer<Color>() { @NotNull @Override public Color produce() { return UIUtil.getLabelBackground(); } }), PlatformColors.BLUE); }
public HyperlinkLabel createActionLabel(final String text, final Runnable action) { HyperlinkLabel label = new HyperlinkLabel(text, PlatformColors.BLUE, getBackground(), PlatformColors.BLUE); label.addHyperlinkListener(new HyperlinkAdapter() { @Override protected void hyperlinkActivated(HyperlinkEvent e) { action.run(); } }); myLinksPanel.add(label); return label; }
@Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { if (value instanceof RepoPackage) { RepoPackage repoPackage = (RepoPackage) value; String name = repoPackage.getName(); if (myCurrentlyInstalling.contains(name)) { final String colorCode = UIUtil.isUnderDarcula() ? "589df6" : "0000FF"; name = "<html><body>" + repoPackage.getName() + " <font color=\"#" + colorCode + "\">(installing)</font></body></html>"; } myNameLabel.setText(name); myRepositoryLabel.setText(repoPackage.getRepoUrl()); Component orig = super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); final Color fg = orig.getForeground(); myNameLabel.setForeground(myInstalledPackages.contains(name) ? PlatformColors.BLUE : fg); } myRepositoryLabel.setForeground(JBColor.GRAY); final Color bg; if (isSelected) { bg = UIUtil.getListSelectionBackground(); } else { bg = index % 2 == 1 ? UIUtil.getListBackground() : UIUtil.getDecoratedRowColor(); } myPanel.setBackground(bg); myNameLabel.setBackground(bg); myRepositoryLabel.setBackground(bg); return myPanel; }
public void paintFeedback(Graphics2D g2d, Rectangle rc) { g2d.setColor(PlatformColors.BLUE); g2d.setStroke(new BasicStroke(1.5f)); int right = rc.x + rc.width - 1; int bottom = rc.y + rc.height - 1; int midX = (int) rc.getCenterX(); g2d.drawLine(rc.x, rc.y, midX, rc.y+GridInsertLocation.INSERT_ARROW_SIZE); g2d.drawLine(right, rc.y, midX, rc.y+GridInsertLocation.INSERT_ARROW_SIZE); g2d.drawLine(midX, rc.y+GridInsertLocation.INSERT_ARROW_SIZE, midX, bottom-GridInsertLocation.INSERT_ARROW_SIZE); g2d.drawLine(rc.x, bottom, midX, bottom-GridInsertLocation.INSERT_ARROW_SIZE); g2d.drawLine(right, bottom, midX, bottom-GridInsertLocation.INSERT_ARROW_SIZE); }
public void paintFeedback(Graphics2D g2d, Rectangle rc) { g2d.setColor(PlatformColors.BLUE); g2d.setStroke(new BasicStroke(1.5f)); int midY = (int)rc.getCenterY(); int right = rc.x + rc.width - 1; int bottom = rc.y + rc.height - 1; g2d.drawLine(rc.x, rc.y, GridInsertLocation.INSERT_ARROW_SIZE, midY); g2d.drawLine(rc.x, bottom, GridInsertLocation.INSERT_ARROW_SIZE, midY); g2d.drawLine(GridInsertLocation.INSERT_ARROW_SIZE, midY, right - GridInsertLocation.INSERT_ARROW_SIZE, midY); g2d.drawLine(right, rc.y, rc.x+rc.width-GridInsertLocation.INSERT_ARROW_SIZE, midY); g2d.drawLine(right, bottom, right-GridInsertLocation.INSERT_ARROW_SIZE, midY); }
@Override public void paintCaptionDecoration(final RadContainer container, final boolean isRow, final int index, final Graphics2D g2d, final Rectangle rc) { // don't paint gap rows/columns with red background if (isGapCell(container, isRow, index)) { g2d.setColor(Color.LIGHT_GRAY); g2d.fillRect(rc.x, rc.y, rc.width, rc.height); } if (canCellGrow(container, isRow, index)) { drawGrowMarker(isRow, g2d, rc); } FormLayout layout = (FormLayout) container.getLayout(); int[][] groups = isRow ? layout.getRowGroups() : layout.getColumnGroups(); //noinspection MultipleVariablesInDeclaration boolean haveTopLeft = false, haveTopRight = false, haveTopLine = false; //noinspection MultipleVariablesInDeclaration boolean haveBottomLeft = false, haveBottomRight = false, haveBottomLine = false; boolean inGroup = false; for(int i=0; i<groups.length; i++) { int minMember = Integer.MAX_VALUE; int maxMember = -1; for(int member: groups [i]) { minMember = Math.min(member-1, minMember); maxMember = Math.max(member-1, maxMember); inGroup = inGroup || (member-1 == index); } if (minMember <= index && index <= maxMember) { if (i % 2 == 0) { haveTopLeft = haveTopLeft || index > minMember; haveTopRight = haveTopRight || index < maxMember; haveTopLine = haveTopLine || inGroup; } else { haveBottomLeft = haveBottomLeft || index > minMember; haveBottomRight = haveBottomRight || index < maxMember; haveBottomLine = haveBottomLine || inGroup; } } } g2d.setColor(PlatformColors.BLUE); drawGroupLine(rc, isRow, g2d, true, haveTopLeft, haveTopRight, haveTopLine); drawGroupLine(rc, isRow, g2d, false, haveBottomLeft, haveBottomRight, haveBottomLine); }
public LinkRenderer() { label.setForeground(PlatformColors.BLUE); Font font = label.getFont(); Map attributes = font.getAttributes(); attributes.put(TextAttribute.UNDERLINE, TextAttribute.UNDERLINE_ON); label.setFont(font.deriveFont(attributes)); }
public HyperlinkLabel createActionLabel(final String text, final Runnable action) { HyperlinkLabel label = new HyperlinkLabel(text, PlatformColors.BLUE, getBackground(), PlatformColors.BLUE); label.addHyperlinkListener(new HyperlinkListener() { public void hyperlinkUpdate(final HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { action.run(); } } }); myLinksPanel.add(label); return label; }
static JComponent createComponentForTitle(@Nullable String title, @NotNull final LineSeparator separator, boolean left) { JPanel bottomPanel = new JPanel(new BorderLayout()); JLabel sepLabel = new JLabel(separator.name()); sepLabel.setForeground(separator.equals(LineSeparator.CRLF) ? JBColor.RED : PlatformColors.BLUE); bottomPanel.add(sepLabel, left ? BorderLayout.EAST : BorderLayout.WEST); JPanel panel = new JPanel(new BorderLayout()); panel.add(new JLabel(title == null ? "" : title)); panel.add(bottomPanel, BorderLayout.SOUTH); return panel; }
/** * Renders checkbox tree cell filled with @{link TemplateTreeNode} data. * * @param tree current working tree * @param value template data * @param selected node is selected * @param expanded node is expanded * @param leaf node is a leaf * @param row node is a row * @param hasFocus node has focus */ public void customizeRenderer(final JTree tree, final Object value, final boolean selected, final boolean expanded, final boolean leaf, final int row, final boolean hasFocus) { if (!(value instanceof TemplateTreeNode)) { return; } TemplateTreeNode node = (TemplateTreeNode) value; final Color background = selected ? UIUtil.getTreeSelectionBackground() : UIUtil.getTreeTextBackground(); UIUtil.changeBackGround(this, background); Color foreground = selected ? UIUtil.getTreeSelectionForeground() : node.getTemplate() == null ? PlatformColors.BLUE : UIUtil.getTreeTextForeground(); int style = SimpleTextAttributes.STYLE_PLAIN; String text = "", hint = ""; if (node.getTemplate() != null) { // template leaf text = node.getTemplate().getName(); } else if (node.getContainer() != null) { // container group hint = IgnoreBundle.message("template.container." + node.getContainer().toString().toLowerCase()); getCheckbox().setVisible(false); } SearchUtil.appendFragments(getFilter(), text, style, foreground, background, getTextRenderer()); getTextRenderer().append(hint, selected ? new SimpleTextAttributes(Font.PLAIN, foreground) : SimpleTextAttributes.GRAYED_ATTRIBUTES); setForeground(foreground); }
public HoverHyperlinkLabel(String text) { this(text, PlatformColors.BLUE); }
private JPanel createShortContextPanel(final boolean allowNoContexts) { JPanel panel = new JPanel(new BorderLayout()); final JLabel ctxLabel = new JLabel(); final JLabel change = new JLabel(); change.setForeground(PlatformColors.BLUE); change.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR)); panel.add(ctxLabel, BorderLayout.CENTER); panel.add(change, BorderLayout.EAST); final Runnable updateLabel = new Runnable() { @Override public void run() { myExpandByCombo.setEnabled(isExpandableFromEditor()); updateHighlighter(); StringBuilder sb = new StringBuilder(); String oldPrefix = ""; for (TemplateContextType type : getApplicableContexts()) { final TemplateContextType base = type.getBaseContextType(); String ownName = UIUtil.removeMnemonic(type.getPresentableName()); String prefix = ""; if (base != null && !(base instanceof EverywhereContextType)) { prefix = UIUtil.removeMnemonic(base.getPresentableName()) + ": "; ownName = StringUtil.decapitalize(ownName); } if (type instanceof EverywhereContextType) { ownName = "Other"; } if (sb.length() > 0) { sb.append(oldPrefix.equals(prefix) ? ", " : "; "); } if (!oldPrefix.equals(prefix)) { sb.append(prefix); oldPrefix = prefix; } sb.append(ownName); } final boolean noContexts = sb.length() == 0; String contexts = (noContexts ? "No applicable contexts" + (allowNoContexts ? "" : " yet") : "Applicable in " + sb.toString()) + ". "; ctxLabel.setText(StringUtil.first(contexts, 100, true)); ctxLabel.setForeground(noContexts ? allowNoContexts ? JBColor.GRAY : JBColor.RED : UIUtil.getLabelForeground()); change.setText(noContexts ? "Define" : "Change"); } }; new ClickListener() { @Override public boolean onClick(@NotNull MouseEvent e, int clickCount) { if (disposeContextPopup()) return false; final JPanel content = createPopupContextPanel(updateLabel, myContext); Dimension prefSize = content.getPreferredSize(); if (myLastSize != null && (myLastSize.width > prefSize.width || myLastSize.height > prefSize.height)) { content.setPreferredSize(new Dimension(Math.max(prefSize.width, myLastSize.width), Math.max(prefSize.height, myLastSize.height))); } myContextPopup = JBPopupFactory.getInstance().createComponentPopupBuilder(content, null).setResizable(true).createPopup(); myContextPopup.show(new RelativePoint(change, new Point(change.getWidth() , -content.getPreferredSize().height - 10))); myContextPopup.addListener(new JBPopupAdapter() { @Override public void onClosed(LightweightWindowEvent event) { myLastSize = content.getSize(); } }); return true; } }.installOn(change); updateLabel.run(); return panel; }
public static void paintComponentTag(final RadComponent component, final Graphics g) { if (component instanceof RadContainer) return; for (IProperty prop : component.getModifiedProperties()) { if (prop.getName().equals(SwingProperties.TEXT)) { final Object desc = prop.getPropertyValue(component); if (!(desc instanceof StringDescriptor) || ((StringDescriptor)desc).getValue() == null || ((StringDescriptor)desc).getValue().length() > 0) { return; } } else if (prop.getName().equals(SwingProperties.MODEL)) { // don't paint tags on non-empty lists final Object value = prop.getPropertyValue(component); if (value instanceof String[] && ((String[])value).length > 0) { return; } } } Rectangle bounds = component.getDelegee().getBounds(); if (bounds.width > 100 && bounds.height > 40) { StringBuilder tagBuilder = new StringBuilder(); if (component.getBinding() != null) { tagBuilder.append(component.getBinding()).append(':'); } String className = component.getComponentClassName(); int pos = className.lastIndexOf('.'); if (pos >= 0) { tagBuilder.append(className.substring(pos + 1)); } else { tagBuilder.append(className); } final Rectangle2D stringBounds = g.getFontMetrics().getStringBounds(tagBuilder.toString(), g); Graphics2D g2d = (Graphics2D)g; g2d.setColor(PlatformColors.BLUE); g2d.fillRect(0, 0, (int)stringBounds.getWidth(), (int)stringBounds.getHeight()); g2d.setColor(JBColor.WHITE); UISettings.setupAntialiasing(g); g.drawString(tagBuilder.toString(), 0, g.getFontMetrics().getAscent()); } }
public HyperlinkLabel(String text) { this(text, PlatformColors.BLUE, UIUtil.getLabelBackground(), PlatformColors.BLUE); }
@Override public Component getTreeCellRendererComponent(JTree tree, Object value, boolean selected, boolean expanded, boolean leaf, int row, boolean hasFocus) { Color foreground = selected ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeForeground(); Color background = selected ? UIUtil.getTreeSelectionBackground() : null; if (value instanceof HierarchyTree.ComponentNode) { HierarchyTree.ComponentNode componentNode = (HierarchyTree.ComponentNode)value; Component component = componentNode.getOwnComponent(); String name = component.getName(); if (StringUtil.isEmpty(name)) { name = component.getClass().getSimpleName(); if (name.isEmpty()) { name = component.getClass().getSuperclass().getSimpleName(); } } if (!selected) { if (!component.isVisible()) { foreground = Color.GRAY; } else if (component.getWidth() == 0 || component.getHeight() == 0) { foreground = new Color(128, 10, 0); } else if (component.getPreferredSize() != null && (component.getSize().width < component.getPreferredSize().width || component.getSize().height < component.getPreferredSize().height)) { foreground = PlatformColors.BLUE; } if (componentNode.getToSelect() == componentNode.getOwnComponent()) { background = new Color(31, 128, 8, 58); } } setText(name); } setForeground(foreground); setBackground(background); return this; }