1. /*
  2. * @(#)Clipboard.java 1.18 03/01/23
  3. *
  4. * Copyright 2003 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. package java.awt.datatransfer;
  8. /**
  9. * A class which implements a mechanism to transfer data using
  10. * cut/copy/paste operations.
  11. *
  12. * @see java.awt.Toolkit#getSystemClipboard
  13. *
  14. * @version 1.18, 01/23/03
  15. * @author Amy Fowler
  16. */
  17. public class Clipboard {
  18. String name;
  19. protected ClipboardOwner owner;
  20. protected Transferable contents;
  21. /**
  22. * Creates a clipboard object.
  23. *
  24. * @see java.awt.Toolkit#getSystemClipboard
  25. */
  26. public Clipboard(String name) {
  27. this.name = name;
  28. }
  29. /**
  30. * Returns the name of this clipboard object.
  31. *
  32. * @see java.awt.Toolkit#getSystemClipboard
  33. */
  34. public String getName() {
  35. return name;
  36. }
  37. /**
  38. * Sets the current contents of the clipboard to the specified
  39. * transferable object and registers the specified clipboard owner
  40. * as the owner of the new contents. If there is an existing owner
  41. * registered, that owner is notified that it no longer holds ownership
  42. * of the clipboard contents. The method throws
  43. * <code>IllegalStateException</code> if the clipboard is currently
  44. * unavailable. For example, on some platforms, the system clipboard is
  45. * unavailable while it is accessed by another application.
  46. *
  47. * @param contents the transferable object representing the
  48. * clipboard content
  49. * @param owner the object which owns the clipboard content
  50. * @throws IllegalStateException if the clipboard is currently unavailable
  51. * @see java.awt.Toolkit#getSystemClipboard
  52. */
  53. public synchronized void setContents(Transferable contents, ClipboardOwner owner) {
  54. final ClipboardOwner oldOwner = this.owner;
  55. final Transferable oldContents = this.contents;
  56. this.owner = owner;
  57. this.contents = contents;
  58. if (oldOwner != null && oldOwner != owner) {
  59. oldOwner.lostOwnership(this, oldContents);
  60. }
  61. }
  62. /**
  63. * Returns a transferable object representing the current contents
  64. * of the clipboard. If the clipboard currently has no contents,
  65. * it returns <code>null</code>. The parameter Object requestor is
  66. * not currently used. The method throws
  67. * <code>IllegalStateException</code> if the clipboard is currently
  68. * unavailable. For example, on some platforms, the system clipboard is
  69. * unavailable while it is accessed by another application.
  70. *
  71. * @param requestor the object requesting the clip data (not used)
  72. * @return the current transferable object on the clipboard
  73. * @throws IllegalStateException if the clipboard is currently unavailable
  74. * @see java.awt.Toolkit#getSystemClipboard
  75. */
  76. public synchronized Transferable getContents(Object requestor) {
  77. return contents;
  78. }
  79. }