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
18 private List<String> labels = new ArrayList<String>();
19 private Map<String, String> groups = new HashMap<String, String>();
20 private Map<String, Integer> gids = new HashMap<String, Integer>();
21 private boolean groupEnabled = true;
27 public LabelMap(String[] labels){
29 for(String label: labels){
34 public boolean isAvailableLabel(int index){
35 return index >= 0 && index < labels.size();
38 public void setGroupEnabled(boolean flag){
39 this.groupEnabled = flag;
42 public boolean isGroupEnabled(){
43 return groupEnabled && getGroupCount() < GeometoryType.getMaxGroupCount();
46 public void addLabel(String label){
50 public String getLabel(int index){
51 return labels.get(index);
54 public void setGroup(String label, String groupLabel){
55 groups.put(label, groupLabel);
56 if(gids.get(groupLabel) == null){
57 gids.put(groupLabel, gids.size());
61 public String getGroup(String label){
62 String group = groups.get(label);
69 public int getGroupIdFromElementName(String label){
70 return getGroupId(groups.get(label));
73 public int getGroupId(String groupLabel){
74 Integer i = new Integer(0);
76 i = gids.get(groupLabel);
84 public int getGroupCount(){
88 public String[] getGroupNames(){
89 String[] names = new String[gids.size()];
91 for(String name: gids.keySet()){
99 public synchronized Map<String, Integer> getGroupElementCounts(){
100 Map<String, Integer> map = new HashMap<String, Integer>();
102 for(Map.Entry<String, String> entry: groups.entrySet()){
103 Integer i = map.get(entry.getValue());
107 map.put(entry.getValue(), i + 1);
109 return Collections.unmodifiableMap(map);
112 public synchronized int getGroupElementCount(String group){
114 for(Map.Entry<String, String> entry: groups.entrySet()){
115 if(group.equals(entry.getValue())){
122 public synchronized String[] getGroupElements(String group){
123 List<String> elements = new ArrayList<String>();
124 for(Map.Entry<String, String> entry: groups.entrySet()){
125 if(group.equals(entry.getValue())){
126 elements.add(entry.getKey());
129 return elements.toArray(new String[elements.size()]);