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.rep.RepApplication;
21  import org.vectomatic.common.model.FloatAttributeValue;
22  
23  import com.google.gwt.user.client.ui.ClickListener;
24  import com.google.gwt.user.client.ui.Grid;
25  import com.google.gwt.user.client.ui.Label;
26  import com.google.gwt.user.client.ui.PopupPanel;
27  import com.google.gwt.user.client.ui.SourcesTableEvents;
28  import com.google.gwt.user.client.ui.TableListener;
29  import com.google.gwt.user.client.ui.Widget;
30  
31  /**
32   * Menu class to select line widths
33   */
34  public class LineWidthMenu extends PopupPanel {
35  	private LineWidthController _controller;
36  	private LineWidthEditor _editor;
37  	public LineWidthMenu(LineWidthController controller) {
38  		super(true, true);
39  		_controller = controller;
40  		_editor = new LineWidthEditor(controller);
41  		Grid grid = new Grid(6, 1);
42  		Label editLabel = new Label(RepApplication.app._constants.editLineWidth());
43  		editLabel.setStyleName("lineWidthMenuCustom");
44  		editLabel.addClickListener(new ClickListener() {
45  			public void onClick(Widget sender) {
46  			}			
47  		});
48  		final int[] lineWidths = {1, 2, 3, 5, 8};
49  		for (int i = 0; i < lineWidths.length; i++) {
50  			LineWidthWidget lineWidthWidget = new LineWidthWidget(lineWidths[i], true);
51  			grid.setWidget(i, 0, lineWidthWidget);
52  		}
53  		grid.setWidget(lineWidths.length, 0, editLabel);
54  		setWidget(grid);
55  		setStyleName("lineWidthMenu");
56  		grid.addTableListener(new TableListener() {
57  			public void onCellClicked(SourcesTableEvents sender, int row, int cell) {
58  				hide();
59  				if (row < lineWidths.length) {
60  					_controller.setLineWidth(new FloatAttributeValue(lineWidths[row]));
61  				} else {
62  					_editor.show();
63  				}
64  			}
65  		});
66  	}
67  }