MCPcopy Create free account
hub / github.com/AstroImageJ/astroimagej / copyToClipboard

Method copyToClipboard

ij/src/main/java/ij/gui/PlotWindow.java:863–905  ·  view source on GitHub ↗

Copy the first dataset or all values to the clipboard

(boolean writeAllColumns)

Source from the content-addressed store, hash-verified

861
862 /** Copy the first dataset or all values to the clipboard */
863 @AstroImageJ(reason = "Enhanced Plot Copy", modified = true)
864 void copyToClipboard(boolean writeAllColumns) {
865 float[] xValues = plot.getXValues();
866 float[] yValues = plot.getYValues();
867 if (xValues == null) return;
868 Clipboard systemClipboard = null;
869 try {systemClipboard = getToolkit().getSystemClipboard();}
870 catch (Exception e) {systemClipboard = null; }
871 if (systemClipboard==null)
872 {IJ.error("Unable to copy to Clipboard."); return;}
873 IJ.showStatus("Copying plot values...");
874 /*CharArrayWriter aw = new CharArrayWriter(10*xValues.length);
875 PrintWriter pw = new PrintWriter(aw); //uses platform's line termination characters
876
877 if (writeAllColumns) {
878 ResultsTable rt = plot.getResultsTableWithLabels();
879 if (!Prefs.dontSaveHeaders) {
880 String headings = rt.getColumnHeadings();
881 pw.println(headings);
882 }
883 for (int i=0; i<rt.size(); i++)
884 pw.println(rt.getRowAsString(i));
885 } else {
886 int xdigits = 0;
887 if (saveXValues)
888 xdigits = plot.getPrecision(xValues);
889 int ydigits = plot.getPrecision(yValues);
890 for (int i=0; i<Math.min(xValues.length, yValues.length); i++) {
891 if (saveXValues)
892 pw.println(IJ.d2s(xValues[i],xdigits)+"\t"+IJ.d2s(yValues[i],ydigits));
893 else
894 pw.println(IJ.d2s(yValues[i],ydigits));
895 }
896 }
897 String text = aw.toString();
898 pw.close();
899 StringSelection contents = new StringSelection(text);
900 systemClipboard.setContents(contents, this);
901 IJ.showStatus(text.length() + " characters copied to Clipboard");*/
902 systemClipboard.setContents(new TransferablePlot(plot), this);
903 if (autoClose)
904 {imp.changes=false; close();}
905 }
906
907 public void lostOwnership(Clipboard clipboard, Transferable contents) {}
908

Callers 1

actionPerformedMethod · 0.95

Calls 5

errorMethod · 0.95
showStatusMethod · 0.95
closeMethod · 0.65
getXValuesMethod · 0.45
getYValuesMethod · 0.45

Tested by

no test coverage detected