/******************************************************************************* * ALMA - Atacama Large Millimeter Array * Copyright (c) UKATC - UK Astronomy Technology Centre, Science and Technology Facilities Council, 2011 * (in the framework of the ALMA collaboration). * All rights reserved. * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA *******************************************************************************/ package alma.obsprep.ot.gui.resources; import java.awt.Color; import java.util.Iterator; import java.util.Map; import java.util.SortedMap; import java.util.TreeMap; import alma.obsprep.util.OrderedMap; import alma.obsprep.util.OrderedSet; /** * A list of colours to use throughout the tool. * * @author dac */ public class Colors implements ColorPalette { // note: US spelling, done reluctantly for consistency // Names of the various colours // ============================ public final static String FOREGROUND = "Foreground"; public final static String CLIPBOARD = "Clipboard"; public final static String ERROR = "Error"; public final static String WARNING = "Warning"; public final static String PHASE1 = "Phase1"; public final static String PHASE2 = "Phase2"; public final static String DDT = "DDT"; public final static String COMMISSION = "Commission"; public final static String REST_FREQUENCY = "Rest Frequency"; public final static String CENTRE_FREQUENCY = "Centre Frequency"; public final static String CATALOG_LINES = "Catalog Lines"; public final static String SIDEBANDS = "Sidebands"; public final static String SIDEBANDS_UNCONFIG = "Sidebands(Unconfigured)"; public final static String ZOOMBOX = "Zoom Box"; public final static String BASEBAND = "Baseband"; public final static String SPECTRAL_WINDOW = "Spectral Window"; public final static String AVERAGING_REGION = "Averaging Region"; public final static String SUPPRESSED = "Suppressed Windows"; public final static String TRANSMISSION = "Transmission Spectrum"; // Colors for the FOV indicators on the spatial visualiser public final static String FOV = "FOV"; public final static String FOVMAINFLUX = "FOV 1/3 HPBW"; // A static set of default Colors // ============================== private static Colors defaultColors; static { defaultColors = new Colors(false); defaultColors.setForegroundColor(Color.BLACK); defaultColors.setClipboardColor(Color.MAGENTA); defaultColors.setErrorColor(Color.RED); defaultColors.setWarningColor(Color.ORANGE); defaultColors.setPhase1Color(new Color(138, 226, 52)); defaultColors.setDDTColor(new Color(249, 112, 108)); defaultColors.setPhase2Color(new Color(150, 185, 225)); defaultColors.setCommissionColor(new Color(173, 127, 168)); defaultColors.setFOVColor(Color.GREEN); defaultColors.setFOVMainFluxColor(Color.RED); defaultColors.setRestFrequencyColor(new Color(102, 153, 255)); defaultColors.setCentreFrequencyColor(Color.RED); defaultColors.setCatalogLinesColor(Color.GREEN); defaultColors.setSidebandsColor(Color.ORANGE); defaultColors.setUnconfiguredSidebandsColor(new Color(200, 200, 175)); defaultColors.setZoomBoxColor(new Color(0, 64, 128, 95)); defaultColors.setBasebandColor(Color.GREEN.darker()); defaultColors.setSpectralWindowColor(Color.BLUE.darker()); defaultColors.setAveragingRegionColor(Color.LIGHT_GRAY); defaultColors.setSuppressedColor(Color.GRAY); defaultColors.setTransmissionColor(Color.GRAY); } public static Color transparentColor(Color c, int alpha) { final Color result = new Color( c.getRed(), c.getGreen(), c.getBlue(), alpha); return result; } public static Color transparentColor(Color c) { return transparentColor(c, 127); } /** * @return Returns the defaultClipboard. */ public static Color getDefaultClipboard() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getClipboardColor(); } /** * @return Returns the defaultError. */ public static Color getDefaultError() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getErrorColor(); } /** * @return Returns the defaultWarning. */ public static Color getDefaultWarning() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getWarningColor(); } /** * @return Returns the defaultPhase1. */ public static Color getDefaultPhase1() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getPhase1Color(); } /** * @return Returns the default colour for a DDT phase 1 proposal. */ public static Color getDefaultDDT() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getDDTColor(); } /** * @return Returns the default colour for the FOV indicator in the spectral visualiser. */ public static Color getDefaultFOV() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getFOVColor(); } /** * @return Returns the default colour for the FOV main flux indicator in the spectral visualiser. */ public static Color getDefaultFOVMainFlux() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getFOVMainFluxColor(); } /** * @return Returns the defaultPhase2. */ public static Color getDefaultPhase2() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getPhase2Color(); } /** * @return Returns the defaultCommission. */ public static Color getDefaultCommission() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getCommissionColor(); } /** * @return Returns the defaultRestFrequency. */ public static Color getDefaultRestFrequency() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getRestFrequencyColor(); } /** * @return Returns the defaultCentreFrequency. */ public static Color getDefaultCentreFrequency() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getCentreFrequencyColor(); } /** * @return Returns the defaultCatalogLines. */ public static Color getDefaultCatalogLines() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getCatalogLinesColor(); } /** * @return Returns the defaultSidebands. */ public static Color getDefaultSidebands() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getSidebandsColor(); } /** * @return Returns the defaultUnconfiguredSidebands. */ public static Color getDefaultUnconfiguredSidebands() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getUnconfiguredSidebandsColor(); } /** * @return Returns the defaultZoomBox. */ public static Color getDefaultZoomBox() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getZoomBoxColor(); } /** * @return Returns the defaultForeground. */ public static Color getDefaultForeground() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getForegroundColor(); } /** * @return Returns the defaultBaseband. */ public static Color getDefaultBaseband() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getBasebandColor(); } /** * @return Returns the defaultSpectralWindow. */ public static Color getDefaultSpectralWindow() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getSpectralWindowColor(); } /** * @return Returns the defaultAveragingRegion. */ public static Color getDefaultAveragingRegion() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getAveragingRegionColor(); } /** * @return Returns the defaultSuppressed. */ public static Color getDefaultSuppressed() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getSuppressedColor(); } /** * @return Returns the defaultTransmission. */ public static Color getDefaultTransmission() { // WARNING: this will recurse indefinitely if defaultColors doesn't have the requested color return defaultColors.getTransmissionColor(); } public static Map> colourGroups() { OrderedMap> result; result = new OrderedMap>(); OrderedSet colorNames; colorNames = new OrderedSet(); colorNames.add(FOREGROUND); colorNames.add(CLIPBOARD); colorNames.add(ERROR); colorNames.add(WARNING); colorNames.add(PHASE1); colorNames.add(PHASE2); colorNames.add(DDT); colorNames.add(FOV); colorNames.add(FOVMAINFLUX); result.put("General", colorNames); colorNames = new OrderedSet(); colorNames.add(BASEBAND); colorNames.add(SPECTRAL_WINDOW); colorNames.add(AVERAGING_REGION); colorNames.add(SUPPRESSED); colorNames.add(REST_FREQUENCY); colorNames.add(CENTRE_FREQUENCY); colorNames.add(CATALOG_LINES); colorNames.add(SIDEBANDS); colorNames.add(SIDEBANDS_UNCONFIG); colorNames.add(TRANSMISSION); result.put("Spectral Display", colorNames); return result; } // The instance side implementation // ================================ // Colors are stored in a String -> Color map, where the String is the name // of the role for the Color (e.g. "foreground") rather than the name of the // Color itself (so not things like "red"). private SortedMap colors; private Colors(boolean copyDefaults) { super(); colors = new TreeMap(); if (copyDefaults) { Iterator i = defaultColors.colorSet(); while (i.hasNext()) { String name = (String) i.next(); setColor(name, defaultColors.getColor(name)); } } } public Colors() { this(true); } public Iterator colorSet() { return colors.keySet().iterator(); } public Color setColor(String label, Color color) { return colors.put(label, color); } public Color getColor(String label) { return (Color) colors.get(label); } public void setForegroundColor(Color color) { colors.put(FOREGROUND, color); } public Color getForegroundColor() { Color result = getColor(FOREGROUND); if (result == null) { result = getDefaultForeground(); } return result; } public void setClipboardColor(Color color) { colors.put(CLIPBOARD, color); } public Color getClipboardColor() { Color result = getColor(CLIPBOARD); if (result == null) { result = getDefaultClipboard(); } return result; } public void setErrorColor(Color color) { colors.put(ERROR, color); } public Color getErrorColor() { Color result = getColor(ERROR); if (result == null) { result = getDefaultError(); } return result; } public void setWarningColor(Color color) { colors.put(WARNING, color); } public Color getWarningColor() { Color result = getColor(WARNING); if (result == null) { result = getDefaultWarning(); } return result; } public void setPhase1Color(Color color) { colors.put(PHASE1, color); } public void setDDTColor(Color color) { colors.put(DDT,color); } public Color getDDTColor() { Color result = getColor(DDT); if (result == null) { result = getDefaultDDT(); } return result; } public void setFOVColor(Color color) { colors.put(FOV,color); //defaultColors.setFOVColor(color); } public Color getFOVColor() { Color result = getColor(FOV); if (result == null) { result = getDefaultFOV(); } return result; } public void setFOVMainFluxColor(Color color) { colors.put(FOVMAINFLUX,color); //defaultColors.setFOVMainFluxColor(color); } public Color getFOVMainFluxColor() { Color result = getColor(FOVMAINFLUX); if (result == null) { result = getDefaultFOVMainFlux(); } return result; } public Color getPhase1Color() { Color result = getColor(PHASE1); if (result == null) { result = getDefaultPhase1(); } return result; } public void setPhase2Color(Color color) { colors.put(PHASE2, color); } public Color getPhase2Color() { Color result = getColor(PHASE2); if (result == null) { result = getDefaultPhase2(); } return result; } public void setCommissionColor(Color color) { colors.put(COMMISSION, color); } public Color getCommissionColor() { Color result = getColor(COMMISSION); if (result == null) { result = getDefaultCommission(); } return result; } public void setRestFrequencyColor(Color color) { colors.put(REST_FREQUENCY, color); } public Color getRestFrequencyColor() { Color result = getColor(REST_FREQUENCY); if (result == null) { result = getDefaultRestFrequency(); } return result; } public void setCentreFrequencyColor(Color color) { colors.put(CENTRE_FREQUENCY, color); } public Color getCentreFrequencyColor() { Color result = getColor(CENTRE_FREQUENCY); if (result == null) { result = getDefaultCentreFrequency(); } return result; } public void setCatalogLinesColor(Color color) { colors.put(CATALOG_LINES, color); } public Color getCatalogLinesColor() { Color result = getColor(CATALOG_LINES); if (result == null) { result = getDefaultCatalogLines(); } return result; } public void setSidebandsColor(Color color) { colors.put(SIDEBANDS, color); } public Color getSidebandsColor() { Color result = getColor(SIDEBANDS); if (result == null) { result = getDefaultSidebands(); } return result; } public void setUnconfiguredSidebandsColor(Color color) { colors.put(SIDEBANDS_UNCONFIG, color); } public Color getUnconfiguredSidebandsColor() { Color result = getColor(SIDEBANDS_UNCONFIG); if (result == null) { result = getDefaultUnconfiguredSidebands(); } return result; } public void setZoomBoxColor(Color color) { colors.put(ZOOMBOX, color); } public Color getZoomBoxColor() { Color result = getColor(ZOOMBOX); if (result == null) { result = getDefaultZoomBox(); } return result; } public void setBasebandColor(Color color) { colors.put(BASEBAND, color); } public Color getBasebandColor() { Color result = getColor(BASEBAND); if (result == null) { result = getDefaultBaseband(); } return result; } public void setSpectralWindowColor(Color color) { colors.put(SPECTRAL_WINDOW, color); } public Color getSpectralWindowColor() { Color result = getColor(SPECTRAL_WINDOW); if (result == null) { result = getDefaultSpectralWindow(); } return result; } public void setAveragingRegionColor(Color color) { colors.put(AVERAGING_REGION, color); } public Color getAveragingRegionColor() { Color result = getColor(AVERAGING_REGION); if (result == null) { result = getDefaultAveragingRegion(); } return result; } public void setSuppressedColor(Color color) { colors.put(SUPPRESSED, color); } public Color getSuppressedColor() { Color result = getColor(SUPPRESSED); if (result == null) { result = getDefaultSuppressed(); } return result; } public void setTransmissionColor(Color color) { colors.put(TRANSMISSION, color); } public Color getTransmissionColor() { Color result = getColor(TRANSMISSION); if (result == null) { result = getDefaultTransmission(); } return result; } }