adjusted light colors
[javainspect.git] / src / main / java / eu / svjatoslav / inspector / java / structure / Utils.java
1 /*
2  * JavaInspect - Utility to visualize java software
3  * Copyright (C) 2013, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu
4  * 
5  * This program is free software; you can redistribute it and/or
6  * modify it under the terms of version 2 of the GNU General Public License
7  * as published by the Free Software Foundation.
8  */
9
10 package eu.svjatoslav.inspector.java.structure;
11
12 import java.util.ArrayList;
13 import java.util.List;
14
15 public class Utils {
16
17         private static final List<String> systemDataTypes = new ArrayList<String>();
18
19         private static final List<String> systemMethods = new ArrayList<String>();
20
21         private static final List<String> systemPackages = new ArrayList<String>();
22
23         private static final List<String> darkColors = new ArrayList<String>();
24
25         private static final List<String> lightColors = new ArrayList<String>();
26
27         private static final List<String> enumMethods = new ArrayList<String>();
28
29         public static int lastChosenDarkColor = -1;
30
31         public static int lastChosenLightColor = -1;
32
33         static {
34                 initEnumMethods();
35                 initSystemDataTypes();
36                 initDarkColors();
37                 initLightColors();
38                 initSystemMethods();
39                 initSystemPackages();
40         }
41
42         /**
43          * retrieves colors from predefined palette
44          */
45         public static String getNextDarkColor() {
46                 lastChosenDarkColor++;
47                 if (lastChosenDarkColor >= darkColors.size())
48                         lastChosenDarkColor = 0;
49
50                 return darkColors.get(lastChosenDarkColor);
51         }
52
53         /**
54          * retrieves colors from predefined palette
55          */
56         public static String getNextLightColor() {
57                 lastChosenLightColor++;
58                 if (lastChosenLightColor >= lightColors.size())
59                         lastChosenLightColor = 0;
60
61                 return lightColors.get(lastChosenLightColor);
62         }
63
64         public static void initDarkColors() {
65                 darkColors.add("antiquewhite4");
66                 darkColors.add("blueviolet");
67                 darkColors.add("brown4");
68                 darkColors.add("chartreuse4");
69                 darkColors.add("cyan4");
70                 darkColors.add("deeppink1");
71                 darkColors.add("deepskyblue3");
72                 darkColors.add("firebrick1");
73                 darkColors.add("goldenrod3");
74                 darkColors.add("gray0");
75         }
76
77         public static void initEnumMethods() {
78                 enumMethods.add("values");
79                 enumMethods.add("valueOf");
80                 enumMethods.add("name");
81                 enumMethods.add("compareTo");
82                 enumMethods.add("valueOf");
83                 enumMethods.add("getDeclaringClass");
84                 enumMethods.add("ordinal");
85         }
86
87         public static void initLightColors() {
88                 lightColors.add("olivedrab2");
89                 lightColors.add("peachpuff2");
90                 lightColors.add("seagreen1");
91                 lightColors.add("violet");
92                 lightColors.add("aqua");
93                 lightColors.add("orange");
94         }
95
96         public static void initSystemDataTypes() {
97                 systemDataTypes.add("void");
98                 systemDataTypes.add("int");
99                 systemDataTypes.add("long");
100                 systemDataTypes.add("float");
101                 systemDataTypes.add("double");
102                 systemDataTypes.add("boolean");
103                 systemDataTypes.add("char");
104                 systemDataTypes.add("short");
105                 systemDataTypes.add("byte");
106         }
107
108         public static void initSystemMethods() {
109                 systemMethods.add("wait");
110                 systemMethods.add("equals");
111                 systemMethods.add("toString");
112                 systemMethods.add("hashCode");
113                 systemMethods.add("notify");
114                 systemMethods.add("notifyAll");
115                 systemMethods.add("getClass");
116         }
117
118         public static void initSystemPackages() {
119                 systemPackages.add("java.");
120                 systemPackages.add("javax.");
121                 systemPackages.add("sun.");
122         }
123
124         public static boolean isEnumMethod(final String name) {
125                 return enumMethods.contains(name);
126         }
127
128         public static boolean isSystemDataType(final String name) {
129                 return systemDataTypes.contains(name);
130         }
131
132         public static boolean isSystemMethod(final String name) {
133                 return systemMethods.contains(name);
134         }
135
136         public static boolean isSystemPackage(final String name) {
137
138                 for (final String packagePrefix : systemPackages)
139                         if (name.startsWith(packagePrefix))
140                                 return true;
141
142                 return false;
143         }
144
145 }