Java Code Examples for java.awt.Toolkit#addPropertyChangeListener()

The following examples show how to use java.awt.Toolkit#addPropertyChangeListener() . 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: JBRCustomDecorations.java    From FlatLaf with Apache License 2.0 6 votes vote down vote up
private JBRWindowTopBorder() {
	super( 1, 0, 0, 0 );

	colorizationAffectsBorders = calculateAffectsBorders();
	activeColor = calculateActiveBorderColor();

	Toolkit toolkit = Toolkit.getDefaultToolkit();
	toolkit.addPropertyChangeListener( "win.dwm.colorizationColor.affects.borders", e -> {
		colorizationAffectsBorders = calculateAffectsBorders();
		activeColor = calculateActiveBorderColor();
	} );

	PropertyChangeListener l = e -> {
		activeColor = calculateActiveBorderColor();
	};
	toolkit.addPropertyChangeListener( "win.dwm.colorizationColor", l );
	toolkit.addPropertyChangeListener( "win.dwm.colorizationColorBalance", l );
	toolkit.addPropertyChangeListener( "win.frame.activeBorderColor", l );
}
 
Example 2
Source File: JFileChooser.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 3
Source File: JFileChooser.java    From jdk1.8-source-analysis with Apache License 2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 4
Source File: JFileChooser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 5
Source File: JFileChooser.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 6
Source File: JFileChooser.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 7
Source File: JFileChooser.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 8
Source File: JFileChooser.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 9
Source File: JFileChooser.java    From Java8CN with Apache License 2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 10
Source File: JFileChooser.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 11
Source File: JFileChooser.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 12
Source File: JFileChooser.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 13
Source File: DesktopProperty.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the value from the desktop.
 */
protected Object getValueFromDesktop() {
    Toolkit toolkit = Toolkit.getDefaultToolkit();

    if (pcl == null) {
        pcl = new WeakPCL(this, getKey(), UIManager.getLookAndFeel());
        toolkit.addPropertyChangeListener(getKey(), pcl);
    }

    return toolkit.getDesktopProperty(getKey());
}
 
Example 14
Source File: JFileChooser.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 15
Source File: JFileChooser.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 16
Source File: JFileChooser.java    From JDKSourceCode1.8 with MIT License 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 17
Source File: JFileChooser.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 18
Source File: JFileChooser.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 19
Source File: JFileChooser.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
private void installShowFilesListener() {
    // Track native setting for showing hidden files
    Toolkit tk = Toolkit.getDefaultToolkit();
    Object showHiddenProperty = tk.getDesktopProperty(SHOW_HIDDEN_PROP);
    if (showHiddenProperty instanceof Boolean) {
        useFileHiding = !((Boolean)showHiddenProperty).booleanValue();
        showFilesListener = new WeakPCL(this);
        tk.addPropertyChangeListener(SHOW_HIDDEN_PROP, showFilesListener);
    }
}
 
Example 20
Source File: FlatLaf.java    From FlatLaf with Apache License 2.0 4 votes vote down vote up
@Override
public void initialize() {
	if( SystemInfo.IS_MAC )
		initializeAqua();

	super.initialize();

	// install popup factory
	oldPopupFactory = PopupFactory.getSharedInstance();
	PopupFactory.setSharedInstance( new FlatPopupFactory() );

	// install mnemonic handler
	mnemonicHandler = new MnemonicHandler();
	mnemonicHandler.install();

	// listen to desktop property changes to update UI if system font or scaling changes
	if( SystemInfo.IS_WINDOWS ) {
		// Windows 10 allows increasing font size independent of scaling:
		//   Settings > Ease of Access > Display > Make text bigger (100% - 225%)
		desktopPropertyName = "win.messagebox.font";
	} else if( SystemInfo.IS_LINUX ) {
		// Linux/Gnome allows changing font in "Tweaks" app
		desktopPropertyName = "gnome.Gtk/FontName";

		// Linux/Gnome allows extra scaling and larger text:
		//   Settings > Devices > Displays > Scale (100% or 200%)
		//   Settings > Universal access > Large Text (off or on, 125%)
		//   "Tweaks" app > Fonts > Scaling Factor (0,5 - 3)
		desktopPropertyName2 = "gnome.Xft/DPI";
	}
	if( desktopPropertyName != null ) {
		desktopPropertyListener = e -> {
			String propertyName = e.getPropertyName();
			if( desktopPropertyName.equals( propertyName ) || propertyName.equals( desktopPropertyName2 ) )
				reSetLookAndFeel();
			else if( DESKTOPFONTHINTS.equals( propertyName ) ) {
				if( UIManager.getLookAndFeel() instanceof FlatLaf ) {
					putAATextInfo( UIManager.getLookAndFeelDefaults() );
					updateUILater();
				}
			}
		};
		Toolkit toolkit = Toolkit.getDefaultToolkit();
		toolkit.addPropertyChangeListener( desktopPropertyName, desktopPropertyListener );
		if( desktopPropertyName2 != null )
			toolkit.addPropertyChangeListener( desktopPropertyName2, desktopPropertyListener );
		toolkit.addPropertyChangeListener( DESKTOPFONTHINTS, desktopPropertyListener );
	}

	// Following code should be ideally in initialize(), but needs color from UI defaults.
	// Do not move this code to getDefaults() to avoid side effects in the case that
	// getDefaults() is directly invoked from 3rd party code. E.g. `new FlatLightLaf().getDefaults()`.
	postInitialization = defaults -> {
		// update link color in HTML text
		Color linkColor = defaults.getColor( "Component.linkColor" );
		if( linkColor != null ) {
			new HTMLEditorKit().getStyleSheet().addRule(
				String.format( "a { color: #%06x; }", linkColor.getRGB() & 0xffffff ) );
		}
	};

	// enable/disable window decorations, but only if system property is either
	// "true" or "false"; in other cases it is not changed
	Boolean useWindowDecorations = FlatSystemProperties.getBooleanStrict( FlatSystemProperties.USE_WINDOW_DECORATIONS, null );
	if( useWindowDecorations != null ) {
		oldFrameWindowDecorated = JFrame.isDefaultLookAndFeelDecorated();
		oldDialogWindowDecorated = JDialog.isDefaultLookAndFeelDecorated();
		JFrame.setDefaultLookAndFeelDecorated( useWindowDecorations );
		JDialog.setDefaultLookAndFeelDecorated( useWindowDecorations );
	}
}