|
@@ -1,12 +1,16 @@
|
|
package ui.view.holarchy;
|
|
package ui.view.holarchy;
|
|
|
|
|
|
|
|
+import java.awt.BasicStroke;
|
|
import java.awt.Color;
|
|
import java.awt.Color;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics;
|
|
import java.awt.Graphics2D;
|
|
import java.awt.Graphics2D;
|
|
|
|
+import java.awt.Stroke;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseEvent;
|
|
import java.awt.event.MouseListener;
|
|
import java.awt.event.MouseListener;
|
|
import java.awt.geom.Ellipse2D;
|
|
import java.awt.geom.Ellipse2D;
|
|
import java.util.ArrayList;
|
|
import java.util.ArrayList;
|
|
|
|
+import java.util.Collection;
|
|
|
|
+import java.util.Collections;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
import java.util.List;
|
|
import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
@@ -74,17 +78,35 @@ public class HolarchyPanel extends JPanel {
|
|
this.sep2.setBounds(0, 235, 60, 1);
|
|
this.sep2.setBounds(0, 235, 60, 1);
|
|
this.add(this.sep2);
|
|
this.add(this.sep2);
|
|
|
|
|
|
- this.ellipses = new ArrayList();
|
|
|
|
- this.ellipsesChild = new ArrayList();
|
|
|
|
|
|
+ this.ellipses = new ArrayList<Map<Ellipse2D, Holon>>();
|
|
|
|
+ this.ellipsesChild = new ArrayList<Map<Ellipse2D, Map<Ellipse2D, Holon>>>();
|
|
this.displayedLayer = 0;
|
|
this.displayedLayer = 0;
|
|
- this.layeredHolons = new ArrayList();
|
|
|
|
- this.surroundings = new ArrayList();
|
|
|
|
- this.coloredHolons = new HashMap();
|
|
|
|
|
|
+ this.layeredHolons = new ArrayList<ArrayList<Holon>>();
|
|
|
|
+ this.surroundings = new ArrayList<Ellipse2D>();
|
|
|
|
+ this.coloredHolons = new HashMap<Holon, Color>();
|
|
getAllHolons();
|
|
getAllHolons();
|
|
setSliderMax(this.layeredHolons.size());
|
|
setSliderMax(this.layeredHolons.size());
|
|
createAllLayers();
|
|
createAllLayers();
|
|
generateColorSet();
|
|
generateColorSet();
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ public void update() {
|
|
|
|
+ ArrayList<ArrayList<Holon>> layeredHolonsCpy = new ArrayList<ArrayList<Holon>>();
|
|
|
|
+ copyList(layeredHolonsCpy, this.layeredHolons);
|
|
|
|
+ this.layeredHolons.clear();
|
|
|
|
+ getAllHolons();
|
|
|
|
+ //the holarchy did not change
|
|
|
|
+ if(compareAllHolons(layeredHolonsCpy))
|
|
|
|
+ return;
|
|
|
|
+ this.ellipses = new ArrayList<Map<Ellipse2D, Holon>>();
|
|
|
|
+ this.ellipsesChild = new ArrayList<Map<Ellipse2D, Map<Ellipse2D, Holon>>>();
|
|
|
|
+ this.surroundings = new ArrayList<Ellipse2D>();
|
|
|
|
+ this.coloredHolons = new HashMap<Holon, Color>();
|
|
|
|
+ setSliderMax(this.layeredHolons.size());
|
|
|
|
+ createAllLayers();
|
|
|
|
+ generateColorSet();
|
|
|
|
+ repaint();
|
|
|
|
+ }
|
|
|
|
|
|
public void paintComponent(Graphics g) {
|
|
public void paintComponent(Graphics g) {
|
|
super.paintComponent(g);
|
|
super.paintComponent(g);
|
|
@@ -99,21 +121,19 @@ public class HolarchyPanel extends JPanel {
|
|
public void paintLayer(Graphics g, int layer) {
|
|
public void paintLayer(Graphics g, int layer) {
|
|
this.displayedLayer = layer;
|
|
this.displayedLayer = layer;
|
|
Graphics2D g2 = (Graphics2D) g;
|
|
Graphics2D g2 = (Graphics2D) g;
|
|
|
|
+ Stroke stroke = new BasicStroke(3f);
|
|
|
|
+ g2.setStroke(stroke);
|
|
|
|
|
|
//resize panel
|
|
//resize panel
|
|
Ellipse2D surrounding = this.surroundings.get(this.displayedLayer);
|
|
Ellipse2D surrounding = this.surroundings.get(this.displayedLayer);
|
|
if(surrounding.getWidth() > this.getWidth()) {
|
|
if(surrounding.getWidth() > this.getWidth()) {
|
|
this.setSize((int) surrounding.getWidth(), this.getHeight());
|
|
this.setSize((int) surrounding.getWidth(), this.getHeight());
|
|
-// this.parentFrame.resizeScrollPane((int) surrounding.getWidth(), this.getHeight());
|
|
|
|
}
|
|
}
|
|
if(surrounding.getHeight() > this.getHeight()) {
|
|
if(surrounding.getHeight() > this.getHeight()) {
|
|
this.setSize(this.getWidth(), (int) surrounding.getHeight());
|
|
this.setSize(this.getWidth(), (int) surrounding.getHeight());
|
|
-// this.parentFrame.resizeScrollPane(this.getWidth(), (int) surrounding.getHeight());
|
|
|
|
}
|
|
}
|
|
|
|
|
|
-// System.out.println("painting layer "+layer+"#elements="+this.ellipses.get(layer).size());
|
|
|
|
for(Ellipse2D e : this.ellipses.get(this.displayedLayer).keySet()) {
|
|
for(Ellipse2D e : this.ellipses.get(this.displayedLayer).keySet()) {
|
|
-// System.out.println("paint ellipse");
|
|
|
|
//draw ellipse
|
|
//draw ellipse
|
|
g2.setColor( this.coloredHolons.get(this.ellipses.get(this.displayedLayer).get(e)) );
|
|
g2.setColor( this.coloredHolons.get(this.ellipses.get(this.displayedLayer).get(e)) );
|
|
g2.draw(e);
|
|
g2.draw(e);
|
|
@@ -127,11 +147,9 @@ public class HolarchyPanel extends JPanel {
|
|
|
|
|
|
public void createAllLayers() {
|
|
public void createAllLayers() {
|
|
for(int layer=0; layer<this.layeredHolons.size(); layer++) {
|
|
for(int layer=0; layer<this.layeredHolons.size(); layer++) {
|
|
-// System.out.println("creating layer "+layer+" #elements="+this.layeredHolons.get(layer).size());
|
|
|
|
- this.ellipsesChild.add(layer, new HashMap());
|
|
|
|
-// System.out.println("creating ellipse");
|
|
|
|
|
|
+ this.ellipsesChild.add(layer, new HashMap<Ellipse2D, Map<Ellipse2D, Holon>>());
|
|
//estimate the required area, center if it is smaller than the panels size
|
|
//estimate the required area, center if it is smaller than the panels size
|
|
- Ellipse2D surrounding = estimateSurrounding(60, 0, layer);
|
|
|
|
|
|
+ Ellipse2D surrounding = estimateSurrounding(60, 0, layer, this.minRadius);
|
|
double newX = surrounding.getX(), newY = surrounding.getY();
|
|
double newX = surrounding.getX(), newY = surrounding.getY();
|
|
if(surrounding.getWidth() <= this.getWidth()) {
|
|
if(surrounding.getWidth() <= this.getWidth()) {
|
|
double diff = this.getWidth() - surrounding.getWidth();
|
|
double diff = this.getWidth() - surrounding.getWidth();
|
|
@@ -146,8 +164,6 @@ public class HolarchyPanel extends JPanel {
|
|
|
|
|
|
//create ellipse for each holon
|
|
//create ellipse for each holon
|
|
this.ellipses.add(layer, placeHolons(this.layeredHolons.get(layer), surrounding, true));
|
|
this.ellipses.add(layer, placeHolons(this.layeredHolons.get(layer), surrounding, true));
|
|
-// System.out.println("paint surrounding width="+surrounding.getWidth()+" height="+surrounding.getHeight());
|
|
|
|
-// System.out.println("pending holons "+this.ellipses.get(layer).size());
|
|
|
|
for(Ellipse2D e : this.ellipses.get(layer).keySet()) {
|
|
for(Ellipse2D e : this.ellipses.get(layer).keySet()) {
|
|
//draw child ellipses and add them to global list
|
|
//draw child ellipses and add them to global list
|
|
Map<Ellipse2D, Holon> ellipses2 = placeHolons(ellipses.get(layer).get(e).childHolons, e, false);
|
|
Map<Ellipse2D, Holon> ellipses2 = placeHolons(ellipses.get(layer).get(e).childHolons, e, false);
|
|
@@ -169,7 +185,7 @@ public class HolarchyPanel extends JPanel {
|
|
double width = surrounding.getWidth();
|
|
double width = surrounding.getWidth();
|
|
double height = surrounding.getHeight();
|
|
double height = surrounding.getHeight();
|
|
|
|
|
|
- Map<Ellipse2D, Holon> shapes = new HashMap();
|
|
|
|
|
|
+ Map<Ellipse2D, Holon> shapes = new HashMap<Ellipse2D, Holon>();
|
|
int abord = 0;
|
|
int abord = 0;
|
|
int i = 0;
|
|
int i = 0;
|
|
|
|
|
|
@@ -196,13 +212,11 @@ public class HolarchyPanel extends JPanel {
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
-// System.out.println("try to add ellipse "+i+" x="+e.getX()+" y="+e.getY());
|
|
|
|
|
|
|
|
abord++;
|
|
abord++;
|
|
//if not add the ellipse to the already existing ones
|
|
//if not add the ellipse to the already existing ones
|
|
if(!overlap) {
|
|
if(!overlap) {
|
|
shapes.put(e, h);
|
|
shapes.put(e, h);
|
|
-// System.out.println("added ellipse "+i+" at ("+e.getX()+", "+e.getY()+")");
|
|
|
|
i++;
|
|
i++;
|
|
abord = 0;
|
|
abord = 0;
|
|
}
|
|
}
|
|
@@ -211,43 +225,35 @@ public class HolarchyPanel extends JPanel {
|
|
return shapes;
|
|
return shapes;
|
|
}
|
|
}
|
|
|
|
|
|
- public Ellipse2D estimateSurrounding(int x, int y, int layer) {
|
|
|
|
- if(this.layeredHolons == null || this.layeredHolons.size() < layer+1)
|
|
|
|
|
|
+ public Ellipse2D estimateSurrounding(int x, int y, int layer, int radius) {
|
|
|
|
+ if(this.layeredHolons == null || this.layeredHolons.size() <= layer)
|
|
return new Ellipse2D.Double(x, y, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
|
return new Ellipse2D.Double(x, y, Integer.MAX_VALUE, Integer.MAX_VALUE);
|
|
|
|
|
|
int w = 0;
|
|
int w = 0;
|
|
for(Holon h : this.layeredHolons.get(layer)) {
|
|
for(Holon h : this.layeredHolons.get(layer)) {
|
|
- w += this.minRadius * (h.getChildCount()+1);
|
|
|
|
|
|
+ w += radius * (h.getChildCount()+1);
|
|
}
|
|
}
|
|
w = w * 4 + 10;
|
|
w = w * 4 + 10;
|
|
|
|
|
|
- return new Ellipse2D.Double(x, y, w, w);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- /**
|
|
|
|
- * @deprecated
|
|
|
|
- * calculate distance between the two specified ellipses and check if they overlap
|
|
|
|
- * @param e1
|
|
|
|
- * @param e2
|
|
|
|
- * @return
|
|
|
|
- */
|
|
|
|
- public boolean overlap(Ellipse2D e1, Ellipse2D e2) {
|
|
|
|
- int dist = (int) Math.sqrt( Math.pow((e1.getCenterX()+e2.getCenterX()), 2) + Math.pow((e1.getCenterY()+e2.getCenterY()), 2) );
|
|
|
|
|
|
+ if(w > this.getHeight() - 50) {
|
|
|
|
+ int div = radius / (w/(this.getHeight()-50));
|
|
|
|
+ if(div == radius)
|
|
|
|
+ div--;
|
|
|
|
+ return estimateSurrounding(x, y, layer, div );
|
|
|
|
+ }
|
|
|
|
|
|
- if(dist < e1.getWidth()/2 + e2.getWidth()/2 + 10)
|
|
|
|
- return true;
|
|
|
|
- return false;
|
|
|
|
|
|
+ return new Ellipse2D.Double(x, y, w, w);
|
|
}
|
|
}
|
|
|
|
|
|
public void getAllHolons() {
|
|
public void getAllHolons() {
|
|
- this.layeredHolons.add(this.root.childHolons);
|
|
|
|
|
|
+ this.layeredHolons.add((ArrayList<Holon>) this.root.childHolons.clone());
|
|
|
|
|
|
//TODO: potential infinit loop
|
|
//TODO: potential infinit loop
|
|
while(true) {
|
|
while(true) {
|
|
//new layer
|
|
//new layer
|
|
- ArrayList<Holon> children = new ArrayList();
|
|
|
|
|
|
+ ArrayList<Holon> children = new ArrayList<Holon>();
|
|
for(Holon h : this.layeredHolons.get(this.layeredHolons.size()-1)) {
|
|
for(Holon h : this.layeredHolons.get(this.layeredHolons.size()-1)) {
|
|
- children.addAll(h.childHolons);
|
|
|
|
|
|
+ children.addAll((Collection<? extends Holon>) h.childHolons.clone());
|
|
}
|
|
}
|
|
if(children.size() > 0) {
|
|
if(children.size() > 0) {
|
|
this.layeredHolons.add(children);
|
|
this.layeredHolons.add(children);
|
|
@@ -281,8 +287,7 @@ public class HolarchyPanel extends JPanel {
|
|
numColors = this.layeredHolons.get(layer).size();
|
|
numColors = this.layeredHolons.get(layer).size();
|
|
if(numColors <= 0)
|
|
if(numColors <= 0)
|
|
continue;
|
|
continue;
|
|
-// System.out.println("generating colors for "+numColors+" holons");
|
|
|
|
- ArrayList<Color> colors = new ArrayList();
|
|
|
|
|
|
+ ArrayList<Color> colors = new ArrayList<Color>();
|
|
float hue = Random.nextFloatInRange(0, 1);
|
|
float hue = Random.nextFloatInRange(0, 1);
|
|
for(float i = 0; i < 360; i += 360 / numColors) {
|
|
for(float i = 0; i < 360; i += 360 / numColors) {
|
|
hue += 0.618033988749895f;
|
|
hue += 0.618033988749895f;
|
|
@@ -291,12 +296,36 @@ public class HolarchyPanel extends JPanel {
|
|
Color c = Color.getHSBColor(hue%1, saturation, lightness);
|
|
Color c = Color.getHSBColor(hue%1, saturation, lightness);
|
|
|
|
|
|
colors.add(c);
|
|
colors.add(c);
|
|
-// System.out.println("generated color "+c.toString()+" by h "+hue+" sat "+saturation+" light "+lightness);
|
|
|
|
}
|
|
}
|
|
|
|
|
|
for(int j=0;j<this.layeredHolons.get(layer).size(); j++) {
|
|
for(int j=0;j<this.layeredHolons.get(layer).size(); j++) {
|
|
this.coloredHolons.put(this.layeredHolons.get(layer).get(j), colors.get(j));
|
|
this.coloredHolons.put(this.layeredHolons.get(layer).get(j), colors.get(j));
|
|
-// System.out.println("generated color "+colors.get(j).toString()+" for holon "+this.layeredHolons.get(layer).get(j));
|
|
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * compares list with this.layeredHolons
|
|
|
|
+ * @param list
|
|
|
|
+ * @return true if list is equivalent to this.layeredHolons
|
|
|
|
+ */
|
|
|
|
+ private boolean compareAllHolons(ArrayList<ArrayList<Holon>> list) {
|
|
|
|
+ if(this.layeredHolons.size() != list.size())
|
|
|
|
+ return false;
|
|
|
|
+ for(int i=0; i<this.layeredHolons.size(); i++) {
|
|
|
|
+ if(this.layeredHolons.get(i).size() != list.get(i).size())
|
|
|
|
+ return false;
|
|
|
|
+ if(!list.get(i).containsAll(this.layeredHolons.get(i)))
|
|
|
|
+ return false;
|
|
|
|
+ }
|
|
|
|
+ return true;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private void copyList(ArrayList<ArrayList<Holon>> dest, ArrayList<ArrayList<Holon>> src) {
|
|
|
|
+ for(int i=0; i<src.size(); i++) {
|
|
|
|
+ dest.add(new ArrayList<Holon>());
|
|
|
|
+ for(int j=0; j<src.get(i).size(); j++) {
|
|
|
|
+ dest.get(i).add(src.get(i).get(j));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@@ -305,7 +334,6 @@ public class HolarchyPanel extends JPanel {
|
|
|
|
|
|
@Override
|
|
@Override
|
|
public void mouseClicked(MouseEvent arg0) {
|
|
public void mouseClicked(MouseEvent arg0) {
|
|
-// System.out.println("mouse click at ("+arg0.getX()+","+arg0.getY()+")");
|
|
|
|
//Get clicked Holon
|
|
//Get clicked Holon
|
|
for(Ellipse2D e : ellipses.get(displayedLayer).keySet()) {
|
|
for(Ellipse2D e : ellipses.get(displayedLayer).keySet()) {
|
|
if(e.contains(arg0.getX(), arg0.getY())) {
|
|
if(e.contains(arg0.getX(), arg0.getY())) {
|
|
@@ -317,14 +345,12 @@ public class HolarchyPanel extends JPanel {
|
|
//child was clicked
|
|
//child was clicked
|
|
child = true;
|
|
child = true;
|
|
parentFrame.displayHolonInfos(ellipsesChild.get(displayedLayer).get(e).get(e2));
|
|
parentFrame.displayHolonInfos(ellipsesChild.get(displayedLayer).get(e).get(e2));
|
|
-// System.out.println("child holon "+ellipsesChild.get(e).get(e2).name+" was clicked");
|
|
|
|
break;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
if(!child) {
|
|
if(!child) {
|
|
//no child was clicked
|
|
//no child was clicked
|
|
parentFrame.displayHolonInfos(ellipses.get(displayedLayer).get(e));
|
|
parentFrame.displayHolonInfos(ellipses.get(displayedLayer).get(e));
|
|
-// System.out.println("holon "+ellipses.get(e).name+" was clicked");
|
|
|
|
}
|
|
}
|
|
break;
|
|
break;
|
|
}
|
|
}
|