List of usage examples for org.eclipse.jface.preference PreferenceStore getInt
@Override public int getInt(String name)
From source file:com.android.ddms.PrefsDialog.java
License:Apache License
/** * Do some one-time prep./* w ww.j a va 2s. c om*/ * * The original plan was to let the individual classes define their * own defaults, which we would get and then override with the config * file. However, PreferencesStore.load() doesn't trigger the "changed" * events, which means we have to pull the loaded config values out by * hand. * * So, we set the defaults, load the values from the config file, and * then run through and manually export the values. Then we duplicate * the second part later on for the "changed" events. */ public static void init() { PreferenceStore prefStore = mStore.getPreferenceStore(); if (prefStore == null) { // we have a serious issue here... Log.e("ddms", "failed to access both the user HOME directory and the system wide temp folder. Quitting."); System.exit(1); } // configure default values setDefaults(System.getProperty("user.home")); //$NON-NLS-1$ // listen for changes prefStore.addPropertyChangeListener(new ChangeListener()); // Now we initialize the value of the preference, from the values in the store. // First the ddm lib. DdmPreferences.setDebugPortBase(prefStore.getInt(PREFS_DEBUG_PORT_BASE)); DdmPreferences.setSelectedDebugPort(prefStore.getInt(PREFS_SELECTED_DEBUG_PORT)); DdmPreferences.setLogLevel(prefStore.getString(PREFS_LOG_LEVEL)); DdmPreferences.setInitialThreadUpdate(prefStore.getBoolean(PREFS_DEFAULT_THREAD_UPDATE)); DdmPreferences.setInitialHeapUpdate(prefStore.getBoolean(PREFS_DEFAULT_HEAP_UPDATE)); DdmPreferences.setTimeOut(prefStore.getInt(PREFS_TIMEOUT)); DdmPreferences.setProfilerBufferSizeMb(prefStore.getInt(PREFS_PROFILER_BUFFER_SIZE_MB)); DdmPreferences.setUseAdbHost(prefStore.getBoolean(PREFS_USE_ADBHOST)); DdmPreferences.setAdbHostValue(prefStore.getString(PREFS_ADBHOST_VALUE)); // some static values String out = System.getenv("ANDROID_PRODUCT_OUT"); //$NON-NLS-1$ DdmUiPreferences.setSymbolsLocation(out + File.separator + "symbols"); //$NON-NLS-1$ DdmUiPreferences.setAddr2LineLocation("arm-linux-androideabi-addr2line"); //$NON-NLS-1$ DdmUiPreferences.setAddr2LineLocation64("aarch64-linux-android-addr2line"); String traceview = System.getProperty("com.android.ddms.bindir"); //$NON-NLS-1$ if (traceview != null && traceview.length() != 0) { traceview += File.separator + DdmConstants.FN_TRACEVIEW; } else { traceview = DdmConstants.FN_TRACEVIEW; } DdmUiPreferences.setTraceviewLocation(traceview); // Now the ddmui lib DdmUiPreferences.setStore(prefStore); DdmUiPreferences.setThreadRefreshInterval(prefStore.getInt(PREFS_THREAD_REFRESH_INTERVAL)); }
From source file:com.android.ddms.UIThread.java
License:Apache License
/** * Set the size and position of the main window from the preference, and * setup listeners for control events (resize/move of the window) */// w w w . ja v a2 s .co m private void setSizeAndPosition(final Shell shell) { shell.setMinimumSize(400, 200); // get the x/y and w/h from the prefs PreferenceStore prefs = PrefsDialog.getStore(); int x = prefs.getInt(PrefsDialog.SHELL_X); int y = prefs.getInt(PrefsDialog.SHELL_Y); int w = prefs.getInt(PrefsDialog.SHELL_WIDTH); int h = prefs.getInt(PrefsDialog.SHELL_HEIGHT); // check that we're not out of the display area Rectangle rect = mDisplay.getClientArea(); // first check the width/height if (w > rect.width) { w = rect.width; prefs.setValue(PrefsDialog.SHELL_WIDTH, rect.width); } if (h > rect.height) { h = rect.height; prefs.setValue(PrefsDialog.SHELL_HEIGHT, rect.height); } // then check x. Make sure the left corner is in the screen if (x < rect.x) { x = rect.x; prefs.setValue(PrefsDialog.SHELL_X, rect.x); } else if (x >= rect.x + rect.width) { x = rect.x + rect.width - w; prefs.setValue(PrefsDialog.SHELL_X, rect.x); } // then check y. Make sure the left corner is in the screen if (y < rect.y) { y = rect.y; prefs.setValue(PrefsDialog.SHELL_Y, rect.y); } else if (y >= rect.y + rect.height) { y = rect.y + rect.height - h; prefs.setValue(PrefsDialog.SHELL_Y, rect.y); } // now we can set the location/size shell.setBounds(x, y, w, h); // add listener for resize/move shell.addControlListener(new ControlListener() { @Override public void controlMoved(ControlEvent e) { // get the new x/y Rectangle controlBounds = shell.getBounds(); // store in pref file PreferenceStore currentPrefs = PrefsDialog.getStore(); currentPrefs.setValue(PrefsDialog.SHELL_X, controlBounds.x); currentPrefs.setValue(PrefsDialog.SHELL_Y, controlBounds.y); } @Override public void controlResized(ControlEvent e) { // get the new w/h Rectangle controlBounds = shell.getBounds(); // store in pref file PreferenceStore currentPrefs = PrefsDialog.getStore(); currentPrefs.setValue(PrefsDialog.SHELL_WIDTH, controlBounds.width); currentPrefs.setValue(PrefsDialog.SHELL_HEIGHT, controlBounds.height); } }); }
From source file:com.android.ddms.UIThread.java
License:Apache License
/** * Set the size and position of the file explorer window from the * preference, and setup listeners for control events (resize/move of * the window)//w w w . jav a 2 s . c o m */ private void setExplorerSizeAndPosition(final Shell shell) { shell.setMinimumSize(400, 200); // get the x/y and w/h from the prefs PreferenceStore prefs = PrefsDialog.getStore(); int x = prefs.getInt(PrefsDialog.EXPLORER_SHELL_X); int y = prefs.getInt(PrefsDialog.EXPLORER_SHELL_Y); int w = prefs.getInt(PrefsDialog.EXPLORER_SHELL_WIDTH); int h = prefs.getInt(PrefsDialog.EXPLORER_SHELL_HEIGHT); // check that we're not out of the display area Rectangle rect = mDisplay.getClientArea(); // first check the width/height if (w > rect.width) { w = rect.width; prefs.setValue(PrefsDialog.EXPLORER_SHELL_WIDTH, rect.width); } if (h > rect.height) { h = rect.height; prefs.setValue(PrefsDialog.EXPLORER_SHELL_HEIGHT, rect.height); } // then check x. Make sure the left corner is in the screen if (x < rect.x) { x = rect.x; prefs.setValue(PrefsDialog.EXPLORER_SHELL_X, rect.x); } else if (x >= rect.x + rect.width) { x = rect.x + rect.width - w; prefs.setValue(PrefsDialog.EXPLORER_SHELL_X, rect.x); } // then check y. Make sure the left corner is in the screen if (y < rect.y) { y = rect.y; prefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, rect.y); } else if (y >= rect.y + rect.height) { y = rect.y + rect.height - h; prefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, rect.y); } // now we can set the location/size shell.setBounds(x, y, w, h); // add listener for resize/move shell.addControlListener(new ControlListener() { @Override public void controlMoved(ControlEvent e) { // get the new x/y Rectangle controlBounds = shell.getBounds(); // store in pref file PreferenceStore currentPrefs = PrefsDialog.getStore(); currentPrefs.setValue(PrefsDialog.EXPLORER_SHELL_X, controlBounds.x); currentPrefs.setValue(PrefsDialog.EXPLORER_SHELL_Y, controlBounds.y); } @Override public void controlResized(ControlEvent e) { // get the new w/h Rectangle controlBounds = shell.getBounds(); // store in pref file PreferenceStore currentPrefs = PrefsDialog.getStore(); currentPrefs.setValue(PrefsDialog.EXPLORER_SHELL_WIDTH, controlBounds.width); currentPrefs.setValue(PrefsDialog.EXPLORER_SHELL_HEIGHT, controlBounds.height); } }); }
From source file:com.android.ddms.UIThread.java
License:Apache License
private void createWidgets(final Shell shell) { Color darkGray = shell.getDisplay().getSystemColor(SWT.COLOR_DARK_GRAY); /*// w ww . j a v a 2s.co m * Create three areas: tool bar, split panels, status line */ shell.setLayout(new GridLayout(1, false)); // 1. panel area final Composite panelArea = new Composite(shell, SWT.BORDER); // make the panel area absorb all space panelArea.setLayoutData(new GridData(GridData.FILL_BOTH)); // 2. status line. mStatusLine = new Label(shell, SWT.NONE); // make status line extend all the way across mStatusLine.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); mStatusLine.setText("Initializing..."); /* * Configure the split-panel area. */ final PreferenceStore prefs = PrefsDialog.getStore(); Composite topPanel = new Composite(panelArea, SWT.NONE); final Sash sash = new Sash(panelArea, SWT.HORIZONTAL); sash.setBackground(darkGray); Composite bottomPanel = new Composite(panelArea, SWT.NONE); panelArea.setLayout(new FormLayout()); createTopPanel(topPanel, darkGray); mClipboard = new Clipboard(panelArea.getDisplay()); if (useOldLogCatView()) { createBottomPanel(bottomPanel); } else { createLogCatView(bottomPanel); } // form layout data FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(sash, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); topPanel.setLayoutData(data); final FormData sashData = new FormData(); if (prefs != null && prefs.contains(PREFERENCE_LOGSASH)) { sashData.top = new FormAttachment(0, prefs.getInt(PREFERENCE_LOGSASH)); } else { sashData.top = new FormAttachment(50, 0); // 50% across } sashData.left = new FormAttachment(0, 0); sashData.right = new FormAttachment(100, 0); sash.setLayoutData(sashData); data = new FormData(); data.top = new FormAttachment(sash, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(100, 0); bottomPanel.setLayoutData(data); // allow resizes, but cap at minPanelWidth sash.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { Rectangle sashRect = sash.getBounds(); Rectangle panelRect = panelArea.getClientArea(); int bottom = panelRect.height - sashRect.height - 100; e.y = Math.max(Math.min(e.y, bottom), 100); if (e.y != sashRect.y) { sashData.top = new FormAttachment(0, e.y); if (prefs != null) { prefs.setValue(PREFERENCE_LOGSASH, e.y); } panelArea.layout(); } } }); // add a global focus listener for all the tables mTableListener = new TableFocusListener(); // now set up the listener in the various panels if (useOldLogCatView()) { mLogPanel.setTableFocusListener(mTableListener); } else { mLogCatPanel.setTableFocusListener(mTableListener); } mEventLogPanel.setTableFocusListener(mTableListener); for (TablePanel p : mPanels) { if (p != null) { p.setTableFocusListener(mTableListener); } } mStatusLine.setText(""); }
From source file:com.android.ddms.UIThread.java
License:Apache License
private void createTopPanel(final Composite comp, Color darkGray) { final PreferenceStore prefs = PrefsDialog.getStore(); comp.setLayout(new FormLayout()); Composite leftPanel = new Composite(comp, SWT.NONE); final Sash sash = new Sash(comp, SWT.VERTICAL); sash.setBackground(darkGray);// w w w .ja v a 2s . co m Composite rightPanel = new Composite(comp, SWT.NONE); createLeftPanel(leftPanel); createRightPanel(rightPanel); FormData data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(0, 0); data.right = new FormAttachment(sash, 0); leftPanel.setLayoutData(data); final FormData sashData = new FormData(); sashData.top = new FormAttachment(0, 0); sashData.bottom = new FormAttachment(100, 0); if (prefs != null && prefs.contains(PREFERENCE_SASH)) { sashData.left = new FormAttachment(0, prefs.getInt(PREFERENCE_SASH)); } else { // position the sash 380 from the right instead of x% (done by using // FormAttachment(x, 0)) in order to keep the sash at the same // position // from the left when the window is resized. // 380px is just enough to display the left table with no horizontal // scrollbar with the default font. sashData.left = new FormAttachment(0, 380); } sash.setLayoutData(sashData); data = new FormData(); data.top = new FormAttachment(0, 0); data.bottom = new FormAttachment(100, 0); data.left = new FormAttachment(sash, 0); data.right = new FormAttachment(100, 0); rightPanel.setLayoutData(data); final int minPanelWidth = 60; // allow resizes, but cap at minPanelWidth sash.addListener(SWT.Selection, new Listener() { @Override public void handleEvent(Event e) { Rectangle sashRect = sash.getBounds(); Rectangle panelRect = comp.getClientArea(); int right = panelRect.width - sashRect.width - minPanelWidth; e.x = Math.max(Math.min(e.x, right), minPanelWidth); if (e.x != sashRect.x) { sashData.left = new FormAttachment(0, e.x); if (prefs != null) { prefs.setValue(PREFERENCE_SASH, e.x); } comp.layout(); } } }); }
From source file:net.sourceforge.eclipsetrader.trading.internal.WatchlistTableViewer.java
License:Open Source License
public void updateView() { int index;/* w w w . ja v a 2s. co m*/ TableColumn tableColumn; String[] items = getView().getPreferenceStore().getString(WatchlistView.PREFS_SORTING).split(";"); if (items.length != 2) items = new String[] { "", "0" }; sortDirection = new Integer(items[1]).intValue(); index = 1; for (Iterator iter = getView().getWatchlist().getColumns().iterator(); iter.hasNext();) { WatchlistColumn column = (WatchlistColumn) iter.next(); String name = ""; int style = SWT.LEFT; Image image = null; ILabelProvider provider = ColumnRegistry.createLabelProvider(column.getId()); if (provider != null) { LogFactory.getLog(getClass()).debug("Adding column [" + column.getId() + "]"); name = ColumnRegistry.getName(column.getId()); style = ColumnRegistry.getOrientation(column.getId()); if (provider instanceof ITableLabelProvider) { name = ((ITableLabelProvider) provider).getColumnText(getView().getWatchlist(), index); image = ((ITableLabelProvider) provider).getColumnImage(getView().getWatchlist(), index); } } else LogFactory.getLog(getClass()).warn("Missing column [" + column.getId() + "]"); if (index < table.getColumnCount()) { tableColumn = table.getColumn(index); tableColumn.setAlignment(style); if (tableColumn.getData("labelProvider") != null) ((ILabelProvider) tableColumn.getData("labelProvider")).dispose(); } else { tableColumn = new EditableTableColumn(table, style); tableColumn.addControlListener(columnControlListener); tableColumn.addDisposeListener(new DisposeListener() { public void widgetDisposed(DisposeEvent e) { if (e.widget.getData("labelProvider") != null) ((ILabelProvider) e.widget.getData("labelProvider")).dispose(); } }); tableColumn.addSelectionListener(columnSelectionListener); } tableColumn.setText(name); tableColumn.setImage(image); tableColumn.setData(column); tableColumn.setData("labelProvider", provider); if (column.getId().equals(items[0])) sortColumn = index; index++; } while (index < table.getColumnCount()) table.getColumn(index).dispose(); list = new ArrayList(getView().getWatchlist().getItems()); if (sortColumn >= 1 && sortColumn < table.getColumnCount()) { table.setSortColumn(table.getColumn(sortColumn)); table.setSortDirection(sortDirection == 0 ? SWT.UP : SWT.DOWN); Collections.sort(list, comparator); } else { table.setSortColumn(null); sortColumn = -1; sortDirection = 0; } updateTableContents(); PreferenceStore preferences = getView().getPreferenceStore(); for (int i = 1; i < table.getColumnCount(); i++) { WatchlistColumn column = (WatchlistColumn) table.getColumn(i).getData(); preferences.setDefault(column.getId() + ".width", -1); int size = preferences.getInt(column.getId() + ".width"); if (size != -1) table.getColumn(i).setWidth(size); else table.getColumn(i).pack(); } if ("gtk".equals(SWT.getPlatform())) table.getColumn(table.getColumnCount() - 1).pack(); }
From source file:org.eclipsetrader.ui.internal.charts.DataImportJobTest.java
License:Open Source License
public void testGetDefaultYearsStartDate() throws Exception { PreferenceStore preferences = new PreferenceStore(); preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_METHOD, 1); preferences.setValue(UIActivator.PREFS_INITIAL_BACKFILL_YEARS, 5); Calendar c = Calendar.getInstance(); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.YEAR, -preferences.getInt(UIActivator.PREFS_INITIAL_BACKFILL_YEARS)); DataImportJob job = new DataImportJob(new Security("Test", null), 0, null, null, null); job.preferences = preferences;/* w ww .j a va 2s . c o m*/ assertEquals(c.getTime(), job.getDefaultStartDate()); }
From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java
License:Open Source License
public void testSaveStartDateBackfillMethod() throws Exception { PreferenceStore preferences = new PreferenceStore(); DefaultsPage page = new DefaultsPage(); page.setPreferenceStore(preferences); page.createContents(shell);/*from w ww.j av a2s. co m*/ page.useStartDate.setSelection(true); page.useYears.setSelection(false); page.performOk(); assertEquals(0, preferences.getInt(UIActivator.PREFS_INITIAL_BACKFILL_METHOD)); }
From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java
License:Open Source License
public void testSaveYearsBackfillMethod() throws Exception { PreferenceStore preferences = new PreferenceStore(); DefaultsPage page = new DefaultsPage(); page.setPreferenceStore(preferences); page.createContents(shell);/* w w w . java 2 s. c o m*/ page.useStartDate.setSelection(false); page.useYears.setSelection(true); page.performOk(); assertEquals(1, preferences.getInt(UIActivator.PREFS_INITIAL_BACKFILL_METHOD)); }
From source file:org.eclipsetrader.ui.internal.charts.DefaultsPageTest.java
License:Open Source License
public void testSaveYears() throws Exception { PreferenceStore preferences = new PreferenceStore(); DefaultsPage page = new DefaultsPage(); page.setPreferenceStore(preferences); page.createContents(shell);//from w w w . jav a 2 s. com page.years.setSelection(5); page.performOk(); assertEquals(5, preferences.getInt(UIActivator.PREFS_INITIAL_BACKFILL_YEARS)); }