001/* 002 * Copyright 2020 Anyware Services 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 */ 016package org.ametys.plugins.explorer.calendars; 017 018import java.util.LinkedHashMap; 019import java.util.Map; 020 021import org.apache.avalon.framework.component.Component; 022import org.apache.avalon.framework.configuration.Configurable; 023import org.apache.avalon.framework.configuration.Configuration; 024import org.apache.avalon.framework.configuration.ConfigurationException; 025 026import org.ametys.plugins.explorer.calendars.Calendar; 027 028/** 029 * Component listing the available colors for a {@link Calendar} 030 */ 031public class CalendarColorsComponent implements Component, Configurable 032{ 033 /** The component role */ 034 public static final String ROLE = CalendarColorsComponent.class.getName(); 035 036 private Map<String, CalendarColor> _colors; 037 038 public void configure(Configuration configuration) throws ConfigurationException 039 { 040 Map<String, CalendarColor> calendarColors = new LinkedHashMap<>(); 041 for (Configuration colorConfiguration : configuration.getChildren("color")) 042 { 043 String id = colorConfiguration.getAttribute("id"); 044 String label = colorConfiguration.getChild("label").getValue(); 045 String bgColor = colorConfiguration.getChild("bg").getValue(); 046 String fgColor = colorConfiguration.getChild("fg").getValue(); 047 048 CalendarColor color = new CalendarColor(id, label, bgColor, fgColor); 049 calendarColors.put(id, color); 050 } 051 052 _colors = calendarColors; 053 } 054 055 /** 056 * Get the colors of calendars 057 * @return colors 058 */ 059 public Map<String, CalendarColor> getColors() 060 { 061 return _colors; 062 } 063 064 /** 065 * Get the color by id 066 * @param id the id 067 * @return the color 068 */ 069 public CalendarColor getColor(String id) 070 { 071 return _colors.get(id); 072 } 073 074 /** 075 * Class representing a calendar color 076 * 077 */ 078 public class CalendarColor 079 { 080 String _bgColor; 081 String _fgColor; 082 String _label; 083 String _id; 084 085 /** 086 * Constructor 087 * @param id the id 088 * @param label the label 089 * @param bgColor the color 090 * @param fgCOlor the text color 091 */ 092 public CalendarColor (String id, String label, String bgColor, String fgCOlor) 093 { 094 _id = id; 095 _label = label; 096 _bgColor = bgColor; 097 _fgColor = fgCOlor; 098 } 099 100 /** 101 * Get the id 102 * @return the id 103 */ 104 public String getId() 105 { 106 return _id; 107 } 108 109 /** 110 * Get the label 111 * @return the label 112 */ 113 public String getLabel() 114 { 115 return _label; 116 } 117 118 /** 119 * Get the color 120 * @return the color 121 */ 122 public String getColor() 123 { 124 return _bgColor; 125 } 126 127 /** 128 * Get the text color 129 * @return the text color 130 */ 131 public String getTextColor() 132 { 133 return _fgColor; 134 } 135 } 136}