aboutsummaryrefslogtreecommitdiffstats
path: root/src/net/java/sip/communicator/impl/gui/main/call/FullScreenLayout.java
blob: c56a415c1814fa979f643726e2f535e2b56708cb (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
/*
 * Jitsi, the OpenSource Java VoIP and Instant Messaging client.
 *
 * Copyright @ 2015 Atlassian Pty Ltd
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package net.java.sip.communicator.impl.gui.main.call;

import java.awt.*;
import java.util.*;
import java.util.List;

/**
 * Implements a <tt>LayoutManager</tt> for the full-screen <tt>Call</tt>
 * display.
 *
 * @author Lyubomir Marinov
 */
public class FullScreenLayout
    implements LayoutManager
{
    public static final String CENTER = "CENTER";

    public static final String SOUTH = "SOUTH";

    private Component center;

    /**
     * The indicator which determines whether {@link #south} is to be laid out
     * on top of {@link #center} i.e. as an overlay.
     */
    private final boolean overlay;

    private Component south;

    /**
     * The vertical gap between the center and the south components.
     */
    private int yGap = 0;

    /**
     * Initializes a new <tt>FullScreenLayout</tt> instance.
     *
     * @param overlay <tt>true</tt> to lay out the <tt>Component</tt> at
     * {@link #SOUTH} on top of the <tt>Component</tt> at {@link #CENTER} i.e as
     * an overlay; otherwise, <tt>false</tt>
     * @oaram yGap the gap betwen the center and the south component
     */
    public FullScreenLayout(boolean overlay, int yGap)
    {
        this.overlay = overlay;
        this.yGap = yGap;
    }

    /**
     * Adds the given component to this layout.
     *
     * @param name the name of the constraint (CENTER or SOUTH)
     * @param comp the component to add to this layout
     */
    public void addLayoutComponent(String name, Component comp)
    {
        if (CENTER.equals(name))
            center = comp;
        else if (SOUTH.equals(name))
            south = comp;
    }

    /**
     * Gets a <tt>List</tt> of the <tt>Component</tt>s to be laid out by this
     * <tt>LayoutManager</tt> i.e. the non-<tt>null</tt> of {@link #center}
     * and {@link #south}.
     *
     * @return a <tt>List</tt> of the <tt>Component</tt>s to be laid out by this
     * <tt>LayoutManager</tt>
     */
    private List<Component> getLayoutComponents()
    {
        List<Component> layoutComponents = new ArrayList<Component>(2);

        if (center != null)
            layoutComponents.add(center);
        if (south != null)
            layoutComponents.add(south);
        return layoutComponents;
    }

    /**
     * Lays out the components added in the given parent container
     *
     * @param parent the parent container to lay out
     */
    public void layoutContainer(Container parent)
    {
        int southWidth;
        int southHeight;

        if (south == null)
        {
            southWidth = southHeight = 0;
        }
        else
        {
            Dimension southSize = south.getPreferredSize();

            southWidth = southSize.width;
            southHeight = southSize.height;
        }

        Dimension parentSize = parent.getSize();

        if (center != null)
        {
            /*
             * If the Component at the SOUTH is not to be shown as an overlay,
             * make room for it bellow the Component at the CENTER.
             */
            int yOffset = overlay ? 0 : southHeight + yGap;

            center.setBounds(
                    0,
                    0,
                    parentSize.width,
                    parentSize.height - yOffset);
        }
        if (south != null)
        {
            south.setBounds(
                    (parentSize.width - southWidth) / 2,
                    parentSize.height - southHeight,
                    southWidth,
                    southHeight);
        }
    }

    public Dimension minimumLayoutSize(Container parent)
    {
        List<Component> components = getLayoutComponents();
        Dimension size = new Dimension(0, 0);

        for (Component component : components)
        {
            Dimension componentSize = component.getMinimumSize();

            size.width = Math.max(size.width, componentSize.width);
            if (overlay)
                size.height = Math.max(size.height, componentSize.height);
            else
                size.height += componentSize.height;
        }
        return size;
    }

    public Dimension preferredLayoutSize(Container parent)
    {
        List<Component> components = getLayoutComponents();
        Dimension size = new Dimension(0, 0);

        for (Component component : components)
        {
            Dimension componentSize = component.getPreferredSize();

            size.width = Math.max(size.width, componentSize.width);
            if (overlay)
                size.height = Math.max(size.height, componentSize.height);
            else
                size.height += componentSize.height;
        }
        return size;
    }

    public void removeLayoutComponent(Component comp)
    {
        if (comp.equals(center))
            center = null;
        else if (comp.equals(south))
            south = null;
    }
}