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.QLabel;
28 import com.trolltech.qt.gui.QLineEdit;
29 import com.trolltech.qt.gui.QPushButton;
31 public class TagEdit extends QDialog {
32 private boolean okPressed;
33 private final QLineEdit tag;
35 List<Tag> currentTags;
41 setWindowTitle("Add Tag");
42 QGridLayout grid = new QGridLayout();
45 QGridLayout textGrid = new QGridLayout();
46 tag = new QLineEdit();
47 textGrid.addWidget(new QLabel("Tag Name"), 1,1);
48 textGrid.addWidget(tag, 1, 2);
49 textGrid.setContentsMargins(10, 10,-10, -10);
50 grid.addLayout(textGrid,1,1);
52 QGridLayout buttonGrid = new QGridLayout();
53 ok = new QPushButton("OK");
54 ok.clicked.connect(this, "okButtonPressed()");
56 QPushButton cancel = new QPushButton("Cancel");
57 cancel.clicked.connect(this, "cancelButtonPressed()");
58 tag.textChanged.connect(this, "textChanged()");
59 buttonGrid.addWidget(ok, 3, 1);
60 buttonGrid.addWidget(cancel, 3,2);
61 grid.addLayout(buttonGrid,2,1);
64 // The OK button was pressed
65 @SuppressWarnings("unused")
66 private void okButtonPressed() {
71 // The CANCEL button was pressed
72 @SuppressWarnings("unused")
73 private void cancelButtonPressed() {
78 // Get the name from the field
79 public String getTag() {
84 public void setTag(String name) {
88 // Check if the OK button was pressed
89 public boolean okPressed() {
93 // Set the window title
94 public void setTitle(String s) {
97 // List of existing tags
98 public void setTagList(List<Tag> t) {
101 // Watch what text is being entered
102 @SuppressWarnings("unused")
103 private void textChanged() {
104 if (tag.text().equals("")) {
105 ok.setEnabled(false);
108 if (currentTags == null) {
109 ok.setEnabled(false);
112 for (int i=0; i<currentTags.size(); i++) {
113 String s = currentTags.get(i).getName();
114 if (s.equalsIgnoreCase(tag.text())) {
115 ok.setEnabled(false);