KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inzyme > jmds > DSCrossBar


1 package com.inzyme.jmds;
2
3 import java.util.NoSuchElementException JavaDoc;
4
5 /**
6  * Provides an interface to controlling a DirectShow Crossbar filter.
7  *
8  * @author Mike Schrag
9  */

10 public class DSCrossBar {
11     private DSDataSource myDataSource;
12     private DSInputCrossBarPin[] myInputPins;
13     private DSOutputCrossBarPin[] myOutputPins;
14     
15     /**
16      * Constructs a new DSCrossBar.
17      *
18      * @param _dataSource the parent DataSource
19      */

20     public DSCrossBar(DSDataSource _dataSource) {
21         myDataSource = _dataSource;
22     }
23     
24     /**
25      * Returns the set of input pins for this CrossBar.
26      *
27      * @return the set of input pins for this CrossBar
28      */

29     public DSInputCrossBarPin[] getInputPins() {
30         if (myInputPins == null) {
31             fillInCrossBarPins();
32         }
33         return myInputPins;
34     }
35     
36     /**
37      * Returns the set of output pins for this CrossBar.
38      *
39      * @return the set of output pins for this CrossBar
40      */

41     public DSOutputCrossBarPin[] getOutputPins() {
42         if (myOutputPins == null) {
43             fillInCrossBarPins();
44         }
45         return myOutputPins;
46     }
47     
48     /**
49      * Routes the specified output pin to the specified input pin. Currently
50      * this will not change the route of the related pin automatically.
51      *
52      * @param _outputPin the output pin to route from
53      * @param _inputPin the input pin to route to
54      */

55     public void route(DSOutputCrossBarPin _outputPin, DSInputCrossBarPin _inputPin) {
56         route0(_outputPin.getPinIndex(), _inputPin.getPinIndex());
57
58         // force a reload now that we've changed things (this could clearly be optimized)
59
myInputPins = null;
60         myOutputPins = null;
61     }
62     
63     /**
64      * Returns the input pin that has the given physical connector type.
65      *
66      * @param _physicalType the physical connector type to retrieve (one of DSPhysicalConnectorType.PhysConn_xxx)
67      * @return the matching input pin (or null if there is no match)
68      */

69     public DSInputCrossBarPin getInputPinWithPhysicalType(int _physicalType) {
70         DSInputCrossBarPin matchingInputPin = null;
71         DSInputCrossBarPin[] inputPins = getInputPins();
72         for (int i = 0; matchingInputPin == null && i < inputPins.length; i ++) {
73             if (inputPins[i].getPhysicalType() == _physicalType) {
74                 matchingInputPin = inputPins[i];
75             }
76         }
77         
78         if (matchingInputPin == null) {
79             throw new NoSuchElementException JavaDoc("There is no input pin with the type " + DSPhysicalConnectorType.getPhysicalTypeName(_physicalType));
80         }
81         
82         return matchingInputPin;
83     }
84     
85     /**
86      * Returns the output pin that has the given physical connector type.
87      *
88      * @param _physicalType the physical connector type to retrieve (one of DSPhysicalConnectorType.PhysConn_xxx)
89      * @return the matching output pin (or null if there is no match)
90      */

91     public DSOutputCrossBarPin getOutputPinWithPhysicalType(int _physicalType) {
92         DSOutputCrossBarPin matchingOutputPin = null;
93         DSOutputCrossBarPin[] outputPins = getOutputPins();
94         for (int i = 0; matchingOutputPin == null && i < outputPins.length; i ++) {
95             if (outputPins[i].getPhysicalType() == _physicalType) {
96                 matchingOutputPin = outputPins[i];
97             }
98         }
99         
100         if (matchingOutputPin == null) {
101             throw new NoSuchElementException JavaDoc("There is no output pin with the type " + DSPhysicalConnectorType.getPhysicalTypeName(_physicalType));
102         }
103         
104         return matchingOutputPin;
105     }
106     
107     /**
108      * Returns the input pin at the given index.
109      *
110      * @param _index the index of the input pin to retrieve
111      * @return the input pin at the given index
112      */

113     public DSInputCrossBarPin getInputPinAt(int _index) {
114         DSInputCrossBarPin pin;
115         if (_index == -1) {
116             pin = null;
117         }
118         else {
119             pin = getInputPins()[_index];
120         }
121         return pin;
122     }
123     
124     /**
125      * Returns the output pin at the given index.
126      *
127      * @param _index the index of the output pin to retrieve
128      * @return the output pin at the given index
129      */

130     public DSOutputCrossBarPin getOutputPinAt(int _index) {
131         DSOutputCrossBarPin pin;
132         if (_index == -1) {
133             pin = null;
134         }
135         else {
136             pin = getOutputPins()[_index];
137         }
138         return pin;
139     }
140     
141     private native void route0(int _outputPinIndex, int _inputPinIndex);
142     
143     private native void fillInCrossBarPins();
144 }
145
Popular Tags