OpenConcerto

Dépôt officiel du code source de l'ERP OpenConcerto
sonarqube

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 94 Rev 180
1
/*
1
/*
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
2
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
3
 * 
3
 * 
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
4
 * Copyright 2011 OpenConcerto, by ILM Informatique. All rights reserved.
5
 * 
5
 * 
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
6
 * The contents of this file are subject to the terms of the GNU General Public License Version 3
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
7
 * only ("GPL"). You may not use this file except in compliance with the License. You can obtain a
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
8
 * copy of the License at http://www.gnu.org/licenses/gpl-3.0.html See the License for the specific
9
 * language governing permissions and limitations under the License.
9
 * language governing permissions and limitations under the License.
10
 * 
10
 * 
11
 * When distributing the software, include this License Header Notice in each file.
11
 * When distributing the software, include this License Header Notice in each file.
12
 */
12
 */
13
 
13
 
14
 package org.openconcerto.ui.group;
14
 package org.openconcerto.ui.group;
15
 
15
 
16
import net.jcip.annotations.Immutable;
16
import net.jcip.annotations.Immutable;
17
 
17
 
18
@Immutable
18
@Immutable
19
public class LayoutHints {
19
public class LayoutHints {
20
    private final boolean visible;
20
    private boolean visible;
21
    private final boolean largeWidth;
21
    private final boolean largeWidth;
22
    private final boolean largeHeight;
22
    private final boolean largeHeight;
23
    private boolean foldable = false;
23
    private boolean foldable = false;
24
 
24
 
25
    private final boolean showLabel;
25
    private final boolean showLabel;
26
    // true if the layouted element (group or label+editor) is visually separated from the others
26
    // true if the layouted element (group or label+editor) is visually separated from the others
27
    // elements
27
    // elements
28
    private final boolean separated;
28
    private final boolean separated;
29
    private final boolean fillWidth;
29
    private final boolean fillWidth;
30
    private final boolean fillHeight;
30
    private final boolean fillHeight;
31
    // true if label and editor are separated
31
    // true if label and editor are separated
32
    private final boolean split;
32
    private final boolean split;
33
 
33
 
34
    public static final LayoutHints DEFAULT_FIELD_HINTS = new LayoutHints(false, false, true, false, false, false);
34
    public static final LayoutHints DEFAULT_FIELD_HINTS = new LayoutHints(false, false, true, false, false, false);
35
    public static final LayoutHints DEFAULT_LARGE_FIELD_HINTS = new LayoutHints(false, false, true, false, true, false);
35
    public static final LayoutHints DEFAULT_LARGE_FIELD_HINTS = new LayoutHints(false, false, true, false, true, false);
36
    public static final LayoutHints DEFAULT_VERY_LARGE_FIELD_HINTS = new LayoutHints(true, false, true, false, false, false);
36
    public static final LayoutHints DEFAULT_VERY_LARGE_FIELD_HINTS = new LayoutHints(true, false, true, false, false, false);
37
    public static final LayoutHints DEFAULT_VERY_LARGE_TEXT_HINTS = new LayoutHints(true, false, true, false, true, false, true);
37
    public static final LayoutHints DEFAULT_VERY_LARGE_TEXT_HINTS = new LayoutHints(true, false, true, false, true, false, true);
38
    public static final LayoutHints DEFAULT_LIST_HINTS = new LayoutHints(true, true, false, true, true, true);
38
    public static final LayoutHints DEFAULT_LIST_HINTS = new LayoutHints(true, true, false, true, true, true);
39
    public static final LayoutHints DEFAULT_GROUP_HINTS = new LayoutHints(true, false, false, false, true, true);
39
    public static final LayoutHints DEFAULT_GROUP_HINTS = new LayoutHints(true, false, false, false, true, true);
40
    public static final LayoutHints DEFAULT_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, true, true, true, true);
40
    public static final LayoutHints DEFAULT_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, true, true, true, true);
41
    public static final LayoutHints DEFAULT_NOLABEL_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, false, true, true, true);
41
    public static final LayoutHints DEFAULT_NOLABEL_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, false, true, true, true);
-
 
42
    public static final LayoutHints DEFAULT_SEPARATED_VERY_LARGE_HINTS = new LayoutHints(false, false, true, true, true, false, false, true);
42
 
43
 
43
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel) {
44
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel) {
44
        this(largeWidth, largeHeight, showLabel, false, false, false);
45
        this(largeWidth, largeHeight, showLabel, false, false, false);
45
    }
46
    }
46
 
47
 
47
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight) {
48
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight) {
48
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, false);
49
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, false);
49
    }
50
    }
