OpenConcerto

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

svn://code.openconcerto.org/openconcerto

Rev

Rev 73 | Rev 94 | Go to most recent revision | 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 {
73 ilm 20
    private final boolean visible;
21
    private final boolean largeWidth;
22
    private final boolean largeHeight;
41 ilm 23
 
73 ilm 24
    private final boolean showLabel;
90 ilm 25
    // true if the layouted element (group or label+editor) is visually separated from the others
26
    // elements
73 ilm 27
    private final boolean separated;
28
    private final boolean fillWidth;
29
    private final boolean fillHeight;
30
    // true if label and editor are separated
31
    private final boolean split;
65 ilm 32
 
33
    public static final LayoutHints DEFAULT_FIELD_HINTS = new LayoutHints(false, false, true, false, false, false);
34
    public static final LayoutHints DEFAULT_LARGE_FIELD_HINTS = new LayoutHints(false, false, true, false, true, false);
35
    public static final LayoutHints DEFAULT_VERY_LARGE_FIELD_HINTS = new LayoutHints(true, false, true, false, false, false);
73 ilm 36
    public static final LayoutHints DEFAULT_VERY_LARGE_TEXT_HINTS = new LayoutHints(true, false, true, false, true, false, true);
65 ilm 37
    public static final LayoutHints DEFAULT_LIST_HINTS = new LayoutHints(true, true, false, true, true, true);
38
    public static final LayoutHints DEFAULT_GROUP_HINTS = new LayoutHints(true, false, false, false, true, true);
39
    public static final LayoutHints DEFAULT_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, true, true, true, true);
67 ilm 40
    public static final LayoutHints DEFAULT_NOLABEL_SEPARATED_GROUP_HINTS = new LayoutHints(true, false, false, true, true, true);
41 ilm 41
 
73 ilm 42
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel) {
43
        this(largeWidth, largeHeight, showLabel, false, false, false);
44
    }
45
 
65 ilm 46
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight) {
73 ilm 47
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, false);
48
    }
49
 
50
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split) {
51
        this(largeWidth, largeHeight, showLabel, separated, fillWidth, fillHeight, split, true);
52
    }
53
 
54
    public LayoutHints(boolean largeWidth, boolean largeHeight, boolean showLabel, boolean separated, boolean fillWidth, boolean fillHeight, boolean split, boolean visible) {
65 ilm 55
        this.largeWidth = largeWidth;
56
        this.largeHeight = largeHeight;
41 ilm 57
        this.showLabel = showLabel;
58
        this.separated = separated;
65 ilm 59
        this.fillWidth = fillWidth;
60
        this.fillHeight = fillHeight;
73 ilm 61
        this.split = split;
62
        this.visible = visible;
41 ilm 63
    }
64
 
67 ilm 65
    public LayoutHints(LayoutHints localHint) {
66
        this.largeWidth = localHint.largeWidth;
67
        this.largeHeight = localHint.largeHeight;
68
        this.showLabel = localHint.showLabel;
69
        this.separated = localHint.separated;
70
        this.fillWidth = localHint.fillWidth;
71
        this.fillHeight = localHint.fillHeight;
73 ilm 72
        this.split = localHint.split;
73
        this.visible = localHint.visible;
67 ilm 74
    }
75
 
73 ilm 76
    public final LayoutHintsBuilder getBuilder() {
77
        return new LayoutHintsBuilder(this.largeWidth, this.largeHeight, this.showLabel).setFillHeight(this.fillHeight).setFillWidth(this.fillWidth).setSeparated(this.separated).setSplit(this.split)
78
                .setVisible(this.visible);
41 ilm 79
    }
80
 
73 ilm 81
    public boolean largeWidth() {
82
        return this.largeWidth;
67 ilm 83
    }
84
 
65 ilm 85
    public boolean largeHeight() {
73 ilm 86
        return this.largeHeight;
41 ilm 87
    }
88
 
89
    public boolean showLabel() {
73 ilm 90
        return this.showLabel;
41 ilm 91
    }
92
 
93
    public boolean isSeparated() {
73 ilm 94
        return this.separated;
41 ilm 95
    }
96
 
65 ilm 97
    public boolean fillWidth() {
73 ilm 98
        return this.fillWidth;
41 ilm 99
    }
100
 
65 ilm 101
    public boolean fillHeight() {
73 ilm 102
        return this.fillHeight;
65 ilm 103
    }
104
 
73 ilm 105
    public boolean isSplit() {
106
        return this.split;
67 ilm 107
    }
108
 
41 ilm 109
    @Override
110
    public String toString() {
111
        String r = "";
73 ilm 112
        if (this.largeHeight && this.largeWidth) {
65 ilm 113
            r += "LargeW&H";
41 ilm 114
        } else {
73 ilm 115
            if (this.largeHeight) {
65 ilm 116
                r += "LargeH";
41 ilm 117
            }
73 ilm 118
            if (this.largeWidth) {
65 ilm 119
                r += "LargeW";
41 ilm 120
            }
121
        }
73 ilm 122
        if (this.separated) {
123
            r += " Separated";
124
        }
125
        if (this.showLabel) {
126
            r += " StdLabel";
41 ilm 127
        } else {
73 ilm 128
            r += " NoLabel";
41 ilm 129
        }
73 ilm 130
        if (this.split) {
131
            r += " (label and editor splitted)";
132
        }
133
        if (this.fillHeight && this.fillWidth) {
65 ilm 134
            r += " FillW&H";
135
        } else {
73 ilm 136
            if (this.fillHeight) {
65 ilm 137
                r += " FillH";
138
            }
73 ilm 139
            if (this.fillWidth) {
65 ilm 140
                r += " FillW";
141
            }
41 ilm 142
        }
73 ilm 143
        if (!this.isVisible()) {
144
            r += " (hidden)";
145
        }
41 ilm 146
        return r;
147
    }
73 ilm 148
 
149
    public boolean isVisible() {
150
        return visible;
151
    }
152
 
153
    @Override
154
    public int hashCode() {
155
        final int prime = 31;
156
        int result = 1;
157
        result = prime * result + (this.fillHeight ? 1231 : 1237);
158
        result = prime * result + (this.fillWidth ? 1231 : 1237);
159
        result = prime * result + (this.largeHeight ? 1231 : 1237);
160
        result = prime * result + (this.largeWidth ? 1231 : 1237);
161
        result = prime * result + (this.separated ? 1231 : 1237);
162
        result = prime * result + (this.showLabel ? 1231 : 1237);
163
        result = prime * result + (this.split ? 1231 : 1237);
164
        result = prime * result + (this.visible ? 1231 : 1237);
165
        return result;
166
    }
167
 
168
    @Override
169
    public boolean equals(Object obj) {
170
        if (this == obj)
171
            return true;
172
        if (obj == null)
173
            return false;
174
        if (getClass() != obj.getClass())
175
            return false;
176
        final LayoutHints other = (LayoutHints) obj;
177
        return this.fillHeight == other.fillHeight && this.fillWidth == other.fillWidth && this.largeHeight == other.largeHeight && this.largeWidth == other.largeWidth
178
                && this.separated == other.separated && this.showLabel == other.showLabel && this.split == other.split && this.visible == other.visible;
179
    }
41 ilm 180
}