org.jdesktop.swingx.prompt.PromptSupport Java Examples

The following examples show how to use org.jdesktop.swingx.prompt.PromptSupport. 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: AddFilterRuleDialog.java    From AndroidStringsOneTabTranslation with Apache License 2.0 6 votes vote down vote up
protected JComponent doCreateCenterPanel() {
    JPanel panel = new JPanel(new BorderLayout(5, 0));

    FilterRule.FilterRuleType[] types = FilterRule.FilterRuleType.values();

    ruleType = new ComboBox(types);
    ruleType.setEnabled(true);
    ruleType.setSelectedIndex(0);

    panel.add(ruleType, BorderLayout.WEST);

    filterName = new JTextField(20);
    PromptSupport.setPrompt("Set the string name here", filterName);
    panel.add(filterName, BorderLayout.CENTER);

    return panel;
}
 
Example #2
Source File: DesktopTextField.java    From cuba with Apache License 2.0 6 votes vote down vote up
@Override
public void setInputPrompt(String inputPrompt) {
    this.inputPrompt = inputPrompt;

    if ((!isEditableWithParent() || !this.impl.isEnabled()) && StringUtils.isNotBlank(inputPrompt)) {
        return;
    }

    if (StringUtils.isNotBlank(inputPrompt)) {
        // Save old tooltipText value to use it later
        String toolTipText = this.impl.getToolTipText();

        PromptSupport.setPrompt(inputPrompt, impl);

        // Use old tooltipText value because it was overwritten in org.jdesktop.swingx.prompt.PromptSupport.setPrompt()
        this.impl.setToolTipText(toolTipText);
    } else {
        PromptSupport.setPrompt(null, impl);
    }
}
 
Example #3
Source File: ValidationView2.java    From otroslogviewer with Apache License 2.0 6 votes vote down vote up
public ValidationView2() {
  super("validView", "Validation view 2", "View with validation,");
  jPanel = new JPanel(new MigLayout());
  tfName = new JTextField(20);
  PromptSupport.setPrompt("Enter name with uppercase", tfName);
  JLabel labelName = new JLabel("Name: ");
  labelName.setDisplayedMnemonic('m');
  labelName.setLabelFor(tfName);
  tfAge = new JTextField(20);
  PromptSupport.setPrompt("Enter age", tfAge);
  JLabel ageLabel = new JLabel("Age: ");
  ageLabel.setDisplayedMnemonic('a');
  ageLabel.setLabelFor(tfAge);
  jPanel.add(labelName);
  jPanel.add(tfName, "wrap");
  jPanel.add(ageLabel);
  jPanel.add(tfAge, "wrap");
}
 
Example #4
Source File: UIUtils.java    From snap-desktop with GNU General Public License v3.0 6 votes vote down vote up
public static void addPromptSupport(JComponent component, Property property, String promptText) {
    if (JTextComponent.class.isAssignableFrom(component.getClass())) {
        JTextComponent castedComponent = (JTextComponent) component;
        String text;
        if (File.class.isAssignableFrom(property.getType())) {
            text = promptText != null ? promptText :
                    String.format(FILE_FIELD_PROMPT, separateWords(property.getName()));
        } else {
            if (promptText == null) {
                text = property.getDescriptor().getDescription();
                if (StringUtils.isNullOrEmpty(text)) {
                    text = String.format(TEXT_FIELD_PROMPT, separateWords(property.getName()));
                }
            } else {
                text = promptText;
            }
        }
        PromptSupport.setPrompt(text, castedComponent);
        PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.HIDE_PROMPT, castedComponent);
    }
}
 
Example #5
Source File: DesktopTextArea.java    From cuba with Apache License 2.0 5 votes vote down vote up
@Override
public void setInputPrompt(String inputPrompt) {
    this.inputPrompt = inputPrompt;

    if (StringUtils.isNotBlank(inputPrompt)) {
        PromptSupport.setPrompt(inputPrompt, impl);
    } else {
        PromptSupport.setPrompt(null, impl);
    }
}
 
