Example usage for com.google.gwt.user.client.ui MouseListenerAdapter MouseListenerAdapter

List of usage examples for com.google.gwt.user.client.ui MouseListenerAdapter MouseListenerAdapter

Introduction

In this page you can find the example usage for com.google.gwt.user.client.ui MouseListenerAdapter MouseListenerAdapter.

Prototype

MouseListenerAdapter

Source Link

Usage

From source file:com.apress.progwt.client.college.gui.ext.EditableLabelExtension.java

License:Apache License

/**
 * Creates the Label, the TextBox and Buttons. Also associates the
 * update method provided in the constructor with this instance.
 * //  ww w .j  a  v  a 2 s  .c o m
 * @param labelText
 *            The value of the initial Label.
 * @param onUpdate
 *            The class that provides the update method called when
 *            the Label has been updated.
 * @param visibleLength
 *            The visible length (width) of the TextBox/TextArea.
 * @param maxLength
 *            The maximum length of text in the TextBox.
 * @param maxHeight
 *            The maximum number of visible lines of the TextArea
 * @param okButtonText
 *            The text diplayed in the OK button.
 * @param cancelButtonText
 *            The text displayed in the Cancel button.
 */
private void createEditableLabel(String labelText, ChangeListener onUpdate, String okButtonText,
        String cancelButtonText) {
    // Put everything in a VerticalPanel
    FlowPanel instance = new FlowPanel();

    if (labelText == null || labelText.length() < 1) {
        labelText = "Click to edit me";
    }

    // Create the Label element and add a ClickListener to call out
    // Change method when clicked
    text = new Label(labelText);
    text.setStylePrimaryName("editableLabel-label");

    text.addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            changeTextLabel();
        }
    });
    text.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            text.addStyleDependentName(HOVER_STYLE);
        }

        public void onMouseLeave(Widget sender) {
            text.removeStyleDependentName(HOVER_STYLE);
        }
    });

    // Create the TextBox element used for non word wrapped Labels
    // and add a KeyboardListener for Return and Esc key presses
    changeText = new TextBox();
    changeText.setStyleName("editableLabel-textBox");

    changeText.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            // If return then save, if Esc cancel the change,
            // otherwise do nothing
            switch (keyCode) {
            case 13:
                setTextLabel();
                break;
            case 27:
                cancelLabelChange();
                break;
            }
        }
    });

    // Create the TextAre element used for word-wrapped Labels
    // and add a KeyboardListener for Esc key presses (not return in
    // this case)

    changeTextArea = new TextArea();
    changeTextArea.setStyleName("editableLabel-textArea");

    changeTextArea.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            // If Esc then cancel the change, otherwise do nothing
            switch (keyCode) {
            case 27:
                cancelLabelChange();
                break;
            }
        }
    });

    // Set up Confirmation Button
    confirmChange = createConfirmButton(okButtonText);

    if (!(confirmChange instanceof SourcesClickEvents)) {
        throw new RuntimeException("Confirm change button must allow for click events");
    }

    ((SourcesClickEvents) confirmChange).addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            setTextLabel();
        }
    });

    // Set up Cancel Button
    cancelChange = createCancelButton(cancelButtonText);
    if (!(cancelChange instanceof SourcesClickEvents)) {
        throw new RuntimeException("Cancel change button must allow for click events");
    }

    ((SourcesClickEvents) cancelChange).addClickListener(new ClickListener() {
        public void onClick(Widget sender) {
            cancelLabelChange();
        }
    });

    // Put the buttons in a panel
    FlowPanel buttonPanel = new FlowPanel();
    buttonPanel.setStyleName("editableLabel-buttonPanel");
    buttonPanel.add(confirmChange);
    buttonPanel.add(cancelChange);

    // Add panels/widgets to the widget panel
    instance.add(text);
    instance.add(changeText);
    instance.add(changeTextArea);
    instance.add(buttonPanel);

    // Set initial visibilities. This needs to be after
    // adding the widgets to the panel because the FlowPanel
    // will mess them up when added.
    text.setVisible(true);
    changeText.setVisible(false);
    changeTextArea.setVisible(false);
    confirmChange.setVisible(false);
    cancelChange.setVisible(false);

    // Set the updater method.
    updater = onUpdate;

    // Assume that this is a non word wrapped Label unless explicitly
    // set otherwise
    text.setWordWrap(false);

    // Set the widget that this Composite represents
    initWidget(instance);
}

