OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 94 | Details | Compare with Previous | Last modification | View Log | RSS feed

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