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 org.openflexo.foundation.technologyadapter.TechnologyAdapter;
24  import org.openflexo.pamela.annotations.Getter;
25  import org.openflexo.pamela.annotations.ModelEntity;
26  import org.openflexo.pamela.annotations.PropertyIdentifier;
27  import org.openflexo.pamela.annotations.Setter;
28  
29  /**
30   * Named style of a text-based document (eg .docx, .odt, etc...)<br>
31   * 
32   * References a {@link FlexoParagraphStyle} and a {@link FlexoRunStyle}
33   * 
34   * @author sylvain
35   *
36   * @param <D>
37   *            type of {@link FlexoDocument} involving this concept
38   * @param <TA>
39   *            {@link TechnologyAdapter} of current implementation
40   */
41  @ModelEntity(isAbstract = true)
42  public interface NamedDocStyle<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>> extends FlexoDocStyle<D, TA> {
43  
44  	@PropertyIdentifier(type = String.class)
45  	public static final String NAME_KEY = "name";
46  	@PropertyIdentifier(type = String.class)
47  	public static final String STYLE_ID_KEY = "styleId";
48  	@PropertyIdentifier(type = Integer.class)
49  	public static final String LEVEL_KEY = "level";
50  	@PropertyIdentifier(type = FlexoParagraphStyle.class)
51  	public static final String PARAGRAPH_STYLE_KEY = "paragraphStyle";
52  	@PropertyIdentifier(type = FlexoRunStyle.class)
53  	public static final String RUN_STYLE_KEY = "runStyle";
54  
55  	/**
56  	 * Return name of the {@link FlexoDocStyle} in the {@link FlexoDocument}<br>
57  	 * 
58  	 * @return
59  	 */
60  	@Getter(value = NAME_KEY)
61  	public String getName();
62  
63  	@Setter(NAME_KEY)
64  	public void setName(String name);
65  
66  	/**
67  	 * Return identifier of the {@link FlexoDocStyle} in the {@link FlexoDocument}<br>
68  	 * 
69  	 * @return
70  	 */
71  	@Getter(value = STYLE_ID_KEY)
72  	public String getStyleId();
73  
74  	@Setter(STYLE_ID_KEY)
75  	public void setStyleId(String styleId);
76  
77  	/**
78  	 * Return level of this style, when trying to interpret the owner document as a structured document.<br>
79  	 * This level is computed from the list of structuring styles as defined in {@link FlexoDocument} (see #
80  	 * 
81  	 * If this style is not structuring (not present in document's structuring style), return null
82  	 * 
83  	 * @return
84  	 */
85  	@Getter(value = LEVEL_KEY)
86  	public Integer getLevel();
87  
88  	@Setter(LEVEL_KEY)
89  	public void setLevel(Integer level);
90  
91  	/**
92  	 * Return flag indicating if this style is levelled or not
93  	 * 
94  	 * @return
95  	 */
96  	public boolean isLevelled();
97  
98  	@Getter(PARAGRAPH_STYLE_KEY)
99  	public FlexoParagraphStyle<D, TA> getParagraphStyle();
100 
101 	@Setter(PARAGRAPH_STYLE_KEY)
102 	public void setParagraphStyle(FlexoParagraphStyle<D, TA> paragraph);
103 
104 	@Getter(RUN_STYLE_KEY)
105 	public FlexoRunStyle<D, TA> getRunStyle();
106 
107 	@Setter(RUN_STYLE_KEY)
108 	public void setRunStyle(FlexoRunStyle<D, TA> run);
109 
110 	public static abstract class NamedDocStyleImpl<D extends FlexoDocument<D, TA>, TA extends TechnologyAdapter<TA>>
111 			extends FlexoDocStyleImpl<D, TA> implements NamedDocStyle<D, TA> {
112 
113 		@Override
114 		public boolean isLevelled() {
115 			if (getFlexoDocument() != null) {
116 				return getFlexoDocument().getStructuringStyles().contains(this);
117 			}
118 			return false;
119 		}
120 
121 		@Override
122 		public Integer getLevel() {
123 			if (getFlexoDocument() != null) {
124 				return getFlexoDocument().getStructuringStyles().indexOf(this);
125 			}
126 			return null;
127 		}
128 
129 		@Override
130 		public void setLevel(Integer level) {
131 		}
132 	}
133 }