2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package com
.intellij
.uiDesigner
.designSurface
;
19 import java
.awt
.event
.KeyEvent
;
20 import java
.awt
.event
.MouseEvent
;
23 * @author Anton Katilin
24 * @author Vladimir Kondratyev
26 public abstract class EventProcessor
{
27 private Cursor myCursor
;
29 public final Cursor
getCursor(){
33 public final void setCursor(final Cursor cursor
){
37 protected abstract void processKeyEvent(KeyEvent e
);
39 protected abstract void processMouseEvent(MouseEvent e
);
42 * @return true if processor cancelled its operation; false otherwise
44 protected abstract boolean cancelOperation();
46 public boolean isDragActive() {
50 public boolean needMousePressed() {
54 protected static ComponentDropLocation
.Direction
directionFromKey(final int keyCode
) {
56 case KeyEvent
.VK_RIGHT
: return ComponentDropLocation
.Direction
.RIGHT
;
57 case KeyEvent
.VK_LEFT
: return ComponentDropLocation
.Direction
.LEFT
;
58 case KeyEvent
.VK_UP
: return ComponentDropLocation
.Direction
.UP
;
59 case KeyEvent
.VK_DOWN
: return ComponentDropLocation
.Direction
.DOWN
;
60 case KeyEvent
.VK_END
: return ComponentDropLocation
.Direction
.RIGHT
;
61 case KeyEvent
.VK_HOME
: return ComponentDropLocation
.Direction
.LEFT
;
62 case KeyEvent
.VK_PAGE_UP
: return ComponentDropLocation
.Direction
.UP
;
63 case KeyEvent
.VK_PAGE_DOWN
: return ComponentDropLocation
.Direction
.DOWN
;
68 private static boolean isMoveToLast(final int keyCode
) {
69 return keyCode
== KeyEvent
.VK_HOME
|| keyCode
== KeyEvent
.VK_END
||
70 keyCode
== KeyEvent
.VK_PAGE_UP
|| keyCode
== KeyEvent
.VK_PAGE_DOWN
;
73 protected static ComponentDropLocation
moveDropLocation(final GuiEditor editor
, final ComponentDropLocation location
,
74 final ComponentDragObject dragObject
, final KeyEvent e
) {
75 ComponentDropLocation
.Direction dir
= directionFromKey(e
.getKeyCode());
76 boolean moveToLast
= isMoveToLast(e
.getKeyCode());
77 if (dir
!= null && location
!= null) {
79 ComponentDropLocation adjacentLocation
;
81 adjacentLocation
= location
.getAdjacentLocation(dir
);
82 ComponentDropLocation lastLocation
= location
;
83 while(adjacentLocation
!= null) {
84 if (adjacentLocation
.canDrop(dragObject
)) {
85 lastLocation
= adjacentLocation
;
87 adjacentLocation
= adjacentLocation
.getAdjacentLocation(dir
);
89 adjacentLocation
= lastLocation
;
92 adjacentLocation
= location
.getAdjacentLocation(dir
);
93 while(adjacentLocation
!= null && !adjacentLocation
.canDrop(dragObject
)) {
94 adjacentLocation
= adjacentLocation
.getAdjacentLocation(dir
);
98 if (adjacentLocation
!= null && adjacentLocation
.canDrop(dragObject
)) {
99 adjacentLocation
.placeFeedback(editor
.getActiveDecorationLayer(), dragObject
);
100 return adjacentLocation
;