• 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_LOGCAT_GOTO_PROBLEM =
70         DdmsPlugin.PLUGIN_ID + ".logcatGoToProblem"; //$NON-NLS-1$
71 
72     public final static String ATTR_USE_ADBHOST =
73         DdmsPlugin.PLUGIN_ID + ".useAdbHost"; //$NON-NLS-1$
74 
75     public final static String ATTR_ADBHOST_VALUE =
76         DdmsPlugin.PLUGIN_ID + ".adbHostValue"; //$NON-NLS-1$
77 
78     public final static String ATTR_SWITCH_PERSPECTIVE =
79         DdmsPlugin.PLUGIN_ID + ".switchPerspective"; //$NON-NLS-1$
80 
81     public final static String ATTR_PERSPECTIVE_ID =
82         DdmsPlugin.PLUGIN_ID + ".perspectiveId"; //$NON-NLS-1$
83 
84     /*
85      * (non-Javadoc)
86      *
87      * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer
88      * #initializeDefaultPreferences()
89      */
90     @Override
initializeDefaultPreferences()91     public void initializeDefaultPreferences() {
92         IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
93 
94         store.setDefault(ATTR_DEBUG_PORT_BASE, DdmPreferences.DEFAULT_DEBUG_PORT_BASE);
95 
96         store.setDefault(ATTR_SELECTED_DEBUG_PORT, DdmPreferences.DEFAULT_SELECTED_DEBUG_PORT);
97 
98         store.setDefault(ATTR_DEFAULT_THREAD_UPDATE, DdmPreferences.DEFAULT_INITIAL_THREAD_UPDATE);
99         store.setDefault(ATTR_DEFAULT_HEAP_UPDATE,
100                 DdmPreferences.DEFAULT_INITIAL_HEAP_UPDATE);
101 
102         store.setDefault(ATTR_THREAD_INTERVAL, DdmUiPreferences.DEFAULT_THREAD_REFRESH_INTERVAL);
103 
104         String homeDir = System.getProperty("user.home"); //$NON-NLS-1$
105         store.setDefault(ATTR_IMAGE_SAVE_DIR, homeDir);
106 
107         store.setDefault(ATTR_LOG_LEVEL, DdmPreferences.DEFAULT_LOG_LEVEL.getStringValue());
108 
109         store.setDefault(ATTR_LOGCAT_FONT,
110                 new FontData("Courier", 10, SWT.NORMAL).toString()); //$NON-NLS-1$
111 
112         store.setDefault(ATTR_HPROF_ACTION, HProfHandler.ACTION_SAVE);
113 
114         store.setDefault(ATTR_TIME_OUT, DdmPreferences.DEFAULT_TIMEOUT);
115 
116         store.setDefault(ATTR_LOGCAT_GOTO_PROBLEM, LogCatView.CHOICE_ERROR_LINE);
117         store.setDefault(ATTR_USE_ADBHOST, DdmPreferences.DEFAULT_USE_ADBHOST);
118         store.setDefault(ATTR_ADBHOST_VALUE, DdmPreferences.DEFAULT_ADBHOST_VALUE);
119         store.setDefault(ATTR_SWITCH_PERSPECTIVE, LogCatView.DEFAULT_SWITCH_PERSPECTIVE);
120         store.setDefault(ATTR_PERSPECTIVE_ID, LogCatView.DEFAULT_PERSPECTIVE_ID);
121 
122         store.setDefault(LogCatMonitor.AUTO_MONITOR_PREFKEY, true);
123     }
124 
125     /**
126      * Initializes the preferences of ddmlib and ddmuilib with values from the eclipse store.
127      */
setupPreferences()128     public synchronized static void setupPreferences() {
129         IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore();
130 
131         DdmPreferences.setDebugPortBase(store.getInt(ATTR_DEBUG_PORT_BASE));
132         DdmPreferences.setSelectedDebugPort(store.getInt(ATTR_SELECTED_DEBUG_PORT));
133         DdmPreferences.setLogLevel(store.getString(ATTR_LOG_LEVEL));
134         DdmPreferences.setInitialThreadUpdate(store.getBoolean(ATTR_DEFAULT_THREAD_UPDATE));
135         DdmPreferences.setInitialHeapUpdate(store.getBoolean(ATTR_DEFAULT_HEAP_UPDATE));
136         DdmUiPreferences.setThreadRefreshInterval(store.getInt(ATTR_THREAD_INTERVAL));
137         DdmPreferences.setTimeOut(store.getInt(ATTR_TIME_OUT));
138         DdmPreferences.setUseAdbHost(store.getBoolean(ATTR_USE_ADBHOST));
139         DdmPreferences.setAdbHostValue(store.getString(ATTR_ADBHOST_VALUE));
140     }
141 }
142