package svgdevicestest.maps.SVG;
|
|
import art.client.GUI.components.pictures.svg.PanelScaleVectorGraphics;
|
import art.client.controllers.ServerServiceName;
|
import art.client.invokes.Invokes;
|
import art.client.models.ModelGUI;
|
import art.client.models.Shared;
|
import art.library.gui.flat.FlatPanel;
|
import art.library.gui.flat.FlatTitle;
|
import art.library.interop.InteropParameter;
|
import art.library.interop.InteropParameters;
|
import art.library.interop.InteropResponse;
|
import art.library.model.devices.Device;
|
import art.library.model.devices.DeviceGraphics;
|
import art.library.model.devices.vms.general.VmsGeneral;
|
import com.kitfox.svg.SVGDiagram;
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.lang.reflect.Method;
|
|
public class MyPanelDeviceStatusSvg extends FlatPanel
|
{
|
private Device device;
|
private PanelScaleVectorGraphics panelScaleVectorGraphics;
|
private int dimensionHeight;
|
private int dimensionWidth;
|
private String titleString;
|
private boolean loadedSVG = false;
|
private FlatTitle title;
|
private Object scriptClassInstance = null;
|
private Class scriptClass = null;
|
|
|
private boolean even = false;
|
|
public MyPanelDeviceStatusSvg(Device device)
|
{
|
this.device = device;
|
this.titleString = Shared.getMessage("Aspect");
|
this.dimensionHeight = 0;
|
this.dimensionWidth = 0;
|
initialise();
|
loadSVG();
|
}
|
|
public void reload(byte[] dataSVG)
|
{
|
if (panelScaleVectorGraphics != null)
|
{
|
panelScaleVectorGraphics.reload(dataSVG);
|
}
|
}
|
|
public void reload(Class scriptClass)
|
{
|
this.scriptClass = scriptClass;
|
}
|
|
|
public void reload()
|
{
|
even = !even;
|
|
SVGDiagram diagram = panelScaleVectorGraphics.getDiagram();
|
|
if (diagram != null)
|
{
|
if (scriptClass == null)
|
{
|
scriptClassInstance = DeviceGraphics.revalidate(diagram, device);
|
} else
|
{
|
try
|
{
|
scriptClassInstance = scriptClass.getDeclaredConstructor(Device.class, SVGDiagram.class).newInstance(device, diagram);
|
|
if(even)
|
{
|
try
|
{
|
scriptClassInstance.getClass().getDeclaredMethod("timer").invoke(scriptClassInstance);
|
} catch (Exception ex)
|
{
|
}
|
}
|
|
scriptClassInstance.getClass().getDeclaredMethod("status").invoke(scriptClassInstance);
|
} catch (Exception ex)
|
{
|
}
|
}
|
}
|
repaint();
|
}
|
|
|
|
|
public void timer()
|
{
|
try
|
{
|
if (scriptClassInstance != null)
|
{
|
Method method = scriptClassInstance.getClass().getDeclaredMethod("timer");
|
method.invoke(scriptClassInstance);
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
|
if (panelScaleVectorGraphics != null) panelScaleVectorGraphics.repaint();
|
}
|
|
|
|
|
private void initialise()
|
{
|
try
|
{
|
if (panelScaleVectorGraphics == null)
|
{
|
panelScaleVectorGraphics = new PanelScaleVectorGraphics();
|
panelScaleVectorGraphics.disableOptionLayers();
|
panelScaleVectorGraphics.disableOptionDevices();
|
panelScaleVectorGraphics.repaint();
|
}
|
|
this.setMinimumSize(new Dimension(dimensionWidth, dimensionHeight));
|
this.setLayout(new BorderLayout());
|
title = new FlatTitle(titleString, ModelGUI.TABLE_TITLE_HEIGTH);
|
this.add(title, BorderLayout.NORTH);
|
this.add(panelScaleVectorGraphics, BorderLayout.CENTER);
|
}
|
catch (Exception e)
|
{
|
}
|
|
}
|
|
public String getTitleString()
|
{
|
return titleString;
|
}
|
|
public void setTitleString(String text)
|
{
|
this.titleString = text;
|
title.setText(titleString);
|
}
|
|
public int getDimensionHeight()
|
{
|
return dimensionHeight;
|
}
|
|
public void setDimensionHeight(int dimensionHeight)
|
{
|
this.dimensionHeight = dimensionHeight;
|
}
|
|
public int getDimensionWidth()
|
{
|
return dimensionWidth;
|
}
|
|
public void setDimensionWidth(int dimensionWidth)
|
{
|
this.dimensionWidth = dimensionWidth;
|
}
|
|
public void loadSVG()
|
{
|
if (loadedSVG == false)
|
{
|
try
|
{
|
int timeout = 5000;
|
if (device instanceof VmsGeneral)
|
{
|
VmsGeneral vms = (VmsGeneral)device;
|
if (vms.getDeviceInformation().dgtmat != null)
|
timeout = 120000;
|
}
|
InteropParameters parameters = Invokes.getParameters(ServerServiceName.UNKNOWN, "getScalableVectorGraphics", new InteropParameter("name", "status"));
|
InteropResponse response = (InteropResponse) device.invoke("get", parameters, timeout, Shared.isConnectionExternal);
|
byte[] dataSVG = (byte[])response.getValue()[0];
|
|
if (dataSVG.length > 0)
|
{
|
reload(dataSVG);
|
loadedSVG = true;
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
}
|