2 * This file is part of NixNote/NeighborNote
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 //**********************************************
23 //**********************************************
24 //* Create or edit a tag
25 //**********************************************
26 //**********************************************
28 import java.util.List;
30 import com.evernote.edam.type.Tag;
31 import com.trolltech.qt.gui.QCheckBox;
32 import com.trolltech.qt.gui.QDialog;
33 import com.trolltech.qt.gui.QGridLayout;
34 import com.trolltech.qt.gui.QIcon;
35 import com.trolltech.qt.gui.QLabel;
36 import com.trolltech.qt.gui.QLineEdit;
37 import com.trolltech.qt.gui.QPushButton;
39 public class TagEdit extends QDialog {
40 private boolean okPressed;
41 private final QLineEdit tag;
43 private final QCheckBox useParentTag;
44 List<Tag> currentTags;
45 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
50 setWindowTitle(tr("Add Tag"));
51 QGridLayout grid = new QGridLayout();
52 setWindowIcon(new QIcon(iconPath+"tag.png"));
55 QGridLayout textGrid = new QGridLayout();
56 tag = new QLineEdit();
57 textGrid.addWidget(new QLabel(tr("Tag Name")), 1,1);
58 textGrid.addWidget(tag, 1, 2);
60 textGrid.setContentsMargins(10, 10,-10, -10);
61 grid.addLayout(textGrid,1,1);
63 useParentTag = new QCheckBox();
64 useParentTag.setVisible(false);
65 useParentTag.setChecked(false);
66 grid.addWidget(useParentTag,2,1);
68 QGridLayout buttonGrid = new QGridLayout();
69 ok = new QPushButton(tr("OK"));
70 ok.clicked.connect(this, "okButtonPressed()");
72 QPushButton cancel = new QPushButton(tr("Cancel"));
73 cancel.clicked.connect(this, "cancelButtonPressed()");
74 tag.textChanged.connect(this, "textChanged()");
75 buttonGrid.addWidget(ok, 3, 1);
76 buttonGrid.addWidget(cancel, 3,2);
77 grid.addLayout(buttonGrid,3,1);
80 // The OK button was pressed
81 @SuppressWarnings("unused")
82 private void okButtonPressed() {
87 // The CANCEL button was pressed
88 @SuppressWarnings("unused")
89 private void cancelButtonPressed() {
94 // Get the name from the field
95 public String getTag() {
100 public void setTag(String name) {
105 public void setParentTag(String name) {
106 useParentTag.setText(tr("Create as child of \"") +name +"\"");
107 useParentTag.setVisible(true);
108 useParentTag.setChecked(true);
110 public QCheckBox getParentTag() {
114 // Check if the OK button was pressed
115 public boolean okPressed() {
119 // Set the window title
120 public void setTitle(String s) {
123 // List of existing tags
124 public void setTagList(List<Tag> t) {
127 // Watch what text is being entered
128 @SuppressWarnings("unused")
129 private void textChanged() {
130 if (tag.text().equals("")) {
131 ok.setEnabled(false);
134 if (currentTags == null) {
135 ok.setEnabled(false);
138 for (int i=0; i<currentTags.size(); i++) {
139 String s = currentTags.get(i).getName();
140 if (s.equalsIgnoreCase(tag.text())) {
141 ok.setEnabled(false);