|
Matthias@224
|
1 |
/* |
|
Matthias@224
|
2 |
* Copyright (c) 2008-2011, Matthias Mann |
|
Matthias@224
|
3 |
* |
|
Matthias@224
|
4 |
* All rights reserved. |
|
Matthias@224
|
5 |
* |
|
Matthias@224
|
6 |
* Redistribution and use in source and binary forms, with or without |
|
Matthias@224
|
7 |
* modification, are permitted provided that the following conditions are met: |
|
Matthias@224
|
8 |
* |
|
Matthias@224
|
9 |
* * Redistributions of source code must retain the above copyright notice, |
|
Matthias@224
|
10 |
* this list of conditions and the following disclaimer. |
|
Matthias@224
|
11 |
* * Redistributions in binary form must reproduce the above copyright |
|
Matthias@224
|
12 |
* notice, this list of conditions and the following disclaimer in the |
|
Matthias@224
|
13 |
* documentation and/or other materials provided with the distribution. |
|
Matthias@224
|
14 |
* * Neither the name of Matthias Mann nor the names of its contributors may |
|
Matthias@224
|
15 |
* be used to endorse or promote products derived from this software |
|
Matthias@224
|
16 |
* without specific prior written permission. |
|
Matthias@224
|
17 |
* |
|
Matthias@224
|
18 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
|
Matthias@224
|
19 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
|
Matthias@224
|
20 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
|
Matthias@224
|
21 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR |
|
Matthias@224
|
22 |
* CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, |
|
Matthias@224
|
23 |
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, |
|
Matthias@224
|
24 |
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR |
|
Matthias@224
|
25 |
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF |
|
Matthias@224
|
26 |
* LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING |
|
Matthias@224
|
27 |
* NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
|
Matthias@224
|
28 |
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
|
Matthias@224
|
29 |
*/ |
|
Matthias@224
|
30 |
package nodes; |
|
Matthias@224
|
31 |
|
|
Matthias@224
|
32 |
import de.matthiasmann.twl.ResizableFrame; |
|
Matthias@224
|
33 |
import java.util.ArrayList; |
|
Matthias@224
|
34 |
|
|
Matthias@224
|
35 |
/** |
|
Matthias@224
|
36 |
* |
|
Matthias@224
|
37 |
* @author Matthias Mann |
|
Matthias@224
|
38 |
*/ |
|
Matthias@224
|
39 |
public class Node extends ResizableFrame { |
|
Matthias@224
|
40 |
|
|
Matthias@224
|
41 |
private final NodeArea nodeArea; |
|
Matthias@224
|
42 |
private final ArrayList<Pad> pads; |
|
Matthias@224
|
43 |
|
|
Matthias@224
|
44 |
public Node(NodeArea nodeArea) { |
|
Matthias@224
|
45 |
this.nodeArea = nodeArea; |
|
Matthias@224
|
46 |
this.pads = new ArrayList<Pad>(); |
|
Matthias@224
|
47 |
} |
|
Matthias@224
|
48 |
|
|
Matthias@224
|
49 |
public NodeArea getNodeArea() { |
|
Matthias@224
|
50 |
return nodeArea; |
|
Matthias@224
|
51 |
} |
|
Matthias@224
|
52 |
|
|
Matthias@224
|
53 |
public Pad addPad(String name, boolean input) { |
|
Matthias@224
|
54 |
Pad pad = new Pad(this, input); |
|
Matthias@224
|
55 |
pad.setTooltipContent(name); |
|
Matthias@224
|
56 |
pads.add(pad); |
|
Matthias@224
|
57 |
add(pad); |
|
Matthias@224
|
58 |
return pad; |
|
Matthias@224
|
59 |
} |
|
Matthias@224
|
60 |
|
|
Matthias@224
|
61 |
public Pad padFromMouse(int x, int y) { |
|
Matthias@224
|
62 |
for(int i=0,n=pads.size() ; i<n ; i++) { |
|
Matthias@224
|
63 |
Pad pad = pads.get(i); |
|
Matthias@224
|
64 |
if(pad.isInside(x, y)) { |
|
Matthias@224
|
65 |
return pad; |
|
Matthias@224
|
66 |
} |
|
Matthias@224
|
67 |
} |
|
Matthias@224
|
68 |
return null; |
|
Matthias@224
|
69 |
} |
|
Matthias@224
|
70 |
|
|
Matthias@224
|
71 |
@Override |
|
Matthias@224
|
72 |
protected void layout() { |
|
Matthias@224
|
73 |
super.layout(); |
|
Matthias@224
|
74 |
|
|
Matthias@224
|
75 |
int yIn = getInnerY(); |
|
Matthias@224
|
76 |
int yOut = getInnerY(); |
|
Matthias@224
|
77 |
int xIn = getX(); |
|
Matthias@224
|
78 |
int xOut = getRight() - 2*Pad.RADIUS; |
|
Matthias@224
|
79 |
|
|
Matthias@224
|
80 |
for(int i=0,n=pads.size() ; i<n ; i++) { |
|
Matthias@224
|
81 |
Pad pad = pads.get(i); |
|
Matthias@224
|
82 |
|
|
Matthias@224
|
83 |
pad.adjustSize(); |
|
Matthias@224
|
84 |
if(pad.isInput()) { |
|
Matthias@224
|
85 |
pad.setPosition(xIn, yIn); |
|
Matthias@224
|
86 |
yIn += Pad.RADIUS * 3; |
|
Matthias@224
|
87 |
} else { |
|
Matthias@224
|
88 |
pad.setPosition(xOut, yOut); |
|
Matthias@224
|
89 |
yOut += Pad.RADIUS * 3; |
|
Matthias@224
|
90 |
} |
|
Matthias@224
|
91 |
} |
|
Matthias@224
|
92 |
} |
|
Matthias@224
|
93 |
|
|
Matthias@224
|
94 |
} |