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.controller;
19  
20  import org.vectomatic.client.UIConstants;
21  import org.vectomatic.client.rep.RepApplication;
22  import org.vectomatic.client.rep.view.Spinner;
23  
24  import com.google.gwt.user.client.ui.Button;
25  import com.google.gwt.user.client.ui.ClickListener;
26  import com.google.gwt.user.client.ui.DialogBox;
27  import com.google.gwt.user.client.ui.FlexTable;
28  import com.google.gwt.user.client.ui.FlowPanel;
29  import com.google.gwt.user.client.ui.HasHorizontalAlignment;
30  import com.google.gwt.user.client.ui.HasVerticalAlignment;
31  import com.google.gwt.user.client.ui.Label;
32  import com.google.gwt.user.client.ui.Widget;
33  import com.google.gwt.user.client.ui.FlexTable.FlexCellFormatter;
34  
35  /**
36   * Widget class to enter drawing dimensions
37   */
38  public class ResizeDrawingPanel extends DialogBox {
39  	private Spinner _widthSpinner;
40  	private Spinner _heightSpinner;
41  	
42  	public ResizeDrawingPanel(final ResizeController resizeController) {
43  		super(false, true);
44  		UIConstants constants = RepApplication.app._constants;
45  		setText(constants.dimensionsPanel());
46  		Label widthLabel = new Label(constants.widthLabel());
47  		_widthSpinner = new Spinner(1, 1024, 100);
48  		Label heightLabel = new Label(constants.heightLabel());
49  		_heightSpinner = new Spinner(1, 1024, 100);
50  		FlexTable contentTable = new FlexTable();
51  		contentTable.setWidget(0, 0, widthLabel);
52  		contentTable.setWidget(0, 1, _widthSpinner);
53  		contentTable.setWidget(1, 0, heightLabel);
54  		contentTable.setWidget(1, 1, _heightSpinner);
55  		
56  		Button okButton = new Button(constants.okButton());
57  		okButton.setWidth("150px");
58  		okButton.addClickListener(new ClickListener() {
59  			public void onClick(Widget sender) {
60  				resizeController.resize(_widthSpinner.getValue(), _heightSpinner.getValue());
61  				hide();
62  			}				
63  		});
64  		Button cancelButton = new Button(constants.cancelButton());
65  		cancelButton.setWidth("150px");
66  		cancelButton.addClickListener(new ClickListener() {
67  			public void onClick(Widget sender) {
68  				hide();
69  			}				
70  		});
71  		FlexTable layoutTable = new FlexTable();
72  		FlexCellFormatter cellFormatter = layoutTable.getFlexCellFormatter();
73  		layoutTable.setWidget(0, 0, contentTable);
74  		FlowPanel flowPanel = new FlowPanel();
75  		flowPanel.add(cancelButton);
76  		flowPanel.add(okButton);
77  		layoutTable.setWidget(1, 0, flowPanel);
78  		cellFormatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
79  		setWidget(layoutTable);
80  	}
81  
82  	public void show(int width, int height) {
83  		_widthSpinner.setValue(width);
84  		_heightSpinner.setValue(height);
85  		show();
86  	}
87  }