OSDN Git Service

Add the ability to add & remove notebook stacks.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / StackNotebook.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.trolltech.qt.gui.QComboBox;
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.QPushButton;
29
30 public class StackNotebook extends QDialog {
31         private boolean                 okPressed;
32         private final QComboBox stack;
33         QPushButton                     ok;
34         List<String>                    currentStacks;
35         
36         // Constructor
37         public StackNotebook() {
38                 okPressed = false;
39                 setWindowTitle(tr("Stack Notebook"));
40                 QGridLayout grid = new QGridLayout();
41                 setLayout(grid);
42                 
43                 QGridLayout textGrid = new QGridLayout();
44                 stack = new QComboBox();
45                 stack.setEditable(true);
46                 textGrid.addWidget(new QLabel(tr("Stack Name")), 1,1);
47                 textGrid.addWidget(stack, 1, 2);
48                 textGrid.setContentsMargins(10, 10,-10, -10);
49                 grid.addLayout(textGrid,1,1);
50                 
51                 QGridLayout buttonGrid = new QGridLayout();
52                 ok = new QPushButton(tr("OK"));
53                 ok.clicked.connect(this, "okButtonPressed()");
54                 ok.setEnabled(true);
55                 QPushButton cancel = new QPushButton(tr("Cancel"));
56                 cancel.clicked.connect(this, "cancelButtonPressed()");
57                 stack.currentStringChanged.connect(this, "textChanged(String)");
58                 buttonGrid.addWidget(ok, 3, 1);
59                 buttonGrid.addWidget(cancel, 3,2);
60                 grid.addLayout(buttonGrid,2,1);
61         }
62         
63         // The OK button was pressed
64         @SuppressWarnings("unused")
65         private void okButtonPressed() {
66                 okPressed = true;
67                 close();
68         }
69         
70         // The CANCEL button was pressed
71         @SuppressWarnings("unused")
72         private void cancelButtonPressed() {
73                 okPressed = false;
74                 close();
75         }
76         
77         // Get the name from the field
78         public String getStackName() {
79                 return stack.currentText();
80         }
81         
82         public void setStackNames(List<String> names) {
83                 currentStacks = names;
84                 stack.clear();
85                 for (int i=0; i<names.size(); i++) {
86                         stack.addItem(names.get(i));
87                 }
88         }
89         
90         // Set the tag name
91         public void setStackName(String name) {
92                 stack.setEditText(name);
93         }
94         
95         // Check if the OK button was pressed
96         public boolean okPressed() {
97                 return okPressed;
98         }
99         
100         // Set the window title
101         public void setTitle(String s) {
102                 setWindowTitle(s);
103         }
104         // List of existing tags
105         public void setTagList(List<String> t) {
106                 currentStacks = t;
107         }
108         // Watch what text is being entered
109         @SuppressWarnings("unused")
110         private void textChanged(String text) {
111                 ok.setEnabled(true);
112         }
113 }