OSDN Git Service

Add Linked notebooks to the ignore sync process.
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / TableDialog.java
1 /*\r
2  * This file is part of NeverNote \r
3  * Copyright 2009 Randy Baumgarte\r
4  * \r
5  * This file may be licensed under the terms of of the\r
6  * GNU General Public License Version 2 (the ``GPL'').\r
7  *\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
12  *\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
17  *\r
18 */\r
19 \r
20 package cx.fbn.nevernote.dialog;\r
21 \r
22 \r
23 import com.trolltech.qt.gui.QComboBox;\r
24 import com.trolltech.qt.gui.QDialog;\r
25 import com.trolltech.qt.gui.QGridLayout;\r
26 import com.trolltech.qt.gui.QIcon;\r
27 import com.trolltech.qt.gui.QIntValidator;\r
28 import com.trolltech.qt.gui.QLabel;\r
29 import com.trolltech.qt.gui.QLineEdit;\r
30 import com.trolltech.qt.gui.QPushButton;\r
31 import com.trolltech.qt.gui.QSpinBox;\r
32 \r
33 public class TableDialog extends QDialog {\r
34 \r
35         private boolean                         okPressed;\r
36         private final QSpinBox          rows;\r
37         private final QSpinBox          cols;\r
38         private final QLineEdit         width;\r
39         private final QPushButton       ok;\r
40         private final QLabel            error;\r
41         private final QIntValidator     widthValidator;\r
42         private final QComboBox          unit;\r
43         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
44         \r
45         // Constructor\r
46         public TableDialog() {\r
47                 okPressed = false;\r
48                 setWindowTitle(tr("Insert Table"));\r
49                 setWindowIcon(new QIcon(iconPath+"table.png"));\r
50                 QGridLayout grid = new QGridLayout();\r
51                 QGridLayout input = new QGridLayout();\r
52                 QGridLayout msgGrid = new QGridLayout();\r
53                 QGridLayout button = new QGridLayout();\r
54                 setLayout(grid);\r
55                 \r
56                 unit = new QComboBox(this);\r
57                 unit.addItem(tr("Percent"),new Boolean(true));\r
58                 unit.addItem(tr("Pixels"),new Boolean(false));\r
59                 \r
60                 \r
61                 width = new QLineEdit("80");\r
62                 widthValidator = new QIntValidator(0,100, this);\r
63                 width.setValidator(widthValidator);\r
64                 width.textChanged.connect(this, "validateWidth()");\r
65                 rows = new QSpinBox();\r
66                 cols = new QSpinBox();\r
67                 rows.setMaximum(30);\r
68                 rows.setMinimum(1);\r
69                 cols.setMaximum(30);\r
70                 cols.setMinimum(1);\r
71                 \r
72                 unit.activated.connect(this, "unitChanged()");\r
73                 \r
74                 input.addWidget(new QLabel(tr("Rows")), 1,1);\r
75                 input.addWidget(rows, 1, 2);\r
76                 input.addWidget(new QLabel(tr("Columns")), 2,1);\r
77                 input.addWidget(cols, 2, 2);\r
78                 input.addWidget(new QLabel(tr("Width")), 3,1);\r
79                 input.addWidget(width, 3, 2);\r
80                 input.addWidget(new QLabel(tr("Unit")),4,1);\r
81                 input.addWidget(unit,4,2);\r
82                 input.setContentsMargins(10, 10,  -10, -10);\r
83                 grid.addLayout(input, 1,1);\r
84                 \r
85                 error = new QLabel();\r
86                 msgGrid.addWidget(error, 1, 1);\r
87                 grid.addLayout(msgGrid, 2, 1);\r
88                 \r
89                 ok = new QPushButton(tr("OK"));\r
90                 ok.clicked.connect(this, "okButtonPressed()");\r
91                 \r
92                 QPushButton cancel = new QPushButton(tr("Cancel"));\r
93                 cancel.clicked.connect(this, "cancelButtonPressed()");\r
94                 button.addWidget(ok, 1, 1);\r
95                 button.addWidget(cancel, 1,2);\r
96                 grid.addLayout(button, 3, 1);\r
97                 \r
98 //              width.textChanged.connect(this, "validateInput()");\r
99                 \r
100         }\r
101         \r
102         // The OK button was pressed\r
103         @SuppressWarnings("unused")\r
104         private void okButtonPressed() {\r
105                 okPressed = true;\r
106                 close();\r
107         }\r
108         // The CANCEL button was pressed\r
109         @SuppressWarnings("unused")\r
110         private void cancelButtonPressed() {\r
111                 okPressed = false;\r
112                 close();\r
113         }\r
114         // Check if the OK button was pressed\r
115         public boolean okPressed() {\r
116                 return okPressed;\r
117         }\r
118         // Check if proper input was input\r
119         @SuppressWarnings("unused")\r
120         private void validateInput() {\r
121                 ok.setEnabled(false);\r
122                 \r
123                 ok.setEnabled(true);\r
124         }\r
125         \r
126         @SuppressWarnings("unused")\r
127         private void validateWidth() {\r
128                 if (width.text().trim().length() == 0) {\r
129                         ok.setEnabled(false);\r
130                 } else\r
131                         ok.setEnabled(true);\r
132         }\r
133         \r
134         @SuppressWarnings("unused")\r
135         private void unitChanged() {\r
136                 int i = unit.currentIndex();\r
137                 if ((Boolean)unit.itemData(i)) { // if 'percent'\r
138                         Integer w = new Integer(width.text());\r
139                         if (w > 100)\r
140                                 width.setText("80");\r
141                         widthValidator.setTop(100);\r
142                 } else {\r
143                         widthValidator.setTop(32767);\r
144                 }\r
145         }\r
146         \r
147         public int getRows() {\r
148                 return new Integer(rows.text());\r
149         }\r
150         public int getCols() {\r
151                 return new Integer(cols.text());\r
152         }\r
153         public int getWidth() {\r
154                 return new Integer(width.text());\r
155         }\r
156         public boolean isPercent() {\r
157                 int i = unit.currentIndex();\r
158                 return ((Boolean)unit.itemData(i)).booleanValue();\r
159         }\r
160 \r
161 }\r