1 package jp.sourceforge.stigmata.ui.swing.mds;
6 import java.util.ArrayList;
7 import java.util.Collections;
8 import java.util.HashMap;
12 import jp.sourceforge.talisman.mds.ui.swing.GeometoryType;
15 * @author Haruaki TAMADA
19 private List<String> labels = new ArrayList<String>();
20 private Map<String, String> groups = new HashMap<String, String>();
21 private Map<String, Integer> gids = new HashMap<String, Integer>();
22 private boolean groupEnabled = true;
28 public LabelMap(String[] labels){
30 for(String label: labels){
35 public boolean isAvailableLabel(int index){
36 return index >= 0 && index < labels.size();
39 public void setGroupEnabled(boolean flag){
40 this.groupEnabled = flag;
43 public boolean isGroupEnabled(){
44 return groupEnabled && getGroupCount() < GeometoryType.getMaxGroupCount();
47 public void addLabel(String label){
51 public String getLabel(int index){
52 return labels.get(index);
55 public void setGroup(String label, String groupLabel){
56 groups.put(label, groupLabel);
57 if(gids.get(groupLabel) == null){
58 gids.put(groupLabel, gids.size());
62 public String getGroup(String label){
63 String group = groups.get(label);
70 public int getGroupIdFromElementName(String label){
71 return getGroupId(groups.get(label));
74 public int getGroupId(String groupLabel){
75 Integer i = new Integer(0);
77 i = gids.get(groupLabel);
85 public int getGroupCount(){
89 public String[] getGroupNames(){
90 String[] names = new String[gids.size()];
92 for(String name: gids.keySet()){
100 public synchronized Map<String, Integer> getGroupElementCounts(){
101 Map<String, Integer> map = new HashMap<String, Integer>();
103 for(Map.Entry<String, String> entry: groups.entrySet()){
104 Integer i = map.get(entry.getValue());
108 map.put(entry.getValue(), i + 1);
110 return Collections.unmodifiableMap(map);
113 public synchronized int getGroupElementCount(String group){
115 for(Map.Entry<String, String> entry: groups.entrySet()){
116 if(group.equals(entry.getValue())){
123 public synchronized String[] getGroupElements(String group){
124 List<String> elements = new ArrayList<String>();
125 for(Map.Entry<String, String> entry: groups.entrySet()){
126 if(group.equals(entry.getValue())){
127 elements.add(entry.getKey());
130 return elements.toArray(new String[elements.size()]);