linux - Java: Proper way to resize SWT shell to maintain aspect ratio -
i did see other threads here on task. recommended answer pretty implemented, see code below. code works okay on windows (head shaking bit), on centos of time application locks. assume application goes infinite loop or something.
my thought add java equivalent of c#.net application.doevents(), not find how , other threads here on consider improper solution , time should spent implement proper solution.
the problem on windows when resize application, see brief outline / flash of application in desired size user wants , final size maintains aspect ratio. prefer clean no jitter. need support centos (linux), hence question here.
here code fragment.
public class appmain { public shell shell; public display display; public controllistener oshellcontrollistener; public boolean isresizing = false; protected void createcontents(display display) { shell = new shell(swt.shell_trim); shell.setminimumsize(new point(660, 690)); oshellcontrollistener = new controladapter() { @override public void controlresized(controlevent arg0) { oappevents.eventappresized(); } }; shell.addcontrollistener(oshellcontrollistener); } protected void eventappresized() { // not allow multiple events. if (true == this.isresizing) return; else { this.isresizing = true; this.shell.removecontrollistener(this.oshellcontrollistener); } // new dimensions , application minimum size (gives x/y ratio). point sizapp = this.shell.getsize(); point sizappmin = this.shell.getminimumsize(); // make sure user sizes application while maintaining same initial x/y ratio. y limiting factor. int cxappnew = (int)((double)sizapp.y * ((double)sizappmin.x / (double)sizappmin.y)); if (sizapp.x != cxappnew) { sizapp.x = cxappnew; this.shell.setsize(sizapp); } // allow resize event. this.shell.addcontrollistener(this.oshellcontrollistener); this.isresizing = false; } }
here links. reason did not put links using recommended solutions, namely using static variable prevent going resize event , removing control listener while resizing. yes, 2 approaches duplicate each other, 1 or other, not both. when things working, clean things up.
there other articles, closed browser , not find them again. solutions wrote: 1) variable 2) removecontrollistener()
Comments
Post a Comment