package pointGroups.gui;

import java.awt.BorderLayout;

import javax.swing.JPanel;

import pointGroups.geometry.Edge;
import pointGroups.geometry.Point;
import pointGroups.geometry.Schlegel;
import pointGroups.gui.event.EventDispatcher;
import pointGroups.gui.event.types.SchlegelResultEvent;
import pointGroups.gui.event.types.SchlegelResultHandler;
import pointGroups.util.jreality.JRealityUtility;
import de.jreality.scene.Geometry;


public class SchlegelView
  extends JPanel
  implements SchlegelResultHandler
{
  private static final long serialVersionUID = -3642299900579728806L;

  private final EventDispatcher dispatcher = EventDispatcher.get();

  protected final UiViewer uiViewer = new UiViewer(this);
  protected Schlegel lastSchlegel;

  public SchlegelView() {
    super();

    setLayout(new BorderLayout());

    dispatcher.addHandler(SchlegelResultHandler.class, this);
  }

  public void dispose() {
    uiViewer.dispose();
  }

  @Override
  public void onSchlegelResultEvent(SchlegelResultEvent event) {
    lastSchlegel = event.getResult();

    Point[] points = lastSchlegel.points;
    Edge<Integer, Integer>[] edges = lastSchlegel.edgesViaIndices;
    Geometry geom = JRealityUtility.generateGraph(points, edges);

    uiViewer.setGeometry(geom);
  }
}

@@ -227,24 +227,140 @@
 Dispatcher;%0A
+import pointGroups.gui.event.types.DimensionSwitchEvent;%0Aimport pointGroups.gui.event.types.DimensionSwitchHandler;%0A
 import point
@@ -399,24 +399,24 @@
 esultEvent;%0A
-
 import point
@@ -625,16 +625,40 @@
 tHandler
+, DimensionSwitchHandler
 %0A%7B%0A  pri
@@ -1024,16 +1024,79 @@
  this);%0A
+    dispatcher.addHandler(DimensionSwitchHandler.class, this);%0A
   %7D%0A%0A  p
@@ -1435,24 +1435,24 @@
 s, edges);%0A%0A
-
     uiViewer
@@ -1474,11 +1474,228 @@
 om);%0A  %7D
+%0A%0A  @Override%0A  public void onDimensionSwitchEvent(DimensionSwitchEvent event) %7B%0A    if (event.switchedTo3D()) %7B%0A      uiViewer.set2DMode();%0A    %7D%0A%0A    if (event.switchedTo4D()) %7B%0A      uiViewer.set3DMode();%0A    %7D%0A  %7D
 %0A%7D%0A

switch UiViewer modes on dimensions change