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.
17 package com
.intellij
.ui
;
19 import com
.intellij
.ui
.awt
.RelativePoint
;
20 import com
.intellij
.ui
.popup
.AbstractPopup
;
23 import java
.awt
.event
.MouseAdapter
;
24 import java
.awt
.event
.MouseEvent
;
25 import java
.awt
.event
.MouseMotionListener
;
31 public class MoveComponentListener
extends MouseAdapter
implements MouseMotionListener
{
32 private final CaptionPanel myComponent
;
33 private Point myStartPoint
= null;
35 public MoveComponentListener(final CaptionPanel component
) {
36 myComponent
= component
;
39 private void endOperation() {
40 AbstractPopup
.setDefaultCursor(myComponent
);
44 public void mousePressed(MouseEvent e
) {
45 myStartPoint
= new RelativePoint(e
).getScreenPoint();
46 final Point titleOffset
= RelativePoint
.getNorthWestOf(myComponent
).getScreenPoint();
47 myStartPoint
.x
-= titleOffset
.x
;
48 myStartPoint
.y
-= titleOffset
.y
;
51 public void mouseClicked(MouseEvent e
) {
55 public void mouseReleased(MouseEvent e
) {
59 public void mouseMoved(MouseEvent e
) {
60 if (e
.isConsumed()) return;
61 AbstractPopup
.setDefaultCursor(myComponent
);
64 public void mouseDragged(MouseEvent e
) {
65 if (e
.isConsumed()) return;
66 AbstractPopup
.setDefaultCursor(myComponent
);
67 if (myStartPoint
!= null) {
68 final Point draggedTo
= new RelativePoint(e
).getScreenPoint();
69 draggedTo
.x
-= myStartPoint
.x
;
70 draggedTo
.y
-= myStartPoint
.y
;
72 AbstractPopup
.moveTo(myComponent
, draggedTo
, null);