OSDN Git Service

連想ノートリストの重み付けにプリセットモードを導入した
authoryuki <kimaira7@gmail.com>
Mon, 9 Sep 2013 08:10:15 +0000 (17:10 +0900)
committeryuki <kimaira7@gmail.com>
Mon, 9 Sep 2013 08:10:15 +0000 (17:10 +0900)
src/cx/fbn/nevernote/Global.java
src/cx/fbn/nevernote/dialog/ConfigDialog.java
src/cx/fbn/nevernote/dialog/ConfigRensoNoteListPage.java
src/cx/fbn/nevernote/gui/RensoNoteList.java
src/cx/fbn/nevernote/gui/RensoNoteListDock.java

index d10d6e4..38b615c 100644 (file)
@@ -2141,11 +2141,11 @@ public class Global {
                settings.beginGroup("RensoNoteList");
                Integer value;
                try {
                settings.beginGroup("RensoNoteList");
                Integer value;
                try {
-                       String val  = (String)settings.value("addNewNoteWeight", 1);
+                       String val  = (String)settings.value("addNewNoteWeight", 3);
                        value = new Integer(val.trim());
                } catch (Exception e) {
                        try {
                        value = new Integer(val.trim());
                } catch (Exception e) {
                        try {
-                               value = (Integer)settings.value("addNewNoteWeight", 1);
+                               value = (Integer)settings.value("addNewNoteWeight", 3);
                        } catch (Exception e1) {
                                value = 1;
                        }
                        } catch (Exception e1) {
                                value = 1;
                        }
@@ -2236,11 +2236,11 @@ public class Global {
                settings.beginGroup("RensoNoteList");
                Integer value;
                try {
                settings.beginGroup("RensoNoteList");
                Integer value;
                try {
-                       String val = (String)settings.value("enRelatedNotesWeight", 10);
+                       String val = (String)settings.value("enRelatedNotesWeight", 5);
                        value = new Integer(val.trim());
                } catch (Exception e) {
                        try {
                        value = new Integer(val.trim());
                } catch (Exception e) {
                        try {
-                               value = (Integer)settings.value("enRelatedNotesWeight", 10);
+                               value = (Integer)settings.value("enRelatedNotesWeight", 5);
                        } catch (Exception e1) {
                                value = 10;
                        }
                        } catch (Exception e1) {
                                value = 10;
                        }
@@ -2439,5 +2439,179 @@ public class Global {
                        settings.setValue("haltOperationLog", "false");
                settings.endGroup();
     }
                        settings.setValue("haltOperationLog", "false");
                settings.endGroup();
     }
+    
+    // 連想ノートリストの重み付けモードの状態
+    public static String rensoWeightingSelect() {
+               settings.beginGroup("RensoNoteList");
+               String text = (String)settings.value("rensoWeightingSelect", "Standard");
+               settings.endGroup();
+               return text;
+    }
+    public static void saveRensoWeightingSelect(String val) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("rensoWeightingSelect", val);
+               settings.endGroup();
+    }
+    
+    //ordinal から指定した Enum の要素に変換する汎用関数
+       public static <E extends Enum<E>> E fromOrdinal(Class<E> enumClass, int ordinal) {
+           E[] enumArray = enumClass.getEnumConstants();
+           return enumArray[ordinal];
+       }
+       
+       // 連想ノートリスト重み付けモード:カスタムの設定値(同時閲覧)
+    public static int customBrowseWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customBrowseWeight", 1);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customBrowseWeight", 1);
+                       } catch (Exception e1) {
+                               value = 1;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomBrowseWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customBrowseWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(コピー&ペースト)
+    public static int customCopyPasteWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customCopyPasteWeight", 3);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customCopyPasteWeight", 3);
+                       } catch (Exception e1) {
+                               value = 3;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomCopyPasteWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customCopyPasteWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(新規ノート追加)
+    public static int customAddNewNoteWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customAddNewNoteWeight", 3);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customAddNewNoteWeight", 3);
+                       } catch (Exception e1) {
+                               value = 3;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomAddNewNoteWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customAddNewNoteWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(連想ノートクリック)
+    public static int customRensoItemClickWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customRensoItemClickWeight", 10);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customRensoItemClickWeight", 10);
+                       } catch (Exception e1) {
+                               value = 10;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomRensoItemClickWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customRensoItemClickWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(同じタグ)
+    public static int customSameTagWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customSameTagWeight", 2);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customSameTagWeight", 2);
+                       } catch (Exception e1) {
+                               value = 2;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomSameTagWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customSameTagWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(同じノートブック)
+    public static int customSameNotebookWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customSameNotebookWeight", 2);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customSameNotebookWeight", 2);
+                       } catch (Exception e1) {
+                               value = 2;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomSameNotebookWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customSameNotebookWeight", weight);
+               settings.endGroup();
+       }
+       // 連想ノートリスト重み付けモード:カスタムの設定値(Evernote関連ノート)
+    public static int customENRelatedNotesWeight() {
+               settings.beginGroup("RensoNoteList");
+               Integer value;
+               try {
+                       String val  = (String)settings.value("customENRelatedNotesWeight", 5);
+                       value = new Integer(val.trim());
+               } catch (Exception e) {
+                       try {
+                               value = (Integer)settings.value("customENRelatedNotesWeight", 5);
+                       } catch (Exception e1) {
+                               value = 5;
+                       }
+               }
+               settings.endGroup();
+               return value;
+    }
+       public static void saveCustomENRelatedNotesWeight(int weight) {
+               settings.beginGroup("RensoNoteList");
+               settings.setValue("customENRelatedNotesWeight", weight);
+               settings.endGroup();
+       }
 }
 
 }
 
