1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans.
5 *
6 * CosyBeans is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans. If not, see <http://www.gnu.org/licenses/>.
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 * <code>DataConsumerDispatcher</code> is support class for data consumer
31 * dispatcher implementators.
32 *
33 * @author <a href="mailto:igor.kriznar@cosylab.com">Igor Kriznar</a>
34 * @version $Id: DataConsumerDispatcher.java,v 1.7 2008-04-22 12:31:02 jbobnar Exp $
35 *
36 * @since Feb 14, 2004.
37 */
38 public abstract class DataConsumerDispatcher extends DataSourceSupport
39 implements DataConsumer
40 {
41 protected String name = "DataConsumerDisplatcher";
42
43 /**
44 * Constructs a new DataConsumerDispatcher with the given supported types.
45 *
46 * @param supportedTypes
47 *
48 * @throws IllegalArgumentException
49 * @see {@link DataSourceSupport#DataSourceSupport(Class[])}
50 */
51 public DataConsumerDispatcher(Class[] supportedTypes)
52 {
53 super(supportedTypes);
54 }
55
56 /* (non-Javadoc)
57 * @see com.cosylab.gui.displayers.DataConsumer#getDefaultDataConsumer()
58 */
59 public DataConsumer getDefaultDataConsumer()
60 {
61 return this;
62 }
63
64 /* (non-Javadoc)
65 * @see com.cosylab.gui.displayers.DataConsumer#getName()
66 */
67 public String getName()
68 {
69 return name;
70 }
71
72 /* (non-Javadoc)
73 * @see com.cosylab.gui.displayers.DataConsumer#getSupportedCharacteristics()
74 */
75 public String[] getSupportedCharacteristics()
76 {
77 return extractSupportedCharacteristics();
78 }
79
80 /* (non-Javadoc)
81 * @see com.cosylab.gui.displayers.DataConsumer#getSupportedConsumerTypes()
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 /* __oOo__ */