List of usage examples for java.awt.datatransfer DataFlavor javaJVMLocalObjectMimeType
String javaJVMLocalObjectMimeType
To view the source code for java.awt.datatransfer DataFlavor javaJVMLocalObjectMimeType.
Click Source Link
From source file:Main.java
public static void main(String[] args) { String df = DataFlavor.javaJVMLocalObjectMimeType; System.out.println(df); }
From source file:DnDDemo2.java
public boolean importData(JComponent component, Transferable transferable) { String colorMimeType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.awt.Color"; JTextComponent textComponent = (JTextComponent) component; try {/*w w w.j a va 2 s .c o m*/ DataFlavor colorFlavor = new DataFlavor(colorMimeType); Color color = (Color) transferable.getTransferData(colorFlavor); String text = (String) transferable.getTransferData(DataFlavor.stringFlavor); textComponent.setForeground(color); textComponent.setText(text); } catch (Exception e) { e.printStackTrace(); } return true; }
From source file:DnDDemo2.java
public TextColor(String text, Color color) { String colorMimeType = DataFlavor.javaJVMLocalObjectMimeType + ";class=java.awt.Color"; DataFlavor colorFlavor = null; try {// w ww . j av a 2 s. c om colorFlavor = new DataFlavor(colorMimeType); } catch (ClassNotFoundException e) { } flavors = new DataFlavor[2]; flavors[0] = DataFlavor.stringFlavor; flavors[1] = colorFlavor; this.text = text; this.color = color; }
From source file:com.rockhoppertech.symchords.fx.SymChordsController.java
protected void setupDragonDrop() { Image image = new Image(getClass().getResourceAsStream("/images/rocky-32-trans.png")); dragImageView = new ImageView(image); dragImageView.setFitHeight(32);/*from ww w. ja v a2 s.c om*/ dragImageView.setFitWidth(32); grandStaff.setOnDragDetected(new EventHandler<MouseEvent>() { @Override public void handle(MouseEvent me) { if (!root.getChildren().contains(dragImageView)) { root.getChildren().add(dragImageView); } // dragImageView.setOpacity(0.5); dragImageView.toFront(); dragImageView.setMouseTransparent(true); dragImageView.setVisible(true); dragImageView.relocate((int) (me.getSceneX() - dragImageView.getBoundsInLocal().getWidth() / 2), (int) (me.getSceneY() - dragImageView.getBoundsInLocal().getHeight() / 2)); Dragboard db = grandStaff.startDragAndDrop(TransferMode.ANY); // TODO remove the custom image nonsense in javafx 8 // javafx 8 // db.setDragView(dragImageView); ClipboardContent content = new ClipboardContent(); // MIDITrack track = grandStaff.getMIDITrack(); MIDITrack track = model.getMIDITrack(); content.put(midiTrackDataFormat, track); db.setContent(content); me.consume(); } }); grandStaff.setOnDragDone(new EventHandler<DragEvent>() { public void handle(DragEvent e) { dragImageView.setVisible(false); e.consume(); } }); // Parent root = grandStaff.getScene().getRoot(); // stage.getScene().getRoot(); if (root != null) { root.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent e) { Point2D localPoint = grandStaff.getScene().getRoot() .sceneToLocal(new Point2D(e.getSceneX(), e.getSceneY())); dragImageView.relocate( (int) (localPoint.getX() - dragImageView.getBoundsInLocal().getWidth() / 2), (int) (localPoint.getY() - dragImageView.getBoundsInLocal().getHeight() / 2)); e.consume(); } }); } trackList.setOnDragOver(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* * data is dragged over the target; accept it only if it is not * dragged from the same node and if it has MIDITrack data */ if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) { logger.debug("drag over"); /* allow for both copying and moving, whatever user chooses */ event.acceptTransferModes(TransferMode.COPY_OR_MOVE); } // Don't consume the event. Let the layers below process the // DragOver event as well so that the // translucent container image will follow the cursor. // event.consume(); } }); trackList.setOnDragEntered(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* the drag-and-drop gesture entered the target */ /* show to the user that it is an actual gesture target */ logger.debug("drag entered"); if (event.getGestureSource() != trackList && event.getDragboard().hasContent(midiTrackDataFormat)) { DropShadow dropShadow = new DropShadow(); dropShadow.setRadius(5.0); dropShadow.setOffsetX(3.0); dropShadow.setOffsetY(3.0); dropShadow.setColor(Color.color(0.4, 0.5, 0.5)); trackList.setEffect(dropShadow); } event.consume(); } }); trackList.setOnDragExited(new EventHandler<DragEvent>() { public void handle(DragEvent event) { /* mouse moved away, remove the graphical cues */ trackList.setEffect(null); event.consume(); } }); trackList.setOnDragDropped(new EventHandler<DragEvent>() { public void handle(DragEvent event) { Dragboard db = event.getDragboard(); boolean success = false; if (db.hasContent(midiTrackDataFormat)) { MIDITrack track = (MIDITrack) db.getContent(midiTrackDataFormat); trackList.getItems().add(track); success = true; } /* * let the source know whether the data was successfully * transferred and used */ event.setDropCompleted(success); event.consume(); } }); logger.debug("jvm mime {}", DataFlavor.javaJVMLocalObjectMimeType); }
From source file:org.simmi.GeneSetHead.java
License:asdf
public TransferHandler dragRows(final JTable table, final List<String> specs) { TransferHandler th = null;/*from w w w .jav a2s .c o m*/ try { final DataFlavor ndf = new DataFlavor(DataFlavor.javaJVMLocalObjectMimeType); final DataFlavor df = DataFlavor.getTextPlainUnicodeFlavor(); final String charset = df.getParameter("charset"); final Transferable transferable = new Transferable() { @Override public Object getTransferData(DataFlavor arg0) throws UnsupportedFlavorException, IOException { if (arg0.equals(ndf)) { int[] rr = currentRowSelection; //table.getSelectedRows(); List<String> selseq = new ArrayList<String>(rr.length); for (int r : rr) { int i = table.convertRowIndexToModel(r); selseq.add(specs.get(i)); } return selseq; } else { String ret = "";//makeCopyString(); for (int r = 0; r < table.getRowCount(); r++) { Object o = table.getValueAt(r, 0); if (o != null) { ret += o.toString(); } else { ret += ""; } for (int c = 1; c < table.getColumnCount(); c++) { o = table.getValueAt(r, c); if (o != null) { ret += "\t" + o.toString(); } else { ret += "\t"; } } ret += "\n"; } //return arg0.getReaderForText( this ); return new ByteArrayInputStream(ret.getBytes(charset)); } //return ret; } @Override public DataFlavor[] getTransferDataFlavors() { return new DataFlavor[] { df, ndf }; } @Override public boolean isDataFlavorSupported(DataFlavor arg0) { if (arg0.equals(df) || arg0.equals(ndf)) { return true; } return false; } }; th = new TransferHandler() { private static final long serialVersionUID = 1L; public int getSourceActions(JComponent c) { return TransferHandler.COPY_OR_MOVE; } public boolean canImport(TransferHandler.TransferSupport support) { return true; } protected Transferable createTransferable(JComponent c) { currentRowSelection = table.getSelectedRows(); return transferable; } public boolean importData(TransferHandler.TransferSupport support) { try { System.err.println(table.getSelectedRows().length); DataFlavor[] dfs = support.getDataFlavors(); if (support.isDataFlavorSupported(ndf)) { Object obj = support.getTransferable().getTransferData(ndf); ArrayList<String> seqs = (ArrayList<String>) obj; /*ArrayList<String> newlist = new ArrayList<String>( serifier.lgse.size() ); for( int r = 0; r < table.getRowCount(); r++ ) { int i = table.convertRowIndexToModel(r); newlist.add( specs.get(i) ); } serifier.lgseq.clear(); serifier.lgseq = newlist;*/ Point p = support.getDropLocation().getDropPoint(); int k = table.rowAtPoint(p); specs.removeAll(seqs); for (String s : seqs) { specs.add(k++, s); } TableRowSorter<TableModel> trs = (TableRowSorter<TableModel>) table.getRowSorter(); trs.setSortKeys(null); table.tableChanged(new TableModelEvent(table.getModel())); return true; } /* else if( support.isDataFlavorSupported( df ) ) { Object obj = support.getTransferable().getTransferData( df ); InputStream is = (InputStream)obj; System.err.println( charset ); importReader( new BufferedReader(new InputStreamReader(is, charset)) ); updateView(); return true; } else if( support.isDataFlavorSupported( DataFlavor.stringFlavor ) ) { Object obj = support.getTransferable().getTransferData( DataFlavor.stringFlavor ); String str = (String)obj; importReader( new BufferedReader( new StringReader(str) ) ); updateView(); return true; }*/ } catch (UnsupportedFlavorException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } return false; } }; } catch (Exception e) { e.printStackTrace(); } return th; }