View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.common.model.style;
19  
20  import java.util.ArrayList;
21  import java.util.List;
22  
23  import com.google.gwt.user.client.rpc.IsSerializable;
24  
25  /**
26   * Class to represent a list of palettes
27   */
28  public class PaletteList implements IsSerializable {
29  	/**
30  	 * A List of palettes.
31  	 */
32  	private List<Palette> _palettes;
33  	public PaletteList() {
34  		_palettes = new ArrayList<Palette>();
35  	}
36  	
37  	public void addPalette(Palette palette) {
38  		_palettes.add(palette);
39  	}
40  
41  	public void fromPaletteList(PaletteList paletteList) {
42  		_palettes.clear();
43  		_palettes.addAll(paletteList._palettes);
44  	}
45  
46  	public Palette newPalette() {
47  		Palette palette = new Palette();
48  		_palettes.add(palette);
49  		return palette;
50  	}
51  	
52  	public Palette clonePalette(int index) {
53  		Palette clone = new Palette(getPalette(index));
54  		_palettes.add(clone);
55  		return clone;
56  	}
57  	
58  	public void removePalette(int index) {
59  		_palettes.remove(index);
60  	}
61  	
62  	public Palette getPalette(int index) {
63  		return _palettes.get(index);
64  	}
65  	
66  	public int size() {
67  		return _palettes.size();
68  	}
69  	
70  	public void clear() {
71  		_palettes.clear();
72  	}
73  	
74  	@Override
75  	public boolean equals(Object obj) {
76  		if (obj instanceof PaletteList) {
77  			return _palettes.equals(((PaletteList)obj)._palettes);
78  		}
79  		return false;
80  	}
81  	
82  	@Override
83  	public int hashCode() {
84  		return _palettes.hashCode();
85  	}
86  	
87  	@Override
88  	public String toString() {
89  		StringBuffer buffer = new StringBuffer();
90  		buffer.append("PaletteList(");
91  		for (int i = 0, size = _palettes.size(); i < size; i++) {
92  			if (i > 0) {
93  				buffer.append(" ");
94  			}
95  			buffer.append(_palettes.get(i).toString());
96  		}
97  		buffer.append(")");
98  		return buffer.toString();
99  	}
100 
101 }