package svgdevicestest.maps.SVG;
|
|
|
import art.library.gui.flat.FlatPanel;
|
import art.library.gui.flat.FlatTabbedPane;
|
import art.library.gui.flat.listeners.FlatTabbedPaneListener;
|
import art.library.interop.serialization.Serialization;
|
import art.library.utils.ArticJavaManagerCompiler;
|
import com.kitfox.svg.SVGDiagram;
|
import java.awt.BorderLayout;
|
import java.awt.Component;
|
import java.lang.reflect.Constructor;
|
import java.lang.reflect.Method;
|
import java.util.ArrayList;
|
import java.util.List;
|
|
public class PanelMapSchema extends FlatPanel
|
{
|
//-1 if not use tabIndex
|
public int tabIndex = -1;
|
private List<ModelFile> lmodelFile = new ArrayList<ModelFile>();
|
private List<Object> linstance = new ArrayList<Object>();
|
private List<PanelScaleVectorGraphics> lPanelScaleVectorGraphics = new ArrayList<PanelScaleVectorGraphics>();
|
|
public PanelMapSchema()
|
{
|
initialise();
|
reload();
|
}
|
|
|
public void MapSchemaWindowPanel(ModelFile modelFile)
|
{
|
initialise();
|
this.lmodelFile = new ArrayList<ModelFile>();
|
this.lmodelFile.add(modelFile);
|
reload();
|
}
|
|
public void MapSchemaWindowPanel(List<ModelFile> lmodelFile)
|
{
|
initialise();
|
this.lmodelFile = lmodelFile;
|
reload();
|
}
|
|
|
public void timer()
|
{
|
for (Object instance : linstance)
|
{
|
try
|
{
|
Method method = instance.getClass().getDeclaredMethod("status");
|
method.invoke(instance);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
for (PanelScaleVectorGraphics panelScaleVectorGraphics : lPanelScaleVectorGraphics)
|
{
|
try
|
{
|
panelScaleVectorGraphics.repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|
|
|
public void edit(boolean value)
|
{
|
}
|
|
|
public void grants()
|
{
|
}
|
|
|
public void reload()
|
{
|
try
|
{
|
List<ModelFile> lmodelFile = this.lmodelFile;
|
|
this.removeAll();
|
this.linstance.clear();
|
this.lPanelScaleVectorGraphics.clear();
|
|
if (lmodelFile.size() == 1)
|
{
|
for (ModelFile modelfile : lmodelFile)
|
{
|
try
|
{
|
this.add(createMap(modelfile), BorderLayout.CENTER);
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
}
|
else
|
{
|
FlatTabbedPane flatTabbedPane = new FlatTabbedPane();
|
{
|
flatTabbedPane.setFlatTabbedPaneListener(new MyFlatTabbedPaneListener()
|
{
|
@Override
|
public void close(FlatTabbedPane flatTabbedPane, int index, Component component)
|
{
|
flatTabbedPane.removeTab(component);
|
}
|
});
|
|
for (ModelFile modelfile : lmodelFile)
|
{
|
flatTabbedPane.addTabClose(modelfile.name, createMap(modelfile));
|
}
|
|
flatTabbedPane.allowTitleChange(false);
|
}
|
|
|
this.add(flatTabbedPane, BorderLayout.CENTER);
|
}
|
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
|
|
|
private void initialise()
|
{
|
this.setLayout(new BorderLayout());
|
}
|
|
public List<ModelFile> getLmodelFile()
|
{
|
return lmodelFile;
|
}
|
|
private PanelScaleVectorGraphics createMap(ModelFile modelfile) throws Exception
|
{
|
ModelFile copyModelFile = Serialization.clone(modelfile);
|
|
byte[] dataSVG = modelfile.dataSVG;
|
PanelScaleVectorGraphics panelScaleVectorGraphics = new PanelScaleVectorGraphics();
|
panelScaleVectorGraphics.reload(dataSVG);
|
lPanelScaleVectorGraphics.add(panelScaleVectorGraphics);
|
|
try
|
{
|
copyModelFile.extension = "java";
|
copyModelFile.folder = "java";
|
byte[] dataJAVA = modelfile.dataJAVA;
|
Class clazz = ArticJavaManagerCompiler.getRuntimeClass("art.runtime.maps", copyModelFile.name, new String(dataJAVA));
|
Constructor constructor = clazz.getDeclaredConstructor(new Class[]{SVGDiagram.class});
|
Object instance = constructor.newInstance(new Object[]{panelScaleVectorGraphics.getDiagram()});
|
this.linstance.add(instance);
|
Method method = instance.getClass().getDeclaredMethod("status");
|
method.invoke(instance);
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
|
return panelScaleVectorGraphics;
|
|
}
|
|
|
|
private class MyFlatTabbedPaneListener extends FlatTabbedPaneListener
|
{
|
|
@Override
|
public void close(FlatTabbedPane flatTabbedPane, int index, Component component){}
|
@Override
|
public void open(FlatTabbedPane flatTabbedPane, int index, Component component){}
|
@Override
|
public void name(FlatTabbedPane flatTabbedPane, int index, Component component, String name){}
|
}
|
|
|
}
|