1: //..+....1....+....2....+....3....+....4....+....5....+....6....+....7....+....8
2: /*
3: * Copyright (c) 2010-2011, KOTSUBU-chan and/or its affiliates. All rights reserved.
4: * @version 1.0
5: */
6: package cherry;
7:
8: import java.awt.*;
9: import java.util.*;
10:
11: // ----------------------------------------
12: public class ExTreeMap {
13:
14: private static Map createMap() {
15: Map map = new TreeMap();
16: // map.put("black", Color.black);
17: map.put("blue", Color.blue);
18: map.put("cyan", Color.cyan);
19: // map.put("darkGray", Color.darkGray);
20: // map.put("gray", Color.gray);
21: map.put("green", Color.green);
22: // map.put("lightGray", Color.lightGray);
23: map.put("magenta", Color.magenta);
24: map.put("orange", Color.orange);
25: map.put("pink", Color.pink);
26: map.put("red", Color.red);
27: map.put("white", Color.white);
28: map.put("yellow", Color.yellow);
29: return map;
30: }
31:
32: static void ex_keySet(String title, Dimension d) {
33: TextView view = new TextView(title, d);
34:
35: for (Object item: createMap().keySet()) {
36: view.println(""+item);
37: }
38: view.setVisible(true);
39: }
40:
41: static void ex_values(String title, Dimension d) {
42: TextView view = new TextView(title, d);
43:
44: for (Object item: createMap().values()) {
45: view.println(""+item);
46: }
47: view.setVisible(true);
48: }
49:
50: static void ex_entrySet(String title, Dimension d) {
51: TextView view = new TextView(title, d);
52:
53: for (Map.Entry item: createMap().entrySet()) {
54: view.println(""+item);
55: }
56: view.setVisible(true);
57: }
58:
59: static void ex_namedColor(String title, Dimension d) {
60: TextView view = new TextView(title, d);
61:
62: for (Map.Entry item: createMap().entrySet()) {
63: view.println(displayString(item));
64: }
65: view.setVisible(true);
66: }
67:
68: // ----------------------------------------
69: private static String displayString(Map.Entry item) {
70: Color color = (Color) item.getValue();
71: return String.format("%s(%d,%d,%d)",
72: item.getKey(),
73: color.getRed(),
74: color.getGreen(),
75: color.getBlue());
76: }
77:
78: // ----------------------------------------
79: static void tips() {
80: ex_keySet(
81: "map.keySet()", new Dimension(200, 200));
82: ex_values(
83: "map.values()", new Dimension(250, 200));
84: ex_entrySet(
85: "map.entrySet()", new Dimension(300, 200));
86: ex_namedColor(
87: "name(red,green,blue)", new Dimension(220, 200));
88: }
89:
90: // ----------------------------------------
91: ExTreeMap() {}
92: static String version = new ExTreeMap()
93: .getClass().getName()+": #1.0.05";
94: }
95:
96: // ========================================