private void jLabel7MousePressed(
     java.awt.event.MouseEvent evt) { // GEN-FIRST:event_jLabel7MousePressed
   JComponent comp =
       (JComponent) evt.getSource(); // se crea una variable componente y se le da un evento
   TransferHandler handler = comp.getTransferHandler(); // se le agrega al handler el componente
   handler.exportAsDrag(comp, evt, TransferHandler.COPY);
 } // GEN-LAST:event_jLabel7MousePressed
 public final void startDrag(MouseEvent e) {
   if (enable) {
     JPanel c = (JPanel) e.getComponent().getParent();
     // this.gui.selectElement(e.getX(), e.getY());
     TransferHandler handler = c.getTransferHandler();
     handler.exportAsDrag(c, e, TransferHandler.MOVE);
   }
 }
 /** {@inheritDoc} */
 public void dragEnter(DropTargetDragEvent evt) {
   target = (JComponent) evt.getDropTargetContext().getComponent();
   TransferHandler th = target.getTransferHandler();
   canImport = th.canImport(target, evt.getCurrentDataFlavors());
   if (canImport) {
     saveComponentState(target);
     lastPosition = evt.getLocation();
   }
 }
  @Override()
  public void mousePressed(MouseEvent e) {
    System.out.println(
        "Step 1 of 7: Mouse pressed. Going to export our RandomDragAndDropPanel so that it is draggable.");

    JComponent c = (JComponent) e.getSource();
    TransferHandler handler = c.getTransferHandler();
    handler.exportAsDrag(c, e, TransferHandler.COPY);
  }
    @Override
    @SuppressWarnings("unchecked")
    public boolean importData(TransferSupport support) {
      if (!this.canImport(support)) return false;

      if (support.getComponent() == mTextArea && mTextHandler.importData(support)) {
        // dropping text on text area was handled
        return true;
      }

      List<File> files;
      try {
        files =
            (List<File>) support.getTransferable().getTransferData(DataFlavor.javaFileListFlavor);
      } catch (UnsupportedFlavorException | IOException ex) {
        // should never happen (or JDK is buggy)
        return false;
      }

      for (File file : files) {
        if (Utils.isAllowedAttachmentFile(file)) {
          mChatView.sendFile(file);
        }
      }
      return !files.isEmpty();
    }
    @Override
    public void mouseDragged(MouseEvent e) {
      int ctrlMask = InputEvent.CTRL_DOWN_MASK;
      int action =
          ((e.getModifiersEx() & ctrlMask) == ctrlMask)
              ? TransferHandler.COPY
              : TransferHandler.MOVE;

      JTable setTable = (JTable) e.getSource();
      // 非選択状態からいきなりドラッグを開始すると cellEditor が残ってしまう問題の workaround
      if (setTable.isEditing()) {
        setTable.getCellEditor().stopCellEditing();
      }
      TransferHandler handler = setTable.getTransferHandler();
      handler.exportAsDrag(setTable, e, action);
    }
 // ======================================================
 // ======================================================
 private void treeMousePressed(java.awt.event.MouseEvent evt) {
   int mask = evt.getModifiers();
   if ((mask & MouseEvent.BUTTON1_MASK) != 0) {
     TreePath selectedPath = getPathForLocation(evt.getX(), evt.getY());
     if (selectedPath == null) return;
     DefaultMutableTreeNode node =
         (DefaultMutableTreeNode) selectedPath.getPathComponent(selectedPath.getPathCount() - 1);
     Object o = node.getUserObject();
     if (o instanceof String) {
       TransferHandler transfer = this.getTransferHandler();
       transfer.exportAsDrag(this, evt, TransferHandler.COPY);
       dragged_node = node;
       parent.setCursor(renderer.getNodeCursor(node));
     }
   }
 }
