下面列出了java.awt.image.FilteredImageSource#com.intellij.ui.JBColor 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
/**
* http://stackoverflow.com/questions/665406/how-to-make-a-color-transparent-in-a-bufferedimage-and-save-as-png
*
* @param image the image
* @return the image
*/
public static Image whiteToTransparent(@NotNull BufferedImage image) {
ImageFilter filter = new RGBImageFilter() {
int markerRGB = JBColor.WHITE.getRGB() | 0xFF000000;
@Override
public final int filterRGB(int x, int y, int rgb) {
if ((rgb | 0xFF000000) == markerRGB) {
// Mark the alpha bits as zero - transparent
return 0x00FFFFFF & rgb;
} else {
// nothing to do
return rgb;
}
}
};
ImageProducer ip = new FilteredImageSource(image.getSource(), filter);
return Toolkit.getDefaultToolkit().createImage(ip);
}
private void writeHeader(@NonNls Writer writer, String title) throws IOException {
EditorColorsScheme scheme = EditorColorsManager.getInstance().getGlobalScheme();
writer.write("<html>\r\n");
writer.write("<head>\r\n");
writer.write("<title>" + title + "</title>\r\n");
writer.write("<meta http-equiv=\"Content-Type\" content=\"text/html; charset=utf-8\">\r\n");
writeStyles(writer);
writer.write("</head>\r\n");
Color color = scheme.getDefaultBackground();
if (color==null) color = JBColor.GRAY;
writer.write("<BODY BGCOLOR=\"#" + Integer.toString(color.getRGB() & 0xFFFFFF, 16) + "\">\r\n");
writer.write("<TABLE CELLSPACING=0 CELLPADDING=5 COLS=1 WIDTH=\"100%\" BGCOLOR=\"#C0C0C0\" >\r\n");
writer.write("<TR><TD><CENTER>\r\n");
writer.write("<FONT FACE=\"Arial, Helvetica\" COLOR=\"#000000\">\r\n");
writer.write(title + "</FONT>\r\n");
writer.write("</center></TD></TR></TABLE>\r\n");
writer.write("<pre>\r\n");
}
public void checkYiiAppParams() {
ConfigParser parser = new ConfigParser(YiiStormProjectComponent.getInstance(project));
if (yiiLitePath.getText().length() > 0) {
if (parser.testYiiLitePath(yiiLitePath.getText())) {
yiiLitePath.setBackground(JBColor.GREEN);
if (yiiConfigPath.getText().length() > 0) {
if (parser.testYiiConfigPath(yiiConfigPath.getText())) {
yiiConfigPath.setBackground(JBColor.GREEN);
} else {
yiiConfigPath.setBackground(JBColor.PINK);
}
} else {
yiiConfigPath.setBackground(JBColor.background());
}
} else {
yiiLitePath.setBackground(JBColor.PINK);
}
} else {
yiiLitePath.setBackground(JBColor.background());
}
}
@Override
protected void paintComponent(Graphics g) {
final Graphics2D g2d = (Graphics2D)g;
final Rectangle bounds = getBounds();
final Insets insets = getInsets();
final GraphicsConfig cfg = new GraphicsConfig(g);
cfg.setAntialiasing(true);
final Shape shape = new RoundRectangle2D.Double(insets.left, insets.top, bounds.width - 1 - insets.left - insets.right,
bounds.height - 1 - insets.top - insets.bottom, 6, 6);
g2d.setColor(JBColor.WHITE);
g2d.fill(shape);
Color bgColor = getBackground();
g2d.setColor(bgColor);
g2d.fill(shape);
g2d.setColor(getBackground().darker());
g2d.draw(shape);
cfg.restore();
super.paintComponent(g);
}
public TableCellRenderer getRenderer(final ScopeSetting scopeSetting) {
return new DefaultTableCellRenderer() {
public Component getTableCellRendererComponent(JTable table,
Object value,
boolean isSelected,
boolean hasFocus,
int row,
int column) {
final Component rendererComponent = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (!isSelected) {
final CopyrightProfile profile = myProfilesModel.getAllProfiles().get(scopeSetting.getProfileName());
setForeground(profile == null ? JBColor.RED : UIUtil.getTableForeground());
}
setText(scopeSetting.getProfileName());
return rendererComponent;
}
};
}
static JComponent createTitle(@Nonnull String titleText, @Nonnull Color background) {
JLabel titleLabel = new JLabel(StringUtil.capitalizeWords(titleText, true));
titleLabel.setFont(getTitleFont());
titleLabel.setForeground(UIUtil.getLabelDisabledForeground());
SeparatorComponent separatorComponent = new SeparatorComponent(titleLabel.getPreferredSize().height / 2, new JBColor(Gray._220, Gray._80), null);
JPanel panel = new JPanel(new BorderLayout());
panel.add(titleLabel, BorderLayout.WEST);
panel.add(separatorComponent, BorderLayout.CENTER);
panel.setBorder(JBUI.Borders.empty(3));
titleLabel.setBorder(JBUI.Borders.emptyRight(3));
panel.setBackground(background);
return panel;
}
private void paintBorder() {
final int row = FocusTracesDialog.this.myRequestsTable.getSelectedRow();
if (row != -1) {
final FocusRequestInfo info = FocusTracesDialog.this.myRequests.get(row);
if (prev != null && prev != info.getComponent()) {
prev.repaint();
}
prev = info.getComponent();
if (prev != null && prev.isDisplayable()) {
final Graphics g = prev.getGraphics();
g.setColor(JBColor.RED);
final Dimension sz = prev.getSize();
UIUtil.drawDottedRectangle(g, 1, 1, sz.width - 2, sz.height - 2);
}
}
}
@Nonnull
private static Image createMnemonicIcon(char cha) {
int width = AllIcons.Actions.Checked.getWidth();
int height = AllIcons.Actions.Checked.getHeight();
return ImageEffects.canvas(width, height, c -> {
// FIXME [VISTALL] make constant ??
c.setFillStyle(TargetAWT.from(new JBColor(new Color(0xffffcc), new Color(0x675133))));
c.fillRect(0, 0, width, height);
c.setStrokeStyle(StandardColors.GRAY);
c.rect(0, 0, width, height);
c.stroke();
c.setFillStyle(ComponentColors.TEXT);
c.setFont(FontManager.get().createFont("Monospaced", 11, consulo.ui.font.Font.STYLE_BOLD));
c.setTextAlign(Canvas2D.TextAlign.center);
c.setTextBaseline(Canvas2D.TextBaseline.middle);
c.fillText(Character.toString(cha), width / 2, height / 2 - 2);
});
}
@NotNull
public static Color forCategory(@NotNull String category) {
if (category.equals(ERROR_CATEGORY)) {
return JBColor.red;
}
if (category.startsWith("flutter.")) {
return JBColor.gray;
}
if (category.startsWith("runtime.")) {
return UIUtil.isUnderDarcula() ? JBColor.magenta : JBColor.pink;
}
if (category.equals("http")) {
return JBColor.blue;
}
// TODO(pq): add more presets.
// Default.
return JBColor.darkGray;
}
protected void updateStyle(@Nonnull JEditorPane editorPane, @Nullable JTree tree, Object value, boolean selected, boolean hasFocus) {
final HTMLDocument htmlDocument = (HTMLDocument)editorPane.getDocument();
final Style style = htmlDocument.getStyleSheet().getStyle(MSG_STYLE);
if (value instanceof LoadingNode) {
StyleConstants.setForeground(style, JBColor.GRAY);
}
else {
if (selected) {
StyleConstants.setForeground(style, hasFocus ? UIUtil.getTreeSelectionForeground() : UIUtil.getTreeTextForeground());
}
else {
StyleConstants.setForeground(style, UIUtil.getTreeTextForeground());
}
}
if (UIUtil.isUnderGTKLookAndFeel() ||
UIUtil.isUnderNimbusLookAndFeel() && selected && hasFocus ||
tree != null && tree.getUI() instanceof WideSelectionTreeUI && ((WideSelectionTreeUI)tree.getUI()).isWideSelection()) {
editorPane.setOpaque(false);
}
else {
editorPane.setOpaque(selected && hasFocus);
}
htmlDocument.setCharacterAttributes(0, htmlDocument.getLength(), style, false);
}
@Override
public Component getListCellRendererComponent(JList<? extends ConfigProblem> list, ConfigProblem problem,
int index, boolean isSelected, boolean cellHasFocus) {
cell.setForeground(problem.isError()
? JBColor.RED
: UIUtil.getTextAreaForeground());
// > v183 has nice API for this...
cell.setBackground(
isSelected
? cellHasFocus
? UIUtil.getListUnfocusedSelectionBackground()
: UIUtil.getListSelectionBackground()
: UIUtil.getListBackground()
);
cell.setText(problem.getMessage());
return cell;
}
@NotNull
public static Color forCategory(@NotNull String category) {
if (category.equals(ERROR_CATEGORY)) {
return JBColor.red;
}
if (category.startsWith("flutter.")) {
return JBColor.gray;
}
if (category.startsWith("runtime.")) {
return UIUtil.isUnderDarcula() ? JBColor.magenta : JBColor.pink;
}
if (category.equals("http")) {
return JBColor.blue;
}
// TODO(pq): add more presets.
// Default.
return JBColor.darkGray;
}
@Override
public void customize(JList list, ModuleDescription moduleDescription, int index, boolean selected, boolean hasFocus) {
if (moduleDescription == null) {
setText(myEmptySelectionText);
}
else {
if (moduleDescription instanceof LoadedModuleDescription) {
setIcon(AllIcons.Nodes.Module);
setForeground(null);
}
else {
setIcon(AllIcons.Nodes.Module); //FIXME [VISTALL] another icon?
setForeground(JBColor.RED);
}
setText(moduleDescription.getName());
}
}
@Override
protected void customizeCellRenderer(JList list, Object value, int index, boolean selected, boolean hasFocus) {
Color bgColor = UIUtil.getListBackground();
setPaintFocusBorder(hasFocus && UIUtil.isToUseDottedCellBorder());
if (value instanceof StringElement) {
StringElement element = (StringElement) value;
String stringKeyText = "(" + element.getName() + ")";
String text = new StringEllipsisPolicy().ellipsizeText(element.getValue(), matcher);
SimpleTextAttributes nameAttributes = new SimpleTextAttributes(Font.PLAIN, list.getForeground());
SpeedSearchUtil.appendColoredFragmentForMatcher(text, this, nameAttributes, matcher, bgColor, selected);
// TODO Change icon
setIcon(AndroidIcons.EmptyFlag);
append(" " + stringKeyText, new SimpleTextAttributes(Font.PLAIN, JBColor.GRAY));
}
setBackground(selected ? UIUtil.getListSelectionBackground() : bgColor);
}
private void updateStatusLabel(final boolean testingFinished) {
if (myFailedTestCount > 0) {
myStatusLine.setStatusColor(ColorProgressBar.RED);
}
if (testingFinished) {
if (myTotalTestCount == 0) {
myStatusLine.setStatusColor(myTestsRootNode.wasLaunched() || !myTestsRootNode.isTestsReporterAttached() ? JBColor.LIGHT_GRAY : ColorProgressBar.RED);
}
// else color will be according failed/passed tests
}
// launchedAndFinished - is launched and not in progress. If we remove "launched' that onTestingStarted() before
// initializing will be "launchedAndFinished"
final boolean launchedAndFinished = myTestsRootNode.wasLaunched() && !myTestsRootNode.isInProgress();
if (!TestsPresentationUtil.hasNonDefaultCategories(myMentionedCategories)) {
myStatusLine.formatTestMessage(myTotalTestCount, myFinishedTestCount, myFailedTestCount, myIgnoredTestCount, myTestsRootNode.getDuration(), myEndTime);
}
else {
myStatusLine.setText(TestsPresentationUtil.getProgressStatus_Text(myStartTime, myEndTime, myTotalTestCount, myFinishedTestCount, myFailedTestCount,
myMentionedCategories, launchedAndFinished));
}
}
public ArrangementColorsProviderImpl(@Nullable ArrangementColorsAware colorsAware) {
myColorsAware = colorsAware;
// Default settings.
myDefaultNormalAttributes.setForegroundColor(UIUtil.getTreeTextForeground());
myDefaultNormalAttributes.setBackgroundColor(UIUtil.getPanelBackground());
myDefaultSelectedAttributes.setForegroundColor(UIUtil.getTreeSelectionForeground());
myDefaultSelectedAttributes.setBackgroundColor(UIUtil.getTreeSelectionBackground());
myDefaultNormalBorderColor = UIUtil.getBorderColor();
Color selectionBorderColor = UIUtil.getTreeSelectionBorderColor();
if (selectionBorderColor == null) {
selectionBorderColor = JBColor.black;
}
myDefaultSelectedBorderColor = selectionBorderColor;
}
public void setStartRuleName(VirtualFile grammarFile, String startRuleName) {
startRuleLabel.setText(String.format(startRuleLabelText, grammarFile.getName(), startRuleName));
startRuleLabel.setForeground(JBColor.BLACK);
final Font oldFont = startRuleLabel.getFont();
startRuleLabel.setFont(oldFont.deriveFont(Font.BOLD));
startRuleLabel.setIcon(Icons.FILE);
}
private void setWaiting() {
errorsList.setForeground(new JBColor(new Color(GRAY), new Color(DARK_GRAY)));
errorsList.setCellRenderer(defaultRenderer);
mypyStatus.setText("Running...");
mypyStatus.setForeground(new JBColor(new Color(BLACK), new Color(GRAY)));
mypyStatus.setBackground(new JBColor(new Color(WHITE), new Color(BLACK)));
errorsList.setListData(new MypyError[] {});
errorsList.setPaintBusy(true);
mypyRun.setText("Wait...");
mypyRun.setEnabled(false);
}
public void annotateErrorsInPreviewInputEditor(SyntaxError e) {
Editor editor = getInputEditor();
if ( editor==null ) return;
MarkupModel markupModel = editor.getMarkupModel();
int a, b; // Start and stop index
RecognitionException cause = e.getException();
if ( cause instanceof LexerNoViableAltException ) {
a = ((LexerNoViableAltException) cause).getStartIndex();
b = ((LexerNoViableAltException) cause).getStartIndex()+1;
}
else {
Token offendingToken = e.getOffendingSymbol();
a = offendingToken.getStartIndex();
b = offendingToken.getStopIndex()+1;
}
final TextAttributes attr = new TextAttributes();
attr.setForegroundColor(JBColor.RED);
attr.setEffectColor(JBColor.RED);
attr.setEffectType(EffectType.WAVE_UNDERSCORE);
RangeHighlighter highlighter =
markupModel.addRangeHighlighter(a,
b,
ERROR_LAYER, // layer
attr,
HighlighterTargetArea.EXACT_RANGE);
highlighter.putUserData(SYNTAX_ERROR, e);
}
static void show(Project project) {
MypyHelp dialog = new MypyHelp();
dialog.pack();
dialog.setSize(600, 400);
JFrame frame = WindowManager.getInstance().getFrame(project);
dialog.setLocationRelativeTo(frame);
dialog.textPane.setCaretPosition(0);
dialog.textPane.setForeground(new JBColor(MypyTerminal.BLACK, MypyTerminal.GRAY));
dialog.textPane.setBackground(new JBColor(new Color(MypyTerminal.WHITE),
dialog.contentPane.getBackground()));
dialog.setVisible(true);
}
ReplacementView(@Nullable String replacement) {
String textToShow = replacement;
if (replacement == null) {
textToShow = MALFORMED_REPLACEMENT_STRING;
}
JLabel jLabel = new JLabel(textToShow);
jLabel.setForeground(replacement != null ? new JBColor(Gray._240, Gray._200) : JBColor.RED);
add(jLabel);
}
private static void exportToImage(UberTreeViewer parseTreeViewer, File file, boolean useTransparentBackground, String imageFormat) {
int imageType = useTransparentBackground ? BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
BufferedImage bi = UIUtil.createImage(parseTreeViewer.getWidth(), parseTreeViewer.getHeight(), imageType);
Graphics graphics = bi.getGraphics();
if (!useTransparentBackground) {
graphics.setColor(JBColor.WHITE);
graphics.fillRect(0, 0, parseTreeViewer.getWidth(), parseTreeViewer.getHeight());
}
parseTreeViewer.paint(graphics);
try {
if (!ImageIO.write(bi, imageFormat, file)) {
Notification notification = new Notification(
"ANTLR 4 export",
"Error while exporting parse tree to file " + file.getAbsolutePath(),
"unknown format '" + imageFormat + "'?",
NotificationType.WARNING
);
Notifications.Bus.notify(notification);
}
} catch (IOException e) {
Logger.getInstance(ParseTreeContextualMenu.class)
.error("Error while exporting parse tree to file " + file.getAbsolutePath(), e);
}
}
@Override
public void appendFileName(final ChangesBrowserNodeRenderer renderer, final VirtualFile vFile, final String fileName, final Color color, final boolean highlightProblems) {
int style = SimpleTextAttributes.STYLE_PLAIN;
Color underlineColor = null;
if (highlightProblems && vFile != null && !vFile.isDirectory() && myProblemSolver.isProblemFile(vFile)) {
underlineColor = JBColor.RED;
style = SimpleTextAttributes.STYLE_WAVED;
}
renderer.append(fileName, new SimpleTextAttributes(style, color, underlineColor));
}
@Override
public Component getListCellRendererComponent(JList<? extends StatisticsItem> list, StatisticsItem value, int index, boolean isSelected, boolean cellHasFocus) {
final Color foreground = list.getForeground();
final Color background = list.getBackground();
final String message = KeyPromoterBundle.message(
"kp.list.suppressed.item",
value.getShortcut(),
value.description
);
if (isSelected) {
setBackground(JBColor.GRAY);
} else {
setBackground(background);
}
setText(message);
setForeground(foreground);
setBorder(JBUI.Borders.empty(2, 10));
if (value.ideaActionID != null && !"".equals(value.ideaActionID)) {
final AnAction action = ActionManager.getInstance().getAction(value.ideaActionID);
if (action != null) {
final Icon icon = action.getTemplatePresentation().getIcon();
if (icon != null) {
setIcon(icon);
} else {
setIcon(KeyPromoterIcons.KP_ICON);
}
}
}
return this;
}
public ReplacementView(@Nullable String replacement) {
String textToShow = StringUtil.notNullize(replacement, MALFORMED_REPLACEMENT_STRING);
textToShow = StringUtil.escapeXmlEntities(StringUtil.shortenTextWithEllipsis(textToShow, 500, 0, true)).replaceAll("\n+", "\n").replace("\n", "<br>");
//noinspection HardCodedStringLiteral
JLabel jLabel = new JBLabel("<html>" + textToShow).setAllowAutoWrapping(true);
jLabel.setForeground(replacement != null ? new JBColor(Gray._240, Gray._200) : JBColor.RED);
add(jLabel);
}
@Override
protected void paintTrack(Graphics g, JComponent c, Rectangle bounds) {
g.setColor(new JBColor(LightColors.SLIGHTLY_GRAY, UIUtil.getListBackground()));
g.fillRect(bounds.x, bounds.y, bounds.width, bounds.height);
RegionPainter<Object> painter = UIUtil.getClientProperty(c, ScrollBarUIConstants.TRACK);
if (painter != null) {
painter.paint((Graphics2D)g, bounds.x, bounds.y, bounds.width, bounds.height, null);
}
}
@Nonnull
private static SideBorder createTopBottomSideBorder(boolean top) {
return new SideBorder(null, top ? SideBorder.BOTTOM : SideBorder.TOP) {
@Override
public Color getLineColor() {
Color result = EditorColorsManager.getInstance().getGlobalScheme().getColor(EditorColors.TEARLINE_COLOR);
return result == null ? JBColor.BLACK : result;
}
};
}
NixIDEASettings(@NotNull Project project) {
this.projectProperties = PropertiesComponent.getInstance(project);
settings = Arrays.asList((Setting) new ResettableEnvField("NIX_PATH", (TextFriend) new TextComponent(nixPath))
, (Setting) new ResettableEnvField("NIX_PROFILES", (TextFriend) new TextComponent(nixProfiles))
, (Setting) new ResettableEnvField("NIX_OTHER_STORES", (TextFriend) new TextComponent(nixOtherStores))
, (Setting) new ResettableEnvField("NIX_REMOTE", (TextFriend) new TextComponent(nixRemote))
, (Setting) new ResettableEnvField("NIXPKGS_CONFIG", (TextFriend) new TextComponent(nixPkgsConfig))
, (Setting) new ResettableEnvField("NIX_CONF_DIR", (TextFriend) new TextComponent(nixConfDir))
, (Setting) new ResettableEnvField("NIX_USER_PROFILE_DIR", (TextFriend) new TextComponent(nixUserProfileDir))
);
final Color originalBackground = nixPath.getBackground();
nixPath.setInputVerifier(new InputVerifier() {
@Override
public boolean verify(JComponent input) {
JTextField tf = (JTextField) input;
NixPathVerifier npv = new NixPathVerifier(tf.getText());
if (npv.verify()) {
input.setBackground(originalBackground);
return true;
} else {
//Some parts of the paths are inaccessible
//TODO: change to individual path strikeout
input.setBackground(JBColor.RED);
return false;
}
}
});
}
public void buildView() {
setTitle(Localizer.get("title.LibraryDialog"));
panel.setBackground(JBColor.BLUE);
tabbedPane = new JBTabbedPane();
panel.add(tabbedPane, new CC().push().grow());
initBinaryFilesTab();
initSecondTab();
}
private void appendError(String text) {
errors.add(text);
myLabel.setBounds(0, 0, 0, 0);
StringBuilder sb = new StringBuilder("<html><font color='#" + ColorUtil.toHex(JBColor.RED) + "'>");
errors.forEach(error -> sb.append("<left>").append(error).append("</left><br/>"));
sb.append("</font></html>");
myLabel.setText(sb.toString());
setVisible(true);
updateSize();
}