001 // This file is part of AceWiki. 002 // Copyright 2008-2012, AceWiki developers. 003 // 004 // AceWiki is free software: you can redistribute it and/or modify it under the terms of the GNU 005 // Lesser General Public License as published by the Free Software Foundation, either version 3 of 006 // the License, or (at your option) any later version. 007 // 008 // AceWiki is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without 009 // even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 010 // Lesser General Public License for more details. 011 // 012 // You should have received a copy of the GNU Lesser General Public License along with AceWiki. If 013 // not, see http://www.gnu.org/licenses/. 014 015 package ch.uzh.ifi.attempto.echocomp; 016 017 import java.util.HashMap; 018 019 import nextapp.echo.app.Color; 020 import nextapp.echo.app.Font; 021 import nextapp.echo.app.ResourceImageReference; 022 import nextapp.echo.app.StyleSheet; 023 import nextapp.echo.app.serial.SerialException; 024 import nextapp.echo.app.serial.StyleSheetLoader; 025 026 /** 027 * This class defines some style attributes that are used by the components of this package. 028 * 029 * @author Tobias Kuhn 030 */ 031 public class Style { 032 033 private Style() {} // no instances allowed 034 035 private static final HashMap<String, ResourceImageReference> images = 036 new HashMap<String, ResourceImageReference>(); 037 038 static { 039 try { 040 styleSheet = StyleSheetLoader.load( 041 "ch/uzh/ifi/attempto/echocomp/style/Default.stylesheet.xml", 042 Thread.currentThread().getContextClassLoader() 043 ); 044 } catch (SerialException ex) { 045 throw new RuntimeException(ex); 046 } 047 } 048 049 /** 050 * The style sheet containing the shadows for internal windows. 051 */ 052 public static StyleSheet styleSheet; 053 054 /** 055 * The light background color. 056 */ 057 public static Color lightBackground = new Color(190, 190, 255); 058 059 /** 060 * The medium background color. 061 */ 062 public static Color mediumBackground = new Color(160, 160, 255); 063 064 /** 065 * The dark background color. 066 */ 067 public static Color darkBackground = new Color(60, 60, 220); 068 069 /** 070 * The color for shaded background areas. 071 */ 072 public static Color shadedBackground = new Color(240, 240, 240); 073 074 /** 075 * The light foreground color. 076 */ 077 public static Color lightForeground = new Color(255, 255, 255); 078 079 /** 080 * The medium foreground color. 081 */ 082 public static Color mediumForeground = new Color(60, 60, 220); 083 084 /** 085 * The dark foreground color. 086 */ 087 public static Color darkForeground = new Color(0, 0, 0); 088 089 /** 090 * The light color for disabled components 091 */ 092 public static Color lightDisabled = new Color(220, 220, 220); 093 094 /** 095 * The dark color for disabled components 096 */ 097 public static Color darkDisabled = new Color(100, 100, 100); 098 099 /** 100 * The color for the title background of internal windows. 101 */ 102 public static Color windowTitleBackground = new Color(110, 110, 210); 103 104 /** 105 * The font typeface. 106 */ 107 public static Font.Typeface fontTypeface = Font.VERDANA; 108 109 /** 110 * This method is used to modify a given color by keeping its brightness and saturation. A 111 * shift value of 120, for example, means a shift by 120 "degrees" towards violet. A shift of 112 * 360 is a full rotation and result in the original color. 113 * 114 * @param c The original color. 115 * @param colorShift The color shift value. 116 * @return The modified color. 117 */ 118 public static Color shiftColor(Color c, int colorShift) { 119 if (colorShift >= 240) { 120 c = new Color(c.getGreen(), c.getBlue(), c.getRed()); 121 } else if (colorShift >= 120) { 122 c = new Color(c.getBlue(), c.getRed(), c.getGreen()); 123 } 124 double s = (colorShift % 120) / 120.0; 125 Color color = new Color( 126 (int) (s * c.getBlue() + (1-s) * c.getRed()), 127 (int) (s * c.getRed() + (1-s) * c.getGreen()), 128 (int) (s * c.getGreen() + (1-s) * c.getBlue()) 129 ); 130 return color; 131 } 132 133 /** 134 * Returns an image reference for the given file. The same reference is returned when 135 * this method is called twice for the same file. 136 * 137 * @param file Path and file name of an image file. 138 * @return An image reference for the given file. 139 */ 140 public static ResourceImageReference getImage(String file) { 141 ResourceImageReference i = images.get(file); 142 if (i != null) { 143 return i; 144 } else { 145 i = new ResourceImageReference(file); 146 images.put(file, i); 147 return i; 148 } 149 } 150 151 }