Beispiel #8
0
  public static class CopyKeyAdapter extends KeyAdapter {
    private static final String defaultEditorKitCopyActionName = DefaultEditorKit.copyAction;
    private static final String transferHandlerCopyActionName =
        (String) TransferHandler.getCopyAction().getValue(Action.NAME);

    @Override
    public void keyPressed(KeyEvent e) {
      // Accept "copy" key strokes
      KeyStroke ks = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers());
      JComponent comp = (JComponent) e.getSource();
      for (int i = 0; i < 3; i++) {
        InputMap im = comp.getInputMap(i);
        Object key = im.get(ks);
        if (defaultEditorKitCopyActionName.equals(key)
            || transferHandlerCopyActionName.equals(key)) {
          return;
        }
      }
      // Accept JTable navigation key strokes
      if (!tableNavigationKeys.contains(e.getKeyCode())) {
        e.consume();
      }
    }

    @Override
    public void keyTyped(KeyEvent e) {
      e.consume();
    }
  }
 @Override
 public void exportAsDrag(JComponent comp, InputEvent e, int action) {
   /* TODO: add support for dragging file link from table icon into other apps */
   if (e instanceof MouseEvent) {
     MouseEvent me = (MouseEvent) e;
     int col = entryTable.columnAtPoint(me.getPoint());
     String[] res = entryTable.getIconTypeForColumn(col);
     if (res == null) {
       super.exportAsDrag(comp, e, DnDConstants.ACTION_LINK);
       return;
     }
     // We have an icon column:
     if (res == MainTableFormat.FILE) {
       LOGGER.info("Dragging file");
       draggingFile = true;
     }
   }
   super.exportAsDrag(comp, e, DnDConstants.ACTION_LINK);
 }
  /** action handler function for copying a legend into clip board */
  public void exportToClipBoard() {
    BufferedImage img;
    try {
      img = MapTools.getLegendAsImage(appContainer.getMapModel(null), true);
    } catch (Exception e) {
      LOG.logError(e.getMessage(), e);
      return;
    }

    final JLabel label = new JLabel(new ImageIcon(img));
    label.setTransferHandler(new ImageSelection());

    // use both clip boards for text?
    Clipboard clip = getDefaultToolkit().getSystemSelection();
    if (clip != null) {
      TransferHandler handler = label.getTransferHandler();
      handler.exportToClipboard(label, clip, TransferHandler.COPY);
    }
    clip = getDefaultToolkit().getSystemClipboard();
    TransferHandler handler = label.getTransferHandler();
    handler.exportToClipboard(label, clip, TransferHandler.COPY);
  }
  public static void ImageToClipBoard(Image i) {

    final Clipboard clipboard = java.awt.Toolkit.getDefaultToolkit().getSystemClipboard();

    JLabel l = new JLabel("");

    l.setIcon(new ImageIcon(i));

    l.setTransferHandler(new ImageSelection());

    if (clipboard == null) {
      System.out.print("\ncb is null");
    }

    TransferHandler handler = l.getTransferHandler();

    if (handler == null) {
      System.out.print("\thc is null");
    }

    handler.exportToClipboard(l, clipboard, TransferHandler.COPY);
  }
    @Override
    public boolean canImport(TransferSupport support) {
      if (support.isDrop() && !mDropEnabled) return false;

      if (support.getComponent() == mTextArea && mTextHandler.canImport(support)) return true;

      for (DataFlavor flavor : support.getDataFlavors()) {
        if (flavor.isFlavorJavaFileListType()) {
          return true;
        }
      }

      return false;
    }
  protected void processMousePressedEvent(MouseEvent e) {

    requestFocusInWindow();

    int ex = e.getX();
    int ey = e.getY();
    Image image = null;
    float w;
    Insets insets = getInsets();
    int x = insets.left;
    int n = SnapshotGallery.sharedInstance().size();
    for (int i = n - 1; i >= 0; i--) {
      image = SnapshotGallery.sharedInstance().getThumbnail(i);
      w = image.getWidth(this);
      if (ex > x && ex < x + w && ey > insets.top && ey < insets.top + IMAGE_HEIGHT) {
        SnapshotGallery.sharedInstance().setSelectedIndex(i);
        repaint();
        break;
      }
      if (getLayout() instanceof FlowLayout) {
        x += (int) w + ((FlowLayout) getLayout()).getHgap();
      } else {
        x += (int) w + IMAGE_GAP;
      }
    }

    if (draggable) {
      if (!ModelerUtilities.isRightClick(e) && e.getClickCount() < 2) {
        JComponent c = (JComponent) e.getSource();
        TransferHandler handler = c.getTransferHandler();
        handler.exportAsDrag(c, e, TransferHandler.COPY);
      }
    } else {
      if (!ModelerUtilities.isRightClick(e) && e.getClickCount() >= 2)
        SnapshotGallery.sharedInstance().invokeSnapshotEditor(this, true, true);
    }
  }
 @Override
 public void exportToClipboard(JComponent comp, Clipboard clip, int action) {
   // default implementation is OK
   super.exportToClipboard(comp, clip, action);
 }
 @Override
 protected void exportDone(JComponent source, Transferable data, int action) {
   // default implementation is OK
   super.exportDone(source, data, action);
 }
 @Override
 public boolean importData(TransferSupport support) {
   TransferHandler handler = pickTransferHandler(support);
   if (handler != null) return handler.importData(support);
   return false;
 }
 @Override
 public boolean canImport(TransferSupport support) {
   for (TransferHandler handler : handlers) if (handler.canImport(support)) return true;
   return false;
 }
 @Override
 protected void exportDone(JComponent source, Transferable data, int action) {
   // TODO Auto-generated method stub
   super.exportDone(source, data, action);
 }
