Skip to main content
summaryrefslogtreecommitdiffstats
blob: c1ef6ef8355c3ac631409d9664dce99bc92db270 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
/*******************************************************************************
 * Copyright (c) 2008 IBM Corporation and others.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the Eclipse Public License v1.0
 * which accompanies this distribution, and is available at
 * http://www.eclipse.org/legal/epl-v10.html
 *
 * Contributors:
 *     IBM Corporation - initial API and implementation
 *******************************************************************************/
package org.eclipse.pde.internal.picasso;

import java.util.Properties;

import org.eclipse.core.runtime.Platform;

public class Options extends Object {
	public static final String PLUGIN_ID = "org.eclipse.pde.picasso"; //$NON-NLS-1$
	public static final String OPTION_ID_PAINT = "paint"; //$NON-NLS-1$
	public static final String OPTION_ID_PAINT_EXTRA_COMPOSITE_MARGIN = "paint/extraCompositeMargin"; //$NON-NLS-1$
	public static final String OPTION_ID_PAINT_TOOL_TIP = "paint/toolTip"; //$NON-NLS-1$

	private Properties properties;

	public Options(Properties properties) {
		super();
		this.properties = properties;
	}

	private String createOptionKey(String option) {
		return Options.PLUGIN_ID + '/' + option;
	}

	private boolean getBooleanOption(String option, boolean defaultValue) {
		String value = getOption(option);
		boolean result = value != null ? Boolean.parseBoolean(value) : defaultValue;
		return result;
	}

	private boolean getBooleanOptionDefault(String option, boolean defaultValue) {
		String key = createOptionKey(option);
		String value = System.getProperty(key);
		boolean result;

		if (value != null) {
			result = Boolean.parseBoolean(value);
		} else {
			String propertyValue = properties.getProperty(option);
			result = propertyValue != null ? Boolean.parseBoolean(propertyValue) : defaultValue;
		}

		return result;
	}

	public int getExtraCompositeMargin() {
		int defaultValue = getIntegerOptionDefault(Options.OPTION_ID_PAINT_EXTRA_COMPOSITE_MARGIN, 0);
		int value = getIntegerOption(Options.OPTION_ID_PAINT_EXTRA_COMPOSITE_MARGIN, defaultValue);
		return value;
	}

	private int getIntegerOption(String option, int defaultValue) {
		String value = getOption(option);
		int result = value != null ? Integer.parseInt(value) : defaultValue;
		return result;
	}

	private int getIntegerOptionDefault(String option, int defaultValue) {
		String key = createOptionKey(option);
		String value = System.getProperty(key);
		int result;

		if (value != null) {
			result = Integer.parseInt(value);
		} else {
			String propertyValue = properties.getProperty(option);
			result = propertyValue != null ? Integer.parseInt(propertyValue) : defaultValue;
		}
		return result;
	}

	private String getOption(String option) {
		String key = createOptionKey(option);
		return Platform.getDebugOption(key);
	}

	public boolean getPaint() {
		boolean defaultValue = getBooleanOptionDefault(Options.OPTION_ID_PAINT, false);
		boolean value = getBooleanOption(Options.OPTION_ID_PAINT, defaultValue);
		return value;
	}

	public boolean getToolTip() {
		boolean defaultValue = getBooleanOptionDefault(Options.OPTION_ID_PAINT_TOOL_TIP, false);
		boolean value = getBooleanOption(Options.OPTION_ID_PAINT_TOOL_TIP, defaultValue);
		return value;
	}
}

Back to the top