@Override public void actionPerformed(ActionEvent ev) { Component component = (Component) ev.getSource(); final String componentName = component.getName(); switch (componentName) { case SAVE_MENU_ITEM_NAME: case SAVE_AS_MENU_ITEM_NAME: boolean mustChooseFile = SAVE_AS_MENU_ITEM_NAME.equals(componentName); saveToDisk(mustChooseFile); break; case NEW_MENU_ITEM_NAME: case OPEN_MENU_ITEM_NAME: showSaveConfirmationIfNecessaryAndRun( "You have changes on your current document. Save before continuing?", componentName, new Runnable() { @Override public void run() { if (NEW_MENU_ITEM_NAME.equals(componentName)) { setSpreadsheet(new Spreadsheet()); setCurrentFile(null); } else { // open Path chosenFile = chooseFile(JFileChooser.OPEN_DIALOG); openSpreadsheet(chosenFile); } } }); break; case COPY_MENU_ITEM_NAME: Object displayValue = mCellDisplayValueManager.getDisplayValueOfCellAt(getSelectedCellLocation()); if (!"".equals(displayValue)) { Transferable contents = new StringSelection(displayValue.toString()); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null); } break; case COPY_FORMULA_MENU_ITEM_NAME: String cellContent = mSpreadsheet.getCellContentAt(getSelectedCellLocation()); if (cellContent != null) { Transferable contents = new StringSelection(cellContent); Toolkit.getDefaultToolkit().getSystemClipboard().setContents(contents, null); } break; case PASTE_MENU_ITEM_NAME: Transferable clipboard = Toolkit.getDefaultToolkit().getSystemClipboard().getContents(null); CellLocation selectedLocation = getSelectedCellLocation(); try { Object transferData = clipboard.getTransferData(DataFlavor.stringFlavor); mTableModel.setValueAt( transferData.toString(), selectedLocation.getRow(), selectedLocation.getColumn()); } catch (UnsupportedFlavorException | IOException ex) { // we can only use the string flavor anyway, nothing we can do here } break; } }
void canvasFocusLost(FocusEvent e) { if (isXEmbedActive() && !e.isTemporary()) { xembedLog.fine("Forwarding FOCUS_LOST"); int num = 0; if (AccessController.doPrivileged(new GetBooleanAction("sun.awt.xembed.testing"))) { Component opp = e.getOppositeComponent(); try { num = Integer.parseInt(opp.getName()); } catch (NumberFormatException nfe) { } } xembed.sendMessage(xembed.handle, XEMBED_FOCUS_OUT, num, 0, 0); } }