~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to flamingo/src/main/java/org/pushingpixels/flamingo/api/ribbon/resize/CoreRibbonResizeSequencingPolicies.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Flamingo Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
10
 *  o Redistributions in binary form must reproduce the above copyright notice, 
 
11
 *    this list of conditions and the following disclaimer in the documentation 
 
12
 *    and/or other materials provided with the distribution. 
 
13
 *     
 
14
 *  o Neither the name of Flamingo Kirill Grouchnikov nor the names of 
 
15
 *    its contributors may be used to endorse or promote products derived 
 
16
 *    from this software without specific prior written permission. 
 
17
 *     
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 
19
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
20
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 
21
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 
22
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 
25
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 
27
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 
28
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
29
 */
 
30
package org.pushingpixels.flamingo.api.ribbon.resize;
 
31
 
 
32
import java.util.List;
 
33
 
 
34
import org.pushingpixels.flamingo.api.ribbon.AbstractRibbonBand;
 
35
import org.pushingpixels.flamingo.api.ribbon.RibbonTask;
 
36
 
 
37
/**
 
38
 * The core resize sequencing policies. Provides the following:
 
39
 * 
 
40
 * <ul>
 
41
 * <li>{@link RoundRobin} under which the ribbon bands are being collapsed in a
 
42
 * cyclic fashion, distributing the collapsed pixels between the different
 
43
 * bands.</li>
 
44
 * <li>{@link CollapseFromLast} under which the ribbon bands are being collapsed
 
45
 * from right to left.</li>
 
46
 * </ul>
 
47
 * 
 
48
 * @author Kirill Grouchnikov
 
49
 */
 
50
public class CoreRibbonResizeSequencingPolicies {
 
51
        /**
 
52
         * The round robin resize sequencing policy. Under this policy the ribbon
 
53
         * bands are being collapsed in a cyclic fashion, distributing the collapsed
 
54
         * pixels between the different bands.
 
55
         * 
 
56
         * @author Kirill Grouchnikov
 
57
         */
 
58
        public static class RoundRobin extends BaseRibbonBandResizeSequencingPolicy {
 
59
                /**
 
60
                 * The index of the next ribbon task for collapsing.
 
61
                 */
 
62
                int nextIndex;
 
63
 
 
64
                /**
 
65
                 * Creates a new round robin resize sequencing policy for the specified
 
66
                 * task.
 
67
                 * 
 
68
                 * @param ribbonTask
 
69
                 *            Ribbon task.
 
70
                 */
 
71
                public RoundRobin(RibbonTask ribbonTask) {
 
72
                        super(ribbonTask);
 
73
                }
 
74
 
 
75
                @Override
 
76
                public void reset() {
 
77
                        this.nextIndex = this.ribbonTask.getBandCount() - 1;
 
78
                }
 
79
 
 
80
                @Override
 
81
                public AbstractRibbonBand next() {
 
82
                        AbstractRibbonBand result = this.ribbonTask.getBand(this.nextIndex);
 
83
                        this.nextIndex--;
 
84
                        if (this.nextIndex < 0)
 
85
                                this.nextIndex = this.ribbonTask.getBandCount() - 1;
 
86
                        return result;
 
87
                }
 
88
        }
 
89
 
 
90
        /**
 
91
         * The collapse from last resize sequencing policy. Under this policy the
 
92
         * ribbon bands are being collapsed from right to left.
 
93
         * 
 
94
         * @author Kirill Grouchnikov
 
95
         */
 
96
        public static class CollapseFromLast extends
 
97
                        BaseRibbonBandResizeSequencingPolicy {
 
98
                /**
 
99
                 * The index of the next ribbon task for collapsing.
 
100
                 */
 
101
                int nextIndex;
 
102
 
 
103
                /**
 
104
                 * Creates a new collapse from last resize sequencing policy for the
 
105
                 * specified task.
 
106
                 * 
 
107
                 * @param ribbonTask
 
108
                 *            Ribbon task.
 
109
                 */
 
110
                public CollapseFromLast(RibbonTask ribbonTask) {
 
111
                        super(ribbonTask);
 
112
                }
 
113
 
 
114
                @Override
 
115
                public void reset() {
 
116
                        this.nextIndex = this.ribbonTask.getBandCount() - 1;
 
117
                }
 
118
 
 
119
                @Override
 
120
                public AbstractRibbonBand next() {
 
121
                        AbstractRibbonBand result = this.ribbonTask.getBand(this.nextIndex);
 
122
 
 
123
                        // check whether the current resize policy on the returned ribbon
 
124
                        // band is the last
 
125
                        List<RibbonBandResizePolicy> resizePolicies = result
 
126
                                        .getResizePolicies();
 
127
                        if (result.getCurrentResizePolicy() == resizePolicies
 
128
                                        .get(resizePolicies.size() - 1)) {
 
129
                                this.nextIndex--;
 
130
                                if (this.nextIndex < 0)
 
131
                                        this.nextIndex = 0;
 
132
                        }
 
133
                        return result;
 
134
                }
 
135
        }
 
136
}