Example usage for org.eclipse.jface.preference PreferenceStore setValue

List of usage examples for org.eclipse.jface.preference PreferenceStore setValue

Introduction

In this page you can find the example usage for org.eclipse.jface.preference PreferenceStore setValue.

Prototype

@Override
    public void setValue(String name, boolean value) 

Source Link

Usage

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)
 *///from  w  ww . java  2  s .  c o  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)/*from  ww w .  j  a  va  2s. c om*/
 */
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);

    /*//from w  ww.j a v a  2  s  .c  om
     * 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);//  ww  w . j  a  v  a2 s .  c om
    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:com.android.ide.eclipse.common.preferences.UsagePreferencePage.java

License:Open Source License

private void save() {
    try {/*from  www  .j a v  a2s. c  o  m*/
        PreferenceStore store = SdkStatsService.getPreferenceStore();
        if (store != null) {
            store.setValue(SdkStatsService.PING_OPT_IN, mOptInCheckBox.getBooleanValue());
            store.save();
        }
    } catch (IOException e) {
        e.printStackTrace();
    }
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Generates a new random ping ID and saves it in the preference store.
 *
 * @return The new ping ID./*from   w w w  .j  a  v  a  2 s  .co m*/
 */
public long generateNewPingId() {
    PreferenceStore prefs = getPreferenceStore();

    Random rnd = new Random();
    long id = rnd.nextLong();

    synchronized (DdmsPreferenceStore.class) {
        prefs.setValue(PING_ID, id);
        try {
            prefs.save();
        } catch (IOException e) {
            /* ignore exceptions while saving preferences */
        }
    }

    return id;
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Saves the "ping opt in" value in the preference store.
 *
 * @param optIn The new user opt-in value.
 *///w  w  w. j av a2  s . co  m
public void setPingOptIn(boolean optIn) {
    PreferenceStore prefs = getPreferenceStore();

    synchronized (DdmsPreferenceStore.class) {
        prefs.setValue(PING_OPT_IN, optIn);
        try {
            prefs.save();
        } catch (IOException e) {
            /* ignore exceptions while saving preferences */
        }
    }
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Sets the ping time for the given app from the preference store.
 * Callers should use {@link System#currentTimeMillis()} for time stamps.
 *
 * @param app The app name identifier./*from  w w  w.j a  va  2s .c o  m*/
 * @param timeStamp The time stamp from the store.
 *                   0L is a special value that should not be used.
 */
public void setPingTime(String app, long timeStamp) {
    PreferenceStore prefs = getPreferenceStore();
    String timePref = PING_TIME + "." + app; //$NON-NLS-1$
    synchronized (DdmsPreferenceStore.class) {
        prefs.setValue(timePref, timeStamp);
        try {
            prefs.save();
        } catch (IOException ioe) {
            /* ignore exceptions while saving preferences */
        }
    }
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Sets whether the ADT startup wizard has been shown.
 * ADT sets first to false once the welcome wizard has been shown once.
 *
 * @param used true if ADT has been used
 *///from w  ww . j  a va2  s  . c  om
public void setAdtUsed(boolean used) {
    PreferenceStore prefs = getPreferenceStore();
    synchronized (DdmsPreferenceStore.class) {
        prefs.setValue(ADT_USED, used);
        try {
            prefs.save();
        } catch (IOException ioe) {
            /* ignore exceptions while saving preferences */
        }
    }
}

From source file:com.android.sdkstats.DdmsPreferenceStore.java

License:Apache License

/**
 * Sets the last SDK OS path./*w w w  . j ava2s. co m*/
 *
 * @param osSdkPath The SDK OS Path. Can be null or empty.
 */
public void setLastSdkPath(String osSdkPath) {
    PreferenceStore prefs = getPreferenceStore();
    synchronized (DdmsPreferenceStore.class) {
        prefs.setValue(LAST_SDK_PATH, osSdkPath);
        try {
            prefs.save();
        } catch (IOException ioe) {
            /* ignore exceptions while saving preferences */
        }
    }
}