package com.opera.core.systems;

import java.awt.Dimension;
import java.awt.Point;

import com.opera.core.systems.scope.protos.DesktopWmProtos.QuickWidgetInfo;
import com.opera.core.systems.scope.protos.DesktopWmProtos.DesktopWindowRect;

public class QuickWidget {
		private final QuickWidgetInfo info; // or just int objectId
		//private final OperaDriver parent;
		//private final IOperaExec execService;
		
		public QuickWidget(QuickWidgetInfo info) {
	        //this.parent = parent;
	        this.info = info;
	        //execService = parent.getExecService();
	    }
		
		public String getName() {
			return info.getName();
		}

		public String getText() {
			return info.getText();
		}
		
		/* (non-Javadoc)
		 * @see com.opera.core.systems.IOperaWidget#isEnabled()
		 */
		public boolean isDefault() {
			return info.getDefaultLook();
		}
		
		public boolean hasFocusedLook() {
			return info.getFocusedLook();
		}

		public boolean isEnabled() {
			return info.getEnabled();
		}
		
		/* (non-Javadoc)
		 * @see com.opera.core.systems.IOperaWidget#isSelected()
		 */
		public boolean isSelected() {
			return info.getState() == 1;
		}
		
		/* (non-Javadoc)
		 * @see com.opera.core.systems.IOperaWidget#isVisible()
		 * TODO, FIXME: This needs to handle also if the dialog is not expanded, is off_screen etc.
		 */
		public boolean isVisible(){
			return info.getVisible() != 0 ? true : false; 
		}
		
		public boolean isDefault() {
			return info.getDefaultLook() &&  info.getFocusedLook();
		}
		
		
		/* (non-Javadoc)
		 * @see com.opera.core.systems.IOperaWidget#toggle()
		 */
		public boolean toggle() {
			// TODO FIXME
			return false; 
		}
		
		private DesktopWindowRect getRect() {
			return info.getRect();
		}
		
		
		public Point getLocation() {
			DesktopWindowRect rect = getRect();
			return new Point(rect.getX(), rect.getY());
		}

		/* (non-Javadoc)
		 * @see com.opera.core.systems.IOperaWidget#getSize()
		 */
		public Dimension getSize() {
			DesktopWindowRect rect = getRect();
			return new Dimension(rect.getWidth(), rect.getHeight());
		}

		@Override
		public boolean equals(Object obj) {
			if(obj instanceof QuickWidget) {
				QuickWidget ref = (QuickWidget) obj;
				return (ref.getName().equals(this.getName()));
			}
			return false;
		}
		
		@Override
		public int hashCode() {
			int result = 42;
			result = 31 * result + getName().hashCode();
			return result;
		}
		
		@Override
		public String toString() {
			return "quickwidget" + hashCode();
		}
}




@@ -835,32 +835,63 @@
 tLook();%0A%09%09%7D%0A%09%09%0A
+%09%09// TODO: FIXME . isFocused()%0A
 %09%09public boolean
@@ -906,24 +906,24 @@
 sedLook() %7B%0A
-
 %09%09%09return in
@@ -1153,12 +1153,12 @@
 .get
-Stat
+Valu
 e() 
@@ -1438,105 +1438,8 @@
 %0A%09%09%0A
-%09%09public boolean isDefault() %7B%0A%09%09%09return info.getDefaultLook() &&  info.getFocusedLook();%0A%09%09%7D%0A%09%09%0A
 %09%09%0A%09
@@ -2395,33 +2395,711 @@
 rn %22
-q
+Q
 uick
-w
+W
 idget
+ 
 %22 + 
-hashCode()
+getName();%0A%09%09%7D%0A%09%09%0A%09%09public String toFullString() %7B%0A%09%09%09return %22QuickWidget%5Cn%22 +  %0A%09%09%09  %22       Widget name: %22 + info.getName() + %22%5Cn%22%0A%09%09%09+ %22       type: %22 + info.getType()  + %22%5Cn%22%0A%09%09%09+ %22    visible: %22 + info.getVisible() + %22%5Cn%22%0A%09%09%09+ %22       text: %22 + info.getText() + %22%5Cn%22%0A%09%09%09+ %22      state: %22 + info.getValue() + %22%5Cn%22%0A%09%09%09+ %22    enabled: %22 + info.getEnabled() + %22%5Cn%22%0A%09%09%09+ %22    default: %22 + info.getDefaultLook() + %22%5Cn%22%0A%09%09%09+ %22    focused: %22 + info.getFocusedLook() + %22%5Cn%22%0A%09%09%09+ %22          x: %22 + info.getRect().getX() + %22%5Cn%22%0A%09%09%09+ %22          y: %22 + info.getRect().getY() + %22%5Cn%22%0A%09%09%09+ %22      width: %22 + info.getRect().getWidth() + %22%5Cn%22%0A%09%09%09+ %22     height: %22 + info.getRect().getHeight() + %22 %5Cn%22
 ;%0A%09%09

Human-readable toString