diff -r e8e63152f320 -r 2a9601315dfc javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/BaseCSSEngine.java --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/javauis/eswt_qt/org.eclipse.swt/Eclipse_SWT_PI/qt/org/eclipse/swt/internal/qt/BaseCSSEngine.java Mon May 03 12:27:20 2010 +0300 @@ -0,0 +1,156 @@ +package org.eclipse.swt.internal.qt; + +import org.eclipse.swt.SWT; +import org.eclipse.swt.SWTException; +import org.eclipse.swt.widgets.Display; +import org.eclipse.swt.widgets.Internal_PackageSupport; +import org.eclipse.swt.widgets.Widget; + +/** + * Base CSS Engine for eSWT. This engine recognizes only Qt + * stylesheet syntax. + * + * CSS id selectors are supported by setting an id to the widget as follows. + *
+ *	Button myButton = new Button(composite, SWT.PUSH);
+ *	myButton.setData(WidgetConstant.CSS_ID,"myButtonId");
+ * 
+ * + *

NOTE: This class is intended for internal use only.

+ */ +public final class BaseCSSEngine { + private Display parent; + + /** + * Creates an engine instance. + * + * @exception IllegalArgumentException + * + * @exception SWTException + * + */ + public BaseCSSEngine(Display display){ + if (display == null) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if (display.isDisposed ()) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + if (Display.getCurrent() == null ) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); + this.parent = display; + } + + /** + * Applies the given string containing valid CSS to all the widgets created for the Display. + * CSS used in this method can not have any relative urls (for example for imports and images). + * Relative urls will not be resolved. + * + *

NOTE: This is intended for internal use.

+ * + * @param style + * @exception IllegalArgumentException + * + * @exception SWTException + */ + public void applyCSS( String style ){ + checkEngine(); + if( style == null ) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if( style.startsWith("file:///") ) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + OS.QApplication_setStyleSheet(style); + } + + /** + * Applies the given string containing valid CSS to the widget. + * CSS used in this method can not have any relative urls (for example for imports and images). + * Relative urls will not be resolved. + * + *

NOTE: This is intended for internal use.

+ * + * @param style + * @exception IllegalArgumentException + * + * @exception SWTException + */ + public void applyCSS(Widget widget, String style ){ + checkEngine(); + if( style == null ) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if( widget == null ) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if( widget.isDisposed() ) SWT.error( SWT.ERROR_WIDGET_DISPOSED); + if( style.startsWith("file:///") ) SWT.error (SWT.ERROR_INVALID_ARGUMENT); + OS.QWidget_setStyleSheet(Internal_PackageSupport.handle(widget), style); + } + /** + * Loads a file containing valid CSS and applies to all the widgets for Display. + * This function bypasses java security checks for accessing the file. + * + *

NOTE: This is intended for internal use.

+ * + * @param style + * @exception IllegalArgumentException + * @exception SWTException + */ + public void loadCSS( String filename ){ + checkEngine(); + if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + OS.QApplication_setStyleSheet("file:///"+filename); + } + + /** + * Loads a file containing valid CSS and applies to the widget. + * This function bypasses Java security checks for accessing the file. + * + *

NOTE: This is intended for internal use.

+ * + * @param style + * @exception IllegalArgumentException + * + * @exception SWTException + */ + public void loadCSS( Widget widget, String filename ){ + if (filename == null) SWT.error(SWT.ERROR_NULL_ARGUMENT); + if( widget == null ) SWT.error (SWT.ERROR_NULL_ARGUMENT); + if( widget.isDisposed() ) SWT.error( SWT.ERROR_WIDGET_DISPOSED); + OS.QWidget_setStyleSheet(Internal_PackageSupport.handle(widget), "file:///"+filename); + } + + /** + * Dispose the engine. + * @exception SWTException + * + */ + public void dispose(){ + if (Display.getCurrent() == null ) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); + parent = null; + } + + private void checkEngine(){ + if ( parent == null || parent.isDisposed() ) SWT.error( SWT.ERROR_WIDGET_DISPOSED); + if (Display.getCurrent() == null ) SWT.error (SWT.ERROR_THREAD_INVALID_ACCESS); + } +}