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.views.DeviceView.HProfHandler; 21 import com.android.ddmlib.DdmPreferences; 22 import com.android.ddmuilib.DdmUiPreferences; 23 24 import org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer; 25 import org.eclipse.jface.preference.IPreferenceStore; 26 import org.eclipse.swt.SWT; 27 import org.eclipse.swt.graphics.FontData; 28 29 /** 30 * Class used to initialize default preference values. 31 */ 32 public class PreferenceInitializer extends AbstractPreferenceInitializer { 33 34 public final static String ATTR_LOG_LEVEL = 35 DdmsPlugin.PLUGIN_ID + ".logLevel"; //$NON-NLS-1$ 36 37 public final static String ATTR_DEBUG_PORT_BASE = 38 DdmsPlugin.PLUGIN_ID + ".adbDebugBasePort"; //$NON-NLS-1$ 39 40 public final static String ATTR_SELECTED_DEBUG_PORT = 41 DdmsPlugin.PLUGIN_ID + ".debugSelectedPort"; //$NON-NLS-1$ 42 43 public final static String ATTR_DEFAULT_THREAD_UPDATE = 44 DdmsPlugin.PLUGIN_ID + ".defaultThreadUpdateEnabled"; //$NON-NLS-1$ 45 46 public final static String ATTR_DEFAULT_HEAP_UPDATE = 47 DdmsPlugin.PLUGIN_ID + ".defaultHeapUpdateEnabled"; //$NON-NLS-1$ 48 49 public final static String ATTR_THREAD_INTERVAL = 50 DdmsPlugin.PLUGIN_ID + ".threadStatusInterval"; //$NON-NLS-1$ 51 52 public final static String ATTR_IMAGE_SAVE_DIR = 53 DdmsPlugin.PLUGIN_ID + ".imageSaveDir"; //$NON-NLS-1$ 54 55 public final static String ATTR_LAST_IMAGE_SAVE_DIR = 56 DdmsPlugin.PLUGIN_ID + ".lastImageSaveDir"; //$NON-NLS-1$ 57 58 public final static String ATTR_LOGCAT_FONT = 59 DdmsPlugin.PLUGIN_ID + ".logcatFont"; //$NON-NLS-1$ 60 61 public final static String ATTR_HPROF_ACTION = 62 DdmsPlugin.PLUGIN_ID + ".hprofAction"; //$NON-NLS-1$ 63 64 public final static String ATTR_TIME_OUT = 65 DdmsPlugin.PLUGIN_ID + ".timeOut"; //$NON-NLS-1$ 66 67 /* 68 * (non-Javadoc) 69 * 70 * @see org.eclipse.core.runtime.preferences.AbstractPreferenceInitializer 71 * #initializeDefaultPreferences() 72 */ 73 @Override initializeDefaultPreferences()74 public void initializeDefaultPreferences() { 75 IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore(); 76 77 store.setDefault(ATTR_DEBUG_PORT_BASE, DdmPreferences.DEFAULT_DEBUG_PORT_BASE); 78 79 store.setDefault(ATTR_SELECTED_DEBUG_PORT, DdmPreferences.DEFAULT_SELECTED_DEBUG_PORT); 80 81 store.setDefault(ATTR_DEFAULT_THREAD_UPDATE, DdmPreferences.DEFAULT_INITIAL_THREAD_UPDATE); 82 store.setDefault(ATTR_DEFAULT_HEAP_UPDATE, 83 DdmPreferences.DEFAULT_INITIAL_HEAP_UPDATE); 84 85 store.setDefault(ATTR_THREAD_INTERVAL, DdmUiPreferences.DEFAULT_THREAD_REFRESH_INTERVAL); 86 87 String homeDir = System.getProperty("user.home"); //$NON-NLS-1$ 88 store.setDefault(ATTR_IMAGE_SAVE_DIR, homeDir); 89 90 store.setDefault(ATTR_LOG_LEVEL, DdmPreferences.DEFAULT_LOG_LEVEL.getStringValue()); 91 92 store.setDefault(ATTR_LOGCAT_FONT, 93 new FontData("Courier", 10, SWT.NORMAL).toString()); //$NON-NLS-1$ 94 95 store.setDefault(ATTR_HPROF_ACTION, HProfHandler.ACTION_OPEN); 96 97 store.setDefault(ATTR_TIME_OUT, DdmPreferences.DEFAULT_TIMEOUT); 98 } 99 100 /** 101 * Initializes the preferences of ddmlib and ddmuilib with values from the eclipse store. 102 */ setupPreferences()103 public synchronized static void setupPreferences() { 104 IPreferenceStore store = DdmsPlugin.getDefault().getPreferenceStore(); 105 106 DdmPreferences.setDebugPortBase(store.getInt(ATTR_DEBUG_PORT_BASE)); 107 DdmPreferences.setSelectedDebugPort(store.getInt(ATTR_SELECTED_DEBUG_PORT)); 108 DdmPreferences.setLogLevel(store.getString(ATTR_LOG_LEVEL)); 109 DdmPreferences.setInitialThreadUpdate(store.getBoolean(ATTR_DEFAULT_THREAD_UPDATE)); 110 DdmPreferences.setInitialHeapUpdate(store.getBoolean(ATTR_DEFAULT_HEAP_UPDATE)); 111 DdmUiPreferences.setThreadRefreshInterval(store.getInt(ATTR_THREAD_INTERVAL)); 112 DdmPreferences.setTimeOut(store.getInt(ATTR_TIME_OUT)); 113 } 114 } 115