List of usage examples for org.eclipse.jface.preference IPreferenceStore getBoolean
boolean getBoolean(String name);
From source file:com.axmor.eclipse.typescript.editor.preferences.OverlayPreferenceStore.java
License:Open Source License
private void propagateProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target) { if (orgin.isDefault(key.fKey)) { if (!target.isDefault(key.fKey)) target.setToDefault(key.fKey); return;//from ww w . j a v a 2s . c o m } TypeDescriptor d = key.fDescriptor; if (BOOLEAN == d) { boolean originValue = orgin.getBoolean(key.fKey); boolean targetValue = target.getBoolean(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (DOUBLE == d) { double originValue = orgin.getDouble(key.fKey); double targetValue = target.getDouble(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (FLOAT == d) { float originValue = orgin.getFloat(key.fKey); float targetValue = target.getFloat(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (INT == d) { int originValue = orgin.getInt(key.fKey); int targetValue = target.getInt(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (LONG == d) { long originValue = orgin.getLong(key.fKey); long targetValue = target.getLong(key.fKey); if (targetValue != originValue) target.setValue(key.fKey, originValue); } else if (STRING == d) { String originValue = orgin.getString(key.fKey); String targetValue = target.getString(key.fKey); if (targetValue != null && originValue != null && !targetValue.equals(originValue)) target.setValue(key.fKey, originValue); } }
From source file:com.axmor.eclipse.typescript.editor.preferences.OverlayPreferenceStore.java
License:Open Source License
private void loadProperty(IPreferenceStore orgin, OverlayKey key, IPreferenceStore target, boolean forceInitialization) { TypeDescriptor d = key.fDescriptor;/*from w ww . ja v a 2s . c o m*/ if (BOOLEAN == d) { if (forceInitialization) target.setValue(key.fKey, true); target.setValue(key.fKey, orgin.getBoolean(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultBoolean(key.fKey)); } else if (DOUBLE == d) { if (forceInitialization) target.setValue(key.fKey, 1.0D); target.setValue(key.fKey, orgin.getDouble(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultDouble(key.fKey)); } else if (FLOAT == d) { if (forceInitialization) target.setValue(key.fKey, 1.0F); target.setValue(key.fKey, orgin.getFloat(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultFloat(key.fKey)); } else if (INT == d) { if (forceInitialization) target.setValue(key.fKey, 1); target.setValue(key.fKey, orgin.getInt(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultInt(key.fKey)); } else if (LONG == d) { if (forceInitialization) target.setValue(key.fKey, 1L); target.setValue(key.fKey, orgin.getLong(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultLong(key.fKey)); } else if (STRING == d) { if (forceInitialization) target.setValue(key.fKey, "1"); //$NON-NLS-1$ target.setValue(key.fKey, orgin.getString(key.fKey)); target.setDefault(key.fKey, orgin.getDefaultString(key.fKey)); } }
From source file:com.bdaum.zoom.ai.clarifai.internal.core.ClarifaiServiceProvider.java
License:Open Source License
@SuppressWarnings("unchecked") @Override/*from www.java 2 s . c om*/ public Prediction predict(byte[] jpeg) { Prediction prediction = null; ClarifaiActivator activator = ClarifaiActivator.getDefault(); ClarifaiClient client = activator.getClient(); if (client != null) { String modelId = activator.getModelId(); if (modelId != null) { IPreferenceStore preferenceStore = activator.getPreferenceStore(); String lang = preferenceStore.getString(PreferenceConstants.LANGUAGE); int maxConcepts = preferenceStore.getInt(PreferenceConstants.MAXCONCEPTS); double minConfidence = preferenceStore.getInt(PreferenceConstants.MINCONFIDENCE) * 0.01f; Model<?> model = getModel(client, modelId); ClarifaiInput input = ClarifaiInput.forInputValue(ClarifaiImage.of(jpeg)); ClarifaiResponse<?> response = model.predict().withInputs(input).withLanguage(lang) .withMaxConcepts(maxConcepts).withMinValue(minConfidence).executeSync(); ClarifaiStatus status = response.getStatus(); if (response.isSuccessful()) { List<Token> result = new ArrayList<>(20); for (ClarifaiOutput<Concept> clarifaiOutput : (List<ClarifaiOutput<Concept>>) response.get()) for (Concept concept : clarifaiOutput.data()) result.add(new Token(concept.name(), concept.value())); if (preferenceStore.getBoolean(PreferenceConstants.TRANSLATE)) { TranslatorClient translatorClient = AiActivator.getDefault().getClient(); if (translatorClient != null) { StringBuilder sb = new StringBuilder(); for (Token tok : result) { if (sb.length() > 0) sb.append(", "); //$NON-NLS-1$ sb.append(tok.getLabel()); } try { String translate = translatorClient.translate(sb.toString()); StringTokenizer st = new StringTokenizer(translate, ","); //$NON-NLS-1$ Iterator<Token> it = result.iterator(); while (st.hasMoreTokens() && it.hasNext()) it.next().setLabel(st.nextToken().trim()); } catch (Exception e) { // don't translate } } } prediction = new Prediction(getName(), result.toArray(new Token[result.size()]), null, getStatus(status)); if (checkAdultContent()) { ClarifaiResponse<List<ClarifaiOutput<Concept>>> response2 = client.getDefaultModels() .nsfwModel().predict().withInputs(input).executeSync(); if (response2.isSuccessful()) lp: for (ClarifaiOutput<Concept> clarifaiOutput : response2.get()) for (Concept concept : clarifaiOutput.data()) if (SAFE_FOR_WORK.equals(concept.name())) { prediction.setSafeForWork(concept.value(), -1f); break lp; } } List<Rectangle> rects = null; if (checkCelebrities()) { ClarifaiResponse<List<ClarifaiOutput<clarifai2.dto.prediction.Prediction>>> response4 = client .predict(CELEBRITIES_ID) .withInputs(ClarifaiInput.forInputValue(ClarifaiImage.of(jpeg))) .withMaxConcepts(maxConcepts).withMinValue(minConfidence).executeSync(); if (response4.isSuccessful()) { int height = 0; int width = 0; if (checkFaces()) { try (InputStream in = new ByteArrayInputStream(jpeg)) { BufferedImage image = ImageIO.read(in); height = image.getHeight(); width = image.getWidth(); rects = new ArrayList<>(); } catch (IOException e) { // should never happen } } for (ClarifaiOutput<clarifai2.dto.prediction.Prediction> clarifaiOutput : response4 .get()) for (clarifai2.dto.prediction.Prediction p : clarifaiOutput.data()) { if (p instanceof FaceConcepts) { FaceConcepts fc = (FaceConcepts) p; if (rects != null) { Crop crop = fc.boundingBox(); rects.add(new Rectangle((int) (crop.left() * width + 0.5f), (int) (crop.top() * height + 0.5f), (int) ((crop.right() - crop.left()) * width + 0.5f), (int) ((crop.bottom() - crop.top()) * height + 0.5f))); } for (Concept concept : fc.concepts()) result.add(new Token(concept.name(), concept.value())); } } if (rects != null) prediction.setFaces(rects); } } if (rects == null && checkFaces()) { Model<?> faceModel = client.getDefaultModels().faceDetectionModel(); ClarifaiResponse<?> response3 = faceModel.predict().withInputs(input).executeSync(); if (response3.isSuccessful()) { try (InputStream in = new ByteArrayInputStream(jpeg)) { BufferedImage image = ImageIO.read(in); int height = image.getHeight(); int width = image.getWidth(); rects = new ArrayList<>(); for (ClarifaiOutput<clarifai2.dto.prediction.Prediction> clarifaiOutput : (List<ClarifaiOutput<clarifai2.dto.prediction.Prediction>>) response3 .get()) for (clarifai2.dto.prediction.Prediction p : clarifaiOutput.data()) { Crop crop = p.asFaceDetection().boundingBox(); rects.add(new Rectangle((int) (crop.left() * width + 0.5f), (int) (crop.top() * height + 0.5f), (int) ((crop.right() - crop.left()) * width + 0.5f), (int) ((crop.bottom() - crop.top()) * height + 0.5f))); } prediction.setFaces(rects); } catch (IOException e) { // should never happen } } } return prediction; } else if (status.networkErrorOccurred()) return new Prediction(getName(), null, null, getStatus(status)); } } return null; }
From source file:com.bdaum.zoom.ai.clarifai.internal.preference.PagePart.java
License:Open Source License
@Override public void fillValues() { clientIdField.removeModifyListener(this); clientSecretField.removeModifyListener(this); IPreferenceStore preferenceStore = getPreferenceStore(); clientIdField.setText(preferenceStore.getString(PreferenceConstants.CLIENTID)); clientSecretField.setText(preferenceStore.getString(PreferenceConstants.CLIENTSECRET)); conceptField.setSelection(preferenceStore.getInt(PreferenceConstants.MAXCONCEPTS)); confidenceField.setSelection(preferenceStore.getInt(PreferenceConstants.MINCONFIDENCE)); aboveField.setSelection(preferenceStore.getInt(PreferenceConstants.MARKABOVE)); knownButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.MARKKNOWNONLY)); adultButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ADULTCONTENTS)); faceButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.FACES)); celebrityButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.CELEBRITIES)); translateButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.TRANSLATE)); ClarifaiActivator activator = ClarifaiActivator.getDefault(); activator.setAccountCredentials(clientIdField.getText().trim(), clientSecretField.getText().trim()); verifyAccountCredenials(100);/*from w ww . j a v a2 s .c om*/ modelCombo.setSelection(new StructuredSelection(ClarifaiActivator.getDefault().getTheme())); currentLanguage = preferenceStore.getString(PreferenceConstants.LANGUAGE); languageCombo.setSelection(new StructuredSelection(currentLanguage)); clientIdField.addModifyListener(this); clientSecretField.addModifyListener(this); }
From source file:com.bdaum.zoom.ai.internal.preference.AiPreferencePage.java
License:Open Source License
@Override protected void doFillValues() { IPreferenceStore preferenceStore = getPreferenceStore(); enableButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ENABLE)); keyField.setText(preferenceStore.getString(PreferenceConstants.TRANSLATORKEY)); }
From source file:com.bdaum.zoom.ai.msvision.internal.core.MsVisionServiceProvider.java
License:Open Source License
public Prediction predict(byte[] jpeg) { Prediction prediction = null;//from ww w . j a v a 2 s.co m MsVisionActivator activator = MsVisionActivator.getDefault(); VisionServiceRestClient client = activator.getClient(); List<String> features = new ArrayList<>(); features.add("Categories"); //$NON-NLS-1$ features.add("Tags"); //$NON-NLS-1$ if (generateDescription()) features.add("Description"); //$NON-NLS-1$ if (checkFaces()) features.add("Faces"); //$NON-NLS-1$ if (checkAdultContent()) features.add("Adult"); //$NON-NLS-1$ String[] details = checkCelebrities() ? CELEBRITIES : EMPTY; try (InputStream stream = new ByteArrayInputStream(jpeg)) { AnalysisResult analysisResult = client.analyzeImage(stream, features.toArray(new String[features.size()]), details); IPreferenceStore preferenceStore = activator.getPreferenceStore(); int maxConcepts = preferenceStore.getInt(PreferenceConstants.MAXCONCEPTS); float minConfidence = preferenceStore.getInt(PreferenceConstants.MINCONFIDENCE) * 0.01f; List<Token> cats = new ArrayList<>(); List<Category> categories = analysisResult.categories; if (categories != null) for (Category category : categories) cats.add(new Token(CategoryMessages.getString(category.name), (float) category.score)); if (cats.size() >= maxConcepts) cats = cats.subList(0, maxConcepts); Collections.sort(cats, TokenComparator.INSTANCE); List<Token> keywords = new ArrayList<>(); List<Tag> tags = analysisResult.tags; if (tags != null) for (Tag tag : tags) { double score = tag.confidence; if (score >= minConfidence) keywords.add(new Token(tag.name, (float) score)); } if (keywords.size() >= maxConcepts) keywords = keywords.subList(0, maxConcepts); Collections.sort(keywords, TokenComparator.INSTANCE); boolean trCats = preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_CATEGORIES) && !cats.isEmpty(); boolean trTags = preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_TAGS) && !keywords.isEmpty(); if (trCats || trTags) { TranslatorClient translatorClient = AiActivator.getDefault().getClient(); if (translatorClient != null) { StringBuilder sb = new StringBuilder(); if (trCats) { for (Token tok : cats) { if (sb.length() > 0) sb.append(", "); //$NON-NLS-1$ sb.append(tok.getLabel()); } } if (trTags && trCats) sb.append(" : "); //$NON-NLS-1$ int l = sb.length(); if (trTags) { for (Token tok : keywords) { if (sb.length() > l) sb.append(", "); //$NON-NLS-1$ sb.append(tok.getLabel()); } } String translate = translatorClient.translate(sb.toString()); String translatedCats = null; String translatedTags = null; if (trTags) { if (trCats) { int p = translate.indexOf(':'); if (p >= 0) { translatedCats = translate.substring(0, p); translatedTags = translate.substring(p + 1); } else translatedCats = translate; } else translatedTags = translate; } else if (trCats) translatedCats = translate; applyTranslation(translatedCats, cats); applyTranslation(translatedTags, keywords); } } prediction = new Prediction(SERVICENAME, cats.toArray(new Token[cats.size()]), keywords.toArray(new Token[keywords.size()]), Status.OK_STATUS); if (generateDescription()) { Description description = analysisResult.description; if (description != null) { List<Caption> captions = description.captions; if (!captions.isEmpty()) { List<Token> descriptions = new ArrayList<>(captions.size()); for (Caption caption : captions) descriptions.add(new Token(caption.text, (float) caption.confidence)); Collections.sort(descriptions, TokenComparator.INSTANCE); String descr = descriptions.get(0).getLabel(); if (preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_DESCRIPTION)) { TranslatorClient translatorClient = AiActivator.getDefault().getClient(); if (translatorClient != null) descr = translatorClient.translate(descr); } if (descr.length() > 1) descr = Character.toUpperCase(descr.charAt(0)) + descr.substring(1); prediction.setDescription(descr); } } } if (checkFaces()) { List<Rectangle> rects = new ArrayList<>(); List<Face> faces = analysisResult.faces; if (faces != null) for (Face face : faces) { FaceRectangle faceRectangle = face.faceRectangle; rects.add(new Rectangle(faceRectangle.left, faceRectangle.top, faceRectangle.width, faceRectangle.height)); } prediction.setFaces(rects); } if (checkAdultContent()) { Adult adult = analysisResult.adult; boolean isAdultContent = adult != null && adult.isAdultContent; boolean isRacyContent = adult != null && adult.isRacyContent; prediction.setSafeForWork(isAdultContent ? 0f : 1f, isRacyContent ? 0f : 1f); } return prediction; } catch (VisionServiceException e) { return new Prediction(SERVICENAME, null, null, new Status(IStatus.ERROR, MsVisionActivator.PLUGIN_ID, Messages.MsVisionServiceProvider_ms_vision_exception, e)); } catch (IOException e) { return new Prediction(SERVICENAME, null, null, new Status(IStatus.ERROR, MsVisionActivator.PLUGIN_ID, Messages.MsVisionServiceProvider_ms_vision_io_error, e)); } }
From source file:com.bdaum.zoom.ai.msvision.internal.preference.PagePart.java
License:Open Source License
@Override public void fillValues() { keyField.removeModifyListener(this); IPreferenceStore preferenceStore = getPreferenceStore(); keyField.setText(preferenceStore.getString(PreferenceConstants.KEY)); conceptField.setSelection(preferenceStore.getInt(PreferenceConstants.MAXCONCEPTS)); confidenceField.setSelection(preferenceStore.getInt(PreferenceConstants.MINCONFIDENCE)); aboveField.setSelection(preferenceStore.getInt(PreferenceConstants.MARKABOVE)); knownButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.MARKKNOWNONLY)); adultButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.ADULTCONTENTS)); faceButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.FACES)); celebrityButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.CELEBRITIES)); descriptionButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.DESCRIPTION)); translateDescriptionButton/*from w w w . j a v a 2 s. c om*/ .setSelection(preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_DESCRIPTION)); translateCatButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_CATEGORIES)); translateTagButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.TRANSLATE_TAGS)); MsVisionActivator activator = MsVisionActivator.getDefault(); activator.setAccountCredentials(keyField.getText().trim()); verifyAccountCredenials(100); keyField.addModifyListener(this); updateButtons(); }
From source file:com.bdaum.zoom.gps.internal.preferences.GpsPreferencePage.java
License:Open Source License
@Override protected void doFillValues() { IPreferenceStore preferenceStore = getPreferenceStore(); altitudeButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.UPDATEALTITUDE)); coordinateButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.INCLUDECOORDINATES)); placenameButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.INCLUDENAMES)); editButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.EDIT)); tagButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.OVERWRITE)); waypointButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.USEWAYPOINTS)); timeShiftMinuteField.setSelection(preferenceStore.getInt(PreferenceConstants.TIMESHIFT)); toleranceHourField.setSelection(preferenceStore.getInt(PreferenceConstants.TOLERANCE) / 60); toleranceMinuteField.setSelection(preferenceStore.getInt(PreferenceConstants.TOLERANCE) % 60); GpsUtilities.getGeoAreas(preferenceStore, nogoAreas); nogoViewer.setInput(nogoAreas);//www. j a va2 s . c om reqhField.setSelection(preferenceStore.getInt(PreferenceConstants.HOURLYLIMIT)); String nservice = preferenceStore.getString(PreferenceConstants.NAMINGSERVICE); setNamingServiceCombo(nservice); for (IGeocodingService service : GpsActivator.getDefault().getNamingServices()) for (Parameter parameter : service.getParameters()) { CheckedText field = keyMap.get(parameter.getId()); field.setText(preferenceStore.getString(parameter.getId())); field.setHint(parameter.getHint()); } }
From source file:com.bdaum.zoom.ui.internal.preferences.AppearancePreferencePage.java
License:Open Source License
@Override protected void doFillValues() { IPreferenceStore preferenceStore = getPreferenceStore(); theme = preferenceStore.getString(PreferenceConstants.BACKGROUNDCOLOR); colorViewer.setSelection(new StructuredSelection(theme)); distViewer/*from w w w . java 2 s. c o m*/ .setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.DISTANCEUNIT))); dimViewer.setSelection(new StructuredSelection(preferenceStore.getString(PreferenceConstants.DIMUNIT))); locationButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWLOCATION)); doneButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWDONEMARK)); regionField.setSelection(preferenceStore.getInt(PreferenceConstants.MAXREGIONS)); String rating = preferenceStore.getString(PreferenceConstants.SHOWRATING); int r = 1; for (int i = 0; i < ratingOptions.length; i++) if (ratingOptions[i].equals(rating)) { r = i; break; } showRatingGroup.setSelection(r); rotateButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWROTATEBUTTONS)); voiceNoteButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWVOICENOTE)); expandButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.SHOWEXPANDCOLLAPSE)); labelConfigGroup.setSelection(preferenceStore.getInt(PreferenceConstants.SHOWLABEL), preferenceStore.getString(PreferenceConstants.THUMBNAILTEMPLATE), preferenceStore.getInt(PreferenceConstants.LABELFONTSIZE)); updateButtons(); }
From source file:com.bdaum.zoom.ui.internal.preferences.ApplicationPreferencePage.java
License:Open Source License
@Override protected void doFillValues() { IPreferenceStore preferenceStore = getPreferenceStore(); menuButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.HIDE_MENU_BAR)); statusButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.HIDE_STATUS_BAR)); String mode = preferenceStore.getString(PreferenceConstants.TRAY_MODE); trayButtonGroup.setSelection(PreferenceConstants.TRAY_PROMPT.equals(mode) ? 2 : PreferenceConstants.TRAY_TRAY.equalsIgnoreCase(mode) ? 0 : 1); trashButton.setSelection(preferenceStore.getBoolean(PreferenceConstants.FORCEDELETETRASH)); }