From source file:com.cubusmail.gwtui.client.widgets.EmailAddressLink.java

License:Open Source License

public EmailAddressLink(GWTAddress address, boolean withSeparator) {

    super();/* ww w  .  ja va 2 s .co m*/

    FlowPanel panel = new FlowPanel();
    initWidget(panel);
    DOM.setStyleAttribute(panel.getElement(), "whiteSpace", "nowrap");
    DOM.setStyleAttribute(getElement(), "whiteSpace", "nowrap");

    ImageHyperlink link = new ImageHyperlink();
    link.setText(address.getInternetAddress());

    AddContactFromEmailAddressAction addContactAction = new AddContactFromEmailAddressAction();
    addContactAction.setAddress(address);
    NewMessageToEmailAddressAction newMessageAction = new NewMessageToEmailAddressAction();
    newMessageAction.setAddress(address);

    this.contextMenu = new Menu();
    this.contextMenu.addItem(UIFactory.createMenuItem(addContactAction));
    this.contextMenu.addItem(UIFactory.createMenuItem(newMessageAction));

    MouseListenerAdapter listener = new MouseListenerAdapter() {

        @Override
        public void onMouseDown(Widget sender, int x, int y) {

            contextMenu.showAt(sender.getAbsoluteLeft() + x + 10, sender.getAbsoluteTop() + y);
        }
    };
    link.addLeftButtonListener(listener);
    link.addRightButtonListener(listener);

    panel.add(link);
    if (withSeparator) {
        panel.add(new HTML(",&nbsp;&nbsp;"));
    }
}

From source file:com.dimdim.conference.ui.common.client.user.NewChatPanel.java

License:Open Source License

/**
 * Same chat panel is used for global as well as personal chats. Global
 * chat is simply identified by using 'other' argument as null.
 *///from  w w  w . ja  va  2  s  .c o  m
