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.util.List;
24  
25  import org.openflexo.foundation.technologyadapter.TechnologyAdapter;
26  import org.openflexo.pamela.annotations.Adder;
27  import org.openflexo.pamela.annotations.Embedded;
28  import org.openflexo.pamela.annotations.Getter;
29  import org.openflexo.pamela.annotations.ModelEntity;
30  import org.openflexo.pamela.annotations.PropertyIdentifier;
31  import org.openflexo.pamela.annotations.Remover;
32  import org.openflexo.pamela.annotations.Setter;
33  import org.openflexo.pamela.annotations.Getter.Cardinality;
34  
35  /**
36   * Generic abstract concept representing style information of a paragraph
37   * 
38   * @author sylvain
39   *
40   * @param <D>
41   *            type of {@link FlexoDocument} involving this concept
42   * @param <TA>
43   *            {@link TechnologyAdapter} of current implementation
44   */
45  @ModelEntity(isAbstract = true)
46  public interface FlexoParagraphStyle<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>> extends FlexoDocStyle<D, TA> {
47  
48  	public enum ParagraphAlignment {
49  		Right, Left, Center, Justify
50  	}
51  
52  	@ModelEntity
53  	public static interface ParagraphTab {
54  		@PropertyIdentifier(type = Float.class)
55  		public static final String POS_KEY = "pos";
56  		@PropertyIdentifier(type = Integer.class)
57  		public static final String ALIGN_KEY = "align";
58  		@PropertyIdentifier(type = Integer.class)
59  		public static final String LEADER_KEY = "leader";
60  
61  		@Getter(POS_KEY)
62  		public Float getPos();
63  
64  		@Setter(POS_KEY)
65  		public void setPos(Float pos);
66  
67  		@Getter(ALIGN_KEY)
68  		public Integer getAlign();
69  
70  		@Setter(ALIGN_KEY)
71  		public void setAlign(Integer align);
72  
73  		@Getter(LEADER_KEY)
74  		public Integer getLeader();
75  
76  		@Setter(LEADER_KEY)
77  		public void setLeader(Integer leader);
78  	}
79  
80  	@ModelEntity
81  	public static interface ParagraphSpacing {
82  		@PropertyIdentifier(type = LineSpacingRule.class)
83  		public static final String LINE_SPACING_RULE_KEY = "lineSpacingRule";
84  		@PropertyIdentifier(type = Integer.class)
85  		public static final String LINE_KEY = "line";
86  		@PropertyIdentifier(type = Integer.class)
87  		public static final String BEFORE_KEY = "before";
88  		@PropertyIdentifier(type = Integer.class)
89  		public static final String AFTER_KEY = "after";
90  
91  		public enum LineSpacingRule {
92  			AUTO, EXACT, AT_LEAST
93  		};
94  
95  		@Getter(LINE_SPACING_RULE_KEY)
96  		public LineSpacingRule getLineSpacingRule();
97  
98  		@Setter(LINE_SPACING_RULE_KEY)
99  		public void setLineSpacingRule(LineSpacingRule lineSpacingRule);
100 
101 		@Getter(LINE_KEY)
102 		public Integer getLine();
103 
104 		@Setter(LINE_KEY)
105 		public void setLine(Integer line);
106 
107 		@Getter(BEFORE_KEY)
108 		public Integer getBefore();
109 
110 		@Setter(BEFORE_KEY)
111 		public void setBefore(Integer before);
112 
113 		@Getter(AFTER_KEY)
114 		public Integer getAfter();
115 
116 		@Setter(AFTER_KEY)
117 		public void setAfter(Integer after);
118 
119 	}
120 
121 	@ModelEntity
122 	public static interface ParagraphIndent {
123 		@PropertyIdentifier(type = Integer.class)
124 		public static final String LEFT_KEY = "left";
125 		@PropertyIdentifier(type = Integer.class)
126 		public static final String RIGHT_KEY = "right";
127 		@PropertyIdentifier(type = Integer.class)
128 		public static final String FIRST_KEY = "first";
129 
130 		@Getter(LEFT_KEY)
131 		public Integer getLeft();
132 
133 		@Setter(LEFT_KEY)
134 		public void setLeft(Integer left);
135 
136 		@Getter(RIGHT_KEY)
137 		public Integer getRight();
138 
139 		@Setter(RIGHT_KEY)
140 		public void setRight(Integer right);
141 
142 		@Getter(FIRST_KEY)
143 		public Integer getFirst();
144 
145 		@Setter(FIRST_KEY)
146 		public void setFirst(Integer first);
147 
148 	}
149 
150 	@ModelEntity
151 	public static interface ParagraphNumbering {
152 		@PropertyIdentifier(type = Integer.class)
153 		public static final String NUM_ID_KEY = "numId";
154 		@PropertyIdentifier(type = Integer.class)
155 		public static final String ILVL_KEY = "ilvl";
156 
157 		@Getter(NUM_ID_KEY)
158 		public Integer getNumId();
159 
160 		@Setter(NUM_ID_KEY)
161 		public void setNumId(Integer left);
162 
163 		@Getter(ILVL_KEY)
164 		public Integer getIlvl();
165 
166 		@Setter(ILVL_KEY)
167 		public void setIlvl(Integer right);
168 
169 	}
170 
171 	@PropertyIdentifier(type = ParagraphAlignment.class)
172 	public static final String PARAGRAPH_ALIGNMENT_KEY = "paragraphAlignment";
173 	@PropertyIdentifier(type = ParagraphTab.class, cardinality = Cardinality.LIST)
174 	public static final String PARAGRAPH_TABS_KEY = "paragraphTabs";
175 	@PropertyIdentifier(type = ParagraphSpacing.class)
176 	public static final String PARAGRAPH_SPACING_KEY = "paragraphSpacing";
177 	@PropertyIdentifier(type = ParagraphIndent.class)
178 	public static final String PARAGRAPH_INDENT_KEY = "paragraphIndent";
179 	@PropertyIdentifier(type = ParagraphNumbering.class)
180 	public static final String PARAGRAPH_NUMBERING_KEY = "paragraphNumbering";
181 
182 	@Getter(PARAGRAPH_ALIGNMENT_KEY)
183 	public ParagraphAlignment getParagraphAlignment();
184 
185 	@Setter(PARAGRAPH_ALIGNMENT_KEY)
186 	public void setParagraphAlignment(ParagraphAlignment align);
187 
188 	@Getter(value = PARAGRAPH_TABS_KEY, cardinality = Cardinality.LIST)
189 	@Embedded
190 	public List<ParagraphTab> getParagraphTabs();
191 
192 	@Setter(PARAGRAPH_TABS_KEY)
193 	public void setParagraphTabs(List<ParagraphTab> someTabs);
194 
195 	@Adder(PARAGRAPH_TABS_KEY)
196 	public void addToParagraphTabs(ParagraphTab aTab);
197 
198 	@Remover(PARAGRAPH_TABS_KEY)
199 	public void removeFromParagraphTabs(ParagraphTab aTab);
200 
201 	@Getter(PARAGRAPH_SPACING_KEY)
202 	public ParagraphSpacing getParagraphSpacing();
203 
204 	@Setter(PARAGRAPH_SPACING_KEY)
205 	public void setParagraphSpacing(ParagraphSpacing spacing);
206 
207 	@Getter(PARAGRAPH_INDENT_KEY)
208 	public ParagraphIndent getParagraphIndent();
209 
210 	@Setter(PARAGRAPH_INDENT_KEY)
211 	public void setParagraphIndent(ParagraphIndent indent);
212 
213 	@Getter(PARAGRAPH_NUMBERING_KEY)
214 	public ParagraphNumbering getParagraphNumbering();
215 
216 	@Setter(PARAGRAPH_NUMBERING_KEY)
217 	public void setParagraphNumbering(ParagraphNumbering numbering);
218 
219 	@Override
220 	public String getStringRepresentation();
221 
222 	public static abstract class FlexoParagraphStyleImpl<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>>
223 			extends FlexoDocStyleImpl<D, TA> implements FlexoParagraphStyle<D, TA> {
224 
225 		@Override
226 		public String getStringRepresentation() {
227 			StringBuffer sb = new StringBuffer();
228 			sb.append(getParagraphAlignment() != null ? getParagraphAlignment().name() + "," : "");
229 			if (sb.length() > 0) {
230 				sb.deleteCharAt(sb.length() - 1);
231 			}
232 			return sb.toString();
233 		}
234 
235 	}
236 
237 }