2 * This file is part of NeverNote
3 * Copyright 2009 Randy Baumgarte
5 * This file may be licensed under the terms of of the
6 * GNU General Public License Version 2 (the ``GPL'').
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.
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.
20 package cx.fbn.nevernote.dialog;
22 import java.util.List;
24 import com.evernote.edam.type.Tag;
25 import com.trolltech.qt.gui.QDialog;
26 import com.trolltech.qt.gui.QGridLayout;
27 import com.trolltech.qt.gui.QIcon;
28 import com.trolltech.qt.gui.QLabel;
29 import com.trolltech.qt.gui.QLineEdit;
30 import com.trolltech.qt.gui.QPushButton;
32 public class TagEdit extends QDialog {
33 private boolean okPressed;
34 private final QLineEdit tag;
36 List<Tag> currentTags;
37 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
42 setWindowTitle(tr("Add Tag"));
43 QGridLayout grid = new QGridLayout();
44 setWindowIcon(new QIcon(iconPath+"tag.png"));
47 QGridLayout textGrid = new QGridLayout();
48 tag = new QLineEdit();
49 textGrid.addWidget(new QLabel(tr("Tag Name")), 1,1);
50 textGrid.addWidget(tag, 1, 2);
51 textGrid.setContentsMargins(10, 10,-10, -10);
52 grid.addLayout(textGrid,1,1);
54 QGridLayout buttonGrid = new QGridLayout();
55 ok = new QPushButton(tr("OK"));
56 ok.clicked.connect(this, "okButtonPressed()");
58 QPushButton cancel = new QPushButton(tr("Cancel"));
59 cancel.clicked.connect(this, "cancelButtonPressed()");
60 tag.textChanged.connect(this, "textChanged()");
61 buttonGrid.addWidget(ok, 3, 1);
62 buttonGrid.addWidget(cancel, 3,2);
63 grid.addLayout(buttonGrid,2,1);
66 // The OK button was pressed
67 @SuppressWarnings("unused")
68 private void okButtonPressed() {
73 // The CANCEL button was pressed
74 @SuppressWarnings("unused")
75 private void cancelButtonPressed() {
80 // Get the name from the field
81 public String getTag() {
86 public void setTag(String name) {
90 // Check if the OK button was pressed
91 public boolean okPressed() {
95 // Set the window title
96 public void setTitle(String s) {
99 // List of existing tags
100 public void setTagList(List<Tag> t) {
103 // Watch what text is being entered
104 @SuppressWarnings("unused")
105 private void textChanged() {
106 if (tag.text().equals("")) {
107 ok.setEnabled(false);
110 if (currentTags == null) {
111 ok.setEnabled(false);
114 for (int i=0; i<currentTags.size(); i++) {
115 String s = currentTags.get(i).getName();
116 if (s.equalsIgnoreCase(tag.text())) {
117 ok.setEnabled(false);