001/* 002 * JGrapes Event Driven Framework 003 * Copyright (C) 2018 Michael N. Lipp 004 * 005 * This program is free software; you can redistribute it and/or modify it 006 * under the terms of the GNU Affero General Public License as published by 007 * the Free Software Foundation; either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, but 011 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 012 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License 013 * for more details. 014 * 015 * You should have received a copy of the GNU Affero General Public License along 016 * with this program; if not, see <http://www.gnu.org/licenses/>. 017 */ 018 019package org.jgrapes.webconsole.base; 020 021import java.util.Map; 022import org.jgrapes.core.ComponentType; 023import org.jgrapes.core.Components; 024 025/** 026 * Evaluates and provides the styling info to a web console component. 027 */ 028public class StylingInfo { 029 030 private final ComponentType component; 031 private final Map<?, ?> properties; 032 private String styling; 033 034 /** 035 * Instantiates a new styling info. 036 * 037 * @param component the component 038 * @param properties the properties 039 */ 040 public StylingInfo(ComponentType component, Map<?, ?> properties) { 041 super(); 042 this.component = component; 043 this.properties = properties; 044 } 045 046 /** 047 * Returns the styling information. The method looks for an entry 048 * with key "style" in properties first. If no entry is found, 049 * it searches through the anchestors of this component for 050 * a component of type {@link ConsoleWeblet} and returns 051 * the result of invoking {@link ConsoleWeblet#styling()}. 052 * Else it returns "standard". 053 * 054 * @return the result 055 */ 056 public String get() { 057 if (styling != null) { 058 return styling; 059 } 060 if (properties != null) { 061 styling = (String) properties.get("styling"); 062 } 063 if (styling == null) { 064 // Try to get the information from the web console (weblet) 065 ComponentType console = component; 066 while (true) { 067 console = Components.manager(console).parent(); 068 if (console == null) { 069 break; 070 } 071 // Component is in tree, cache result. 072 styling = "standard"; 073 if (console instanceof ConsoleWeblet) { 074 styling = ((ConsoleWeblet) console).styling(); 075 break; 076 } 077 } 078 } 079 if (styling == null) { 080 return "standard"; 081 } 082 return styling; 083 } 084 085}