package svgdevicestest.maps;
|
|
import art.library.gui.FlatGUI;
|
import art.library.gui.flat.FlatButton;
|
import art.library.gui.flat.FlatMenu;
|
import art.library.gui.flat.FlatMenuItemCheck;
|
import art.library.gui.flat.FlatPopupMenu;
|
import art.library.utils.ArticScalableVectorGraphics;
|
import static art.library.utils.ArticScalableVectorGraphics.setAttribute;
|
import art.library.utils.resources.Resources;
|
import com.kitfox.svg.SVGDiagram;
|
import com.kitfox.svg.SVGElement;
|
import com.kitfox.svg.SVGUniverse;
|
import com.kitfox.svg.animation.AnimationElement;
|
import java.awt.AlphaComposite;
|
import java.awt.Color;
|
import java.awt.Component;
|
import java.awt.Dimension;
|
import java.awt.Graphics;
|
import java.awt.Graphics2D;
|
import java.awt.MouseInfo;
|
import java.awt.Point;
|
import java.awt.Rectangle;
|
import java.awt.RenderingHints;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.awt.event.ComponentAdapter;
|
import java.awt.event.ComponentEvent;
|
import java.awt.event.MouseAdapter;
|
import java.awt.event.MouseEvent;
|
import java.awt.event.MouseMotionAdapter;
|
import java.awt.event.MouseWheelEvent;
|
import java.awt.event.MouseWheelListener;
|
import java.awt.geom.Point2D;
|
import java.awt.geom.Rectangle2D;
|
import java.io.ByteArrayInputStream;
|
import java.io.File;
|
import java.nio.file.Files;
|
import java.util.ArrayList;
|
import java.util.List;
|
import javax.swing.JButton;
|
import javax.swing.SwingConstants;
|
import javax.swing.SwingUtilities;
|
import javax.swing.Timer;
|
|
public class PanelScaleVectorGraphics3 extends JButton
|
{
|
|
private SVGDiagram diagram = null;
|
private FlatButton buttonMenu = null;
|
private FlatButton buttonTop = null;
|
private FlatButton buttonLeft = null;
|
private FlatButton buttonBottom = null;
|
private FlatButton buttonRight = null;
|
private FlatButton buttonCenter = null;
|
private FlatButton buttonMinus = null;
|
private FlatButton buttonPlus = null;
|
|
private boolean lockNavigation = false;
|
private boolean fitToPage = false;
|
private double scalex = 1.0;
|
private double scaley = 1.0;
|
private boolean dragging = false;
|
private double translatex = 0.0;
|
private double translatey = 0.0;
|
private double viewportx = 0;
|
private double viewporty = 0;
|
private double worldx = 0;
|
private double worldy = 0;
|
private double worlddraggingx = 0;
|
private double worlddraggingy = 0;
|
private Object selectedObject = null;
|
private List<String> llayer = new ArrayList<String>();
|
private List<String> ldevice = new ArrayList<String>();
|
private Timer timer = null;
|
private boolean showButtonLayers = true;
|
private boolean showButtonDevices = true;
|
private boolean showButtonNavigation = true;
|
|
public PanelScaleVectorGraphics3()
|
{
|
initialise();
|
events();
|
}
|
|
public PanelScaleVectorGraphics3(File file)
|
{
|
reload(file);
|
initialise();
|
events();
|
}
|
|
public PanelScaleVectorGraphics3(byte[] data)
|
{
|
reload(data);
|
initialise();
|
events();
|
}
|
|
public SVGDiagram getDiagram()
|
{
|
return diagram;
|
}
|
|
public boolean isValid()
|
{
|
return (diagram != null);
|
}
|
|
public void disableOptionLayers()
|
{
|
showButtonLayers = false;
|
}
|
|
public void disableOptionDevices()
|
{
|
showButtonDevices = false;
|
}
|
|
public void disableOptionNavigation()
|
{
|
showButtonNavigation = false;
|
this.remove(buttonMenu);
|
this.remove(buttonTop);
|
this.remove(buttonLeft);
|
this.remove(buttonBottom);
|
this.remove(buttonRight);
|
this.remove(buttonCenter);
|
this.remove(buttonMinus);
|
this.remove(buttonPlus);
|
}
|
|
public void enableOptionLayers()
|
{
|
showButtonLayers = true;
|
}
|
|
public void enableOptionDevices()
|
{
|
showButtonDevices = true;
|
}
|
|
public void enableOptionNavigation()
|
{
|
disableOptionNavigation();
|
this.add(buttonMenu);
|
this.add(buttonTop);
|
this.add(buttonLeft);
|
this.add(buttonBottom);
|
this.add(buttonRight);
|
this.add(buttonCenter);
|
this.add(buttonMinus);
|
this.add(buttonPlus);
|
showButtonNavigation = true;
|
}
|
|
public void hideLayers()
|
{
|
try
|
{
|
for (String layer : llayer)
|
{
|
SVGElement element = ArticScalableVectorGraphics.getLayer(diagram, layer);
|
try
|
{
|
element.addAttribute("art.display", AnimationElement.AT_CSS, "none");
|
}
|
catch (Exception e)
|
{
|
}
|
;
|
element.setAttribute("art.display", AnimationElement.AT_CSS, "none");
|
setAttribute(element, "display", AnimationElement.AT_CSS, "none", 99999);
|
}
|
}
|
catch (Exception e)
|
{
|
e.printStackTrace();
|
}
|
}
|
|
public void showLayer(String name)
|
{
|
try
|
{
|
SVGElement element = ArticScalableVectorGraphics.getLayer(diagram, name);
|
try
|
{
|
element.addAttribute("art.display", AnimationElement.AT_CSS, "inline");
|
}
|
catch (Exception e)
|
{
|
}
|
;
|
element.setAttribute("art.display", AnimationElement.AT_CSS, "inline");
|
setAttribute(element, "display", AnimationElement.AT_CSS, "inline", 99999);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
public void reload(File file)
|
{
|
try
|
{
|
reload(Files.readAllBytes(file.toPath()));
|
}
|
catch (Exception e)
|
{
|
}
|
|
this.repaint();
|
}
|
|
public void reload(byte[] data)
|
{
|
this.diagram = null;
|
|
try
|
{
|
try
|
{
|
ByteArrayInputStream bis = new ByteArrayInputStream(data);
|
SVGUniverse svgUniverse = new SVGUniverse();
|
svgUniverse.setVerbose(false);
|
diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(bis, "diagram", true));
|
llayer.clear();
|
|
for (int i = 0; i < diagram.getRoot().getNumChildren(); i++)
|
{
|
try
|
{
|
SVGElement child = diagram.getRoot().getChild(i);
|
String label = child.getPresAbsolute("inkscape:label").getStringValue();
|
String groupMode = child.getPresAbsolute("inkscape:groupmode").getStringValue();
|
if (groupMode.equalsIgnoreCase("layer") == true)
|
{
|
String display = ArticScalableVectorGraphics.getAttributeString(child, "display");
|
|
if (display == null)
|
{
|
child.addAttribute("display", AnimationElement.AT_CSS, "inline");
|
child.addAttribute("art.display", AnimationElement.AT_CSS, "inline");
|
display = ArticScalableVectorGraphics.getAttributeString(child, "display");
|
}
|
|
if (display != null)
|
{
|
if (display.equalsIgnoreCase("none") == true)
|
{
|
// SVG Salamander bug. If layer is display:none we can to change all objects
|
// recursively.
|
// If not only first object of the layer is not displayed
|
|
setAttribute(child, "display", AnimationElement.AT_CSS, "none", 99999);
|
child.addAttribute("art.display", AnimationElement.AT_CSS, "none");
|
}
|
else
|
{
|
child.addAttribute("art.display", AnimationElement.AT_CSS, "inline");
|
}
|
}
|
|
llayer.add(label);
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
diagram = null;
|
}
|
|
}
|
catch (Exception e)
|
{
|
}
|
|
this.fit();
|
}
|
|
public void paint(Graphics graphics)
|
{
|
try
|
{
|
Graphics2D g2 = (Graphics2D) graphics;
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_LCD_HRGB);
|
g2.setRenderingHint(RenderingHints.KEY_DITHERING, RenderingHints.VALUE_DITHER_DEFAULT);
|
g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);
|
g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BILINEAR);
|
g2.setRenderingHint(RenderingHints.KEY_ALPHA_INTERPOLATION, RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_COLOR_RENDERING, RenderingHints.VALUE_COLOR_RENDER_QUALITY);
|
g2.setRenderingHint(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_DEFAULT);
|
g2.setBackground(Color.white);
|
g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
|
g2.clearRect(0, 0, getWidth(), getHeight());
|
|
double a = diagram.getWidth();
|
double b = diagram.getHeight();
|
|
g2.scale(scalex, scaley);
|
g2.translate(translatex, translatey);
|
diagram.render(g2);
|
g2.translate(-translatex, -translatey);
|
g2.scale(1 / scalex, 1 / scaley);
|
|
g2.scale(1.0, 1.0);
|
g2.translate(0, 0);
|
g2.setColor(Color.red);
|
|
if (isFocusOwner() == true)
|
{
|
paintMenu(g2);
|
paintPanTiltZoom(g2);
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
private void initialise()
|
{
|
buttonMenu = new FlatButton();
|
{
|
buttonMenu.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/menu.png"));
|
buttonMenu.setPreferredSize(new Dimension(buttonMenu.getStringWidth(), 0));
|
buttonMenu.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonMenu.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonMenu.getLook().focus = false;
|
buttonMenu.getLook().borderRollover = false;
|
buttonMenu.getLook().borderSelected = false;
|
buttonMenu.getLook().colorBackgroundSelected = null;
|
buttonMenu.getLook().colorBackgroundRollover = null;
|
buttonMenu.revalidate();
|
buttonMenu.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
showMenu(0, 0, true);
|
repaint();
|
}
|
});
|
}
|
|
buttonTop = new FlatButton();
|
{
|
buttonTop.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/move-top.png"));
|
buttonTop.setPreferredSize(new Dimension(buttonTop.getStringWidth(), 0));
|
buttonTop.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonTop.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonTop.getLook().focus = false;
|
buttonTop.getLook().borderRollover = false;
|
buttonTop.getLook().borderSelected = false;
|
buttonTop.getLook().colorBackgroundSelected = null;
|
buttonTop.getLook().colorBackgroundRollover = null;
|
buttonTop.revalidate();
|
}
|
|
buttonLeft = new FlatButton();
|
{
|
buttonLeft.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/move-left.png"));
|
buttonLeft.setPreferredSize(new Dimension(buttonLeft.getStringWidth(), 0));
|
buttonLeft.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonLeft.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonLeft.getLook().focus = false;
|
buttonLeft.getLook().borderRollover = false;
|
buttonLeft.getLook().borderSelected = false;
|
buttonLeft.getLook().colorBackgroundSelected = null;
|
buttonLeft.getLook().colorBackgroundRollover = null;
|
buttonLeft.revalidate();
|
}
|
|
buttonBottom = new FlatButton();
|
{
|
buttonBottom.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/move-bottom.png"));
|
buttonBottom.setPreferredSize(new Dimension(buttonBottom.getStringWidth(), 0));
|
buttonBottom.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonBottom.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonBottom.getLook().focus = false;
|
buttonBottom.getLook().borderRollover = false;
|
buttonBottom.getLook().borderSelected = false;
|
buttonBottom.getLook().colorBackgroundSelected = null;
|
buttonBottom.getLook().colorBackgroundRollover = null;
|
buttonBottom.revalidate();
|
}
|
|
buttonRight = new FlatButton();
|
{
|
buttonRight.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/move-right.png"));
|
buttonRight.setPreferredSize(new Dimension(buttonRight.getStringWidth(), 0));
|
buttonRight.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonRight.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonRight.getLook().focus = false;
|
buttonRight.getLook().borderRollover = false;
|
buttonRight.getLook().borderSelected = false;
|
buttonRight.getLook().colorBackgroundSelected = null;
|
buttonRight.getLook().colorBackgroundRollover = null;
|
buttonRight.revalidate();
|
}
|
|
buttonCenter = new FlatButton();
|
{
|
buttonCenter.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/move-center.png"));
|
buttonCenter.setPreferredSize(new Dimension(buttonCenter.getStringWidth(), 0));
|
buttonCenter.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonCenter.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonCenter.getLook().focus = false;
|
buttonCenter.getLook().borderRollover = false;
|
buttonCenter.getLook().borderSelected = false;
|
buttonCenter.getLook().colorBackgroundSelected = null;
|
buttonCenter.getLook().colorBackgroundRollover = null;
|
buttonCenter.revalidate();
|
}
|
|
buttonMinus = new FlatButton();
|
{
|
buttonMinus.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/minus-button.png"));
|
buttonMinus.setPreferredSize(new Dimension(buttonCenter.getStringWidth(), 0));
|
buttonMinus.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonMinus.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonMinus.getLook().focus = false;
|
buttonMinus.getLook().borderRollover = false;
|
buttonMinus.getLook().borderSelected = false;
|
buttonMinus.getLook().colorBackgroundSelected = null;
|
buttonMinus.getLook().colorBackgroundRollover = null;
|
buttonMinus.revalidate();
|
}
|
|
buttonPlus = new FlatButton();
|
{
|
buttonPlus.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/plus-button.png"));
|
buttonPlus.setPreferredSize(new Dimension(buttonCenter.getStringWidth(), 0));
|
buttonPlus.setHorizontalAlignment(SwingConstants.CENTER);
|
buttonPlus.setHorizontalTextPosition(SwingConstants.CENTER);
|
buttonPlus.getLook().focus = false;
|
buttonPlus.getLook().borderRollover = false;
|
buttonPlus.getLook().borderSelected = false;
|
buttonPlus.getLook().colorBackgroundSelected = null;
|
buttonPlus.getLook().colorBackgroundRollover = null;
|
buttonPlus.revalidate();
|
}
|
|
this.setLayout(null);
|
this.add(buttonMenu);
|
this.add(buttonTop);
|
this.add(buttonLeft);
|
this.add(buttonBottom);
|
this.add(buttonRight);
|
this.add(buttonCenter);
|
this.add(buttonMinus);
|
this.add(buttonPlus);
|
}
|
|
// <editor-fold defaultstate="collapsed" desc="Events">
|
private void events()
|
{
|
this.addComponentListener(new ComponentAdapter()
|
{
|
public void componentResized(ComponentEvent e)
|
{
|
fit();
|
}
|
|
public void componentShown(ComponentEvent e)
|
{
|
fit();
|
}
|
});
|
|
buttonTop.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
|
translatey = translatey + (30 / scaley);
|
PanelScaleVectorGraphics3.this.repaint();
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
translatey = translatey + (30 / scaley);
|
PanelScaleVectorGraphics3.this.repaint();
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
buttonBottom.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
translatey = translatey - (30 / scaley);
|
PanelScaleVectorGraphics3.this.repaint();
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
translatey = translatey - (30 / scaley);
|
PanelScaleVectorGraphics3.this.repaint();
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
buttonLeft.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
translatex = translatex + (30 / scalex);
|
PanelScaleVectorGraphics3.this.repaint();
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
translatex = translatex + (30 / scalex);
|
PanelScaleVectorGraphics3.this.repaint();
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
buttonRight.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
translatex = translatex - (30 / scalex);
|
PanelScaleVectorGraphics3.this.repaint();
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
translatex = translatex - (30 / scalex);
|
PanelScaleVectorGraphics3.this.repaint();
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
buttonCenter.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
fit();
|
}
|
});
|
|
buttonMinus.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
zoom(1 / 1.1, getWidth() / 2, getHeight() / 2);
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
zoom(1 / 1.1, getWidth() / 2, getHeight() / 2);
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
buttonPlus.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
zoom(1.1, getWidth() / 2, getHeight() / 2);
|
|
timer = new Timer(100, new ActionListener()
|
{
|
public void actionPerformed(ActionEvent evt)
|
{
|
zoom(1.1, getWidth() / 2, getHeight() / 2);
|
}
|
});
|
timer.start();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
if (timer != null)
|
{
|
timer.stop();
|
}
|
timer = null;
|
}
|
});
|
|
this.addMouseListener(new MouseAdapter()
|
{
|
public void mousePressed(MouseEvent e)
|
{
|
setCursor(FlatGUI.lookDesign.getCursor("cursor.pressed"));
|
viewportx = e.getX();
|
viewporty = e.getY();
|
worldx = (viewportx / scalex) - translatex;
|
worldy = (viewporty / scaley) - translatey;
|
selectedObject = getSelected(worldx, worldy);
|
|
if (SwingUtilities.isRightMouseButton(e) == true)
|
{
|
showMenu(e.getX(), e.getY(), false);
|
}
|
else
|
{
|
Rectangle rectangle = new Rectangle(4, getHeight() - buttonMenu.getHeight() - 8,
|
buttonMenu.getWidth(), buttonMenu.getHeight());
|
|
if (rectangle.contains(e.getX(), e.getY()))
|
{
|
showMenu(e.getX(), e.getY(), true);
|
repaint();
|
return;
|
}
|
}
|
|
repaint();
|
}
|
|
public void mouseReleased(MouseEvent e)
|
{
|
dragging = false;
|
setCursor(FlatGUI.lookDesign.getCursor("cursor.hand"));
|
repaint();
|
}
|
});
|
|
this.addMouseMotionListener(new MouseMotionAdapter()
|
{
|
public void mouseMoved(MouseEvent e)
|
{
|
}
|
|
public void mouseDragged(MouseEvent e)
|
{
|
try
|
{
|
dragging = true;
|
worlddraggingx = (e.getX() / scalex) - translatex;
|
worlddraggingy = (e.getY() / scaley) - translatey;
|
|
if ((selectedObject == null) && (lockNavigation == false))
|
{
|
double tx = (e.getX() - viewportx) / scalex;
|
double ty = (e.getY() - viewporty) / scaley;
|
viewportx = e.getX();
|
viewporty = e.getY();
|
translatex = translatex + tx;
|
translatey = translatey + ty;
|
}
|
}
|
catch (Exception exception)
|
{
|
}
|
|
repaint();
|
}
|
});
|
|
this.addMouseWheelListener(new MouseWheelListener()
|
{
|
public void mouseWheelMoved(MouseWheelEvent e)
|
{
|
float increment = (1 + ((float) -e.getWheelRotation() / 10));
|
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
|
Point panelPoint = getLocationOnScreen();
|
double x = mousePoint.getX() - panelPoint.getX();
|
double y = mousePoint.getY() - panelPoint.getY();
|
zoom(increment, x, y);
|
}
|
});
|
|
}
|
|
// </editor-fold>
|
// <editor-fold defaultstate="collapsed" desc="Paint">
|
public void paintMenu(Graphics2D g2)
|
{
|
int x = 4;
|
int y = getHeight() - buttonMenu.getHeight() - 4;
|
buttonMenu.setBounds(x, y, 32, 32);
|
paintComponent(buttonMenu, g2);
|
}
|
|
public void paintPanTiltZoom(Graphics2D g2)
|
{
|
if (lockNavigation == true)
|
{
|
return;
|
}
|
|
int x = getWidth() - 16 - 10 - 48;
|
int y = 12 + 10 + 24;
|
buttonCenter.setBounds(x, y, 32, 32);
|
paintComponent(buttonCenter, g2);
|
|
x = getWidth() - 16 - 10 - 48;
|
y = 12;
|
buttonTop.setBounds(x, y, 32, 32);
|
paintComponent(buttonTop, g2);
|
|
x = getWidth() - 16 - 20 - 72;
|
y = 12 + 10 + 24;
|
buttonLeft.setBounds(x, y, 32, 32);
|
paintComponent(buttonLeft, g2);
|
|
x = getWidth() - 16 - 10 - 48;
|
y = 12 + 20 + 48;
|
buttonBottom.setBounds(x, y, 32, 32);
|
paintComponent(buttonBottom, g2);
|
|
x = getWidth() - 16 - 24;
|
y = 12 + 10 + 24;
|
buttonRight.setBounds(x, y, 32, 32);
|
paintComponent(buttonRight, g2);
|
|
x = getWidth() - 16 - 24;
|
y = 12 + 20 + 64;
|
buttonMinus.setBounds(x, y, 32, 32);
|
paintComponent(buttonMinus, g2);
|
|
x = getWidth() - 16 - 20 - 72;
|
y = 12 + 20 + 64;
|
buttonPlus.setBounds(x, y, 32, 32);
|
paintComponent(buttonPlus, g2);
|
|
}
|
|
public void paintComponent(Component component, Graphics2D g2)
|
{
|
try
|
{
|
Point mousePoint = MouseInfo.getPointerInfo().getLocation();
|
Point panelPoint = getLocationOnScreen();
|
double mousex = mousePoint.getX() - panelPoint.getX();
|
double mousey = mousePoint.getY() - panelPoint.getY();
|
|
Rectangle bounds = component.getBounds();
|
|
g2.translate(bounds.x, bounds.y);
|
|
if (bounds.contains(mousex, mousey) == true)
|
{
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f));
|
}
|
else
|
{
|
g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.4f));
|
}
|
|
component.paint(g2);
|
g2.translate(-bounds.x, -bounds.y);
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
private void showMenu(int x, int y, boolean autopos)
|
{
|
FlatPopupMenu popupMenu = new FlatPopupMenu();
|
|
if (showButtonNavigation == true)
|
{
|
FlatMenu menuNavigation = new FlatMenu();
|
{
|
menuNavigation.setText("Navigation");
|
menuNavigation.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/earth.png"));
|
{
|
FlatMenuItemCheck item = new FlatMenuItemCheck();
|
item.setText("Lock navigation");
|
item.setStayOpen(true);
|
item.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/globe.png"));
|
item.setSelected(lockNavigation == true);
|
item.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
lockNavigation = ((FlatMenuItemCheck) e.getSource()).isSelected();
|
}
|
});
|
menuNavigation.add(item);
|
}
|
{
|
FlatMenuItemCheck item = new FlatMenuItemCheck();
|
item.setText("Fit to page");
|
item.setStayOpen(true);
|
item.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/adjust-page.png"));
|
item.setSelected(fitToPage == true);
|
item.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
FlatMenuItemCheck item = (FlatMenuItemCheck) e.getSource();
|
fitToPage = item.isSelected();
|
fit();
|
}
|
});
|
menuNavigation.add(item);
|
}
|
}
|
|
popupMenu.add(menuNavigation);
|
}
|
|
if (showButtonLayers == true)
|
{
|
try
|
{
|
FlatMenu menuLayers = new FlatMenu();
|
{
|
menuLayers.setText("Layers");
|
menuLayers.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/layers.png"));
|
|
for (String layer : llayer)
|
{
|
double minZoom = ArticScalableVectorGraphics.getAttributeDouble(diagram, layer, "art.minzoom");
|
double maxZoom = ArticScalableVectorGraphics.getAttributeDouble(diagram, layer, "art.maxzoom");
|
boolean showlayer = ((minZoom == 0) && (maxZoom == 0)) || (minZoom > maxZoom)
|
|| ((scalex >= minZoom) && (scalex <= maxZoom));
|
|
if (showlayer == false)
|
{
|
SVGElement element = ArticScalableVectorGraphics.getLayer(diagram, layer);
|
setAttribute(element, "display", AnimationElement.AT_CSS, "none", 99999);
|
}
|
else
|
{
|
FlatMenuItemCheck item = new FlatMenuItemCheck();
|
{
|
item.setName(layer);
|
item.setText(layer);
|
item.setStayOpen(true);
|
item.setSelected(ArticScalableVectorGraphics
|
.getAttributeString(diagram, item.getName(), "display")
|
.equalsIgnoreCase("none") == false);
|
|
item.addActionListener(new ActionListener()
|
{
|
public void actionPerformed(ActionEvent e)
|
{
|
try
|
{
|
SVGElement element = ArticScalableVectorGraphics.getLayer(diagram,
|
((FlatMenuItemCheck) e.getSource()).getName());
|
|
if (item.isSelected() == false)
|
{
|
// SVG Salamander bug. We can to change all objects recursively.
|
element.setAttribute("art.display", AnimationElement.AT_CSS, "none");
|
setAttribute(element, "display", AnimationElement.AT_CSS, "none",
|
99999);
|
}
|
else
|
{
|
// SVG Salamander bug. We can to change all objects recursively.
|
element.setAttribute("art.display", AnimationElement.AT_CSS, "inline");
|
setAttribute(element, "display", AnimationElement.AT_CSS, "inline",
|
99999);
|
}
|
|
repaint();
|
}
|
catch (Exception exception)
|
{
|
}
|
}
|
});
|
|
if (showlayer == true)
|
{
|
menuLayers.add(item);
|
}
|
}
|
}
|
}
|
}
|
|
popupMenu.add(menuLayers);
|
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
if (showButtonDevices == true)
|
{
|
FlatMenu menuDevices = new FlatMenu();
|
{
|
menuDevices.setText("Devices");
|
menuDevices
|
.setIcon(Resources.getResourceURL("data/art.client/icons/24x24/geometrical-shapes-group.png"));
|
}
|
popupMenu.add(menuDevices);
|
}
|
|
popupMenu.pack();
|
|
if (autopos == true)
|
{
|
popupMenu.show(this, buttonMenu.getX(),
|
buttonMenu.getY() - (int) popupMenu.getPreferredSize().getHeight() - popupMenu.getHeight());
|
}
|
else
|
{
|
popupMenu.show(this, x, y);
|
}
|
}
|
|
// </editor-fold>
|
private Point2D windowToScreen(double x, double y)
|
{
|
double wx = (x / scalex) - translatex;
|
double wy = (y / scaley) - translatey;
|
Point2D resultado = new Point2D.Double(wx, wy);
|
return resultado;
|
}
|
|
private Object getSelected(double x, double y)
|
{
|
return null;
|
}
|
|
private void fit()
|
{
|
if (lockNavigation == true)
|
{
|
return;
|
}
|
|
try
|
{
|
if (fitToPage == false)
|
{
|
Rectangle2D view = diagram.getViewRect();
|
double ratiox = getWidth() / view.getWidth();
|
double ratioy = getHeight() / view.getHeight();
|
double ratio = Math.min(ratiox, ratioy);
|
translatex = -view.getX() + (getWidth() - (view.getWidth() * ratio)) / 2;
|
translatey = -view.getY() + (getHeight() - (view.getHeight() * ratio)) / 2;
|
translatex = translatex / ratio;
|
translatey = translatey / ratio;
|
scalex = ratio;
|
scaley = ratio;
|
}
|
else
|
{
|
Rectangle2D view = diagram.getViewRect();
|
translatex = -view.getX();
|
translatey = -view.getY();
|
scalex = getWidth() / view.getWidth();
|
scaley = getHeight() / view.getHeight();
|
}
|
|
repaint();
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
private void zoom(double increment, double x, double y)
|
{
|
try
|
{
|
if (lockNavigation == true)
|
{
|
return;
|
}
|
|
if ((scalex * increment) < 0.10)
|
{
|
return;
|
}
|
if ((scaley * increment) < 0.10)
|
{
|
return;
|
}
|
|
Point2D O = windowToScreen(0, 0);
|
Point2D P = windowToScreen(x, y);
|
|
// Ponemos el punto del mouse en el (0,0)
|
double tx = P.getX() - O.getX();
|
double ty = P.getY() - O.getY();
|
translatex = translatex - tx;
|
translatey = translatey - ty;
|
|
// Ampliamos
|
scalex = scalex * increment;
|
scaley = scaley * increment;
|
|
// Devolvemos el punto del mouse al punto de pantalla original
|
translatex = translatex + (tx / increment);
|
translatey = translatey + (ty / increment);
|
|
zoomLayer();
|
|
}
|
catch (Exception exception)
|
{
|
}
|
|
repaint();
|
}
|
|
private void zoomLayer()
|
{
|
try
|
{
|
for (String layer : llayer)
|
{
|
SVGElement element = ArticScalableVectorGraphics.getLayer(diagram, layer);
|
double minZoom = ArticScalableVectorGraphics.getAttributeDouble(diagram, layer, "art.minzoom");
|
double maxZoom = ArticScalableVectorGraphics.getAttributeDouble(diagram, layer, "art.maxzoom");
|
boolean showlayer = ((minZoom == 0) && (maxZoom == 0)) || (minZoom > maxZoom)
|
|| ((scalex >= minZoom) && (scalex <= maxZoom));
|
showlayer = showlayer && (ArticScalableVectorGraphics.getAttributeString(diagram, layer, "art.display")
|
.equalsIgnoreCase("none") == false);
|
String display = ArticScalableVectorGraphics.getAttributeString(diagram, layer, "display");
|
|
if ((showlayer == true) && (display.equalsIgnoreCase("none") == true))
|
{
|
ArticScalableVectorGraphics.setAttribute(element, "display", AnimationElement.AT_CSS, "inline",
|
99999);
|
}
|
|
if ((showlayer == false) && (display.equalsIgnoreCase("none") == false))
|
{
|
ArticScalableVectorGraphics.setAttribute(element, "display", AnimationElement.AT_CSS, "none",
|
99999);
|
}
|
}
|
}
|
catch (Exception e)
|
{
|
}
|
}
|
|
}
|