2 * This file is part of NixNote
\r
3 * Copyright 2009 Randy Baumgarte
\r
5 * This file may be licensed under the terms of of the
\r
6 * GNU General Public License Version 2 (the ``GPL'').
\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
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
20 package cx.fbn.nevernote.dialog;
\r
22 //**********************************************
\r
23 //**********************************************
\r
24 //* Dialog box used to assign a tag to a note
\r
25 //**********************************************
\r
26 //**********************************************
\r
28 import java.util.ArrayList;
\r
29 import java.util.List;
\r
31 import com.evernote.edam.type.Tag;
\r
32 import com.trolltech.qt.gui.QAbstractItemView;
\r
33 import com.trolltech.qt.gui.QDialog;
\r
34 import com.trolltech.qt.gui.QHBoxLayout;
\r
35 import com.trolltech.qt.gui.QIcon;
\r
36 import com.trolltech.qt.gui.QLineEdit;
\r
37 import com.trolltech.qt.gui.QListWidget;
\r
38 import com.trolltech.qt.gui.QListWidgetItem;
\r
39 import com.trolltech.qt.gui.QPushButton;
\r
40 import com.trolltech.qt.gui.QVBoxLayout;
\r
42 public class TagAssign extends QDialog {
\r
43 private final QListWidget tagList;
\r
44 private final QPushButton okButton;
\r
45 private final QPushButton cancelButton;
\r
46 private final QLineEdit newTag;
\r
47 private final QPushButton newTagButton;
\r
48 private boolean okClicked;
\r
49 private final List<String> tags;
\r
50 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
52 public TagAssign(List<Tag> allTags, List<String> selectedTags, boolean permitNew) {
\r
54 tags = new ArrayList<String>();
\r
55 setWindowIcon(new QIcon(iconPath+"tag.png"));
\r
57 tagList = new QListWidget();
\r
58 tagList.setSortingEnabled(true);
\r
59 tagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);
\r
61 newTag = new QLineEdit();
\r
62 newTag.textChanged.connect(this, "newTagTextChanged()");
\r
63 newTagButton = new QPushButton(tr("Add"));
\r
64 newTagButton.setEnabled(false);
\r
65 newTagButton.clicked.connect(this, "addTag()");
\r
67 QHBoxLayout addLayout = new QHBoxLayout();
\r
68 addLayout.addWidget(newTag);
\r
69 addLayout.setStretch(0, 10);
\r
70 addLayout.addWidget(newTagButton);
\r
73 newTagButton.setVisible(false);
\r
74 newTag.setVisible(false);
\r
77 okButton = new QPushButton();
\r
78 okButton.setText(tr("OK"));
\r
79 okButton.pressed.connect(this, "onClicked()");
\r
81 cancelButton = new QPushButton();
\r
82 cancelButton.setText(tr("Cancel"));
\r
83 cancelButton.pressed.connect(this, "onCancel()");
\r
85 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
86 horizontalLayout.addWidget(tagList);
\r
88 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
89 buttonLayout.addStretch(1);
\r
90 buttonLayout.addWidget(okButton);
\r
91 buttonLayout.addWidget(cancelButton);
\r
92 setWindowTitle(tr("Note Tags"));
\r
94 QVBoxLayout mainLayout = new QVBoxLayout();
\r
95 mainLayout.addLayout(horizontalLayout);
\r
96 mainLayout.addLayout(addLayout);
\r
97 //mainLayout.addStretch(1);
\r
98 mainLayout.addSpacing(1);
\r
99 mainLayout.addLayout(buttonLayout);
\r
100 setLayout(mainLayout);
\r
102 if (allTags != null) {
\r
103 for (int i=0; i<allTags.size(); i++) {
\r
104 tags.add(allTags.get(i).getName());
\r
105 // tagList.addItem(allTags.get(i).getName());
\r
106 QListWidgetItem item = new QListWidgetItem(allTags.get(i).getName());
\r
107 tagList.addItem(item);
\r
108 if (selectedTags != null) {
\r
109 for (int j=0; j<selectedTags.size(); j++) {
\r
110 String name = selectedTags.get(j);
\r
111 if (name.equals(item.text())) {
\r
112 item.setSelected(true);
\r
113 j=selectedTags.size()+1;
\r
123 @SuppressWarnings("unused")
\r
124 private void onClicked() {
\r
129 @SuppressWarnings("unused")
\r
130 private void onCancel() {
\r
135 public boolean okClicked() {
\r
139 @SuppressWarnings("unused")
\r
140 private void newTagTextChanged() {
\r
141 if (newTag.text().equals("")) {
\r
142 newTagButton.setEnabled(false);
\r
145 newTagButton.setEnabled(true);
\r
146 for (int i=0; i<tags.size(); i++) {
\r
147 if (tags.get(i).trim().equalsIgnoreCase(newTag.text().trim())) {
\r
148 newTagButton.setEnabled(false);
\r
154 @SuppressWarnings("unused")
\r
155 private void addTag() {
\r
156 String tag = newTag.text().trim();
\r
157 tagList.addItem(tag);
\r
158 newTag.setText("");
\r
159 newTagButton.setEnabled(false);
\r
161 for (int i=0; i<tagList.count(); i++) {
\r
162 QListWidgetItem item = tagList.item(i);
\r
163 if (item.text().equals(tag)) {
\r
164 item.setSelected(true);
\r
171 public QListWidget getTagList() {
\r