📄 inlineeditbox.java
字号:
private void doSelectAll() { if (attached) { textArea.selectAll(); } else { exttextArea.selectAll(); } } /** * Enables/disables edit menu items in the popup menu.<br> * Check the contents of the <code>textArea</code> component and the * system clipboard. */ private void updatePopup() { if ((textArea.getSelectedText() == null) || (textArea.getSelectedText().length() == 0)) { cutPUMI.setEnabled(false); copyPUMI.setEnabled(false); } else { cutPUMI.setEnabled(true); copyPUMI.setEnabled(true); } if (isTextOnClipboard()) { pastePUMI.setEnabled(true); } else { pastePUMI.setEnabled(false); } if ((textArea.getText() == null) || (textArea.getText().length() == 0)) { selectAllPUMI.setEnabled(false); } else { selectAllPUMI.setEnabled(true); } } /** * Enables/disables edit menu items in the popup menu.<br> * Check the contents of the <code>textArea</code> component and the * system clipboard. */ private void updateMenuBar() { if ((exttextArea.getSelectedText() == null) || (exttextArea.getSelectedText().length() == 0)) { cutMI.setEnabled(false); copyMI.setEnabled(false); } else { cutMI.setEnabled(true); copyMI.setEnabled(true); } if (isTextOnClipboard()) { pasteMI.setEnabled(true); } else { pasteMI.setEnabled(false); } if ((exttextArea.getText() == null) || (exttextArea.getText().length() == 0)) { selectAllMI.setEnabled(false); } else { selectAllMI.setEnabled(true); } } /** * Checks whether the contents of the system clipboard can be paste into a * textcomponent. * * @return true if there is contents of type text, false otherwise */ private boolean isTextOnClipboard() { Transferable contents = null; try { contents = Toolkit.getDefaultToolkit().getSystemClipboard() .getContents(this); } catch (IllegalStateException ise) { LOG.warning("Could not access the system clipboard."); } if (contents != null) { DataFlavor[] flavors = contents.getTransferDataFlavors(); DataFlavor best = DataFlavor.selectBestTextFlavor(flavors); if (best != null) { return true; } } return false; } /** * Returns the (configured) editor component, ready to be used in a * viewer's layout. * * @return the editor component * * @see #configureEditor(Class, Font, Dimension) * @see #startEdit() */ public JComponent getEditorComponent() { if (editorComponent == null) { return this; } return editorComponent; } /** * Sets up and configures a certain kind of editor component.<br> * * @param preferredComponent DOCUMENT ME! * @param font DOCUMENT ME! * @param size DOCUMENT ME! * * @see #getEditorComponent() * @see #startEdit() */ public void configureEditor(Class preferredComponent, Font font, Dimension size) { if (preferredComponent == JPanel.class) { // configures "this" editorComponent = this; if (isUsingControlledVocabulary) { if (cvEntryComp == null) { cvEntryComp = new CVEntryComponent(JScrollPane.class); cvEntryComp.setAnnotation(annotation); } else { if (!(cvEntryComp.getEditorComponent() instanceof JScrollPane)) { cvEntryComp.setDelegate(preferredComponent); } } if (font != null) { cvEntryComp.setFont(font); } cvEntryComp.addPopupListener(); int w; int h; if (size == null) { w = minCVWidth; h = minCVHeight; } else { w = size.width; h = size.height; if (w < minCVWidth) { w = minCVWidth; } if (h < minCVHeight) { h = minCVHeight; } } removeAll(); add(cvEntryComp.getEditorComponent(), BorderLayout.CENTER); this.setSize(w, h); validate(); } else { if (font != null) { setFont(font); } removeAll(); add(textAreaScrollPane, BorderLayout.CENTER); if (size != null) { setSize(size); } validate(); } } else if (preferredComponent == JScrollPane.class) { // configure the scrollpane of either the attached-mode textfield // or the CVEntry list if (isUsingControlledVocabulary) { if (cvEntryComp == null) { cvEntryComp = new CVEntryComponent(preferredComponent); cvEntryComp.setAnnotation(annotation); } else { if (!(cvEntryComp.getEditorComponent() instanceof JScrollPane)) { cvEntryComp.setDelegate(preferredComponent); } } if (font != null) { cvEntryComp.setFont(font); } cvEntryComp.addPopupListener(); if (size != null) { cvEntryComp.getEditorComponent().setSize(size); } editorComponent = cvEntryComp.getEditorComponent(); } else { if (font != null) { setFont(font); } if (size != null) { setSize(size); } editorComponent = textAreaScrollPane; } } else if (preferredComponent == JComboBox.class) { if (isUsingControlledVocabulary) { if (cvEntryComp == null) { cvEntryComp = new CVEntryComponent(preferredComponent); cvEntryComp.setAnnotation(annotation); } else { if (!(cvEntryComp.getEditorComponent() instanceof JComboBox)) { cvEntryComp.setDelegate(preferredComponent); } } if (font != null) { cvEntryComp.setFont(font); } if (size != null) { cvEntryComp.getEditorComponent().setSize(size); } editorComponent = cvEntryComp.getEditorComponent(); } } } /** * Makes the editorComponent visible and tries to grabFocus.<br> * This should be called after configuring and getting the editor * component * * @see #configureEditor(Class, Font, Dimension) * @see #getEditorComponent() */ public void startEdit() { isEditing = true; if (editorComponent == this) { setVisible(true); requestFocus(); } else { if (isUsingControlledVocabulary) { cvEntryComp.grabFocus(); } else { editorComponent.requestFocus(); } } } /** * Menu items' ActionPerformed handling. * * @param e the action event */ public void actionPerformed(ActionEvent e) { String command = e.getActionCommand(); if (command.equals(EDIT_MENU_DET)) { detachEditor(); } else if (command.equals(EDIT_MENU_ATT)) { if (attachable == true) { attachEditor(); } } else if (command.equals(EDIT_MENU_CNL)) { cancelEdit(); } else if (command.equals(EDIT_MENU_CMT)) { commitEdit(); } else if (command.equals("cut")) { doCut(); } else if (command.equals("copy")) { doCopy(); } else if (command.equals("paste")) { doPaste(); } else if (command.equals("selectAll")) { doSelectAll(); } else { for (int i = 0; i < numberOfLocales; i++) { if (command.equals(allLocales[i].getDisplayName())) { annotationLocale = allLocales[i]; if (attached) { ImUtil.setLanguage(textArea, annotationLocale); textArea.setFont(uniFont); } else { ImUtil.setLanguage(exttextArea, annotationLocale); exttextArea.setFont(uniFont.deriveFont(20.0f)); } break; } } } } /** * Mouse event handling for popping up the popup menu. * * @param e the mouse event */ public void mouseClicked(MouseEvent e) { } /** * Stub * * @param e the mouse event */ public void mouseEntered(MouseEvent e) { } /** * Stub * * @param e the mouse event */ public void mouseExited(MouseEvent e) { } /** * Stub * * @param e the mouse event */ public void mousePressed(MouseEvent e) { if (javax.swing.SwingUtilities.isRightMouseButton(e) || e.isPopupTrigger()) { updatePopup(); popupMenu.show(textArea, e.getX(), e.getY()); popupMenu.setVisible(true); } } /** * Stub * * @param e the mouse event */ public void mouseReleased(MouseEvent e) { } /** * M_P all e.consume() calls outcommented because the events are needed to * deselect a newly made / edited annotation in EudicoAnnotationFrame * with the Escape key M_P 25 june 2003 Just the first outcommented. The * last when has to be consumed. * * @param e the key event */ public void keyPressed(KeyEvent e) { // KB Cancel Changes if (e.getKeyCode() == KeyEvent.VK_ESCAPE) { //e.consume(); cancelEdit(); } // KB Detach else if ((e.getKeyCode() == KeyEvent.VK_ENTER) && e.isShiftDown()) { if (attachable == true) { e.consume(); // thread is necessary to avoid the dialog blocking events still in the eventqueue! if (attached) { SwingUtilities.invokeLater(new Runnable() { public void run() { detachEditor(); } }); } else { attachEditor(); } } } // KB Confirm else if ((e.getKeyCode() == KeyEvent.VK_ENTER) && ((e.getModifiers() & Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()) != 0)) { e.consume(); commitEdit(); } /*else if ((e.getKeyCode() == KeyEvent.VK_ENTER) && e.isMetaDown() && System.getProperty("os.name").startsWith("Mac OS")) { commitEdit(); // hack for osx metake }*/ } /** * Stub * * @param e the key event */ public void keyReleased(KeyEvent e) { } /** * Stub * * @param e the key event */ public void keyTyped(KeyEvent e) { } /** * Updates menu items of the menubar by checking the system clipboard. * * @param e the menu event */ public void menuSelected(MenuEvent e) { updateMenuBar(); } /** * Stub * * @param e the menu event */ public void menuDeselected(MenuEvent e) { } /** * Stub * * @param e the menu event */ public void menuCanceled(MenuEvent e) { } /** * Updates UI elements after a change in the selected Locale. */ public void updateLocale() { detachPUMI.setText(ElanLocale.getString("InlineEditBox.Detach")); commitPUMI.setText(ElanLocale.getString("InlineEditBox.Commit")); cancelPUMI.setText(ElanLocale.getString("InlineEditBox.Cancel")); cutPUMI.setText(ElanLocale.getString("InlineEditBox.Edit.Cut")); copyPUMI.setText(ElanLocale.getString("InlineEditBox.Edit.Copy")); pastePUMI.setText(ElanLocale.getString("InlineEditBox.Edit.Paste"));
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -