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  import org.vectomatic.common.model.FloatAttributeValue;
24  
25  import com.google.gwt.user.client.ui.Button;
26  import com.google.gwt.user.client.ui.ClickListener;
27  import com.google.gwt.user.client.ui.DialogBox;
28  import com.google.gwt.user.client.ui.FlexTable;
29  import com.google.gwt.user.client.ui.FlowPanel;
30  import com.google.gwt.user.client.ui.HasHorizontalAlignment;
31  import com.google.gwt.user.client.ui.HasVerticalAlignment;
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 specify a custom line width
37   */
38  public class LineWidthEditor extends DialogBox {
39  	private LineWidthController _controller;
40  	private Spinner _lineWidthSpinner;
41  	
42  	public LineWidthEditor(LineWidthController controller) {
43  		super(false, true);
44  		_controller = controller;
45  		
46  		UIConstants constants = RepApplication.app._constants;
47  		setText(constants.lineWidthEditor());
48  
49  		_lineWidthSpinner = new Spinner(1, 10, 5);
50  		Button okButton = new Button(constants.okButton());
51  		okButton.setWidth("150px");
52  		okButton.addClickListener(new ClickListener() {
53  			public void onClick(Widget sender) {
54  				hide();
55  				try {
56  					_controller.setLineWidth(new FloatAttributeValue(_lineWidthSpinner.getValue()));
57  				} catch(NumberFormatException e) {
58  				}
59  			}				
60  		});
61  		Button cancelButton = new Button(constants.cancelButton());
62  		cancelButton.setWidth("150px");
63  		cancelButton.addClickListener(new ClickListener() {
64  			public void onClick(Widget sender) {
65  				hide();
66  			}				
67  		});
68  		FlexTable layoutTable = new FlexTable();
69  		FlexCellFormatter cellFormatter = layoutTable.getFlexCellFormatter();
70  		layoutTable.setWidget(0, 0, _lineWidthSpinner);
71  		FlowPanel flowPanel = new FlowPanel();
72  		flowPanel.add(cancelButton);
73  		flowPanel.add(okButton);
74  		layoutTable.setWidget(1, 0, flowPanel);
75  		cellFormatter.setAlignment(1, 0, HasHorizontalAlignment.ALIGN_RIGHT, HasVerticalAlignment.ALIGN_MIDDLE);
76  		setWidget(layoutTable);
77  	}
78  	
79  	@Override
80  	public void show() {
81  		FloatAttributeValue lineWidth = _controller.getLineWidth();
82  		_lineWidthSpinner.setValue(lineWidth == null ? 5 : (int)lineWidth.getValue());
83  		super.show();
84  	}
85  
86  }