Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2010 JBoss Inc
   *
   * Licensed under the Apache License, Version 2.0 (the "License");
   * you may not use this file except in compliance with the License.
   * You may obtain a copy of the License at
   *
   *      http://www.apache.org/licenses/LICENSE-2.0
   *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
 package org.drools.guvnor.client.common;
 
 
 
 public abstract class Popup extends PopupPanel {
 
     private boolean       dragged       = false;
     private int           dragStartX;
     private int           dragStartY;
 
     private Command       afterShowEvent;
     private Command       afterCloseEvent;
     private boolean       fixedLocation = false;
 
     private PopupTitleBar titleBar;
 
     public Popup() {
         setGlassEnabledtrue );
     }
 
     public void setAfterShow(Command afterShowEvent) {
         this. = afterShowEvent;
     }
 
     public void setAfterCloseEvent(Command afterCloseEvent) {
         this. = afterCloseEvent;
     }
 
     @Override
     public void show() {
 
         if (  != null ) {
             .execute();
         }
 
         VerticalPanel verticalPanel = new VerticalPanel();
         verticalPanel.setHorizontalAlignment. );
 
         this. = new PopupTitleBargetTitle() );
 
         this...addClickHandlernew ClickHandler() {
             public void onClick(ClickEvent event) {
                 hide();
                 if (  != null ) {
                     .execute();
                 }
             }
         } );
         this..addMouseDownHandlernew MouseDownHandler() {
 
             public void onMouseDown(MouseDownEvent event) {
                  = true;
                  = event.getRelativeXgetElement() );
                  = event.getRelativeYgetElement() );
                 DOM.setCapture.getElement() );
             }
         } );
         this..addMouseMoveHandlernew MouseMoveHandler() {
 
             public void onMouseMove(MouseMoveEvent event) {
                 if (  ) {
                     setPopupPositionevent.getClientX() - ,
                                       event.getClientY() -  );
                }
            }
        } );
        this..addMouseUpHandlernew MouseUpHandler() {
            public void onMouseUp(MouseUpEvent event) {
                 = false;
                DOM.releaseCapture.getElement() );
            }
        } );
        verticalPanel.add );
        Widget content = getContent();
        content.setWidth"100%" );
        verticalPanel.addcontent );
        addverticalPanel );
        addcreateKeyListeningFocusPanelverticalPanel ) );
        super.show();
        focusFirstWidgetcontent );
        if ( ! ) {
            center();
        }
    }
    private FocusPanel createKeyListeningFocusPanel(VerticalPanel verticalPanel) {
        FocusPanel focusPanel = new FocusPanelverticalPanel );
        focusPanel.addKeyDownHandlernew KeyDownHandler() {
            public void onKeyDown(KeyDownEvent event) {
                if ( event.getNativeKeyCode() == . ) {
                    hide();
                }
            }
        } );
        focusPanel.setStyleName"" );
        focusPanel.setFocustrue );
        focusPanel.setWidth"100%" );
        return focusPanel;
    }
    private void focusFirstWidget(Widget content) {
        if ( content instanceof FormStyleLayout ) {
            FormStyleLayout fsl = (FormStyleLayoutcontent;
            Widget ow = fsl.getWidget();
            if ( ow instanceof HasWidgets ) {
                focusFirstWidget( (HasWidgetsow );
            }
        }
    }
    private boolean focusFirstWidget(HasWidgets container) {
        boolean bFocused = false;
        Iterator<Widgetiw = container.iterator();
        while ( !bFocused && iw.hasNext() ) {
            Widget w = iw.next();
            if ( w instanceof HasWidgets ) {
                bFocused = focusFirstWidget( (HasWidgetsw );
            } else if ( w instanceof Focusable ) {
                ((Focusablew).setFocustrue );
                bFocused = true;
                break;
            } else if ( w instanceof FocusWidget ) {
                ((FocusWidgetw).setFocustrue );
                bFocused = true;
                break;
            }
        }
        return bFocused;
    }
    @Override
    public void setPopupPosition(int left,
                                 int top) {
        super.setPopupPositionleft,
                                top );
        if ( left != 0 && top != 0 ) {
             = true;
        }
    }

    
This returns the height of the usable client space, excluding title bar.

Returns:
    public int getClientHeight() {
        return this.getWidget().getOffsetHeight() - this..getOffsetHeight();
    }
    abstract public Widget getContent();
New to GrepCode? Check out our FAQ X