Coverage Summary for Class: CircleLayout (it.polimi.ingsw.Client.GUI)

Class Class, % Method, % Branch, % Line, %
CircleLayout 0% (0/1) 0% (0/7) 0% (0/4) 0% (0/32)


1 package it.polimi.ingsw.Client.GUI; 2  3 import java.awt.*; 4  5 public class CircleLayout implements LayoutManager { 6  7  /** 8  * For compatibility with LayoutManager interface 9  */ 10  public void addLayoutComponent(String name, Component comp) { 11  } 12  13  /** 14  * For compatibility with LayoutManager interface 15  */ 16  public void removeLayoutComponent(Component comp) { 17  } 18  19  /** 20  * Returns this CircleLayout's preferred size based on its Container 21  * 22  * @param target This CircleLayout's target container 23  * @return The preferred size 24  */ 25  26  public Dimension preferredLayoutSize(Container target) { 27  return target.getSize(); 28  } 29  30  /** 31  * Returns this CircleLayout's minimum size based on its Container 32  * 33  * @param target This CircleLayout's target container 34  * @return The minimum size 35  */ 36  public Dimension minimumLayoutSize(Container target) { 37  return target.getSize(); 38  } 39  40  /** 41  * Arranges the parent's Component objects in a Circle. 42  */ 43  public void layoutContainer(Container parent) { 44  int x, y, w, h, s, c; 45  int n = parent.getComponentCount(); 46  double parentWidth = parent.getSize().width; 47  double parentHeight = parent.getSize().height; 48  Insets insets = parent.getInsets(); 49  int centerX = ((int) (parentWidth - (insets.left + insets.right)) / 2) - 100; 50  int centerY = ((int) (parentHeight - (insets.top + insets.bottom)) / 2) - 75; 51  52  Component comp; 53  Dimension compPS; 54  if (n == 1) { 55  comp = parent.getComponent(0); 56  x = centerX; 57  y = centerY; 58  compPS = comp.getPreferredSize(); 59  w = compPS.width; 60  h = compPS.height; 61  comp.setBounds(x, y, w, h); 62  } else { 63  double r = (Math.min(parentWidth - (insets.left + insets.right), parentHeight 64  - (insets.top + insets.bottom))) / 2; 65  r *= 0.75; // Multiply by .75 to account for extreme right and bottom 66  // Components 67  for (int i = 0; i < n; i++) { 68  comp = parent.getComponent(i); 69  compPS = comp.getPreferredSize(); 70  c = (int) (r * Math.cos(2 * i * Math.PI / n)); 71  s = (int) (r * Math.sin(2 * i * Math.PI / n)); 72  x = c + centerX; 73  y = s + centerY; 74  75  w = compPS.width; 76  h = compPS.height; 77  78  comp.setBounds(x, y, w, h); 79  } 80  } 81  82  } 83  84  /** 85  * Returns a String representation of this CircleLayout. 86  * 87  * @return A String that represents this CircleLayout 88  */ 89  public String toString() { 90  return this.getClass().getName(); 91  } 92  93 }