Java Code Examples for java.util.prefs.Preferences#getInt()

The following examples show how to use java.util.prefs.Preferences#getInt() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: BlazeActions.java    From constellation with Apache License 2.0 6 votes vote down vote up
private void updateSliders(final Graph graph) {
    final ReadableGraph rg = graph.getReadableGraph();
    try {
        Preferences preferences = NbPreferences.forModule(GraphPreferenceKeys.class);

        final int blazeSizeAttributeId = VisualConcept.GraphAttribute.BLAZE_SIZE.get(rg);
        final float blazeSize = blazeSizeAttributeId == Graph.NOT_FOUND
                ? (preferences.getInt(GraphPreferenceKeys.BLAZE_SIZE, GraphPreferenceKeys.BLAZE_SIZE_DEFAULT)) / 100f
                : rg.getFloatValue(blazeSizeAttributeId, 0);

        final int blazeOpacityAttributeId = VisualConcept.GraphAttribute.BLAZE_OPACITY.get(rg);
        final float blazeOpacity = blazeOpacityAttributeId == Graph.NOT_FOUND
                ? (preferences.getInt(GraphPreferenceKeys.BLAZE_OPACITY, GraphPreferenceKeys.BLAZE_OPACITY_DEFAULT)) / 100f
                : rg.getFloatValue(blazeOpacityAttributeId, 0);

        sizeSlider.removeChangeListener(sliderChangeListener);
        sizeSlider.setValue((int) (blazeSize * 100));
        sizeSlider.addChangeListener(sliderChangeListener);
        opacitySlider.removeChangeListener(sliderChangeListener);
        opacitySlider.setValue((int) (blazeOpacity * 100));
        opacitySlider.addChangeListener(sliderChangeListener);
    } finally {
        rg.release();
    }
}
 
Example 2
Source File: FilterRepository.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void load() throws IOException {
    filters.clear();
    active = -1;
    Preferences prefs = NbPreferences.forModule(FilterRepository.class);
    prefs = prefs.node("Filters"); //NOI18N
    active = prefs.getInt("active", -1);

    int count = prefs.getInt("count", 0); //NOI18N
    for (int i = 0; i < count; i++) {
        NotificationFilter filter = new NotificationFilter();
        try {
            filter.load(prefs, "Filter_" + i); //NOI18N
        } catch (BackingStoreException bsE) {
            throw new IOException("Cannot load filter repository", bsE);
        }
        filters.add(filter);
    }
}
 
Example 3
Source File: CodeStyleOperation.java    From editorconfig-netbeans with MIT License 6 votes vote down vote up
protected boolean operate(String simpleValueName, int value) {
  boolean codeStyleChangeNeeded = false;

  if (value < 0) {
    return false;
  }

  Preferences codeStyle = CodeStylePreferences.get(file, file.getMIMEType()).getPreferences();
  int currentValue = codeStyle.getInt(simpleValueName, -1);

  LOG.log(Level.INFO, "\u00ac Current value: {0}", currentValue);
  LOG.log(Level.INFO, "\u00ac New value: {0}", value);

  if (currentValue == value) {
    LOG.log(Level.INFO, "\u00ac No change needed");
  } else {
    codeStyle.putInt(simpleValueName, value);
    codeStyleChangeNeeded = true;
    LOG.log(Level.INFO, "\u00ac Changing value from \"{0}\" to \"{1}\"",
            new Object[]{currentValue, value});
  }

  return codeStyleChangeNeeded;
}
 
Example 4
Source File: Utilities.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** @deprecated
 * @see Formatter.insertTabString()
 */
public static String getTabInsertString(BaseDocument doc, int offset)
throws BadLocationException {
    int col = getVisualColumn(doc, offset);
    Preferences prefs = CodeStylePreferences.get(doc).getPreferences();
    boolean expandTabs = prefs.getBoolean(SimpleValueNames.EXPAND_TABS, EditorPreferencesDefaults.defaultExpandTabs);
    if (expandTabs) {
        int spacesPerTab = prefs.getInt(SimpleValueNames.SPACES_PER_TAB, EditorPreferencesDefaults.defaultSpacesPerTab);
        if (spacesPerTab <= 0) {
            return ""; //NOI18N
        }
        int len = (col + spacesPerTab) / spacesPerTab * spacesPerTab - col;
        return new String(Analyzer.getSpacesBuffer(len), 0, len);
    } else { // insert pure tab
        return "\t"; // NOI18N
    }
}
 
