use of java.awt.dnd.DropTargetDragEvent in project intellij-community by JetBrains.
the class EditorImpl method initComponent.
private void initComponent() {
myPanel.setLayout(new BorderLayout());
myPanel.add(myHeaderPanel, BorderLayout.NORTH);
myGutterComponent.setOpaque(true);
myScrollPane.setViewportView(myEditorComponent);
//myScrollPane.setBorder(null);
myScrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
myScrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
myScrollPane.setRowHeaderView(myGutterComponent);
myEditorComponent.setTransferHandler(new MyTransferHandler());
myEditorComponent.setAutoscrolls(true);
if (mayShowToolbar()) {
JLayeredPane layeredPane = new JBLayeredPane() {
@Override
public void doLayout() {
final Component[] components = getComponents();
final Rectangle r = getBounds();
for (Component c : components) {
if (c instanceof JScrollPane) {
c.setBounds(0, 0, r.width, r.height);
} else {
final Dimension d = c.getPreferredSize();
int rightInsets = getVerticalScrollBar().getWidth() + (isMirrored() ? myGutterComponent.getWidth() : 0);
c.setBounds(r.width - d.width - rightInsets - 20, 20, d.width, d.height);
}
}
}
@Override
public Dimension getPreferredSize() {
return myScrollPane.getPreferredSize();
}
};
layeredPane.add(myScrollPane, JLayeredPane.DEFAULT_LAYER);
myPanel.add(layeredPane);
new ContextMenuImpl(layeredPane, myScrollPane, this);
} else {
myPanel.add(myScrollPane);
}
myEditorComponent.addKeyListener(new KeyListener() {
@Override
public void keyPressed(@NotNull KeyEvent e) {
if (e.getKeyCode() >= KeyEvent.VK_A && e.getKeyCode() <= KeyEvent.VK_Z) {
myCharKeyPressed = true;
}
KeyboardInternationalizationNotificationManager.showNotification();
}
@Override
public void keyTyped(@NotNull KeyEvent event) {
myNeedToSelectPreviousChar = false;
if (event.isConsumed()) {
return;
}
if (processKeyTyped(event)) {
event.consume();
}
}
@Override
public void keyReleased(KeyEvent e) {
myCharKeyPressed = false;
}
});
myEditorComponent.addMouseListener(myMouseListener);
myGutterComponent.addMouseListener(myMouseListener);
myEditorComponent.addMouseMotionListener(myMouseMotionListener);
myGutterComponent.addMouseMotionListener(myMouseMotionListener);
myEditorComponent.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(@NotNull FocusEvent e) {
myCaretCursor.activate();
for (Caret caret : myCaretModel.getAllCarets()) {
int caretLine = caret.getLogicalPosition().line;
repaintLines(caretLine, caretLine);
}
fireFocusGained();
}
@Override
public void focusLost(@NotNull FocusEvent e) {
clearCaretThread();
for (Caret caret : myCaretModel.getAllCarets()) {
int caretLine = caret.getLogicalPosition().line;
repaintLines(caretLine, caretLine);
}
fireFocusLost();
}
});
UiNotifyConnector connector = new UiNotifyConnector(myEditorComponent, new Activatable.Adapter() {
@Override
public void showNotify() {
myGutterComponent.updateSizeOnShowNotify();
}
});
Disposer.register(getDisposable(), connector);
try {
final DropTarget dropTarget = myEditorComponent.getDropTarget();
if (dropTarget != null) {
// might be null in headless environment
dropTarget.addDropTargetListener(new DropTargetAdapter() {
@Override
public void drop(@NotNull DropTargetDropEvent e) {
}
@Override
public void dragOver(@NotNull DropTargetDragEvent e) {
Point location = e.getLocation();
getCaretModel().moveToVisualPosition(getTargetPosition(location.x, location.y, true));
getScrollingModel().scrollToCaret(ScrollType.RELATIVE);
requestFocus();
}
});
}
} catch (TooManyListenersException e) {
LOG.error(e);
}
// update area available for soft wrapping on component shown/hidden
myPanel.addHierarchyListener(e -> mySoftWrapModel.getApplianceManager().updateAvailableArea());
myPanel.addComponentListener(new ComponentAdapter() {
@Override
public void componentResized(@NotNull ComponentEvent e) {
myMarkupModel.recalcEditorDimensions();
myMarkupModel.repaint(-1, -1);
}
});
}
use of java.awt.dnd.DropTargetDragEvent in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method processEnterMessage.
/**
* actual processing on EventQueue Thread
*/
protected void processEnterMessage(SunDropTargetEvent event) {
Component c = (Component) event.getSource();
DropTarget dt = c.getDropTarget();
Point hots = event.getPoint();
local = getJVMLocalSourceTransferable();
if (currentDTC != null) {
// some wreckage from last time
currentDTC.removeNotify();
currentDTC = null;
}
if (c.isShowing() && dt != null && dt.isActive()) {
currentDT = dt;
currentDTC = currentDT.getDropTargetContext();
currentDTC.addNotify(this);
currentA = dt.getDefaultActions();
try {
((DropTargetListener) dt).dragEnter(new DropTargetDragEvent(currentDTC, hots, currentDA, currentSA));
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDT = null;
currentDTC = null;
currentDA = DnDConstants.ACTION_NONE;
currentSA = DnDConstants.ACTION_NONE;
currentA = DnDConstants.ACTION_NONE;
}
}
use of java.awt.dnd.DropTargetDragEvent in project jdk8u_jdk by JetBrains.
the class SunDropTargetContextPeer method processMotionMessage.
/**
*
*/
protected void processMotionMessage(SunDropTargetEvent event, boolean operationChanged) {
Component c = (Component) event.getSource();
Point hots = event.getPoint();
int id = event.getID();
DropTarget dt = c.getDropTarget();
DropTargetContext dtc = null;
if (c.isShowing() && (dt != null) && dt.isActive()) {
if (currentDT != dt) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDT = dt;
currentDTC = null;
}
dtc = currentDT.getDropTargetContext();
if (dtc != currentDTC) {
if (currentDTC != null) {
currentDTC.removeNotify();
}
currentDTC = dtc;
currentDTC.addNotify(this);
}
currentA = currentDT.getDefaultActions();
try {
DropTargetDragEvent dtde = new DropTargetDragEvent(dtc, hots, currentDA, currentSA);
DropTargetListener dtl = (DropTargetListener) dt;
if (operationChanged) {
dtl.dropActionChanged(dtde);
} else {
dtl.dragOver(dtde);
}
if (dragRejected) {
currentDA = DnDConstants.ACTION_NONE;
}
} catch (Exception e) {
e.printStackTrace();
currentDA = DnDConstants.ACTION_NONE;
}
} else {
currentDA = DnDConstants.ACTION_NONE;
}
}
use of java.awt.dnd.DropTargetDragEvent in project jna by java-native-access.
the class DropHandler method getDropAction.
/** Calculate the effective action. The default implementation
* checks whether any {@link DataFlavor}s are supported, and if so,
* will change the current action from {@link DnDConstants#ACTION_NONE} to
* something in common between the source and destination. Refuse
* user-requested actions if they are not supported (rather than silently
* accepting a non-user-requested action, which is the Java's DnD default
* behavior). The drop action is forced to {@link DnDConstants#ACTION_NONE}
* if there is no supported data flavor.
* @param e {@link DropTargetEvent}
* @return effective drop action
* @see #isSupported(DataFlavor[])
* @see #getDropActionsForFlavors
* @see #getDropAction(DropTargetEvent, int, int, int)
* @see #canDrop(DropTargetEvent, int, Point)
*/
protected int getDropAction(DropTargetEvent e) {
int currentAction = DragHandler.NONE;
int sourceActions = DragHandler.NONE;
Point location = null;
DataFlavor[] flavors = new DataFlavor[0];
if (e instanceof DropTargetDragEvent) {
DropTargetDragEvent ev = (DropTargetDragEvent) e;
currentAction = ev.getDropAction();
sourceActions = ev.getSourceActions();
flavors = ev.getCurrentDataFlavors();
location = ev.getLocation();
} else if (e instanceof DropTargetDropEvent) {
DropTargetDropEvent ev = (DropTargetDropEvent) e;
currentAction = ev.getDropAction();
sourceActions = ev.getSourceActions();
flavors = ev.getCurrentDataFlavors();
location = ev.getLocation();
}
if (isSupported(flavors)) {
int availableActions = getDropActionsForFlavors(flavors);
currentAction = getDropAction(e, currentAction, sourceActions, availableActions);
if (currentAction != DragHandler.NONE) {
if (canDrop(e, currentAction, location)) {
return currentAction;
}
}
}
return DragHandler.NONE;
}
use of java.awt.dnd.DropTargetDragEvent in project android by JetBrains.
the class DropTargetDragEventBuilder method build.
public DropTargetDragEvent build() {
DropTargetDragEvent event = mock(DropTargetDragEvent.class);
when(event.getSource()).thenReturn(mySource);
when(event.getLocation()).thenReturn(new Point(myX, myY));
when(event.getDropTargetContext()).thenReturn(myDropTargetContext);
when(event.getDropAction()).thenReturn(myDropAction);
when(event.getSourceActions()).thenReturn(mySourceActions);
when(event.getTransferable()).thenReturn(myTransferable);
DataFlavor[] flavors = myTransferable.getTransferDataFlavors();
when(event.getCurrentDataFlavors()).thenReturn(flavors);
when(event.getCurrentDataFlavorsAsList()).thenReturn(Arrays.asList(flavors));
return event;
}
Aggregations