OSDN Git Service

Add notebook specific sorting and alter some NeverNote labels to say NixNote.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / InsertLinkDialog.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 used when a user wants\r
25 //* to add a HTML link.\r
26 //**********************************************\r
27 //**********************************************\r
28 \r
29 import com.trolltech.qt.core.Qt;\r
30 import com.trolltech.qt.gui.QDialog;\r
31 import com.trolltech.qt.gui.QGridLayout;\r
32 import com.trolltech.qt.gui.QIcon;\r
33 import com.trolltech.qt.gui.QLabel;\r
34 import com.trolltech.qt.gui.QLineEdit;\r
35 import com.trolltech.qt.gui.QPushButton;\r
36 \r
37 public class InsertLinkDialog extends QDialog {\r
38 \r
39         private boolean         okPressed;\r
40         private final QLineEdit url;\r
41         private final QPushButton ok;\r
42         private String          urlText;\r
43         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
44         private final boolean insertHyperlink;\r
45         \r
46         \r
47         // Constructor\r
48         public InsertLinkDialog(boolean insert) {\r
49                 okPressed = false;\r
50                 setWindowTitle(tr("Insert Link"));\r
51                 setWindowIcon(new QIcon(iconPath+"link.png"));\r
52                 QGridLayout grid = new QGridLayout();\r
53                 QGridLayout input = new QGridLayout();\r
54                 QGridLayout button = new QGridLayout();\r
55                 setLayout(grid);\r
56                 insertHyperlink = insert;\r
57                 \r
58                 \r
59                 url = new QLineEdit("");\r
60                 \r
61                 input.addWidget(new QLabel(tr("Url")), 1,1);\r
62                 input.addWidget(url, 1, 2);\r
63                 input.setContentsMargins(10, 10,  -10, -10);\r
64                 grid.addLayout(input, 1,1);\r
65                         \r
66                 ok = new QPushButton(tr("OK"));\r
67                 ok.clicked.connect(this, "accept()");\r
68                 ok.setEnabled(false);\r
69                 \r
70                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
71                 cancel.clicked.connect(this, "reject()");\r
72                 button.addWidget(ok, 1, 1);\r
73                 button.addWidget(cancel, 1,2);\r
74                 grid.addLayout(button, 3, 1);\r
75                 url.textChanged.connect(this, "validateInput()");\r
76                 \r
77                 setAttribute(Qt.WidgetAttribute.WA_DeleteOnClose);\r
78         }\r
79         \r
80         // Get the password \r
81         public String getUrl() {\r
82                 return urlText;\r
83         }\r
84         // Set the url\r
85         public void setUrl(String u) {\r
86                 url.setText(u);\r
87         }\r
88         // Check if the OK button was pressed\r
89         public boolean okPressed() {\r
90                 return okPressed;\r
91         }\r
92         // Check that we have a valid URL\r
93         @SuppressWarnings("unused")\r
94         private void validateInput() {\r
95                 ok.setEnabled(true);\r
96                 if (url.text().trim().equals("") && insertHyperlink) \r
97                         ok.setEnabled(false);\r
98         }\r
99         \r
100         @Override\r
101         public void accept() {\r
102                 if (ok.isEnabled()) {\r
103                         okPressed = true;\r
104                         urlText = url.text();\r
105                         super.accept();\r
106                 }\r
107         }\r
108         \r
109         @Override\r
110         public void reject() {\r
111                 okPressed=false;\r
112                 super.reject();\r
113         }\r
114 }\r