Example #6
Source File: DesktopTextField.java    From cuba with Apache License 2.0 5 votes vote down vote up
protected void refreshInputPrompt() {
    if (StringUtils.isNotBlank(inputPrompt)) {
        if (isEnabledWithParent() && isEditableWithParent()) {
            // Save old tooltipText value to use it later
            String toolTipText = this.impl.getToolTipText();

            PromptSupport.setPrompt(inputPrompt, impl);

            // Use old tooltipText value because it was overwritten in org.jdesktop.swingx.prompt.PromptSupport.setPrompt()
            this.impl.setToolTipText(toolTipText);
        } else {
            PromptSupport.setPrompt(null, impl);
        }
    }
}
 
Example #7
Source File: SwingTools.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Replaces {@link PromptSupport#setPrompt(String, JTextComponent)}, as that library contains a bug that can cause
 * the entire Studio UI to freeze permanently.
 *
 * @param promptText
 * 		the prompt text or {@code null} if an existing prompt text should be removed
 * @param textComponent
 * 		the text component for which the prompt should be, must not be {@code null}
 * @since 9.3.0
 */
public static void setPrompt(String promptText, JTextComponent textComponent) {
	if (textComponent == null) {
		throw new IllegalArgumentException("textComponent must not be null!");
	}

	PromptSupport.setPrompt(promptText, textComponent);
	PromptSupport.setForeground(PROMPT_TEXT_COLOR, textComponent);
	PromptSupport.setFontStyle(Font.ITALIC, textComponent);
	PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT, textComponent);

	// we already exchanged the map with a synchronized map in SwingX, nothing to do anymore
	if (!needToMakeSwingXWeakHashMapSynchronized.compareAndSet(false, true)) {
		return;
	}

	// we need to exchange the WeakHashMap with a synchronized one once (as it's the same instance all the time)
	// otherwise we can get a permanent freeze of the UI due to a broken map (https://mailinator.blogspot.com/2009/06/beautiful-race-condition.html)
	AccessController.doPrivileged((PrivilegedAction<Void>) () -> {
		try {
			PropertyChangeListener[] uiListener = textComponent.getPropertyChangeListeners("UI");
			for (PropertyChangeListener listener : uiListener) {
				if (listener instanceof AbstractUIChangeHandler) {
					Field installedWeakHashMap = AbstractUIChangeHandler.class.getDeclaredField("installed");
					installedWeakHashMap.setAccessible(true);
					Map mapObject = (Map) installedWeakHashMap.get(listener);
					if (mapObject instanceof WeakHashMap) {
						installedWeakHashMap.set(listener, Collections.synchronizedMap(mapObject));
					}
				}
			}
		} catch (NoSuchFieldException | IllegalAccessException e) {
			// should not happen
			LogService.getRoot().log(Level.SEVERE, "com.rapidminer.gui.tools.SwingTools.failed_hashmap_fix", e);
		}

		return null;
	});
}
 
Example #8
Source File: ValidationView.java    From otroslogviewer with Apache License 2.0 5 votes vote down vote up
public ValidationView() {
  super("validView", "Validation view", "View with validation,");
  jPanel = new JPanel(new MigLayout());
  tf = new JTextField(20);
  PromptSupport.setPrompt("Enter name with uppercase", tf);
  JLabel jLabel = new JLabel("Name: ");
  jLabel.setDisplayedMnemonic('m');
  jLabel.setLabelFor(tf);
  jPanel.add(jLabel);
  jPanel.add(tf);
}
 
Example #9
Source File: UIUtils.java    From snap-desktop with GNU General Public License v3.0 5 votes vote down vote up
public static void addPromptSupport(JComponent component, String text) {
    if (JTextComponent.class.isAssignableFrom(component.getClass())) {
        JTextComponent castedComponent = (JTextComponent) component;
        PromptSupport.setPrompt(text, castedComponent);
        PromptSupport.setFocusBehavior(PromptSupport.FocusBehavior.HIDE_PROMPT, castedComponent);
    }
}
 
Example #10
Source File: DatePicker.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public DatePicker() {
    ObjectRegistry.getInstance().getEventDispatcher().addEventHandler(EventType.SWITCH_LOCALE, this);
    setFormats("yyyy-MM-dd", "dd.MM.yyyy");
    getMonthView().setZoomable(true);
    getEditor().setPromptForeground(Color.LIGHT_GRAY);
    getEditor().setFocusBehavior(PromptSupport.FocusBehavior.SHOW_PROMPT);
    getEditor().setPrompt("YYYY-MM-DD");
}
 
