1 18 package org.apache.batik.swing.gvt; 19 20 import java.awt.AlphaComposite ; 21 import java.awt.Color ; 22 import java.awt.Dimension ; 23 import java.awt.EventQueue ; 24 import java.awt.Graphics ; 25 import java.awt.Graphics2D ; 26 import java.awt.Rectangle ; 27 import java.awt.RenderingHints ; 28 import java.awt.Toolkit ; 29 import java.awt.Shape ; 30 import java.awt.datatransfer.Clipboard ; 31 import java.awt.datatransfer.StringSelection ; 32 import java.awt.event.ComponentAdapter ; 33 import java.awt.event.ComponentEvent ; 34 import java.awt.event.InputEvent ; 35 import java.awt.event.KeyEvent ; 36 import java.awt.event.KeyListener ; 37 import java.awt.event.MouseEvent ; 38 import java.awt.event.MouseListener ; 39 import java.awt.event.MouseMotionListener ; 40 import java.awt.geom.AffineTransform ; 41 import java.awt.geom.NoninvertibleTransformException ; 42 import java.awt.image.BufferedImage ; 43 import java.text.CharacterIterator ; 44 import java.util.Collections ; 45 import java.util.Iterator ; 46 import java.util.LinkedList ; 47 import java.util.List ; 48 49 import javax.swing.JComponent ; 50 51 import org.apache.batik.gvt.GraphicsNode; 52 import org.apache.batik.gvt.event.AWTEventDispatcher; 53 import org.apache.batik.gvt.event.SelectionAdapter; 54 import org.apache.batik.gvt.event.SelectionEvent; 55 import org.apache.batik.gvt.renderer.ConcreteImageRendererFactory; 56 import org.apache.batik.gvt.renderer.ImageRenderer; 57 import org.apache.batik.gvt.renderer.ImageRendererFactory; 58 import org.apache.batik.gvt.text.Mark; 59 import org.apache.batik.util.HaltingThread; 60 61 67 public class JGVTComponent extends JComponent { 68 69 72 protected Listener listener; 73 74 77 protected GVTTreeRenderer gvtTreeRenderer; 78 79 82 protected GraphicsNode gvtRoot; 83 84 87 protected ImageRendererFactory rendererFactory = 88 new ConcreteImageRendererFactory(); 89 90 93 protected ImageRenderer renderer; 94 95 98 protected List gvtTreeRendererListeners = 99 Collections.synchronizedList(new LinkedList ()); 100 101 104 protected boolean needRender; 105 106 109 protected boolean progressivePaint; 110 111 114 protected HaltingThread progressivePaintThread; 115 116 119 protected BufferedImage image; 120 121 124 protected AffineTransform initialTransform = new AffineTransform (); 125 126 129 protected AffineTransform renderingTransform = new AffineTransform (); 130 131 134 protected AffineTransform paintingTransform; 135 136 139 protected List interactors = new LinkedList (); 140 141 144 protected Interactor interactor; 145 146 149 protected List overlays = new LinkedList (); 150 151 154 protected List jgvtListeners = null; 155 156 159 protected AWTEventDispatcher eventDispatcher; 160 161 164 protected TextSelectionManager textSelectionManager; 165 166 169 protected boolean doubleBufferedRendering; 170 171 174 protected boolean eventsEnabled; 175 176 180 protected boolean selectableText; 181 182 188 protected boolean useUnixTextSelection = true; 189 190 193 protected boolean suspendInteractions; 194 195 198 protected boolean disableInteractions; 199 200 203 public JGVTComponent() { 204 this(false, false); 205 } 206 207 214 public JGVTComponent(boolean eventsEnabled, boolean selectableText) { 215 setBackground(Color.white); 216 218 this.eventsEnabled = eventsEnabled; 219 this.selectableText = selectableText; 220 221 listener = createListener(); 222 223 addKeyListener(listener); 224 addMouseListener(listener); 225 addMouseMotionListener(listener); 226 227 addGVTTreeRendererListener(listener); 228 229 addComponentListener(new ComponentAdapter () { 230 public void componentResized(ComponentEvent e) { 231 if (updateRenderingTransform()) 232 scheduleGVTRendering(); 233 } 234 }); 235 236 } 237 238 242 public void setDisableInteractions(boolean b) { 243 disableInteractions = b; 244 } 245 246 250 public boolean getDisableInteractions() { 251 return disableInteractions; 252 } 253 254 261 public void setUseUnixTextSelection(boolean b) { 262 useUnixTextSelection = b; 263 } 264 265 269 public void getUseUnixTextSelection(boolean b) { 270 useUnixTextSelection = b; 271 } 272 273 276 public List getInteractors() { 277 return interactors; 278 } 279 280 283 public List getOverlays() { 284 return overlays; 285 } 286 287 290 public BufferedImage getOffScreen() { 291 return image; 292 } 293 294 295 public void addJGVTComponentListener(JGVTComponentListener listener) { 296 if (jgvtListeners == null) 297 jgvtListeners = new LinkedList (); 298 jgvtListeners.add(listener); 299 } 300 301 public void removeJGVTComponentListener(JGVTComponentListener listener) { 302 if (jgvtListeners == null) return; 303 jgvtListeners.remove(listener); 304 } 305 306 309 public void resetRenderingTransform() { 310 setRenderingTransform(initialTransform); 311 } 312 313 316 public void stopProcessing() { 317 if (gvtTreeRenderer != null) { 318 needRender = false; 319 gvtTreeRenderer.halt(); 320 haltProgressivePaintThread(); 321 } 322 } 323 324 327 public GraphicsNode getGraphicsNode() { 328 return gvtRoot; 329 } 330 331 334 public void setGraphicsNode(GraphicsNode gn) { 335 setGraphicsNode(gn, true); 336 initialTransform = new AffineTransform (); 337 updateRenderingTransform(); 338 setRenderingTransform(initialTransform, true); 339 } 340 341 344 protected void setGraphicsNode(GraphicsNode gn, boolean createDispatcher) { 345 gvtRoot = gn; 346 if (gn != null && createDispatcher) { 347 initializeEventHandling(); 348 } 349 if (eventDispatcher != null) { 350 eventDispatcher.setRootNode(gn); 351 } 352 } 353 354 357 protected void initializeEventHandling() { 358 if (eventsEnabled) { 359 eventDispatcher = new AWTEventDispatcher(); 360 if (selectableText) { 361 textSelectionManager = createTextSelectionManager(); 362 textSelectionManager.addSelectionListener 363 (new UnixTextSelectionListener()); 364 } 365 } 366 } 367 368 373 protected TextSelectionManager createTextSelectionManager() { 374 return new TextSelectionManager(this, eventDispatcher); 375 } 376 377 381 386 public TextSelectionManager getTextSelectionManager() { 387 return textSelectionManager; 388 } 389 390 395 public void setSelectionOverlayColor(Color color) { 396 if (textSelectionManager != null) { 397 textSelectionManager.setSelectionOverlayColor(color); 398 } 399 } 400 401 404 public Color getSelectionOverlayColor() { 405 if (textSelectionManager != null) { 406 return textSelectionManager.getSelectionOverlayColor(); 407 } else { 408 return null; 409 } 410 } 411 412 418 public void setSelectionOverlayStrokeColor(Color color) { 419 if (textSelectionManager != null) { 420 textSelectionManager.setSelectionOverlayStrokeColor(color); 421 } 422 } 423 424 427 public Color getSelectionOverlayStrokeColor() { 428 if (textSelectionManager != null) { 429 return textSelectionManager.getSelectionOverlayStrokeColor(); 430 } else { 431 return null; 432 } 433 } 434 435 441 public void setSelectionOverlayXORMode(boolean state) { 442 if (textSelectionManager != null) { 443 textSelectionManager.setSelectionOverlayXORMode(state); 444 } 445 } 446 447 451 public boolean isSelectionOverlayXORMode() { 452 if (textSelectionManager != null) { 453 return textSelectionManager.isSelectionOverlayXORMode(); 454 } else { 455 return false; 456 } 457 } 458 459 465 public void select(Mark start, Mark end) { 466 if (textSelectionManager != null) { 467 textSelectionManager.setSelection(start, end); 468 } 469 } 470 471 474 public void deselectAll() { 475 if (textSelectionManager != null) { 476 textSelectionManager.clearSelection(); 477 } 478 } 479 480 484 487 public void setProgressivePaint(boolean b) { 488 if (progressivePaint != b) { 489 progressivePaint = b; 490 haltProgressivePaintThread(); 491 } 492 } 493 494 497 public boolean getProgressivePaint() { 498 return progressivePaint; 499 } 500 501 public Rectangle getRenderRect() { 502 Dimension d = getSize(); 503 return new Rectangle (0, 0, d.width, d.height); 504 } 505 506 509 public void immediateRepaint() { 510 if (EventQueue.isDispatchThread()) { 511 Rectangle visRect = getRenderRect(); 512 if (doubleBufferedRendering) 513 repaint(visRect.x, visRect.y, 514 visRect.width, visRect.height); 515 else 516 paintImmediately(visRect.x, visRect.y, 517 visRect.width, visRect.height); 518 } else { 519 try { 520 EventQueue.invokeAndWait(new Runnable () { 521 public void run() { 522 Rectangle visRect = getRenderRect(); 523 if (doubleBufferedRendering) 524 repaint(visRect.x, visRect.y, 525 visRect.width, visRect.height); 526 else 527 paintImmediately(visRect.x, visRect.y, 528 visRect.width,visRect.height); 529 } 530 }); 531 } catch (Exception e) { 532 } 533 } 534 } 535 536 539 public void paintComponent(Graphics g) { 540 super.paintComponent(g); 541 542 Graphics2D g2d = (Graphics2D )g; 543 544 Rectangle visRect = getRenderRect(); 545 g2d.setComposite(AlphaComposite.SrcOver); 546 g2d.setPaint(getBackground()); 547 g2d.fillRect(visRect.x, visRect.y, 548 visRect.width, visRect.height); 549 550 if (image != null) { 551 if (paintingTransform != null) { 552 g2d.transform(paintingTransform); 553 } 554 g2d.drawRenderedImage(image, null); 555 g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, 556 RenderingHints.VALUE_ANTIALIAS_OFF); 557 Iterator it = overlays.iterator(); 558 while (it.hasNext()) { 559 ((Overlay)it.next()).paint(g); 560 } 561 } 562 } 563 564 569 public void setPaintingTransform(AffineTransform at) { 570 paintingTransform = at; 571 immediateRepaint(); 572 } 573 574 577 public AffineTransform getPaintingTransform() { 578 return paintingTransform; 579 } 580 581 585 public void setRenderingTransform(AffineTransform at) { 586 setRenderingTransform(at, true); 587 } 588 589 public void setRenderingTransform(AffineTransform at, 590 boolean performRedraw) { 591 renderingTransform = at; 592 suspendInteractions = true; 593 if (eventDispatcher != null) { 594 try { 595 eventDispatcher.setBaseTransform 596 (renderingTransform.createInverse()); 597 } catch (NoninvertibleTransformException e) { 598 handleException(e); 599 } 600 } 601 if (jgvtListeners != null) { 602 Iterator iter = jgvtListeners.iterator(); 603 ComponentEvent ce = new ComponentEvent 604 (this, JGVTComponentListener.COMPONENT_TRANSFORM_CHANGED); 605 while (iter.hasNext()) { 606 JGVTComponentListener l = (JGVTComponentListener)iter.next(); 607 l.componentTransformChanged(ce); 608 } 609 } 610 611 if (performRedraw) 612 scheduleGVTRendering(); 613 } 614 615 618 public AffineTransform getInitialTransform() { 619 return initialTransform; 620 } 621 622 625 public AffineTransform getRenderingTransform() { 626 return renderingTransform; 627 } 628 629 634 public void setDoubleBufferedRendering(boolean b) { 635 doubleBufferedRendering = b; 636 } 637 638 642 public boolean getDoubleBufferedRendering() { 643 return doubleBufferedRendering; 644 } 645 646 649 public void addGVTTreeRendererListener(GVTTreeRendererListener l) { 650 gvtTreeRendererListeners.add(l); 651 } 652 653 656 public void removeGVTTreeRendererListener(GVTTreeRendererListener l) { 657 gvtTreeRendererListeners.remove(l); 658 } 659 660 664 public void flush() { 665 renderer.flush(); 666 } 667 668 672 public void flush(Rectangle r) { 673 renderer.flush(r); 674 } 675 676 679 protected ImageRenderer createImageRenderer() { 680 return rendererFactory.createStaticImageRenderer(); 681 } 682 683 686 protected void renderGVTTree() { 687 Rectangle visRect = getRenderRect(); 688 if (gvtRoot == null || visRect.width <= 0 || visRect.height <= 0) { 689 return; 690 } 691 692 if (renderer == null || renderer.getTree() != gvtRoot) { 694 renderer = createImageRenderer(); 695 renderer.setTree(gvtRoot); 696 } 697 698 AffineTransform inv; 700 try { 701 inv = renderingTransform.createInverse(); 702 } catch (NoninvertibleTransformException e) { 703 throw new InternalError (e.getMessage()); 704 } 705 Shape s = inv.createTransformedShape(visRect); 706 707 gvtTreeRenderer = new GVTTreeRenderer(renderer, renderingTransform, 709 doubleBufferedRendering, s, 710 visRect.width, visRect.height); 711 gvtTreeRenderer.setPriority(Thread.MIN_PRIORITY); 712 713 Iterator it = gvtTreeRendererListeners.iterator(); 714 while (it.hasNext()) { 715 gvtTreeRenderer.addGVTTreeRendererListener 716 ((GVTTreeRendererListener)it.next()); 717 } 718 719 if (eventDispatcher != null) { 722 eventDispatcher.setEventDispatchEnabled(false); 723 } 724 725 gvtTreeRenderer.start(); 726 } 727 728 732 protected boolean computeRenderingTransform() { 733 initialTransform = new AffineTransform (); 734 if (!initialTransform.equals(renderingTransform)) { 735 setRenderingTransform(initialTransform, false); 736 return true; 737 } 738 return false; 739 } 740 741 745 protected boolean updateRenderingTransform() { 746 return false; 748 } 749 750 753 protected void handleException(Exception e) { 754 } 756 757 760 protected void releaseRenderingReferences() { 761 eventDispatcher = null; 762 if (textSelectionManager != null) { 763 overlays.remove(textSelectionManager.getSelectionOverlay()); 764 textSelectionManager = null; 765 } 766 renderer = null; 767 image = null; 768 gvtRoot = null; 769 } 770 771 774 protected void scheduleGVTRendering() { 775 if (gvtTreeRenderer != null) { 776 needRender = true; 777 gvtTreeRenderer.halt(); 778 } else { 779 renderGVTTree(); 780 } 781 } 782 783 private void haltProgressivePaintThread() { 784 if (progressivePaintThread != null) { 785 progressivePaintThread.halt(); 786 progressivePaintThread = null; 787 } 788 } 789 790 793 protected Listener createListener() { 794 return new Listener (); 795 } 796 797 800 protected class Listener 801 implements GVTTreeRendererListener, 802 KeyListener , 803 MouseListener , 804 MouseMotionListener { 805 boolean checkClick = false; 806 boolean hadDrag = false; 807 int startX, startY; 808 long startTime; 809 int MAX_DISP = 4*4; 810 long CLICK_TIME = 200; 811 812 815 protected Listener() { 816 } 817 818 820 823 public void gvtRenderingPrepare(GVTTreeRendererEvent e) { 824 suspendInteractions = true; 825 if (!progressivePaint && !doubleBufferedRendering) { 826 image = null; 827 } 828 } 829 830 833 public void gvtRenderingStarted(GVTTreeRendererEvent e) { 834 if (progressivePaint && !doubleBufferedRendering) { 835 image = e.getImage(); 836 progressivePaintThread = new HaltingThread() { 837 public void run() { 838 final Thread thisThread = this; 839 try { 840 while (!hasBeenHalted()) { 841 EventQueue.invokeLater(new Runnable () { 842 public void run() { 843 if (progressivePaintThread == 844 thisThread) { 845 Rectangle vRect = getRenderRect(); 846 repaint(vRect.x, vRect.y, 847 vRect.width, vRect.height); 848 } 849 } 850 }); 851 sleep(200); 852 } 853 } catch (InterruptedException ie) { 854 } catch (ThreadDeath td) { 855 throw td; 856 } catch (Throwable t) { 857 t.printStackTrace(); 858 } 859 } 860 }; 861 progressivePaintThread.setPriority(Thread.MIN_PRIORITY + 1); 862 progressivePaintThread.start(); 863 } 864 if (!doubleBufferedRendering) { 865 paintingTransform = null; 866 suspendInteractions = false; 867 } 868 } 869 870 873 public void gvtRenderingCompleted(GVTTreeRendererEvent e) { 874 haltProgressivePaintThread(); 875 876 if (doubleBufferedRendering) { 877 paintingTransform = null; 878 suspendInteractions = false; 879 } 880 881 gvtTreeRenderer = null; 882 if (needRender) { 883 renderGVTTree(); 884 needRender = false; 885 } else { 886 image = e.getImage(); 887 immediateRepaint(); 888 } 889 if (eventDispatcher != null) { 890 eventDispatcher.setEventDispatchEnabled(true); 891 } 892 } 893 894 897 public void gvtRenderingCancelled(GVTTreeRendererEvent e) { 898 renderingStopped(); 899 } 900 901 904 public void gvtRenderingFailed(GVTTreeRendererEvent e) { 905 renderingStopped(); 906 } 907 908 912 private void renderingStopped() { 913 haltProgressivePaintThread(); 914 915 if (doubleBufferedRendering) { 916 suspendInteractions = false; 917 } 918 919 gvtTreeRenderer = null; 920 if (needRender) { 921 renderGVTTree(); 922 needRender = false; 923 } else { 924 immediateRepaint(); 925 } 926 927 if (eventDispatcher != null) { 928 eventDispatcher.setEventDispatchEnabled(true); 929 } 930 } 931 932 934 938 public void keyTyped(KeyEvent e) { 939 selectInteractor(e); 940 if (interactor != null) { 941 interactor.keyTyped(e); 942 deselectInteractor(); 943 } else if (eventDispatcher != null) { 944 dispatchKeyTyped(e); 945 } 946 } 947 948 951 protected void dispatchKeyTyped(KeyEvent e) { 952 eventDispatcher.keyTyped(e); 953 } 954 955 958 public void keyPressed(KeyEvent e) { 959 selectInteractor(e); 960 if (interactor != null) { 961 interactor.keyPressed(e); 962 deselectInteractor(); 963 } else if (eventDispatcher != null) { 964 dispatchKeyPressed(e); 965 } 966 } 967 968 971 protected void dispatchKeyPressed(KeyEvent e) { 972 eventDispatcher.keyPressed(e); 973 } 974 975 978 public void keyReleased(KeyEvent e) { 979 selectInteractor(e); 980 if (interactor != null) { 981 interactor.keyReleased(e); 982 deselectInteractor(); 983 } else if (eventDispatcher != null) { 984 dispatchKeyReleased(e); 985 } 986 } 987 988 991 protected void dispatchKeyReleased(KeyEvent e) { 992 eventDispatcher.keyReleased(e); 993 } 994 995 997 1000 public void mouseClicked(MouseEvent e) { 1001 selectInteractor(e); 1002 if (interactor != null) { 1003 interactor.mouseClicked(e); 1004 deselectInteractor(); 1005 } else if (eventDispatcher != null) { 1006 dispatchMouseClicked(e); 1007 } 1008 } 1009 1010 1013 protected void dispatchMouseClicked(MouseEvent e) { 1014 eventDispatcher.mouseClicked(e); 1015 } 1016 1017 1020 public void mousePressed(MouseEvent e) { 1021 startX = e.getX(); 1022 startY = e.getY(); 1023 startTime = System.currentTimeMillis(); 1024 checkClick = true; 1025 1026 selectInteractor(e); 1027 if (interactor != null) { 1028 interactor.mousePressed(e); 1029 deselectInteractor(); 1030 } else if (eventDispatcher != null) { 1031 dispatchMousePressed(e); 1032 } 1033 } 1034 1035 1038 protected void dispatchMousePressed(MouseEvent e) { 1039 eventDispatcher.mousePressed(e); 1040 } 1041 1042 1045 public void mouseReleased(java.awt.event.MouseEvent e) { 1046 if ((checkClick) && hadDrag) { 1047 int dx = startX-e.getX(); 1048 int dy = startY-e.getY(); 1049 long cTime = System.currentTimeMillis(); 1050 if ((dx*dx+dy*dy < MAX_DISP) && 1051 (cTime-startTime) < CLICK_TIME) { 1052 MouseEvent click = new MouseEvent 1055 (e.getComponent(), 1056 MouseEvent.MOUSE_CLICKED, 1057 e.getWhen(), 1058 e.getModifiers(), e.getX(), 1060 e.getY(), 1061 e.getClickCount(), 1062 e.isPopupTrigger()); 1063 1064 mouseClicked(click); 1065 } 1066 } 1067 checkClick = false; 1068 hadDrag = false; 1069 1070 selectInteractor(e); 1071 if (interactor != null) { 1072 interactor.mouseReleased(e); 1073 deselectInteractor(); 1074 } else if (eventDispatcher != null) { 1075 dispatchMouseReleased(e); 1076 } 1077 } 1078 1079 1082 protected void dispatchMouseReleased(MouseEvent e) { 1083 eventDispatcher.mouseReleased(e); 1084 } 1085 1086 1089 public void mouseEntered(MouseEvent e) { 1090 selectInteractor(e); 1092 if (interactor != null) { 1093 interactor.mouseEntered(e); 1094 deselectInteractor(); 1095 } else if (eventDispatcher != null) { 1096 dispatchMouseEntered(e); 1097 } 1098 } 1099 1100 1103 protected void dispatchMouseEntered(MouseEvent e) { 1104 eventDispatcher.mouseEntered(e); 1105 } 1106 1107 1110 public void mouseExited(MouseEvent e) { 1111 selectInteractor(e); 1112 if (interactor != null) { 1113 interactor.mouseExited(e); 1114 deselectInteractor(); 1115 } else if (eventDispatcher != null) { 1116 dispatchMouseExited(e); 1117 } 1118 } 1119 1120 1123 protected void dispatchMouseExited(MouseEvent e) { 1124 eventDispatcher.mouseExited(e); 1125 } 1126 1127 1129 1136 public void mouseDragged(MouseEvent e) { 1137 hadDrag = true; 1138 int dx = startX-e.getX(); 1139 int dy = startY-e.getY(); 1140 if (dx*dx+dy*dy > MAX_DISP) 1141 checkClick = false; 1142 1143 selectInteractor(e); 1144 if (interactor != null) { 1145 interactor.mouseDragged(e); 1146 deselectInteractor(); 1147 } else if (eventDispatcher != null) { 1148 dispatchMouseDragged(e); 1149 } 1150 } 1151 1152 1155 protected void dispatchMouseDragged(MouseEvent e) { 1156 eventDispatcher.mouseDragged(e); 1157 } 1158 1159 1163 public void mouseMoved(MouseEvent e) { 1164 selectInteractor(e); 1165 if (interactor != null) { 1166 interactor.mouseMoved(e); 1167 deselectInteractor(); 1168 } else if (eventDispatcher != null) { 1169 dispatchMouseMoved(e); 1170 } 1171 } 1172 1173 1176 protected void dispatchMouseMoved(MouseEvent e) { 1177 eventDispatcher.mouseMoved(e); 1178 } 1179 1180 1183 protected void selectInteractor(InputEvent ie) { 1184 if (!disableInteractions && 1185 !suspendInteractions && 1186 interactor == null && 1187 gvtRoot != null) { 1188 Iterator it = interactors.iterator(); 1189 while (it.hasNext()) { 1190 Interactor i = (Interactor)it.next(); 1191 if (i.startInteraction(ie)) { 1192 interactor = i; 1193 break; 1194 } 1195 } 1196 } 1197 } 1198 1199 1202 protected void deselectInteractor() { 1203 if (interactor.endInteraction()) { 1204 interactor = null; 1205 } 1206 } 1207 } 1208 1209 protected class UnixTextSelectionListener 1210 extends SelectionAdapter { 1211 1212 public void selectionDone(SelectionEvent evt) { 1213 if (!useUnixTextSelection) return; 1214 1215 Object o = evt.getSelection(); 1216 if (!(o instanceof CharacterIterator )) 1217 return; 1218 CharacterIterator iter = (CharacterIterator ) o; 1219 1220 SecurityManager securityManager; 1222 securityManager = System.getSecurityManager(); 1223 if (securityManager != null) { 1224 try { 1225 securityManager.checkSystemClipboardAccess(); 1226 } catch (SecurityException e) { 1227 return; } 1229 } 1230 1231 int sz = iter.getEndIndex()-iter.getBeginIndex(); 1232 if (sz == 0) return; 1233 1234 char[] cbuff = new char[sz]; 1235 cbuff[0] = iter.first(); 1236 for (int i=1; i<cbuff.length;++i) { 1237 cbuff[i] = iter.next(); 1238 } 1239 final String strSel = new String (cbuff); 1240 new Thread () { 1244 public void run() { 1245 Clipboard cb; 1246 cb = Toolkit.getDefaultToolkit().getSystemClipboard(); 1247 StringSelection sel; 1248 sel = new StringSelection (strSel); 1249 cb.setContents(sel, sel); 1250 } 1251 }.start(); 1252 } 1253 } 1254 1255 1256} 1257 | Popular Tags |