Advertisement
nex036ara

pr13

Dec 12th, 2013
84
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 2.21 KB | None | 0 0
  1. package grafeditor.actions;
  2.  
  3. import java.awt.datatransfer.Transferable;
  4. import java.util.EventObject;
  5.  
  6. public class ClipboardEvent extends EventObject{
  7.    
  8.     protected Transferable newContent;
  9.    
  10.  
  11.     //clipboar je source  za cl.event
  12.     public ClipboardEvent(Object source) {
  13.         super(source);
  14.         // TODO Auto-generated constructor stub
  15.     }
  16.  
  17.     public Transferable getNewContent() {
  18.         return newContent;
  19.     }
  20.  
  21.     public void setNewContent(Transferable newContent) {
  22.         this.newContent = newContent;
  23.     }
  24.    
  25.    
  26. }
  27. --------------------
  28. package grafeditor.actions;
  29.  
  30. import java.util.EventListener;
  31.  
  32. public interface ClipboardListener extends EventListener{
  33.     public void clipboardContentChange(ClipboardEvent c_event);
  34.  
  35. }
  36. --------------------------
  37. package grafeditor.actions;
  38.  
  39. import grafeditor.event.UpdateEvent;
  40. import grafeditor.event.UpdateListener;
  41.  
  42. import java.awt.datatransfer.Clipboard;
  43. import java.awt.datatransfer.ClipboardOwner;
  44. import java.awt.datatransfer.Transferable;
  45.  
  46. import javax.swing.event.EventListenerList;
  47.  
  48. public class IspaljivacDogadjaja extends Clipboard{
  49.  
  50.    
  51.     transient  EventListenerList listenerList = new EventListenerList();
  52.    
  53.    
  54.     public IspaljivacDogadjaja(String name) {
  55.         super(name);
  56.         // TODO Auto-generated constructor stub
  57.     }
  58.    
  59.    
  60.      public void addUpdateListener(ClipboardListener l) {
  61.          listenerList.add(ClipboardListener.class, l);
  62.      }
  63.  
  64.      public void removeUpdateListener(ClipboardListener l) {
  65.          listenerList.remove(ClipboardListener.class, l);
  66.      }
  67.      
  68.         /**
  69.          * Javljamo svim listenerima da se dogaÄ‘aj desio
  70.          */
  71.         protected void fireUpdatePerformed(ClipboardEvent e) {
  72.            
  73.              Object[] listeners = listenerList.getListenerList();
  74.              for (int i = listeners.length-2; i>=0; i-=2) {
  75.                  if (listeners[i]==ClipboardListener.class) {
  76.                      ((ClipboardListener)listeners[i+1]).clipboardContentChange(e);
  77.                  }
  78.              }
  79.          }
  80.  
  81.  
  82.         @Override
  83.         public synchronized void setContents(Transferable contents,ClipboardOwner owner) {
  84.             // TODO Auto-generated method stub
  85.             super.setContents(contents, owner);
  86.            
  87.             ClipboardEvent e = new ClipboardEvent(this);
  88.             e.setNewContent(contents);
  89.             fireUpdatePerformed(e);
  90.         }  
  91.    
  92. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement