ColorHandler.java 3.65 KB
Newer Older
Matthias Betz's avatar
Matthias Betz committed
1
2
3
4
package de.hft.stuttgart.citygml.viewer.parser;

import java.awt.Color;
import java.io.FileReader;
5
import java.nio.file.Path;
Matthias Betz's avatar
Matthias Betz committed
6
7
8
9
10
11
12
import java.util.Properties;
import java.util.logging.Logger;

public class ColorHandler {
	
	private static final Logger logger = Logger.getLogger(ColorHandler.class.getName());

13
14
15
16
17
18
19
20
21
22
	private Color groundColor = new Color(0.9411765f, 0.9019608f, 0.54901963f);
	private Color roofColor = Color.RED;
	private Color doorColor = Color.ORANGE;
	private Color windowColor = new Color(0.0f, 0.5019608f, 0.5019608f);
	private Color wallColor = Color.WHITE;
	private Color bridgeColor = new Color(1.0f, 0.49803922f, 0.3137255f);
	private Color landColor = new Color(0.64705884f, 0.16470589f, 0.16470589f);
	private Color transportationColor = new Color(1.0f, 1.0f, 0.0f);
	private Color vegetationColor = new Color(0.5647059f, 0.93333334f, 0.5647059f);
	private Color waterColor = new Color(0.5294118f, 0.80784315f, 0.98039216f);
Matthias Betz's avatar
Matthias Betz committed
23
	
24
25
	public ColorHandler(Path path) {
		try (FileReader reader = new FileReader(path.toFile())) {
Matthias Betz's avatar
Matthias Betz committed
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
			Properties props = new Properties();
			props.load(reader);
			Color parsedGroundColor = parseColor(props.getProperty("groundColor"));
			if (parsedGroundColor != null) {
				groundColor = parsedGroundColor;
			}
			Color parsedRoofColor = parseColor(props.getProperty("roofColor"));
			if (parsedRoofColor != null) {
				roofColor = parsedRoofColor;
			}
			Color parsedDoorColor = parseColor(props.getProperty("doorColor"));
			if (parsedDoorColor != null) {
				doorColor = parsedDoorColor;
			}
			Color parsedWindowColor = parseColor(props.getProperty("windowColor"));
			if (parsedWindowColor != null) {
				windowColor = parsedWindowColor;
			}
			Color parsedWallColor = parseColor(props.getProperty("wallColor"));
			if (parsedWallColor != null) {
				wallColor = parsedWallColor;
			}
			Color parsedBridgeColor = parseColor(props.getProperty("bridgeColor"));
			if (parsedBridgeColor != null) {
				bridgeColor = parsedBridgeColor;
			}
			Color parsedLandColor = parseColor(props.getProperty("landColor"));
			if (parsedLandColor != null) {
				landColor = parsedLandColor;
			}
			Color parsedTransportationColor = parseColor(props.getProperty("transportationColor"));
			if (parsedTransportationColor != null) {
				transportationColor = parsedTransportationColor;
			}
			Color parsedVegetationColor = parseColor(props.getProperty("vegetationColor"));
			if (parsedVegetationColor != null) {
				vegetationColor = parsedVegetationColor;
			}
			Color parsedWaterColor = parseColor(props.getProperty("waterColor"));
			if (parsedWaterColor != null) {
				waterColor = parsedWaterColor;
			}
		}catch (Exception e) {
			logger.warning(() -> "Failed to read color properties file: " + e.getMessage());
		}
	}
	
73
	private Color parseColor(String colorString) {
Matthias Betz's avatar
Matthias Betz committed
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
		if (colorString == null) {
			return null;
		}
		try {
			String[] split = colorString.split(" ");
			float r = Float.parseFloat(split[0]);
			float g = Float.parseFloat(split[1]);
			float b = Float.parseFloat(split[2]);
			return new Color(r, g, b);
		} catch (Exception e) {
			e.printStackTrace();
			return null;
		}
	}

89
	public Color getGroundColor() {
Matthias Betz's avatar
Matthias Betz committed
90
91
92
		return groundColor;
	}

93
	public Color getRoofColor() {
Matthias Betz's avatar
Matthias Betz committed
94
95
96
		return roofColor;
	}

97
	public Color getDoorColor() {
Matthias Betz's avatar
Matthias Betz committed
98
99
100
		return doorColor;
	}

101
	public Color getWindowColor() {
Matthias Betz's avatar
Matthias Betz committed
102
103
104
		return windowColor;
	}

105
	public Color getWallColor() {
Matthias Betz's avatar
Matthias Betz committed
106
107
108
		return wallColor;
	}

109
	public Color getBridgeColor() {
Matthias Betz's avatar
Matthias Betz committed
110
111
112
		return bridgeColor;
	}

113
	public Color getLandColor() {
Matthias Betz's avatar
Matthias Betz committed
114
115
116
		return landColor;
	}

117
	public Color getTransportationColor() {
Matthias Betz's avatar
Matthias Betz committed
118
119
120
		return transportationColor;
	}

121
	public Color getVegetationColor() {
Matthias Betz's avatar
Matthias Betz committed
122
123
124
		return vegetationColor;
	}

125
	public Color getWaterColor() {
Matthias Betz's avatar
Matthias Betz committed
126
127
128
129
		return waterColor;
	}

}