1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.adapters;
21
22 import java.util.Map;
23
24 import com.cosylab.gui.displayers.DataConsumer;
25 import com.cosylab.gui.displayers.DataSourceSupport;
26 import com.cosylab.gui.displayers.DataState;
27
28
29
30
31
32
33
34
35
36
37
38 public abstract class DataConsumerDispatcher extends DataSourceSupport
39 implements DataConsumer
40 {
41 protected String name = "DataConsumerDisplatcher";
42
43
44
45
46
47
48
49
50
51 public DataConsumerDispatcher(Class[] supportedTypes)
52 {
53 super(supportedTypes);
54 }
55
56
57
58
59 public DataConsumer getDefaultDataConsumer()
60 {
61 return this;
62 }
63
64
65
66
67 public String getName()
68 {
69 return name;
70 }
71
72
73
74
75 public String[] getSupportedCharacteristics()
76 {
77 return extractSupportedCharacteristics();
78 }
79
80
81
82
83 public Class[] getSupportedConsumerTypes()
84 {
85 return getAcceptableConsumerTypes();
86 }
87
88 public DataConsumer getDataConsumer(Class type) {
89 if (type==null) {
90 throw new NullPointerException("type");
91 }
92 if (type.isAssignableFrom(getClass())) {
93 return this;
94 }
95 return null;
96 }
97
98 public void updateDataState(DataState state) {
99 DataConsumer[] delegates = getConsumers();
100
101 for (int i = 0; i < delegates.length; i++) {
102 try {
103 delegates[i].updateDataState(state);
104 } catch (Exception e) {
105 e.printStackTrace();
106 }
107 }
108 }
109
110 public void setCharacteristics(Map characteristics) {
111 DataConsumer[] delegates = getConsumers();
112
113 for (int i = 0; i < delegates.length; i++) {
114 try {
115 delegates[i].setCharacteristics(characteristics);
116 } catch (Exception e) {
117 e.printStackTrace();
118 }
119 }
120 }
121
122 }
123
124