Example #11
Source File: SettingConfigurable.java    From AndroidStringsOneTabTranslation with Apache License 2.0 4 votes vote down vote up
@Override
public void apply() throws ConfigurationException {
    Log.i("apply clicked");
    if (languageEngineBox == null || filterList == null
            || btnAddFilter == null || btnDeleteFilter == null
            || line1TextField == null || line2TextField == null)
        return;

    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();

    languageEngineChanged = false;
    propertiesComponent.setValue(StorageDataKey.SettingLanguageEngine, currentEngine.toName());

    switch (currentEngine) {
        case Bing: {
            if (!line1TextField.getText().trim().isEmpty()) {
                propertiesComponent.setValue(StorageDataKey.BingClientIdStored, line1TextField.getText());
                PromptSupport.setPrompt(line1TextField.getText(), line1TextField);
            }

            if (!line2TextField.getText().trim().isEmpty()) {
                propertiesComponent.setValue(StorageDataKey.BingClientSecretStored, line2TextField.getText());
                PromptSupport.setPrompt(line2TextField.getText(), line2TextField);
            }
            line1TextField.setText("");
            line2TextField.setText("");
        }
        break;
        case Google: {
            if (!line1TextField.getText().trim().isEmpty()) {
                propertiesComponent.setValue(StorageDataKey.GoogleApiKeyStored, line1TextField.getText());
                PromptSupport.setPrompt(line1TextField.getText(), line1TextField);
            }
            line1TextField.setText("");
        }
        break;
    }
    languageEngineBox.requestFocus();

    filterRulesChanged = false;
    propertiesComponent.setValue(StorageDataKey.SettingFilterRules,
            SerializeUtil.serializeFilterRuleList(filterRules));
}
 
Example #12
Source File: SettingConfigurable.java    From AndroidStringsOneTabTranslation with Apache License 2.0 4 votes vote down vote up
private void initUI(TranslationEngineType engineType) {
    if (settingPanel == null)
        return;

    PropertiesComponent propertiesComponent = PropertiesComponent.getInstance();
    switch (engineType) {
        case Bing: {
            line1Text.setText("Client Id:");
            line2Text.setText("Client secret:");
            line2Text.setVisible(true);

            line2TextField.setVisible(true);

            howToLabel.setText(BING_HOW_TO);
            howToLabel.removeMouseMotionListener(googleHowTo);
            howToLabel.addMouseListener(bingHowTo);

            String bingClientIdStored = propertiesComponent.getValue(StorageDataKey.BingClientIdStored);
            String bingClientSecretStored = propertiesComponent.getValue(StorageDataKey.BingClientSecretStored);

            if (bingClientIdStored != null) {
                PromptSupport.setPrompt(bingClientIdStored, line1TextField);
            } else {
                PromptSupport.setPrompt(DEFAULT_CLIENT_ID, line1TextField);
            }
            line1TextField.setText("");

            if (bingClientSecretStored != null) {
                PromptSupport.setPrompt(bingClientSecretStored, line2TextField);
            } else {
                PromptSupport.setPrompt(DEFAULT_CLIENT_SECRET, line2TextField);
            }
            line2TextField.setText("");
        }
        break;
        case Google: {
            line1Text.setText("API key:");
            line2Text.setVisible(false);

            line2TextField.setVisible(false);

            howToLabel.setText(GOOGLE_HOW_TO);
            howToLabel.removeMouseListener(bingHowTo);
            howToLabel.addMouseListener(googleHowTo);

            String googleAPIKey = propertiesComponent.getValue(StorageDataKey.GoogleApiKeyStored);
            Log.i("apikey====" + PropertiesComponent.getInstance().getValue(StorageDataKey.GoogleApiKeyStored));
            if (googleAPIKey != null) {
                PromptSupport.setPrompt(googleAPIKey, line1TextField);
            } else {
                PromptSupport.setPrompt(DEFAULT_GOOGLE_API_KEY, line1TextField);
            }
            line1TextField.setText("");
        }
        break;
    }
}