javax.swing.JComponent.getTransferHandler()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(114)

本文整理了Java中javax.swing.JComponent.getTransferHandler()方法的一些代码示例,展示了JComponent.getTransferHandler()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JComponent.getTransferHandler()方法的具体详情如下:
包路径:javax.swing.JComponent
类名称:JComponent
方法名:getTransferHandler

JComponent.getTransferHandler介绍

暂无

代码示例

代码示例来源:origin: stanfordnlp/CoreNLP

@Override
public void mouseDragged(MouseEvent e) {
 if (MatchesPanel.getInstance().isEmpty()) return;
 if (firstMouseEvent1 != null) {
  e.consume();
  int dx = Math.abs(e.getX() - firstMouseEvent1.getX());
  int dy = Math.abs(e.getY() - firstMouseEvent1.getY());
  //Arbitrarily define a 5-pixel shift as the
  //official beginning of a drag.
  if (dx > 5 || dy > 5) {
   //This is a drag, not a click.
   JComponent c = (JComponent)e.getSource();
   //Tell the transfer handler to initiate the drag.
   TransferHandler handler = c.getTransferHandler();
   handler.exportAsDrag(c, firstMouseEvent1, TransferHandler.COPY);
   firstMouseEvent1 = null;
  }
 }
}

代码示例来源:origin: stackoverflow.com

if(c!=null && c instanceof JLabel) {
 p.draggingLabel = (JLabel)c;
 p.getTransferHandler().exportAsDrag(p, e, TransferHandler.MOVE);

代码示例来源:origin: stackoverflow.com

JButton b = new JButton("Button");

String propertyName = "MyButton";
label.setTransferHandler(new TransferHandler(propertyName));

label.addMouseListener(new MouseAdapter() {
  public void mousePressed(MouseEvent e) {
    JComponent c = (JComponent)evt.getSource();
    TransferHandler handler = c.getTransferHandler();
    th.exportAsDrag(c, e, TransferHandler.COPY);
  }
});

代码示例来源:origin: stackoverflow.com

public static void applyTo(JComponent component) {
   if (component.getTransferHandler() == null) {
     throw new IllegalStateException("A TransferHandler must be set before calling this method!");
   }
   try {
     component.getDropTarget().addDropTargetListener(new AutoscrollWorkaround(component));
   } catch (TooManyListenersException e) {
     throw new IllegalStateException("Something went wrong! DropTarget should have been " +
         "SwingDropTarget which accepts multiple listeners", e);
   }
 }

代码示例来源:origin: stackoverflow.com

jLabel1.addMouseListener(new MouseAdapter() {
 public void mousePressed(MouseEvent evt) {
  JComponent comp = (JComponent) evt.getSource();
  TransferHandler th = comp.getTransferHandler();

  th.exportAsDrag(comp, evt, TransferHandler.COPY);
 }
});

代码示例来源:origin: org.fudaa.framework.ctulu/ctulu-bu

private boolean check(Component _c,DataFlavor[] _f)
{
 boolean r=false;
 if(_c instanceof JComponent)
 {
  JComponent      c=(JComponent)_c;
  TransferHandler h=c.getTransferHandler();
  if((h!=null)&&h.canImport(c,_f))
   r=true;
 }
 return r;
}

代码示例来源:origin: de.sciss/scisslib

public void mouseDragged( MouseEvent e )
  {
    if( !dndStarted && (dndInit != null) &&
      ((Math.abs( e.getX() - dndInit.getX() ) > 5) ||
       (Math.abs( e.getY() - dndInit.getY() ) > 5))) {
      JComponent c = (JComponent) e.getSource();
      c.getTransferHandler().exportAsDrag( c, e, TransferHandler.COPY );
      dndStarted = true;
    }
  }
};

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

private TransferHandler getTransferHandler(MouseEvent e)
{
  JComponent c= getComponent(e);
  return c == null ? null : c.getTransferHandler();
}

代码示例来源:origin: IanDarwin/javasrc

public void mousePressed(MouseEvent e) {
    JComponent c = (JComponent)e.getSource();
    TransferHandler handler = c.getTransferHandler();
    handler.exportAsDrag(c, e, TransferHandler.COPY);
  }
};

代码示例来源:origin: stackoverflow.com

table.addMouseMotionListener(new MouseMotionListener() {
  public void mouseDragged(MouseEvent e) {
    e.consume();
    JComponent c = (JComponent) e.getSource();
    TransferHandler handler = c.getTransferHandler();
    handler.exportAsDrag(c, e, TransferHandler.MOVE);
  }

  public void mouseMoved(MouseEvent e) {
  }
});

代码示例来源:origin: igvteam/igv

@Override()
  public void mouseDragged(MouseEvent e) {
    if (isDragging) {
      return;
    }
    isDragging = true;
    JComponent c = HeaderPanel.this;
    TransferHandler handler = c.getTransferHandler();
    if (handler != null) {
      handler.exportAsDrag(c, e, TransferHandler.MOVE);
    }
  }
};

代码示例来源:origin: org.tinyjee.jgraphx/jgraphx

/**
 * Helper method to return the component for a drop target event.
 */
protected static final mxGraphTransferHandler getGraphTransferHandler(
    DropTargetEvent e)
{
  JComponent component = getDropTarget(e);
  TransferHandler transferHandler = component.getTransferHandler();
  if (transferHandler instanceof mxGraphTransferHandler)
  {
    return (mxGraphTransferHandler) transferHandler;
  }
  return null;
}

代码示例来源:origin: com.eas.platypus/platypus-js-scalable-widget

protected TransferHandler getScalableTransferHandler()
{
  if(scalable != null && scalable.getInnerDropTargetComponent() != null)
  {
    Component lc = scalable.getInnerDropTargetComponent();
    if(lc instanceof JComponent)
    {
      JComponent jlc = (JComponent)lc;
      return jlc.getTransferHandler();
    }
  }
  return null;
}

代码示例来源:origin: com.synaptix/SynaptixSwing

/**
 * Returns whether or not the event is potentially part of a drag sequence.
 */
private boolean mousePressedImpl(MouseEvent me) {
  component = (JComponent) me.getSource();
  if (mapDragOperationFromModifiers(me, component.getTransferHandler()) != TransferHandler.NONE) {
    motionThreshold = DragSource.getDragThreshold();
    dndArmedEvent = me;
    return true;
  }
  clearState();
  return false;
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-designer

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();

    if ((mods & InputEvent.BUTTON1_DOWN_MASK) != InputEvent.BUTTON1_DOWN_MASK) {
      return TransferHandler.NONE;
    }

    JComponent c = getComponent(e);
    TransferHandler th = c.getTransferHandler();
//        return SunDragSourceContextPeer.convertModifiersToDropAction(mods, th.getSourceActions(c));
    return convertModifiersToDropAction(mods, th.getSourceActions(c));
  }

代码示例来源:origin: org.opentcs.thirdparty.jhotdraw/jhotdraw

@Override
public void mouseDragged(MouseEvent e) {
  DrawingView v = getView();
  Figure f = v.findFigure(e.getPoint());
  if (f != null) {
    if (!v.getSelectedFigures().contains(f)) {
      v.clearSelection();
      v.addToSelection(f);
    }
    v.getComponent().getTransferHandler().exportAsDrag(v.getComponent(), e, DnDConstants.ACTION_MOVE);
  }
  fireToolDone();
}

代码示例来源:origin: net.sf.ingenias/ingeniasjgraphmod

public void dragEnter(DropTargetDragEvent e) {
  component = getComponent(e);
  javax.swing.TransferHandler th = ((JComponent) component).getTransferHandler();
  canImport = th.canImport(component, e.getCurrentDataFlavors());
  if (canImport) {
    saveComponentState(component);
    lastPosition = e.getLocation();
    updateAutoscrollRegion(component);
    initPropertiesIfNecessary();
  }
}

代码示例来源:origin: org.netbeans.modules/org-netbeans-modules-visualweb-extension-openide

public void dragEnter(DropTargetDragEvent e) {
component = getComponent(e);
TransferHandler th = component.getTransferHandler();
canImport = th.canImport(component, e.getCurrentDataFlavors());
if (canImport) {
  saveComponentState(component);
  lastPosition = e.getLocation();
  updateAutoscrollRegion(component);
    initPropertiesIfNecessary();
}
}

代码示例来源:origin: com.synaptix/SynaptixSwing

public void dragDropEnd(DragSourceDropEvent dsde) {
  DragSourceContext dsc = dsde.getDragSourceContext();
  JComponent c = (JComponent) dsc.getComponent();
  SynaptixTransferHandler th = (SynaptixTransferHandler) c
      .getTransferHandler();
  clearDropDDCs();
  if (dsde.getDropSuccess()) {
    th.exportDone(c, dsc.getTransferable(), dsde.getDropAction());
  } else {
    th.exportDone(c, dsc.getTransferable(), NONE);
  }
  c.setAutoscrolls(scrolls);
}

代码示例来源:origin: net.sf.squirrel-sql.thirdparty-non-maven/toniclf

public void dragEnter(DropTargetDragEvent e)
{
  component= getComponent(e);
  TransferHandler th= component.getTransferHandler();
  canImport= th.canImport(component, e.getCurrentDataFlavors());
  if (canImport)
  {
    saveComponentState(component);
    lastPosition= e.getLocation();
    updateAutoscrollRegion(component);
    initPropertiesIfNecessary();
  }
}

相关文章

JComponent类方法