List of usage examples for java.awt Color getHSBColor
public static Color getHSBColor(float h, float s, float b)
From source file:nz.ac.massey.cs.gql4jung.browser.resultviews.GraphBasedResultView.java
private Map<String, Color> createColorMap(MotifInstance instance) { if (instance == null) return new HashMap<String, Color>(0); Set<Vertex> vertices = instance.getVertices(); Set<String> packages = new HashSet<String>(vertices.size()); for (Vertex v : vertices) { packages.add(v.getNamespace());/* w w w .j ava 2 s.co m*/ } int count = 0; Map<String, Color> pmap = new HashMap<String, Color>(packages.size()); float offset = 100 / packages.size(); offset = offset / 100; for (String p : packages) { Color hsb = Color.getHSBColor(count * offset, settings.getVertexSaturation(), settings.getVertexBrightness()); pmap.put(p, new Color(hsb.getRed(), hsb.getGreen(), hsb.getBlue(), settings.getVertexTransparency())); // transparency //pmap.put(p,hsb); count = count + 1; } return pmap; }
From source file:org.bigwiv.blastgraph.gui.BlastGraphFrame.java
private void refreshColorControl() { // find the minimal taxon length and attribute key collection Collection<HitVertex> hvs = Global.graph.getVertices(); int minTaxon = 0; Collection<String> minKeySet = new HashSet<String>(); for (HitVertex hitVertex : hvs) { int value = hitVertex.getTaxon().getLevels(); Set<String> keySet = hitVertex.getAllAttributes().keySet(); if (minTaxon == 0) { minTaxon = value;// w ww. ja v a 2 s .com minKeySet = keySet; } else { minTaxon = value < minTaxon ? value : minTaxon; minKeySet = CollectionUtils.intersection(minKeySet, keySet); } } // clear taxons and attrs // final int seleceted = colorComboBox.getSelectedIndex(); for (int i = colorComboBox.getItemCount() - 1; i >= 5; i--) { colorComboBox.removeItemAt(i); } // add taxons for (int i = 0; i < minTaxon; i++) { colorComboBox.addItem("taxon" + i); } // add attrs for (String string : minKeySet) { colorComboBox.addItem(string); } colorComboBox.setSelectedIndex(0); final int min = minTaxon; if (colorItemListener != null) { colorComboBox.removeItemListener(colorItemListener); } colorItemListener = new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { int index = colorComboBox.getSelectedIndex(); String attr = (String) colorComboBox.getSelectedItem(); ArrayList<String> attrValues = new ArrayList<String>(); Map<String, Color> colorMap = new HashMap<String, Color>(); Collection<HitVertex> hvs = Global.graph.getVertices(); String value = ""; if (index != 0) { for (HitVertex hitVertex : hvs) { if (index < 5) { switch (index) { case 1: value = hitVertex.getIndex() + ""; break; case 2: value = hitVertex.getStrand() + ""; break; case 3: value = hitVertex.getGenomeAcc(); break; case 4: value = hitVertex.getOrganism(); break; default: break; } } else if (index < (5 + min)) { value = hitVertex.getTaxon().getTaxon(index - 5); } else { value = hitVertex.getAttribute((String) colorComboBox.getItemAt(index)); System.out.println(index + " " + "attr"); } if (!attrValues.contains(value)) { attrValues.add(value); } } } float hue = 0; int size = attrValues.size(); for (int i = 0; i < size; i++) { Color c = Color.getHSBColor(hue, 0.85f, 1.0f); colorMap.put(attrValues.get(i), c); hue += 1.0f / size; } if (index < (5 + min)) { rc.setVertexFillPaintTransformer(new VertexPainter(index, colorMap)); } else { rc.setVertexFillPaintTransformer(new AttrVertexPainter(attr, colorMap)); } vv.repaint(); } }; colorComboBox.addItemListener(colorItemListener); }
From source file:org.eknet.neoswing.view.DefaultVisualizationViewFactory.java
@Override public VisualizationViewer<Vertex, Edge> createViewer(Graph<Vertex, Edge> graph, GraphDb db) { final VisualizationViewer<Vertex, Edge> vv = new VisualizationViewer<Vertex, Edge>( new FRLayout2<Vertex, Edge>(graph)); vv.getModel().getRelaxer().setSleepTime(0); DefaultModalGraphMouse<Vertex, Edge> mouseSupport = new DefaultModalGraphMouse<Vertex, Edge>(); final GraphModel model = new SimpleGraphModel(graph, vv, db); addMousePlugins(mouseSupport, model); vv.setGraphMouse(mouseSupport);/*w ww . j av a2s .co m*/ vv.addKeyListener(mouseSupport.getModeKeyListener()); vv.setToolTipText("<html><center>Type 'p' for Pick mode<p>Type 't' for Transform mode"); VertexLabelAsShapeRenderer<Vertex, Edge> vertexShape = new VertexLabelAsShapeRenderer<Vertex, Edge>( vv.getRenderContext()) { @Override public Shape transform(Vertex v) { Rectangle rect = (Rectangle) super.transform(v); return new RoundRectangle2D.Double(rect.x - 3, rect.y - 3, rect.width + 7, rect.height + 7, 10, 10); } }; vertexShape.setPosition(Renderer.VertexLabel.Position.CNTR); vv.setBackground(Color.WHITE); vv.getRenderContext().setVertexShapeTransformer(vertexShape); vv.getRenderContext().setVertexLabelTransformer(new VertexTransformer(model)); vv.getRenderer().setVertexLabelRenderer(vertexShape); vv.getRenderContext().setVertexFillPaintTransformer(new Transformer<Vertex, Paint>() { private Color nodefill = Color.getHSBColor(207, 19, 97); @Override public Paint transform(Vertex v) { // if (v.getId() == 0) { // return Color.green; // } return nodefill; } }); vv.getRenderContext().setEdgeLabelTransformer(new Transformer<Edge, String>() { private final WeakHashMap<Object, String> cache = new WeakHashMap<Object, String>(); @Override public String transform(final Edge e) { String s = cache.get(e.getId()); if (s == null) { s = "<null>"; GraphDb.Tx tx = model.getDatabase().beginTx(); try { Edge edge = model.getDatabase().lookupEdge(e.getId()); s = edge.getLabel(); tx.success(); cache.put(edge.getId(), s); } catch (Exception e1) { log.error("Error obtaining edge label", e1); } finally { tx.finish(); } } return s; } }); return vv; }
From source file:org.emonocot.portal.view.Functions.java
private static Map<String, String> getColorMap(Set<String> categories) { int numberOfCategories = categories.size(); float increment = 0.5f / (numberOfCategories / 5); Map<String, String> colorMap = new HashMap<String, String>(); int i = 0;/* w w w .j a va 2 s. c o m*/ for (String category : categories) { Color baseColor = baseColors[i % 5]; int offset = i / 5; if (offset > 0) { float hsbVals[] = Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), null); Color highlight = Color.getHSBColor(hsbVals[0], hsbVals[1], offset * increment * (1f + hsbVals[2])); colorMap.put(category, String.format("#%06X", (0xFFFFFF & highlight.getRGB()))); } else { colorMap.put(category, String.format("#%06X", (0xFFFFFF & baseColor.getRGB()))); } i++; } return colorMap; }
From source file:org.esa.s1tbx.ocean.worldwind.layers.Level2ProductLayer.java
public static AnalyticSurface.GridPointAttributes createColorGradientAttributes(final double value, double minValue, double maxValue, double minHue, double maxHue, boolean whiteZero) { final double hueFactor = WWMath.computeInterpolationFactor(value, minValue, maxValue); //double hue = WWMath.mixSmooth(hueFactor, minHue, maxHue); final double hue = WWMath.mix(hueFactor, minHue, maxHue); double sat = 1.0; if (whiteZero) { sat = Math.abs(WWMath.mixSmooth(hueFactor, -1, 1)); }//from w w w. j ava 2s . c o m final Color color = Color.getHSBColor((float) hue, (float) sat, 1f); final double opacity = WWMath.computeInterpolationFactor(value, minValue, minValue + (maxValue - minValue) * 0.1); final Color rgbaColor = new Color(color.getRed(), color.getGreen(), color.getBlue(), (int) (255 * opacity)); return AnalyticSurface.createGridPointAttributes(value, rgbaColor); }
From source file:org.gofleet.module.routing.RoutingMap.java
private void processTSPPlan(TSPPlan[] res, JProgressBar progressBar) { Random random = new Random(); try {// w w w.j a va2 s .co m @SuppressWarnings("unchecked") Collection<Layer> allLayers = Collections.unmodifiableCollection(this.mapView.getAllLayers()); List<Layer> toremove = new LinkedList<Layer>(); for (Layer l : allLayers) { if (l.name.startsWith("Route Plan") || l.name.startsWith("Stops")) toremove.add(l); } for (Layer l : toremove) this.mapView.removeLayer(l); LatLon latlon_origin = null; int id_layer = 0; for (TSPPlan plan : res) { latlon_origin = new LatLon(plan.getOrigin()[1], plan.getOrigin()[0]); log.info(latlon_origin); LineElemStyle ls = new LineElemStyle(); float f = random.nextFloat(); ls.color = Color.getHSBColor(f * random.nextFloat(), 0.9f, 0.9f); ls.width = LogicConstants.getInt("PLAN_WAY_WIDTH", 2); MarkerLayer stops = new MarkerLayer(new GpxData(), "Stops " + id_layer, File.createTempFile("stops", "tmp"), new GpxLayer(new GpxData()), this.mapView); stops.data.add(new StopMarker(latlon_origin, "origin", "tsp_stop", stops, 0, 0, ls.color)); for (String stop : plan.getStops()) { String[] array = stop.split(","); double[] point = new double[2]; point[1] = new Double(array[0]); point[0] = new Double(array[1]); LatLon ll = new LatLon(point[0], point[1]); log.info(ll); stops.data.add(new StopMarker(ll, array[2], "tsp_stop", stops, 0, 0, ls.color)); } this.mapView.addLayer(stops, true); OsmDataLayer layer = new OsmDataLayer(new DataSet(), "Route Plan " + id_layer++, File.createTempFile("planning", "route")); String way2 = plan.getWay(); if (way2 != null) { Way way = new Way(); LatLon info = null; MultiLineString multilinestring = (MultiLineString) wktReader.read(way2); multilinestring.getLength(); int numGeometries = multilinestring.getNumGeometries(); for (int i = 0; i < numGeometries; i++) { for (Coordinate coordenada : multilinestring.getGeometryN(i).getCoordinates()) { LatLon ll = new LatLon(coordenada.y, coordenada.x); way.addNode(new Node(ll)); if (info == null) info = ll; } way.mappaintStyle = ls; layer.data.ways.add(way); way = new Way(); } progressBar.setValue(progressBar.getValue() + 1); StopMarker marker = new StopMarker(info, (new Double(plan.getDistance())).toString().substring(0, 5) + " km in " + (new Double(plan.getTime() / 60)).toString().substring(0, 3) + " hours", "tsp_stop", stops, 0, 0, ls.color); marker.setPaintIcon(false); stops.data.add(marker); } this.mapView.addLayer(layer, true); layer.visible = true; stops.visible = true; } } catch (Throwable e) { log.error("Error painting plan", e); } }
From source file:org.kalypso.ui.wizards.results.ResultSldHelper.java
/** * returns the interpolated color of a color map defined by start and end color. * /*from w w w . j av a 2 s .c o m*/ * @param currentClass * current class * @param numOfClasses * number of all classes in which the colormap is divided. */ public static Color interpolateColor(final Color minColor, final Color maxColor, final int currentClass, final int numOfClasses) { // interpolate color final float[] minhsb = Color.RGBtoHSB(minColor.getRed(), minColor.getGreen(), minColor.getBlue(), null); final float[] maxhsb = Color.RGBtoHSB(maxColor.getRed(), maxColor.getGreen(), maxColor.getBlue(), null); final float minHue = minhsb[0]; final float maxHue = maxhsb[0]; final float minSat = minhsb[1]; final float maxSat = maxhsb[1]; final float minBri = minhsb[2]; final float maxBri = maxhsb[2]; final double Hue = minHue + (currentClass * (maxHue - minHue) / (numOfClasses - 1)); final double Sat = minSat + (currentClass * (maxSat - minSat) / (numOfClasses - 1)); final double Bri = minBri + (currentClass * (maxBri - minBri) / (numOfClasses - 1)); final Color hsbColor = Color.getHSBColor((float) Hue, (float) Sat, (float) Bri); final Color rgbColor = new Color(hsbColor.getRed(), hsbColor.getGreen(), hsbColor.getBlue()); return rgbColor; }
From source file:org.nuxeo.theme.presets.PhotoshopPaletteParser.java
public static Map<String, String> parse(byte[] bytes) { Map<String, String> entries = new LinkedHashMap<String, String>(); ByteArrayInputStream is = new ByteArrayInputStream(bytes); DataInputStream dis = new DataInputStream(is); char[] words = new char[bytes.length]; int size = 0; while (true) { try {//from w w w .j a va 2 s . c o m words[size] = dis.readChar(); size++; } catch (Exception e) { break; } } try { is.close(); dis.close(); } catch (IOException e) { log.error(e, e); } int offset = 1; int version = words[0] & 0xffff; int nc = words[1] & 0xffff; // get version 2 if it exists if (version == 1 && size > nc * 5 + 2) { offset += nc * 5 + 2; version = words[offset - 1] & 0xffff; nc = words[offset] & 0xffff; } if (version == 1) { log.debug("Found ACO v1 color file (Photoshop < 7.0)"); } else if (version == 2) { log.debug("Found ACO v2 color file (Photoshop >= 7.0)"); } else { log.error("Unknown ACO file version: " + version); return entries; } log.debug("Found " + nc + " colors."); int counter = 1; for (int j = 0; j < nc; j++) { String value = null; int colorSpace = words[offset + 1] & 0xff; int w = words[offset + 2] & 0xffff; int x = words[offset + 3] & 0xffff; int y = words[offset + 4] & 0xffff; int z = words[offset + 5] & 0xffff; if (colorSpace == RGB) { value = rgbToHex(w / 256, x / 256, y / 256); } else if (colorSpace == HSB) { float hue = w / 65535F; // [0.0-1.0] float saturation = x / 65535F; // [0.0-1.0] float brightness = y / 65535F; // [0.0-1.0] Color color = Color.getHSBColor(hue, saturation, brightness); value = rgbToHex(color.getRed(), color.getGreen(), color.getBlue()); } else if (colorSpace == CMYK) { float cyan = 1F - w / 65535F; // [0.0-1.0] float magenta = 1F - x / 65535F; // [0.0-1.0] float yellow = 1F - y / 65535F; // [0.0-1.0] float black = 1F - z / 65535F; // [0.0-1.0] // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: CMYK"); } else if (colorSpace == GRAYSCALE) { int gray = (int) (w * 256F / 10000F); // [0-256] value = rgbToHex(gray, gray, gray); } else if (colorSpace == LAB) { float l = w / 100F; float a = x / 100F; float b = y / 100F; // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: CIE Lab"); } else if (colorSpace == WIDE_CMYK) { float cyan = w / 10000F; // [0.0-1.0] float magenta = x / 10000F; // [0.0-1.0] float yellow = y / 10000F; // [0.0-1.0] float black = z / 10000F; // [0.0-1.0] // TODO: do the conversion to RGB. An ICC profile is required. log.warn("Unsupported color space: Wide CMYK"); } else { log.warn("Unknown color space: " + colorSpace); } String name = ""; if (version == 1) { name = String.format("Color %s", counter); } else if (version == 2) { int len = (words[offset + 7] & 0xffff) - 1; name = String.copyValueOf(words, offset + 8, len); offset += len + 3; String n = name; int c = 2; while (entries.containsKey(n)) { n = String.format("%s %s", name, c); c++; } name = n; } if (value != null) { entries.put(name, value); } offset += 5; counter++; } return entries; }
From source file:Presentacion.SimpleGraphView.java
public void printarNewmanFinal(Grafo<Cancion, Float> G, Solucion s) { init(G);/*from w w w. j av a 2s. c o m*/ crearGrafo(G); solu = s; Transformer<Cancion, Paint> vertexPaint = new Transformer<Cancion, Paint>() { Integer n = solu.obtenerComunidades().size(); Color[] cols = new Color[n]; public Paint transform(Cancion can) { for (Integer i = 0; i < n; i++) cols[i] = Color.getHSBColor((float) i / (float) n, 0.85f, 1.0f); Integer color = solu.consultarComunidad(can); Color c = cols[color]; return c; } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); add(vv); revalidate(); }
From source file:Presentacion.SimpleGraphView.java
public void printarLouvainParcial(Grafo<Cancion, Float> G) { init(G);/*w ww .jav a2s. com*/ crearGrafo(G); Transformer<Cancion, Paint> vertexPaint = new Transformer<Cancion, Paint>() { Integer n = soluL.obtenerComunidades().size(); Color[] cols = new Color[n]; public Paint transform(Cancion can) { for (Integer i = 0; i < n; i++) cols[i] = Color.getHSBColor((float) i / (float) n, 0.85f, 1.0f); Integer color = soluL.consultarComunidad(can); Color c = cols[color]; return c; } }; vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint); add(vv); revalidate(); }