View Javadoc
1   /*
2    * (c) Copyright 2013 Openflexo
3    *
4    * This file is part of OpenFlexo.
5    *
6    * OpenFlexo is free software: you can redistribute it and/or modify
7    * it under the terms of the GNU General Public License as published by
8    * the Free Software Foundation, either version 3 of the License, or
9    * (at your option) any later version.
10   *
11   * OpenFlexo is distributed in the hope that it will be useful,
12   * but WITHOUT ANY WARRANTY; without even the implied warranty of
13   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14   * GNU General Public License for more details.
15   *
16   * You should have received a copy of the GNU General Public License
17   * along with OpenFlexo. If not, see <http://www.gnu.org/licenses/>.
18   *
19   */
20  
21  package org.openflexo.foundation.doc;
22  
23  import java.awt.Color;
24  import java.awt.Font;
25  
26  import org.openflexo.foundation.technologyadapter.TechnologyAdapter;
27  import org.openflexo.pamela.annotations.Getter;
28  import org.openflexo.pamela.annotations.ModelEntity;
29  import org.openflexo.pamela.annotations.PropertyIdentifier;
30  import org.openflexo.pamela.annotations.Setter;
31  
32  /**
33   * Generic abstract concept representing style information of a run
34   * 
35   * @author sylvain
36   *
37   * @param <D>
38   *            type of {@link FlexoDocument} involving this concept
39   * @param <TA>
40   *            {@link TechnologyAdapter} of current implementation
41   */
42  @ModelEntity(isAbstract = true)
43  public interface FlexoRunStyle<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>> extends FlexoDocStyle<D, TA> {
44  
45  	@PropertyIdentifier(type = FlexoRunStyle.class)
46  	public static final String BASED_ON_KEY = "basedOn";
47  
48  	@PropertyIdentifier(type = Font.class)
49  	public static final String FONT_KEY = "font";
50  	@PropertyIdentifier(type = Integer.class)
51  	public static final String FONT_SIZE_KEY = "fontSize";
52  	@PropertyIdentifier(type = Color.class)
53  	public static final String FONT_COLOR_KEY = "fontColor";
54  	@PropertyIdentifier(type = Color.class)
55  	public static final String BACKGROUND_COLOR_KEY = "backgroundColor";
56  	@PropertyIdentifier(type = Boolean.class)
57  	public static final String BOLD_KEY = "bold";
58  	@PropertyIdentifier(type = Boolean.class)
59  	public static final String ITALIC_KEY = "italic";
60  	@PropertyIdentifier(type = Boolean.class)
61  	public static final String UNDERLINE_KEY = "underline";
62  
63  	@Getter(BASED_ON_KEY)
64  	public FlexoRunStyle<D, TA> getBasedOn();
65  
66  	@Setter(BASED_ON_KEY)
67  	public void setBasedOn(FlexoRunStyle<D, TA> style);
68  
69  	@Getter(FONT_KEY)
70  	public Font getFont();
71  
72  	@Setter(FONT_KEY)
73  	public void setFont(Font aFont);
74  
75  	@Getter(FONT_SIZE_KEY)
76  	public Integer getFontSize();
77  
78  	@Setter(FONT_SIZE_KEY)
79  	public void setFontSize(Integer aFontSize);
80  
81  	@Getter(FONT_COLOR_KEY)
82  	public Color getFontColor();
83  
84  	@Setter(FONT_COLOR_KEY)
85  	public void setFontColor(Color aColor);
86  
87  	@Getter(BACKGROUND_COLOR_KEY)
88  	public Color getBackgroundColor();
89  
90  	@Setter(BACKGROUND_COLOR_KEY)
91  	public void setBackgroundColor(Color aColor);
92  
93  	@Getter(BOLD_KEY)
94  	public Boolean getBold();
95  
96  	@Setter(BOLD_KEY)
97  	public void setBold(Boolean bold);
98  
99  	@Getter(ITALIC_KEY)
100 	public Boolean getItalic();
101 
102 	@Setter(ITALIC_KEY)
103 	public void setItalic(Boolean italic);
104 
105 	@Getter(UNDERLINE_KEY)
106 	public Boolean getUnderline();
107 
108 	@Setter(UNDERLINE_KEY)
109 	public void setUnderline(Boolean underline);
110 
111 	@Override
112 	public String getStringRepresentation();
113 
114 	public static abstract class FlexoRunStyleImpl<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>>
115 			extends FlexoDocStyleImpl<D, TA> implements FlexoRunStyle<D, TA> {
116 
117 		@Override
118 		public String getStringRepresentation() {
119 			StringBuffer sb = new StringBuffer();
120 			sb.append(getFont() != null ? getFont().getFontName() + "," : "");
121 			sb.append(getFontSize() != null ? getFontSize() + "pt," : "");
122 			sb.append(getFontColor() != null ? getFontColor() : "");
123 			sb.append(getBold() != null ? (getBold() ? "bold," : "") : "");
124 			sb.append(getItalic() != null ? (getItalic() ? "italic," : "") : "");
125 			sb.append(getUnderline() != null ? (getUnderline() ? "underline," : "") : "");
126 			if (sb.length() > 0) {
127 				sb.deleteCharAt(sb.length() - 1);
128 			}
129 			return sb.toString();
130 		}
131 
132 	}
133 
134 }