OSDN Git Service

Evernote APIの帯域制限超過時にエラーメッセージを表示するようにした
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / SetIcon.java
1 /*
2  * This file is part of NixNote/NeighborNote 
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 //**********************************************
23 //**********************************************
24 //* Show the "set icon" dialog box for notebooks, tags, etc...
25 //**********************************************
26 //**********************************************
27
28
29 import com.trolltech.qt.gui.QCheckBox;
30 import com.trolltech.qt.gui.QDialog;
31 import com.trolltech.qt.gui.QFileDialog;
32 import com.trolltech.qt.gui.QFileDialog.AcceptMode;
33 import com.trolltech.qt.gui.QFileDialog.FileMode;
34 import com.trolltech.qt.gui.QGridLayout;
35 import com.trolltech.qt.gui.QIcon;
36 import com.trolltech.qt.gui.QPushButton;
37 import com.trolltech.qt.gui.QSizePolicy.Policy;
38
39 import cx.fbn.nevernote.Global;
40
41 public class SetIcon extends QDialog {
42         private boolean okPressed;
43         QPushButton     ok;
44         QPushButton             iconButton;
45         QCheckBox               useDefault;
46         QIcon                   defaultIcon;
47         boolean                 startUseDefault;
48         String                  path;
49         
50         private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
51         
52         // Constructor
53         public SetIcon(QIcon i, String path) {
54                 okPressed = false;
55                 this.path = path;
56                 setWindowTitle(tr("Set Icon"));
57                 QGridLayout grid = new QGridLayout();
58                 setWindowIcon(new QIcon(iconPath+"nevernote.png"));
59                 setLayout(grid);
60                 
61                 QGridLayout textGrid = new QGridLayout();
62                 textGrid.setContentsMargins(10, 10,-10, -10);
63                 useDefault = new QCheckBox();
64                 iconButton = new QPushButton();
65                 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
66                 iconButton.clicked.connect(this, "iconButtonPressed()");
67                 useDefault.setText(tr("Use Default"));
68                 iconButton.setIcon(i);
69                 
70                 textGrid.addWidget(iconButton,1,1);
71                 textGrid.addWidget(useDefault,2,1);
72                 useDefault.clicked.connect(this, "useDefaultIconChecked(Boolean)");
73                 grid.addLayout(textGrid,1,1);
74                 
75                 QGridLayout buttonGrid = new QGridLayout();
76                 ok = new QPushButton(tr("OK"));
77                 ok.clicked.connect(this, "okButtonPressed()");
78                 ok.setEnabled(false);
79                 QPushButton cancel = new QPushButton(tr("Cancel"));
80                 cancel.clicked.connect(this, "cancelButtonPressed()");
81                 buttonGrid.addWidget(ok, 3, 1);
82                 buttonGrid.addWidget(cancel, 3,2);
83                 grid.addLayout(buttonGrid,2,1);
84         }
85         
86         // The OK button was pressed
87         @SuppressWarnings("unused")
88         private void okButtonPressed() {
89                 okPressed = true;
90                 close();
91         }
92         
93         // The CANCEL button was pressed
94         @SuppressWarnings("unused")
95         private void cancelButtonPressed() {
96                 okPressed = false;
97                 close();
98         }
99         
100         // Check if the OK button was pressed
101         public boolean okPressed() {
102                 return okPressed;
103         }
104         
105         // Icon Button pressed
106         @SuppressWarnings("unused")
107         private void iconButtonPressed() {
108                 QFileDialog fd = new QFileDialog(this);
109                 fd.setFileMode(FileMode.ExistingFile);
110                 fd.setConfirmOverwrite(true);
111                 fd.setWindowTitle(tr("Icon"));
112                 fd.setFilter(tr("PNG (*.png);;All Files (*.*)"));
113                 fd.setAcceptMode(AcceptMode.AcceptOpen);
114                 if (path == null || path.equals(""))
115                         fd.setDirectory(Global.getFileManager().getImageDirPath(""));
116                 else
117                         fd.setDirectory(path);
118                 if (fd.exec() == 0 || fd.selectedFiles().size() == 0) {
119                         return;
120                 }
121                 
122                 this.path = fd.selectedFiles().get(0);
123                 this.path = path.substring(0,path.lastIndexOf("/"));
124                 ok.setEnabled(true);
125                 String path = fd.selectedFiles().get(0);
126                 iconButton.setIcon(new QIcon(path));
127                 iconButton.setSizePolicy(Policy.Fixed, Policy.Fixed);
128         }
129         
130         public void setUseDefaultIcon(boolean val) {
131                 useDefault.setChecked(val);
132                 iconButton.setEnabled(!val);
133                 startUseDefault = val;
134         }
135         
136         public QIcon getIcon() {
137                 if (useDefault.isChecked())
138                         return null;
139                 return iconButton.icon();
140         }
141         
142         public void useDefaultIconChecked(Boolean value) {
143                 iconButton.setEnabled(!value);
144                 
145                 if (value != startUseDefault) 
146                         ok.setEnabled(true);
147                 else
148                         ok.setEnabled(false);
149         }
150         
151         public String getFileType() {
152                 return "PNG";
153         }
154         
155         public String getPath() {
156                 return path;
157         }
158 }