📄 svgeditor.java
字号:
* update the toolbar buttons. */ public void updateToolBarShapeButtons() { if (editorPanel != null) { if (editorPanel.getShape() != null) { deleteButton.setEnabled(true); cutButton.setEnabled(true); copyButton.setEnabled(true); } else { deleteButton.setEnabled(false); cutButton.setEnabled(false); copyButton.setEnabled(false); } if (getClipboardContents() instanceof Shape) { pasteButton.setEnabled(true); } else { pasteButton.setEnabled(false); } } } /** * Update the object's coordinates etc. in the statusbar. */ public void updateObjectStatus() { if (editorPanel != null) { if (editorPanel.getShape() != null) { Shape s = editorPanel.getShape(); xValue.setText("" + s.getBounds().x); yValue.setText("" + s.getBounds().y); wValue.setText("" + s.getBounds().width); hValue.setText("" + s.getBounds().height); double d = Math.sqrt(Math.pow(s.getBounds().width, 2) + Math.pow(s.getBounds().height, 2)); dValue.setText("" + numbFormat.format(d)); } else { xValue.setText(null); yValue.setText(null); wValue.setText(null); hValue.setText(null); dValue.setText(null); } } } /** * Updates the coordinates of the mouse position in the statusbar. * * @param xPos the x position of the mouse * @param yPos the y position of the mouse */ public void updateMouseStatus(int xPos, int yPos) { mxValue.setText("" + xPos); myValue.setText("" + yPos); } /** * Enables and disables buttons that handle the activation of frame images * that exist within the boundaries of the current annotation. */ protected void updateFramePositionButtons() { if (currentFrame == (annotation.getBeginTimeBoundary() / msPerFrame)) { firstFrameButton.setEnabled(false); frameBackButton.setEnabled(false); frameForwardButton.setEnabled(true); lastFrameButton.setEnabled(true); } else { firstFrameButton.setEnabled(true); frameBackButton.setEnabled(true); if (currentFrame == ((annotation.getEndTimeBoundary() - 1) / msPerFrame)) { frameForwardButton.setEnabled(false); lastFrameButton.setEnabled(false); } else { frameForwardButton.setEnabled(true); lastFrameButton.setEnabled(true); } } } /** * Tries to load the next frame. The next frame's begin time should be * within the boundaries of the current annotation. */ private void nextFrame() { long next = currentFrame + 1; long time = next * msPerFrame; if ((time >= annotation.getBeginTimeBoundary()) && (time < annotation.getEndTimeBoundary())) { Image nextImage = getFrameForTime(time); currentFrame++; if (editorPanel != null) { editorPanel.setImage(nextImage); } } updateFramePositionButtons(); } /** * Tries to load the previous frame. The previous frame's end time should * be within the boundaries of the current annotation. */ private void previousFrame() { long prev = currentFrame - 1; long time = prev * msPerFrame; if ((time >= annotation.getBeginTimeBoundary()) && (time < annotation.getEndTimeBoundary())) { Image prevImage = getFrameForTime(time); currentFrame--; if (editorPanel != null) { editorPanel.setImage(prevImage); } } updateFramePositionButtons(); } /** * Tries to laod the frame that corresponds to the begin time of the * current annotation. */ private void firstFrame() { Image firstImage = getFrameForTime(annotation.getBeginTimeBoundary()); currentFrame = annotation.getBeginTimeBoundary() / msPerFrame; if (editorPanel != null) { editorPanel.setImage(firstImage); } updateFramePositionButtons(); } /** * Tries to load the frame that corresponds to the end time of the current * annotation. */ private void lastFrame() { Image lastImage = getFrameForTime(annotation.getEndTimeBoundary()); currentFrame = (annotation.getEndTimeBoundary() - 1) / msPerFrame; if (editorPanel != null) { editorPanel.setImage(lastImage); } updateFramePositionButtons(); } /** * Copy the current shape to the clipboard and remove it from the editor. */ private void cut() { if (editorPanel != null) { if (canAccessSystemClipboard()) { Shape s = editorPanel.getShape(); if (s != null) { ShapeTransferable st = new ShapeTransferable(s, editorPanel); Clipboard board = getToolkit().getSystemClipboard(); board.setContents(st, null); editorPanel.setShape(null); updateToolBarShapeButtons(); } } } } /** * Copy the current shape to the clipboard. */ private void copy() { if (editorPanel != null) { if (canAccessSystemClipboard()) { Shape s = editorPanel.getShape(); if (s != null) { Shape copy = null; if (s instanceof RectangularShape) { copy = (Shape) ((RectangularShape) s).clone(); } else if (s instanceof GeneralPath) { copy = (Shape) ((GeneralPath) s).clone(); } //add Polygon, Line, Point?? if (copy != null) { ShapeTransferable st = new ShapeTransferable(copy, editorPanel); Clipboard board = getToolkit().getSystemClipboard(); board.setContents(st, null); updateToolBarShapeButtons(); } } } } } /** * If there is a Shape object on the clipboard paste it to the editor. */ private void paste() { if (editorPanel != null) { Object contents = getClipboardContents(); if (contents instanceof Shape) { editorPanel.setShape((Shape) contents); } updateToolBarShapeButtons(); } } /** * Performs a check on the accessibility of the system clipboard. * * @return true if the system clipboard is accessible, false otherwise */ protected boolean canAccessSystemClipboard() { SecurityManager sm = System.getSecurityManager(); if (sm != null) { try { sm.checkSystemClipboardAccess(); return true; } catch (SecurityException se) { se.printStackTrace(); return false; } } return true; } /** * Returns the contents of the system clipboard if it is accessible. * * @return the contents of the system clipboard or null */ private Object getClipboardContents() { if (canAccessSystemClipboard()) { Transferable t = getToolkit().getSystemClipboard().getContents(null); try { DataFlavor df = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType + ";class=" + Shape.class.getName()); return t.getTransferData(df); } catch (Exception e) { //System.out.println("Could not get contents from the clipboard."); //e.printStackTrace(); } } return null; } /** * Cancel the edit operation. */ protected void cancelEdit() { savePreferences(); setVisible(false); dispose(); } /** * Commit the changes made to the graphic annotation. */ protected void commitEdit() { Shape shape = editorPanel.getShape(); Command c = ELANCommandFactory.createCommand(transcription, ELANCommandFactory.MODIFY_GRAPHIC_ANNOTATION); c.execute(annotation, new Object[] { shape }); savePreferences(); setVisible(false); dispose(); } /** * Load preferences. */ protected void loadPreferences() { dialogBounds = (Rectangle) Preferences.get("GraphicsEditorBounds", null); if (dialogBounds == null) { Window owner = this.getOwner(); if (owner != null) { //center relative to parent Dimension dim = owner.getSize(); Point loc = owner.getLocation(); dialogBounds = new Rectangle(loc.x + (dim.width / 4), loc.y + (dim.height / 4), dim.width / 2, dim.height / 2); } else { dialogBounds = new Rectangle(0, 0, 600, 500); } } } /** * Save preferences. */ protected void savePreferences() { Preferences.set("GraphicsEditorBounds", getBounds(), null); if (libraryFrame != null) { Preferences.set("LibraryIFrameBounds", libraryFrame.getBounds(), null); } if (editFrame != null) { Preferences.set("EditorIFrameBounds", editFrame.getBounds(), null); } } //#####################################################################// /** * A ListCellRenderer that uses a JLabel with an icon to render the cell. * It gets the icon from a Hashtable using the value String as a key. * * @author Han Sloetjes */ protected class LibraryIconRenderer extends DefaultListCellRenderer { /** * Creates a new LibraryIconRenderer instance */ LibraryIconRenderer() { super(); setIconTextGap(8); } /** * Returns a JLabel based list-cell renderer component. * * @param list the list this component is part of * @param value the value * @param index the index in the list * @param isSelected the selected state of this index * @param cellHasFocus the focused state of this index * * @return a list-cell renderer component */ public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); //setBorder(BorderFactory.createEmptyBorder(2, 8, 2, 2)); if (value instanceof String) { ImageIcon icon = (ImageIcon) iconTable.get(value); if (icon != null) { setIcon(icon); } } return this; } } //end list renderer //#######################################################################// /** * The panel that actual handles the edting of the graphical annotations. * Because it needs access to a lot of stuff that is administered by the * SVGEditor, this is implemented as an internal class. * * @author Han Sloetjes */ protected class EditorPanel extends JPanel implements MouseListener, MouseMotionListener { // tool constants
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -