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.Shared; import art.library.gui.flat.FlatPanel; 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.DeviceCommands; 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 MyPanelDeviceCommandsSvg extends FlatPanel { private DeviceCommands deviceCommands; private PanelScaleVectorGraphics panelScaleVectorGraphics; private Device device = null; private int dimensionHeight; private int dimensionWidth; private boolean loadedSVG = false; private Object scriptClassInstance = null; private Class scriptClass = null; public MyPanelDeviceCommandsSvg(DeviceCommands deviceCommands) { this.deviceCommands = deviceCommands; this.dimensionHeight = 0; this.dimensionWidth = 0; loadedSVG = true; initialise(); } public MyPanelDeviceCommandsSvg(Device device, DeviceCommands deviceCommands) { this.deviceCommands = deviceCommands; this.device = device; 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() { SVGDiagram diagram = panelScaleVectorGraphics.getDiagram(); if (diagram != null) { if (scriptClass == null) { scriptClassInstance = DeviceGraphics.revalidate(diagram, device, deviceCommands); } else { try { scriptClassInstance = scriptClass.getDeclaredConstructor(Device.class, DeviceCommands.class, SVGDiagram.class).newInstance(device, deviceCommands, diagram); scriptClassInstance.getClass().getDeclaredMethod("commands").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()); this.add(panelScaleVectorGraphics, BorderLayout.CENTER); } catch (Exception e) { } } 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 setDeviceCommands(DeviceCommands commands) { this.deviceCommands = commands; } 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", "action")); 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) { } } } }