public NewChatPanel(UIRosterEntry me, UIRosterEntry other) {
    this.me = me;
    this.other = other;
    if (other != null) {
        this.toId = other.getUserId();
    }
    this.lastActivityTime = System.currentTimeMillis();
    if (ConferenceGlobals.isBrowserIE()) {
        spaceSequence = "DIMDIM_LTwbr>";
    }

    //   Add the central scroll panel that will hold the messages.

    scrollPanel = new ScrollPanel();
    scrollPanel.add(this.chatMessages);
    scrollPanel.setStyleName("dm-chat-message-area");

    //   A small and short instructions / message area.

    instructionPanel = new HorizontalPanel();
    instructionPanel.setStyleName("chat-instruction-panel");
    instructionPanel.setWidth("248px");

    //in public chat add powered by dimdim logo else have the help text
    if (null == toId) {
        HorizontalPanel hp = new HorizontalPanel();

        HorizontalPanel tempSpacer = new HorizontalPanel();
        tempSpacer.setWidth("10px");
        tempSpacer.add(new Label("  "));
        hp.add(tempSpacer);
        hp.setCellHorizontalAlignment(tempSpacer, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(tempSpacer, VerticalPanel.ALIGN_MIDDLE);

        PNGImage image = new PNGImage("images/logo_powered.png", 8, 14);
        hp.add(image);
        //instructionPanel.setCellWidth(image,"100%");
        hp.setCellHorizontalAlignment(image, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(image, VerticalPanel.ALIGN_MIDDLE);

        //hp.setBorderWidth(1);
        HTML instruction = new HTML("Powered By <a href='#'><u> Dimdim </u></a>");
        instruction.addClickListener(new ClickListener() {
            public void onClick(Widget sender) {
                openDimdimWebSite();
            }
        });
        instruction.setStyleName("poweredby-text");
        hp.add(instruction);
        //instructionPanel.setCellWidth(instruction,"100%");
        hp.setCellHorizontalAlignment(instruction, HorizontalPanel.ALIGN_LEFT);
        hp.setCellVerticalAlignment(instruction, VerticalPanel.ALIGN_MIDDLE);

        instructionPanel.add(hp);
        //instructionPanel.setCellWidth(instruction,"100%");
        instructionPanel.setCellHorizontalAlignment(hp, HorizontalPanel.ALIGN_LEFT);
        instructionPanel.setCellVerticalAlignment(hp, VerticalPanel.ALIGN_MIDDLE);

    } else {
        Label instruction = new Label(UIStrings.getChatPanelInstruction());
        instruction.setStyleName("chat-instruction");
        instructionPanel.add(instruction);
        //instructionPanel.setCellWidth(instruction,"100%");
        instructionPanel.setCellHorizontalAlignment(instruction, HorizontalPanel.ALIGN_LEFT);
        instructionPanel.setCellVerticalAlignment(instruction, VerticalPanel.ALIGN_MIDDLE);
    }

    Label emoticon = new Label(UIStrings.getChatPanelEmoticonInstruction());
    emoticon.setStyleName("chat-emoticon-lable");
    instructionPanel.add(emoticon);
    //instructionPanel.setCellWidth(emoticon,"30%");
    instructionPanel.setCellHorizontalAlignment(emoticon, HorizontalPanel.ALIGN_RIGHT);
    instructionPanel.setCellVerticalAlignment(emoticon, VerticalPanel.ALIGN_MIDDLE);

    //   Add the text area that the users will type their messages in.

    sendText = new TextArea();
    sendText.setText("");
    if (null == toId) {
        sendText.setText(UIStrings.getChatPanelInstruction());
        sendText.setStyleName("chat-instruction");
    }
    //if (ConferenceGlobals.isBrowserIE())
    //{
    sendText.setVisibleLines(2);
    //}
    //else
    //{
    //   sendText.setVisibleLines(1);
    //}
    sendText.setStyleName("chat-text-area");

    keyboardListener = new KeyboardListenerAdapter() {
        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_ENTER) {
                sendChatMessage();
            }
        }
    };
    sendText.addKeyboardListener(keyboardListener);
    sendText.addFocusListener(this);

    //   Assemble the overall chat panel.

    initWidget(pane);
    pane.setWidth("100%");
    pane.add(outer);
    outer.setWidth("100%");

    outer.add(scrollPanel);
    scrollPanel.addStyleName("dm-chat-message-area-pane");

    outer.add(this.instructionPanel);
    outer.setCellWidth(this.instructionPanel, "100%");
    outer.setCellHorizontalAlignment(this.instructionPanel, HorizontalPanel.ALIGN_LEFT);

    outer.add(this.sendText);
    outer.setCellWidth(this.sendText, "100%");
    outer.setCellHorizontalAlignment(this.sendText, HorizontalPanel.ALIGN_CENTER);
    this.sendText.setStyleName("dm-chat-text-area");

    this.rosterModel = ClientModel.getClientModel().getRosterModel();

    //      Window.alert("created popup..");
    //setting up emoticons popup panel
    ePopUP = new EmoticonsPopup(sendText);
    emoticon.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            int left = sender.getAbsoluteLeft() - 5;
            int top = sender.getAbsoluteTop() - 75;
            ePopUP.setPopupPosition(left, top);
            ePopUP.showHoverPopup();
            ePopUP.popupVisible();
        }
    });

    if (emoticonsMap == null) {
        emoticonsMap = new HashMap();
        prepareEmoticonsList();
        //         this is to handle :) and :( also         
    }
}

From source file:com.dimdim.conference.ui.user.client.MoodControlPopup.java

License:Open Source License

protected HorizontalPanel getMoodPanel(UserMood mood, boolean custom) {
    /*// w  w  w.  ja v  a  2 s . co m
    FocusPanel   pane = new FocusPanel();
    pane.addMouseListener(new MouseListenerAdapter()
    {
       public void onMouseEnter(Widget sender)
       {
    sender.addStyleName("mood-menu-entry-selected");
       }
       public void onMouseLeave(Widget sender)
       {
    sender.removeStyleName("mood-menu-entry-selected");
       }
    });
    */
    final HorizontalPanel moodPanel = new HorizontalPanel();
    //      pane.add(moodPanel);
    moodPanel.setStyleName("mood-menu-entry");
    if (!custom) {
        moodPanel.addStyleName("mood-menu-entry-border");
    }
    Image moodImage = UIImages.getImageBundle(UIImages.defaultSkin).getNewMoodImageUrl(mood.getMood());
    moodImage.setStyleName(mood.getImageStyleName());
    moodPanel.add(moodImage);
    moodPanel.setCellVerticalAlignment(moodImage, VerticalPanel.ALIGN_MIDDLE);

    Label moodLabel = getMoodLabel(mood, custom);
    moodLabel.addStyleName("mood-label");
    moodPanel.add(moodLabel);
    moodPanel.setCellVerticalAlignment(moodLabel, VerticalPanel.ALIGN_MIDDLE);
    moodLabel.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            moodPanel.addStyleName("mood-menu-entry-selected");
        }

        public void onMouseLeave(Widget sender) {
            moodPanel.removeStyleName("mood-menu-entry-selected");
        }
    });
    moodPanel.setTitle(mood.getDisplayLabel());
    return moodPanel;
}

