KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > genimen > djeneric > tools > modeler > diagrammer > ExtentViewer


1 /*
2  * Copyright (c) 2001-2005 by Genimen BV (www.genimen.com) All rights reserved.
3  *
4  * Redistribution and use in source and binary forms, with or without
5  * modification, is permitted provided that the following conditions are met: -
6  * Redistributions of source code must retain the above copyright notice, this
7  * list of conditions and the following disclaimer. - Redistributions in binary
8  * form must reproduce the above copyright notice, this list of conditions and
9  * the following disclaimer in the documentation and/or other materials
10  * provided with the distribution. - All advertising materials mentioning
11  * features or use of this software must display the following acknowledgment:
12  * "This product includes Djeneric." - Products derived from this software may
13  * not be called "Djeneric" nor may "Djeneric" appear in their names without
14  * prior written permission of Genimen BV. - Redistributions of any form
15  * whatsoever must retain the following acknowledgment: "This product includes
16  * Djeneric."
17  *
18  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS"
19  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21  * ARE DISCLAIMED. IN NO EVENT SHALL GENIMEN BV, DJENERIC.ORG, OR CONTRIBUTORS
22  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
23  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
24  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
25  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
26  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
27  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
28  * POSSIBILITY OF SUCH DAMAGE.
29  */

