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

Method copySelection

ij/src/main/java/ij/text/TextPanel.java:818–863  ·  view source on GitHub ↗

Copies the current selection to the system clipboard. Returns the number of characters copied.

()

Source from the content-addressed store, hash-verified

816 Returns the number of characters copied.
817 */
818 @AstroImageJ(reason = "Limit selection to tabs", modified = true)
819 public int copySelection() {
820 if (IJ.recording() && title.equals("Results"))
821 Recorder.record("String.copyResults");
822 if (selStart==-1 || selEnd==-1)
823 return copyAll();
824 StringBuffer sb = new StringBuffer();
825 ResultsTable rt2 = getResultsTable();
826 boolean hasRowNumers = rt2!=null && rt2.showRowNumbers();
827 if (Prefs.copyColumnHeaders && labels!=null && !labels.equals("") && selStart==0 && selEnd==iRowCount-1) {
828 if (hasRowNumers && Prefs.noRowNumbers) {
829 String s = labels;
830 int index = s.indexOf("\t",s.indexOf("\t")+1);
831 if (index!=-1)
832 s = s.substring(index+1, s.length());
833 sb.append(s);
834 } else
835 sb.append(labels);
836 sb.append('\n');
837 }
838 for (int i=selStart; i<=selEnd; i++) {
839 char[] chars = (char[])(vData.elementAt(i));
840 String s = new String(chars);
841 if (s.endsWith("\t"))
842 s = s.substring(0, s.length()-1);
843 if (hasRowNumers && Prefs.noRowNumbers && labels!=null && !labels.equals("")) {
844 int index = s.indexOf("\t");
845 if (index!=-1)
846 s = s.substring(index+1, s.length());
847 sb.append(s);
848 } else
849 sb.append(s);
850 if (i<selEnd || selEnd>selStart) sb.append('\n');
851 }
852 String s = new String(sb);
853 Clipboard clip = getToolkit().getSystemClipboard();
854 if (clip==null) return 0;
855 StringSelection cont = new StringSelection(s);
856 clip.setContents(cont,this);
857 if (s.length()>0) {
858 IJ.showStatus((selEnd-selStart+1)+" lines copied to clipboard");
859 if (this.getParent() instanceof ImageJ)
860 Analyzer.setUnsavedMeasurements(false);
861 }
862 return s.length();
863 }
864
865 int copyAll() {
866 selectAll();

Callers 4

copyResultsMethod · 0.95
doCommandMethod · 0.95
copyAllMethod · 0.95
cutSelectionMethod · 0.95

Calls 13

recordingMethod · 0.95
recordMethod · 0.95
copyAllMethod · 0.95
getResultsTableMethod · 0.95
showRowNumbersMethod · 0.95
showStatusMethod · 0.95
substringMethod · 0.80
getParentMethod · 0.80
lengthMethod · 0.65
appendMethod · 0.65
equalsMethod · 0.45

Tested by

no test coverage detected