1 package jp.sourceforge.stigmata.ui.swing.mds;
3 import java.util.ArrayList;
4 import java.util.Collections;
5 import java.util.HashMap;
9 import jp.sourceforge.talisman.mds.ui.swing.GeometoryType;
12 * @author Haruaki TAMADA
15 private List<String> labels = new ArrayList<String>();
16 private Map<String, String> groups = new HashMap<String, String>();
17 private Map<String, Integer> gids = new HashMap<String, Integer>();
18 private boolean groupEnabled = true;
24 public LabelMap(String[] labels){
26 for(String label: labels){
31 public boolean isAvailableLabel(int index){
32 return index >= 0 && index < labels.size();
35 public void setGroupEnabled(boolean flag){
36 this.groupEnabled = flag;
39 public boolean isGroupEnabled(){
40 return groupEnabled && getGroupCount() < GeometoryType.getMaxGroupCount();
43 public void addLabel(String label){
47 public String getLabel(int index){
48 return labels.get(index);
51 public void setGroup(String label, String groupLabel){
52 groups.put(label, groupLabel);
53 if(gids.get(groupLabel) == null){
54 gids.put(groupLabel, gids.size());
58 public String getGroup(String label){
59 String group = groups.get(label);
66 public int getGroupIdFromElementName(String label){
67 return getGroupId(groups.get(label));
70 public int getGroupId(String groupLabel){
71 Integer i = new Integer(0);
73 i = gids.get(groupLabel);
81 public int getGroupCount(){
85 public String[] getGroupNames(){
86 String[] names = new String[gids.size()];
88 for(String name: gids.keySet()){
96 public synchronized Map<String, Integer> getGroupElementCounts(){
97 Map<String, Integer> map = new HashMap<String, Integer>();
99 for(Map.Entry<String, String> entry: groups.entrySet()){
100 Integer i = map.get(entry.getValue());
104 map.put(entry.getValue(), i + 1);
106 return Collections.unmodifiableMap(map);
109 public synchronized int getGroupElementCount(String group){
111 for(Map.Entry<String, String> entry: groups.entrySet()){
112 if(group.equals(entry.getValue())){
119 public synchronized String[] getGroupElements(String group){
120 List<String> elements = new ArrayList<String>();
121 for(Map.Entry<String, String> entry: groups.entrySet()){
122 if(group.equals(entry.getValue())){
123 elements.add(entry.getKey());
126 return elements.toArray(new String[elements.size()]);