PageRenderTime 24ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/projects/argouml-0.34/argouml/src/argouml-core-diagrams-activity2/src/org/argouml/activity2/diagram/FigCompartment.java

https://gitlab.com/essere.lab.public/qualitas.class-corpus
Java | 148 lines | 99 code | 19 blank | 30 comment | 7 complexity | 4dc483960ee1f0685ad97d1fb291d898 MD5 | raw file
  1. /* $Id: $
  2. *****************************************************************************
  3. * Copyright (c) 2011 Contributors - see below
  4. * All rights reserved. This program and the accompanying materials
  5. * are made available under the terms of the Eclipse Public License v1.0
  6. * which accompanies this distribution, and is available at
  7. * http://www.eclipse.org/legal/epl-v10.html
  8. *
  9. * Contributors:
  10. * Bob Tarling
  11. *****************************************************************************
  12. */
  13. package org.argouml.activity2.diagram;
  14. import java.awt.Dimension;
  15. import java.awt.Rectangle;
  16. import java.util.Arrays;
  17. import java.util.List;
  18. import org.argouml.model.AddAssociationEvent;
  19. import org.argouml.model.AssociationChangeListener;
  20. import org.argouml.model.InvalidElementException;
  21. import org.argouml.model.Model;
  22. import org.argouml.model.RemoveAssociationEvent;
  23. import org.argouml.notation2.NotationType;
  24. import org.argouml.uml.diagram.DiagramSettings;
  25. import org.tigris.gef.presentation.Fig;
  26. /**
  27. * The UML defines a Name Compartment, and a List Compartment.
  28. * This class implements the latter.<p>
  29. *
  30. * A List Compartment is a boxed compartment,
  31. * containing vertically stacked figs,
  32. * which is common to e.g. a stereotypes compartment, operations
  33. * compartment and an attributes compartment.<p>
  34. *
  35. * @author Bob Tarling
  36. */
  37. class FigCompartment extends FigComposite implements AssociationChangeListener {
  38. public FigCompartment(
  39. final Object owner,
  40. final Rectangle bounds,
  41. final DiagramSettings settings,
  42. final Object metaType,
  43. final String propertyName) {
  44. this(owner, bounds, settings,
  45. Arrays.asList(new Object[] {metaType}),
  46. propertyName);
  47. }
  48. /**
  49. * @param owner the model element that owns the compartment
  50. * @param bounds the initial bounds of the compartment
  51. * @param settings the diagram settings
  52. * @param metaType the different metatype that can be displayed in the compartment
  53. */
  54. public FigCompartment(
  55. final Object owner,
  56. final Rectangle bounds,
  57. final DiagramSettings settings,
  58. final List<Object> metaTypes,
  59. final String propertyName) {
  60. super(owner, settings);
  61. Model.getFacade().getModelElementContents(owner);
  62. for (Object element
  63. : Model.getFacade().getModelElementContents(owner)) {
  64. if (metaTypes.contains(element.getClass())) {
  65. try {
  66. int y = bounds.y + getTopMargin();
  67. int x = bounds.x + getLeftMargin();
  68. Rectangle childBounds = new Rectangle(x, y, 0, 0);
  69. FigNotation fn = new FigNotation(
  70. element, childBounds, settings, NotationType.NAME);
  71. addFig(fn);
  72. y += fn.getHeight();
  73. } catch (InvalidElementException e) {
  74. }
  75. }
  76. }
  77. Model.getPump().addModelEventListener(
  78. (AssociationChangeListener) this, owner, propertyName);
  79. // TODO: Remove listeners for add/remove events
  80. }
  81. public FigCompartment(
  82. final Object owner,
  83. final DiagramSettings settings) {
  84. super(owner, settings);
  85. }
  86. @Override
  87. public Dimension getMinimumSize() {
  88. int minWidth = 0;
  89. int minHeight = 0;
  90. for (Object f : getFigs()) {
  91. Fig fig = (Fig) f;
  92. minWidth = Math.max(fig.getMinimumSize().width, minWidth);
  93. minHeight += fig.getMinimumSize().height;
  94. }
  95. minHeight += getTopMargin() + getBottomMargin();
  96. minWidth += getLeftMargin() + getRightMargin();
  97. return new Dimension(minWidth, minHeight);
  98. }
  99. @Override
  100. protected void positionChildren() {
  101. int w = _w - (getLeftMargin() + getRightMargin());
  102. int x = _x + getLeftMargin();
  103. int y = _y + getTopMargin();
  104. for (Object f : getFigs()) {
  105. Fig fig = (Fig) f;
  106. fig.setBounds(x, y, w, fig.getMinimumSize().height);
  107. y += fig.getHeight();
  108. }
  109. }
  110. public void elementAdded(AddAssociationEvent evt) {
  111. Object element = evt.getNewValue();
  112. Rectangle childBounds = new Rectangle(getX() + getHeight(), getY(), 0, 0);
  113. FigNotation fn = new FigNotation(
  114. element, childBounds, getDiagramSettings(), NotationType.NAME);
  115. addFig(fn);
  116. calcBounds();
  117. }
  118. public void elementRemoved(RemoveAssociationEvent evt) {
  119. Object element = evt.getOldValue();
  120. for (Object f : getFigs()) {
  121. Fig fig = (Fig) f;
  122. if (fig.getOwner() == element) {
  123. removeFig(fig);
  124. calcBounds();
  125. return;
  126. }
  127. }
  128. }
  129. }