
org.gnome.gtk.PasswordEntry Maven / Gradle / Ivy
Show all versions of gtk Show documentation
// This file was automatically generated by Java-GI. Do not edit this file
// directly! Visit for more information.
//
// The API documentation in this file was derived from GObject-Introspection
// metadata and may include text or comments from the original C sources.
//
// Copyright (c), upstream authors as identified in the GObject-Introspection
// metadata.
//
// This generated file is distributed under the same license as the original
// GObject-Introspection data, unless otherwise specified. Users of this file
// are responsible for complying with any licenses or terms required by the
// original authors.
//
// THIS FILE IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE, AND NONINFRINGEMENT.
//
package org.gnome.gtk;
import io.github.jwharm.javagi.base.FunctionPointer;
import io.github.jwharm.javagi.base.GLibLogger;
import io.github.jwharm.javagi.gobject.InstanceCache;
import io.github.jwharm.javagi.gobject.SignalConnection;
import io.github.jwharm.javagi.gobject.types.Signals;
import io.github.jwharm.javagi.gobject.types.Types;
import io.github.jwharm.javagi.interop.Arenas;
import io.github.jwharm.javagi.interop.Interop;
import java.lang.FunctionalInterface;
import java.lang.String;
import java.lang.foreign.Arena;
import java.lang.foreign.FunctionDescriptor;
import java.lang.foreign.Linker;
import java.lang.foreign.MemorySegment;
import java.lang.foreign.ValueLayout;
import java.lang.invoke.MethodHandle;
import javax.annotation.processing.Generated;
import org.gnome.gio.MenuModel;
import org.gnome.glib.Type;
import org.gnome.gobject.GObject;
import org.gnome.gobject.TypeClass;
import org.gnome.gobject.Value;
import org.jetbrains.annotations.Nullable;
/**
* {@code GtkPasswordEntry} is an entry that has been tailored for entering secrets.
*
*
*
* It does not show its contents in clear text, does not allow to copy it
* to the clipboard, and it shows a warning when Caps Lock is engaged. If
* the underlying platform allows it, {@code GtkPasswordEntry} will also place
* the text in a non-pageable memory area, to avoid it being written out
* to disk by the operating system.
*
* Optionally, it can offer a way to reveal the contents in clear text.
*
* {@code GtkPasswordEntry} provides only minimal API and should be used with
* the {@link Editable} API.
*
* CSS Nodes
*
{@code
* entry.password
* ╰── text
* ├── image.caps-lock-indicator
* ┊
* }
*
* {@code GtkPasswordEntry} has a single CSS node with name entry that carries
* a .passwordstyle class. The text Css node below it has a child with
* name image and style class .caps-lock-indicator for the Caps Lock
* icon, and possibly other children.
*
* Accessibility
* {@code GtkPasswordEntry} uses the {@link org.gnome.gtk.AccessibleRole#TEXT_BOX} role.
*/
@Generated("io.github.jwharm.JavaGI")
public class PasswordEntry extends Widget implements Accessible, Buildable, ConstraintTarget, Editable {
static {
Gtk.javagi$ensureInitialized();
}
/**
* Create a PasswordEntry proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public PasswordEntry(MemorySegment address) {
super(Interop.reinterpret(address, getMemoryLayout().byteSize()));
}
/**
* Creates a {@code GtkPasswordEntry}.
*/
public PasswordEntry() {
this(constructNew());
InstanceCache.put(handle(), this);
}
/**
* Get the GType of the PasswordEntry class
*
* @return the GType
*/
public static Type getType() {
return Interop.getType("gtk_password_entry_get_type");
}
/**
* Returns this instance as if it were its parent type. This is mostly
* synonymous to the Java {@code super} keyword, but will set the native
* typeclass function pointers to the parent type. When overriding a native
* virtual method in Java, "chaining up" with {@code super.methodName()}
* doesn't work, because it invokes the overridden function pointer again.
* To chain up, call {@code asParent().methodName()}. This will call the
* native function pointer of this virtual method in the typeclass of the
* parent type.
*/
protected PasswordEntry asParent() {
PasswordEntry _parent = new PasswordEntry(handle());
_parent.callParent(true);
return _parent;
}
private static MemorySegment constructNew() {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_password_entry_new.invokeExact();
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result;
}
/**
* Gets the menu model set with gtk_password_entry_set_extra_menu().
*
* @return the menu model
*/
public MenuModel getExtraMenu() {
MemorySegment _result;
try {
_result = (MemorySegment) MethodHandles.gtk_password_entry_get_extra_menu.invokeExact(
handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
var _object = (MenuModel) InstanceCache.getForType(_result, MenuModel.MenuModelImpl::new, true);
if (_object instanceof GObject _gobject) {
GLibLogger.debug("Ref org.gnome.gio.MenuModel %ld", _gobject.handle().address());
_gobject.ref();
}
return _object;
}
/**
* Returns whether the entry is showing an icon to
* reveal the contents.
*
* @return {@code true} if an icon is shown
*/
public boolean getShowPeekIcon() {
int _result;
try {
_result = (int) MethodHandles.gtk_password_entry_get_show_peek_icon.invokeExact(
handle());
} catch (Throwable _err) {
throw new AssertionError(_err);
}
return _result != 0;
}
/**
* Sets a menu model to add when constructing
* the context menu for this PasswordEntry.
*
* @param model a {@code GMenuModel}
*/
public void setExtraMenu(@Nullable MenuModel model) {
try {
MethodHandles.gtk_password_entry_set_extra_menu.invokeExact(handle(),
(MemorySegment) (model == null ? MemorySegment.NULL : model.handle()));
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Sets whether the entry should have a clickable icon
* to reveal the contents.
*
* Setting this to {@code false} also hides the text again.
*
* @param showPeekIcon whether to show the peek icon
*/
public void setShowPeekIcon(boolean showPeekIcon) {
try {
MethodHandles.gtk_password_entry_set_show_peek_icon.invokeExact(handle(),
showPeekIcon ? 1 : 0);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* Emitted when the entry is activated.
*
* The keybindings for this signal are all forms of the Enter key.
*
* @param handler the signal handler
* @return a signal handler ID to keep track of the signal connection
* @see ActivateCallback#run
*/
public SignalConnection onActivate(ActivateCallback handler) {
try (Arena _arena = Arena.ofConfined()) {
try {
var _name = Interop.allocateNativeString("activate", _arena);
var _callbackArena = Arena.ofShared();
var _result = (int) (long) Signals.g_signal_connect_data.invokeExact(handle(),
_name, handler.toCallback(_callbackArena),
Arenas.cacheArena(_callbackArena), Arenas.CLOSE_CB_SYM, 0);
return new SignalConnection<>(handle(), _result);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
}
/**
* Emits the "activate" signal. See {@link #onActivate}.
*/
public void emitActivate() {
try (Arena _arena = Arena.ofConfined()) {
MemorySegment _name = Interop.allocateNativeString("activate", _arena);
Object[] _args = new Object[0];
Signals.g_signal_emit_by_name.invokeExact(handle(), _name, _args);
} catch (Throwable _err) {
throw new AssertionError(_err);
}
}
/**
* A {@link Builder} object constructs a {@code PasswordEntry}
* with the specified properties.
* Use the various {@code set...()} methods to set properties,
* and finish construction with {@link Builder#build()}.
*/
public static Builder extends Builder> builder() {
return new Builder<>();
}
/**
* Functional interface declaration of the {@code ActivateCallback} callback.
*
* @see ActivateCallback#run
*/
@FunctionalInterface
public interface ActivateCallback extends FunctionPointer {
/**
* Emitted when the entry is activated.
*
* The keybindings for this signal are all forms of the Enter key.
*/
void run();
/**
* The {@code upcall} method is called from native code. The parameters
* are marshaled and {@link #run} is executed.
*/
default void upcall(MemorySegment sourcePasswordEntry) {
run();
}
/**
* Creates a native function pointer to the {@link #upcall} method.
*
* @return the native function pointer
*/
default MemorySegment toCallback(Arena arena) {
FunctionDescriptor _fdesc = FunctionDescriptor.ofVoid(ValueLayout.ADDRESS);
MethodHandle _handle = Interop.upcallHandle(java.lang.invoke.MethodHandles.lookup(), ActivateCallback.class, _fdesc);
return Linker.nativeLinker().upcallStub(_handle.bindTo(this), _fdesc, arena);
}
}
public static class PasswordEntryClass extends TypeClass {
/**
* Create a PasswordEntryClass proxy instance for the provided memory address.
*
* @param address the memory address of the native object
*/
public PasswordEntryClass(MemorySegment address) {
super(address);
}
}
/**
* Inner class implementing a builder pattern to construct a GObject with
* properties.
*
* @param the type of the Builder that is returned
*/
public static class Builder> extends Widget.Builder implements Accessible.Builder, Editable.Builder {
/**
* Default constructor for a {@code Builder} object.
*/
protected Builder() {
}
/**
* Finish building the {@code PasswordEntry} object. This will call
* {@link GObject#withProperties} to create a new GObject instance,
* which is then cast to {@code PasswordEntry}.
*
* @return a new instance of {@code PasswordEntry} with the properties
* that were set in the Builder object.
*/
public PasswordEntry build() {
try {
var _instance = (PasswordEntry) GObject.withProperties(PasswordEntry.getType(), getNames(), getValues());
connectSignals(_instance.handle());
return _instance;
} finally {
for (Value _value : getValues()) _value.unset();
getArena().close();
}
}
/**
* Whether to activate the default widget when Enter is pressed.
*
* @param activatesDefault the value for the {@code activates-default} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setActivatesDefault(boolean activatesDefault) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.BOOLEAN);
_value.setBoolean(activatesDefault);
addBuilderProperty("activates-default", _value);
return (B) this;
}
/**
* A menu model whose contents will be appended to
* the context menu.
*
* @param extraMenu the value for the {@code extra-menu} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setExtraMenu(MenuModel extraMenu) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(MenuModel.getType());
_value.setObject((GObject) extraMenu);
addBuilderProperty("extra-menu", _value);
return (B) this;
}
/**
* The text that will be displayed in the {@code GtkPasswordEntry}
* when it is empty and unfocused.
*
* @param placeholderText the value for the {@code placeholder-text} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setPlaceholderText(String placeholderText) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.STRING);
_value.setString(placeholderText);
addBuilderProperty("placeholder-text", _value);
return (B) this;
}
/**
* Whether to show an icon for revealing the content.
*
* @param showPeekIcon the value for the {@code show-peek-icon} property
* @return the {@code Builder} instance is returned, to allow method chaining
*/
public B setShowPeekIcon(boolean showPeekIcon) {
Arena _arena = getArena();
Value _value = new Value(_arena);
_value.init(Types.BOOLEAN);
_value.setBoolean(showPeekIcon);
addBuilderProperty("show-peek-icon", _value);
return (B) this;
}
/**
* Emitted when the entry is activated.
*
* The keybindings for this signal are all forms of the Enter key.
*
* @param handler the signal handler
* @return the {@code Builder} instance is returned, to allow method chaining
* @see ActivateCallback#run
*/
public B onActivate(ActivateCallback handler) {
connect("activate", handler);
return (B) this;
}
}
private static final class MethodHandles {
static final MethodHandle gtk_password_entry_new = Interop.downcallHandle(
"gtk_password_entry_new", FunctionDescriptor.of(ValueLayout.ADDRESS), false);
static final MethodHandle gtk_password_entry_get_extra_menu = Interop.downcallHandle(
"gtk_password_entry_get_extra_menu", FunctionDescriptor.of(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_password_entry_get_show_peek_icon = Interop.downcallHandle(
"gtk_password_entry_get_show_peek_icon", FunctionDescriptor.of(ValueLayout.JAVA_INT,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_password_entry_set_extra_menu = Interop.downcallHandle(
"gtk_password_entry_set_extra_menu", FunctionDescriptor.ofVoid(ValueLayout.ADDRESS,
ValueLayout.ADDRESS), false);
static final MethodHandle gtk_password_entry_set_show_peek_icon = Interop.downcallHandle(
"gtk_password_entry_set_show_peek_icon",
FunctionDescriptor.ofVoid(ValueLayout.ADDRESS, ValueLayout.JAVA_INT), false);
}
}