⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 viewer.java

📁 一个用Java写的
💻 JAVA
字号:
/****************************************************************** * Copyright (C) 2002-2006 Andrew Girow. All rights reserved.     * * ---------------------------------------------------------------* * This software is published under the terms of the TinyLine     * * License, a copy of which has been included with this           * * distribution in the TINYLINE_LICENSE.TXT file.                 * *                                                                * * For more information on the TinyLine,                          * * please see <http://www.tinyline.com/>.                         * *****************************************************************/package tinyapp;import com.tinyline.svg.*;import java.awt.*;import java.awt.event.*;import java.io.*;import java.net.*;import java.util.zip.*;import java.awt.image.*;/** * The <tt>Viewer</tt> application demostrates how to use the * TinyLine SVG Library for creating a very basic Static SVG Viewer. * <p> * @author (C) Andrew Girow * @version 1.10 * <p> */public class Viewer extends Frame implements ActionListener{    /** The Menu for the <tt>Viewer</tt>. */    MenuBar menuBar1 = new MenuBar();    Menu menuFile = new Menu();    MenuItem pauseButton, refreshButton, exitButton, openButton;    MenuItem linkButton, panButton, zoomInButton, zoomOutButton;    MenuItem qualityButton;    // Java mouse event handler    MouseHandler mouseHandler;    /** The <tt>MapViewer</tt> SVG canvas. */    ViewerCanvas canvas;    /**     * Constructs a new <tt>MapViewer</tt> instance.     */    public Viewer()    {    }    /** Builds the <tt>MapViewer</tt> layout. */    public void init()    {      setTitle("Viewer");      setBackground(SystemColor.control);      setLayout(null);      Dimension dim = getSize();      setResizable(false);      menuFile.setLabel("File");      openButton    = new MenuItem("Open");      openButton.addActionListener(this);      menuFile.add(openButton);      linkButton    = new MenuItem("Link");      linkButton.addActionListener(this);      menuFile.add(linkButton);      panButton     = new MenuItem("Pan");      panButton.addActionListener(this);      menuFile.add(panButton);      zoomInButton  = new MenuItem("Zoom In");      zoomInButton.addActionListener(this);      menuFile.add(zoomInButton);      zoomOutButton = new MenuItem("Zoom Out");      zoomOutButton.addActionListener(this);      menuFile.add(zoomOutButton);      refreshButton = new MenuItem("Original");      refreshButton.addActionListener(this);      menuFile.add(refreshButton);      qualityButton = new MenuItem("Quality");      qualityButton.addActionListener(this);      menuFile.add(qualityButton);      exitButton    = new MenuItem("Exit");      exitButton.addActionListener(this);      menuFile.add(exitButton);      menuBar1.add(menuFile);      setMenuBar(menuBar1);      canvas = new ViewerCanvas(dim.width-10,dim.height-10);      canvas.setBounds(5,5,dim.width-10,dim.height-10);      add(canvas);      // Sets the event listener      mouseHandler = new MouseHandler(canvas);      mouseHandler.type = MouseHandler.LINK_MOUSE;      canvas.addMouseListener(mouseHandler);      canvas.addMouseMotionListener(mouseHandler);      // Loads the default fontSystem.out.println("canvas " + canvas);      SVGDocument doc = canvas.loadSVG(getImage("images/helvetica.svg").toExternalForm());      SVGFontElem font = SVGDocument.getFont(doc,SVG.VAL_DEFAULT_FONTFAMILY);      SVGDocument.defaultFont = font;    }    /** Handles action events */    public void actionPerformed(ActionEvent e)    {//        System.out.println(""+e);        Object src = e.getSource();        if(src == exitButton)        {           fileExit();        }        else if(src == openButton)        {           fileOpen();        }        else if(src == panButton)        {           mouseHandler.type = MouseHandler.PAN_MOUSE;        }        else if(src == zoomInButton)        {           mouseHandler.type = MouseHandler.ZOOM_IN_MOUSE;        }        else if(src == zoomOutButton)        {           mouseHandler.type = MouseHandler.ZOOM_OUT_MOUSE;        }        else if(src == linkButton)        {           mouseHandler.type = MouseHandler.LINK_MOUSE;        }        else if(src == refreshButton)        {           mouseHandler.type = MouseHandler.LINK_MOUSE;           mouseHandler.origView();        }        else if(src == qualityButton)        {           mouseHandler.type = MouseHandler.LINK_MOUSE;           mouseHandler.quality();        }    }    /**     * Performs the action defined for "File|Exit".     */    void fileExit()    {      System.exit(0);    }                /** Gets an image URL by name */    private URL getImage(String name)    {        return getClass().getResource(name);    }                /** Open file dialog */    private void fileOpen()    {        FileDialog fd = new FileDialog(this, "Load file", FileDialog.LOAD);        if(fd == null ) return;        fd.setModal(true);        fd.setVisible(true);        if (fd.getFile() != null)        {            File file = new File(fd.getDirectory(),fd.getFile());            try            {               URL svgurl = new URL("file", "", slashify(file.getAbsolutePath(), file.isDirectory()));               String documentUrl = svgurl.toExternalForm();               canvas.goURL(documentUrl);                                 Runtime.getRuntime().gc();            }            catch (Exception e)            {               return;            }        }        fd = null;    }    /** Slashifies the path depends on the isDirectory flag */    private static String slashify(String path, boolean isDirectory)    {        String p = path;        if (File.separatorChar != '/')        {            p = p.replace(File.separatorChar, '/');        }        if (!p.startsWith("/"))        {                  p = "/" + p;        }        if (!p.endsWith("/") && isDirectory)        {                  p = p + "/";        }              return p;    }    /**     * Main. Runs the MapViewer sample appplication     */    public static void main(String[] args)    {        Viewer frame = new Viewer();        // Typical iPAQ or Zaurus dimentions 240 * 320        frame.setBounds(0,0,240,320);        // For desktops is better 480 * 480//      frame.setBounds(0,0,480,480);        frame.init();        frame.setVisible(true);    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -