List of usage examples for javafx.scene.input Clipboard getString
public final String getString()
From source file:com.cdd.bao.editor.EditSchema.java
public void actionEditPaste() { if (!treeView.isFocused()) return; // punt to default action TreeItem<Branch> item = currentBranch(); if (item == null) { Util.informMessage("Clipboard Paste", "Select a group to paste into."); return;/*www. ja va 2 s .com*/ } Branch branch = item.getValue(); Clipboard clipboard = Clipboard.getSystemClipboard(); String serial = clipboard.getString(); if (serial == null) { Util.informWarning("Clipboard Paste", "Content is not parseable."); return; } JSONObject json = null; try { json = new JSONObject(new JSONTokener(serial)); } catch (JSONException ex) { Util.informWarning("Clipboard Paste", "Content is not parseable: it should be a JSON-formatted string."); return; } Schema.Group group = ClipboardSchema.unpackGroup(json); Schema.Assignment assn = ClipboardSchema.unpackAssignment(json); Schema.Assay assay = ClipboardSchema.unpackAssay(json); if (group == null && assn == null && assay == null) { Util.informWarning("Clipboard Paste", "Content does not represent a group, assignment or assay: cannot paste."); return; } pullDetail(); Schema schema = stack.getSchema(); if (group != null) { schema.appendGroup(schema.obtainGroup(branch.locatorID), group); } else if (assn != null) { schema.appendAssignment(schema.obtainGroup(branch.locatorID), assn); } else if (assay != null) { schema.appendAssay(assay); } stack.changeSchema(schema); rebuildTree(); if (group != null) setCurrentBranch(locateBranch(schema.locatorID(group))); else if (assn != null) setCurrentBranch(locateBranch(schema.locatorID(assn))); }
From source file:com.panemu.tiwulfx.table.TableControl.java
/** * Paste text on clipboard. Doesn't work on READ mode. *///from w w w . ja v a 2s . c om public void paste() { if (mode.get() == Mode.READ) { return; } final Clipboard clipboard = Clipboard.getSystemClipboard(); if (clipboard.hasString()) { final String text = clipboard.getString(); if (text != null) { List<TablePosition> cells = tblView.getSelectionModel().getSelectedCells(); if (cells.isEmpty()) { return; } TablePosition cell = cells.get(0); List<TableColumn<R, ?>> lstColumn = getLeafColumns(); TableColumn startColumn = null; for (TableColumn clm : lstColumn) { if (clm instanceof BaseColumn && clm == cell.getTableColumn()) { startColumn = (BaseColumn) clm; break; } } if (startColumn == null) { return; } int rowIndex = cell.getRow(); String[] arrString = text.split("\n"); boolean stopPasting = false; for (String line : arrString) { if (stopPasting) { break; } R item = null; if (rowIndex < tblView.getItems().size()) { item = tblView.getItems().get(rowIndex); } else if (mode.get() == Mode.EDIT) { /** * Will ensure the content display to TEXT_ONLY because * there is no way to update cell editors value (in * agile editing mode) */ tblView.getSelectionModel().clearSelection(); return;//stop pasting as it already touched last row } if (!lstChangedRow.contains(item)) { if (mode.get() == Mode.INSERT) { //means that selected row is not new row. Let's create new row createNewRow(rowIndex); item = tblView.getItems().get(rowIndex); } else { lstChangedRow.add(item); } } showRow(rowIndex); /** * Handle multicolumn paste */ String[] stringCellValues = line.split("\t"); TableColumn toFillColumn = startColumn; tblView.getSelectionModel().select(rowIndex, toFillColumn); for (String stringCellValue : stringCellValues) { if (toFillColumn == null) { break; } if (toFillColumn instanceof BaseColumn && toFillColumn.isEditable() && toFillColumn.isVisible()) { try { Object oldValue = toFillColumn.getCellData(item); Object newValue = ((BaseColumn) toFillColumn).convertFromString(stringCellValue); PropertyUtils.setSimpleProperty(item, ((BaseColumn) toFillColumn).getPropertyName(), newValue); if (mode.get() == Mode.EDIT) { ((BaseColumn) toFillColumn).addRecordChange(item, oldValue, newValue); } } catch (Exception ex) { MessageDialog.Answer answer = MessageDialogBuilder.error(ex) .message("msg.paste.error", stringCellValue, toFillColumn.getText()) .buttonType(MessageDialog.ButtonType.YES_NO) .yesOkButtonText("continue.pasting").noButtonText("stop") .show(getScene().getWindow()); if (answer == MessageDialog.Answer.NO) { stopPasting = true; break; } } } tblView.getSelectionModel().selectRightCell(); TablePosition nextCell = tblView.getSelectionModel().getSelectedCells().get(0); if (nextCell.getTableColumn() instanceof BaseColumn && nextCell.getTableColumn() != toFillColumn) { toFillColumn = (BaseColumn) nextCell.getTableColumn(); } else { toFillColumn = null; } } rowIndex++; } refresh(); /** * Will ensure the content display to TEXT_ONLY because there is * no way to update cell editors value (in agile editing mode) */ tblView.getSelectionModel().clearSelection(); } } }
From source file:net.rptools.tokentool.controller.TokenTool_Controller.java
@FXML void editPasteImageMenu_onAction(ActionEvent event) { Clipboard clipboard = Clipboard.getSystemClipboard(); Image originalImage = portraitImageView.getImage(); // Strangely, we get an error if we try to paste an image we put in the clipboard ourselves but File works ok? // -Dprism.order=sw also fixes it but not sure why... // So lets just check for File first... if (clipboard.hasFiles()) { clipboard.getFiles().forEach(file -> { try { Image cbImage = new Image(file.toURI().toURL().toExternalForm()); if (cbImage != null) updatePortrait(cbImage); updateFileNameTextField(FilenameUtils.getBaseName(file.toURI().toURL().toExternalForm())); } catch (Exception e) { log.error("Could not load image " + file); e.printStackTrace();/*from w w w .j a va 2s . c o m*/ } }); } else if (clipboard.hasImage()) { try { Image cbImage = clipboard.getImage(); if (cbImage != null) updatePortrait(cbImage); } catch (IllegalArgumentException e) { log.info(e); updatePortrait(originalImage); } } else if (clipboard.hasUrl()) { try { Image cbImage = new Image(clipboard.getUrl()); if (cbImage != null) updatePortrait(cbImage); updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getUrl())); } catch (IllegalArgumentException e) { log.info(e); } } else if (clipboard.hasString()) { try { Image cbImage = new Image(clipboard.getString()); if (cbImage != null) updatePortrait(cbImage); updateFileNameTextField(FileSaveUtil.searchURL(clipboard.getString())); } catch (IllegalArgumentException e) { log.info(e); } } }