All Downloads are FREE. Search and download functionalities are using the official Maven repository.

jcurses.widgets.WindowManager Maven / Gradle / Ivy

Go to download

Internal Version of JCurses for use with Kolja. For projects please use http://sourceforge.net/projects/javacurses/

The newest version!
/* -*- tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */
package jcurses.widgets;

import java.util.ArrayList;

import jcurses.system.CharColor;
import jcurses.system.InputChar;
import jcurses.system.Toolkit;
import jcurses.util.Rectangle;

/**
 * This class is a jcurses-internal class, whose task is 
 * to manage jcurses text based windows. It schouldn't be used writing applications. 
 */
class WindowManager {
	
	
	private static java.util.List __windowsStack = new ArrayList();
	
	private static CharColor __defaultScreenColors = new CharColor(CharColor.BLUE, CharColor.BLUE);
	private static CharColor __colors = getDefaultScreenColors();
	
	/**
	 * Method to be used by external threads wishing to perform
	 * safe calls to jcurses widgets. Access to this method is
	 * provided from WidgetUtilities.invokeAndWait().
	 *
	 * @param r a Runnable containing the code to be
	 * executed in a thread-safe manner.
	 */
	static synchronized void invokeAndWait(Runnable r) {
		r.run();
	}

	public static CharColor getScreenColors() {
		return __colors;
	}
	
	public static void setScreenColors(CharColor colors) {
		__colors = colors;
	}
	
	
	protected static CharColor getDefaultScreenColors() {
		return __defaultScreenColors; 
	}
	
	
	
	
	protected static void createWindow(Window w) {
		if (__windowsStack.size() == 0) {
			init();
		}
		__windowsStack.add(w);
	}
	
	
	
	protected static void removeWindow(Window w) {
		if (__windowsStack.indexOf(w)!=-1) {
			removeWindowFromScreen(w);
			  __windowsStack.remove(w);
			w.closed();
			if (getTopWindow() == null) {
				shutdown();
			} else {
				getTopWindow().activate();
			}
		}
	}
	
	
	
	
	protected static void makeWindowVisible(Window w, Window oldTop) {
		Toolkit.startPainting();
		if (__windowsStack.indexOf(w)!=-1) {
			int index = __windowsStack.indexOf(w);
			for (int i=index; i<__windowsStack.size(); i++) {
			  	Window aw = __windowsStack.get(i);
				if (aw.isVisible()) {
					aw.paint();
				}
			}
			
		}
		
		if (getTopWindow()!=oldTop) {
			if (oldTop!=null) {
				oldTop.deactivate();
			}
			getTopWindow().activate();
		}
		Toolkit.endPainting();
	}
	

	
	protected static void makeWindowInvisible(Window w, Window oldTop) {
		if (__windowsStack.indexOf(w)!=-1) {
			if (getTopWindow() == null) {
				shutdown();
			} else {
			  removeWindowFromScreen(w);
			  if (w == oldTop) {
			  	w.deactivate();
				if (getTopWindow() == null) {
					getTopWindow().activate();
				}
			  }
			}
		}
	}
	
	
	
    
	
	private static void removeWindowFromScreen(Window w) {
		Toolkit.startPainting();
		int index = __windowsStack.indexOf(w);
		if (!wasPartVisible(index)) {
			Toolkit.endPainting();
			return;
		}
		Rectangle rect = w.getRectangle();
		if (w.hasShadow()) {
			rect = ((Rectangle)rect.clone());
			rect.resize(rect.getWidth()+1, rect.getHeight()+1);
		}
		Toolkit.drawRectangle(rect, getScreenColors());
		for (int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy