This is an automated email from the ASF dual-hosted git repository. skygo pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/netbeans.git
The following commit(s) were added to refs/heads/master by this push: new ab6a2eb [NETBEANS-4039] Added SPI for Preferred Color Profile Changes new 5d9e62e Merge pull request #2039 from lkishalmi/NETBEANS-4039 ab6a2eb is described below commit ab6a2ebc89b93c73dc89800efb18c42bcb6b3911 Author: Laszlo Kishalmi <laszlo.kisha...@gmail.com> AuthorDate: Fri Mar 20 07:34:47 2020 -0700 [NETBEANS-4039] Added SPI for Preferred Color Profile Changes --- ide/options.editor/nbproject/project.xml | 9 +++ .../modules/options/colors/ColorModel.java | 19 +++++- platform/core.windows/apichanges.xml | 20 +++++++ platform/core.windows/manifest.mf | 2 +- platform/core.windows/nbproject/project.xml | 7 +-- .../netbeans/core/windows/options/LafPanel.java | 70 ++++++---------------- .../options/spi/PreferredColorProfileSupport.java | 50 ++++++++++++++++ 7 files changed, 117 insertions(+), 60 deletions(-) diff --git a/ide/options.editor/nbproject/project.xml b/ide/options.editor/nbproject/project.xml index 61f2d4f..47a637f 100644 --- a/ide/options.editor/nbproject/project.xml +++ b/ide/options.editor/nbproject/project.xml @@ -26,6 +26,15 @@ <code-name-base>org.netbeans.modules.options.editor</code-name-base> <module-dependencies> <dependency> + <code-name-base>org.netbeans.core.windows</code-name-base> + <build-prerequisite/> + <compile-dependency/> + <run-dependency> + <release-version>2</release-version> + <specification-version>2.92</specification-version> + </run-dependency> + </dependency> + <dependency> <code-name-base>org.netbeans.modules.editor</code-name-base> <build-prerequisite/> <compile-dependency/> diff --git a/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java b/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java index dc98303..e1749de 100644 --- a/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java +++ b/ide/options.editor/src/org/netbeans/modules/options/colors/ColorModel.java @@ -71,9 +71,11 @@ import org.openide.filesystems.FileUtil; import org.openide.text.CloneableEditorSupport; import org.openide.util.ImageUtilities; import org.openide.util.NbBundle; +import org.openide.util.lookup.ServiceProvider; +import org.netbeans.core.windows.options.spi.PreferredColorProfileSupport; - -public final class ColorModel { +@ServiceProvider(service = PreferredColorProfileSupport.class) +public final class ColorModel implements PreferredColorProfileSupport { private static final Logger LOG = Logger.getLogger(ColorModel.class.getName()); @@ -95,6 +97,12 @@ public final class ColorModel { return EditorSettings.getDefault().isCustomFontColorProfile (profile); } + @Override + public String getCurrentProfileName () { + String name = getCurrentProfile(); + return isCustomProfile(name) ? null : name; + } + public void setCurrentProfile (String profile) { EditorSettings.getDefault().setCurrentFontColorProfile (profile); } @@ -291,6 +299,13 @@ public final class ColorModel { return new Preview("test" + hashCode(), mimeType); //NOI18N } + @Override + public void setPreferredProfile(String profileName) { + setCurrentProfile(profileName); + Collection<AttributeSet> annotations = getAnnotations(profileName); + setAnnotations(profileName, annotations); + } + final class Preview extends JPanel { static final String PROP_CURRENT_ELEMENT = "currentAElement"; diff --git a/platform/core.windows/apichanges.xml b/platform/core.windows/apichanges.xml index 9fa948c..10179c9 100644 --- a/platform/core.windows/apichanges.xml +++ b/platform/core.windows/apichanges.xml @@ -84,6 +84,26 @@ is the proper place. <changes> + <change id="preferred-color-profile-spi" > + <api name="winsys"/> + <summary>Add SPI support for preferred color profile change.</summary> + <version major="2" minor="91"/> + <date day="18" month="3" year="2020"/> + <author login="lkishalmi"/> + <compatibility addition="yes" binary="compatible" source="compatible" semantic="compatible" deprecation="no" deletion="no" modification="no"/> + <description> + A new interface <code>PreferredColorProfileSupport</code> has been + added in order to let other modules reflect on preferred color profile + change when the user requests for that during Look and Feel change. + Look and Feels can register a color profile name as <code>String</code> + named <code>nb.preferred.color.profile</code> in their UIDefaults. + Changing the Look and Feel would offer the user to change the color + profile of additional components (most likely the Editor), if it's + current profile does not match the one preferred by the + selected Look and Feel. + </description> + <issue number="NETBEANS-4039"/> + </change> <change id="sort-editor-tabs" > <api name="winsys"/> <summary>Add preference for sorting editor tabs</summary> diff --git a/platform/core.windows/manifest.mf b/platform/core.windows/manifest.mf index 0978ba6..92b06fe 100644 --- a/platform/core.windows/manifest.mf +++ b/platform/core.windows/manifest.mf @@ -6,5 +6,5 @@ OpenIDE-Module-Provides: org.netbeans.core.WindowSystem, org.openide.windows.Win OpenIDE-Module-Recommends: org.netbeans.core.windows.nativeaccess.NativeWindowSystem AutoUpdate-Show-In-Client: false AutoUpdate-Essential-Module: true -OpenIDE-Module-Specification-Version: 2.91 +OpenIDE-Module-Specification-Version: 2.92 diff --git a/platform/core.windows/nbproject/project.xml b/platform/core.windows/nbproject/project.xml index 4d647f2..9ef0018 100644 --- a/platform/core.windows/nbproject/project.xml +++ b/platform/core.windows/nbproject/project.xml @@ -208,13 +208,12 @@ </test-dependency> </test-type> </test-dependencies> - <friend-packages> - <friend>org.netbeans.core.multitabs</friend> - <friend>org.netbeans.core.nativeaccess</friend> + <public-packages> <package>org.netbeans.core.windows.nativeaccess</package> <package>org.netbeans.core.windows.options</package> + <package>org.netbeans.core.windows.options.spi</package> <package>org.netbeans.core.windows.view.ui.tabcontrol</package> - </friend-packages> + </public-packages> </data> </configuration> </project> diff --git a/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java b/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java index 08d949f..d94d2a0 100644 --- a/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java +++ b/platform/core.windows/src/org/netbeans/core/windows/options/LafPanel.java @@ -22,10 +22,8 @@ package org.netbeans.core.windows.options; import java.awt.BorderLayout; import java.awt.Cursor; import java.awt.event.ItemEvent; -import java.awt.event.ItemListener; import java.awt.event.MouseAdapter; import java.awt.event.MouseEvent; -import java.lang.reflect.Method; import java.util.ArrayList; import java.util.Collection; import java.util.logging.Level; @@ -41,6 +39,7 @@ import javax.swing.SwingUtilities; import javax.swing.UIManager; import javax.swing.UIManager.LookAndFeelInfo; import javax.swing.UnsupportedLookAndFeelException; +import org.netbeans.core.windows.options.spi.PreferredColorProfileSupport; import org.netbeans.spi.options.OptionsPanelController; import org.openide.LifecycleManager; import org.openide.awt.Notification; @@ -58,7 +57,6 @@ public class LafPanel extends javax.swing.JPanel { private final Preferences prefs = NbPreferences.forModule(LafPanel.class); - private final boolean isAquaLaF = "Aqua".equals(UIManager.getLookAndFeel().getID()); //NOI18N private static final boolean NO_RESTART_ON_LAF_CHANGE = Boolean.getBoolean("nb.laf.norestart"); //NOI18N private int defaultLookAndFeelIndex; private final ArrayList<LookAndFeelInfo> lafs = new ArrayList<LookAndFeelInfo>( 10 ); @@ -67,12 +65,8 @@ public class LafPanel extends javax.swing.JPanel { this.controller = controller; initComponents(); // TODO listen to changes in form fields and call controller.changed() - checkMaximizeNativeLaF.addItemListener(new ItemListener() { - - @Override - public void itemStateChanged(ItemEvent e) { - fireChanged(); - } + checkMaximizeNativeLaF.addItemListener((ItemEvent e) -> { + fireChanged(); }); initLookAndFeel(); lblRestart.setVisible(!NO_RESTART_ON_LAF_CHANGE); @@ -81,21 +75,14 @@ public class LafPanel extends javax.swing.JPanel { model.addElement( li.getName() ); } comboLaf.setModel( model ); - comboLaf.addItemListener( new ItemListener() { - - @Override - public void itemStateChanged( ItemEvent e ) { - fireChanged(); - } + comboLaf.addItemListener((ItemEvent e) -> { + fireChanged(); }); } private void fireChanged() { - boolean isChanged = false; - if (checkMaximizeNativeLaF.isSelected() != prefs.getBoolean(WinSysPrefs.MAXIMIZE_NATIVE_LAF, false) - || comboLaf.getSelectedIndex() != lafs.indexOf(isForcedLaF() ? getCurrentLaF() : getPreferredLaF())) { - isChanged = true; - } + boolean isChanged = checkMaximizeNativeLaF.isSelected() != prefs.getBoolean(WinSysPrefs.MAXIMIZE_NATIVE_LAF, false); + isChanged |= comboLaf.getSelectedIndex() != lafs.indexOf(isForcedLaF() ? getCurrentLaF() : getPreferredLaF()); controller.changed(isChanged); } @@ -255,54 +242,31 @@ public class LafPanel extends javax.swing.JPanel { void selectDarkLookAndFeel() { comboLaf.requestFocusInWindow(); - SwingUtilities.invokeLater( new Runnable() { - - @Override - public void run() { - comboLaf.setPopupVisible( true ); - } + SwingUtilities.invokeLater(() -> { + comboLaf.setPopupVisible( true ); }); } - //Use reflection to instantiate ColorModel class and get/set the current profile - private static final String COLOR_MODEL_CLASS_NAME = "org.netbeans.modules.options.colors.ColorModel"; //NOI18N - private boolean isChangeEditorColorsPossible() { String preferredProfile = getPreferredColorProfile(); if( preferredProfile == null ) return false; - ClassLoader cl = Lookup.getDefault().lookup( ClassLoader.class ); - if( null == cl ) - cl = LafPanel.class.getClassLoader(); - try { - Class klz = cl.loadClass( COLOR_MODEL_CLASS_NAME ); - Object colorModel = klz.newInstance(); - Method m = klz.getDeclaredMethod( "getCurrentProfile", new Class[0] ); //NOI18N - Object res = m.invoke( colorModel, new Object[0] ); - return res != null && !preferredProfile.equals( res ); - } catch( Exception ex ) { - //ignore + boolean ret = false; + Collection<? extends PreferredColorProfileSupport> supports = Lookup.getDefault().lookupAll(PreferredColorProfileSupport.class); + for (PreferredColorProfileSupport support : supports) { + ret |= !preferredProfile.equals(support.getCurrentProfileName()); } - return false; + return ret; } private void switchEditorColorsProfile() { if( !isChangeEditorColorsPossible() ) return; String preferredProfile = getPreferredColorProfile(); - - ClassLoader cl = Lookup.getDefault().lookup( ClassLoader.class ); - if( null == cl ) - cl = LafPanel.class.getClassLoader(); try { - Class klz = cl.loadClass( COLOR_MODEL_CLASS_NAME ); - Object colorModel = klz.newInstance(); - Method m = klz.getDeclaredMethod( "getAnnotations", String.class ); //NOI18N - Object annotations = m.invoke( colorModel, preferredProfile ); - m = klz.getDeclaredMethod( "setAnnotations", String.class, Collection.class ); //NOI18N - m.invoke( colorModel, preferredProfile, annotations ); - m = klz.getDeclaredMethod( "setCurrentProfile", String.class ); //NOI18N - m.invoke( colorModel, preferredProfile ); + Lookup.getDefault().lookupAll(PreferredColorProfileSupport.class).forEach((supp) -> { + supp.setPreferredProfile(preferredProfile); + }); } catch( Exception ex ) { //ignore Logger.getLogger( LafPanel.class.getName() ).log( Level.INFO, "Cannot change editor colors profile.", ex ); //NOI18N diff --git a/platform/core.windows/src/org/netbeans/core/windows/options/spi/PreferredColorProfileSupport.java b/platform/core.windows/src/org/netbeans/core/windows/options/spi/PreferredColorProfileSupport.java new file mode 100644 index 0000000..f4bb946 --- /dev/null +++ b/platform/core.windows/src/org/netbeans/core/windows/options/spi/PreferredColorProfileSupport.java @@ -0,0 +1,50 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.netbeans.core.windows.options.spi; + +/** + * Whenever a component supports color profiles it can implement this interface + * in order to be updated when LaF change requested with a color profile change. + * + * @author lkishalmi + * @since 2.92 + */ +public interface PreferredColorProfileSupport { + /** + * This method shall try to set the current color profile of the supported + * component according to the provided profile name. The default profile + * name is usually called {@code "NetBeans"}. + * + * @param profileName the color profile name to be set. + * @since 2.92 + */ + void setPreferredProfile(String profileName); + + /** + * This method shall return the name of the current color profile used by + * the implementation. It can return <code>null</code> if this information + * cannot be determined (e.g. some user customized profile is in use). In + * that case the color profile change option will always be presented to + * the user. + * + * @return the current color profile name or <code>null</code>. + * @since 2.92 + */ + String getCurrentProfileName(); +} --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@netbeans.apache.org For additional commands, e-mail: commits-h...@netbeans.apache.org For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists