I'm trying to get a draggable image in Dart. Though setting the draggable bool of my image doesn't work.
image = new ImageElement();
image.src = ImageSourceByName(name);
image.on.load.add((event) {Context.drawImage(image, 10, 10, CARD_SMALL_WIDTH, CARD_SMALL_HEIGHT);});
image.draggable = true;
(Note: Context is the 2D context I get from my Canvas.)
The drawing works perfectly, I can see my card, though I can't drag it around. I'm pretty new to Dart, so it might be something obvious, though I can't find any tutorial explaining it.
You're using an ImageElement as the source to paint something on your CanvasElement.
Once the pixels are on the canvas(through drawImage()), your image data is not an HTMLElement but, well, pixels :)
The draggable attr, however, is an attribute of an HTMLElement.
If you add the image to your document, you'll notice that you can study the behaviour of draggable, like this:
document.body.nodes.add(image);
If you 'only' want to have draggable images, you can take it from there and maybe look at http://www.whatwg.org/specs/web-apps/current-work/multipage/dnd.html
Otherwise, if you want stuff on a canvas to be draggable, thats a different(more complicated?) story.
Related
Does anyone know if you are able to set the colour of the text for a vertex label in JUNG.
I'm using the Visualisation Viewer and can seem to be able to set the colour for everything else.
vv = new VisualizationViewer<String,Integer>(treeLayout, new Dimension(410,557));
Transformer<String,Paint> vertexPaint = new Transformer<String,Paint>() {
public Paint transform(String b) {
return Color.orange;
}
};
vv.setBackground(Color.white);
vv.getRenderContext().setEdgeShapeTransformer(new EdgeShape.Line());
vv.getRenderContext().setVertexLabelTransformer(new ToStringLabeller());
vv.getRenderContext().setVertexFillPaintTransformer(vertexPaint);
//vv.getRenderContext().setVertexFontTransformer(vertexFont);
// add a listener for ToolTips
vv.setVertexToolTipTransformer(new ToStringLabeller());
vv.getRenderContext().setArrowFillPaintTransformer(new ConstantTransformer(Color.WHITE));
The DefaultVertexLabelRenderer and the DefaultEdgeLabelRenderer extend JLabel (it is similar to the way cell renderers work in JTable and JTree).
By default, it uses the foreground color of the VisualizationViewer to draw the label text.
vv.setForegroundColor(Color.red);
will make all of your labels red.
This approach is less expensive than making all of the labels parse HTML.
Sorry that the solution is so obscure.
Additionally, since the default renderers extend JLabel, the use of html is the same as it is for JLabel. There are good online resources to show examples of using html with javax.swing. What's missing is documentation to make the connection between using html in JUNG and using html in javax.swing.
You can use HTML in the label to specify the color; an example is here: https://stackoverflow.com/a/2017576/664856
In your case,
vv.getRenderContext().setVertexLabelRenderer(new DefaultVertexLabelRenderer(Color.RED));
should work (if you wanted selected vertex to be Red). I tested it myself. This applies to the selected vertex.
Upon inspection of code, I would have to believe that the link I provided does correctly work for those vertices which are not selected, but I did not actually try implementing that link.
I trying to create a fixed border to the site that dynamically change size with the browser window from this sprite (it isn't perfect I know.): http://fc07.deviantart.net/fs70/f/2011/269/7/0/bordersprite_by_nakos-d4ayzne.png
DEMO on jSFiddle
My problem as you can see is the vertical wall part. As the #falJ and #falB are height:100% they include the bottom wall's end too with the space between the two wall sprites. Is there a way to force backround-position to only use vertical wall part without bottom wall's end?
Thanks in advance.
Solution: http://jsfiddle.net/vonkly/Ld43B/
It's not the prettiest thing in the world, but it achieves what you want. Check out the source code & direct link for the background images to see what you'll need to do. It's currently set at 299px wide; I imagine you'll be using something wider.
I'd also suggest adding some padding around your content (either with a p tag, span, another div, etc.) - the way it is currently set up isn't what I'd recommend for readability.
EDIT
The only way I can imagine achieving a fluid width + height box with the borders that you have in the way that you want is to use a second image for the west and east containing divs. This should work with your current method.
I am new to jQuery I am facing a some problem with jQuery gradient image please give me some solution for this
I have one div divided vertically in three part left, middle,right.The div has a background images (that is gradient) .and there is some data in the div. I want that the image height should be increase when the user input more data in the div
Can we increase the height of the gradient image using jQuery. Please give me some reference site or some solution
I don't know that you need JQuery to do this for you; it will be fun to do it on you own.
As you know, you can style the div such that its height will increase as you add more content to it. So your question really is how to make the gradient background appear the way you want it: you might want the gradient to grow lighter and lighter at the bottom, say, as the div increases in height. It just so happens (lucky you!) that background-image CSS is rich and capable. That's why it's fun: it actually works!
Read about CSS background-position for some ideas. You might find that the effect you want is automatic.
-- pete
I've noticed that the CSS3 scale attribute does really bad things to jquery ui, specifically to sortable. The problem is that the mouse still needs to move as much as if the elements were not scaled. Check out this jsfiddle example.
Does anybody have thoughts on how to fix this? Is it possible to change the speed that the mouse moves? I'm going to look into the html5 native drag and drop next, and try to write my own sortable function.
UPDATE:
Jquery ui draggable works ok with CSS3 scaled elements, here is a fiddle for it.
It turns out the real answer does not require writing special move functions. Jquery ui sortable can be used as long as the items being sorted have been wrapped in a div of the appropriate size with overflow hidden. Check this jsfiddle for an example.
The problem was that I had forced the scaled divs to be close to one another using a negative margin. Then when I started to drag an item it was taking up the wrong amount of space. With the scaled item wrapped in a non-scaled div everything works as expected.
I don't have a solution for working with jquery ui but I do have a solution for working with Raphael and by extension other svg objects.
First, using chrome or firefox, go drag the dots around in this jsfiddle. Be sure to drag both dots and to use the slider at the bottom to change the scale of the box. The slider has a default scale range of .4 to 1.2. In Chrome the slider is actually a slider but in Firefox it shows up as a textbox. If you are using firefox enter values that are 100 x the scale, i.e. 70 => 0.7.
What you should have just experienced is that the black dot tracks with the mouse regardless of the scale and the red dot only tracks when the scale is 1.0.
The reason for this is the two dots are using different 'onMove' functions. The black dot moves according to 1/scale while the red dot moves normally.
var moveCorrected = function (dx, dy) {
// move will be called with dx and dy
this.attr({
cx: this.ox + (1/scale)*dx,
cy: this.oy + (1/scale)*dy
});
}
var move = function (dx, dy) {
// move will be called with dx and dy
this.attr({
cx: this.ox + dx,
cy: this.oy + dy
});
}
So, in answer to my original question. You can't (and shouldn't) be able to change how the mouse moves, that is clearly user defined behavior, but you can change the move function of the object being moved to track with the mouse.
A lable sized like a rectangle with no text but has a border and is invisible (for a visual rectangle on the form around controls but not to contain the controls) or a panel?
What you want to use is a GroupBox. Not that it really matters, most likely, but a label should be cheaper than a panel.
The answer is; it doesn't matter which has the smaller footprint, and if it does you have a design problem (i.e., you have way too many controls on your form). Anyhow, you should just use the control that fits the job, in this case, a Panel or a GroupBox.
If this is really a problem, then the best way to provide a visual separation between controls is to handle each tab page's Paint event, and use e.Graphics.FillRectangle(...) to draw the separator. You would get rid of a very large number of controls that way.
If you can't do something as simple as just drawing a rectangle underneath each control on each tab page, you can write a code-generating routine that you run one time on the form, and for each tab page you generate something like this (by iterating through all the separator controls on the page):
List<Rectangle> rects = new List<Rectangle>();
rects.Add(new Rectangle(10, 40, 200, 5)); // position of first separator
rects.Add(new Rectangle(10, 80, 200, 5)); // position of second separator
// etc.
Then you copy-and-paste these generated code routines into your application, and use them for each page's Paint event, like so:
SolidBrush brush = new SolidBrush(Color.PeachPuff);
foreach (Rectangle rect in rects)
{
e.Graphics.FillRectangle(brush, rect);
}
Then you delete all the separators from your tab control. What you should end up with is an array of type List<Rectangle> (one list for each page) that you instantiate and fill in the form's Load event or its constructor (using the generated code).
I have to reiterate what Ed said, though. .Net forms can have a lot of controls on them without any real problems, so if you're running into problems stemming from having too many controls on the form, you might be better off redesigning the whole thing.