aboutsummaryrefslogtreecommitdiff
path: root/src/uk/org/ury/show/ShowChannel.java
blob: 8448e0f3d2da1ab0d2f5e8d489410c0a9c3d02cb (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
package uk.org.ury.show;

import java.util.ArrayList;
import java.util.List;

import javax.swing.AbstractListModel;

import uk.org.ury.show.item.ShowItem;


/**
 * A channel of ShowItems in a show.
 * 
 * @author  Matt Windsor
 */

public class ShowChannel extends AbstractListModel
{
  /**
   * 
   */
  private static final long serialVersionUID = -4651104185166068150L;
  
  /* Items enqueued in channel. */
  private List<ShowItem> items;
  
  
  /**
   * Construct a new, empty channel.
   */
  
  public
  ShowChannel ()
  {
    items = new ArrayList<ShowItem> ();
  }
  
  
  /**
   * Add a new item to the channel.
   * 
   * @param index  The position at which to add the item.
   *               
   * @param item   The new item to add.
   * 
   * @throws       IllegalArgumentException if the item is 
   *               null, the index is negative or the index 
   *               is out of bounds.
   */
  
  public void
  add (int index, ShowItem item)
  {
    if (item == null)
      throw new IllegalArgumentException ("Item is null.");
    
    if (index < 0 || index >= items.size ())
      throw new IllegalArgumentException ("Index " + index + 
                                          " out of bounds.");
    
    items.add (index, item);
    fireIntervalAdded (this, index, index);
  }
  
  
  /**
   * Add a new item to the end of the channel.
   * 
   * @param item  The new item to add.
   */
  
  public void
  add (ShowItem item)
  {
    if (item == null)
      throw new IllegalArgumentException ("Item is null.");
    
    items.add (item);
    fireIntervalAdded (this, items.size () - 1, items.size () - 1);
  }
  
  
  /**
   * Retrieve an item from the channel.
   * 
   * @param index  The index of the item to retrieve from the channel.
   * 
   * @return       the item at the given index in the list.
   * 
   * @throws       IllegalArgumentException if the index is negative
   *               or overflowing.
   */
  
  public ShowItem
  get (int index)
  {
    if (index < 0 || index >= items.size ())
      throw new IllegalArgumentException ("Index " + index + 
                                          " out of bounds.");
    
    return items.get (index);
  }

  
  /**
   * List model retrieval wrapper for get.
   * 
   * @param index  The index of the item to retrieve from the channel.
   * 
   * @return       the item at the given index in the list.
   */

  @Override
  public Object
  getElementAt (int index)
  {
    return get (index);
  }


  /**
   * @return the size of the list.
   */
  
  @Override
  public int
  getSize ()
  {
    return items.size ();
  }
}