Esempio n. 1
0
 public CommandResult execute(CommandContext context, Selection selection) {
   Clipboard.get(context).set(context.getScreen(), selection, this);
   return new BatchResult(
       new UpdateCommandsResult(),
       new NotificationResult(context, this)
           .setArgs(selection.size())
           .setDefaultMessage("{0,choice,1#Item|1<{0} items} put into the clipboard"));
 }
Esempio n. 2
0
  @Test
  public void testSimple() throws Exception {
    List<String> list = new ArrayList<String>();
    list.add("hello");
    list.add("world");

    String uuid = Clipboard.put(list);

    List<String> serList = (List<String>) Clipboard.get(uuid);

    assertEquals(serList.get(0), list.get(0));
  }
  @Override
  public void paste() {
    ClipboardContents clip = Clipboard.get();
    Collection<CanvasObject> contents = clip.getElements();
    List<CanvasObject> add = new ArrayList<CanvasObject>(contents.size());
    for (CanvasObject o : contents) {
      add.add(o.clone());
    }
    if (add.isEmpty()) return;

    // find how far we have to translate shapes so that at least one of the
    // pasted shapes doesn't match what's already in the model
    Collection<CanvasObject> raw = canvas.getModel().getObjectsFromBottom();
    MatchingSet<CanvasObject> cur = new MatchingSet<CanvasObject>(raw);
    int dx = 0;
    while (true) {
      // if any shapes in "add" aren't in canvas, we are done
      boolean allMatch = true;
      for (CanvasObject o : add) {
        if (!cur.contains(o)) {
          allMatch = false;
          break;
        }
      }
      if (!allMatch) break;

      // otherwise translate everything by 10 pixels and repeat test
      for (CanvasObject o : add) {
        o.translate(10, 10);
      }
      dx += 10;
    }

    Location anchorLocation = clip.getAnchorLocation();
    if (anchorLocation != null && dx != 0) {
      anchorLocation = anchorLocation.translate(dx, dx);
    }

    canvas
        .getProject()
        .doAction(
            new SelectionAction(
                canvas,
                Strings.getter("pasteClipboardAction"),
                null,
                add,
                add,
                anchorLocation,
                clip.getAnchorFacing()));
  }