Beispiel #19
0
 @Override
 public void exportToClipboard(JComponent comp, Clipboard clip, int action) {
   super.exportToClipboard(comp, clip, action);
 }
 protected void exportDone(JComponent source, Transferable data, int action) {
   super.exportDone(source, data, action);
   inDrag = false;
 }
 @Override
 public void exportToClipboard(JComponent comp, Clipboard clip, int action)
     throws IllegalStateException {
   mTextHandler.exportToClipboard(comp, clip, action);
 }
  @Override
  public void exportAsDrag(JComponent comp, InputEvent e, int action) {

    super.exportAsDrag(comp, e, action);
  }
 @Override
 public void exportToClipboard(JComponent comp, Clipboard clip, int action)
     throws IllegalStateException {
   // TODO Auto-generated method stub
   super.exportToClipboard(comp, clip, action);
 }
Beispiel #24
0
  /** To support drag-drop of strings, and cut-copy-paste actions in the code window text editor. */
  protected void setShortcutKeystrokes() {
    final int SHORTCUT_KEY_MASK = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();

    InputMap imap = textarea.getInputMap();
    imap.put(
        KeyStroke.getKeyStroke('X', SHORTCUT_KEY_MASK),
        TransferHandler.getCutAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('C', SHORTCUT_KEY_MASK),
        TransferHandler.getCopyAction().getValue(Action.NAME));
    imap.put(
        KeyStroke.getKeyStroke('V', SHORTCUT_KEY_MASK),
        TransferHandler.getPasteAction().getValue(Action.NAME));
    imap.put(KeyStroke.getKeyStroke('A', SHORTCUT_KEY_MASK), "selectAll");
    imap.put(KeyStroke.getKeyStroke('/', SHORTCUT_KEY_MASK), "commentUncomment");
    imap.put(KeyStroke.getKeyStroke(']', SHORTCUT_KEY_MASK), "increaseIndent");
    imap.put(KeyStroke.getKeyStroke('[', SHORTCUT_KEY_MASK), "decreaseIndent");

    ActionMap amap = textarea.getActionMap();
    amap.put(
        TransferHandler.getCutAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> cut "+e.getSource());
            ((JEditTextArea) e.getSource()).cut();
          }
        });
    amap.put(
        TransferHandler.getCopyAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> copy "+e.getSource());
            ((JEditTextArea) e.getSource()).copy();
          }
        });
    amap.put(
        TransferHandler.getPasteAction().getValue(Action.NAME),
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> paste "+e.getSource());
            ((JEditTextArea) e.getSource()).paste();
          }
        });
    amap.put(
        "selectAll",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> select all "+e.getSource());
            ((JEditTextArea) e.getSource()).selectAll();
          }
        });
    amap.put(
        "commentUncomment",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> comment
            // uncomment"+e.getSource());
            handleCommentUncomment();
          }
        });
    amap.put(
        "increaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> increaseIndent"+e.getSource());
            handleIndentOutdent(true);
          }
        });
    amap.put(
        "decreaseIndent",
        new AbstractAction() {
          public void actionPerformed(ActionEvent e) {
            //        System.out.println("kCodeWindow ActionMap >> decreaseIndent"+e.getSource());
            handleIndentOutdent(false);
          }
        });
  }
 // Invoked after data has been exported.
 public void exportDone(JComponent source, Transferable data, int action) {
   super.exportDone(source, data, action);
 }
 public void exportToClipboard(JComponent comp, Clipboard clip, int action)
     throws IllegalStateException {
   super.exportToClipboard(comp, clip, action);
 }
Beispiel #27
0
 /** paste from clip board with the common shift */
 public void pasteFromClipboard() {
   Clipboard clip = Toolkit.getDefaultToolkit().getSystemClipboard();
   TransferHandler handler = getTransferHandler();
   handler.importData(this, clip.getContents(this));
 }
