| CODENOTIFIER | HelpYou are not signed inSign in |
Project: gwt-ext
Revision: 1809
Author: mlim1972
Date: 16 Aug 2008 12:16:29
Changes:Issue 389. Adding FocusPanel into GWTExt
Files:| ... | ...@@ -0,0 +1,189 @@ | |
| 1 | /* | |
| 2 | * GWT-Ext Widget Library | |
| 3 | * Copyright 2007 - 2008, GWT-Ext LLC., and individual contributors as indicated | |
| 4 | * by the @authors tag. See the copyright.txt in the distribution for a | |
| 5 | * full listing of individual contributors. | |
| 6 | * | |
| 7 | * This is free software; you can redistribute it and/or modify it | |
| 8 | * under the terms of the GNU Lesser General Public License as | |
| 9 | * published by the Free Software Foundation; either version 3 of | |
| 10 | * the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This software is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | * Lesser General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU Lesser General Public | |
| 18 | * License along with this software; if not, write to the Free | |
| 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 21 | */ | |
| 22 | package com.gwtext.client.widgets; | |
| 23 | ||
| 24 | import com.google.gwt.core.client.JavaScriptObject; | |
| 25 | import com.google.gwt.user.client.ui.impl.FocusImpl; | |
| 26 | import com.gwtext.client.core.EventCallback; | |
| 27 | import com.gwtext.client.core.EventObject; | |
| 28 | import com.gwtext.client.widgets.event.PanelListener; | |
| 29 | import com.gwtext.client.widgets.event.PanelListenerAdapter; | |
| 30 | ||
| 31 | /** | |
| 32 | * This class replicates the FocusPanel provided by GWT but | |
| 33 | * subclassing from the GWTExt Panel instead. Mainly, this | |
| 34 | * class provides events listeners for the Panel not available | |
| 35 | * on the normal Panel. | |
| 36 | * @author malim | |
| 37 | * | |
| 38 | */ | |
| 39 | public class FocusPanel extends Panel { | |
| 40 | ||
| 41 | static final FocusImpl impl = FocusImpl.getFocusImplForPanel(); | |
| 42 | ||
| 43 | public FocusPanel() { | |
| 44 | super(); | |
| 45 | setAttribute("tabindex", 0, true); | |
| 46 | setStyle("visibility: visible"); | |
| 47 | } | |
| 48 | ||
| 49 | /** | |
| 50 | * Construct a new Panel with the given title. | |
| 51 | * | |
| 52 | * @param title the title | |
| 53 | */ | |
| 54 | public FocusPanel(String title) { | |
| 55 | super(title); | |
| 56 | setAttribute("tabindex", 0, true); | |
| 57 | setStyle("visibility: visible"); | |
| 58 | } | |
| 59 | ||
| 60 | /** | |
| 61 | * Constructor to use title and the html used internally | |
| 62 | * @param title title for the panel | |
| 63 | * @param html the inner html in the panel | |
| 64 | */ | |
| 65 | public FocusPanel(String title, String html) { | |
| 66 | super(title, html); | |
| 67 | setAttribute("tabindex", 0, true); | |
| 68 | setStyle("visibility: visible"); | |
| 69 | } | |
| 70 | ||
| 71 | /** | |
| 72 | * Constructor that accepts the title and the width and height of | |
| 73 | * the panel | |
| 74 | * @param title title for the panel | |
| 75 | * @param width the width for the panel | |
| 76 | * @param height the height of the panel | |
| 77 | */ | |
| 78 | public FocusPanel(String title, int width, int height) { | |
| 79 | super(title, width, height); | |
| 80 | setAttribute("tabindex", 0, true); | |
| 81 | setStyle("visibility: visible"); | |
| 82 | } | |
| 83 | ||
| 84 | /** | |
| 85 | * FocusPanel can be reconstructed from the javascript object itself | |
| 86 | * @param jsObj | |
| 87 | */ | |
| 88 | protected FocusPanel(JavaScriptObject jsObj) { | |
| 89 | super(jsObj); | |
| 90 | } | |
| 91 | ||
| 92 | /** | |
| 93 | * Add listeners for the different events | |
| 94 | * @param listener | |
| 95 | */ | |
| 96 | public void addListener(final FocusPanelListener listener){ | |
| 97 | addListener((PanelListener)listener); | |
| 98 | final FocusPanel fpanel = this; | |
| 99 | ||
| 100 | this.addListener(new PanelListenerAdapter() { | |
| 101 | public void onRender(Component component) { | |
| 102 | component.getEl().addListener("blur", new EventCallback() { | |
| 103 | public void execute(EventObject e) { | |
| 104 | listener.onBlur(fpanel, e); | |
| 105 | } | |
| 106 | }); | |
| 107 | ||
| 108 | component.getEl().addListener("focus", new EventCallback() { | |
| 109 | public void execute(EventObject e) { | |
| 110 | listener.onFocus(fpanel, e); | |
| 111 | } | |
| 112 | }); | |
| 113 | ||
| 114 | component.getEl().addListener("click", new EventCallback() { | |
| 115 | public void execute(EventObject e) { | |
| 116 | listener.onClick(fpanel, e); | |
| 117 | } | |
| 118 | }); | |
| 119 | ||
| 120 | component.getEl().addListener("dblclick", new EventCallback() { | |
| 121 | public void execute(EventObject e) { | |
| 122 | listener.onDblClick(fpanel, e); | |
| 123 | } | |
| 124 | }); | |
| 125 | ||
| 126 | component.getEl().addListener("mousedown", new EventCallback() { | |
| 127 | public void execute(EventObject e) { | |
| 128 | listener.onMouseDown(fpanel, e); | |
| 129 | } | |
| 130 | }); | |
| 131 | ||
| 132 | component.getEl().addListener("mouseup", new EventCallback() { | |
| 133 | public void execute(EventObject e) { | |
| 134 | listener.onMouseUp(fpanel, e); | |
| 135 | } | |
| 136 | }); | |
| 137 | ||
| 138 | component.getEl().addListener("keypress", new EventCallback() { | |
| 139 | public void execute(EventObject e) { | |
| 140 | listener.onKeyPress(fpanel, e); | |
| 141 | } | |
| 142 | }); | |
| 143 | ||
| 144 | component.getEl().addListener("keydown", new EventCallback() { | |
| 145 | public void execute(EventObject e) { | |
| 146 | listener.onKeyDown(fpanel, e); | |
| 147 | } | |
| 148 | }); | |
| 149 | ||
| 150 | component.getEl().addListener("keyup", new EventCallback() { | |
| 151 | public void execute(EventObject e) { | |
| 152 | listener.onKeyUp(fpanel, e); | |
| 153 | } | |
| 154 | }); | |
| 155 | ||
| 156 | // Chaining the renderer from the caller... | |
| 157 | listener.onRender(component); | |
| 158 | } | |
| 159 | }); | |
| 160 | ||
| 161 | //wheel... http://adomas.org/javascript-mouse-wheel/ | |
| 162 | } | |
| 163 | ||
| 164 | public void setAccessKey(char key) { | |
| 165 | impl.setAccessKey(getElement(), key); | |
| 166 | } | |
| 167 | ||
| 168 | public void setFocus(boolean focused) { | |
| 169 | if (focused) { | |
| 170 | impl.focus(getElement()); | |
| 171 | } else { | |
| 172 | impl.blur(getElement()); | |
| 173 | } | |
| 174 | } | |
| 175 | ||
| 176 | public void setTabIndex(int index) { | |
| 177 | impl.setTabIndex(getElement(), index); | |
| 178 | } | |
| 179 | ||
| 180 | public native int getZIndex() /*-{ | |
| 181 | var panel = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()(); | |
| 182 | return panel.style.zIndex; | |
| 183 | }-*/; | |
| 184 | ||
| 185 | public native void setZIndex(int index) /*-{ | |
| 186 | var panel = this.@com.gwtext.client.widgets.Component::getOrCreateJsObj()(); | |
| 187 | panel.style.zIndex = index; | |
| 188 | }-*/; | |
| 189 | } |
| ... | ...@@ -0,0 +1,91 @@ | |
| 1 | /* | |
| 2 | * GWT-Ext Widget Library | |
| 3 | * Copyright 2007 - 2008, GWT-Ext LLC., and individual contributors as indicated | |
| 4 | * by the @authors tag. See the copyright.txt in the distribution for a | |
| 5 | * full listing of individual contributors. | |
| 6 | * | |
| 7 | * This is free software; you can redistribute it and/or modify it | |
| 8 | * under the terms of the GNU Lesser General Public License as | |
| 9 | * published by the Free Software Foundation; either version 3 of | |
| 10 | * the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This software is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | * Lesser General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU Lesser General Public | |
| 18 | * License along with this software; if not, write to the Free | |
| 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 21 | */ | |
| 22 | package com.gwtext.client.widgets; | |
| 23 | ||
| 24 | import com.gwtext.client.core.EventObject; | |
| 25 | import com.gwtext.client.widgets.event.PanelListener; | |
| 26 | ||
| 27 | public interface FocusPanelListener extends PanelListener { | |
| 28 | /** | |
| 29 | * Listener for when the panel gets focused | |
| 30 | * @param panel the FocusPanel where the event took place | |
| 31 | * @param e the event object | |
| 32 | */ | |
| 33 | public void onFocus(FocusPanel panel, EventObject e); | |
| 34 | ||
| 35 | /** | |
| 36 | * Listener for when the panel gets out of focus | |
| 37 | * @param panel the FocusPanel where the event took place | |
| 38 | * @param e the event object | |
| 39 | */ | |
| 40 | public void onBlur(FocusPanel panel, EventObject e); | |
| 41 | ||
| 42 | /** | |
| 43 | * Listener for when the panel gets clicked | |
| 44 | * @param panel the FocusPanel where the event took place | |
| 45 | * @param e the event object | |
| 46 | */ | |
| 47 | public void onClick(FocusPanel panel, EventObject e); | |
| 48 | ||
| 49 | /** | |
| 50 | * Listener for when the panel gets double clicked | |
| 51 | * @param panel the FocusPanel where the event took place | |
| 52 | * @param e the event object | |
| 53 | */ | |
| 54 | public void onDblClick(FocusPanel panel, EventObject e); | |
| 55 | ||
| 56 | /** | |
| 57 | * Listener for when the panel gets a mouse down event | |
| 58 | * @param panel the FocusPanel where the event took place | |
| 59 | * @param e the event object | |
| 60 | */ | |
| 61 | public void onMouseDown(FocusPanel panel, EventObject e); | |
| 62 | ||
| 63 | /** | |
| 64 | * Listener for when the panel gets a mouse up event | |
| 65 | * @param panel the FocusPanel where the event took place | |
| 66 | * @param e the event object | |
| 67 | */ | |
| 68 | public void onMouseUp(FocusPanel panel, EventObject e); | |
| 69 | ||
| 70 | /** | |
| 71 | * Listener for when the panel gets a key press event | |
| 72 | * @param panel the FocusPanel where the event took place | |
| 73 | * @param e the event object | |
| 74 | */ | |
| 75 | public void onKeyPress(FocusPanel panel, EventObject e); | |
| 76 | ||
| 77 | /** | |
| 78 | * Listener for when the panel gets a key down event | |
| 79 | * @param panel the FocusPanel where the event took place | |
| 80 | * @param e the event object | |
| 81 | */ | |
| 82 | public void onKeyDown(FocusPanel panel, EventObject e); | |
| 83 | ||
| 84 | /** | |
| 85 | * Listener for when the panel gets a key up event | |
| 86 | * @param panel the FocusPanel where the event took place | |
| 87 | * @param e the event object | |
| 88 | */ | |
| 89 | public void onKeyUp(FocusPanel panel, EventObject e); | |
| 90 | ||
| 91 | } |
| ... | ...@@ -0,0 +1,58 @@ | |
| 1 | /* | |
| 2 | * GWT-Ext Widget Library | |
| 3 | * Copyright 2007 - 2008, GWT-Ext LLC., and individual contributors as indicated | |
| 4 | * by the @authors tag. See the copyright.txt in the distribution for a | |
| 5 | * full listing of individual contributors. | |
| 6 | * | |
| 7 | * This is free software; you can redistribute it and/or modify it | |
| 8 | * under the terms of the GNU Lesser General Public License as | |
| 9 | * published by the Free Software Foundation; either version 3 of | |
| 10 | * the License, or (at your option) any later version. | |
| 11 | * | |
| 12 | * This software is distributed in the hope that it will be useful, | |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
| 15 | * Lesser General Public License for more details. | |
| 16 | * | |
| 17 | * You should have received a copy of the GNU Lesser General Public | |
| 18 | * License along with this software; if not, write to the Free | |
| 19 | * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA | |
| 20 | * 02110-1301 USA, or see the FSF site: http://www.fsf.org. | |
| 21 | */ | |
| 22 | package com.gwtext.client.widgets; | |
| 23 | ||
| 24 | import com.gwtext.client.core.EventObject; | |
| 25 | import com.gwtext.client.widgets.event.PanelListenerAdapter; | |
| 26 | ||
| 27 | public class FocusPanelListenerAdapter extends PanelListenerAdapter implements | |
| 28 | FocusPanelListener { | |
| 29 | ||
| 30 | public void onFocus(FocusPanel panel, EventObject e) { | |
| 31 | } | |
| 32 | ||
| 33 | public void onBlur(FocusPanel panel, EventObject e) { | |
| 34 | } | |
| 35 | ||
| 36 | public void onClick(FocusPanel panel, EventObject e) { | |
| 37 | } | |
| 38 | ||
| 39 | public void onDblClick(FocusPanel panel, EventObject e) { | |
| 40 | } | |
| 41 | ||
| 42 | public void onKeyDown(FocusPanel panel, EventObject e) { | |
| 43 | } | |
| 44 | ||
| 45 | ||
| 46 | public void onKeyPress(FocusPanel panel, EventObject e) { | |
| 47 | } | |
| 48 | ||
| 49 | public void onKeyUp(FocusPanel panel, EventObject e) { | |
| 50 | } | |
| 51 | ||
| 52 | public void onMouseDown(FocusPanel panel, EventObject e) { | |
| 53 | } | |
| 54 | ||
| 55 | public void onMouseUp(FocusPanel panel, EventObject e) { | |
| 56 | } | |
| 57 | ||
| 58 | } |