01: package de.java2html.properties;
02:
03: import java.util.Properties;
04:
05: import de.java2html.javasource.JavaSourceType;
06: import de.java2html.options.IConversionOptionsConstants;
07: import de.java2html.options.JavaSourceConversionOptions;
08: import de.java2html.options.JavaSourceStyleEntry;
09: import de.java2html.options.JavaSourceStyleTable;
10: import de.java2html.util.LinkedProperties;
11: import de.java2html.util.RGB;
12:
13: /**
14: * @author Markus
15: */
16: public class ConversionOptionsPropertiesWriter {
17:
18: public Properties write(JavaSourceConversionOptions options) {
19: Properties properties = new LinkedProperties();
20: properties.setProperty(
21: IConversionOptionsConstants.DEFAULT_STYLE_NAME, options
22: .getStyleTable().getName());
23: properties.setProperty(
24: IConversionOptionsConstants.SHOW_FILE_NAME, String
25: .valueOf(options.isShowFileName()));
26: properties.setProperty(
27: IConversionOptionsConstants.SHOW_TABLE_BORDER, String
28: .valueOf(options.isShowTableBorder()));
29: properties.setProperty(
30: IConversionOptionsConstants.SHOW_LINE_NUMBERS, String
31: .valueOf(options.isShowLineNumbers()));
32: properties.setProperty(
33: IConversionOptionsConstants.SHOW_JAVA2HTML_LINK, String
34: .valueOf(options.isShowJava2HtmlLink()));
35: properties.setProperty(
36: IConversionOptionsConstants.HORIZONTAL_ALIGNMENT,
37: options.getHorizontalAlignment().getName());
38: properties.setProperty(IConversionOptionsConstants.TAB_SIZE,
39: String.valueOf(options.getTabSize()));
40:
41: addStyleEntries(properties, options.getStyleTable());
42: return properties;
43: }
44:
45: private void addStyleEntries(Properties properties,
46: JavaSourceStyleTable table) {
47: JavaSourceType[] sourceTypes = JavaSourceType.getAll();
48: for (int i = 0; i < sourceTypes.length; i++) {
49: JavaSourceType type = sourceTypes[i];
50: JavaSourceStyleEntry entry = table.get(type);
51: properties.setProperty(type.getName()
52: + IConversionOptionsConstants.POSTFIX_COLOR,
53: getRgbString(entry.getColor()));
54: properties.setProperty(type.getName()
55: + IConversionOptionsConstants.POSTFIX_BOLD, String
56: .valueOf(entry.isBold()));
57: properties.setProperty(type.getName()
58: + IConversionOptionsConstants.POSTFIX_ITALIC,
59: String.valueOf(entry.isItalic()));
60: }
61: }
62:
63: private String getRgbString(RGB color) {
64: return color.getRed() + "," + color.getGreen() + ","
65: + color.getBlue();
66: }
67: }
|