Back to index

moin  1.9.0~rc2
PasteCommand.java
Go to the documentation of this file.
00001 /*
00002  * @(#)PasteCommand.java 5.1
00003  *
00004  */
00005 
00006 package CH.ifa.draw.standard;
00007 
00008 import java.util.*;
00009 import java.awt.*;
00010 import CH.ifa.draw.util.*;
00011 import CH.ifa.draw.framework.*;
00012 
00017 public class PasteCommand extends FigureTransferCommand {
00018 
00025     public PasteCommand(String name, DrawingView view) {
00026         super(name, view);
00027     }
00028 
00029     public void execute() {
00030         Point lastClick = fView.lastClick();
00031         FigureSelection selection = (FigureSelection)Clipboard.getClipboard().getContents();
00032         if (selection != null) {
00033             Vector figures = (Vector)selection.getData(FigureSelection.TYPE);
00034             if (figures.size() == 0)
00035                 return;
00036 
00037             Rectangle r = bounds(figures.elements());
00038             fView.clearSelection();
00039 
00040             insertFigures(figures, lastClick.x-r.x, lastClick.y-r.y);
00041             fView.checkDamage();
00042         }
00043     }
00044 
00045     Rectangle bounds(Enumeration k) {
00046         Rectangle r = ((Figure) k.nextElement()).displayBox();
00047         while (k.hasMoreElements())
00048             r.add(((Figure) k.nextElement()).displayBox());
00049         return r;
00050     }
00051 }
00052 
00053