Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * Copyright 2012 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.uberfire.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 VerticalPanel container = new VerticalPanel();
     private boolean initialized = false;
     private PopupTitleBar titleBar;
 
     public Popup() {
         setGlassEnabledtrue );
         getElement().getStyle().setZIndex. );
 
 
         this. = new PopupTitleBargetTitle() );
 
         this...addClickHandlernew ClickHandler() {
             public void onClickClickEvent event ) {
                 hide();
                 if (  != null ) {
                     .execute();
                 }
             }
         } );
         this..addMouseDownHandlernew MouseDownHandler() {
 
             public void onMouseDownMouseDownEvent event ) {
                  = true;
                  = event.getRelativeXgetElement() );
                  = event.getRelativeYgetElement() );
                 DOM.setCapture.getElement() );
             }
         } );
         this..addMouseMoveHandlernew MouseMoveHandler() {
 
             public void onMouseMoveMouseMoveEvent event ) {
                 if (  ) {
                     setPopupPositionevent.getClientX() - ,
                                       event.getClientY() -  );
                 }
             }
         } );
         this..addMouseUpHandlernew MouseUpHandler() {
 
             public void onMouseUpMouseUpEvent event ) {
                  = false;
                 DOM.releaseCapture.getElement() );
             }
         } );
 
         .add );
 
        add );
        addcreateKeyListeningFocusPanel ) );
    }
    public void setAfterShowCommand afterShowEvent ) {
        this. = afterShowEvent;
    }
    public void setAfterCloseEventCommand afterCloseEvent ) {
        this. = afterCloseEvent;
    }
    @Override
    public void show() {
        if (  != null ) {
            .execute();
        }
        final Widget content = getContent();
        addContentcontent );
        super.show();
        focusFirstTextBoxcontent );
        if ( ! ) {
            center();
        }
    }
    //Lazy initialization of content as sub-classes may not have created content before super-classes' Constructor is invoked
    private void addContentfinal Widget content ) {
        if (  ) {
            return;
        }
        content.setWidth"100%" );
        .addcontent );
         = true;
    }
    private FocusPanel createKeyListeningFocusPanelVerticalPanel verticalPanel ) {
        FocusPanel focusPanel = new FocusPanelverticalPanel );
        focusPanel.addKeyDownHandlernew KeyDownHandler() {
            public void onKeyDownKeyDownEvent event ) {
                if ( event.getNativeKeyCode() == . ) {
                    hide();
                }
            }
        } );
        focusPanel.setStyleName"" );
        focusPanel.setFocustrue );
        focusPanel.setWidth"100%" );
        return focusPanel;
    }
    private void focusFirstTextBoxWidget content ) {
        if ( content instanceof FormStyleLayout ) {
            FormStyleLayout fsl = (FormStyleLayoutcontent;
            Widget ow = fsl.getWidget();
            if ( ow instanceof HasWidgets ) {
                focusFirstTextBox( (HasWidgetsow );
            }
        } else if ( content instanceof HasWidgets ) {
            focusFirstTextBox( ( (HasWidgetscontent ) );
        }
    }
    //It's tempting to check for Focusable, but Buttons don't look good when the focus is set
    //We therefore use a white-list of widgets that respond well to having the focus set
    private boolean focusFirstTextBoxHasWidgets container ) {
        boolean bFocused = false;
        Iterator<Widgetiw = container.iterator();
        while ( iw.hasNext() ) {
            Widget w = iw.next();
            if ( w instanceof HasWidgets ) {
                bFocused = focusFirstTextBox( (HasWidgetsw );
            } else if ( w instanceof TextBox ) {
                TextBox tb = (TextBoxw;
                if ( tb.isEnabled() ) {
                    tb.setFocustrue );
                    bFocused = true;
                    break;
                }
            } else if ( w instanceof RadioButton ) {
                RadioButton rb = (RadioButtonw;
                if ( rb.isEnabled() ) {
                    rb.setFocustrue );
                    bFocused = true;
                    break;
                }
            } else if ( w instanceof CheckBox ) {
                CheckBox cb = (CheckBoxw;
                if ( cb.isEnabled() ) {
                    cb.setFocustrue );
                    bFocused = true;
                    break;
                }
            }
        }
        return bFocused;
    }
    @Override
    public void setPopupPositionint 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