OSDN Git Service

GitHub最初のコミット(SourceForge.jp 128fa38 2013-02-28 15:28:57 と同じ内容)
[neighbornote/NeighborNote.git] / src / cx / fbn / nevernote / dialog / NoteQuickLinkDialog.java
index f8c85ea..be6c4e9 100644 (file)
-/*\r
- * This file is part of NixNote \r
- * Copyright 2011 Randy Baumgarte\r
- * \r
- * This file may be licensed under the terms of of the\r
- * GNU General Public License Version 2 (the ``GPL'').\r
- *\r
- * Software distributed under the License is distributed\r
- * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either\r
- * express or implied. See the GPL for the specific language\r
- * governing rights and limitations.\r
- *\r
- * You should have received a copy of the GPL along with this\r
- * program. If not, go to http://www.gnu.org/licenses/gpl.html\r
- * or write to the Free Software Foundation, Inc.,\r
- * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\r
- *\r
-*/\r
-\r
-package cx.fbn.nevernote.dialog;\r
-\r
-//**********************************************\r
-//**********************************************\r
-//* This is the dialog that shows a user\r
-//* a quick popup of a note based upon its title.\r
-//* It is used in the Quick Link function.\r
-//**********************************************\r
-//**********************************************\r
-\r
-import java.util.List;\r
-\r
-import com.evernote.edam.type.Note;\r
-import com.trolltech.qt.core.QByteArray;\r
-import com.trolltech.qt.core.QTemporaryFile;\r
-import com.trolltech.qt.core.Qt.ContextMenuPolicy;\r
-import com.trolltech.qt.gui.QComboBox;\r
-import com.trolltech.qt.gui.QDialog;\r
-import com.trolltech.qt.gui.QHBoxLayout;\r
-import com.trolltech.qt.gui.QIcon;\r
-import com.trolltech.qt.gui.QLabel;\r
-import com.trolltech.qt.gui.QPushButton;\r
-import com.trolltech.qt.gui.QVBoxLayout;\r
-\r
-import cx.fbn.nevernote.gui.BrowserWindow;\r
-import cx.fbn.nevernote.sql.DatabaseConnection;\r
-import cx.fbn.nevernote.utilities.ApplicationLogger;\r
-import cx.fbn.nevernote.utilities.Pair;\r
-import cx.fbn.nevernote.xml.NoteFormatter;\r
-\r
-public class NoteQuickLinkDialog extends QDialog {\r
-       public final QPushButton        ok;\r
-       public final QPushButton        cancel;\r
-       private final DatabaseConnection  conn;\r
-       public final QComboBox          titleCombo;      \r
-       private final BrowserWindow     browser;\r
-       private final ApplicationLogger logger;\r
-       List<Pair<String,String>> results;\r
-       public boolean okPressed;\r
-       private List<QTemporaryFile> tempFiles;\r
-       private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");\r
-       \r
-       // Constructor\r
-       public NoteQuickLinkDialog(ApplicationLogger l, DatabaseConnection c, String text) {\r
-               okPressed = false;\r
-               setWindowTitle(tr("Quick Link Notes"));\r
-               setWindowIcon(new QIcon(iconPath+"notebook-green.png"));\r
-               QVBoxLayout main = new QVBoxLayout();\r
-               setLayout(main);\r
-               titleCombo = new QComboBox(this);\r
-               \r
-               QHBoxLayout comboLayout = new QHBoxLayout();\r
-               comboLayout.addWidget(new QLabel(tr("Matching Notes:")));\r
-               comboLayout.addWidget(titleCombo);\r
-               comboLayout.addStretch(100);\r
-               \r
-               main.addLayout(comboLayout);\r
-                               \r
-               conn = c;\r
-               browser = new BrowserWindow(conn);\r
-               main.addWidget(browser);\r
-               browser.titleLabel.setVisible(false);\r
-               browser.notebookBox.setVisible(false);\r
-               browser.hideButtons();\r
-               browser.tagEdit.setVisible(false);\r
-               browser.tagLabel.setVisible(false);\r
-               \r
-               QHBoxLayout buttonLayout = new QHBoxLayout();\r
-               buttonLayout.addStretch(100);\r
-               ok = new QPushButton(tr("OK"));\r
-               ok.clicked.connect(this, "okPressed()");\r
-               \r
-               cancel = new QPushButton(tr("Cancel"));\r
-               cancel.clicked.connect(this, "cancelPressed()");\r
-               \r
-               buttonLayout.addWidget(ok);\r
-               buttonLayout.addWidget(cancel);\r
-               main.addLayout(buttonLayout);\r
-               \r
-               browser.getBrowser().setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);\r
-               logger = l;\r
-               \r
-               // Search for matching notes\r
-               results = conn.getNoteTable().findNotesByTitle(text);\r
-               \r
-               // Add the results to the combo box\r
-               for (int i=0; i<results.size(); i++) {\r
-                       titleCombo.addItem(results.get(i).getSecond(), results.get(i).getFirst());\r
-               }\r
-               titleCombo.activated.connect(this, "selectionChanged(String)");\r
-               \r
-               // Load the results into the combo box\r
-               if (results.size() > 0) {\r
-                       Note currentNote = conn.getNoteTable().getNote(results.get(0).getFirst(), true, true, false, true, true);\r
-                       setContent(currentNote);\r
-               }\r
-       }\r
-\r
-       // Cancel button pressed\r
-       @SuppressWarnings("unused")\r
-       private void cancelPressed() {\r
-               this.close();\r
-       }\r
-       \r
-       // OK button pressed\r
-       @SuppressWarnings("unused")\r
-       private void okPressed() {\r
-               okPressed = true;\r
-               close();\r
-       }\r
-\r
-       // When the selection changes, we refresh the browser window with the new content\r
-       @SuppressWarnings("unused")\r
-       private void selectionChanged(String text) {\r
-               int pos = titleCombo.currentIndex();\r
-               String guid = results.get(pos).getFirst();\r
-               Note note = conn.getNoteTable().getNote(guid, true, true, false, true, true);\r
-               setContent(note);\r
-       }\r
-       \r
-       // Return the note the user is currently viewing\r
-       public String getSelectedNote() {\r
-               int pos = titleCombo.currentIndex();\r
-               return results.get(pos).getFirst();\r
-       }\r
-       \r
-       \r
-       // Load the content of the note into the viewing window.\r
-       public void setContent(Note currentNote) {      \r
-               NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);\r
-               formatter.setNote(currentNote, false);\r
-               formatter.setHighlight(null);\r
-               formatter.setNoteHistory(true);\r
-               \r
-               StringBuffer js = new StringBuffer();\r
-               \r
-               // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly \r
-               js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");       \r
-               js.append("<style type=\"text/css\">en-crypt-temp { border-style:solid; border-color:blue; padding:1mm 1mm 1mm 1mm; }</style>");\r
-               js.append("</head>");\r
-               js.append(formatter.rebuildNoteHTML());\r
-               js.append("</HTML>");\r
-               \r
-               browser.setNote(currentNote);\r
-               browser.setContent(new QByteArray(js.toString()));\r
-       }\r
-       \r
-       // give the results from the DB search back to the caller.\r
-       public List<Pair<String,String>> getResults() {\r
-               return results;\r
-       }\r
-       \r
-       \r
-}\r
\r
-\r
-\r
-       \r
-       \r
-       \r
-       \r
-\r
+/*
+ * This file is part of NixNote 
+ * Copyright 2011 Randy Baumgarte
+ * 
+ * This file may be licensed under the terms of of the
+ * GNU General Public License Version 2 (the ``GPL'').
+ *
+ * Software distributed under the License is distributed
+ * on an ``AS IS'' basis, WITHOUT WARRANTY OF ANY KIND, either
+ * express or implied. See the GPL for the specific language
+ * governing rights and limitations.
+ *
+ * You should have received a copy of the GPL along with this
+ * program. If not, go to http://www.gnu.org/licenses/gpl.html
+ * or write to the Free Software Foundation, Inc.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ *
+*/
+
+package cx.fbn.nevernote.dialog;
+
+//**********************************************
+//**********************************************
+//* This is the dialog that shows a user
+//* a quick popup of a note based upon its title.
+//* It is used in the Quick Link function.
+//**********************************************
+//**********************************************
+
+import java.util.List;
+
+import com.evernote.edam.type.Note;
+import com.trolltech.qt.core.QByteArray;
+import com.trolltech.qt.core.QTemporaryFile;
+import com.trolltech.qt.core.Qt.ContextMenuPolicy;
+import com.trolltech.qt.gui.QComboBox;
+import com.trolltech.qt.gui.QDialog;
+import com.trolltech.qt.gui.QHBoxLayout;
+import com.trolltech.qt.gui.QIcon;
+import com.trolltech.qt.gui.QLabel;
+import com.trolltech.qt.gui.QPushButton;
+import com.trolltech.qt.gui.QVBoxLayout;
+
+import cx.fbn.nevernote.gui.BrowserWindow;
+import cx.fbn.nevernote.neighbornote.ClipBoardObserver;
+import cx.fbn.nevernote.sql.DatabaseConnection;
+import cx.fbn.nevernote.utilities.ApplicationLogger;
+import cx.fbn.nevernote.utilities.Pair;
+import cx.fbn.nevernote.xml.NoteFormatter;
+
+public class NoteQuickLinkDialog extends QDialog {
+       public final QPushButton        ok;
+       public final QPushButton        cancel;
+       private final DatabaseConnection  conn;
+       public final QComboBox          titleCombo;      
+       private final BrowserWindow     browser;
+       private final ApplicationLogger logger;
+       List<Pair<String,String>> results;
+       public boolean okPressed;
+       private List<QTemporaryFile> tempFiles;
+       private final String iconPath = new String("classpath:cx/fbn/nevernote/icons/");
+       // ICHANGED
+       private final ClipBoardObserver cbObserver;
+       
+       // ICHANGED 引数にcbObserver追加
+       // Constructor
+       public NoteQuickLinkDialog(ApplicationLogger l, DatabaseConnection c, String text, ClipBoardObserver cbObserver) {
+               okPressed = false;
+               setWindowTitle(tr("Quick Link Notes"));
+               setWindowIcon(new QIcon(iconPath+"notebook-green.png"));
+               QVBoxLayout main = new QVBoxLayout();
+               setLayout(main);
+               titleCombo = new QComboBox(this);
+               
+               QHBoxLayout comboLayout = new QHBoxLayout();
+               comboLayout.addWidget(new QLabel(tr("Matching Notes:")));
+               comboLayout.addWidget(titleCombo);
+               comboLayout.addStretch(100);
+               
+               main.addLayout(comboLayout);
+                               
+               conn = c;
+               
+               // ICHANGED
+               this.cbObserver = cbObserver;
+               browser = new BrowserWindow(conn, this.cbObserver);
+               
+               main.addWidget(browser);
+               browser.titleLabel.setVisible(false);
+               browser.notebookBox.setVisible(false);
+               browser.hideButtons();
+               browser.tagEdit.setVisible(false);
+               browser.tagLabel.setVisible(false);
+               
+               QHBoxLayout buttonLayout = new QHBoxLayout();
+               buttonLayout.addStretch(100);
+               ok = new QPushButton(tr("OK"));
+               ok.clicked.connect(this, "okPressed()");
+               
+               cancel = new QPushButton(tr("Cancel"));
+               cancel.clicked.connect(this, "cancelPressed()");
+               
+               buttonLayout.addWidget(ok);
+               buttonLayout.addWidget(cancel);
+               main.addLayout(buttonLayout);
+               
+               browser.getBrowser().setContextMenuPolicy(ContextMenuPolicy.NoContextMenu);
+               logger = l;
+               
+               // Search for matching notes
+               results = conn.getNoteTable().findNotesByTitle(text);
+               
+               // Add the results to the combo box
+               for (int i=0; i<results.size(); i++) {
+                       titleCombo.addItem(results.get(i).getSecond(), results.get(i).getFirst());
+               }
+               titleCombo.activated.connect(this, "selectionChanged(String)");
+               
+               // Load the results into the combo box
+               if (results.size() > 0) {
+                       Note currentNote = conn.getNoteTable().getNote(results.get(0).getFirst(), true, true, false, true, true);
+                       setContent(currentNote);
+               }
+       }
+
+       // Cancel button pressed
+       @SuppressWarnings("unused")
+       private void cancelPressed() {
+               this.close();
+       }
+       
+       // OK button pressed
+       @SuppressWarnings("unused")
+       private void okPressed() {
+               okPressed = true;
+               close();
+       }
+
+       // When the selection changes, we refresh the browser window with the new content
+       @SuppressWarnings("unused")
+       private void selectionChanged(String text) {
+               int pos = titleCombo.currentIndex();
+               String guid = results.get(pos).getFirst();
+               Note note = conn.getNoteTable().getNote(guid, true, true, false, true, true);
+               setContent(note);
+       }
+       
+       // Return the note the user is currently viewing
+       public String getSelectedNote() {
+               int pos = titleCombo.currentIndex();
+               return results.get(pos).getFirst();
+       }
+       
+       
+       // Load the content of the note into the viewing window.
+       public void setContent(Note currentNote) {      
+               NoteFormatter formatter = new NoteFormatter(logger, conn, tempFiles);
+               formatter.setNote(currentNote, false);
+               formatter.setHighlight(null);
+               formatter.setNoteHistory(true);
+               
+               StringBuffer js = new StringBuffer();
+               
+               // We need to prepend the note with <HEAD></HEAD> or encoded characters are ugly 
+               js.append("<html><head><meta http-equiv=\"Content-Type\" content=\"text/html; charset=UTF-8\">");       
+               js.append("<style type=\"text/css\">en-crypt-temp { border-style:solid; border-color:blue; padding:1mm 1mm 1mm 1mm; }</style>");
+               js.append("</head>");
+               js.append(formatter.rebuildNoteHTML());
+               js.append("</HTML>");
+               
+               browser.setNote(currentNote);
+               browser.setContent(new QByteArray(js.toString()));
+       }
+       
+       // give the results from the DB search back to the caller.
+       public List<Pair<String,String>> getResults() {
+               return results;
+       }
+       
+       
+}
+
+
+       
+       
+       
+       
+