Example 5
Source File: Session.java    From FancyBing with GNU General Public License v3.0 6 votes vote down vote up
public void restoreLocation(Window window, Window owner, String name)
{
    int x = Integer.MIN_VALUE;
    int y = Integer.MIN_VALUE;
    Preferences prefs = getNode(name);
    if (prefs != null)
    {
        x = prefs.getInt("x", Integer.MIN_VALUE);
        y = prefs.getInt("y", Integer.MIN_VALUE);
    }
    if (x == Integer.MIN_VALUE || y == Integer.MIN_VALUE)
    {
        if (! window.isVisible())
            // use a platform-dependent default (setLocationByPlatform can
            // only be used, if window not already visible)
            window.setLocationByPlatform(true);
        return;
    }
    Point ownerLocation = owner.getLocation();
    setLocationChecked(window, x + ownerLocation.x,  y + ownerLocation.y);
}
 
Example 6
Source File: AddUnderscores.java    From netbeans with Apache License 2.0 5 votes vote down vote up
static int getSizeForRadix(Preferences prefs, int radix) {
    String key;
    int def;

    switch (radix) {
        case 2: key = KEY_SIZE_BINARY; def = 4; break;
        case 10: key = KEY_SIZE_DECIMAL; def = 3; break;
        case 16: key = KEY_SIZE_HEXADECIMAL; def = 4; break;
        default: throw new IllegalStateException("radix=" + radix);
    }

    return prefs.getInt(key, def);
}
 
Example 7
Source File: ProblemNotificationController.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public synchronized void updateNotifications() {
    LOG.log(Level.FINE, "Updating notifications for {0}", instance);
    Preferences prefs = instance.prefs().node("notifications"); // NOI18N
    for (HudsonJob job : instance.getJobs()) {
        if (!job.isSalient()) {
            LOG.log(Level.FINEST, "{0} is not being watched", job);
            continue;
        }
        int build = job.getLastCompletedBuild();
        if (prefs.getInt(job.getName(), 0) >= build) {
            LOG.log(Level.FINEST, "{0} was already notified", job);
            continue;
        }
        ProblemNotification n;
        Color color = job.getColor();
        LOG.log(Level.FINEST, "{0} has status {1}", new Object[] {job, color});
        switch (color) {
        case red:
        case red_anime:
            n = new ProblemNotification(job, build, true);
            break;
        case yellow:
        case yellow_anime:
            n = new ProblemNotification(job, build, false);
            break;
        case blue:
        case blue_anime:
            removeFormerNotifications(job, null);
            n = null;
            break;
        default:
            n = null;
        }
        if (n != null && notifications.add(n)) {
            prefs.putInt(job.getName(), build);
            n.add();
            removeFormerNotifications(job, n);
        }
    }
}
 
Example 8
Source File: RocPlot.java    From rtg-tools with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
  if (mFileChooserParent != null) {
    mFileChooser.setCurrentDirectory(mFileChooserParent);
  }

  final Preferences prefs = Preferences.userNodeForPackage(RocPlot.this.getClass());
  if (prefs.getInt(CHOOSER_WIDTH, -1) != -1 && prefs.getInt(CHOOSER_HEIGHT, -1) != -1) {
    mFileChooser.setPreferredSize(new Dimension(prefs.getInt(CHOOSER_WIDTH, 640), prefs.getInt(CHOOSER_HEIGHT, 480)));
  }
  if (mFileChooser.showOpenDialog(mMainPanel.getTopLevelAncestor()) == JFileChooser.APPROVE_OPTION) {
    final File[] files = mFileChooser.getSelectedFiles();
    for (File f : files) {
      try {
        loadFile(f, "", new ParseRocFile.NullProgressDelegate());
      } catch (final IOException | NoTalkbackSlimException e1) {
        JOptionPane.showMessageDialog(mMainPanel.getTopLevelAncestor(),
          "Could not open file: " + f.getPath() + "\n"
            + (e1.getMessage().length() > 100 ? e1.getMessage().substring(0, 100) + "..." : e1.getMessage()),
          "Invalid ROC File", JOptionPane.ERROR_MESSAGE);
      }
    }
  }
  final Dimension r = mFileChooser.getSize();
  prefs.putInt(CHOOSER_WIDTH, (int) r.getWidth());
  prefs.putInt(CHOOSER_HEIGHT, (int) r.getHeight());
}
 
