/** * Convenience method for accessing colour preferences. * * @param colName name of the colour * @param specName name of the special colour settings * @param def default value * @return a Color object for the configured colour, or the default value if none configured. */ public synchronized Color getColor(String colName, String specName, Color def) { putDefault("color." + colName, ColorHelper.color2html(def)); String colStr = specName != null ? get("color." + specName) : ""; if (colStr.equals("")) { colStr = get("color." + colName); } return colStr.equals("") ? def : ColorHelper.html2color(colStr); }
Color convertColor(String colString) { int i = colString.indexOf("#"); Color ret; if (i < 0) { ret = Main.pref.getColor("mappaint." + style.getPrefName() + "." + colString, Color.red); } else if (i == 0) { ret = ColorHelper.html2color(colString); } else { ret = Main.pref.getColor( "mappaint." + style.getPrefName() + "." + colString.substring(0, i), ColorHelper.html2color(colString.substring(i))); } return ret; }
/** Replace the background color by the josm color.background color. */ private void replaceBackground() { int w = bufferedImage.getWidth(); int h = bufferedImage.getHeight(); int josmBackgroundColor = ColorHelper.html2color(Main.pref.get("color.background", "#000000")).getRGB(); for (int x = 0; x < w; x++) { for (int y = 0; y < h; y++) { int pixel = bufferedImage.getRGB(x, y); if (pixel == cadastreBackground) { bufferedImage.setRGB(x, y, josmBackgroundColor); } } } // The cadastre has now a new background (for invertGrey()) cadastreBackground = josmBackgroundColor; }
@Override public void paint(Graphics2D g, MapView mv, Bounds box) { final int iconHeight = ImageProvider.ImageSizes.SMALLICON.getAdjustedHeight(); final int iconWidth = ImageProvider.ImageSizes.SMALLICON.getAdjustedWidth(); for (Note note : noteData.getNotes()) { Point p = mv.getPoint(note.getLatLon()); ImageIcon icon; if (note.getId() < 0) { icon = ImageProvider.get("dialogs/notes", "note_new", ImageProvider.ImageSizes.SMALLICON); } else if (note.getState() == State.CLOSED) { icon = ImageProvider.get("dialogs/notes", "note_closed", ImageProvider.ImageSizes.SMALLICON); } else { icon = ImageProvider.get("dialogs/notes", "note_open", ImageProvider.ImageSizes.SMALLICON); } int width = icon.getIconWidth(); int height = icon.getIconHeight(); g.drawImage(icon.getImage(), p.x - (width / 2), p.y - height, Main.map.mapView); } if (noteData.getSelectedNote() != null) { StringBuilder sb = new StringBuilder("<html>"); sb.append(tr("Note")).append(' ').append(noteData.getSelectedNote().getId()); for (NoteComment comment : noteData.getSelectedNote().getComments()) { String commentText = comment.getText(); // closing a note creates an empty comment that we don't want to show if (commentText != null && !commentText.trim().isEmpty()) { sb.append("<hr/>"); String userName = XmlWriter.encode(comment.getUser().getName()); if (userName == null || userName.trim().isEmpty()) { userName = "******"; } sb.append(userName); sb.append(" on "); sb.append( DateUtils.getDateFormat(DateFormat.MEDIUM).format(comment.getCommentTimestamp())); sb.append(":<br/>"); String htmlText = XmlWriter.encode(comment.getText(), true); htmlText = htmlText.replace( "
", "<br/>"); // encode method leaves us with entity instead of \n htmlText = htmlText.replace("/", "/\u200b"); // zero width space to wrap long URLs (see #10864) sb.append(htmlText); } } sb.append("</html>"); JToolTip toolTip = new JToolTip(); toolTip.setTipText(sb.toString()); Point p = mv.getPoint(noteData.getSelectedNote().getLatLon()); g.setColor(ColorHelper.html2color(Main.pref.get("color.selected"))); g.drawRect(p.x - (iconWidth / 2), p.y - iconHeight, iconWidth - 1, iconHeight - 1); int tx = p.x + (iconWidth / 2) + 5; int ty = p.y - iconHeight - 1; g.translate(tx, ty); // Carried over from the OSB plugin. Not entirely sure why it is needed // but without it, the tooltip doesn't get sized correctly for (int x = 0; x < 2; x++) { Dimension d = toolTip.getUI().getPreferredSize(toolTip); d.width = Math.min(d.width, mv.getWidth() / 2); if (d.width > 0 && d.height > 0) { toolTip.setSize(d); try { toolTip.paint(g); } catch (IllegalArgumentException e) { // See #11123 - https://bugs.openjdk.java.net/browse/JDK-6719550 // Ignore the exception, as Netbeans does: // http://hg.netbeans.org/main-silver/rev/c96f4d5fbd20 Main.error(e, false); } } } g.translate(-tx, -ty); } }
public synchronized boolean putColor(String colName, Color val) { return put("color." + colName, val != null ? ColorHelper.color2html(val) : null); }
public synchronized Color getDefaultColor(String colName) { String colStr = defaults.get("color." + colName); return colStr == null || "".equals(colStr) ? null : ColorHelper.html2color(colStr); }