001: package com.xoetrope.carousel.survey;
002:
003: import com.xoetrope.survey.Condition;
004: import com.xoetrope.survey.Question;
005: import java.awt.Color;
006: import java.awt.Graphics;
007: import java.awt.Graphics2D;
008: import java.awt.Point;
009: import java.awt.Rectangle;
010: import java.awt.event.ActionEvent;
011: import java.awt.event.ActionListener;
012: import java.awt.event.MouseEvent;
013: import java.awt.geom.Rectangle2D;
014: import java.awt.geom.RoundRectangle2D;
015: import java.util.Enumeration;
016: import java.util.Observable;
017: import java.util.Observer;
018: import java.util.Vector;
019: import javax.swing.BorderFactory;
020: import javax.swing.JLabel;
021: import javax.swing.JMenuItem;
022: import javax.swing.JPopupMenu;
023:
024: /**
025: * A view of the question group.
026: *
027: * <p> Copyright (c) Xoetrope Ltd., 2001-2006, This software is licensed under
028: * the GNU Public License (GPL), please see license.txt for more details. If
029: * you make commercial use of this software you must purchase a commercial
030: * license from Xoetrope.</p>
031: * <p> $Revision: 1.5 $</p>
032: */
033: public class XGroupView extends XSurveyComponentBig implements XSource {
034: public static int WIDTH = 200;
035: public static int HEIGHT = 216;
036: public static int LEFT_GAP = 10;
037: public static int RIGHT_GAP = 10;
038: public static int TOP_GAP = 10;
039: public static int BOTTOM_GAP = 30;
040: public static int HEADER_GAP = 30;
041: public static int HEADER_HEIGHT = 20;
042: public static int COMPONENT_HEIGHT = 20;
043: public static int COMPONENT_GAP = 5;
044: public static double ARROW_BUTTON_Y = 0.3;
045: public static int ARROW_BUTTON_GAP = 3;
046: public static int ARROW_BUTTON_WIDTH = 40;
047: public static int ARROW_BUTTON_HEIGHT = 20;
048: public static Color ARROW_BUTTON_BACKGROUND = new Color(39, 147,
049: 173);
050: public static Color ARROW_BUTTON_BORDER = Color.BLACK;
051: public static Color BACKGROUND_COLOR = new Color(128, 230, 255);
052: public static Color BORDER_COLOR = Color.BLACK;
053: public static int ARC = 30;
054: public static int HEADERFIELD_WIDTH = 180;
055: public static int HEADERFIELD_HEIGHT = 20;
056: public static int HEADERFIELD_GAP = 5;
057: public static int HEADERID_WIDTH = 20;
058: public static int HEADERTARGET_WIDTH = 20;
059: public static int HEADERFIELD_ARC = 10;
060: public static int HEADERTEXT_GAP = 3;
061: public static Color HEADERFIELD_BACKGROUND = new Color(213, 247,
062: 255);
063: public static Color HEADERFIELD_BORDER = Color.BLACK;
064: public static int HEADER_FONT_STYLE = 0;
065: public static int HEADER_FONT_SIZE = 12;
066: public static String HEADER_FONT_NAME = "Dialog";
067: public static Color HEADER_FONT_COLOR = Color.BLACK;
068: public static int EXPANDER_WIDTH = 10;
069: public static int EXPANDER_HEIGHT = 10;
070: public static int EXPANDER_LINELENGTH = 5;
071:
072: protected XQuestionGroup group;
073: protected int arc;
074: protected XExpander expander0, expander1, expander2, expander3;
075: protected Vector[] groupRuleLines = null;
076: protected Vector targetLines;
077: protected XLine sourceLine;
078:
079: public XGroupView(XRulesEditorPane ep, XQuestionGroup qg) {
080: super (ep);
081: group = qg;
082: targetLines = new Vector();
083: sourceLine = null;
084: createExpanders();
085: refreshExpanders();
086: createComponents();
087: refreshComponents();
088: headerField.repaint();
089: createRuleViews();
090: moveToFront();
091: createObservers();
092: }
093:
094: public void selectQuestion(Question question) {
095: Enumeration enumComponents = components.elements();
096: while (enumComponents.hasMoreElements()) {
097: XQuestionView questionView = (XQuestionView) enumComponents
098: .nextElement();
099: questionView.isSelected(questionView.getQuestion().equals(
100: question));
101: questionView.repaint();
102: }
103: }
104:
105: public void selectRules(boolean state) {
106: for (int i = 0; i < groupRuleLines.length; i++) {
107: Enumeration enumLines = groupRuleLines[i].elements();
108: while (enumLines.hasMoreElements()) {
109: XGroupRuleLine line = (XGroupRuleLine) enumLines
110: .nextElement();
111: XRuleView ruleView = line.getRuleView();
112: ruleView.selectXComponents(state);
113: ruleView.isSelected(state);
114: ruleView.repaint();
115: }
116: }
117: }
118:
119: public void selectRule(XRule rule) {
120: for (int i = 0; i < groupRuleLines.length; i++) {
121: Enumeration enumLines = groupRuleLines[i].elements();
122: while (enumLines.hasMoreElements()) {
123: XGroupRuleLine line = (XGroupRuleLine) enumLines
124: .nextElement();
125: XRuleView ruleView = line.getRuleView();
126: ruleView.selectXComponents(false);
127: ruleView.isSelected(ruleView.getRule().equals(rule));
128: ruleView.repaint();
129: }
130: }
131: }
132:
133: public void selectCondition(XRule rule, Condition condition) {
134: for (int i = 0; i < groupRuleLines.length; i++) {
135: Enumeration enumLines = groupRuleLines[i].elements();
136: while (enumLines.hasMoreElements()) {
137: XGroupRuleLine line = (XGroupRuleLine) enumLines
138: .nextElement();
139: XRuleView ruleView = line.getRuleView();
140: if (ruleView.getRule().equals(rule))
141: ruleView.selectCondition(condition);
142: else
143: ruleView.selectXComponents(false);
144: }
145: }
146: }
147:
148: protected void createObservers() {
149: group.getDeleteQuestionNotifier().addObserver(new Observer() {
150: public void update(Observable o, Object arg) {
151: Question question = (Question) arg;
152: removeQuestionView(question);
153: }
154: });
155: group.getAddQuestionNotifier().addObserver(new Observer() {
156: public void update(Observable o, Object arg) {
157: Question question = (Question) arg;
158: addQuestionView(question);
159: }
160: });
161: group.getNextGroupNotifier().addObserver(new Observer() {
162: public void update(Observable o, Object arg) {
163: int newGroupId = ((Integer) arg).intValue();
164: changeNextGroup(newGroupId);
165: }
166: });
167: group.getAddRuleNotifier().addObserver(new Observer() {
168: public void update(Observable o, Object arg) {
169: XRule rule = (XRule) arg;
170: addRuleView(rule);
171: }
172: });
173: group.getDeleteRuleNotifier().addObserver(new Observer() {
174: public void update(Observable o, Object arg) {
175: XRule rule = (XRule) arg;
176: deleteRuleView(rule);
177: }
178: });
179: group.getPositionQuestionNotifier().addObserver(new Observer() {
180: public void update(Observable o, Object arg) {
181: removeComponents();
182: createComponents();
183: refreshComponents();
184: }
185: });
186: }
187:
188: public void addRuleView(XRule rule) {
189: XRuleView ruleView = new XRuleView(editorPane, rule);
190: int x = getLocation().x;
191: int y = getLocation().y + getHeight() + 100;
192: ruleView.setLocation(x, y);
193: XGroupRuleLine groupRuleLine = new XGroupRuleLine(this ,
194: ruleView, editorPane);
195: ruleView.setGroupRuleLine(groupRuleLine);
196: groupRuleLine.setLocation();
197: ruleView.createSourceLine();
198: ruleView.moveToFront();
199: }
200:
201: public void deleteRuleView(XRule rule) {
202: XRuleView ruleView = null;
203: for (int i = 0; i < groupRuleLines.length && ruleView == null; i++) {
204: Enumeration enumLines = groupRuleLines[i].elements();
205: while (enumLines.hasMoreElements() && ruleView == null) {
206: XGroupRuleLine line = (XGroupRuleLine) enumLines
207: .nextElement();
208: XRuleView rv = line.getRuleView();
209: if (rv.getRule().equals(rule))
210: ruleView = rv;
211: }
212: }
213: if (ruleView != null) {
214: ruleView.remove();
215: editorPane.repaint();
216: }
217: }
218:
219: public void changeNextGroup(int newGroupId) {
220: int oldGroupId = (sourceLine != null ? sourceLine
221: .getGroupView().getGroup().getId() : -1);
222:
223: if (newGroupId == oldGroupId)
224: return;
225:
226: if (oldGroupId == -1 && newGroupId != -1) {
227: XGroupView newGroupView = editorPane
228: .getGroupView(newGroupId);
229: sourceLine = new XLine(XGroupView.this , newGroupView,
230: editorPane);
231: newGroupView.addTargetLine(sourceLine);
232: sourceLine.setLocation();
233: }
234: if (oldGroupId != -1 && newGroupId == -1) {
235: XGroupView oldGroupView = editorPane
236: .getGroupView(oldGroupId);
237: oldGroupView.removeTargetLine(sourceLine);
238: editorPane.remove(sourceLine);
239: sourceLine = null;
240: }
241: if (oldGroupId != -1 && newGroupId != -1) {
242: XGroupView oldGroupView = editorPane
243: .getGroupView(oldGroupId);
244: oldGroupView.removeTargetLine(sourceLine);
245: XGroupView newGroupView = editorPane
246: .getGroupView(newGroupId);
247: sourceLine.setGroupView(newGroupView);
248: newGroupView.addTargetLine(sourceLine);
249: sourceLine.setLocation();
250: }
251: editorPane.repaint();
252: }
253:
254: protected void removeQuestionView(Question question) {
255: XQuestionView questionView = null;
256: Enumeration enumComponents = components.elements();
257: while (enumComponents.hasMoreElements() && questionView == null) {
258: XQuestionView qv = (XQuestionView) enumComponents
259: .nextElement();
260: if (qv.getQuestion().equals(question))
261: questionView = qv;
262: }
263: if (questionView != null) {
264: questionView.remove();
265: refreshView();
266: }
267: }
268:
269: protected void addQuestionView(Question question) {
270: XQuestionView questionView = new XQuestionView(question,
271: editorPane, this );
272: components.add(questionView);
273: scrollToBottom();
274: refreshView();
275: }
276:
277: public void remove() {
278: super .remove();
279: editorPane.remove(expander0);
280: editorPane.remove(expander1);
281: editorPane.remove(expander2);
282: editorPane.remove(expander3);
283: if (sourceLine != null)
284: editorPane.remove(sourceLine);
285: for (int i = 0; i < groupRuleLines.length; i++) {
286: Enumeration enumLines = groupRuleLines[i].elements();
287: while (enumLines.hasMoreElements()) {
288: XGroupRuleLine line = (XGroupRuleLine) enumLines
289: .nextElement();
290: line.getRuleView().remove();
291: }
292: }
293: }
294:
295: protected void createPopupMenu() {
296: JMenuItem menuItem;
297: popupMenu = new JPopupMenu();
298: JLabel header = new JLabel(" Group Options");
299: header.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
300: popupMenu.add(header);
301:
302: popupMenu.addSeparator();
303: menuItem = new JMenuItem("add new group");
304: popupMenu.add(menuItem);
305: menuItem.addActionListener(new ActionListener() {
306: public void actionPerformed(ActionEvent e) {
307: survey.addNewGroup();
308: }
309: });
310: popupMenu.addSeparator();
311: menuItem = new JMenuItem("change id");
312: popupMenu.add(menuItem);
313: menuItem.addActionListener(new ActionListener() {
314: public void actionPerformed(ActionEvent e) {
315: editorPane.showGroupIdField(XGroupView.this );
316: }
317: });
318: menuItem = new JMenuItem("change name");
319: popupMenu.add(menuItem);
320: menuItem.addActionListener(new ActionListener() {
321: public void actionPerformed(ActionEvent e) {
322: editorPane.showGroupNameField(XGroupView.this );
323: }
324: });
325: menuItem = new JMenuItem("change target");
326: popupMenu.add(menuItem);
327: menuItem.addActionListener(new ActionListener() {
328: public void actionPerformed(ActionEvent e) {
329: editorPane.showGroupTargetField(XGroupView.this );
330: }
331: });
332: popupMenu.addSeparator();
333: menuItem = new JMenuItem("delete group");
334: popupMenu.add(menuItem);
335: menuItem.addActionListener(new ActionListener() {
336: public void actionPerformed(ActionEvent e) {
337: survey.deleteGroup(group);
338: }
339: });
340: menuItem = new JMenuItem("show table");
341: popupMenu.add(menuItem);
342: menuItem.addActionListener(new ActionListener() {
343: public void actionPerformed(ActionEvent e) {
344: editorFrame.showGroup(group);
345: }
346: });
347: menuItem = new JMenuItem("expand/collapse");
348: popupMenu.add(menuItem);
349: menuItem.addActionListener(new ActionListener() {
350: public void actionPerformed(ActionEvent e) {
351: setExpanded(isExpanded() ^ true);
352: }
353: });
354: popupMenu.addSeparator();
355: menuItem = new JMenuItem("add new question");
356: popupMenu.add(menuItem);
357: menuItem.addActionListener(new ActionListener() {
358: public void actionPerformed(ActionEvent e) {
359: group.addNewQuestion();
360: }
361: });
362: menuItem = new JMenuItem("add new rule");
363: menuItem.addActionListener(new ActionListener() {
364: public void actionPerformed(ActionEvent e) {
365: group.addNewRule();
366: }
367: });
368: popupMenu.add(menuItem);
369: }
370:
371: private void setRuleViewsPosition(int dh) {
372: Enumeration enumLines;
373: enumLines = groupRuleLines[1].elements();
374: while (enumLines.hasMoreElements()) {
375: XGroupRuleLine line = (XGroupRuleLine) enumLines
376: .nextElement();
377: XRuleView ruleView = line.getRuleView();
378: int x = ruleView.getLocation().x;
379: int y = ruleView.getLocation().y + dh / 2;
380: ruleView.setLocation(x, y);
381: }
382:
383: enumLines = groupRuleLines[2].elements();
384: while (enumLines.hasMoreElements()) {
385: XGroupRuleLine line = (XGroupRuleLine) enumLines
386: .nextElement();
387: XRuleView ruleView = line.getRuleView();
388: int x = ruleView.getLocation().x;
389: int y = ruleView.getLocation().y + dh;
390: ruleView.setLocation(x, y);
391: }
392:
393: enumLines = groupRuleLines[3].elements();
394: while (enumLines.hasMoreElements()) {
395: XGroupRuleLine line = (XGroupRuleLine) enumLines
396: .nextElement();
397: XRuleView ruleView = line.getRuleView();
398: int x = ruleView.getLocation().x;
399: int y = ruleView.getLocation().y + dh / 2;
400: ruleView.setLocation(x, y);
401: }
402: }
403:
404: private void setTargetLinesPosition() {
405: Enumeration enumLines = targetLines.elements();
406: while (enumLines.hasMoreElements()) {
407: XLine line = (XLine) enumLines.nextElement();
408: line.setLocation();
409: }
410: }
411:
412: protected void expand() {
413: super .expand();
414: int dh = getHeight()
415: - (int) (getScale() * (2 * topGap + headerHeight));
416: if (sourceLine != null)
417: sourceLine.setLocation();
418: setRuleViewsPosition(dh);
419: setTargetLinesPosition();
420: refreshExpanders();
421: repaint();
422: }
423:
424: protected void collapse() {
425: super .collapse();
426: int dh = getHeight() - (int) (getScale() * height);
427: if (sourceLine != null)
428: sourceLine.setLocation();
429: setRuleViewsPosition(dh);
430: setTargetLinesPosition();
431: refreshExpanders();
432: repaint();
433: }
434:
435: public void refresh() {
436: super .refresh();
437: refreshExpanders();
438: }
439:
440: public XLine getSourceLine() {
441: return sourceLine;
442: }
443:
444: public void addTargetLine(XLine line) {
445: targetLines.add(line);
446: }
447:
448: public void removeTargetLine(XLine line) {
449: targetLines.remove(line);
450: }
451:
452: public Vector getTargetLines() {
453: return targetLines;
454: }
455:
456: public void createSourceLine() {
457: int nextGroupId = group.getNextGroupId();
458: if (nextGroupId <= 0)
459: return;
460:
461: XGroupView nextGroupView = editorPane.getGroupView(nextGroupId);
462: if (nextGroupView == null)
463: return;
464: sourceLine = new XLine(this , nextGroupView, editorPane);
465: nextGroupView.addTargetLine(sourceLine);
466: }
467:
468: public void createRulesSourceLines() {
469: for (int i = 0; i < groupRuleLines.length; i++) {
470: Enumeration enumLines = groupRuleLines[i].elements();
471: while (enumLines.hasMoreElements()) {
472: XGroupRuleLine line = (XGroupRuleLine) enumLines
473: .nextElement();
474: XRuleView ruleView = line.getRuleView();
475: ruleView.createSourceLine();
476: }
477: }
478: }
479:
480: public void targetChanged(XGroupView newTarget) {
481: group.changeNextGroupId(newTarget.getGroup());
482: }
483:
484: public Point getCenterPoint() {
485: int cx = getLocation().x + getWidth() / 2;
486: int cy = getLocation().y + getHeight() / 2;
487: return new Point(cx, cy);
488: }
489:
490: public Vector[] getGroupRuleLines() {
491: return groupRuleLines;
492: }
493:
494: public XQuestionGroup getGroup() {
495: return group;
496: }
497:
498: protected void createRuleViews() {
499: groupRuleLines = new Vector[4];
500: groupRuleLines[0] = new Vector();
501: groupRuleLines[1] = new Vector();
502: groupRuleLines[2] = new Vector();
503: groupRuleLines[3] = new Vector();
504:
505: int x = 200, y = 200;
506: Enumeration enumRules = group.getRules().elements();
507: while (enumRules.hasMoreElements()) {
508: XRule rule = (XRule) enumRules.nextElement();
509: XRuleView ruleView = new XRuleView(editorPane, rule);
510: x += 400 + getLocation().x;
511: y = 400 + getLocation().y;
512: ruleView.setLocation(x, y);
513:
514: XGroupRuleLine groupRuleLine = new XGroupRuleLine(this ,
515: ruleView, editorPane);
516: ruleView.setGroupRuleLine(groupRuleLine);
517: groupRuleLine.setLocation();
518: }
519: }
520:
521: public void removeGroupRuleLine(int expanderNr, XGroupRuleLine line) {
522: groupRuleLines[expanderNr].remove(line);
523: }
524:
525: public void addGroupRuleLine(int expanderNr, XGroupRuleLine line) {
526: groupRuleLines[expanderNr].add(line);
527: }
528:
529: public void expandRuleViews(int expanderNr, boolean status) {
530: Enumeration enumLines = groupRuleLines[expanderNr].elements();
531: while (enumLines.hasMoreElements()) {
532: XGroupRuleLine line = (XGroupRuleLine) enumLines
533: .nextElement();
534: XRuleView ruleView = line.getRuleView();
535: ruleView.setVisible(status);
536: }
537: }
538:
539: protected void createExpanders() {
540: int ew = EXPANDER_WIDTH;
541: int eh = EXPANDER_HEIGHT;
542: int ll = EXPANDER_LINELENGTH;
543: Color ec = BACKGROUND_COLOR;
544: Color bc = BORDER_COLOR;
545: XExpandable ob0 = (new XExpandable() {
546: public void expand(boolean status) {
547: expandRuleViews(0, status);
548: }
549:
550: public void moveToFront() {
551: XGroupView.this .moveToFront();
552: }
553: });
554: XExpandable ob1 = (new XExpandable() {
555: public void expand(boolean status) {
556: expandRuleViews(1, status);
557: }
558:
559: public void moveToFront() {
560: XGroupView.this .moveToFront();
561: }
562: });
563: XExpandable ob2 = (new XExpandable() {
564: public void expand(boolean status) {
565: expandRuleViews(2, status);
566: }
567:
568: public void moveToFront() {
569: XGroupView.this .moveToFront();
570: }
571: });
572: XExpandable ob3 = (new XExpandable() {
573: public void expand(boolean status) {
574: expandRuleViews(3, status);
575: }
576:
577: public void moveToFront() {
578: XGroupView.this .moveToFront();
579: }
580: });
581: expander0 = new XExpander(ob0, ew, eh, ll, ec, bc, editorPane);
582: expander1 = new XExpander(ob1, ew, eh, ll, ec, bc, editorPane);
583: expander2 = new XExpander(ob2, ew, eh, ll, ec, bc, editorPane);
584: expander3 = new XExpander(ob3, ew, eh, ll, ec, bc, editorPane);
585: }
586:
587: protected void refreshExpanders() {
588: expander0.setSize();
589: expander1.setSize();
590: expander2.setSize();
591: expander3.setSize();
592:
593: int x = getLocation().x;
594: int y = getLocation().y;
595: int w = getWidth() - 1;
596: int h = getHeight() - 1;
597:
598: int ex, ey, ew, eh;
599: ew = expander0.getWidth() - 1;
600: eh = expander0.getHeight() - 1;
601: ex = x + (w - ew) / 2;
602: ey = y - eh;
603: expander0.setLocation(ex, ey);
604:
605: ew = expander1.getWidth() - 1;
606: eh = expander1.getHeight() - 1;
607: ex = x + w;
608: ey = y + (h - eh) / 2;
609: expander1.setLocation(ex, ey);
610:
611: ew = expander2.getWidth() - 1;
612: eh = expander2.getHeight() - 1;
613: ex = x + (w - ew) / 2;
614: ey = y + h;
615: expander2.setLocation(ex, ey);
616:
617: ew = expander3.getWidth() - 1;
618: eh = expander3.getHeight() - 1;
619: ex = x - ew;
620: ey = y + (h - eh) / 2;
621: expander3.setLocation(ex, ey);
622:
623: expander0.repaint();
624: expander1.repaint();
625: expander2.repaint();
626: expander3.repaint();
627: }
628:
629: protected void initVariables() {
630: super .initVariables();
631: width = WIDTH;
632: height = HEIGHT;
633: leftGap = LEFT_GAP;
634: rightGap = RIGHT_GAP;
635: topGap = TOP_GAP;
636: bottomGap = BOTTOM_GAP;
637: headerHeight = HEADER_HEIGHT;
638: headerGap = HEADER_GAP;
639: componentHeight = COMPONENT_HEIGHT;
640: componentGap = COMPONENT_GAP;
641: backgroundColor = BACKGROUND_COLOR;
642: borderColor = BORDER_COLOR;
643: arc = ARC;
644: arrowButtonY = ARROW_BUTTON_Y;
645: arrowButtonGap = ARROW_BUTTON_GAP;
646: arrowButtonWidth = ARROW_BUTTON_WIDTH;
647: arrowButtonHeight = ARROW_BUTTON_HEIGHT;
648: arrowButtonBackground = ARROW_BUTTON_BACKGROUND;
649: arrowButtonBorder = ARROW_BUTTON_BORDER;
650: headerFieldWidth = HEADERFIELD_WIDTH;
651: headerFieldHeight = HEADERFIELD_HEIGHT;
652: headerFieldGap = HEADERFIELD_GAP;
653: headerFieldArc = HEADERFIELD_ARC;
654: headerIdWidth = HEADERID_WIDTH;
655: headerTargetWidth = HEADERTARGET_WIDTH;
656: headerFieldBackground = HEADERFIELD_BACKGROUND;
657: headerTextGap = HEADERTEXT_GAP;
658: headerFieldBorder = HEADERFIELD_BORDER;
659: headerFontStyle = HEADER_FONT_STYLE;
660: headerFontName = HEADER_FONT_NAME;
661: headerFontSize = HEADER_FONT_SIZE;
662: headerFontColor = HEADER_FONT_COLOR;
663: }
664:
665: protected void createShape() {
666: int w = getWidth() - 1;
667: int h = getHeight() - 1;
668: int arc = getArc();
669: shape = new RoundRectangle2D.Double(0, 0, w, h, arc, arc);
670: }
671:
672: protected void createComponents() {
673: if (group == null)
674: return;
675:
676: components.removeAllElements();
677: Enumeration enumQuestions = group.getQuestions().elements();
678: while (enumQuestions.hasMoreElements()) {
679: Question question = (Question) enumQuestions.nextElement();
680: XQuestionView questionView = new XQuestionView(question,
681: editorPane, this );
682: components.add(questionView);
683: questionView.setWidth(getContentWidth());
684: questionView.setSize();
685: }
686: }
687:
688: public void moveToFront() {
689: super .moveToFront();
690:
691: //lines
692: if (groupRuleLines != null)
693: for (int i = 0; i < groupRuleLines.length; i++) {
694: Enumeration enumLines = groupRuleLines[i].elements();
695: while (enumLines.hasMoreElements()) {
696: XGroupRuleLine line = (XGroupRuleLine) enumLines
697: .nextElement();
698: editorPane.moveToFront(line);
699: }
700: }
701:
702: //expanders
703: if (expander0 != null)
704: editorPane.moveToFront(expander0);
705: if (expander1 != null)
706: editorPane.moveToFront(expander1);
707: if (expander2 != null)
708: editorPane.moveToFront(expander2);
709: if (expander3 != null)
710: editorPane.moveToFront(expander3);
711:
712: //rule views
713: if (groupRuleLines != null) {
714: for (int i = 0; i < groupRuleLines.length; i++) {
715: Enumeration enumLines = groupRuleLines[i].elements();
716: while (enumLines.hasMoreElements()) {
717: XGroupRuleLine line = (XGroupRuleLine) enumLines
718: .nextElement();
719: line.getRuleView().moveToFront();
720: }
721: }
722: }
723: }
724:
725: public void setLocation(int x, int y) {
726: //expanders
727: int dx = x - getLocation().x;
728: int dy = y - getLocation().y;
729: super .setLocation(x, y);
730: x = expander0.getLocation().x + dx;
731: y = expander0.getLocation().y + dy;
732: expander0.setLocation(x, y);
733: x = expander1.getLocation().x + dx;
734: y = expander1.getLocation().y + dy;
735: expander1.setLocation(x, y);
736: x = expander2.getLocation().x + dx;
737: y = expander2.getLocation().y + dy;
738: expander2.setLocation(x, y);
739: x = expander3.getLocation().x + dx;
740: y = expander3.getLocation().y + dy;
741: expander3.setLocation(x, y);
742:
743: //group rule lines
744: if (groupRuleLines != null) {
745: for (int i = 0; i < groupRuleLines.length; i++) {
746: Enumeration enumLines = groupRuleLines[i].elements();
747: while (enumLines.hasMoreElements()) {
748: XGroupRuleLine line = (XGroupRuleLine) enumLines
749: .nextElement();
750: XRuleView ruleView = line.getRuleView();
751: x = ruleView.getLocation().x + dx;
752: y = ruleView.getLocation().y + dy;
753: ruleView.setLocation(x, y);
754: line.setLocation();
755: }
756: }
757: }
758:
759: //source line
760: if (sourceLine != null)
761: sourceLine.setLocation();
762:
763: //target line
764: Enumeration enumTargetLines = targetLines.elements();
765: while (enumTargetLines.hasMoreElements()) {
766: XLine line = (XLine) enumTargetLines.nextElement();
767: line.setLocation();
768: }
769: }
770:
771: public String getHeaderId() {
772: return (group != null ? String.valueOf(group.getId()) : "");
773: }
774:
775: public String getHeaderName() {
776: return (group != null ? group.getName() : "");
777: }
778:
779: public String getHeaderTarget() {
780: int targetId = group.getNextGroupId();
781: return (targetId > 0 ? String.valueOf(targetId) : "N");
782: }
783:
784: public void paint(Graphics g) {
785: Graphics2D g2d = (Graphics2D) g;
786: paintShape(g2d);
787: }
788:
789: public int getArc() {
790: return (int) (getScale() * arc);
791: }
792:
793: public void setArc(int a) {
794: arc = (int) ((double) a / getScale());
795: }
796:
797: public void mouseClicked(MouseEvent e) {
798: if (e.getClickCount() == 2)
799: editorFrame.showGroup(group);
800: else
801: super.mouseClicked(e);
802: }
803:
804: }
|