index aae31c4..2e601aa 100644 (file)
@@ -229,7 +229,6 @@ public class ConfigDialog extends QDialog {
                Global.setDefaultFontSize(fontPage.getFontSize());\r
                Global.setDatabaseCache(debugPage.getDatabaseCacheSize());\r
                \r
                Global.setDefaultFontSize(fontPage.getFontSize());\r
                Global.setDatabaseCache(debugPage.getDatabaseCacheSize());\r
                \r
-               // ICHANGED\r
                Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
                Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
                Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
                Global.setBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
                Global.setCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
                Global.setAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
@@ -238,7 +237,18 @@ public class ConfigDialog extends QDialog {
                Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
                Global.setENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
                \r
                Global.setSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
                Global.setENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
                \r
-               // ICHANGED\r
+               // 現在カスタムモードなら、カスタムモードの設定値として保存\r
+               String mode = new String(Global.rensoWeightingSelect());\r
+               if (mode.equals("Custom")) {\r
+                       Global.saveCustomBrowseWeight(rensoNoteListPage.getBrowseWeight());\r
+                       Global.saveCustomCopyPasteWeight(rensoNoteListPage.getCopyPasteWeight());\r
+                       Global.saveCustomAddNewNoteWeight(rensoNoteListPage.getAddNewNoteWeight());\r
+                       Global.saveCustomRensoItemClickWeight(rensoNoteListPage.getRensoItemClickWeight());\r
+                       Global.saveCustomSameTagWeight(rensoNoteListPage.getSameTagWeight());\r
+                       Global.saveCustomSameNotebookWeight(rensoNoteListPage.getSameNotebookWeight());\r
+                       Global.saveCustomENRelatedNotesWeight(rensoNoteListPage.getENRelatedNotesWeight());\r
+               }\r
+               \r
                Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
                Global.setDuplicateRensoNote(rensoNoteListPage.getDuplicateChecked());\r
                Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
                Global.setMergeRensoNote(rensoNoteListPage.getMergeChecked());\r
                Global.setDuplicateRensoNote(rensoNoteListPage.getDuplicateChecked());\r
                Global.setVerifyExclude(rensoNoteListPage.getVerifyExcludeChecked());\r
index 646b571..1b888bf 100644 (file)
@@ -25,6 +25,7 @@ import com.trolltech.qt.gui.QCheckBox;
 import com.trolltech.qt.gui.QFormLayout;
 import com.trolltech.qt.gui.QGroupBox;
 import com.trolltech.qt.gui.QHBoxLayout;
 import com.trolltech.qt.gui.QFormLayout;
 import com.trolltech.qt.gui.QGroupBox;
 import com.trolltech.qt.gui.QHBoxLayout;
+import com.trolltech.qt.gui.QLabel;
 import com.trolltech.qt.gui.QSlider;
 import com.trolltech.qt.gui.QSpinBox;
 import com.trolltech.qt.gui.QVBoxLayout;
 import com.trolltech.qt.gui.QSlider;
 import com.trolltech.qt.gui.QSpinBox;
 import com.trolltech.qt.gui.QVBoxLayout;
@@ -208,19 +209,45 @@ public class ConfigRensoNoteListPage extends QWidget {
                enRelatedNotesLayout.addWidget(enRelatedNotesSpinner);
                
                // 重み付け設定部分のレイアウト
                enRelatedNotesLayout.addWidget(enRelatedNotesSpinner);
                
                // 重み付け設定部分のレイアウト
+               QVBoxLayout vLayout = new QVBoxLayout();
                QFormLayout styleLayout = new QFormLayout();
                styleLayout.setHorizontalSpacing(10);
                styleLayout.setVerticalSpacing(30);
                QFormLayout styleLayout = new QFormLayout();
                styleLayout.setHorizontalSpacing(10);
                styleLayout.setVerticalSpacing(30);
-               styleLayout.addRow(tr("Browse Weight"), browseLayout);
+               styleLayout.addRow(tr("Concurrent Browse Weight"), browseLayout);
                styleLayout.addRow(tr("Copy&Paste Weight"), copyPasteLayout);
                styleLayout.addRow(tr("Add New Note Weight"), addNewNoteLayout);
                styleLayout.addRow(tr("Renso Item Click Weight"), rensoItemClickLayout);
                styleLayout.addRow(tr("Same Tag Weight"), sameTagLayout);
                styleLayout.addRow(tr("Same Notebook Weight"), sameNotebookLayout);
                styleLayout.addRow(tr("Copy&Paste Weight"), copyPasteLayout);
                styleLayout.addRow(tr("Add New Note Weight"), addNewNoteLayout);
                styleLayout.addRow(tr("Renso Item Click Weight"), rensoItemClickLayout);
                styleLayout.addRow(tr("Same Tag Weight"), sameTagLayout);
                styleLayout.addRow(tr("Same Notebook Weight"), sameNotebookLayout);
-               styleLayout.addRow(tr("Evernote Related Notes Integration"), enRelatedNotesLayout);
+               styleLayout.addRow(tr("Evernote Related Notes Weight"), enRelatedNotesLayout);
+               vLayout.addLayout(styleLayout);
 
                QGroupBox weightingGroup = new QGroupBox(tr("Weighting"));
 
                QGroupBox weightingGroup = new QGroupBox(tr("Weighting"));
-               weightingGroup.setLayout(styleLayout);
+               weightingGroup.setLayout(vLayout);
+               
+               // プリセットモードがカスタム以外ならば設定不可能にする
+               String mode = new String(Global.rensoWeightingSelect());
+               if (!mode.equals("Custom")) {
+                       QLabel attention = new QLabel(tr("You can change these settings if you select \"Custom\" Mode."));
+                       attention.setStyleSheet("color : red");
+                       vLayout.insertWidget(0, attention);
+                       vLayout.insertSpacing(1, 20);
+                       
+                       browseSlider.setEnabled(false);
+                       browseSpinner.setEnabled(false);
+                       copyPasteSlider.setEnabled(false);
+                       copyPasteSpinner.setEnabled(false);
+                       addNewNoteSlider.setEnabled(false);
+                       addNewNoteSpinner.setEnabled(false);
+                       rensoItemClickSlider.setEnabled(false);
+                       rensoItemClickSpinner.setEnabled(false);
+                       sameTagSlider.setEnabled(false);
+                       sameTagSpinner.setEnabled(false);
+                       sameNotebookSlider.setEnabled(false);
+                       sameNotebookSpinner.setEnabled(false);
+                       enRelatedNotesSlider.setEnabled(false);
+                       enRelatedNotesSpinner.setEnabled(false);
+               }
                
                // ノートのマージ・複製の関連ノートリストへの適用
                mergeCheck = new QCheckBox(tr("When you merge the notes, also merge RensoNoteList"));
                
                // ノートのマージ・複製の関連ノートリストへの適用
                mergeCheck = new QCheckBox(tr("When you merge the notes, also merge RensoNoteList"));
index bd6b31c..ba8ed62 100644 (file)
@@ -456,4 +456,8 @@ public class RensoNoteList extends QListWidget {
        public QThread getEnRelatedNotesThread() {
                return enRelatedNotesThread;
        }
        public QThread getEnRelatedNotesThread() {
                return enRelatedNotesThread;
        }
+       
+       public String getGuid() {
+               return guid;
+       }
 }
 }
index ad27680..bb54812 100644 (file)
 
 package cx.fbn.nevernote.gui;
 
 
 package cx.fbn.nevernote.gui;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.EnumMap;
+import java.util.List;
+import java.util.Map;
+
 import com.trolltech.qt.core.QSize;
 import com.trolltech.qt.core.QSize;
+import com.trolltech.qt.gui.QComboBox;
 import com.trolltech.qt.gui.QDockWidget;
 import com.trolltech.qt.gui.QIcon;
 import com.trolltech.qt.gui.QDockWidget;
 import com.trolltech.qt.gui.QIcon;
+import com.trolltech.qt.gui.QLabel;
 import com.trolltech.qt.gui.QMessageBox;
 import com.trolltech.qt.gui.QPushButton;
 import com.trolltech.qt.gui.QSizePolicy;
 import com.trolltech.qt.gui.QMessageBox;
 import com.trolltech.qt.gui.QPushButton;
 import com.trolltech.qt.gui.QSizePolicy;
@@ -41,8 +49,10 @@ public class RensoNoteListDock extends QDockWidget {
        private final SyncRunner                        syncRunner;
        private final ApplicationLogger         logger;
        private final QPushButton                       haltLogButton;                  // 操作ログの取得を停止ボタン
        private final SyncRunner                        syncRunner;
        private final ApplicationLogger         logger;
        private final QPushButton                       haltLogButton;                  // 操作ログの取得を停止ボタン
+       private final QComboBox                         weightingModeSelect;    // 連想ノートリストの重み付けプリセットモード
        private final RensoNoteList                     rensoNoteList;                  // 連想ノートリスト
        private final QToolBar                          rensoToolBar;                   // 連想ノートリストドックのツールバー
        private final RensoNoteList                     rensoNoteList;                  // 連想ノートリスト
        private final QToolBar                          rensoToolBar;                   // 連想ノートリストドックのツールバー
+       private enum PresetMode {Standard, ConcurrentBrowse, OperationToOrganize, ContentSimilarity, Custom};   // プリセットモード一覧
        
        private final String                            iconPath;
        
        
        private final String                            iconPath;
        
@@ -61,6 +71,32 @@ public class RensoNoteListDock extends QDockWidget {
                rensoToolBar = new QToolBar();
                vLayout.addWidget(rensoToolBar);
                
                rensoToolBar = new QToolBar();
                vLayout.addWidget(rensoToolBar);
                
+               QLabel modeLabel = new QLabel(tr("Mode: "));
+               modeLabel.setToolTip(tr("Preset Weighting Mode"));
+               rensoToolBar.addWidget(modeLabel);
+               
+               weightingModeSelect = new QComboBox();
+               weightingModeSelect.setMaximumWidth(150);
+               weightingModeSelect.setToolTip(tr("Preset Weighting Mode"));
+               weightingModeSelect.insertItem(PresetMode.Standard.ordinal(), tr("Standard"));
+               weightingModeSelect.insertItem(PresetMode.ConcurrentBrowse.ordinal(), tr("Concurrent Browse"));
+               weightingModeSelect.insertItem(PresetMode.OperationToOrganize.ordinal(), ("Operation to Organize"));
+               weightingModeSelect.insertItem(PresetMode.ContentSimilarity.ordinal(), tr("Content Similarity"));
+               weightingModeSelect.insertItem(PresetMode.Custom.ordinal(), tr("Custom"));
+               int savedModeIndex = 0;
+               try {
+                       savedModeIndex = PresetMode.valueOf(Global.rensoWeightingSelect()).ordinal();
+               } catch (Exception e) {
+                       this.logger.log(this.logger.EXTREME, "Exception in weightingModeSelect = " + e);
+               }
+               if (savedModeIndex >= 0) {
+                       weightingModeSelect.setCurrentIndex(savedModeIndex);
+               } else {
+                       weightingModeSelect.setCurrentIndex(0);
+               }
+               weightingModeSelect.currentIndexChanged.connect(this, "weightingModeChanged(int)");
+               rensoToolBar.addWidget(weightingModeSelect);
+               
                haltLogButton = new QPushButton();
                QIcon haltLogIcon = new QIcon(this.iconPath + "haltLog.png");
                haltLogButton.setIcon(haltLogIcon);
                haltLogButton = new QPushButton();
                QIcon haltLogIcon = new QIcon(this.iconPath + "haltLog.png");
                haltLogButton.setIcon(haltLogIcon);
@@ -86,6 +122,45 @@ public class RensoNoteListDock extends QDockWidget {
        }
        
        @SuppressWarnings("unused")
        }
        
        @SuppressWarnings("unused")
+       private void weightingModeChanged(int modeIndex) {
+               logger.log(logger.EXTREME, "RensoNoteListDock.weightingModeChanged modeIndex = " + modeIndex);
+               
+               PresetMode mode = Global.fromOrdinal(PresetMode.class, modeIndex);
+               
+               // プリセットの重み付けマップを用意
+               // 値は同時閲覧、コピペ、新規ノート追加、連想ノートクリック、同じタグ、同じノートブック、Evernote関連ノートの順
+               Map<PresetMode, List<Integer>> presetMap = new EnumMap<PresetMode, List<Integer>>(PresetMode.class);
+               presetMap.put(PresetMode.Standard, Arrays.asList(1, 3, 3, 10, 2, 2, 5));
+               presetMap.put(PresetMode.ConcurrentBrowse, Arrays.asList(5, 2, 3, 10, 1, 1, 2));
+               presetMap.put(PresetMode.OperationToOrganize, Arrays.asList(1, 2, 3, 10, 5, 5, 2));
+               presetMap.put(PresetMode.ContentSimilarity, Arrays.asList(1, 2, 2, 10, 1, 1, 10));
+               presetMap.put(PresetMode.Custom, Arrays.asList(Global.customBrowseWeight(), Global.customCopyPasteWeight(), 
+                               Global.customAddNewNoteWeight(), Global.customRensoItemClickWeight(), Global.customSameTagWeight(), 
+                               Global.customSameNotebookWeight(), Global.customENRelatedNotesWeight()));
+               
+               List<Integer> weightList = new ArrayList<Integer>(presetMap.get(mode));
+               Global.setBrowseWeight(weightList.get(0));
+               Global.setCopyPasteWeight(weightList.get(1));
+               Global.setAddNewNoteWeight(weightList.get(2));
+               Global.setRensoItemClickWeight(weightList.get(3));
+               Global.setSameTagWeight(weightList.get(4));
+               Global.setSameNotebookWeight(weightList.get(5));
+               Global.setENRelatedNotesWeight(weightList.get(6));
+               
+               Global.saveRensoWeightingSelect(mode.name());
+               
+               // 連想ノートリストをリフレッシュ
+               if (rensoNoteList != null && rensoNoteList.getGuid() != null ) {
+                       rensoNoteList.refreshRensoNoteList();
+                       
+                       // カスタムモードかつアプリ起動時以外なら、メッセージ表示
+                       if (mode == PresetMode.Custom) {
+                               QMessageBox.information(this, tr("Custom Mode was Selected"), tr("Custom mode was selected.\nYou can customize weighting manually in the Edit/Preferences/Renso Note List."));
+                       }
+               }
+       }
+       
+       @SuppressWarnings("unused")
        private void haltLogToggled(boolean checked) {
                logger.log(logger.EXTREME, "RensoNoteListDock.haltLogToggled");
                
        private void haltLogToggled(boolean checked) {
                logger.log(logger.EXTREME, "RensoNoteListDock.haltLogToggled");
                
@@ -98,4 +173,5 @@ public class RensoNoteListDock extends QDockWidget {
        public RensoNoteList getRensoNoteList() {
                return rensoNoteList;
        }
        public RensoNoteList getRensoNoteList() {
                return rensoNoteList;
        }
+       
 }
 }