package svgdevicestest.maps.SVG; import art.client.models.ModelGUI.Icons; import art.client.models.Shared; 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.model.devices.Device; import art.library.utils.ArticJavaManagerCompiler; import art.library.utils.ArticScalableVectorGraphics; import static art.library.utils.ArticScalableVectorGraphics.setAttribute; import static art.library.utils.ArticScalableVectorGraphics.getAttributeDouble; import static art.library.utils.ArticScalableVectorGraphics.getAttributeString; import static art.library.utils.ArticScalableVectorGraphics.getBoundingBox; import static art.library.utils.ArticScalableVectorGraphics.getElementsWithAttribute; import art.library.utils.ArticStrings; 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 com.kitfox.svg.xml.StyleAttribute; import java.awt.AlphaComposite; import java.awt.BasicStroke; 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.Shape; 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.Ellipse2D; import java.awt.geom.Point2D; import java.awt.geom.Rectangle2D; import java.io.ByteArrayInputStream; import java.io.File; import java.lang.reflect.Constructor; import java.lang.reflect.Method; 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 PanelScaleVectorGraphics extends JButton { protected SVGDiagram diagram = null; protected FlatButton buttonMenu = null; protected FlatButton buttonTop = null; protected FlatButton buttonLeft = null; protected FlatButton buttonBottom = null; protected FlatButton buttonRight = null; protected FlatButton buttonCenter = null; protected FlatButton buttonMinus = null; protected FlatButton buttonPlus = null; private boolean lockNavigation = false; private boolean fitToPage = false; protected double scalex = 1.0; protected double scaley = 1.0; protected double translatex = 0.0; protected double translatey = 0.0; private boolean dragging = false; 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 Timer timer = null; private boolean showButtonLayers = true; private boolean showButtonDevices = true; private boolean showButtonNavigation = true; private double viewbox_tx = 0.0; private double viewbox_ty = 0.0; private double viewbox_sx = 1.0; private double viewbox_sy = 1.0; private Color backgroundColor = FlatGUI.lookDesign.getColor("window.color.background.content"); private List lelement = new ArrayList(); private List listSelectedDevices = new ArrayList(); private double CX = 0; private double CY = 0; public PanelScaleVectorGraphics() { initialise(); events(); } public PanelScaleVectorGraphics(File file) { reload(file); initialise(); events(); } public PanelScaleVectorGraphics(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 reload(File file) { try { reload(Files.readAllBytes(file.toPath())); } catch (Exception e) { } this.repaint(); } public void reload(byte[] data) { this.scriptInstance = null; this.diagram = null; try { // Background color String xml = new String(data); int index1 = xml.indexOf("pagecolor=\"#"); int index2 = xml.indexOf("\"", index1 + 11); String color = xml.substring(index1+12, index2); backgroundColor = new Color(Integer.parseInt(color, 16)); } catch (Exception e) { } try { ByteArrayInputStream bis = new ByteArrayInputStream(data); SVGUniverse svgUniverse = new SVGUniverse(); svgUniverse.setVerbose(false); diagram = svgUniverse.getDiagram(svgUniverse.loadSVG(bis, "diagram", true)); StyleAttribute sty = new StyleAttribute(); diagram.getRoot().getPres(sty.setName("viewBox")); float[] coords = sty.getFloatList(); Rectangle2D.Float viewbox = new Rectangle2D.Float(coords[0], coords[1], coords[2], coords[3]); viewbox_sx = diagram.getRoot().getDeviceWidth() / viewbox.width; viewbox_sy = diagram.getRoot().getDeviceHeight() / viewbox.height; viewbox_tx = -viewbox.x; viewbox_ty = -viewbox.y; // Get art elements lelement = getElementsWithAttribute(diagram, "art.device"); // Add display attribute, may be does not exists, user forgot for (SVGElement element : lelement) { try { element.addAttribute("display", AnimationElement.AT_CSS, "none"); } catch (Exception e) { } } refreshLayers(); } catch (Exception e) { } this.fit(); } private Object scriptInstance = null; public void revalidate(Device device, String...methodNames) { try { if (scriptInstance == null) { SVGElement element = diagram.getRoot().getChild("Metadata"); String script = element.getPresAbsolute("art.script").getStringValue(); String code = new String(Resources.getResourceData("data/art.client/runtime/DeviceGraphicsRuntime.java")); code = ArticStrings.replaceLast(code, "}", script + "}"); Class clazz = ArticJavaManagerCompiler.getRuntimeClass(code, script); Constructor constructor = clazz.getDeclaredConstructor(new Class[]{Device.class, SVGDiagram.class}); scriptInstance = constructor.newInstance(new Object[]{device, diagram}); } for (String methodName : methodNames) { Method method = scriptInstance.getClass().getDeclaredMethod(methodName); method.invoke(scriptInstance); } } catch (Exception e) { } repaint(); } 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.setRenderingHint(RenderingHints.KEY_ANTIALIASING,RenderingHints.VALUE_ANTIALIAS_ON); g2.setBackground(backgroundColor); g2.clearRect(0, 0, getWidth(), getHeight()); g2.scale(scalex, scaley); g2.translate(translatex, translatey); { // Paint map diagram.render(g2); // Paint selected devices { g2.scale(viewbox_sx, viewbox_sy); g2.translate(viewbox_tx, viewbox_ty); g2.setStroke(new BasicStroke(1.0f)); g2.setColor(Color.BLUE); g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 0.25f)); for (SVGElement element : listSelectedDevices) { Shape shape = getBoundingBox(element); g2.fill(shape); } g2.setComposite(AlphaComposite.getInstance(AlphaComposite.SRC_OVER, 1.0f)); g2.translate(-viewbox_tx, -viewbox_ty); g2.scale(1/viewbox_sx, 1/viewbox_sy); } } g2.translate(-translatex, -translatey); g2.scale(1/scalex, 1/scaley); g2.setColor(Color.red); g2.fill(new Ellipse2D.Double(CX, CY, 15, 15)); if (isFocusOwner() == true) { paintMenu(g2); paintPanTiltZoom(g2); } } catch (Exception e) { } } private void initialise() { buttonMenu = createButtonMap(Icons.MENU_24x24); buttonMenu.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { showMenu(0, 0, true); repaint(); } }); buttonTop = createButtonMap(Icons.MOVE_UP_24x24); buttonLeft = createButtonMap(Icons.MOVE_LEFT_24x24); buttonBottom = createButtonMap(Icons.MOVE_DOWN_24x24); buttonRight = createButtonMap(Icons.MOVE_RIGHT_24x24); buttonCenter = createButtonMap(Icons.MOVE_CENTER_24x24); buttonMinus = createButtonMap(Icons.BUTTON_MINUS_24x24); buttonPlus = createButtonMap(Icons.BUTTON_PLUS_24x24); 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); disableOptionDevices(); } // 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); PanelScaleVectorGraphics.this.repaint(); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent evt) { translatey = translatey + (30 / scaley); PanelScaleVectorGraphics.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); PanelScaleVectorGraphics.this.repaint(); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent evt) { translatey = translatey - (30 / scaley); PanelScaleVectorGraphics.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); PanelScaleVectorGraphics.this.repaint(); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent evt) { translatex = translatex + (30 / scalex); PanelScaleVectorGraphics.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); PanelScaleVectorGraphics.this.repaint(); timer = new Timer(100, new ActionListener() { public void actionPerformed(ActionEvent evt) { translatex = translatex - (30 / scalex); PanelScaleVectorGraphics.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; double presx = (worldx/viewbox_sx) - viewbox_tx; double presy = (worldy/viewbox_sy) - viewbox_ty; updateSelected(e, presx, presy); if (SwingUtilities.isRightMouseButton(e) == true) { showMenu(e.getX(), e.getY(), false); } else { if(buttonMenu != null) { 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(); } public void mouseClicked(MouseEvent e) { if (e.getClickCount() == 2) { // TODO : listSelectedDevices the selected devices // Open window } } }); 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); } }); } // // 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) { } } protected void showMenu(int x, int y, boolean autopos) { FlatPopupMenu popupMenu = new FlatPopupMenu(); double presx = (((x/scalex) - translatex)/viewbox_sx) - viewbox_tx; double presy = (((y/scaley) - translatey)/viewbox_sy) - viewbox_ty; { String identifier = getSelected(presx, presy); if (identifier != null) { // TODO : Device idenfitifier popup selection return; } } if (showButtonNavigation == true) { FlatMenu menuNavigation = new FlatMenu(); { menuNavigation.setText(Shared.getMessage("Navigation")); menuNavigation.setIcon(Resources.getResourceURL(Icons.EARTH_24x24)); { FlatMenuItemCheck item = new FlatMenuItemCheck(); item.setText(Shared.getMessage("Lock navigation")); item.setStayOpen(true); item.setIcon(Resources.getResourceURL(Icons.EARTH_LOCK_24x24)); 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(Shared.getMessage("Fit to page")); item.setStayOpen(true); item.setIcon(Resources.getResourceURL(Icons.ADJUST_PAGE_24x24)); 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) { FlatMenu menuLayers = new FlatMenu(); { menuLayers.setText(Shared.getMessage("Layers")); menuLayers.setIcon(Resources.getResourceURL(Icons.LAYERS_24x24)); for (int i=0; i maxZoom) || ((scalex >= minZoom) && (scalex <= maxZoom)); if (showButtonLayer == true) { FlatMenuItemCheck item = new FlatMenuItemCheck(); { item.setName(layer); item.setText(Shared.getMessage(layer)); item.setStayOpen(true); String display = getAttributeString(child, "art.display"); item.setSelected(display.equalsIgnoreCase("inline") == true); 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. setAttribute(element, "display", AnimationElement.AT_AUTO, "none", 99999); element.setAttribute("art.display", AnimationElement.AT_AUTO, "none"); } else { // SVG Salamander bug. We can to change all objects recursively. setAttribute(element, "display", AnimationElement.AT_AUTO, "inline", 99999); element.setAttribute("art.display", AnimationElement.AT_AUTO, "inline"); } repaint(); } catch (Exception exception) { } } }); menuLayers.add(item); } } } catch (Exception e) { } } } popupMenu.add(menuLayers); } if (showButtonDevices == true) { FlatMenu menuDevices = new FlatMenu(); { menuDevices.setText(Shared.getMessage("Devices")); menuDevices.setIcon(Resources.getResourceURL(Icons.SHAPES_GEOMETRICAL_24x24)); } 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); } } // 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; } public void addSelected (String identifier) { try { for (SVGElement element : lelement) { if (getAttributeString(element, "display").equalsIgnoreCase("inline") == true) { if (listSelectedDevices.contains(element) == false) { listSelectedDevices.add(element); } } } } catch (Exception e) { } } public void setSelected (String identifier) { try { listSelectedDevices.clear(); for (SVGElement element : lelement) { if (getAttributeString(element, "art.device").equalsIgnoreCase(identifier)) { if (getAttributeString(element, "display").equalsIgnoreCase("inline") == true) { Shape shape = getBoundingBox(element); double x = shape.getBounds2D().getCenterX(); double y = shape.getBounds2D().getCenterY(); x = (x + viewbox_tx) * viewbox_sx; y = (y + viewbox_ty) * viewbox_sy; //x = (x + translatex) * scalex; //y = (y + translatey) * scaley; translatex = -x + ((getWidth()/2) / scalex); translatey = -y + ((getHeight()/2) / scaley); listSelectedDevices.add(element); repaint(); return; } } } } catch (Exception e) { } } private void updateSelected(MouseEvent event, double x, double y) { try { if ((event == null) || (event.isShiftDown() == false)) { listSelectedDevices.clear(); } for (SVGElement element : lelement) { if (getAttributeString(element, "display").equalsIgnoreCase("inline") == true) { Shape shape = getBoundingBox(element); if (shape.contains(x, y) == true) { listSelectedDevices.add(element); } } } } catch (Exception e) { } } private String getSelected(double x, double y) { try { for (SVGElement element : lelement) { if (getAttributeString(element, "display").equalsIgnoreCase("inline") == true) { Shape shape = getBoundingBox(element); if (shape.contains(x, y) == true) { return getAttributeString(element, "art.device"); } } } } catch (Exception e) { } return null; } protected 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(); } refreshLayers(); 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); refreshLayers(); } catch (Exception exception) { } repaint(); } private void refreshLayers() { for (int i=0; i maxZoom) || ((scalex >= minZoom) && (scalex <= maxZoom)); if (showscale == true) { setAttribute(element, "display", AnimationElement.AT_AUTO, display, 99999); } else { setAttribute(element, "display", AnimationElement.AT_AUTO, "none", 99999); } } catch (Exception e) { } } } private FlatButton createButtonMap(String icon) { FlatButton button = new FlatButton(); button.setIcon(Resources.getResourceURL(icon)); button.setPreferredSize(new Dimension(button.getStringWidth(), 0)); button.setHorizontalAlignment(SwingConstants.CENTER); button.setHorizontalTextPosition(SwingConstants.CENTER); button.getLook().focus = false; button.getLook().borderRollover = false; button.getLook().borderSelected = false; button.getLook().colorBackgroundSelected = null; button.getLook().colorBackgroundRollover = null; button.revalidate(); return button; } }