Example 9
Source File: OutputOptions.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void loadColors(final Preferences preferences,
        final OutputOptions diskData) {
    int rgbStandard = preferences.getInt(PREFIX + PROP_COLOR_STANDARD,
            getDefaultColorStandard().getRGB());
    diskData.setColorStandard(new Color(rgbStandard));
    int rgbError = preferences.getInt(PREFIX + PROP_COLOR_ERROR,
            getDefaultColorError().getRGB());
    diskData.setColorError(new Color(rgbError));
    int rgbInput = preferences.getInt(PREFIX + PROP_COLOR_INPUT,
            getDefaultColorInput().getRGB());
    diskData.setColorInput(new Color(rgbInput));
    int rgbBackground = preferences.getInt(PREFIX + PROP_COLOR_BACKGROUND,
            getDefaultColorBackground().getRGB());
    diskData.setColorBackground(new Color(rgbBackground));
    int rgbLink = preferences.getInt(PREFIX + PROP_COLOR_LINK,
            getDefaultColorLink().getRGB());
    diskData.setColorLink(new Color(rgbLink));
    int rgbLinkImportant = preferences.getInt(
            PREFIX + PROP_COLOR_LINK_IMPORTANT,
            getDefaultColorLinkImportant().getRGB());
    diskData.setColorLinkImportant(new Color(rgbLinkImportant));
    int rgbDebug = preferences.getInt(
            PREFIX + PROP_COLOR_DEBUG,
            getDefaultColorDebug().getRGB());
    diskData.setColorDebug(new Color(rgbDebug));
    int rgbWarning = preferences.getInt(
            PREFIX + PROP_COLOR_WARNING,
            getDefaultColorWarning().getRGB());
    diskData.setColorWarning(new Color(rgbWarning));
    int rgbFailure = preferences.getInt(
            PREFIX + PROP_COLOR_FAILURE,
            getDefaultColorFailure().getRGB());
    diskData.setColorFailure(new Color(rgbFailure));
    int rgbSuccess = preferences.getInt(
            PREFIX + PROP_COLOR_SUCCESS,
            getDefaultColorSuccess().getRGB());
    diskData.setColorSuccess(new Color(rgbSuccess));
}
 
Example 10
Source File: Session.java    From FancyBing with GNU General Public License v3.0 5 votes vote down vote up
public void restoreLocation(Window window, String name)
{
    Preferences prefs = getNode(name);
    if (prefs == null)
        return;
    int x = prefs.getInt("x", Integer.MIN_VALUE);
    int y = prefs.getInt("y", Integer.MIN_VALUE);
    if (x == Integer.MIN_VALUE || y == Integer.MIN_VALUE)
        return;
    setLocationChecked(window, x, y);
}
 
Example 11
Source File: Main.java    From ProtocolAnalyzer with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Load the last saved settings of the CUL port from registry/config file
 */
public void loadCULPreferences() {
	Preferences p = Preferences.userNodeForPackage(this.getClass());
	pulsePort.setSerialPort(p.get("CULPort", pulsePort.getSerialPort()));
	int channel = p.getInt("CULChannel", pulsePort.getChannel().number);
	pulsePort.setChannel(channel == ArduinoProtocolPort.InputChannel.RF.number ?
			ArduinoProtocolPort.InputChannel.RF : ArduinoProtocolPort.InputChannel.IR);
	pulseFilter.setActive(p.getBoolean("PulseFilter", true));
}
 
