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

📄 svgeditor.java

📁 编辑视频文件
💻 JAVA
📖 第 1 页 / 共 5 页
字号:
        statusBar.setFloatable(false);        JPanel objStatusPanel = new JPanel(new GridBagLayout());        GridBagConstraints gbc = new GridBagConstraints();        Insets insets = new Insets(2, 2, 2, 2);        gbc.gridx = 0;        gbc.insets = insets;        gbc.anchor = GridBagConstraints.WEST;        JLabel xLabel = createLabel("X: ", null);        objStatusPanel.add(xLabel, gbc);        int lw = xLabel.getFontMetrics(xLabel.getFont()).stringWidth("0000");        Dimension labdim = new Dimension(lw, Constants.DEFAULTFONT.getSize() +                2);        xValue = createLabel(null, labdim);        gbc.gridx++;        objStatusPanel.add(xValue, gbc);        JLabel yLabel = createLabel("Y: ", null);        yValue = createLabel(null, labdim);        gbc.gridx++;        objStatusPanel.add(yLabel, gbc);        gbc.gridx++;        objStatusPanel.add(yValue, gbc);        JLabel wLabel = createLabel("W: ", null);        gbc.gridx++;        objStatusPanel.add(wLabel, gbc);        wValue = createLabel(null, labdim);        gbc.gridx++;        objStatusPanel.add(wValue, gbc);        JLabel hLabel = createLabel("H: ", null);        gbc.gridx++;        objStatusPanel.add(hLabel, gbc);        hValue = createLabel(null, labdim);        gbc.gridx++;        objStatusPanel.add(hValue, gbc);        JLabel dLabel = createLabel("D: ", null);        gbc.gridx++;        objStatusPanel.add(dLabel, gbc);        dValue = createLabel(null, labdim);        dValue.setPreferredSize(new Dimension(labdim.width * 2, labdim.height));        gbc.gridx++;        objStatusPanel.add(dValue, gbc);        JPanel sep = new JPanel();        Dimension sepSize = new Dimension(10, labdim.height);        sep.setPreferredSize(sepSize);        sep.setMinimumSize(sepSize);        gbc.gridx++;        objStatusPanel.add(sep, gbc);        JLabel mxLabel = createLabel("MX: ", null);        mxValue = createLabel(null, labdim);        JLabel myLabel = createLabel("MY: ", null);        myValue = createLabel(null, labdim);        gbc.gridx++;        objStatusPanel.add(mxLabel, gbc);        gbc.gridx++;        objStatusPanel.add(mxValue, gbc);        gbc.gridx++;        objStatusPanel.add(myLabel, gbc);        gbc.gridx++;        objStatusPanel.add(myValue, gbc);        gbc.gridx++;        gbc.weightx = 1;        gbc.fill = GridBagConstraints.HORIZONTAL;        objStatusPanel.add(new JPanel(), gbc);        statusBar.add(objStatusPanel);        return statusBar;    }    /**     * Create an initialised JLabel.     *     * @param s the text for the label     * @param dim the preferred dimension     *     * @return a JLabel     */    protected JLabel createLabel(String s, Dimension dim) {        JLabel l = new JLabel(s);        l.setFont(Constants.DEFAULTFONT);        if (dim != null) {            l.setPreferredSize(dim);            l.setMinimumSize(dim);        }        return l;    }    /**     * Creates a desktop pane with some internal frames; a frame  holding the     * editor panel and a frame with a list of library objects.     *     * @return a desktop pane     */    protected JDesktopPane createDesktopPane() {        JDesktopPane desktop = new JDesktopPane();        desktop.setBackground(Constants.DEFAULTBACKGROUNDCOLOR);        libraryFrame = new JInternalFrame(ElanLocale.getString(                    "GraphicsEditor.Library"), true);        desktop.add(libraryFrame);        Object rect;        if ((rect = Preferences.get("LibraryIFrameBounds", null)) != null) {            libraryFrame.setBounds((Rectangle) rect);        } else {            libraryFrame.setBounds(350, 0, 180, 350);        }        libraryFrame.setVisible(true);        editFrame = new JInternalFrame("", true);        desktop.add(editFrame);        if ((rect = Preferences.get("EditorIFrameBounds", null)) != null) {            editFrame.setBounds((Rectangle) rect);        } else {            editFrame.setBounds(0, 0, 350, 350);        }        editorPanel = new EditorPanel(grabFirstFrameImage(),                annotation.getShape());        JScrollPane scrollPane = new JScrollPane(editorPanel);        editFrame.getContentPane().add(scrollPane);        editFrame.setVisible(true);        return desktop;    }    /**     * Creates icons from the symbols in the library to display  in a list. The     * symbols are scaled, preserving the aspect ratio.     */    protected void initLibrary() {        Object o = SVGParserAndStore.getLibrary(transcription);        if (o instanceof Hashtable) {            libTable = (Hashtable) o;        }        if ((libTable != null) && (libTable.size() > 0)) {            //StaticRenderer renderer;            BufferedImage iconImg = null;            Graphics2D g2d = null;            iconTable = new Hashtable(libTable.size());            AffineTransform at;            Enumeration keys = libTable.keys();            String id;            Shape shape;            //GraphicsNode node;            ImageIcon icon;            while (keys.hasMoreElements()) {                id = (String) keys.nextElement();                shape = (Shape) libTable.get(id);                if (shape == null) {                    continue;                }                iconImg = new BufferedImage(iconDimension.width,                        iconDimension.height, BufferedImage.TYPE_INT_RGB);                g2d = iconImg.createGraphics();                g2d.setColor(Color.white);                g2d.fillRect(0, 0, iconDimension.width, iconDimension.height);                Rectangle2D bounds = shape.getBounds2D();                float scaleX = (float) ((iconDimension.width - 6) / bounds.getWidth());                float scaleY = (float) ((iconDimension.height - 6) / bounds.getHeight());                float scale = (scaleX >= scaleY) ? scaleY : scaleX;                float realIconWidth = (float) (scale * bounds.getWidth());                float realIconHeight = (float) (scale * bounds.getHeight());                float transX = (float) (-bounds.getX() +                    ((iconDimension.width - 6 - realIconWidth) / 2f));                float transY = (float) (-bounds.getY() +                    ((iconDimension.height - 6 - realIconHeight) / 2f));                //System.out.println("Icon: w: " + realIconWidth + " h: " + realIconHeight + " tx: " + transX + " ty: " + transY);                at = AffineTransform.getTranslateInstance(3 + transX, 3 +                        transY);                at.scale(scale, scale);                g2d.setTransform(at);                g2d.setColor(STROKE_COLOR);                g2d.draw(shape);                //shape.paint(g2d, true);                icon = new ImageIcon(iconImg);                if (icon != null) {                    iconTable.put(id, icon);                }            }            iconList = new JList(iconTable.keySet().toArray());            iconList.setFixedCellHeight(iconDimension.height + 4);            iconList.setDragEnabled(true);            iconList.setCellRenderer(new LibraryIconRenderer());            iconList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);            // add a mouselistener; doubleclick means adding a reference to the selected symbol            iconList.addMouseListener(new MouseAdapter() {                    public void mouseClicked(MouseEvent me) {                        if (me.getClickCount() > 1) {                            if (me.getSource() == iconList) {                                Object o = iconList.getSelectedValue();                                if (o instanceof String &&                                        (editorPanel != null)) {                                    editorPanel.addGraphicAnnotation((String) o);                                }                            }                        }                    }                });        }        if (iconList != null) {            JScrollPane iconPane = new JScrollPane(iconList);            libraryFrame.getContentPane().add(iconPane);        }    }    /**     * Tries to retrieve the image of the first frame of the active annotation.     * The ElanMediaPlayer should provide this image.     *     * @return a BufferedImage containing the first video frame within this     *         annotation's boundaries     */    protected Image grabFirstFrameImage() {        ElanMediaPlayer player = ELANCommandFactory.getViewerManager(transcription)                                                   .getMasterMediaPlayer();        // have to cast to JMFGraphicMediaPlayer for now        if (player instanceof JMFGraphicMediaPlayer) {            JMFGraphicMediaPlayer jmfPlayer = (JMFGraphicMediaPlayer) player;            msPerFrame = (int) jmfPlayer.getMilliSecondsPerSample();            currentFrame = annotation.getBeginTimeBoundary() / msPerFrame;            return jmfPlayer.getFrameImageForTime(annotation.getBeginTimeBoundary());        }        if (player instanceof QTMediaPlayer) {            QTMediaPlayer qtPlayer = (QTMediaPlayer) player;            msPerFrame = (int) qtPlayer.getMilliSecondsPerSample();            currentFrame = annotation.getBeginTimeBoundary() / msPerFrame;            return qtPlayer.getFrameImageForTime(annotation.getBeginTimeBoundary());        }        return null;    }    /**     * Tries to retrieve the image corresponding with specified time.     *     * @param time the requested media time     *     * @return the corresponding video image or null if the operation did not     *         succeed     */    protected Image getFrameForTime(long time) {        ElanMediaPlayer player = ELANCommandFactory.getViewerManager(transcription)                                                   .getMasterMediaPlayer();        // have to cast to JMFGraphicMediaPlayer for now        if (player instanceof JMFGraphicMediaPlayer) {            JMFGraphicMediaPlayer jmfPlayer = (JMFGraphicMediaPlayer) player;            return jmfPlayer.getFrameImageForTime(time);        }        if (player instanceof QTMediaPlayer) {            QTMediaPlayer qtPlayer = (QTMediaPlayer) player;            return qtPlayer.getFrameImageForTime(time);        }        return null;    }    /**     * Handles actions of menuitems and buttons.     *     * @param ae the action event     */    public void actionPerformed(ActionEvent ae) {        String command = ae.getActionCommand();        if (command.equals("cancel")) {            cancelEdit();        } else if (command.equals("commit")) {            commitEdit();        } else if (command.equals("delete")) {            if (editorPanel != null) {                editorPanel.setShape(null);                updateToolBarShapeButtons();            }        } else if (command.equals("cut")) {            cut();        } else if (command.equals("copy")) {            copy();        } else if (command.equals("paste")) {            paste();        } else if (command.equals("select")) {            if (editorPanel != null) {                editorPanel.setToolMode(EditorPanel.SELECT_TOOL);            }        } else if (command.equals("recttool")) {            if (editorPanel != null) {                editorPanel.setToolMode(EditorPanel.RECT_TOOL);            }        } else if (command.equals("ovaltool")) {            if (editorPanel != null) {                editorPanel.setToolMode(EditorPanel.ELLIPSE_TOOL);            }        } else if (command.equals("linetool")) {            if (editorPanel != null) {                editorPanel.setToolMode(EditorPanel.LINE_TOOL);            }        } else if (command.equals("next")) {            if (editorPanel != null) {                nextFrame();            }        } else if (command.equals("prev")) {            if (editorPanel != null) {                previousFrame();            }        } else if (command.equals("first")) {            if (editorPanel != null) {                firstFrame();            }        } else if (command.equals("last")) {            if (editorPanel != null) {                lastFrame();            }        }    }    /**     * Handle zooming.     *     * @param ie the item event     */    public void itemStateChanged(ItemEvent ie) {        if (ie.getStateChange() == ItemEvent.SELECTED) {            String zoomString = (String) ie.getItem();            int index;            if ((index = zoomString.indexOf('%')) > 0) {                zoomString = zoomString.substring(0, index);            }            int zoom = 100;            try {                zoom = Integer.parseInt(zoomString);            } catch (NumberFormatException nfe) {                System.err.println("Error parsing the zoom level");            }            if (editorPanel != null) {                editorPanel.setZoom(zoom);            }        }    }    /**     * Check the state of the editor , the loaded frame and the clipboard and

⌨️ 快捷键说明

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