Gridarta Editor
MapParameterComboBoxModel.java
Go to the documentation of this file.
1 /*
2  * Gridarta MMORPG map editor for Crossfire, Daimonin and similar games.
3  * Copyright (C) 2000-2015 The Gridarta Developers.
4  *
5  * This program 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 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program 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 along
16  * with this program; if not, write to the Free Software Foundation, Inc.,
17  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18  */
19 
20 package net.sf.gridarta.gui.dialog.plugin.parameter.map;
21 
22 import java.util.List;
23 import javax.swing.DefaultComboBoxModel;
32 import org.jetbrains.annotations.NotNull;
33 import org.jetbrains.annotations.Nullable;
34 
35 public class MapParameterComboBoxModel<G extends GameObject<G, A, R>, A extends MapArchObject<A>, R extends Archetype<G, A, R>> extends DefaultComboBoxModel<MapControl<G, A, R>> {
36 
37  @NotNull
39 
40  @Override
41  public boolean isPickmap() {
42  throw new AssertionError();
43  }
44 
45  @NotNull
46  @Override
47  public MapModel<G, A, R> getMapModel() {
48  throw new AssertionError();
49  }
50 
51  @Override
52  public void addMapControlListener(@NotNull final MapControlListener<G, A, R> listener) {
53  throw new AssertionError();
54  }
55 
56  @Override
57  public void removeMapControlListener(@NotNull final MapControlListener<G, A, R> listener) {
58  throw new AssertionError();
59  }
60 
61  @Override
62  public void save() {
63  throw new AssertionError();
64  }
65 
66  @Override
67  public void saveAs(@NotNull final MapFile mapFile) {
68  throw new AssertionError();
69  }
70 
71  @Override
72  public void acquire() {
73  throw new AssertionError();
74  }
75 
76  @Override
77  public void release() {
78  throw new AssertionError();
79  }
80 
81  @Override
82  public int getUseCounter() {
83  throw new AssertionError();
84  }
85 
86  };
87 
88  @Nullable
89  private Object selected;
90 
91  private static final long serialVersionUID = 1L;
92 
96  @NotNull
98 
103  public MapParameterComboBoxModel(@NotNull final MapManager<G, A, R> mapManager) {
104  this.mapManager = mapManager;
105  }
106 
107  @NotNull
108  @Override
109  public MapControl<G, A, R> getElementAt(final int index) {
110  if (index == 0) {
111  return currentMap;
112  }
113 
114  return mapManager.getOpenedMaps().get(index - 1);
115  }
116 
117  @Override
118  public int getIndexOf(@NotNull final Object anObject) {
119  final List<MapControl<G, A, R>> maps = mapManager.getOpenedMaps();
120  if (anObject == currentMap) {
121  return 0;
122  }
123 
124  for (int i = 0; i < maps.size(); i++) {
125  if (maps.get(i) == anObject) {
126  return i + 1;
127  }
128  }
129 
130  return -1;
131  }
132 
133  @Nullable
134  @Override
135  public Object getSelectedItem() {
136  return selected;
137  }
138 
139  @Override
140  public int getSize() {
141  return mapManager.getOpenedMaps().size() + 1;
142  }
143 
144  @Override
145  public void setSelectedItem(@Nullable final Object anObject) {
146  selected = anObject;
147  }
148 
149 }
A MapModel reflects the data of a map.
Definition: MapModel.java:75
A MapManager manages all opened maps.
Definition: MapManager.java:37
Base package of all Gridarta classes.
Reflects a game object (object on a map).
Definition: GameObject.java:36
Interface for listeners listening on changes in MapControl instances.
GameObjects are the objects based on Archetypes found on maps.
Currently nothing more than a marker interface for unification.
Definition: MapControl.java:35
MapParameterComboBoxModel(@NotNull final MapManager< G, A, R > mapManager)
Creates a new instance.
List< MapControl< G, A, R > > getOpenedMaps()
Returns all opened maps.
The location of a map file with a map directory.
Definition: MapFile.java:31