OSDN Git Service

Merge Hiroshi's language changes into development branch.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / GeoDialog.java
1 /*\r
2  * This file is part of NeverNote \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 import com.trolltech.qt.gui.QDialog;\r
23 import com.trolltech.qt.gui.QDoubleValidator;\r
24 import com.trolltech.qt.gui.QDoubleValidator.Notation;\r
25 import com.trolltech.qt.gui.QGridLayout;\r
26 import com.trolltech.qt.gui.QLabel;\r
27 import com.trolltech.qt.gui.QLineEdit;\r
28 import com.trolltech.qt.gui.QPushButton;\r
29 \r
30 public class GeoDialog extends QDialog {\r
31 \r
32         private boolean         okPressed;\r
33         private final QLineEdit altitude;\r
34         private final QLineEdit latitude;\r
35         private final QLineEdit longitude;\r
36         private final QPushButton ok;\r
37         \r
38         \r
39         // Constructor\r
40         public GeoDialog() {\r
41                 okPressed = false;\r
42                 setWindowTitle(tr("NeverNote Login"));\r
43                 QGridLayout grid = new QGridLayout();\r
44                 setLayout(grid);\r
45                 QGridLayout passwordGrid = new QGridLayout();\r
46                 QGridLayout buttonGrid = new QGridLayout();\r
47                 \r
48                 \r
49                 longitude = new QLineEdit();\r
50                 QDoubleValidator longVal = new QDoubleValidator(-180.0,180.0,4,longitude);\r
51                 longVal.setNotation(Notation.StandardNotation);\r
52                 longitude.setValidator(longVal);\r
53                 \r
54                 latitude = new QLineEdit();\r
55                 QDoubleValidator latVal = new QDoubleValidator(-90.0,90.0,4,latitude);\r
56                 latVal.setNotation(Notation.StandardNotation);\r
57                 latitude.setValidator(latVal);\r
58                 \r
59                 altitude = new QLineEdit();\r
60                 QDoubleValidator altVal = new QDoubleValidator(-9999.0,9999.0,4,altitude);\r
61                 altVal.setNotation(Notation.StandardNotation);\r
62                 altitude.setValidator(altVal);\r
63 \r
64                 \r
65                 passwordGrid.addWidget(new QLabel(tr("Longitude")), 1,1);\r
66                 passwordGrid.addWidget(longitude, 1, 2);\r
67                 passwordGrid.addWidget(new QLabel(tr("Latitude")), 2,1);\r
68                 passwordGrid.addWidget(latitude, 2, 2);\r
69                 passwordGrid.addWidget(new QLabel(tr("Altitude")), 3,1);\r
70                 passwordGrid.addWidget(altitude, 3, 2);\r
71                 passwordGrid.setContentsMargins(10, 10,  -10, -10);\r
72                 grid.addLayout(passwordGrid,1,1);\r
73                 \r
74                 ok = new QPushButton(tr("OK"));\r
75                 ok.clicked.connect(this, "okButtonPressed()");\r
76                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
77                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
78                 buttonGrid.addWidget(ok, 1, 1);\r
79                 buttonGrid.addWidget(cancel, 1,2);\r
80                 grid.addLayout(buttonGrid,2,1);\r
81         }\r
82         \r
83         // The OK button was pressed\r
84         @SuppressWarnings("unused")\r
85         private void okButtonPressed() {\r
86                 okPressed = true;\r
87                 close();\r
88         }\r
89         \r
90         // The CANCEL button was pressed\r
91         @SuppressWarnings("unused")\r
92         private void cancelButtonPressed() {\r
93                 okPressed = false;\r
94                 close();\r
95         }\r
96         \r
97         // Get the longitude\r
98         public double getLongitude() {\r
99                 try {\r
100                         return new Double(longitude.text());\r
101                 } catch (java.lang.NumberFormatException e) {\r
102                         return 0.0;\r
103                 }\r
104         }\r
105         \r
106         // Get the latitude\r
107         public double getLatitude() {\r
108                 try {\r
109                         return new Double(latitude.text());\r
110                 } catch (java.lang.NumberFormatException e) {\r
111                         return 0.0;\r
112                 }\r
113         }\r
114         \r
115         // Get the altitude\r
116         public double getAltitude() {\r
117                 try {\r
118                         return new Double(altitude.text()); \r
119                 } catch (java.lang.NumberFormatException e) {\r
120                         return 0.0;\r
121                 }\r
122         }\r
123         \r
124         \r
125         public void setLongitude(double value) {\r
126                 longitude.setText(new Float(value).toString());\r
127         }\r
128 \r
129         public void setLatitude(double value) {\r
130                 latitude.setText(new Float(value).toString());\r
131         }\r
132 \r
133         public void setAltitude(double value) {\r
134                 altitude.setText(new Float(value).toString());\r
135         }\r
136 \r
137         \r
138         // Check if the OK button was pressed\r
139         public boolean okPressed() {\r
140                 return okPressed;\r
141         }\r
142 \r
143         \r
144 }\r