View Javadoc

1   /**********************************************
2    * Copyright (C) 2009 Lukas Laag
3    * This file is part of Vectomatic.
4    * 
5    * Vectomatic is free software: you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation, either version 3 of the License, or
8    * (at your option) any later version.
9    * 
10   * Vectomatic is distributed in the hope that it will be useful,
11   * but WITHOUT ANY WARRANTY; without even the implied warranty of
12   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13   * GNU General Public License for more details.
14   * 
15   * You should have received a copy of the GNU General Public License
16   * along with Vectomatic.  If not, see http://www.gnu.org/licenses/
17   **********************************************/
18  package org.vectomatic.client.rep.view;
19  
20  import org.vectomatic.client.UIConstants;
21  import org.vectomatic.client.rep.RepApplication;
22  
23  import com.google.gwt.user.client.ui.Button;
24  import com.google.gwt.user.client.ui.ClickListener;
25  import com.google.gwt.user.client.ui.DialogBox;
26  import com.google.gwt.user.client.ui.FlexTable;
27  import com.google.gwt.user.client.ui.FlowPanel;
28  import com.google.gwt.user.client.ui.HasHorizontalAlignment;
29  import com.google.gwt.user.client.ui.HasVerticalAlignment;
30  import com.google.gwt.user.client.ui.Label;
31  import com.google.gwt.user.client.ui.Widget;
32  import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
33  
34  /**
35   * Class to implement a warning panel
36   */
37  public class WarningPanel extends DialogBox {
38  	private Button _warningButton;
39  	private Label _warningLabel;
40  	private ClickListener _listener;
41  	public WarningPanel() {
42  		super(false, true);
43  		UIConstants constants = RepApplication.app._constants;
44  		setText(constants.warning());
45  		_warningLabel = new Label();
46  		_warningLabel.setWidth("400px");
47  		_warningButton = new Button();
48  		_warningButton.setWidth("150px");
49  		Button cancelButton = new Button(constants.cancelButton());
50  		cancelButton.setWidth("150px");
51  		cancelButton.addClickListener(new ClickListener() {
52  			public void onClick(Widget sender) {
53  				hide();
54  			}				
55  		});
56  		FlexTable layoutTable = new FlexTable();
57  		FlexCellFormatter cellFormatter = layoutTable.getFlexCellFormatter();
58  		layoutTable.setWidget(0, 0, _warningLabel);
59  		FlowPanel flowPanel = new FlowPanel();
60  		flowPanel.add(cancelButton);
61  		flowPanel.add(_warningButton);
62  		layoutTable.setWidget(1, 0, flowPanel);
63  		cellFormatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
64  		setWidget(layoutTable);
65  	}
66  	
67  	public void show(String labelText, String buttonText, ClickListener listener) {
68  		_warningLabel.setText(labelText);
69  		_warningButton.setText(buttonText);
70  		if (_listener != listener) {
71  			_warningButton.removeClickListener(_listener);
72  			_listener = listener;
73  			_warningButton.addClickListener(listener);
74  		}
75  		show();
76  	}
77  }