30 package com.genimen.djeneric.tools.modeler.diagrammer;
31
32 import java.awt.BasicStroke JavaDoc;
33 import java.awt.Color JavaDoc;
34 import java.awt.FontMetrics JavaDoc;
35 import java.awt.Graphics2D JavaDoc;
36 import java.awt.Rectangle JavaDoc;
37 import java.awt.Shape JavaDoc;
38 import java.awt.Stroke JavaDoc;
39 import java.awt.geom.AffineTransform JavaDoc;
40 import java.awt.geom.Rectangle2D JavaDoc;
41 import java.util.Arrays JavaDoc;
42 import java.util.HashMap JavaDoc;
43
44 import com.genimen.djeneric.repository.DjExtent;
45 import com.genimen.djeneric.repository.DjProperty;
46 import com.genimen.djeneric.repository.DjRelation;
47
48 public class ExtentViewer extends DiagramObject
49 {
50   DjExtent _extent;
51
52   Color JavaDoc _extentColor = new Color JavaDoc(58, 110, 165);
53   Color JavaDoc _columnColor = Color.lightGray;
54   Color JavaDoc _nameColor = Color.white;
55   Color JavaDoc BOXFRAME_COLOR = new Color JavaDoc(130, 130, 130);
56   public final static Color JavaDoc _lighterGray = new Color JavaDoc(230, 230, 230);
57
58   final static int CORNER_SIZE = 11;
59   final static int COLUMN_MARGIN = 12;
60   final static int TYPE_MARGIN = 120;
61   final static int COLUMN_Y_OFFSET = 40;
62
63   static float dash[] = {4.0f};
64   static BasicStroke JavaDoc _dashStroke = new BasicStroke JavaDoc(1.0f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER,
65                                                  10.0f, dash, 0.0f);
66
67   int _relsCountTop = 0;
68   int _relsCountBottom = 0;
69
70   public ExtentViewer(DjExtent extent)
71   {
72     _extent = extent;
73   }
74
75   public void setExtentColor(Color JavaDoc c)
76   {
77     _extentColor = c;
78   }
79
80   public void setNameColor(Color JavaDoc c)
81   {
82     _nameColor = c;
83   }
84
85   public void setPropertyColor(Color JavaDoc c)
86   {
87     _columnColor = c;
88   }
89
90   public Color JavaDoc getExtentColor()
91   {
92     return _extentColor;
93   }
94
95   public Color JavaDoc getNameColor()
96   {
97     return _nameColor;
98   }
99
100   public Color JavaDoc getPropertyColor()
101   {
102     return _columnColor;
103   }
104
105   public DjExtent getExtent()
106   {
107     return _extent;
108   }
109
110   public void setExtent(DjExtent extent)
111   {
112     _extent = extent;
113   }
114
115   public final int getCorner(int x, int y)
116   {
117     if ((x > getX()) && (x < getX() + CORNER_SIZE) && (y > getY()) && (y < getY() + CORNER_SIZE)) return 1;
118     if ((x > getX2() - CORNER_SIZE) && (x < getX2()) && (y > getY()) && (y < getY() + CORNER_SIZE)) return 2;
119     if ((x > getX()) && (x < getX() + CORNER_SIZE) && (y > getY2() - CORNER_SIZE) && (y < getY2())) return 3;
120     if ((x > getX2() - CORNER_SIZE) && (x < getX2()) && (y > getY2() - CORNER_SIZE) && (y < getY2())) return 4;
121
122     return -1;
123   }
124
125   protected final void drawRecursiveRelation(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx, ExtentViewer master,
126                                              DjRelation currentRelation, int counter)
127   {
128     String JavaDoc relName = currentRelation.getName();
129
130     relName += " (" + currentRelation.getDetailProperty().getName() + ")";
131
132     int s1 = 5;
133     int s2 = s1 * 2;
134
135     int step = 20;
136
137     int x1 = getX2() - step * counter;
138     int y1 = getY();
139
140     if (x1 < getX()) x1 = getX();
141
142     int x2 = x1;
143     int y2 = getY() - step * counter;
144
145     int x3 = getX2() + step * counter;
146     int y3 = y2;
147
148     int x4 = x3;
149     int y4 = getY() + step * counter;
150
151     if (y4 > getY2()) y4 = getY2();
152
153     int x5 = getX2();
154     int y5 = y4;
155
156     g2D.drawString(relName, x2, y2 - 7);
157
158     g2D.drawString(currentRelation.isOneToMany() ? "*" : "1", x5 + 10, y5 - 2);
159
160     if (!currentRelation.isDetailsContained())
161     {
162       Stroke JavaDoc org = g2D.getStroke();
163       if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
164
165       g2D.drawLine(x1, y1, x2, y2);
166       g2D.drawLine(x2, y2, x3, y3);
167       g2D.drawLine(x3, y3, x4, y4);
168       g2D.drawLine(x4, y4, x5, y5);
169       g2D.setStroke(org);
170     }
171     else
172     {
173       Stroke JavaDoc org = g2D.getStroke();
174       if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
175
176       g2D.drawLine(x1, y1 - s2, x2, y2);
177       g2D.drawLine(x2, y2, x3, y3);
178       g2D.drawLine(x3, y3, x4, y4);
179       g2D.drawLine(x4, y4, x5, y5);
180
181       g2D.setStroke(org);
182
183       g2D.drawLine(x1, y1, x1 - s1, y1 - s1);
184       g2D.drawLine(x1 - s1, y1 - s1, x1, y1 - s2);
185       g2D.drawLine(x1, y1 - s2, x1 + s1, y1 - s1);
186       g2D.drawLine(x1 + s1, y1 - s1, x1, y1);
187     }
188   }
189
190   protected final void drawNormalRelation(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx, ExtentViewer master,
191                                           DjRelation currentRelation, HashMap JavaDoc horizontalMastersDone,
192                                           HashMap JavaDoc verticalMastersDone)
193   {
194     int drawingOffset = 0;
195
196     String JavaDoc relName = currentRelation.getName();
197     relName += " (" + currentRelation.getDetailProperty().getName() + ")";
198
199     FontMetrics JavaDoc fontMetrics = g2D.getFontMetrics(_editor._font);
200     Rectangle2D JavaDoc r = fontMetrics.getStringBounds(relName, _editor.getPaintPanel().getGraphics());
201     int nameWidth = (int) (r.getWidth()) + 20;
202     int nameHeight = (int) (r.getHeight());
203     LineSpecifics ls = new LineSpecifics(master, this, 0);
204
205     if (!ls.horizontal)
206     {
207       // Determine offset of line; depends on lines from A-B and B-A
208
// (uni-directional)
209
String JavaDoc key1 = master.getExtent().getName();
210       String JavaDoc key2 = getExtent().getName();
211       String JavaDoc key;
212
213       if (key1.compareTo(key2) <= 0) key = ls.horizontal + key1 + key2;
214       else key = ls.horizontal + key2 + key1;
215
216       if (verticalMastersDone.containsKey(key))
217       {
218         int count = ((Integer JavaDoc) verticalMastersDone.get(key)).intValue() + 1;
219         verticalMastersDone.put(key, new Integer JavaDoc(count));
220         drawingOffset += count * nameHeight;
221       }
222       else
223       {
224         verticalMastersDone.put(key, new Integer JavaDoc(0));
225       }
226
227       ls = new LineSpecifics(master, this, drawingOffset);
228
229       drawingOffset = 10;
230
231       // Determine offset of relation name, depends on direction
232
key = "*" + ls.direction + key1;
233       if (verticalMastersDone.containsKey(key))
234       {
235         int count = ((Integer JavaDoc) verticalMastersDone.get(key)).intValue() + 1;
236         verticalMastersDone.put(key, new Integer JavaDoc(count));
237         drawingOffset += count * nameHeight;
238       }
239       else
240       {
241         verticalMastersDone.put(key, new Integer JavaDoc(0));
242       }
243     }
244
245     int x1 = ls.startX1 + getX();
246     int y1 = ls.startY1 + getY();
247     int x2 = ls.startX2 + master.getX();
248     int y2 = ls.startY2 + master.getY();
249     boolean horizontal = ls.horizontal;
250
251     if (horizontal)
252     {
253       // Draw horizontal relation
254

255       // Determine offset of line; depends on lines from A-B and B-A
256
// (uni-directional)
257
String JavaDoc key1 = master.getExtent().getName();
258       String JavaDoc key2 = getExtent().getName();
259       String JavaDoc key;
260
261       if (key1.compareTo(key2) <= 0) key = ls.horizontal + key1 + key2;
262       else key = ls.horizontal + key2 + key1;
263
264       if (horizontalMastersDone.containsKey(key))
265       {
266         int count = ((Integer JavaDoc) horizontalMastersDone.get(key)).intValue() + 1;
267         horizontalMastersDone.put(key, new Integer JavaDoc(count));
268         drawingOffset += count * nameHeight;
269       }
270       else
271       {
272         horizontalMastersDone.put(key, new Integer JavaDoc(0));
273       }
274
275       y1 += drawingOffset;
276       y2 += drawingOffset;
277
278       int s1 = 5;
279       if (x1 > x2)
280       {
281         s1 *= -1;
282         nameWidth = -20;
283       }
284
285       int s2 = s1 * 2;
286
287       g2D.drawString(relName, x2 - nameWidth, y2 - 4);
288
289       g2D.drawString(currentRelation.isOneToMany() ? "*" : "1", x1 + s1, y1 - 2);
290
291       if (!currentRelation.isDetailsContained())
292       {
293         Stroke JavaDoc org = g2D.getStroke();
294         if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
295         g2D.drawLine(x1, y1, x2, y2);
296         g2D.setStroke(org);
297       }
298       else
299       {
300         Stroke JavaDoc org = g2D.getStroke();
301         if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
302         g2D.drawLine(x2 - s2, y2, x1, y1);
303         g2D.setStroke(org);
304
305         g2D.drawLine(x2 - s2, y2, x2 - s1, y2 - s1);
306         g2D.drawLine(x2 - s1, y2 - s1, x2, y2);
307         g2D.drawLine(x2 - s2, y2, x2 - s1, y2 + s1);
308         g2D.drawLine(x2 - s1, y2 + s1, x2, y2);
309       }
310     }
311     else
312     {
313       // Draw vertical relation
314

315       int s1 = 5;
316       int starHeight = nameHeight;
317
318       if (y1 > y2)
319       {
320         s1 *= -1;
321         nameHeight *= -1;
322         starHeight = -2;
323         drawingOffset *= -1;
324       }
325
326       int s2 = s1 * 2;
327
328       g2D.drawString(relName, x2 + 4, (y2 - nameHeight) - drawingOffset);
329       g2D.drawString(currentRelation.isOneToMany() ? "*" : "1", x1 - s1, y1 + starHeight);
330
331       if (!currentRelation.isDetailsContained())
332       {
333         Stroke JavaDoc org = g2D.getStroke();
334         if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
335         g2D.drawLine(x1, y1, x2, y2);
336         g2D.setStroke(org);
337       }
338       else
339       {
340         Stroke JavaDoc org = g2D.getStroke();
341         if (!currentRelation.getDetailProperty().isRequired()) g2D.setStroke(_dashStroke);
342         g2D.drawLine(x2, y2 - s2, x1, y1);
343         g2D.setStroke(org);
344
345         g2D.drawLine(x2, y2, x2 - s1, y2 - s1);
346         g2D.drawLine(x2 - s1, y2 - s1, x2, y2 - s2);
347         g2D.drawLine(x2, y2 - s2, x2 + s1, y2 - s1);
348         g2D.drawLine(x2 + s1, y2 - s1, x2, y2);
349       }
350     }
351   }
352
353   public final void paintInheritance(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx)
354   {
355     DjExtent superExtent = _extent.getSuper();
356     if (superExtent == null) return;
357
358     ExtentViewer superViewer = _editor.getExtentViewer(superExtent);
359     // Present on diagram?
360
if (superViewer == null) return;
361
362     LineSpecifics ls = new LineSpecifics(superViewer, this, 0);
363
364     int x1 = ls.startX1 + getX();
365     int y1 = ls.startY1 + getY();
366     int x2 = ls.startX2 + superViewer.getX();
367     int y2 = ls.startY2 + superViewer.getY();
368     boolean horizontal = ls.horizontal;
369
370     g2D.setTransform(afx);
371     g2D.setPaint(Color.black);
372
373     int s = 8;
374     if (horizontal)
375     {
376       y1 += 5;
377       y2 += 5;
378       if (x1 > x2) s *= -1;
379
380       g2D.drawLine(x2 - s, y2, x1, y1);
381
382       g2D.drawLine(x2 - s, y2 - s, x2, y2);
383       g2D.drawLine(x2 - s, y2 + s, x2, y2);
384       g2D.drawLine(x2 - s, y2 - s, x2 - s, y2 + s);
385     }
386     else
387     {
388       x1 += 5;
389       x2 += 5;
390       if (y2 > y1) s *= -1;
391
392       g2D.drawLine(x2, y2 + s, x1, y1);
393
394       g2D.drawLine(x2 - s, y2 + s, x2, y2);
395       g2D.drawLine(x2 + s, y2 + s, x2, y2);
396       g2D.drawLine(x2 - s, y2 + s, x2 + s, y2 + s);
397     }
398
399     g2D.setTransform(afx);
400   }
401
402   public final void paintRelations(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx, HashMap JavaDoc horizontalMastersDone,
403                                    HashMap JavaDoc verticalMastersDone)
404   {
405     g2D.setTransform(afx);
406     g2D.setPaint(Color.black);
407
408     int recursiveRelationCounter = 1;
409
410     DjRelation[] rels = _extent.getPersonalMasterRelations();
411     for (int i = 0; i < rels.length; i++)
412     {
413       DjRelation currentRelation = rels[i];
414       ExtentViewer master = _editor.getExtentViewer(currentRelation.getMasterExtent());
415       if (master != null && master.getExtent() == getExtent())
416       {
417         // recursive relation
418
drawRecursiveRelation(g2D, afx, master, currentRelation, recursiveRelationCounter++);
419       }
420       else if (master != null)
421       {
422         // Master present on the diagram?
423
drawNormalRelation(g2D, afx, master, currentRelation, horizontalMastersDone, verticalMastersDone);
424       }
425     }
426     g2D.setTransform(afx);
427   }
428
429   public void paint(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx, HashMap JavaDoc horizontalMastersDone, HashMap JavaDoc verticalMastersDone,
430                     int viewMode)
431   {
432     g2D.setPaint(_extentColor);
433
434     Rectangle JavaDoc rect = new Rectangle JavaDoc();
435     rect.setFrame(getX(), getY(), getWidth(), getHeight());
436
437     Shape JavaDoc orgClip = g2D.getClip();
438
439     Rectangle JavaDoc clipRect = new Rectangle JavaDoc();
440     clipRect.setFrame(getX(), getY(), getWidth() + 1, getHeight() + 1);
441     g2D.setClip(clipRect);
442
443     g2D.fill(rect);
444     g2D.draw(rect);
445
446     g2D.setColor(BOXFRAME_COLOR);
447     g2D.draw(rect);
448
449     g2D.setTransform(afx);
450
451     g2D.setColor(_nameColor);
452     g2D.setFont(_editor._largerFont);
453
454     if (viewMode == PaintPanel.SHOW_ALIAS) g2D.drawString(_extent.getAlias(), getX() + CORNER_SIZE + 2,
455                                                           getY() + _editor._largerFont.getSize() + 2);
456     else if (viewMode == PaintPanel.SHOW_CLASS) g2D.drawString(_extent.getObjectType(), getX() + CORNER_SIZE + 2,
457                                                                getY() + _editor._largerFont.getSize() + 2);
458     else if (viewMode == PaintPanel.SHOW_EXTENT) g2D.drawString(_extent.getName(), getX() + CORNER_SIZE + 2,
459                                                                 getY() + _editor._largerFont.getSize() + 2);
460     else if (viewMode == PaintPanel.SHOW_QUALIFIED) g2D.drawString(_extent.getQualifiedObjectType(), getX()
461                                                                                                      + CORNER_SIZE + 2,
462                                                                    getY() + _editor._largerFont.getSize() + 2);
463
464     g2D.setFont(_editor._smallfont);
465     g2D.setColor(_columnColor);
466
467     g2D.setFont(_editor._font);
468     g2D.setColor(_columnColor);
469     Rectangle JavaDoc colClipRect = new Rectangle JavaDoc();
470
471     int maxWidth = TYPE_MARGIN - 4;
472     if (maxWidth > getWidth()) maxWidth = getWidth();
473     colClipRect.setFrame(getX(), getY(), maxWidth, getHeight() + 1);
474
475     int fSize = _editor._font.getSize();
476     DjProperty[] props = _extent.getPersonalProperties();
477     for (int i = 0; i < props.length; i++)
478     {
479       g2D.setClip(colClipRect);
480
481       if (viewMode == PaintPanel.SHOW_ALIAS) g2D.drawString(props[i].getAlias(), _x + COLUMN_MARGIN + 15,
482                                                             _y + fSize * i + COLUMN_Y_OFFSET);
483       else g2D.drawString(props[i].getName(), _x + COLUMN_MARGIN + 15, _y + fSize * i + COLUMN_Y_OFFSET);
484
485       g2D.setClip(clipRect);
486       g2D.drawString(props[i].getTypeName(), _x + TYPE_MARGIN, _y + fSize * i + COLUMN_Y_OFFSET);
487
488       if (props[i].isRequired())
489       {
490         g2D.drawString("*", _x + 5, _y + fSize * i + COLUMN_Y_OFFSET + 2);
491       }
492       if (props[i].isPartOfUID())
493       {
494         g2D.drawString("u", _x + 10, _y + fSize * i + COLUMN_Y_OFFSET);
495       }
496     }
497
498     if (isSelected())
499     {
500       g2D.setColor(_editor._selectionColor);
501       g2D.fillRect(getX(), getY(), CORNER_SIZE, CORNER_SIZE);
502       g2D.fillRect(getX2() - (CORNER_SIZE - 1), getY(), CORNER_SIZE, CORNER_SIZE);
503       g2D.fillRect(getX(), getY2() - (CORNER_SIZE - 1), CORNER_SIZE, CORNER_SIZE);
504       g2D.fillRect(getX2() - (CORNER_SIZE - 1), getY2() - (CORNER_SIZE - 1), CORNER_SIZE, CORNER_SIZE);
505     }
506
507     g2D.setTransform(afx);
508     g2D.setClip(orgClip);
509   }
510
511   public void paintLines(Graphics2D JavaDoc g2D, AffineTransform JavaDoc afx, HashMap JavaDoc horizontalMastersDone, HashMap JavaDoc verticalMastersDone)
512   {
513     paintRelations(g2D, afx, horizontalMastersDone, verticalMastersDone);
514     paintInheritance(g2D, afx);
515   }
516
517   public boolean equals(Object JavaDoc obj)
518   {
519     if (!(obj instanceof ExtentViewer)) return false;
520     ExtentViewer other = (ExtentViewer) obj;
521
522     return _extent == other._extent;
523   }
524
525   public int hashCode()
526   {
527     int result = 0;
528     if (_extent != null) result += _extent.hashCode();
529
530     return result;
531   }
532
533   public void paintShadow(Graphics2D JavaDoc g2D)
534   {
535     g2D.setPaint(_lighterGray);
536     Rectangle JavaDoc rect = new Rectangle JavaDoc();
537     rect.setFrame(getX() + 4, getY() + 4, getWidth(), getHeight());
538     g2D.fill(rect);
539     g2D.draw(rect);
540
541     g2D.setPaint(Color.lightGray);
542     rect = new Rectangle JavaDoc();
543     rect.setFrame(getX() + 2, getY() + 2, getWidth(), getHeight());
544     g2D.fill(rect);
545     g2D.draw(rect);
546   }
547 }
548
549 class LineSpecifics
550 {
551
552   public int startX1 = 0, startY1 = 0, startX2 = 0, startY2 = 0;
553   public boolean horizontal;
554   public char direction = ' ';
555
556   public LineSpecifics(ExtentViewer master, ExtentViewer detail, int drawingOffset)
557   {
558     horizontal = true;
559     if (master.getY2() < detail.getY())
560     {
561       // master above us
562
direction = 'T'; // master at top;
563
horizontal = false;
564       startY1 = 0;
565       startY2 = master.getHeight();
566
567       int middle = getMiddleOfSpan(detail.getX(), detail.getX2(), master.getX(), master.getX2()) + drawingOffset;
568       startX1 = middle - detail.getX();
569       startX2 = middle - master.getX();
570       if (startX1 > detail.getWidth() - 5) startX1 = (detail.getWidth() - 5) - drawingOffset;
571       if (startX1 < 5) startX1 = 5;
572       if (startX2 > master.getWidth() - 5) startX2 = (master.getWidth() - 5) - drawingOffset;
573       if (startX2 < 5) startX2 = 5;
574     }
575     else if (master.getY() > detail.getY2())
576     {
577       // master below us
578
direction = 'B'; // master at top;
579
horizontal = false;
580       startY1 = detail.getHeight();
581       startY2 = 0;
582
583       int middle = getMiddleOfSpan(detail.getX(), detail.getX2(), master.getX(), master.getX2()) + drawingOffset;
584       startX1 = middle - detail.getX();
585       startX2 = middle - master.getX();
586
587       if (startX1 > detail.getWidth() - 5) startX1 = (detail.getWidth() - 5) - drawingOffset;
588       if (startX1 < 5) startX1 = 5;
589       if (startX2 > master.getWidth() - 5) startX2 = (master.getWidth() - 5) - drawingOffset;
590       if (startX2 < 5) startX2 = 5;
591     }
592     else
593     // must be beside then
594
if (master.getX() > detail.getX2())
595     {
596       // master beside to the right
597
direction = 'R'; // master at right;
598
startX1 = detail.getWidth();
599       startX2 = 0;
600
601       startY1 = detail.getHeight() / 2;
602       startY2 = master.getHeight() / 2;
603
604       int middle = getMiddleOfSpan(detail.getY(), detail.getY2(), master.getY(), master.getY2()) + drawingOffset;
605       startY1 = middle - detail.getY();
606       startY2 = middle - master.getY();
607
608       if (startY1 > detail.getHeight() - 5) startY1 = (detail.getHeight() - 5) - drawingOffset;
609       if (startY1 < 5) startY1 = 5;
610       if (startY2 > master.getHeight() - 5) startY2 = (master.getHeight() - 5) - drawingOffset;
611       if (startY2 < 5) startY2 = 5;
612
613     }
614     else if (master.getX() < detail.getX2())
615     {
616       // master beside to the left
617
direction = 'L'; // master at left;
618
startX1 = 0;
619       startX2 = master.getWidth();
620
621       int middle = getMiddleOfSpan(detail.getY(), detail.getY2(), master.getY(), master.getY2()) + drawingOffset;
622       startY1 = middle - detail.getY();
623       startY2 = middle - master.getY();
624
625       if (startY1 > detail.getHeight() - 5) startY1 = (detail.getHeight() - 5) - drawingOffset;
626       if (startY1 < 5) startY1 = 5;
627       if (startY2 > master.getHeight() - 5) startY2 = (master.getHeight() - 5) - drawingOffset;
628       if (startY2 < 5) startY2 = 5;
629     }
630   }
631
632   public final int getMiddleOfSpan(int x1, int x2, int x3, int x4)
633   {
634     int[] p = new int[4];
635     p[0] = x1;
636     p[1] = x2;
637     p[2] = x3;
638     p[3] = x4;
639
640     Arrays.sort(p);
641     return (p[1] + p[2]) / 2;
642   }
643
644 }
Popular Tags