/**
* -----------------------------------------------------------------------------------------------
* File: InputBox.java
*
* Copyright (c) 2007 by Keymind Computing as.
* All rights reserved.
*
* This file is subject to the terms and conditions of the Apache Licence 2.0.
* See the file LICENCE in the main directory of the Keywatch distribution for more details.
*
* Revision History:
* $URL: http://keywatch.googlecode.com/svn/trunk/src/server/gwtgui/src/keymind/keywatch/gui/client/desktop/InputBox.java $
* $Date: 2009-09-17 02:14:51 -0700 (Thu, 17 Sep 2009) $, $Rev: $
* -----------------------------------------------------------------------------------------------
*/
package keymind.keywatch.gui.client.desktop;
import com.google.gwt.event.dom.client.ClickEvent;
import com.google.gwt.event.dom.client.ClickHandler;
import com.google.gwt.user.client.ui.*;
import keymind.keywatch.gui.client.util.Constants;
/**
* A dialog box for getting an input string from the user. This is used rather than
* Window.alert(...) because the alert(...) causes a script warning on some browser,
* and the presentation is not consistent across platforms.
*/
public class InputBox extends DialogBox implements ClickHandler, Constants
{
private TextBox txtInput;
private Label lblInput;
private Button btnOK;
private Button btnCancel;
private boolean okClicked;
/**
* C'tor
*
* @param label Input label text
*/
public InputBox(String title, String label)
{
setText(title);
VerticalPanel form = new VerticalPanel();
// Label row
HorizontalPanel topPanel = new HorizontalPanel();
lblInput = new Label(label);
Image img = GUICtrl.getCoreImageBundle().question().createImage();
topPanel.add(img);
VerticalPanel controlPanel = new VerticalPanel();
topPanel.add(controlPanel);
controlPanel.add(lblInput);
controlPanel.setCellWidth(lblInput, MAX_PERCENT);
form.add(topPanel);
// Input row
txtInput = new TextBox();
controlPanel.add(txtInput);
// Button row
FlowPanel dockPanel = new FlowPanel();
btnOK = new Button("OK", this);
btnOK.setWidth("80px");
btnCancel = new Button("Cancel", this);
btnCancel.setWidth("80px");
dockPanel.add(btnOK);
dockPanel.add(btnCancel);
controlPanel.add(dockPanel);
// Set dialog widget and styling
form.setStyleName("kwDialog");
form.addStyleName("kwInputBox");
txtInput.setFocus(true);
setWidget(form);
}
/**
* Returns the text input
*/
public String getInputText()
{
return txtInput.getText().trim();
}
/**
* Set input text
*/
public void setInputText(String name)
{
if(name != null)
{
txtInput.setText(name);
}
}
/**
* A button has been clicked
*
* @param evt ClickEvent
*/
public void onClick(ClickEvent evt)
{
okClicked = (evt.getSource() == btnOK);
hide();
}
/**
* Returns true if the OK button was clicked
*/
public boolean isOkClicked()
{
return okClicked;
}
}
|