List of usage examples for java.awt Color RGBtoHSB
public static float[] RGBtoHSB(int r, int g, int b, float[] hsbvals)
From source file:gate.gui.docview.AnnotationStack.java
/** * Draw the annotation stack in a JPanel with a GridBagLayout. *///ww w. j a va 2 s. co m public void drawStack() { // clear the panel removeAll(); boolean textTooLong = text.length() > maxTextLength; int upperBound = text.length() - (maxTextLength / 2); GridBagConstraints gbc = new GridBagConstraints(); gbc.gridx = 0; gbc.gridy = 0; gbc.fill = GridBagConstraints.BOTH; /********************** * First row of text * *********************/ gbc.gridwidth = 1; gbc.insets = new java.awt.Insets(10, 10, 10, 10); JLabel labelTitle = new JLabel("Context"); labelTitle.setOpaque(true); labelTitle.setBackground(Color.WHITE); labelTitle.setBorder(new CompoundBorder( new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); labelTitle.setToolTipText("Expression and its context."); add(labelTitle, gbc); gbc.insets = new java.awt.Insets(10, 0, 10, 0); int expressionStart = contextBeforeSize; int expressionEnd = text.length() - contextAfterSize; // for each character for (int charNum = 0; charNum < text.length(); charNum++) { gbc.gridx = charNum + 1; if (textTooLong) { if (charNum == maxTextLength / 2) { // add ellipsis dots in case of a too long text displayed add(new JLabel("..."), gbc); // skip the middle part of the text if too long charNum = upperBound + 1; continue; } else if (charNum > upperBound) { gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } } // set the text and color of the feature value JLabel label = new JLabel(text.substring(charNum, charNum + 1)); if (charNum >= expressionStart && charNum < expressionEnd) { // this part is matched by the pattern, color it label.setBackground(new Color(240, 201, 184)); } else { // this part is the context, no color label.setBackground(Color.WHITE); } label.setOpaque(true); // get the word from which belongs the current character charNum int start = text.lastIndexOf(" ", charNum); int end = text.indexOf(" ", charNum); String word = text.substring((start == -1) ? 0 : start, (end == -1) ? text.length() : end); // add a mouse listener that modify the query label.addMouseListener(textMouseListener.createListener(word)); add(label, gbc); } /************************************ * Subsequent rows with annotations * ************************************/ // for each row to display for (StackRow stackRow : stackRows) { String type = stackRow.getType(); String feature = stackRow.getFeature(); if (feature == null) { feature = ""; } String shortcut = stackRow.getShortcut(); if (shortcut == null) { shortcut = ""; } gbc.gridy++; gbc.gridx = 0; gbc.gridwidth = 1; gbc.insets = new Insets(0, 0, 3, 0); // add the header of the row JLabel annotationTypeAndFeature = new JLabel(); String typeAndFeature = type + (feature.equals("") ? "" : ".") + feature; annotationTypeAndFeature.setText(!shortcut.equals("") ? shortcut : stackRow.getSet() != null ? stackRow.getSet() + "#" + typeAndFeature : typeAndFeature); annotationTypeAndFeature.setOpaque(true); annotationTypeAndFeature.setBackground(Color.WHITE); annotationTypeAndFeature .setBorder(new CompoundBorder(new EtchedBorder(EtchedBorder.LOWERED, new Color(250, 250, 250), new Color(250, 250, 250).darker()), new EmptyBorder(new Insets(0, 2, 0, 2)))); if (feature.equals("")) { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type)); } else { annotationTypeAndFeature.addMouseListener(headerMouseListener.createListener(type, feature)); } gbc.insets = new java.awt.Insets(0, 10, 3, 10); add(annotationTypeAndFeature, gbc); gbc.insets = new java.awt.Insets(0, 0, 3, 0); // add all annotations for this row HashMap<Integer, TreeSet<Integer>> gridSet = new HashMap<Integer, TreeSet<Integer>>(); int gridyMax = gbc.gridy; for (StackAnnotation ann : stackRow.getAnnotations()) { gbc.gridx = ann.getStartNode().getOffset().intValue() - expressionStartOffset + contextBeforeSize + 1; gbc.gridwidth = ann.getEndNode().getOffset().intValue() - ann.getStartNode().getOffset().intValue(); if (gbc.gridx == 0) { // column 0 is already the row header gbc.gridwidth -= 1; gbc.gridx = 1; } else if (gbc.gridx < 0) { // annotation starts before displayed text gbc.gridwidth += gbc.gridx - 1; gbc.gridx = 1; } if (gbc.gridx + gbc.gridwidth > text.length()) { // annotation ends after displayed text gbc.gridwidth = text.length() - gbc.gridx + 1; } if (textTooLong) { if (gbc.gridx > (upperBound + 1)) { // x starts after the hidden middle part gbc.gridx -= upperBound - (maxTextLength / 2) + 1; } else if (gbc.gridx > (maxTextLength / 2)) { // x starts in the hidden middle part if (gbc.gridx + gbc.gridwidth <= (upperBound + 3)) { // x ends in the hidden middle part continue; // skip the middle part of the text } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - gbc.gridx + 2; gbc.gridx = (maxTextLength / 2) + 2; } } else { // x starts before the hidden middle part if (gbc.gridx + gbc.gridwidth < (maxTextLength / 2)) { // x ends before the hidden middle part // do nothing } else if (gbc.gridx + gbc.gridwidth < upperBound) { // x ends in the hidden middle part gbc.gridwidth = (maxTextLength / 2) - gbc.gridx + 1; } else { // x ends after the hidden middle part gbc.gridwidth -= upperBound - (maxTextLength / 2) + 1; } } } if (gbc.gridwidth == 0) { gbc.gridwidth = 1; } JLabel label = new JLabel(); Object object = ann.getFeatures().get(feature); String value = (object == null) ? " " : Strings.toString(object); if (value.length() > maxFeatureValueLength) { // show the full text in the tooltip label.setToolTipText((value.length() > 500) ? "<html><textarea rows=\"30\" cols=\"40\" readonly=\"readonly\">" + value.replaceAll("(.{50,60})\\b", "$1\n") + "</textarea></html>" : ((value.length() > 100) ? "<html><table width=\"500\" border=\"0\" cellspacing=\"0\">" + "<tr><td>" + value.replaceAll("\n", "<br>") + "</td></tr></table></html>" : value)); if (stackRow.getCrop() == CROP_START) { value = "..." + value.substring(value.length() - maxFeatureValueLength - 1); } else if (stackRow.getCrop() == CROP_END) { value = value.substring(0, maxFeatureValueLength - 2) + "..."; } else {// cut in the middle value = value.substring(0, maxFeatureValueLength / 2) + "..." + value.substring(value.length() - (maxFeatureValueLength / 2)); } } label.setText(value); label.setBackground(AnnotationSetsView.getColor(stackRow.getSet(), ann.getType())); label.setBorder(BorderFactory.createLineBorder(Color.BLACK, 1)); label.setOpaque(true); label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, String.valueOf(ann.getId()))); // show the feature values in the tooltip if (!ann.getFeatures().isEmpty()) { String width = (Strings.toString(ann.getFeatures()).length() > 100) ? "500" : "100%"; String toolTip = "<html><table width=\"" + width + "\" border=\"0\" cellspacing=\"0\" cellpadding=\"4\">"; Color color = (Color) UIManager.get("ToolTip.background"); float[] hsb = Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), null); color = Color.getHSBColor(hsb[0], hsb[1], Math.max(0f, hsb[2] - hsb[2] * 0.075f)); // darken the color String hexColor = Integer.toHexString(color.getRed()) + Integer.toHexString(color.getGreen()) + Integer.toHexString(color.getBlue()); boolean odd = false; // alternate background color every other row List<Object> features = new ArrayList<Object>(ann.getFeatures().keySet()); //sort the features into alphabetical order Collections.sort(features, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return o1.toString().compareToIgnoreCase(o2.toString()); } }); for (Object key : features) { String fv = Strings.toString(ann.getFeatures().get(key)); toolTip += "<tr align=\"left\"" + (odd ? " bgcolor=\"#" + hexColor + "\"" : "") + "><td><strong>" + key + "</strong></td><td>" + ((fv.length() > 500) ? "<textarea rows=\"20\" cols=\"40\" cellspacing=\"0\">" + StringEscapeUtils .escapeHtml(fv.replaceAll("(.{50,60})\\b", "$1\n")) + "</textarea>" : StringEscapeUtils.escapeHtml(fv).replaceAll("\n", "<br>")) + "</td></tr>"; odd = !odd; } label.setToolTipText(toolTip + "</table></html>"); } else { label.setToolTipText("No features."); } if (!feature.equals("")) { label.addMouseListener(annotationMouseListener.createListener(stackRow.getSet(), type, feature, Strings.toString(ann.getFeatures().get(feature)), String.valueOf(ann.getId()))); } // find the first empty row span for this annotation int oldGridy = gbc.gridy; for (int y = oldGridy; y <= (gridyMax + 1); y++) { // for each cell of this row where spans the annotation boolean xSpanIsEmpty = true; for (int x = gbc.gridx; (x < (gbc.gridx + gbc.gridwidth)) && xSpanIsEmpty; x++) { xSpanIsEmpty = !(gridSet.containsKey(x) && gridSet.get(x).contains(y)); } if (xSpanIsEmpty) { gbc.gridy = y; break; } } // save the column x and row y of the current value TreeSet<Integer> ts; for (int x = gbc.gridx; x < (gbc.gridx + gbc.gridwidth); x++) { ts = gridSet.get(x); if (ts == null) { ts = new TreeSet<Integer>(); } ts.add(gbc.gridy); gridSet.put(x, ts); } add(label, gbc); gridyMax = Math.max(gridyMax, gbc.gridy); gbc.gridy = oldGridy; } // add a button at the end of the row gbc.gridwidth = 1; if (stackRow.getLastColumnButton() != null) { // last cell of the row gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.insets = new Insets(0, 10, 3, 0); gbc.fill = GridBagConstraints.NONE; gbc.anchor = GridBagConstraints.WEST; add(stackRow.getLastColumnButton(), gbc); gbc.insets = new Insets(0, 0, 3, 0); gbc.fill = GridBagConstraints.BOTH; gbc.anchor = GridBagConstraints.CENTER; } // set the new gridy to the maximum row we put a value gbc.gridy = gridyMax; } if (lastRowButton != null) { // add a configuration button on the last row gbc.insets = new java.awt.Insets(0, 10, 0, 10); gbc.gridx = 0; gbc.gridy++; add(lastRowButton, gbc); } // add an empty cell that takes all remaining space to // align the visible cells at the top-left corner gbc.gridy++; gbc.gridx = Math.min(text.length(), maxTextLength) + 1; gbc.gridwidth = GridBagConstraints.REMAINDER; gbc.gridheight = GridBagConstraints.REMAINDER; gbc.weightx = 1; gbc.weighty = 1; add(new JLabel(""), gbc); validate(); updateUI(); }
From source file:ala.soils2sat.DrawingUtils.java
public static List<Color> generatePalette(int size, Color baseColor) { float[] hsb = { 0, 0, 0 }; Color.RGBtoHSB(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), hsb); double baseHue = hsb[0]; List<Color> colors = new ArrayList<Color>(); colors.add(baseColor);/*from www . ja v a2 s. c o m*/ double step = (240.0 / (double) size); for (int i = 1; i < size; ++i) { float hue = (float) ((baseHue + step * ((double) i)) % 240.0); // this gives a number out of 240. need to scale that to percent hue = hue / 240; Color nextColor = Color.getHSBColor(hue, hsb[1], hsb[2]); colors.add(nextColor); } return colors; }
From source file:GeMSE.GS.Analysis.Stats.OneSamplePCAPanel.java
private void Plot() { double[][] data = _principalComponents.getData(); if (data[0].length < 2) { JOptionPane.showMessageDialog(this, "An error occured when computing principal components. " + "\nRequire at least two principal components, but calculated " + String.valueOf(data[0].length) + "\n", "Not enough data", JOptionPane.ERROR_MESSAGE); return;/*from ww w. j a v a 2 s. c o m*/ } float[] yAxisColor = new float[3]; Color.RGBtoHSB(255, 255, 255, yAxisColor); float[] hsbValues = new float[3]; Color.RGBtoHSB(16, 23, 67, hsbValues); float[] pcColor = new float[3]; Color.RGBtoHSB(255, 255, 0, pcColor); XYSeriesCollection dataset = new XYSeriesCollection(); XYSeries series = new XYSeries("PC"); for (double[] d : data) series.add(d[0], d[1]); dataset.addSeries(series); JFreeChart chart = ChartFactory.createScatterPlot(null, "Principal component 1", "Principal component 2", (XYDataset) dataset); chart.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2])); chart.removeLegend(); XYPlot plot = (XYPlot) chart.getPlot(); plot.setBackgroundPaint(Color.getHSBColor(hsbValues[0], hsbValues[1], hsbValues[2])); Font axisLabelFont = new Font("Dialog", Font.PLAIN, 14); Font axisTickLabelFont = new Font("Dialog", Font.PLAIN, 12); plot.setDomainGridlinePaint(Color.gray); plot.setRangeGridlinePaint(Color.gray); plot.getDomainAxis().setTickLabelPaint(Color.white); plot.getDomainAxis().setLabelPaint(Color.white); plot.getDomainAxis().setLabelFont(axisLabelFont); plot.getDomainAxis().setTickLabelFont(axisTickLabelFont); plot.getRangeAxis().setTickLabelPaint(Color.getHSBColor(yAxisColor[0], yAxisColor[1], yAxisColor[2])); plot.getRangeAxis().setLabelPaint(Color.getHSBColor(yAxisColor[0], yAxisColor[1], yAxisColor[2])); plot.getRangeAxis().setLabelFont(axisLabelFont); plot.getRangeAxis().setTickLabelFont(axisTickLabelFont); Shape shape = ShapeUtilities.createDiagonalCross(4, 0.5f); XYItemRenderer renderer = chart.getXYPlot().getRenderer(); renderer.setSeriesShape(0, shape); renderer.setSeriesPaint(0, Color.getHSBColor(pcColor[0], pcColor[1], pcColor[2])); ChartPanel panel = new ChartPanel(chart); Dimension plotDim = plotPanel.getSize(); plotDim.height -= (plotDim.height * 10) / 100; plotDim.width -= (plotDim.width * 10) / 100; panel.setPreferredSize(plotDim); plotPanel.setViewportView(panel); revalidate(); repaint(); }
From source file:de._13ducks.cor.graphics.GraphicsComponent.java
protected void calcColoredMaps(Color[] colors) { // Berechnet die eingefrbten Texturen, z.B. fr Gebude ArrayList<CoRImage> tList = new ArrayList<CoRImage>(); tList.addAll(coloredImgMap.values()); coloredImgMap.clear();/*from w ww . j a v a 2 s . c o m*/ for (int i = 0; i < tList.size(); i++) { BufferedImage im = (BufferedImage) tList.get(i).getImage(); for (int playerId = 0; playerId < colors.length; playerId++) { BufferedImage preImg = new BufferedImage(im.getWidth(), im.getHeight(), BufferedImage.TYPE_INT_ARGB); for (int x = 0; x < im.getWidth(); x++) { for (int y = 0; y < im.getHeight(); y++) { // Das ganze Raster durchgehen und Farben ersetzen // Ersetzfarbe da? int rgb = im.getRGB(x, y); float[] col = Color.RGBtoHSB((rgb >> 16) & 0xff, (rgb >> 8) & 0xff, rgb & 0xff, null); if (col[0] >= 0.8583333f && col[0] <= 0.8666666f) { // Ja, ersetzen Color tc = colors[playerId]; int targetC = Color.HSBtoRGB( Color.RGBtoHSB(tc.getRed(), tc.getGreen(), tc.getBlue(), null)[0], 1.0f, col[2]); int a = (rgb >> 24) & 0xff; targetC = (targetC & (~(0xff << 24)) | (a << 24)); preImg.setRGB(x, y, targetC); } else { preImg.setRGB(x, y, im.getRGB(x, y)); } } } // Bild berechnet, einfgen CoRImage newImg = new CoRImage(preImg); newImg.setImageName(tList.get(i).getImageName()); coloredImgMap.put(newImg.getImageName() + playerId, newImg); } } }
From source file:com.threerings.getdown.data.Application.java
/** * Instructs the application to parse its {@code getdown.txt} configuration and prepare itself * for operation. The application base URL will be parsed first so that if there are errors * discovered later, the caller can use the application base to download a new {@code * getdown.txt} file and try again./*ww w. j a v a2s . c o m*/ * * @return a configured UpdateInterface instance that will be used to configure the update UI. * * @exception IOException thrown if there is an error reading the file or an error encountered * during its parsing. */ public UpdateInterface init(boolean checkPlatform) throws IOException { Map<String, Object> cdata = null; File config = _config; try { // if we have a configuration file, read the data from it if (config.exists()) { cdata = ConfigUtil.parseConfig(_config, checkPlatform); } // otherwise, try reading data from our backup config file; thanks to funny windows // bullshit, we have to do this backup file fiddling in case we got screwed while // updating getdown.txt during normal operation else if ((config = getLocalPath(CONFIG_FILE + "_old")).exists()) { cdata = ConfigUtil.parseConfig(config, checkPlatform); } // otherwise, issue a warning that we found no getdown file else { log.info("Found no getdown.txt file", "appdir", _appdir); } } catch (Exception e) { log.warning("Failure reading config file", "file", config, e); } // if we failed to read our config file, check for an appbase specified via a system // property; we can use that to bootstrap ourselves back into operation if (cdata == null) { String appbase = SysProps.appBase(); log.info("Attempting to obtain 'appbase' from system property", "appbase", appbase); cdata = new HashMap<String, Object>(); cdata.put("appbase", appbase); } // first determine our application base, this way if anything goes wrong later in the // process, our caller can use the appbase to download a new configuration file _appbase = (String) cdata.get("appbase"); if (_appbase == null) { throw new RuntimeException("m.missing_appbase"); } // make sure there's a trailing slash if (!_appbase.endsWith("/")) { _appbase = _appbase + "/"; } // check if we're overriding the domain in the appbase _appbase = replaceDomain(_appbase); // extract our version information String vstr = (String) cdata.get("version"); if (vstr != null) _version = parseLong(vstr, "m.invalid_version"); // if we are a versioned deployment, create a versioned appbase try { _vappbase = (_version < 0) ? new URL(_appbase) : createVAppBase(_version); } catch (MalformedURLException mue) { String err = MessageUtil.tcompose("m.invalid_appbase", _appbase); throw (IOException) new IOException(err).initCause(mue); } // check for a latest config URL String latest = (String) cdata.get("latest"); if (latest != null) { latest = replaceDomain(latest); try { _latest = new URL(latest); } catch (MalformedURLException mue) { log.warning("Invalid URL for latest attribute.", mue); } } String appPrefix = StringUtil.isBlank(_appid) ? "" : (_appid + "."); // determine our application class name _class = (String) cdata.get(appPrefix + "class"); if (_class == null) { throw new IOException("m.missing_class"); } // check to see if we're using a custom java.version property and regex vstr = (String) cdata.get("java_version_prop"); if (vstr != null) _javaVersionProp = vstr; vstr = (String) cdata.get("java_version_regex"); if (vstr != null) _javaVersionRegex = vstr; // check to see if we require a particular JVM version and have a supplied JVM vstr = (String) cdata.get("java_version"); if (vstr != null) _javaMinVersion = parseLong(vstr, "m.invalid_java_version"); // we support java_min_version as an alias of java_version; it better expresses the check // that's going on and better mirrors java_max_version vstr = (String) cdata.get("java_min_version"); if (vstr != null) _javaMinVersion = parseLong(vstr, "m.invalid_java_version"); // check to see if we require a particular max JVM version and have a supplied JVM vstr = (String) cdata.get("java_max_version"); if (vstr != null) _javaMaxVersion = parseLong(vstr, "m.invalid_java_version"); // check to see if we require a particular JVM version and have a supplied JVM vstr = (String) cdata.get("java_exact_version_required"); _javaExactVersionRequired = Boolean.parseBoolean(vstr); // this is a little weird, but when we're run from the digester, we see a String[] which // contains java locations for all platforms which we can't grok, but the digester doesn't // need to know about that; when we're run in a real application there will be only one! Object javaloc = cdata.get("java_location"); if (javaloc instanceof String) { _javaLocation = (String) javaloc; } // determine whether we have any tracking configuration _trackingURL = (String) cdata.get("tracking_url"); // check for tracking progress percent configuration String trackPcts = (String) cdata.get("tracking_percents"); if (!StringUtil.isBlank(trackPcts)) { _trackingPcts = new HashSet<Integer>(); for (int pct : StringUtil.parseIntArray(trackPcts)) { _trackingPcts.add(pct); } } else if (!StringUtil.isBlank(_trackingURL)) { _trackingPcts = new HashSet<Integer>(); _trackingPcts.add(50); } // Check for tracking cookie configuration _trackingCookieName = (String) cdata.get("tracking_cookie_name"); _trackingCookieProperty = (String) cdata.get("tracking_cookie_property"); // Some app may need an extra suffix added to the tracking URL _trackingURLSuffix = (String) cdata.get("tracking_url_suffix"); // Some app may need to generate google analytics code _trackingGAHash = (String) cdata.get("tracking_ga_hash"); // clear our arrays as we may be reinitializing _codes.clear(); _resources.clear(); _auxgroups.clear(); _jvmargs.clear(); _appargs.clear(); _txtJvmArgs.clear(); // parse our code resources if (ConfigUtil.getMultiValue(cdata, "code") == null && ConfigUtil.getMultiValue(cdata, "ucode") == null) { throw new IOException("m.missing_code"); } parseResources(cdata, "code", false, _codes); parseResources(cdata, "ucode", true, _codes); // parse our non-code resources parseResources(cdata, "resource", false, _resources); parseResources(cdata, "uresource", true, _resources); // parse our auxiliary resource groups for (String auxgroup : parseList(cdata, "auxgroups")) { ArrayList<Resource> codes = new ArrayList<Resource>(); parseResources(cdata, auxgroup + ".code", false, codes); parseResources(cdata, auxgroup + ".ucode", true, codes); ArrayList<Resource> rsrcs = new ArrayList<Resource>(); parseResources(cdata, auxgroup + ".resource", false, rsrcs); parseResources(cdata, auxgroup + ".uresource", true, rsrcs); _auxgroups.put(auxgroup, new AuxGroup(auxgroup, codes, rsrcs)); } // transfer our JVM arguments (we include both "global" args and app_id-prefixed args) String[] jvmargs = ConfigUtil.getMultiValue(cdata, "jvmarg"); addAll(jvmargs, _jvmargs); if (appPrefix.length() > 0) { jvmargs = ConfigUtil.getMultiValue(cdata, appPrefix + "jvmarg"); addAll(jvmargs, _jvmargs); } // Add the launch specific JVM arguments addAll(_extraJvmArgs, _jvmargs); // get the set of optimum JVM arguments _optimumJvmArgs = ConfigUtil.getMultiValue(cdata, "optimum_jvmarg"); // transfer our application arguments String[] appargs = ConfigUtil.getMultiValue(cdata, appPrefix + "apparg"); addAll(appargs, _appargs); // add the launch specific application arguments addAll(_extraAppArgs, _appargs); // look for custom arguments fillAssignmentListFromPairs("extra.txt", _txtJvmArgs); // determine whether we want to allow offline operation (defaults to false) _allowOffline = Boolean.parseBoolean((String) cdata.get("allow_offline")); // look for a debug.txt file which causes us to run in java.exe on Windows so that we can // obtain a thread dump of the running JVM _windebug = getLocalPath("debug.txt").exists(); // whether to cache code resources and launch from cache _useCodeCache = Boolean.parseBoolean((String) cdata.get("use_code_cache")); _codeCacheRetentionDays = cdata.containsKey("code_cache_retention_days") ? Integer.parseInt((String) cdata.get("use_code_cache")) : 7; // parse and return our application config UpdateInterface ui = new UpdateInterface(); _name = ui.name = (String) cdata.get("ui.name"); ui.progress = parseRect(cdata, "ui.progress", ui.progress); ui.progressText = parseColor(cdata, "ui.progress_text", ui.progressText); ui.hideProgressText = Boolean.parseBoolean((String) cdata.get("ui.hide_progress_text")); ui.progressBar = parseColor(cdata, "ui.progress_bar", ui.progressBar); ui.status = parseRect(cdata, "ui.status", ui.status); ui.statusText = parseColor(cdata, "ui.status_text", ui.statusText); ui.textShadow = parseColor(cdata, "ui.text_shadow", ui.textShadow); ui.hideDecorations = Boolean.parseBoolean((String) cdata.get("ui.hide_decorations")); ui.backgroundImage = (String) cdata.get("ui.background_image"); if (ui.backgroundImage == null) { // support legacy format ui.backgroundImage = (String) cdata.get("ui.background"); } // and now ui.background can refer to the background color, but fall back to black // or white, depending on the brightness of the progressText Color defaultBackground = (.5f < Color.RGBtoHSB(ui.progressText.getRed(), ui.progressText.getGreen(), ui.progressText.getBlue(), null)[2]) ? Color.BLACK : Color.WHITE; ui.background = parseColor(cdata, "ui.background", defaultBackground); ui.progressImage = (String) cdata.get("ui.progress_image"); ui.rotatingBackgrounds = ConfigUtil.getMultiValue(cdata, "ui.rotating_background"); ui.iconImages = ConfigUtil.getMultiValue(cdata, "ui.icon"); ui.errorBackground = (String) cdata.get("ui.error_background"); _dockIconPath = (String) cdata.get("ui.mac_dock_icon"); if (_dockIconPath == null) { _dockIconPath = "../desktop.icns"; // use a sensible default } // On an installation error, where do we point the user. String installError = parseUrl(cdata, "ui.install_error", null); ui.installError = (installError == null) ? "m.default_install_error" : MessageUtil.taint(installError); // the patch notes bits ui.patchNotes = parseRect(cdata, "ui.patch_notes", ui.patchNotes); ui.patchNotesUrl = parseUrl(cdata, "ui.patch_notes_url", null); // the play again bits ui.playAgain = parseRect(cdata, "ui.play_again", ui.playAgain); ui.playAgainImage = (String) cdata.get("ui.play_again_image"); // step progress percentages for (UpdateInterface.Step step : UpdateInterface.Step.values()) { String spec = (String) cdata.get("ui.percents." + step.name()); if (spec != null) { try { ui.stepPercentages.put(step, intsToList(StringUtil.parseIntArray(spec))); } catch (Exception e) { log.warning("Failed to parse percentages for " + step + ": " + spec); } } } return ui; }
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;/* ww w . j a va 2s . co 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.jtrfp.trcl.file.LTEFile.java
/** * Reverse-compatible form of the emissive components in ESTuTv form where:<br> * R = E<br>// w ww . j a v a 2s. c o m * G = S<br> * B = Tu<br> * A = Tv<br> * @return * @since Feb 5, 2015 */ public Color[] toColors(Color[] referencePalette) { Color[] result = new Color[256]; for (int i = 0; i < 256; i++) { final Color rColor = referencePalette[i]; final Color loColor = referencePalette[gradientIndex(i, 0)]; final Color hiColor = referencePalette[gradientIndex(i, 15)]; final double loIntensity = new Vector3D(loColor.getRed(), loColor.getGreen(), loColor.getBlue()) .getNorm(); //Brightest final double hiIntensity = new Vector3D(hiColor.getRed(), hiColor.getGreen(), hiColor.getBlue()) .getNorm(); final float[] hsbVals = new float[3]; Color.RGBtoHSB(rColor.getRed(), rColor.getGreen(), rColor.getBlue(), hsbVals); final double saturation = hsbVals[1]; double dI = Math.pow(1 - (Math.abs(hiIntensity - loIntensity) / 442.), 1); //dI = nSaturation*128; if (dI > 255) dI = 255; else if (dI < 0) dI = 0; result[i] = new Color((int) (dI * saturation * 255.), 0, 0, 0); } return result; }
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 . ja v a 2 s. com * @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.pentaho.reporting.engine.classic.core.modules.output.table.xls.helper.StaticExcelColorSupport.java
public static short getNearestColor(final Color awtColor, final Map triplets) { if (awtColor == null) { throw new NullPointerException(); }//from w w w .ja v a 2s.c o m if (triplets == null || triplets.isEmpty()) { logger.warn("Unable to get triplet hashtable"); return HSSFColor.BLACK.index; } short color = HSSFColor.BLACK.index; double minDiff = Double.MAX_VALUE; // get the color without the alpha chanel final float[] hsb = Color.RGBtoHSB(awtColor.getRed(), awtColor.getGreen(), awtColor.getBlue(), null); float[] excelHsb = null; final Iterator elements = triplets.values().iterator(); while (elements.hasNext()) { final HSSFColor crtColor = (HSSFColor) elements.next(); final short[] rgb = crtColor.getTriplet(); excelHsb = Color.RGBtoHSB(rgb[0], rgb[1], rgb[2], excelHsb); final double weight = 3.0 * (Math.min(Math.abs(excelHsb[0] - hsb[0]), Math.abs(excelHsb[0] - hsb[0] + 1))) + Math.abs(excelHsb[1] - hsb[1]) + Math.abs(excelHsb[2] - hsb[2]); if (weight < minDiff) { minDiff = weight; if (minDiff == 0) { // we found the color ... return crtColor.getIndex(); } color = crtColor.getIndex(); } } return color; }
From source file:org.polymap.rhei.batik.engine.svg.Svg2Png.java
private static float[] getHsb(ImageConfiguration imageConfiguration, Color color) { float[] hsb = new float[3]; if (imageConfiguration.isInvert()) { Color.RGBtoHSB(255 - color.getRed(), 255 - color.getGreen(), 255 - color.getBlue(), hsb); } else {//from www . jav a2 s .co m Color.RGBtoHSB(color.getRed(), color.getGreen(), color.getBlue(), hsb); } return hsb; }