java - Flickering overlapped button - GWT -
this class implement simple pics display gwt project
public class photosslideshow extends composite { private list<image> photos; private int curr; private absolutepanel mainpnl; private simplepanel centerpnl; private image n; private image p; private final int width = 800; public photosslideshow(final list<string> result) { curr = 0; photos = new arraylist<image>(); mainpnl = new absolutepanel(); this.initwidget(mainpnl); this.setstylename("slideshow"); centerpnl = new simplepanel(); string path = gwt.getmodulebaseurl() + "imageupload?src="; (string foto : result) { string url = path.concat(foto); image.prefetch(url); final image curr = new image(url); double ratio = getratio(curr); curr.setpixelsize(width, (int) (ratio * width)); curr.addmouseoverhandler(new mouseoverhandler() { @override public void onmouseover(mouseoverevent event) { n.setvisible(true); p.setvisible(true); } }); curr.addmouseouthandler(new mouseouthandler() { @override public void onmouseout(mouseoutevent event) { n.setvisible(false); p.setvisible(false); } }); photos.add(curr); } n = new image("images/next.png"); n.setpixelsize(40, 50); n.setvisible(false); n.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { shownext(); } }); p = new image("images/prev.png"); p.setpixelsize(40, 50); p.setvisible(false); p.addclickhandler(new clickhandler() { @override public void onclick(clickevent event) { showprev(); } }); centerpnl.setwidget(photos.get(curr)); mainpnl.add(centerpnl); mainpnl.add(n); mainpnl.add(p); posizionabottoni(); } private void shownext() { if (curr == photos.size() - 1) { curr = 0; centerpnl.setwidget(photos.get(curr)); } else { curr++; centerpnl.setwidget(photos.get(curr)); } posizionabottoni(); } private void showprev() { if (curr == 0) { curr = photos.size() - 1; centerpnl.setwidget(photos.get(curr)); } else { curr--; centerpnl.setwidget(photos.get(curr)); } posizionabottoni(); } private void posizionabottoni() { mainpnl.setwidgetposition(p, 0, (int) (photos.get(curr).getheight() / 2 - p.getheight() / 2)); mainpnl.setwidgetposition(n, (int) (width - n.getwidth()), (int) (photos.get(curr).getheight() / 2 - n.getheight() / 2)); } private double getratio(image i) { system.out.println("dimensioni originali: " + i.getwidth() + " x " + i.getheight()); double res = (double) i.getheight() / i.getwidth(); system.out.println("ratio: " + res); return res; } }
apparently works pretty fine, there 1 minor problem: when hover pointer on image, buttons correctly appear, move mouse on buttons click them, flicker. know may reason strange behaviour? in advance.
Comments
Post a Comment