Example 12
Source File: InputContext.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 13
Source File: InputContext.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 14
Source File: InputContext.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private AWTKeyStroke getInputMethodSelectionKeyStroke(Preferences root) {
    try {
        if (root.nodeExists(inputMethodSelectionKeyPath)) {
            Preferences node = root.node(inputMethodSelectionKeyPath);
            int keyCode = node.getInt(inputMethodSelectionKeyCodeName, KeyEvent.VK_UNDEFINED);
            if (keyCode != KeyEvent.VK_UNDEFINED) {
                int modifiers = node.getInt(inputMethodSelectionKeyModifiersName, 0);
                return AWTKeyStroke.getAWTKeyStroke(keyCode, modifiers);
            }
        }
    } catch (BackingStoreException bse) {
    }

    return null;
}
 
Example 15
Source File: Autosaver.java    From constellation with Apache License 2.0 5 votes vote down vote up
@Override
public void run() {
    StatusDisplayer.getDefault().setStatusText(String.format("Auto saving %s at %s...", "", new Date()));

    final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
    final boolean autosaveEnabled = prefs.getBoolean(ApplicationPreferenceKeys.AUTOSAVE_ENABLED, ApplicationPreferenceKeys.AUTOSAVE_ENABLED_DEFAULT);
    if (autosaveEnabled) {
        runAutosave();
    }

    final int autosaveSchedule = prefs.getInt(ApplicationPreferenceKeys.AUTOSAVE_SCHEDULE, ApplicationPreferenceKeys.AUTOSAVE_SCHEDULE_DEFAULT);
    final int delayMinutes = autosaveSchedule;
    schedule(delayMinutes);
}
 
Example 16
Source File: Autosaver.java    From constellation with Apache License 2.0 5 votes vote down vote up
/**
 * Schedule a new autosave.
 * <p>
 * A new task is always scheduled, regardless of whether autosave is enabled
 * or not. It is up to the task to determine whether autosave is enabled or
 * not and do the required work.
 *
 * @param delayMinutes The delay (in minutes) until the next autosave.
 */
public static void schedule(final int delayMinutes) {
    int dm = delayMinutes;
    if (dm <= 0) {
        final Preferences prefs = NbPreferences.forModule(ApplicationPreferenceKeys.class);
        final int autosaveSchedule = prefs.getInt(ApplicationPreferenceKeys.AUTOSAVE_SCHEDULE, ApplicationPreferenceKeys.AUTOSAVE_SCHEDULE_DEFAULT);
        dm = autosaveSchedule;
    }

    REQUEST_PROCESSOR.schedule(new Autosaver(), dm, TimeUnit.MINUTES);
}
 
Example 17
Source File: PerformanceTestCase.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/**
 * Turns off blinking of the caret in the editor. It is restored at the end
 * of test case in {@link #doMeasurement} method
 */
protected void disableEditorCaretBlinking() {
    Preferences prefs = getMimeLookupPreferences();
    defaultCaretBlinkRate = prefs.getInt(CARET_BLINK_RATE_KEY, 0);
    prefs.putInt(CARET_BLINK_RATE_KEY, 0);
    caretBlinkingDisabled = true;
}
 
Example 18
Source File: SizeSaver.java    From knopflerfish.org with BSD 3-Clause "New" or "Revised" License 4 votes vote down vote up
public void attach(Component _comp) {
  if(this.comp != null) {
    throw new IllegalStateException("SizeSaver can only be attach to one compoent. current component is " + this.comp);
  }
  this.comp = _comp;

  Dimension size = getSize();

  if(size != null) {
    // System.out.println("attach " + id + " size=" + size);
    comp.setSize(size);
    if(comp instanceof JComponent) {
      ((JComponent)comp).setPreferredSize(size);
    }
  }

  Preferences prefs = getPrefs();

  if(comp instanceof JFrame) {
    Toolkit tk = comp.getToolkit();
    if(tk.isFrameStateSupported(Frame.MAXIMIZED_VERT) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_HORIZ) ||
       tk.isFrameStateSupported(Frame.MAXIMIZED_BOTH)) {
      int state = prefs.getInt(KEY_STATE, Frame.NORMAL);
      ((Frame)comp).setExtendedState(state);
    }
    int x = prefs.getInt(KEY_X, 0);
    int y = prefs.getInt(KEY_Y, 0);
    // System.out.println("attach " + id + " pos=" + x + ", " + y);
    comp.setLocation(x, y);
  }

  if(comp instanceof JSplitPane) {
    JSplitPane split = (JSplitPane)comp;
    int pos = prefs.getInt(KEY_SPLITPOS, defSplit);
    if(pos != -1) {
      // System.out.println("attach " + id + " split=" + pos);
      split.setDividerLocation(pos);
      // Tell components that they may want to redo its layout
      Component parent = split.getParent();
      if (null!=parent) {
        parent.invalidate();
      } else {
        split.invalidate();
      }
    }

    splitListener = new ComponentAdapter() {
        public void 	componentResized(ComponentEvent e) {
          store();
        }
        public void 	componentMoved(ComponentEvent e) {
          store();
        }
      };

    split.getLeftComponent().addComponentListener(splitListener);
  }

  this.comp.addComponentListener(this);
}
 
