OSDN Git Service

Add SpellCheck.java
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / SavedSearchEdit.java
1 /*
2  * This file is part of NeverNote 
3  * Copyright 2009 Randy Baumgarte
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
8  * Software distributed under the License is distributed
9  * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
10  * express or implied. See the GPL for the specific language
11  * governing rights and limitations.
12  *
13  * You should have received a copy of the GPL along with this
14  * program. If not, go to http://www.gnu.org/licenses/gpl.html
15  * or write to the Free Software Foundation, Inc.,
16  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17  *
18 */
19
20 package cx.fbn.nevernote.dialog;
21
22 import java.util.List;
23
24 import com.evernote.edam.type.SavedSearch;
25 import com.trolltech.qt.gui.QDialog;
26 import com.trolltech.qt.gui.QGridLayout;
27 import com.trolltech.qt.gui.QLabel;
28 import com.trolltech.qt.gui.QLineEdit;
29 import com.trolltech.qt.gui.QPushButton;
30
31 public class SavedSearchEdit extends QDialog {
32         private boolean                 okPressed;
33         private final QLineEdit searchName;
34         private final QLineEdit query;
35         QPushButton                     ok;
36         List<SavedSearch>               currentSearches;
37         
38         
39         // Constructor
40         public SavedSearchEdit() {
41                 okPressed = false;
42                 setWindowTitle(tr("Add a search"));
43                 QGridLayout grid = new QGridLayout();
44                 setLayout(grid);
45                 
46                 QGridLayout textLayout = new QGridLayout();
47                 searchName = new QLineEdit();
48                 textLayout.addWidget(new QLabel(tr("Name")), 1,1);
49                 textLayout.addWidget(searchName, 1, 2);
50                 query = new QLineEdit();
51                 textLayout.addWidget(new QLabel(tr("String")), 2,1);
52                 textLayout.addWidget(query, 2, 2);
53                 textLayout.setContentsMargins(10, 10,-10, -10);
54                 grid.addLayout(textLayout, 1, 1);
55                 
56                 QGridLayout buttonLayout = new QGridLayout();
57                 ok = new QPushButton(tr("OK"));
58                 ok.clicked.connect(this, "okButtonPressed()");
59                 ok.setEnabled(false);
60                 QPushButton cancel = new QPushButton(tr("Cancel"));
61                 cancel.clicked.connect(this, "cancelButtonPressed()");
62                 searchName.textChanged.connect(this, "textChanged()");
63                 query.textChanged.connect(this, "textChanged()");
64                 buttonLayout.addWidget(ok, 1, 1);
65                 buttonLayout.addWidget(cancel, 1,2);
66                 grid.addLayout(buttonLayout,2,1);
67         }
68         
69         // The OK button was pressed
70         @SuppressWarnings("unused")
71         private void okButtonPressed() {
72                 okPressed = true;
73                 close();
74         }
75         
76         // The CANCEL button was pressed
77         @SuppressWarnings("unused")
78         private void cancelButtonPressed() {
79                 okPressed = false;
80                 close();
81         }
82         
83         // Get the name from the field
84         public String getName() {
85                 return searchName.text().trim();
86         }
87         
88         // Set the tag name
89         public void setName(String name) {
90                 searchName.setText(name);
91         }
92         // get the query
93         public String getQuery() {
94                 return query.text().trim();
95         }
96         // Set the query
97         public void setQuery(String q) {
98                 query.setText(q);
99         }
100         // Check if the OK button was pressed
101         public boolean okPressed() {
102                 return okPressed;
103         }
104         
105         // Set the window title
106         public void setTitle(String s) {
107                 setWindowTitle(s);
108         }
109         // List of existing tags
110         public void setSearchList(List<SavedSearch> t) {
111                 currentSearches = t;
112         }
113         // Watch what text is being entered
114         @SuppressWarnings("unused")
115         private void textChanged() {
116                 if (searchName.text().trim().equals("")) {
117                         ok.setEnabled(false);
118                         return;
119                 }
120                 if (currentSearches == null) {
121                         ok.setEnabled(false);
122                         return;
123                 }
124                 if (query.text().trim().equals("")) {
125                         ok.setEnabled(false);
126                         return;
127                 }
128 /*              for (int i=0; i<currentSearches.size(); i++) {
129                         String s = currentSearches.get(i).getName();
130                         if (s.equalsIgnoreCase(searchName.text())) {
131                                 ok.setEnabled(false);
132                                 return;
133                         }
134                 } */
135                 ok.setEnabled(true);
136         }
137         // Watch what text is being entered
138 }