| 1 |
/* |
| 2 |
* Licensed to the Apache Software Foundation (ASF) under one |
| 3 |
* or more contributor license agreements. See the NOTICE file |
| 4 |
* distributed with this work for additional information |
| 5 |
* regarding copyright ownership. The ASF licenses this file |
| 6 |
* to you under the Apache License, Version 2.0 (the |
| 7 |
* "License"); you may not use this file except in compliance |
| 8 |
* with the License. You may obtain a copy of the License at |
| 9 |
* |
| 10 |
* http://www.apache.org/licenses/LICENSE-2.0 |
| 11 |
* |
| 12 |
* Unless required by applicable law or agreed to in writing, |
| 13 |
* software distributed under the License is distributed on an |
| 14 |
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 |
* KIND, either express or implied. See the License for the |
| 16 |
* specific language governing permissions and limitations |
| 17 |
* under the License. |
| 18 |
*/ |
| 19 |
|
| 20 |
var htrace = htrace || {}; |
| 21 |
|
| 22 |
// Widget containing draggable horizontal partition |
| 23 |
htrace.PartitionWidget = function(params) { |
| 24 |
this.draw = function() { |
| 25 |
this.ctx.save(); |
| 26 |
this.ctx.fillStyle = this.selected ? "#6600ff" : "#aaaaaa"; |
| 27 |
this.ctx.fillRect(this.x0, this.y0, this.xF - this.x0, this.yF - this.y0); |
| 28 |
this.ctx.restore(); |
| 29 |
}; |
| 30 |
|
| 31 |
this.handle = function(e) { |
| 32 |
switch (e.type) { |
| 33 |
case "mouseDown": |
| 34 |
if (!htrace.inBoundingBox(e.x, e.y, |
| 35 |
this.x0, this.xF, this.y0, this.yF)) { |
| 36 |
return true; |
| 37 |
} |
| 38 |
this.manager.registerHighPriority("mouseUp", this); |
| 39 |
this.manager.registerHighPriority("mouseMove", this); |
| 40 |
this.selected = true; |
| 41 |
$(this.el).css('cursor', 'ew-resize'); |
| 42 |
return false; |
| 43 |
case "mouseMove": |
| 44 |
// Move the partition to the mouse pointer area |
| 45 |
var x = Math.min(Math.max(e.x, this.xMin), this.xMax); |
| 46 |
var width = this.xF - this.x0; |
| 47 |
this.x0 = Math.floor(x - (width / 2)); |
| 48 |
this.xF = this.x0 + width; |
| 49 |
return false; |
| 50 |
case "mouseUp": |
| 51 |
this.manager.unregister("mouseUp", this); |
| 52 |
this.manager.unregister("mouseMove", this); |
| 53 |
$(this.el).css('cursor', 'pointer'); |
| 54 |
this.selected = false; |
| 55 |
this.releaseHandler(this.x0); |
| 56 |
return false; |
| 57 |
case "draw": |
| 58 |
this.draw(); |
| 59 |
return true; |
| 60 |
default: |
| 61 |
return true; |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
for (var k in params) { |
| 66 |
this[k]=params[k]; |
| 67 |
} |
| 68 |
this.selected = false; |
| 69 |
this.manager.register("mouseDown", this); |
| 70 |
this.manager.register("draw", this); |
| 71 |
return this; |
| 72 |
}; |