1 11 12 package org.eclipse.ui.internal; 13 14 import org.eclipse.core.runtime.IProgressMonitor; 15 import org.eclipse.core.runtime.IStatus; 16 import org.eclipse.core.runtime.Status; 17 import org.eclipse.jface.dialogs.ControlAnimator; 18 import org.eclipse.swt.events.DisposeListener; 19 import org.eclipse.swt.graphics.Point; 20 import org.eclipse.swt.graphics.Rectangle; 21 import org.eclipse.swt.widgets.Control; 22 import org.eclipse.ui.progress.UIJob; 23 24 31 public class WorkbenchControlAnimator extends ControlAnimator { 32 33 37 private static final int CLOSED = 0; 38 39 43 private static final int OPENING = 1; 44 45 49 private static final int OPEN = 2; 50 51 55 private static final int CLOSING = 3; 56 57 private UIJob slideJob; 58 59 private int endY; 60 61 private boolean finished; 62 63 private boolean inTransition = false; 64 65 private boolean animated = false; 66 67 private int state = CLOSED; 68 69 private int LONG_DELAY = 300; 70 71 private int SHORT_DELAY = 25; 72 73 74 80 public WorkbenchControlAnimator(Control control) { 81 super(control); 82 } 83 84 87 public void setVisible(boolean visible) { 88 104 if(animated) { 105 super.setVisible(visible); 106 return; 107 } 108 109 setAnimationState(visible ? OPENING: CLOSING); 110 finished = false; 111 112 control.setVisible(true); 113 114 Rectangle parentBounds = control.getParent().getBounds(); 115 int bottom = parentBounds.height; 116 117 if (bottom <= 0) { 118 setAnimationState(OPEN); 119 return; 120 } 121 122 endY = visible ? bottom - control.getBounds().height 123 : bottom; 124 125 if(slideJob != null) 126 slideJob.cancel(); 127 128 slideJob = getSlideJob(); 129 control.addDisposeListener(new DisposeListener(){ 130 public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) { 131 slideJob = null; 132 } 133 }); 134 135 if(getAnimationState() == OPENING && !inTransition){ 138 slideJob.schedule(LONG_DELAY); 139 } else { 140 slideJob.schedule(SHORT_DELAY); 141 } 142 143 } 144 145 154 private UIJob getSlideJob(){ 155 UIJob newSlideJob = new UIJob("Sliding Message") { public IStatus runInUIThread(IProgressMonitor monitor) { 157 if(!monitor.isCanceled() && !control.isDisposed()){ 158 Point loc = control.getLocation(); 159 switch (getAnimationState()) { 160 case OPENING: 161 animated = true; 162 loc.y--; 163 if (loc.y >= endY) { 164 control.setLocation(loc); 165 } else { 166 finished = true; 167 setAnimationState(OPEN); 168 } 169 break; 170 case CLOSING: 171 loc.y++; 172 if (loc.y <= endY) { 173 control.setLocation(loc); 174 } else { 175 finished = true; 176 setAnimationState(CLOSED); 177 control.setVisible(false); 178 } 179 break; 180 default: 181 break; 182 } 183 if(!finished) { 184 inTransition = true; 185 slideJob.schedule(5); 186 } else 187 inTransition = false; 188 return Status.OK_STATUS; 189 } 190 return Status.CANCEL_STATUS; 191 } 192 }; 193 newSlideJob.setSystem(true); 194 return newSlideJob; 195 } 196 197 205 private void setAnimationState(int state) { 206 this.state = state; 207 } 208 209 215 private int getAnimationState() { 216 return state; 217 } 218 219 } 220 | Popular Tags |