50
 
51
 
51
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split) {
52
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split) {
52
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, split, true);
53
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, split, true);
53
    }
54
    }
54
 
55
 
55
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split, boolean visible) {
56
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split, boolean visible) {
56
        this.largeWidth = largeWidth;
57
        this.largeWidth = largeWidth;
57
        this.largeHeight = largeHeight;
58
        this.largeHeight = largeHeight;
58
        this.showLabel = showLabel;
59
        this.showLabel = showLabel;
59
        this.separated = separated;
60
        this.separated = separated;
60
        this.fillWidth = fillWidth;
61
        this.fillWidth = fillWidth;
61
        this.fillHeight = fillHeight;
62
        this.fillHeight = fillHeight;
62
        this.split = split;
63
        this.split = split;
63
        this.visible = visible;
64
        this.visible = visible;
64
    }
65
    }
65
 
66
 
66
    public LayoutHints(LayoutHints localHint) {
67
    public LayoutHints(LayoutHints localHint) {
67
        this.largeWidth = localHint.largeWidth;
68
        this.largeWidth = localHint.largeWidth;
68
        this.largeHeight = localHint.largeHeight;
69
        this.largeHeight = localHint.largeHeight;
69
        this.showLabel = localHint.showLabel;
70
        this.showLabel = localHint.showLabel;
70
        this.separated = localHint.separated;
71
        this.separated = localHint.separated;
71
        this.fillWidth = localHint.fillWidth;
72
        this.fillWidth = localHint.fillWidth;
72
        this.fillHeight = localHint.fillHeight;
73
        this.fillHeight = localHint.fillHeight;
73
        this.split = localHint.split;
74
        this.split = localHint.split;
74
        this.visible = localHint.visible;
75
        this.visible = localHint.visible;
75
        this.foldable = localHint.foldable;
76
        this.foldable = localHint.foldable;
76
    }
77
    }
77
 
78
 
78
    public final LayoutHintsBuilder getBuilder() {
79
    public final LayoutHintsBuilder getBuilder() {
79
        return new LayoutHintsBuilder(this.largeWidth, this.largeHeight, this.showLabel).setFillHeight(this.fillHeight).setFillWidth(this.fillWidth).setSeparated(this.separated).setSplit(this.split)
80
        return new LayoutHintsBuilder(this.largeWidth, this.largeHeight, this.showLabel).setFillHeight(this.fillHeight).setFillWidth(this.fillWidth).setSeparated(this.separated).setSplit(this.split)
80
                .setVisible(this.visible);
81
                .setVisible(this.visible);
81
    }
82
    }
82
 
83
 
83
    public boolean isFoldable() {
84
    public boolean isFoldable() {
84
        return this.foldable;
85
        return this.foldable;
85
    }
86
    }
86
    
87
 
87
    public void setFoldable(final boolean foldable) {
88
    public void setFoldable(final boolean foldable) {
88
        this.foldable = foldable;
89
        this.foldable = foldable;
89
    }
90
    }
90
    
91
 
91
    public boolean largeWidth() {
92
    public boolean largeWidth() {
92
        return this.largeWidth;
93
        return this.largeWidth;
93
    }
94
    }
94
 
95
 
95
    public boolean largeHeight() {
96
    public boolean largeHeight() {
96
        return this.largeHeight;
97
        return this.largeHeight;
97
    }
98
    }
98
 
99
 
99
    public boolean showLabel() {
100
    public boolean showLabel() {
100
        return this.showLabel;
101
        return this.showLabel;
101
    }
102
    }
102
 
103
 
103
    public boolean isSeparated() {
104
    public boolean isSeparated() {
104
        return this.separated;
105
        return this.separated;
105
    }
106
    }
106
 
107
 
107
    public boolean fillWidth() {
108
    public boolean fillWidth() {
108
        return this.fillWidth;
109
        return this.fillWidth;
109
    }
110
    }
110
 
111
 
111
    public boolean fillHeight() {
112
    public boolean fillHeight() {
112
        return this.fillHeight;
113
        return this.fillHeight;
113
    }
114
    }
114
 
115
 
115
    public boolean isSplit() {
116
    public boolean isSplit() {
116
        return this.split;
117
        return this.split;
117
    }
118
    }
118
 
119
 
119
    @Override
120
    @Override