Beispiel #28
0
  public SchemaEditorToolBar(final BasicGraphEditor editor, int orientation) {
    super(orientation);
    setBorder(
        BorderFactory.createCompoundBorder(
            BorderFactory.createEmptyBorder(3, 3, 3, 3), getBorder()));
    setFloatable(false);

    add(
        editor.bind(
            "New", new EditorActions.NewAction(), "/com/gkd/jgraphx_example/images/new.gif"));
    add(
        editor.bind(
            "Open", new EditorActions.OpenAction(), "/com/gkd/jgraphx_example/images/open.gif"));
    add(
        editor.bind(
            "Save",
            new EditorActions.SaveAction(false),
            "/com/gkd/jgraphx_example/images/save.gif"));

    addSeparator();

    add(
        editor.bind(
            "Print", new EditorActions.PrintAction(), "/com/gkd/jgraphx_example/images/print.gif"));

    addSeparator();

    add(
        editor.bind(
            "Cut", TransferHandler.getCutAction(), "/com/gkd/jgraphx_example/images/cut.gif"));
    add(
        editor.bind(
            "Copy", TransferHandler.getCopyAction(), "/com/gkd/jgraphx_example/images/copy.gif"));
    add(
        editor.bind(
            "Paste",
            TransferHandler.getPasteAction(),
            "/com/gkd/jgraphx_example/images/paste.gif"));

    addSeparator();

    add(
        editor.bind(
            "Delete",
            mxGraphActions.getDeleteAction(),
            "/com/gkd/jgraphx_example/images/delete.gif"));

    addSeparator();

    add(
        editor.bind(
            "Undo",
            new EditorActions.HistoryAction(true),
            "/com/gkd/jgraphx_example/images/undo.gif"));
    add(
        editor.bind(
            "Redo",
            new EditorActions.HistoryAction(false),
            "/com/gkd/jgraphx_example/images/redo.gif"));

    addSeparator();

    final mxGraphView view = editor.getGraphComponent().getGraph().getView();
    final JComboBox zoomCombo =
        new JComboBox(
            new Object[] {
              "400%",
              "200%",
              "150%",
              "100%",
              "75%",
              "50%",
              mxResources.get("page"),
              mxResources.get("width"),
              mxResources.get("actualSize")
            });
    zoomCombo.setEditable(true);
    zoomCombo.setMinimumSize(new Dimension(75, 0));
    zoomCombo.setPreferredSize(new Dimension(75, 0));
    zoomCombo.setMaximumSize(new Dimension(75, 100));
    zoomCombo.setMaximumRowCount(9);
    add(zoomCombo);

    // Sets the zoom in the zoom combo the current value
    mxIEventListener scaleTracker =
        new mxIEventListener() {
          /** */
          public void invoke(Object sender, mxEventObject evt) {
            ignoreZoomChange = true;

            try {
              zoomCombo.setSelectedItem((int) Math.round(100 * view.getScale()) + "%");
            } finally {
              ignoreZoomChange = false;
            }
          }
        };

    // Installs the scale tracker to update the value in the combo box
    // if the zoom is changed from outside the combo box
    view.getGraph().getView().addListener(mxEvent.SCALE, scaleTracker);
    view.getGraph().getView().addListener(mxEvent.SCALE_AND_TRANSLATE, scaleTracker);

    // Invokes once to sync with the actual zoom value
    scaleTracker.invoke(null, null);

    zoomCombo.addActionListener(
        new ActionListener() {
          /** */
          public void actionPerformed(ActionEvent e) {
            mxGraphComponent graphComponent = editor.getGraphComponent();

            // Zoomcombo is changed when the scale is changed in the diagram
            // but the change is ignored here
            if (!ignoreZoomChange) {
              String zoom = zoomCombo.getSelectedItem().toString();

              if (zoom.equals(mxResources.get("page"))) {
                graphComponent.setPageVisible(true);
                graphComponent.setZoomPolicy(mxGraphComponent.ZOOM_POLICY_PAGE);
              } else if (zoom.equals(mxResources.get("width"))) {
                graphComponent.setPageVisible(true);
                graphComponent.setZoomPolicy(mxGraphComponent.ZOOM_POLICY_WIDTH);
              } else if (zoom.equals(mxResources.get("actualSize"))) {
                graphComponent.zoomActual();
              } else {
                try {
                  zoom = zoom.replace("%", "");
                  double scale = Math.min(16, Math.max(0.01, Double.parseDouble(zoom) / 100));
                  graphComponent.zoomTo(scale, graphComponent.isCenterZoom());
                } catch (Exception ex) {
                  JOptionPane.showMessageDialog(editor, ex.getMessage());
                }
              }
            }
          }
        });
  }
 // Causes the Swing drag support to be initiated.
 public void exportAsDrag(JComponent comp, java.awt.event.InputEvent e, int action) {
   super.exportAsDrag(comp, e, action);
 }