X-Git-Url: https://gerrit.simantics.org/r/gitweb?a=blobdiff_plain;ds=sidebyside;f=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fbase%2FVisualizationScheduler.java;fp=org.simantics.g3d%2Fsrc%2Forg%2Fsimantics%2Fproconf%2Fg3d%2Fbase%2FVisualizationScheduler.java;h=0000000000000000000000000000000000000000;hb=6b6fcff5d6c326feef07ccf8401f97911778fffe;hp=1a2522562a0ed052f62ec40d03957c6258bb6feb;hpb=504c111db40d78f4913badddd126b283b5504dbb;p=simantics%2F3d.git diff --git a/org.simantics.g3d/src/org/simantics/proconf/g3d/base/VisualizationScheduler.java b/org.simantics.g3d/src/org/simantics/proconf/g3d/base/VisualizationScheduler.java deleted file mode 100644 index 1a252256..00000000 --- a/org.simantics.g3d/src/org/simantics/proconf/g3d/base/VisualizationScheduler.java +++ /dev/null @@ -1,199 +0,0 @@ -/******************************************************************************* - * Copyright (c) 2007- VTT Technical Research Centre of Finland. - * All rights reserved. This program and the accompanying materials - * are made available under the terms of the Eclipse Public License v1.0 - * which accompanies this distribution, and is available at - * http://www.eclipse.org/legal/epl-v10.html - * - * Contributors: - * VTT Technical Research Centre of Finland - initial API and implementation - *******************************************************************************/ -package org.simantics.proconf.g3d.base; - -import java.util.ArrayList; - -import org.eclipse.swt.widgets.Display; -import org.eclipse.ui.PlatformUI; -import org.simantics.utils.ui.ErrorLogger; - - -/** - * TODO : This is a copy-paste from old proconf.utils plug-ing: - * : PreferencePage is not ported, - * : Using Webmon ? - * - * - * VisualizationScheduler is singleton class that schedules - * visualization redraws. - * - * Scheduler has three behaviour patters: - * - * ONCE : Redraws all visualizations one by one and then sleeps for - * a while so that visualizations won't use all available cpu-time. - * - * ALWAYS : Redraws one visualization and sleeps before updating next - * visualization. - * - * OFF : uses asyncExec busy-loop (doesn't block eclipse, but other applications may suffer) - * - * - * @author Marko Luukkainen - * - */ -public class VisualizationScheduler implements Runnable{ - private static VisualizationScheduler instance; - private Display display; - private ArrayList visualizations; - private boolean isDisposed = false; - private boolean stateFlag = false; - private static int sleepTime = 40; - private int index = 0; - - public enum SleepType{ONCE,ALWAYS,OFF}; - - private static SleepType sleepType = SleepType.ONCE; - - private VisualizationScheduler() { - visualizations = new ArrayList(); - display = PlatformUI.getWorkbench().getDisplay(); - //sleepTime = UtilsPlugin.getDefault().getPreferenceStore().getInt(PreferenceConstants.SLEEP_TIME); - //sleepType = SleepType.valueOf(UtilsPlugin.getDefault().getPreferenceStore().getString(PreferenceConstants.SLEEP_TYPE)); - run(); - } - - /** - * Scheduler's run loop
- *
- * Loop contains two stages:
- * In the first stage scheduler runs asyncExec for each visualization - * and after that it runs itself with asyncExec.
- * In the second stage scheduler runs itself with timerExec which allows OS to run it's own code. - */ - public void run() { - if (!isDisposed && !display.isDisposed() && !PlatformUI.getWorkbench().isClosing()) { - switch(sleepType) { - case ALWAYS: - stateFlag = !stateFlag; - if (stateFlag) { - if (visualizations.size() > 0) { - if (index >= visualizations.size()) - index = 0; - Runnable scene = visualizations.get(index); - try { - display.asyncExec(scene); - } catch (Exception e) { - ErrorLogger.defaultLogWarning("Scheduler exception", e); - } - index++; - } - display.asyncExec(this); - } else { - display.timerExec(sleepTime, this); - } - break; - case ONCE: - stateFlag = !stateFlag; - if (stateFlag) { - for (Runnable scene : visualizations) { - try { - display.asyncExec(scene); - } catch (Exception e) { - ErrorLogger.defaultLogWarning("Scheduler exception",e); - } - } - display.asyncExec(this); - } else { - display.timerExec(sleepTime,this); - } - break; - case OFF: - for (Runnable scene : visualizations) { - try { - display.asyncExec(scene); - } catch (Exception e) { - ErrorLogger.defaultLogWarning("Scheduler exception",e); - } - } - display.asyncExec(this); - break; - } - } - } - - /** - * Adds visualization into scheduler - * @param scene - */ - public void addVisualization(Runnable scene) { - visualizations.add(scene); - } - - /** - * Removes visualization from scheduler - * @param scene - */ - public void removeVisualization(Runnable scene) { - visualizations.remove(scene); - } - - /** - * disposes scheduler. - * - */ - public void dispose() { - isDisposed = true; - } - - /** - * @return scheduler's instance - */ - public static VisualizationScheduler getInstance() { - if (instance == null) - instance = new VisualizationScheduler(); - - return instance; - } - - /** - * @return the sleep time of the scheduler - */ - public int getSleepTime() { - return sleepTime; - } - - /** - *

- * Sets scheduler's sleep time. Larger sleep time gives more - * cpu time to other applications, but makes visualizations less - * responsive. - *

- * - * @param sleepTime - */ - public static void setSleepTime(int time) { - sleepTime = time; - } - -// public boolean isSleepAlways() { -// return sleepAlways; -// } - - /** - * if this flag is set scheludler gives time to other aplications - * between each visualization update. Otherwise all visualizations are updated in row and - * then priority is given to other applications. - * @param sleepAlways - */ -// public static void setSleepAlways(boolean sleep) { -// sleepAlways = sleep; -// } - - public static SleepType getSleepType() { - return sleepType; - } - - public static void setSleepType(SleepType s) { - sleepType = s; - } - -}