120
    public String toString() {
121
    public String toString() {
121
        String r = "";
122
        String r = "";
122
        if (this.largeHeight && this.largeWidth) {
123
        if (this.largeHeight && this.largeWidth) {
123
            r += "LargeW&H";
124
            r += "LargeW&H";
124
        } else {
125
        } else {
125
            if (this.largeHeight) {
126
            if (this.largeHeight) {
126
                r += "LargeH";
127
                r += "LargeH";
127
            }
128
            }
128
            if (this.largeWidth) {
129
            if (this.largeWidth) {
129
                r += "LargeW";
130
                r += "LargeW";
130
            }
131
            }
131
        }
132
        }
132
        if (this.separated) {
133
        if (this.separated) {
133
            r += " Separated";
134
            r += " Separated";
134
        }
135
        }
135
        if (this.showLabel) {
136
        if (this.showLabel) {
136
            r += " StdLabel";
137
            r += " StdLabel";
137
        } else {
138
        } else {
138
            r += " NoLabel";
139
            r += " NoLabel";
139
        }
140
        }
140
        if (this.split) {
141
        if (this.split) {
141
            r += " (label and editor splitted)";
142
            r += " (label and editor splitted)";
142
        }
143
        }
143
        if (this.fillHeight && this.fillWidth) {
144
        if (this.fillHeight && this.fillWidth) {
144
            r += " FillW&H";
145
            r += " FillW&H";
145
        } else {
146
        } else {
146
            if (this.fillHeight) {
147
            if (this.fillHeight) {
147
                r += " FillH";
148
                r += " FillH";
148
            }
149
            }
149
            if (this.fillWidth) {
150
            if (this.fillWidth) {
150
                r += " FillW";
151
                r += " FillW";
151
            }
152
            }
152
        }
153
        }
153
        if (!this.isVisible()) {
154
        if (!this.isVisible()) {
154
            r += " (hidden)";
155
            r += " (hidden)";
155
        }
156
        }
156
        return r;
157
        return r;
157
    }
158
    }
158
 
159
 
159
    public boolean isVisible() {
160
    public boolean isVisible() {
160
        return visible;
161
        return this.visible;
-
 
162
    }
-
 
163
 
-
 
164
    public void setVisible(boolean b) {
-
 
165
        this.visible = b;
161
    }
166
    }
162
 
167
 
163
    @Override
168
    @Override
164
    public int hashCode() {
169
    public int hashCode() {
165
        final int prime = 31;
170
        final int prime = 31;
166
        int result = 1;
171
        int result = 1;
167
        result = prime * result + (this.fillHeight ? 1231 : 1237);
172
        result = prime * result + (this.fillHeight ? 1231 : 1237);
168
        result = prime * result + (this.fillWidth ? 1231 : 1237);
173
        result = prime * result + (this.fillWidth ? 1231 : 1237);
169
        result = prime * result + (this.largeHeight ? 1231 : 1237);
174
        result = prime * result + (this.largeHeight ? 1231 : 1237);
170
        result = prime * result + (this.largeWidth ? 1231 : 1237);
175
        result = prime * result + (this.largeWidth ? 1231 : 1237);
171
        result = prime * result + (this.separated ? 1231 : 1237);
176
        result = prime * result + (this.separated ? 1231 : 1237);
172
        result = prime * result + (this.showLabel ? 1231 : 1237);
177
        result = prime * result + (this.showLabel ? 1231 : 1237);
173
        result = prime * result + (this.split ? 1231 : 1237);
178
        result = prime * result + (this.split ? 1231 : 1237);
174
        result = prime * result + (this.visible ? 1231 : 1237);
179
        result = prime * result + (this.visible ? 1231 : 1237);
175
        return result;
180
        return result;
176
    }
181
    }
177
 
182
 
178
    @Override
183
    @Override
179
    public boolean equals(Object obj) {
184
    public boolean equals(Object obj) {
180
        if (this == obj)
185
        if (this == obj)
181
            return true;
186
            return true;
182
        if (obj == null)
187
        if (obj == null)
183
            return false;
188
            return false;
184
        if (getClass() != obj.getClass())
189
        if (getClass() != obj.getClass())
185
            return false;
190
            return false;
186
        final LayoutHints other = (LayoutHints) obj;
191
        final LayoutHints other = (LayoutHints) obj;
187
        return this.fillHeight == other.fillHeight && this.fillWidth == other.fillWidth && this.largeHeight == other.largeHeight && this.largeWidth == other.largeWidth
192
        return this.fillHeight == other.fillHeight && this.fillWidth == other.fillWidth && this.largeHeight == other.largeHeight && this.largeWidth == other.largeWidth
188
                && this.separated == other.separated && this.showLabel == other.showLabel && this.split == other.split && this.visible == other.visible;
193
                && this.separated == other.separated && this.showLabel == other.showLabel && this.split == other.split && this.visible == other.visible;
189
    }
194
    }
-
 
195
 
190
}
196
}