OSDN Git Service

Merge branch 'master' of ssh://nevernote.git.sourceforge.net/gitroot/nevernote/nevern...
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / GeoDialog.java
1 /*\r
2  * This file is part of NixNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\r
8  * Software distributed under the License is distributed\r
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
10  * express or implied. See the GPL for the specific language\r
11  * governing rights and limitations.\r
12  *\r
13  * You should have received a copy of the GPL along with this\r
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
15  * or write to the Free Software Foundation, Inc.,\r
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 //**********************************************\r
23 //**********************************************\r
24 //* This is the dialog when the user clicks\r
25 //* the geo tag for a note.\r
26 //**********************************************\r
27 //**********************************************\r
28 \r
29 import com.trolltech.qt.gui.QDialog;\r
30 import com.trolltech.qt.gui.QDoubleValidator;\r
31 import com.trolltech.qt.gui.QDoubleValidator.Notation;\r
32 import com.trolltech.qt.gui.QGridLayout;\r
33 import com.trolltech.qt.gui.QIcon;\r
34 import com.trolltech.qt.gui.QLabel;\r
35 import com.trolltech.qt.gui.QLineEdit;\r
36 import com.trolltech.qt.gui.QPushButton;\r
37 \r
38 public class GeoDialog extends QDialog {\r
39 \r
40         private boolean         okPressed;\r
41         private final QLineEdit altitude;\r
42         private final QLineEdit latitude;\r
43         private final QLineEdit longitude;\r
44         private final QPushButton ok;\r
45         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
46         \r
47         \r
48         // Constructor\r
49         public GeoDialog() {\r
50                 okPressed = false;\r
51                 setWindowTitle(tr("Geo Location"));\r
52                 setWindowIcon(new QIcon(iconPath+"globe.png"));\r
53                 QGridLayout grid = new QGridLayout();\r
54                 setLayout(grid);\r
55                 QGridLayout passwordGrid = new QGridLayout();\r
56                 QGridLayout buttonGrid = new QGridLayout();\r
57                 \r
58                 \r
59                 longitude = new QLineEdit();\r
60                 QDoubleValidator longVal = new QDoubleValidator(-180.0,180.0,4,longitude);\r
61                 longVal.setNotation(Notation.StandardNotation);\r
62                 longitude.setValidator(longVal);\r
63                 \r
64                 latitude = new QLineEdit();\r
65                 QDoubleValidator latVal = new QDoubleValidator(-90.0,90.0,4,latitude);\r
66                 latVal.setNotation(Notation.StandardNotation);\r
67                 latitude.setValidator(latVal);\r
68                 \r
69                 altitude = new QLineEdit();\r
70                 QDoubleValidator altVal = new QDoubleValidator(-9999.0,9999.0,4,altitude);\r
71                 altVal.setNotation(Notation.StandardNotation);\r
72                 altitude.setValidator(altVal);\r
73 \r
74                 \r
75                 passwordGrid.addWidget(new QLabel(tr("Longitude")), 1,1);\r
76                 passwordGrid.addWidget(longitude, 1, 2);\r
77                 passwordGrid.addWidget(new QLabel(tr("Latitude")), 2,1);\r
78                 passwordGrid.addWidget(latitude, 2, 2);\r
79                 passwordGrid.addWidget(new QLabel(tr("Altitude")), 3,1);\r
80                 passwordGrid.addWidget(altitude, 3, 2);\r
81                 passwordGrid.setContentsMargins(10, 10,  -10, -10);\r
82                 grid.addLayout(passwordGrid,1,1);\r
83                 \r
84                 ok = new QPushButton(tr("OK"));\r
85                 ok.clicked.connect(this, "okButtonPressed()");\r
86                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
87                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
88                 buttonGrid.addWidget(ok, 1, 1);\r
89                 buttonGrid.addWidget(cancel, 1,2);\r
90                 grid.addLayout(buttonGrid,2,1);\r
91         }\r
92         \r
93         // The OK button was pressed\r
94         @SuppressWarnings("unused")\r
95         private void okButtonPressed() {\r
96                 okPressed = true;\r
97                 close();\r
98         }\r
99         \r
100         // The CANCEL button was pressed\r
101         @SuppressWarnings("unused")\r
102         private void cancelButtonPressed() {\r
103                 okPressed = false;\r
104                 close();\r
105         }\r
106         \r
107         // Get the longitude\r
108         public double getLongitude() {\r
109                 try {\r
110                         return new Double(longitude.text());\r
111                 } catch (java.lang.NumberFormatException e) {\r
112                         return 0.0;\r
113                 }\r
114         }\r
115         \r
116         // Get the latitude\r
117         public double getLatitude() {\r
118                 try {\r
119                         return new Double(latitude.text());\r
120                 } catch (java.lang.NumberFormatException e) {\r
121                         return 0.0;\r
122                 }\r
123         }\r
124         \r
125         // Get the altitude\r
126         public double getAltitude() {\r
127                 try {\r
128                         return new Double(altitude.text()); \r
129                 } catch (java.lang.NumberFormatException e) {\r
130                         return 0.0;\r
131                 }\r
132         }\r
133         \r
134         \r
135         public void setLongitude(double value) {\r
136                 longitude.setText(new Float(value).toString());\r
137         }\r
138 \r
139         public void setLatitude(double value) {\r
140                 latitude.setText(new Float(value).toString());\r
141         }\r
142 \r
143         public void setAltitude(double value) {\r
144                 altitude.setText(new Float(value).toString());\r
145         }\r
146 \r
147         \r
148         // Check if the OK button was pressed\r
149         public boolean okPressed() {\r
150                 return okPressed;\r
151         }\r
152 \r
153         \r
154 }\r