Example 19
Source File: IntroduceFieldPanel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
/**
 * Constructs the dialog.
 * 
 * The `allowInitMethods' array contains two indexes. Possible init methods for the current occurrence only is at index 0,
 * possible init methods for all occurrences are at index 1.
 * @param name proposed field name
 * @param allowInitMethods contains INIT_bitfield for possible initialization methods. Null can be passed, meaning initialization from field.
 * @param numOccurrences number of other expression occurrences
 * @param allowFinalInCurrentMethod
 * @param variableRewrite allow to rename variable
 * @param type field/constant/variable
 * @param btnOk confirm button, to hook callbacks
 */
public IntroduceFieldPanel(String name, int[] allowInitMethods, int numOccurrences, boolean allowFinalInCurrentMethod, 
        boolean variableRewrite, int type, String prefNode, JButton btnOk) {
    this.elementType = type;
    this.btnOk = btnOk;
    
    initComponents();
    
    this.name.setText(name);
    if ( name != null && name.trim().length() > 0 && !variableRewrite) {
        this.name.setCaretPosition(name.length());
        this.name.setSelectionStart(0);
        this.name.setSelectionEnd(name.length());
    }

    if (variableRewrite) {
        this.name.setEditable(false);
    }
    
    this.allowInitMethods = allowInitMethods;
    this.replaceAll.setEnabled(numOccurrences > 1);
    this.allowFinalInCurrentMethod = allowFinalInCurrentMethod;
    this.preferences = NbPreferences.forModule( IntroduceFieldPanel.class ).node( prefNode ); //NOI18N
    Preferences pref = preferences;
    if( numOccurrences == 1 ) {
        replaceAll.setEnabled( false );
        replaceAll.setSelected( false );
    } else {
        replaceAll.setEnabled( true );
        // FIXME - I18N
        replaceAll.setText( replaceAll.getText() + " (" + numOccurrences + ")" );
        replaceAll.setSelected( pref.getBoolean("replaceAll", true) ); //NOI18N
    }
    
    if (isConstant()) {
        declareFinal.setEnabled(false);
        // value of declare final will be used in IntroduceFieldFix for constants, no special case in isDeclareFinal()
        declareFinal.setSelected(true);
    } else {
        declareFinal.setSelected( pref.getBoolean("declareFinal", true) ); //NOI18N
    }
    
    if (supportsAccess()) {
        int accessModifier = pref.getInt( "accessModifier", ACCESS_PRIVATE ); //NOI18N
        switch( accessModifier ) {
        case ACCESS_PUBLIC:
            accessPublic.setSelected( true );
            break;
        case ACCESS_PROTECTED:
            accessProtected.setSelected( true );
            break;
        case ACCESS_DEFAULT:
            accessDefault.setSelected( true );
            break;
        case ACCESS_PRIVATE:
            accessPrivate.setSelected( true );
            break;
        }
    } else {
        lblAccess.setVisible(false);
        accessPublic.setVisible(false);
        accessProtected.setVisible(false);
        accessDefault.setVisible(false);
        accessPrivate.setVisible(false);
    }
    
    changeSupport = new FieldNameSupport();
    changeSupport.setChangeListener(this);
    resetAccess();
    resetInit();
    adjustInitializeIn();
    adjustFinal();
}
 
Example 20
Source File: OneOfFilterCondition.java    From netbeans with Apache License 2.0 4 votes vote down vote up
void load( Preferences prefs, String prefix ) throws BackingStoreException {
    id = prefs.getInt( prefix+"_optionId", 0 ); //NOI18N
}