Javaawtcolor Example Code
Java Code Examples for java.awt.Color
The following code examples are extracted from open source projects. You can click to vote up the examples that are useful to you.
Example 1
From project 3Dto2DApplet, under directory /src/java/nl/dannyarends/generic/.
Source file: ColorUtils.java
27
public static Color doubleToColor(double x,double maxx){ float cR=(float)(0.5 + (x / (2 * maxx))); float cG=(float)(0.5 - (x / (2 * maxx))); float cB=(float)(0.5 - (x / (2 * maxx))); Color c=new Color(cR,cG,cB); return c; } Example 2
From project addis, under directory /application/src/main/java/org/drugis/addis/gui/renderer/.
Source file: BRATForestCellRenderer.java
26
@Override public Component getTableCellRendererComponent(JTable table,Object value,boolean isSelected,boolean hasFocus,int row,int column){ Component superRenderer=super.getTableCellRendererComponent(table,value,isSelected,hasFocus,row,column); final Color bg=superRenderer.getBackground(); final Color fg=superRenderer.getForeground(); final BRATForest forest=(BRATForest)value; JPanel panel=new ForestPlotTableCell(forest,bg,fg); return panel; } Example 3
From project alg-vis, under directory /src/algvis/gui/view/.
Source file: View.java
26
void drawWideLine(double x1,double y1,double x2,double y2,float width,Color col){ final Stroke old=g.getStroke(), wide=new BasicStroke(width,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND); final Color c=g.getColor(); g.setColor(col); g.setStroke(wide); g.drawLine((int)x1,(int)y1,(int)x2,(int)y2); g.setStroke(old); g.setColor(c); } Example 4
From project arquillian-graphene, under directory /graphene-selenium/graphene-selenium-impl/src/main/java/org/jboss/arquillian/ajocado/utils/.
Source file: ColorUtils.java
26
/** * <p> Converts a string representation of color to AWT Color object. </p> <p> Works with two formats: </p> <ul> <li><code>#09FE4A</code> - <b>hexadecimal</b></li> <li><code>rgb(132, 5, 18)</code> - <b>decimal</b></li> </ul> * @param colorValue string represented in one of two formats * @return AWT's Color value representation of string-represented colorValue; if colorValue is null, returns null */ public static Color convertToAWTColor(String colorValue){ if (colorValue == null) { return null; } int convertedValue=convertToInteger(colorValue); return new Color(convertedValue); } Example 5
From project arquillian-rusheye, under directory /rusheye-impl/src/main/java/org/jboss/rusheye/core/.
Source file: ColorModelRGBA.java
26
static Color rgb2grayscale(int color){ int r=getR(color); int g=getG(color); int b=getB(color); float gray=(0.3f * r + 0.59f * g + 0.11f * b) / 255.0f; return new Color(gray,gray,gray); } Example 6
From project beanmill_1, under directory /src/main/java/com/traxel/lumbermill/event/.
Source file: SeverityCellView.java
26
@Override public Component getTableCellRendererComponent(final JTable table,final Object value,final boolean isSelected,final boolean hasFocus,final int row,final int column){ final Severity severity; Color color; final int angle; severity=(Severity)value; color=SeverityView.getColor(severity); color=Colors.blend(2,color,1,Color.white); setBackground(color); setFont(table.getFont()); setValue(" " + severity.toString()); return this; } Example 7
From project BMach, under directory /src/jsyntaxpane/components/.
Source file: LineNumbersRuler.java
26
@Override public void config(Configuration config){ int right=config.getInteger(PROPERTY_RIGHT_MARGIN,DEFAULT_R_MARGIN); int left=config.getInteger(PROPERTY_LEFT_MARGIN,DEFAULT_L_MARGIN); Color foreground=config.getColor(PROPERTY_FOREGROUND,Color.BLACK); setForeground(foreground); Color back=config.getColor(PROPERTY_BACKGROUND,Color.WHITE); setBackground(back); setBorder(BorderFactory.createEmptyBorder(0,left,0,right)); currentLineColor=config.getColor(PROPERTY_CURRENT_BACK,back); } Example 8
From project Calendar-Application, under directory /com/toedter/components/.
Source file: JTitlePanel.java
26
public void paintComponent(Graphics g){ super.paintComponent(g); if (isOpaque()) { Color controlColor=new Color(165,201,215); int width=getWidth(); int height=getHeight(); Graphics2D g2=(Graphics2D)g; Paint oldPaint=g2.getPaint(); g2.setPaint(new GradientPaint(0,0,getBackground(),width,0,controlColor)); g2.fillRect(0,0,width,height); g2.setPaint(oldPaint); } } Example 9
From project ceres, under directory /ceres-ui/src/main/java/com/bc/ceres/swing/.
Source file: TreeCellExtender.java
26
@Override public void paintBorder(Component c,Graphics g,int x1,int y1,int width,int height){ final int x2=x1 + width - 1; final int y2=y1 + height - 1; final Color color=g.getColor(); g.setColor(Color.DARK_GRAY); g.drawLine(x1,y1,x2,y1); g.drawLine(x1,y2,x2,y2); g.drawLine(x2,y1,x2,y2); g.setColor(color); } Example 10
From project Chess_1, under directory /src/chess/gui/.
Source file: ColorEditor.java
26
public void paintIcon(Component c,Graphics g,int x,int y){ Rectangle r=new Rectangle(x,y,WIDTH - 1,HEIGHT - 1); Graphics2D g2=(Graphics2D)g; Color oldColor=g2.getColor(); g2.setColor(color); g2.fill(r); g2.setColor(Color.BLACK); g2.draw(r); g2.setColor(oldColor); } Example 11
From project 16Blocks, under directory /src/main/java/de/minestar/sixteenblocks/Number/.
Source file: NumberUnit.java
25
private void loadFromBitmap(){ try { BufferedImage img=ImageIO.read(new File(Core.getInstance().getDataFolder(),"numbers.png")); int startX=this.number * 7; Color thisColor; int thisWidth=0; for (int y=0; y < img.getHeight(); y++) { int nowX=0; for (int x=startX; x < startX + 7; x++) { thisColor=new Color(img.getRGB(x,y)); if (y == 0) { if (thisColor.getRed() != 255) { thisWidth++; } } if (thisColor.getGreen() == 255) { this.addBlock(-nowX,img.getHeight() - y - 1,35,(byte)15); } else if (thisColor.getBlue() == 255) { this.addBlock(-nowX,img.getHeight() - y - 1,35,(byte)8); } nowX++; if (thisColor.getRed() == 255) { nowX--; } } } this.setWidth(thisWidth); } catch ( Exception e) { e.printStackTrace(); } } Example 12
From project ajah, under directory /ajah-image/src/main/java/com/ajah/image/.
Source file: ImageUtils.java
25
/** * Blends two colors with a given alpha value. * @param first The first color (subject to alpha). * @param second The second color (subject to alpha remainder). * @param alpha The alpha value of the blend. * @return The blended color. */ public static Color blend(final Color first,final Color second,final float alpha){ final int red=(int)((first.getRed() * alpha) + second.getRed() * (1 - alpha)); final int green=(int)((first.getGreen() * alpha) + second.getGreen() * (1 - alpha)); final int blue=(int)((first.getBlue() * alpha) + second.getBlue() * (1 - alpha)); return new Color(red,green,blue); } Example 13
From project anadix, under directory /conditions/anadix-section508/src/main/java/org/anadix/section508/.
Source file: ContrastUtility.java
25
/** * Counts relative luminence of a color. For more information see <a href="http://www.w3.org/TR/2007/WD-WCAG20-TECHS-20070517/Overview.html#G18">WCAG 2.0</a>. * @param color - color in form #{32bit in hexadecimal} * @return a relative luminence */ public static double countRelativeLuminance(String color){ if (color == null) { return -1; } Color c=Color.decode(normalizeColor(color)); double rsrgb=c.getRed() / 255.0; double gsrgb=c.getGreen() / 255.0; double bsrgb=c.getBlue() / 255.0; double r; if (rsrgb <= 0.03928) { r=rsrgb / 12.92; } else { r=Math.pow((rsrgb + 0.055) / 1.055,2.4); } double g; if (gsrgb <= 0.03928) { g=gsrgb / 12.92; } else { g=Math.pow((gsrgb + 0.055) / 1.055,2.4); } double b; if (bsrgb <= 0.03928) { b=bsrgb / 12.92; } else { b=Math.pow((bsrgb + 0.055) / 1.055,2.4); } double luminance=0.2126 * r + 0.7152 * g + 0.0722 * b; return luminance; } Example 14
From project ardverk-dht, under directory /components/tools/src/main/java/org/ardverk/dht/ui/.
Source file: SquashPainter.java
25
private void paintLine(Point2D.Double localhost,double width,double height,Graphics2D g){ g.setStroke(PainterUtils.DEFAULT_STROKE); g.setColor(new Color(255,0,0,alpha())); double x1=localhost.x; double y1=localhost.y; double x2=x1 + (width / (2d * 180d)) * extent(); double y2=y1; g.draw(new Line2D.Double(x1,y1,x2,y2)); } Example 15
From project BoneJ, under directory /src/org/doube/bonej/pqct/utils/.
Source file: ResultsImage.java
25
public static ImagePlus addScale(ImagePlus tempImage,double pixelSpacing){ Calibration cal=new Calibration(); cal.setUnit("mm"); cal.pixelWidth=cal.pixelHeight=pixelSpacing; tempImage.setCalibration(cal); tempImage.getProcessor().setColor(new Color(255,0,0)); tempImage.getProcessor().drawLine(5,5,(int)(5.0 + 10.0 / pixelSpacing),5); tempImage.getProcessor().drawString("1 cm",5,20); return tempImage; } Example 16
From project Carnivore, under directory /net/sourceforge/jpcap/util/.
Source file: PropertyHelper.java
25
/** * Convert a space delimited color tuple string to a color. <p> Converts a string value like "255 255 0" to a color constant, in this case, yellow. * @param key the name of the property * @return a Color object equivalent to the provided string contents. Returns white if the string is null or can't be converted. */ public static Color getColorProperty(Properties properties,Object key){ String string=(String)properties.get(key); if (string == null) { System.err.println("WARN: couldn't find color tuplet under '" + key + "'"); return Color.white; } StringTokenizer st=new StringTokenizer(string," "); Color c; try { c=new Color(Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken()),Integer.parseInt(st.nextToken())); } catch ( NoSuchElementException e) { c=Color.white; System.err.println("WARN: invalid color spec '" + string + "' in property file"); } return c; } Example 17
From project Carolina-Digital-Repository, under directory /djatoka-cdr/src/gov/lanl/adore/djatoka/plugin/.
Source file: TextWatermark.java
25
/** * Initializes the implementation, overriding default values. Property keys are typically of the form ClassName.PropName. * @param props Properties object containing implementation properties */ public void setup(Properties props){ if (props.containsKey(PROP_WATERMARK_COPYRIGHT)) msg=(String)props.get(PROP_WATERMARK_COPYRIGHT); if (props.containsKey(PROP_WATERMARK_ALLOWED)) allowedReferringEntity=(String)props.get(PROP_WATERMARK_ALLOWED); if (props.containsKey(PROP_WATERMARK_FONTNAME)) fontName=(String)props.get(PROP_WATERMARK_FONTNAME); if (props.containsKey(PROP_WATERMARK_FONTSIZE)) fontSize=Integer.parseInt((String)props.get(PROP_WATERMARK_FONTSIZE)); if (props.containsKey(PROP_WATERMARK_FONTCOLOR)) { String[] c=((String)props.get(PROP_WATERMARK_FONTCOLOR)).split(","); if (c.length > 3) color=new Color(Integer.parseInt(c[0]),Integer.parseInt(c[1]),Integer.parseInt(c[2]),Integer.parseInt(c[3])); else if (c.length == 3) color=new Color(Integer.parseInt(c[0]),Integer.parseInt(c[1]),Integer.parseInt(c[2]),150); } } Example 18
@Override public void sync(){ if (!window.isVisible()) return; g=(Graphics2D)window.getGraphics(); for (int iy=0; iy < getHeight(); ++iy) { for (int ix=0; ix < getWidth(); ++ix) { int i=iy * getWidth() + ix; byte[] working={bytes[i * 2],bytes[i * 2 + 1]}; Pixel p=Pixel.fromRGB565(working); g.setColor(new Color(p.getRed(),p.getGreen(),p.getBlue())); g.drawLine(ix,iy,ix,iy); } } } Example 19
From project bioclipse.speclipse, under directory /plugins/net.bioclipse.spectrum/src/net/bioclipse/spectrum/graph2d/.
Source file: Spectrum2DDisplay.java
24
public Graph2D makeGraph(){ Graph2D graph; DataSet data1; Axis xaxis; Axis yaxis_left; int i; int j; List<CMLPeak> peaks=spectrum.getPeakListElements().get(0).getPeakChildren(); double data[]=new double[2 * peaks.size()]; graph=new Graph2D(); graph.drawzero=false; graph.drawgrid=false; graph.setDataBackground(Color.WHITE); graph.setGraphBackground(Color.WHITE); try { graph.setMarkers(new Markers()); } catch ( Exception e) { System.out.println("Failed to create Marker URL!"); } for (i=j=0; i < peaks.size(); i++, j+=2) { data[j]=peaks.get(i).getXValue(); data[j + 1]=peaks.get(i).getYValue(); } data1=graph.loadDataSet(data,peaks.size()); data1.linestyle=0; data1.marker=1; data1.markerscale=1.5; data1.markercolor=new Color(0,0,255); xaxis=graph.createAxis(Axis.BOTTOM); xaxis.attachDataSet(data1); xaxis.setTitleFont(new Font("TimesRoman",Font.PLAIN,20)); xaxis.setLabelFont(new Font("Helvetica",Font.PLAIN,15)); yaxis_left=graph.createAxis(Axis.LEFT); yaxis_left.attachDataSet(data1); yaxis_left.setTitleFont(new Font("TimesRoman",Font.PLAIN,20)); yaxis_left.setLabelFont(new Font("Helvetica",Font.PLAIN,15)); yaxis_left.setTitleColor(new Color(0,0,255)); return graph; } Example 20
From project Agot-Java, under directory /src/main/java/got/ui/.
Source file: DrawManager.java
23
private void highlightCerseriSepcialTerritory(){ String battleTerritoryName=gameInfo.getLastSelect(); TerritoryInfo battleTerritory=gameInfo.getTerrMap().get(battleTerritoryName); String loseFamilyName=battleTerritory.getAttackFamilyName().equals("LANNISTER") ? battleTerritory.getConquerFamilyName() : battleTerritory.getAttackFamilyName(); FamilyInfo loseFamilyInfo=gameInfo.getFamiliesMap().get(loseFamilyName); for ( String terrName : loseFamilyInfo.getConquerTerritories()) { TerritoryInfo ti=gameInfo.getTerrMap().get(terrName); if (!ti.getAction().equals(Action.NONE)) { highlightTerritory(terrName,Color.RED); } } } Example 21
From project ANNIS, under directory /annis-gui/src/main/java/annis/gui/visualizers/iframe/tree/backends/staticimg/.
Source file: Java2dBackend.java
23
@Override public AbstractImageGraphicsItem makeLines(final Collection<Line2D> lines,final Color color,final Stroke stroke){ return new AbstractImageGraphicsItem(){ @Override public Rectangle2D getBounds(){ return null; } @Override public void draw( Graphics2D canvas){ canvas.setColor(color); canvas.setStroke(stroke); for ( Line2D l : lines) { canvas.draw(l); } } } ; } Example 22
From project autopsy, under directory /Core/src/org/sleuthkit/autopsy/casemodule/.
Source file: AddImageWizardPanel2.java
23
/** * Creates the database and adds the image to the XML configuration file. */ private void startAddImage(){ component.getCrDbProgressBar().setIndeterminate(true); component.changeProgressBarTextAndColor("*Adding the image may take some time for large images.",0,Color.black); addImageTask=new AddImgTask(); addImageTask.execute(); } Example 23
From project beam-third-party, under directory /beam-meris-veg/src/main/java/org/esa/beam/processor/baer/utils/.
Source file: FlagsManager.java
23
/** * Adds the bitmask definitions for this flag coding to the product passed in * @param prod */ public static void addBitmaskDefsToProduct(Product prod){ prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_FLAG_NAME,FlagsManager.INVALID_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_FLAG_NAME,Color.red,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_INPUT_FLAG_NAME,FlagsManager.INVALID_INPUT_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_INPUT_FLAG_NAME,Color.orange,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.AOT_OUT_OF_RANGE_FLAG_NAME,FlagsManager.AOT_OUT_OF_RANGE_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.AOT_OUT_OF_RANGE_FLAG_NAME,Color.pink,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.ALPHA_OUT_OF_RANGE_FLAG_NAME,FlagsManager.ALPHA_OUT_OF_RANGE_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.ALPHA_OUT_OF_RANGE_FLAG_NAME,Color.red,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.CORRECTION_FLAG_NAME,FlagsManager.CORRECTION_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.CORRECTION_FLAG_NAME,Color.red,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.CLOUD_INPUT_FLAG_NAME,FlagsManager.CLOUD_INPUT_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.CLOUD_INPUT_FLAG_NAME,Color.yellow,0.5F)); prod.addBitmaskDef(new BitmaskDef(BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_OUTPUT_FLAG_NAME,FlagsManager.INVALID_OUTPUT_FLAG_DESCRIPTION,BaerConstants.OUT_FLAGS_BAND_NAME + "." + FlagsManager.INVALID_OUTPUT_FLAG_NAME,Color.red,0.5F)); } Example 24
From project BioMAV, under directory /ParrotSim/Java/src/nl/ru/ai/projects/parrot/dronecontrol/manualcontrol/.
Source file: View.java
23
@Override public void paint(Graphics g){ super.paint(g); g.setColor(Color.RED); g.drawString("Click here to controle the drone!",50,50); g.setColor(Color.BLACK); int y=100; g.drawString("Up = flyForward(1.0)",50,y); g.drawString("Down = flyForward(-1.0)",50,y + 30); g.drawString("Right = spin(1.0)",50,y + 60); g.drawString("Left = spin(-1.0)",50,y + 90); g.drawString("AButton() = flySideways(-1.0)",50,y + 120); g.drawString("DButton() = flySideways(1.0)",50,y + 150); g.drawString("XButton() = land()",50,y + 180); g.drawString("ZButton() = takeoff()",50,y + 210); } Example 25
From project Bit4Tat, under directory /Bit4Tat/src/com/Bit4Tat/.
Source file: Bit4Tat.java
23
public void actionPerformed(ActionEvent event){ currentButton.setContentAreaFilled(false); JButton clickedButton=(JButton)event.getSource(); clickedButton.setBackground(Color.LIGHT_GRAY); clickedButton.setContentAreaFilled(true); currentButton=clickedButton; contentPane=getContentPane(); contentPane.remove(currentPanel); currentPanel=panelList.get(event.getActionCommand()); contentPane.add(currentPanel); contentPane.validate(); repaint(); } Example 26
From project blogs, under directory /request-mappers/src/main/java/com/wicketinaction/requestmappers/resources/images/.
Source file: ImageResourceReference.java
23
/** * Generates an image with a label. For real life application this method will read the image bytes from external source. * @param label the image text to render * @return */ private byte[] getImageAsBytes(String label){ BufferedImage image=new BufferedImage(800,600,BufferedImage.TYPE_INT_RGB); Graphics2D g=(Graphics2D)image.getGraphics(); g.setColor(Color.BLACK); g.setBackground(Color.WHITE); g.clearRect(0,0,image.getWidth(),image.getHeight()); g.setFont(new Font("SansSerif",Font.PLAIN,48)); g.drawString(label,50,50); g.dispose(); Iterator<ImageWriter> writers=ImageIO.getImageWritersByFormatName("jpg"); ImageWriter writer=writers.next(); if (writer == null) { throw new RuntimeException("JPG not supported?!"); } final ByteArrayOutputStream out=new ByteArrayOutputStream(); byte[] imageBytes=null; try { ImageOutputStream imageOut=ImageIO.createImageOutputStream(out); writer.setOutput(imageOut); writer.write(image); imageOut.close(); imageBytes=out.toByteArray(); } catch ( IOException e) { e.printStackTrace(); } return imageBytes; } Example 27
From project Briss, under directory /src/main/java/at/laborg/briss/gui/.
Source file: MergedPanel.java
23
private void drawNormalCropRectangle(Graphics2D g2,int cropCnt,DrawableCropRect crop){ g2.setComposite(SMOOTH_NORMAL); g2.setColor(Color.BLUE); g2.fill(crop); g2.setColor(Color.BLACK); g2.setFont(scaleFont(String.valueOf(cropCnt + 1),crop)); g2.drawString(String.valueOf(cropCnt + 1),crop.x,crop.y + crop.height); int cD=DrawableCropRect.CORNER_DIMENSION; g2.fillRect(crop.x,crop.y,cD,cD); g2.fillRect(crop.x + crop.width - cD - 1,crop.y + crop.height - cD - 1,cD,cD); } Source: http://www.javased.com/index.php?api=java.awt.Color
0 Response to "Javaawtcolor Example Code"
Post a Comment