OSDN Git Service

Change generation of files/paths in images dir to use FileManager
[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.QLabel;
28 import com.trolltech.qt.gui.QLineEdit;
29 import com.trolltech.qt.gui.QPushButton;
30
31 public class TagEdit extends QDialog {
32         private boolean         okPressed;
33         private final QLineEdit tag;
34         QPushButton ok;
35         List<Tag>               currentTags;
36         
37         
38         // Constructor
39         public TagEdit() {
40                 okPressed = false;
41                 setWindowTitle("Add Tag");
42                 QGridLayout grid = new QGridLayout();
43                 setLayout(grid);
44                 
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);
51                 
52                 QGridLayout buttonGrid = new QGridLayout();
53                 ok = new QPushButton("OK");
54                 ok.clicked.connect(this, "okButtonPressed()");
55                 ok.setEnabled(false);
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);
62         }
63         
64         // The OK button was pressed
65         @SuppressWarnings("unused")
66         private void okButtonPressed() {
67                 okPressed = true;
68                 close();
69         }
70         
71         // The CANCEL button was pressed
72         @SuppressWarnings("unused")
73         private void cancelButtonPressed() {
74                 okPressed = false;
75                 close();
76         }
77         
78         // Get the name from the field
79         public String getTag() {
80                 return tag.text();
81         }
82         
83         // Set the tag name
84         public void setTag(String name) {
85                 tag.setText(name);
86         }
87         
88         // Check if the OK button was pressed
89         public boolean okPressed() {
90                 return okPressed;
91         }
92         
93         // Set the window title
94         public void setTitle(String s) {
95                 setWindowTitle(s);
96         }
97         // List of existing tags
98         public void setTagList(List<Tag> t) {
99                 currentTags = t;
100         }
101         // Watch what text is being entered
102         @SuppressWarnings("unused")
103         private void textChanged() {
104                 if (tag.text().equals("")) {
105                         ok.setEnabled(false);
106                         return;
107                 }
108                 if (currentTags == null) {
109                         ok.setEnabled(false);
110                         return;
111                 }
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);
116                                 return;
117                         }
118                 }
119                 ok.setEnabled(true);
120         }
121 }