Skip to content

Commit 61783e0

Browse files
author
soheil_h_y
committed
1. TableColumn Resizing
1 parent 646500e commit 61783e0

1 file changed

Lines changed: 94 additions & 0 deletions

File tree

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*******************************************************************************
2+
* Java2Script Pacemaker (http://j2s.sourceforge.net)
3+
*
4+
* Copyright (c) 2006 ognize.com and others.
5+
* All rights reserved. This program and the accompanying materials
6+
* are made available under the terms of the Eclipse Public License v1.0
7+
* which accompanies this distribution, and is available at
8+
* http://www.eclipse.org/legal/epl-v10.html
9+
*
10+
* Contributors:
11+
* ognize.com - initial API and implementation
12+
*******************************************************************************/
13+
14+
package org.eclipse.swt.internal.dnd;
15+
16+
import org.eclipse.swt.graphics.Point;
17+
import org.eclipse.swt.internal.xhtml.Element;
18+
import org.eclipse.swt.internal.xhtml.document;
19+
20+
21+
/**
22+
* @author Soheil Hassas Yeganeh
23+
*
24+
* 2006-7-1
25+
*/
26+
public class TableColumnDND extends DragAdapter {
27+
protected int sourceX = 0;
28+
protected Element thumb;
29+
public boolean dragBegan(DragEvent e) {
30+
thumb = document.createElement ("DIV");
31+
String cssName = e.sourceElement.className;
32+
thumb.className = cssName;
33+
if (cssName != null && cssName.indexOf ("sash-mouse-down") == -1) {
34+
thumb.className += " sash-mouse-down";
35+
}
36+
thumb.style.left = e.sourceElement.style.left;
37+
thumb.style.top = e.sourceElement.style.top;
38+
thumb.style.width = e.sourceElement.style.width;
39+
thumb.style.height = e.sourceElement.style.height;
40+
thumb.onselectstart = DNDUtils.onselectstart;
41+
if (e.sourceElement.nextSibling != null) {
42+
e.sourceElement.parentNode.insertBefore (thumb,
43+
e.sourceElement.nextSibling);
44+
} else {
45+
e.sourceElement.parentNode.appendChild (thumb);
46+
}
47+
48+
this.sourceX = Integer.parseInt (e.sourceElement.style.left);
49+
/* first time, set start location to current location */
50+
e.startX = e.currentX;
51+
return true;
52+
}
53+
public boolean dragCanceled(DragEvent e) {
54+
clean();
55+
return true;
56+
}
57+
58+
public boolean dragEnded(DragEvent e) {
59+
clean();
60+
return true;
61+
}
62+
63+
protected void clean() {
64+
thumb.style.display = "none";
65+
document.body.style.cursor = "auto";
66+
thumb.parentNode.removeChild(thumb);
67+
}
68+
69+
protected Point currentLocation(DragEvent e) {
70+
int xx = this.sourceX + e.deltaX ();
71+
72+
int gWidth = Integer.parseInt(e.sourceElement.parentNode.style.width);
73+
/*
74+
* On mozilla, the mousemove event can contain mousemove
75+
* outside the browser window, so make bound for the dragging.
76+
*/
77+
int dWidth = Integer.parseInt(e.sourceElement.style.width);
78+
if (xx < 0) {
79+
xx = 0;
80+
} else if (xx > gWidth - dWidth - 2) {
81+
xx = gWidth - dWidth - 2;
82+
}
83+
return new Point(xx, 0);
84+
}
85+
86+
public boolean dragging(DragEvent e) {
87+
document.body.style.cursor = "e-resize";
88+
thumb.style.cursor = "e-resize";
89+
thumb.style.left = currentLocation(e).x + "px";
90+
return true;
91+
}
92+
93+
94+
}

0 commit comments

Comments
 (0)