From source file:com.flatown.client.chess.ChessPanel.java

License:LGPL

protected void addListeners() {
    this.addMouseListener(new MouseListenerAdapter() {
        public void onMouseMove(Widget source, int x, int y) {
            _board.movePiece(x, y);/*from  w  ww .j  ava  2  s  .com*/
        }

        public void onMouseDown(Widget source, int x, int y) {
            DOM.setCapture(source.getElement());
            _board.grabPiece(x, y);
        }

        public void onMouseUp(Widget source, int x, int y) {
            DOM.releaseCapture(source.getElement());
            _board.releasePiece(x, y);
        }
    });
}

From source file:com.flatown.client.FavoritesPanel.java

License:Apache License

private FavoritesPanel() {
    _favorites = new VerticalPanel();
    _favorites.setStyleName("favorites");

    _listenerPanel = new FocusPanel(_favorites);
    _listenerPanel.addMouseListener(new MouseListenerAdapter() {
        public void onMouseLeave(Widget sender) {
            _clicked = null;//from w w w .j ava 2 s .  c  o m
        }

        public void onMouseUp(Widget sender, int x, int y) {
            _clicked = null;
        }
    });

    setWidget(_listenerPanel);
    setStyleName("favoritesPanel");
    DOM.setStyleAttribute(getElement(), "maxHeight", Window.getClientHeight() - 50 + "px");

    _dragListener = new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            if (sender instanceof DragBar) {
                DragBar bar = (DragBar) sender;
                if (isClicked() && _clicked != bar) {
                    int newPos = _favorites.getWidgetIndex(bar.getDragWidget());
                    _favorites.remove(_clicked.getDragWidget());
                    _favorites.insert(_clicked.getDragWidget(), newPos);
                }
            }
        }

        public void onMouseDown(Widget sender, int x, int y) {
            if (sender instanceof DragBar)
                _clicked = (DragBar) sender;
        }

        public void onMouseUp(Widget sender, int x, int y) {
            if (isClicked())
                GBox.Prefs.saveFavorites();
        }
    };
}

From source file:com.flatown.client.SearchLayout.java

License:Apache License

/** Creates the draggable part of the layout */
public FocusPanel createDragBar() {
    _dragBar = new DragBar();
    FlowPanel dragPanel = new FlowPanel();
    dragPanel.add(createTopPanel());// w  w  w . ja  v a 2 s  . c  o m
    dragPanel.add(createBottomPanel());
    _dragBar.setWidget(dragPanel);
    _dragBar.setDragWidget(_searchbox);
    _dragBar.addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            ResultsBox.hideHover();
            ResultsBox.collapse();
        }
    });
    return _dragBar;
}

From source file:com.gs.fw.common.mithra.ui.gwt.client.RolloverButton.java

License:Apache License

public RolloverButton(String title, final AbstractImagePrototype onImage,
        final AbstractImagePrototype offImage) {
    super("");
    this.setTitle(title);
    offImage.applyTo(this);
    addMouseListener(new MouseListenerAdapter() {
        public void onMouseEnter(Widget sender) {
            onImage.applyTo(RolloverButton.this);
        }/*from ww w .  j a v  a 2 s  .  c  o  m*/

        public void onMouseLeave(Widget sender) {
            offImage.applyTo(RolloverButton.this);
        }
    });
}

From source file:com.pronoiahealth.olhie.client.widgets.rating.RateItWidget.java

License:Open Source License

