-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path292.html
90 lines (90 loc) · 18.3 KB
/
292.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
<html><head><title>BoundingBox.java</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" type="text/css" href="sourcestyles.css" />
</head><body link="blue" vlink="blue">
<h3>File: /Users/shatabdi/Education/GitHub/se450_project/src/model/others/BoundingBox.java</h3>
<SCRIPT>
defaultStatus = "File: /Users/shatabdi/Education/GitHub/se450_project/src/model/others/BoundingBox.java";
top.document.title = "BoundingBox.java";
</SCRIPT>
<pre><span class="default"></span><a name="1"><font size=-1>1 </font></a><span class="default"></span><span class="keyword">package </span><span class="default">model.<a href="dictionary_M.html#25">others</a>;</span>
<a name="2"><font size=-1>2 </font></a><span class="default"></span>
<a name="3"><font size=-1>3 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#293">AlphaComposite</a>;</span>
<a name="4"><font size=-1>4 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#294">BasicStroke</a>;</span>
<a name="5"><font size=-1>5 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#108">Color</a>;</span>
<a name="6"><font size=-1>6 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#338">Font</a>;</span>
<a name="7"><font size=-1>7 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#111">Graphics2D</a>;</span>
<a name="8"><font size=-1>8 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#214">Point</a>;</span>
<a name="9"><font size=-1>9 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#340">Rectangle</a>;</span>
<a name="10"><font size=-1>10 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#149">Shape</a>;</span>
<a name="11"><font size=-1>11 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#152">awt</a>.<a href="dictionary_J.html#150">Stroke</a>;</span>
<a name="12"><font size=-1>12 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#77">util</a>.<a href="dictionary_J.html#52">ArrayList</a>;</span>
<a name="13"><font size=-1>13 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#77">util</a>.<a href="dictionary_J.html#337">Collections</a>;</span>
<a name="14"><font size=-1>14 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">java.<a href="dictionary_J.html#77">util</a>.<a href="dictionary_J.html#53">List</a>;</span>
<a name="15"><font size=-1>15 </font></a><span class="default"></span>
<a name="16"><font size=-1>16 </font></a><span class="default"></span><span class="keyword">import <a href="dictionary_M.html#20">model</a></span><span class="default">.<a href="dictionary_M.html#341">GeometricShape</a>;</span>
<a name="17"><font size=-1>17 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">model.<a href="dictionary_M.html#344">factory</a>.<a href="dictionary_M.html#342">ShapeFactory</a>;</span>
<a name="18"><font size=-1>18 </font></a><span class="default"></span><span class="keyword">import </span><span class="default">view.<a href="dictionary_V.html#3">Enum</a>.ShapeType;</span>
<a name="19"><font size=-1>19 </font></a><span class="default"></span>
<a name="20"><font size=-1>20 </font></a><span class="default"></span><span class="keyword">public class <a href="dictionary_M.html#243">BoundingBox</a> </span><span class="default">{</span>
<a name="21"><font size=-1>21 </font></a><span class="default"></span>
<a name="22"><font size=-1>22 </font></a><span class="default"> </span><span class="keyword">public static <a href="dictionary_J.html#149">Shape</a> <a href="dictionary_M.html#295">boundFromPoints</a></span><span class="default">(<a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#299">startPoint</a>, <a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#297">endPoint</a>) {</span>
<a name="23"><font size=-1>23 </font></a><span class="default"> <a href="dictionary_M.html#341">GeometricShape</a> <a href="dictionary_M.html#298">geometricShape</a> = </span><span class="keyword">new <a href="dictionary_M.html#346">GeometricShape</a></span><span class="default">(<a href="dictionary_M.html#299">startPoint</a>, <a href="dictionary_M.html#297">endPoint</a>);</span>
<a name="24"><font size=-1>24 </font></a><span class="default"> <a href="dictionary_M.html#298">geometricShape</a>.<a href="dictionary_M.html#347">setShapeType</a>(ShapeType.<a href="dictionary_R.html#296">RECTANGLE</a>);</span>
<a name="25"><font size=-1>25 </font></a><span class="default"> </span><span class="keyword">return <a href="dictionary_M.html#342">ShapeFactory</a></span><span class="default">.<a href="dictionary_M.html#348">createShape</a>(<a href="dictionary_M.html#298">geometricShape</a>);</span>
<a name="26"><font size=-1>26 </font></a><span class="default"> }</span>
<a name="27"><font size=-1>27 </font></a><span class="default"></span>
<a name="28"><font size=-1>28 </font></a><span class="default"> </span><span class="comment">/**</span>
<a name="29"><font size=-1>29 </font></a><span class="comment"> * Discussion board replies Top left of bounding box is (x, y) Bottom right is</span>
<a name="30"><font size=-1>30 </font></a><span class="comment"> * (x+Width, y+Height) Width of a bounding box is xMax - xMin Height is given by</span>
<a name="31"><font size=-1>31 </font></a><span class="comment"> * yMax - yMin Bounding box = (xMin, yMin, xMax - xMin, yMax - yMin);</span>
<a name="32"><font size=-1>32 </font></a><span class="comment"> */</span>
<a name="33"><font size=-1>33 </font></a><span class="comment"> </span><span class="keyword">public static <a href="dictionary_J.html#149">Shape</a> <a href="dictionary_M.html#300">createBoundingBox</a></span><span class="default">(<a href="dictionary_J.html#53">List</a><<a href="dictionary_J.html#149">Shape</a>> <a href="dictionary_M.html#311">list</a>) {</span>
<a name="34"><font size=-1>34 </font></a><span class="default"> <a href="dictionary_J.html#53">List</a><<a href="dictionary_I.html#339">Integer</a>> <a href="dictionary_M.html#314">listStartXCoord</a> = </span><span class="keyword">new <a href="dictionary_J.html#52">ArrayList</a></span><span class="default"><>();</span>
<a name="35"><font size=-1>35 </font></a><span class="default"> <a href="dictionary_J.html#53">List</a><<a href="dictionary_I.html#339">Integer</a>> <a href="dictionary_M.html#315">listStartYCoord</a> = </span><span class="keyword">new <a href="dictionary_J.html#52">ArrayList</a></span><span class="default"><>();</span>
<a name="36"><font size=-1>36 </font></a><span class="default"></span>
<a name="37"><font size=-1>37 </font></a><span class="default"> <a href="dictionary_J.html#53">List</a><<a href="dictionary_I.html#339">Integer</a>> <a href="dictionary_M.html#312">listEndXCoord</a> = </span><span class="keyword">new <a href="dictionary_J.html#52">ArrayList</a></span><span class="default"><>();</span>
<a name="38"><font size=-1>38 </font></a><span class="default"> <a href="dictionary_J.html#53">List</a><<a href="dictionary_I.html#339">Integer</a>> <a href="dictionary_M.html#313">listEndYCoord</a> = </span><span class="keyword">new <a href="dictionary_J.html#52">ArrayList</a></span><span class="default"><>();</span>
<a name="39"><font size=-1>39 </font></a><span class="default"></span>
<a name="40"><font size=-1>40 </font></a><span class="default"> </span><span class="keyword">for </span><span class="default">(<a href="dictionary_J.html#149">Shape</a> <a href="dictionary_M.html#305">shape</a> : <a href="dictionary_M.html#311">list</a>) {</span>
<a name="41"><font size=-1>41 </font></a><span class="default"> <a href="dictionary_J.html#340">Rectangle</a> <a href="dictionary_M.html#306">shapeBoundingRec</a> = <a href="dictionary_M.html#305">shape</a>.<a href="dictionary_G.html#303">getBounds</a>();</span>
<a name="42"><font size=-1>42 </font></a><span class="default"> <a href="dictionary_M.html#314">listStartXCoord</a>.<a href="dictionary_A.html#56">add</a>(<a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_X.html#308">x</a>);</span>
<a name="43"><font size=-1>43 </font></a><span class="default"> <a href="dictionary_M.html#315">listStartYCoord</a>.<a href="dictionary_A.html#56">add</a>(<a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_Y.html#309">y</a>);</span>
<a name="44"><font size=-1>44 </font></a><span class="default"></span>
<a name="45"><font size=-1>45 </font></a><span class="default"> <a href="dictionary_M.html#312">listEndXCoord</a>.<a href="dictionary_A.html#56">add</a>(<a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_X.html#308">x</a> + <a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_W.html#307">width</a>);</span>
<a name="46"><font size=-1>46 </font></a><span class="default"> <a href="dictionary_M.html#313">listEndYCoord</a>.<a href="dictionary_A.html#56">add</a>(<a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_Y.html#309">y</a> + <a href="dictionary_M.html#306">shapeBoundingRec</a>.<a href="dictionary_H.html#304">height</a>);</span>
<a name="47"><font size=-1>47 </font></a><span class="default"> }</span>
<a name="48"><font size=-1>48 </font></a><span class="default"></span>
<a name="49"><font size=-1>49 </font></a><span class="default"> </span><span class="keyword">int <a href="dictionary_M.html#318">xMin</a> </span><span class="default">= <a href="dictionary_J.html#337">Collections</a>.<a href="dictionary_M.html#302">min</a>(<a href="dictionary_M.html#314">listStartXCoord</a>);</span>
<a name="50"><font size=-1>50 </font></a><span class="default"> </span><span class="keyword">int <a href="dictionary_M.html#320">yMin</a> </span><span class="default">= <a href="dictionary_J.html#337">Collections</a>.<a href="dictionary_M.html#302">min</a>(<a href="dictionary_M.html#315">listStartYCoord</a>);</span>
<a name="51"><font size=-1>51 </font></a><span class="default"> </span><span class="keyword">int <a href="dictionary_M.html#317">xMax</a> </span><span class="default">= <a href="dictionary_J.html#337">Collections</a>.<a href="dictionary_M.html#301">max</a>(<a href="dictionary_M.html#312">listEndXCoord</a>);</span>
<a name="52"><font size=-1>52 </font></a><span class="default"> </span><span class="keyword">int <a href="dictionary_M.html#319">yMax</a> </span><span class="default">= <a href="dictionary_J.html#337">Collections</a>.<a href="dictionary_M.html#301">max</a>(<a href="dictionary_M.html#313">listEndYCoord</a>);</span>
<a name="53"><font size=-1>53 </font></a><span class="default"></span>
<a name="54"><font size=-1>54 </font></a><span class="default"> <a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#316">startPoint</a> = </span><span class="keyword">new <a href="dictionary_J.html#214">Point</a></span><span class="default">(<a href="dictionary_M.html#318">xMin</a>, <a href="dictionary_M.html#320">yMin</a>);</span>
<a name="55"><font size=-1>55 </font></a><span class="default"> <a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#310">endPoint</a> = </span><span class="keyword">new <a href="dictionary_J.html#214">Point</a></span><span class="default">(<a href="dictionary_M.html#317">xMax</a>, <a href="dictionary_M.html#319">yMax</a>);</span>
<a name="56"><font size=-1>56 </font></a><span class="default"> </span><span class="keyword">return <a href="dictionary_M.html#295">boundFromPoints</a></span><span class="default">(<a href="dictionary_M.html#316">startPoint</a>, <a href="dictionary_M.html#310">endPoint</a>);</span>
<a name="57"><font size=-1>57 </font></a><span class="default"> }</span>
<a name="58"><font size=-1>58 </font></a><span class="default"></span>
<a name="59"><font size=-1>59 </font></a><span class="default"> </span><span class="keyword">private <a href="dictionary_J.html#149">Shape</a> <a href="dictionary_M.html#336">boundingBox</a></span><span class="default">;</span>
<a name="60"><font size=-1>60 </font></a><span class="default"> </span>
<a name="61"><font size=-1>61 </font></a><span class="default"> </span><span class="keyword">public void <a href="dictionary_M.html#245">drawBoundingBox</a></span><span class="default">(<a href="dictionary_J.html#111">Graphics2D</a> <a href="dictionary_M.html#332">graphics2d</a>) {</span>
<a name="62"><font size=-1>62 </font></a><span class="default"> <a href="dictionary_J.html#150">Stroke</a> <a href="dictionary_M.html#331">dashed_outline</a> = </span><span class="keyword">new <a href="dictionary_J.html#294">BasicStroke</a></span><span class="default">(</span><span class="number">3</span><span class="default">, <a href="dictionary_J.html#294">BasicStroke</a>.<a href="dictionary_C.html#327">CAP_BUTT</a>, <a href="dictionary_J.html#294">BasicStroke</a>.<a href="dictionary_J.html#328">JOIN_BEVEL</a>, </span><span class="number">1</span><span class="default">, </span><span class="keyword">new float</span><span class="default">[] { </span><span class="number">9 </span><span class="default">},</span>
<a name="63"><font size=-1>63 </font></a><span class="default"> </span><span class="number">0</span><span class="default">);</span>
<a name="64"><font size=-1>64 </font></a><span class="default"></span>
<a name="65"><font size=-1>65 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_S.html#129">setStroke</a>(<a href="dictionary_M.html#331">dashed_outline</a>);</span>
<a name="66"><font size=-1>66 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_S.html#122">setPaint</a>(<a href="dictionary_J.html#108">Color</a>.<a href="dictionary_G.html#333">green</a>);</span>
<a name="67"><font size=-1>67 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_S.html#128">setColor</a>(<a href="dictionary_J.html#108">Color</a>.<a href="dictionary_B.html#330">black</a>);</span>
<a name="68"><font size=-1>68 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_S.html#325">setFont</a>(</span><span class="keyword">new <a href="dictionary_J.html#338">Font</a></span><span class="default">(<a href="dictionary_M.html#345">Messages</a>.<a href="dictionary_M.html#349">getString</a>(</span><span class="string">"BoundingBox.0"</span><span class="default">), <a href="dictionary_J.html#338">Font</a>.<a href="dictionary_B.html#326">BOLD</a>, </span><span class="number">16</span><span class="default">)); </span><span class="comment">//$NON-NLS-1$</span>
<a name="69"><font size=-1>69 </font></a><span class="comment"> <a href="dictionary_M.html#332">graphics2d</a></span><span class="default">.<a href="dictionary_D.html#321">draw</a>(<a href="dictionary_M.html#336">boundingBox</a>);</span>
<a name="70"><font size=-1>70 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_S.html#324">setComposite</a>(<a href="dictionary_J.html#293">AlphaComposite</a>.<a href="dictionary_G.html#323">getInstance</a>(<a href="dictionary_J.html#293">AlphaComposite</a>.<a href="dictionary_S.html#329">SRC_OVER</a>, </span><span class="number">0.7f</span><span class="default">));</span>
<a name="71"><font size=-1>71 </font></a><span class="default"></span>
<a name="72"><font size=-1>72 </font></a><span class="default"> <a href="dictionary_M.html#332">graphics2d</a>.<a href="dictionary_D.html#322">drawString</a>(<a href="dictionary_M.html#345">Messages</a>.<a href="dictionary_M.html#349">getString</a>(</span><span class="string">"BoundingBox.1"</span><span class="default">), <a href="dictionary_M.html#336">boundingBox</a>.<a href="dictionary_G.html#303">getBounds</a>().x, <a href="dictionary_M.html#336">boundingBox</a>.<a href="dictionary_G.html#303">getBounds</a>().y); </span><span class="comment">//$NON-NLS-1$</span>
<a name="73"><font size=-1>73 </font></a><span class="comment"> </span><span class="default">}</span>
<a name="74"><font size=-1>74 </font></a><span class="default"> </span>
<a name="75"><font size=-1>75 </font></a><span class="default"> </span><span class="keyword">public <a href="dictionary_J.html#149">Shape</a> <a href="dictionary_M.html#244">generateFromPoints</a></span><span class="default">(<a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#335">startPoint</a>, <a href="dictionary_J.html#214">Point</a> <a href="dictionary_M.html#334">endPoint</a>) {</span>
<a name="76"><font size=-1>76 </font></a><span class="default"> </span><span class="keyword">this</span><span class="default">.<a href="dictionary_M.html#336">boundingBox</a> = <a href="dictionary_M.html#295">boundFromPoints</a>(<a href="dictionary_M.html#335">startPoint</a>, <a href="dictionary_M.html#334">endPoint</a>);</span>
<a name="77"><font size=-1>77 </font></a><span class="default"> </span><span class="keyword">return this</span><span class="default">.<a href="dictionary_M.html#336">boundingBox</a>;</span>
<a name="78"><font size=-1>78 </font></a><span class="default"> }</span>
<a name="79"><font size=-1>79 </font></a><span class="default">}</span>
<a name="80"><font size=-1>80 </font></a><span class="default"></span>
</pre></body></html>