• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (C) 2007 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package com.android.ide.eclipse.ddms.preferences;
18 
19 import com.android.ide.eclipse.ddms.DdmsPlugin;
20 import com.android.ide.eclipse.ddms.LogCatMonitor;
21 import com.android.ide.eclipse.ddms.views.DeviceView.HProfHandler;
22 import com.android.ide.eclipse.ddms.views.LogCatView;
23 import com.android.ddmlib.DdmPreferences;
24 import com.android.ddmuilib.DdmUiPreferences;
25 
26 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer;
27 import org.eclipse.jface.preference.IPreferenceStore;
28 import org.eclipse.swt.SWT;
29 import org.eclipse.swt.graphics.FontData;
30 
31 /**
32  * Class used to initialize default preference values.
33  */
34 public class PreferenceInitializer extends AbstractPreferenceInitializer {
35 
36     public final static String ATTR_LOG_LEVEL =
37         DdmsPlugin.PLUGIN_ID + ".logLevel"; //$NON-NLS-1$
38 
39     public final static String ATTR_DEBUG_PORT_BASE =
40         DdmsPlugin.PLUGIN_ID + ".adbDebugBasePort"; //$NON-NLS-1$
41 
42     public final static String ATTR_SELECTED_DEBUG_PORT =
43         DdmsPlugin.PLUGIN_ID + ".debugSelectedPort"; //$NON-NLS-1$
44 
45     public final static String ATTR_DEFAULT_THREAD_UPDATE =
46         DdmsPlugin.PLUGIN_ID + ".defaultThreadUpdateEnabled"; //$NON-NLS-1$
47 
48     public final static String ATTR_DEFAULT_HEAP_UPDATE =
49         DdmsPlugin.PLUGIN_ID + ".defaultHeapUpdateEnabled"; //$NON-NLS-1$
50 
51     public final static String ATTR_THREAD_INTERVAL =
52         DdmsPlugin.PLUGIN_ID + ".threadStatusInterval"; //$NON-NLS-1$
53 
54     public final static String ATTR_IMAGE_SAVE_DIR =
55         DdmsPlugin.PLUGIN_ID + ".imageSaveDir"; //$NON-NLS-1$
56 
57     public final static String ATTR_LAST_IMAGE_SAVE_DIR =
58         DdmsPlugin.PLUGIN_ID + ".lastImageSaveDir"; //$NON-NLS-1$
59 
60     public final static String ATTR_LOGCAT_FONT =
61         DdmsPlugin.PLUGIN_ID + ".logcatFont"; //$NON-NLS-1$
62 
63     public final static String ATTR_HPROF_ACTION =
64         DdmsPlugin.PLUGIN_ID + ".hprofAction"; //$NON-NLS-1$
65 
66     public final static String ATTR_TIME_OUT =
67         DdmsPlugin.PLUGIN_ID + ".timeOut"; //$NON-NLS-1$
68 
69     public final static String ATTR_USE_ADBHOST =
70         DdmsPlugin.PLUGIN_ID + ".useAdbHost"; //$NON-NLS-1$
71 
72     public final static String ATTR_ADBHOST_VALUE =
73         DdmsPlugin.PLUGIN_ID + ".adbHostValue"; //$NON-NLS-1$
74 
75     public final static String ATTR_SWITCH_PERSPECTIVE =
76         DdmsPlugin.PLUGIN_ID + ".switchPerspective"; //$NON-NLS-1$
77 
78     public final static String ATTR_PERSPECTIVE_ID =
79         DdmsPlugin.PLUGIN_ID + ".perspectiveId"; //$NON-NLS-1$
80 
81     /*
82      * (non-Javadoc)
83      *
84      * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer
85      * #initializeDefaultPreferences()
86      */
87     @Override
initializeDefaultPreferences()88     public void initializeDefaultPreferences() {
89         IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
90 
91         store.setDefault(ATTR_DEBUG_PORT_BASE, DdmPreferences.DEFAULT_DEBUG_PORT_BASE);
92 
93         store.setDefault(ATTR_SELECTED_DEBUG_PORT, DdmPreferences.DEFAULT_SELECTED_DEBUG_PORT);
94 
95         store.setDefault(ATTR_DEFAULT_THREAD_UPDATE, DdmPreferences.DEFAULT_INITIAL_THREAD_UPDATE);
96         store.setDefault(ATTR_DEFAULT_HEAP_UPDATE,
97                 DdmPreferences.DEFAULT_INITIAL_HEAP_UPDATE);
98 
99         store.setDefault(ATTR_THREAD_INTERVAL, DdmUiPreferences.DEFAULT_THREAD_REFRESH_INTERVAL);
100 
101         String homeDir = System.getProperty("user.home"); //$NON-NLS-1$
102         store.setDefault(ATTR_IMAGE_SAVE_DIR, homeDir);
103 
104         store.setDefault(ATTR_LOG_LEVEL, DdmPreferences.DEFAULT_LOG_LEVEL.getStringValue());
105 
106         store.setDefault(ATTR_LOGCAT_FONT,
107                 new FontData("Courier", 10, SWT.NORMAL).toString()); //$NON-NLS-1$
108 
109         store.setDefault(ATTR_HPROF_ACTION, HProfHandler.ACTION_SAVE);
110 
111         store.setDefault(ATTR_TIME_OUT, DdmPreferences.DEFAULT_TIMEOUT);
112 
113         store.setDefault(ATTR_USE_ADBHOST, DdmPreferences.DEFAULT_USE_ADBHOST);
114         store.setDefault(ATTR_ADBHOST_VALUE, DdmPreferences.DEFAULT_ADBHOST_VALUE);
115         store.setDefault(ATTR_SWITCH_PERSPECTIVE, LogCatView.DEFAULT_SWITCH_PERSPECTIVE);
116         store.setDefault(ATTR_PERSPECTIVE_ID, LogCatView.DEFAULT_PERSPECTIVE_ID);
117 
118         store.setDefault(LogCatMonitor.AUTO_MONITOR_PREFKEY, true);
119     }
120 
121     /**
122      * Initializes the preferences of ddmlib and ddmuilib with values from the eclipse store.
123      */
setupPreferences()124     public synchronized static void setupPreferences() {
125         IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
126 
127         DdmPreferences.setDebugPortBase(store.getInt(ATTR_DEBUG_PORT_BASE));
128         DdmPreferences.setSelectedDebugPort(store.getInt(ATTR_SELECTED_DEBUG_PORT));
129         DdmPreferences.setLogLevel(store.getString(ATTR_LOG_LEVEL));
130         DdmPreferences.setInitialThreadUpdate(store.getBoolean(ATTR_DEFAULT_THREAD_UPDATE));
131         DdmPreferences.setInitialHeapUpdate(store.getBoolean(ATTR_DEFAULT_HEAP_UPDATE));
132         DdmUiPreferences.setThreadRefreshInterval(store.getInt(ATTR_THREAD_INTERVAL));
133         DdmPreferences.setTimeOut(store.getInt(ATTR_TIME_OUT));
134         DdmPreferences.setUseAdbHost(store.getBoolean(ATTR_USE_ADBHOST));
135         DdmPreferences.setAdbHostValue(store.getString(ATTR_ADBHOST_VALUE));
136     }
137 }
138