public RateItWidget(double rating, int maxRating, Image normalImage, Image ratedImage, Image normalZeroImage,
        Image ratedZeroImage, Image[] ratingImages) {
    FocusPanel panel = new FocusPanel();
    panel.addMouseListener(new MouseListenerAdapter() {
        public void onMouseLeave(Widget sender) {
            if (isRated()) {
                drawRating(getUserRating());
            } else {
                setup();//from  w ww  .  j a v a2s .  c  o m
            }
        }
    });
    panel.addKeyboardListener(new KeyboardListenerAdapter() {

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            if (keyCode == KeyboardListener.KEY_RIGHT) {
                RateItWidget.this.setUserRating(RateItWidget.this.getUserRating() + 1, true);
            } else if (keyCode == KeyboardListener.KEY_LEFT) {
                RateItWidget.this.setUserRating(RateItWidget.this.getUserRating() - 1, true);
            } else if (keyCode >= '0' && keyCode <= '9') {
                RateItWidget.this.setUserRating(keyCode - '0', true);
            }
        }
    });
    grid = new Grid(1, maxRating + 1) {
        public boolean clearCell(int row, int column) {
            boolean retValue = super.clearCell(row, column);

            Element td = getCellFormatter().getElement(row, column);
            DOM.setInnerHTML(td, "");
            return retValue;
        }
    };
    grid.setCellSpacing(0);
    grid.setCellPadding(0);
    this.normalImage = normalImage;
    this.ratedImage = ratedImage;
    this.normalZeroImage = normalZeroImage;
    this.ratedZeroImage = ratedZeroImage;
    this.ratingImages = ratingImages;
    this.rating = rating;
    this.userRating = 0;
    setup();
    panel.add(grid);
    setWidget(panel);
    setStyleName("RateItWidget");
}

From source file:com.totsp.gwittir.client.ui.SoftButton.java

License:Open Source License

protected void init() {
    this.baseStyleName = "gwittir-SoftButton";
    this.clickers = new ClickListenerCollection();
    this.softBase = new FocusPanel();
    this.grid = new Grid(1, 1);
    DOM.setStyleAttribute(this.softBase.getElement(), "display", "inline");
    this.setContent(new Label());
    this.softBase.setWidget(grid);

    final SoftButton instance = this;
    listener = new ClickListener() {
        public void onClick(Widget sender) {
            //GWT.log("Clicked " + getAction(), null);
            long clickTime = System.currentTimeMillis();

            if ((clickTime - lastClick) >= 100) {
                lastClick = clickTime;/*from w  w  w.j av  a2s.co m*/
                clickers.fireClick(instance);

                if (enabled && (getAction() != null)) {
                    getAction().execute(instance);
                }
            }
        }
    };
    this.softBase.addClickListener(listener);
    this.focus = new FocusListener() {
        public void onLostFocus(Widget sender) {
            focused = false;

            if (enabled) {
                setStyleName(getBaseStyleName());
            }
        }

        public void onFocus(Widget sender) {
            focused = true;

            if (enabled && !getStyleName().equals(getBaseStyleName() + "-pressed")) {
                setStyleName(getBaseStyleName() + "-focused");
            }
        }
    };
    this.addFocusListener(this.focus);
    this.hover = new MouseListenerAdapter() {
        public void onMouseUp(Widget sender, int x, int y) {
            if (enabled) {
                setStyleName(getBaseStyleName() + "-focused");
            }
        }

        public void onMouseDown(Widget sender, int x, int y) {
            //GWT.log("Press", null);
            if (enabled) {
                setStyleName(getBaseStyleName() + "-pressed");
            }
        }

        public void onMouseLeave(Widget sender) {
            if (enabled) {
                if (focused) {
                    setStyleName(getBaseStyleName() + "-focused");
                } else {
                    setStyleName(getBaseStyleName());
                }
            }
        }

        public void onMouseEnter(Widget sender) {
            if (enabled) {
                setStyleName(getBaseStyleName() + "-hover");
            }
        }
    };
    this.softBase.addMouseListener(hover);
    this.softBase.addKeyboardListener(new KeyboardListenerAdapter() {
        public void onKeyPress(Widget sender, char keyCode, int modifiers) {
            if ((keyCode == ' ') || (keyCode == KeyboardListener.KEY_ENTER)) {
                if (enabled && (getAction() != null)) {
                    listener.onClick(instance);
                    setStyleName(getBaseStyleName() + "-focused");
                }
            }
        }

        public void onKeyUp(Widget sender, char keyCode, int modifiers) {
            if (enabled) {
                setStyleName(getBaseStyleName() + "-focused");
            }
        }

        public void onKeyDown(Widget sender, char keyCode, int modifiers) {
            if (enabled) {
                setStyleName(getBaseStyleName() + "-pressed");
            }
        }
    });
    this.initWidget(this.softBase);
    this.setStyleName(this.baseStyleName);
    this.setEnabled(true);
}