java - Is there some way to delay (or stream) clipboard operations in AWT / Swing? -
i have table million rows.
if select rows , copy, takes approximately 5 minutes before responsiveness returns gui , before can paste application. less great, started looking improvements.
if make alternative thread-safe tablemodel, can background operation of building string , push clipboard (on edt, if need be). gui responsive, still 5 minutes before can paste application, in ways worse experience, because @ least when blocked edt, able tell when operation finished. know add gui feedback it, seems wrong action copy.
if @ same thing happening between native applications, notice can copy enormous amount of data 1 application no delay. can paste application no delay, caveat can take long time all information end in there. instance, if paste huge text textedit terminal, seems bit @ time somehow.
is there way in awt well?
i attempted declaring alternate flavours returning reader
, inputstream
, turns out if this, asks reader one, fetches reader , reads entire stream, storing string. moves 5 minute delay code inside jre, solving nothing. stupid, because there whole framework around type of data transfer methods transferable
supports, yet no matter type expose, system seems convert down same type, in best case take forever build, or in worst case run out of heap.
maybe there type doesn't though, thought i'd post question ask whether knows.
example of 1 transferhandler
, although built-in 1 on jtable
exhibits same issue.
private class combinedtransferhandler extends transferhandler { @override protected transferable createtransferable(jcomponent component) { if (component instanceof jtable) { jtable table = (jtable) component; int[] rows = table.getselectedrows(); if (!table.getrowselectionallowed()) { int rowcount = table.getrowcount(); rows = new int[rowcount]; (int counter = 0; counter < rowcount; counter++) { rows[counter] = counter; } } // columns omitted because know use return new basictransferable(getplaindata(rows), null); } return null; } @override public int getsourceactions(jcomponent c) { return copy; } private string getplaindata(int[] rows) { stringbuilder result = new stringbuilder(); int staticcolumncount = statictable.getcolumncount(); int maincolumncount = maintable.getcolumncount(); (int row : rows) { (int viewcolumn = 0; viewcolumn < staticcolumncount; viewcolumn++) { if (viewcolumn > 0) { result.append('\t'); } object value = statictable.getvalueat(row, viewcolumn); value = (value == null) ? "" : value.tostring(); result.append(value); } (int viewcolumn = 0; viewcolumn < maincolumncount; viewcolumn++) { if (staticcolumncount > 0 || viewcolumn > 0) { result.append('\t'); } object value = maintable.getvalueat(row, viewcolumn); value = (value == null) ? "" : value.tostring(); result.append(value); } result.append('\n'); } return result.tostring(); } }
Comments
Post a Comment