2 * This file is part of NeverNote
\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 import java.util.ArrayList;
\r
23 import java.util.List;
\r
25 import com.evernote.edam.type.Tag;
\r
26 import com.trolltech.qt.gui.QAbstractItemView;
\r
27 import com.trolltech.qt.gui.QDialog;
\r
28 import com.trolltech.qt.gui.QHBoxLayout;
\r
29 import com.trolltech.qt.gui.QIcon;
\r
30 import com.trolltech.qt.gui.QLineEdit;
\r
31 import com.trolltech.qt.gui.QListWidget;
\r
32 import com.trolltech.qt.gui.QListWidgetItem;
\r
33 import com.trolltech.qt.gui.QPushButton;
\r
34 import com.trolltech.qt.gui.QVBoxLayout;
\r
36 public class TagAssign extends QDialog {
\r
37 private final QListWidget tagList;
\r
38 private final QPushButton okButton;
\r
39 private final QPushButton cancelButton;
\r
40 private final QLineEdit newTag;
\r
41 private final QPushButton newTagButton;
\r
42 private boolean okClicked;
\r
43 private final List<String> tags;
\r
44 private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
\r
46 public TagAssign(List<Tag> allTags, List<String> selectedTags) {
\r
48 tags = new ArrayList<String>();
\r
49 setWindowIcon(new QIcon(iconPath+"tag.png"));
\r
51 tagList = new QListWidget();
\r
52 tagList.setSortingEnabled(true);
\r
53 tagList.setSelectionMode(QAbstractItemView.SelectionMode.MultiSelection);
\r
55 newTag = new QLineEdit();
\r
56 newTag.textChanged.connect(this, "newTagTextChanged()");
\r
57 newTagButton = new QPushButton(tr("Add"));
\r
58 newTagButton.setEnabled(false);
\r
59 newTagButton.clicked.connect(this, "addTag()");
\r
61 QHBoxLayout addLayout = new QHBoxLayout();
\r
62 addLayout.addWidget(newTag);
\r
63 addLayout.setStretch(0, 10);
\r
64 addLayout.addWidget(newTagButton);
\r
66 okButton = new QPushButton();
\r
67 okButton.setText(tr("OK"));
\r
68 okButton.pressed.connect(this, "onClicked()");
\r
70 cancelButton = new QPushButton();
\r
71 cancelButton.setText(tr("Cancel"));
\r
72 cancelButton.pressed.connect(this, "onCancel()");
\r
74 QHBoxLayout horizontalLayout = new QHBoxLayout();
\r
75 horizontalLayout.addWidget(tagList);
\r
77 QHBoxLayout buttonLayout = new QHBoxLayout();
\r
78 buttonLayout.addStretch(1);
\r
79 buttonLayout.addWidget(okButton);
\r
80 buttonLayout.addWidget(cancelButton);
\r
81 setWindowTitle(tr("Note Tags"));
\r
83 QVBoxLayout mainLayout = new QVBoxLayout();
\r
84 mainLayout.addLayout(horizontalLayout);
\r
85 mainLayout.addLayout(addLayout);
\r
86 //mainLayout.addStretch(1);
\r
87 mainLayout.addSpacing(1);
\r
88 mainLayout.addLayout(buttonLayout);
\r
89 setLayout(mainLayout);
\r
91 if (allTags != null) {
\r
92 for (int i=0; i<allTags.size(); i++) {
\r
93 tags.add(allTags.get(i).getName());
\r
94 // tagList.addItem(allTags.get(i).getName());
\r
95 QListWidgetItem item = new QListWidgetItem(allTags.get(i).getName());
\r
96 tagList.addItem(item);
\r
97 if (selectedTags != null) {
\r
98 for (int j=0; j<selectedTags.size(); j++) {
\r
99 String name = selectedTags.get(j);
\r
100 if (name.equals(item.text())) {
\r
101 item.setSelected(true);
\r
102 j=selectedTags.size()+1;
\r
112 @SuppressWarnings("unused")
\r
113 private void onClicked() {
\r
118 @SuppressWarnings("unused")
\r
119 private void onCancel() {
\r
124 public boolean okClicked() {
\r
128 @SuppressWarnings("unused")
\r
129 private void newTagTextChanged() {
\r
130 if (newTag.text().equals("")) {
\r
131 newTagButton.setEnabled(false);
\r
134 newTagButton.setEnabled(true);
\r
135 for (int i=0; i<tags.size(); i++) {
\r
136 if (tags.get(i).trim().equalsIgnoreCase(newTag.text().trim())) {
\r
137 newTagButton.setEnabled(false);
\r
143 @SuppressWarnings("unused")
\r
144 private void addTag() {
\r
145 String tag = newTag.text().trim();
\r
146 tagList.addItem(tag);
\r
147 newTag.setText("");
\r
148 newTagButton.setEnabled(false);
\r
150 for (int i=0; i<tagList.count(); i++) {
\r
151 QListWidgetItem item = tagList.item(i);
\r
152 if (item.text().equals(tag)) {
\r
153 item.setSelected(true);
\r
160 public QListWidget getTagList() {
\r