OSDN Git Service

Add logic to display stacks in notebook tree
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / TagEdit.java
1 /*
2  * This file is part of NeverNote 
3  * Copyright 2009 Randy Baumgarte
4  * 
5  * This file may be licensed under the terms of of the
6  * GNU General Public License Version 2 (the ``GPL'').
7  *
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.
12  *
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.
17  *
18 */
19
20 package cx.fbn.nevernote.dialog;
21
22 import java.util.List;
23
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;
31
32 public class TagEdit extends QDialog {
33         private boolean         okPressed;
34         private final QLineEdit tag;
35         QPushButton ok;
36         List<Tag>               currentTags;
37         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
38         
39         // Constructor
40         public TagEdit() {
41                 okPressed = false;
42                 setWindowTitle(tr("Add Tag"));
43                 QGridLayout grid = new QGridLayout();
44                 setWindowIcon(new QIcon(iconPath+"tag.png"));
45                 setLayout(grid);
46                 
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);
53                 
54                 QGridLayout buttonGrid = new QGridLayout();
55                 ok = new QPushButton(tr("OK"));
56                 ok.clicked.connect(this, "okButtonPressed()");
57                 ok.setEnabled(false);
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);
64         }
65         
66         // The OK button was pressed
67         @SuppressWarnings("unused")
68         private void okButtonPressed() {
69                 okPressed = true;
70                 close();
71         }
72         
73         // The CANCEL button was pressed
74         @SuppressWarnings("unused")
75         private void cancelButtonPressed() {
76                 okPressed = false;
77                 close();
78         }
79         
80         // Get the name from the field
81         public String getTag() {
82                 return tag.text();
83         }
84         
85         // Set the tag name
86         public void setTag(String name) {
87                 tag.setText(name);
88         }
89         
90         // Check if the OK button was pressed
91         public boolean okPressed() {
92                 return okPressed;
93         }
94         
95         // Set the window title
96         public void setTitle(String s) {
97                 setWindowTitle(s);
98         }
99         // List of existing tags
100         public void setTagList(List<Tag> t) {
101                 currentTags = t;
102         }
103         // Watch what text is being entered
104         @SuppressWarnings("unused")
105         private void textChanged() {
106                 if (tag.text().equals("")) {
107                         ok.setEnabled(false);
108                         return;
109                 }
110                 if (currentTags == null) {
111                         ok.setEnabled(false);
112                         return;
113                 }
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);
118                                 return;
119                         }
120                 }
121                 ok.setEnabled(true);
122         }
123 }