This is an automated email from the ASF dual-hosted git repository. lkishalmi pushed a commit to branch revert-2039-NETBEANS-4039 in repository https://gitbox.apache.org/repos/asf/netbeans.git
commit 6738ea3f26d340543ff8abb53ba9708fb1123666 Author: Laszlo Kishalmi <[email protected]> AuthorDate: Sat Apr 18 07:37:22 2020 -0700 Revert "[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, 60 insertions(+), 117 deletions(-) diff --git a/ide/options.editor/nbproject/project.xml b/ide/options.editor/nbproject/project.xml index 47a637f..61f2d4f 100644 --- a/ide/options.editor/nbproject/project.xml +++ b/ide/options.editor/nbproject/project.xml @@ -26,15 +26,6 @@ <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 e1749de..dc98303 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,11 +71,9 @@ 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; -@ServiceProvider(service = PreferredColorProfileSupport.class) -public final class ColorModel implements PreferredColorProfileSupport { + +public final class ColorModel { private static final Logger LOG = Logger.getLogger(ColorModel.class.getName()); @@ -97,12 +95,6 @@ public final class ColorModel implements PreferredColorProfileSupport { 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); } @@ -299,13 +291,6 @@ public final class ColorModel implements PreferredColorProfileSupport { 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 10179c9..9fa948c 100644 --- a/platform/core.windows/apichanges.xml +++ b/platform/core.windows/apichanges.xml @@ -84,26 +84,6 @@ 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 92b06fe..0978ba6 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.92 +OpenIDE-Module-Specification-Version: 2.91 diff --git a/platform/core.windows/nbproject/project.xml b/platform/core.windows/nbproject/project.xml index 9ef0018..4d647f2 100644 --- a/platform/core.windows/nbproject/project.xml +++ b/platform/core.windows/nbproject/project.xml @@ -208,12 +208,13 @@ </test-dependency> </test-type> </test-dependencies> - <public-packages> + <friend-packages> + <friend>org.netbeans.core.multitabs</friend> + <friend>org.netbeans.core.nativeaccess</friend> <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> - </public-packages> + </friend-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 d94d2a0..08d949f 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,8 +22,10 @@ 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; @@ -39,7 +41,6 @@ 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; @@ -57,6 +58,7 @@ 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 ); @@ -65,8 +67,12 @@ public class LafPanel extends javax.swing.JPanel { this.controller = controller; initComponents(); // TODO listen to changes in form fields and call controller.changed() - checkMaximizeNativeLaF.addItemListener((ItemEvent e) -> { - fireChanged(); + checkMaximizeNativeLaF.addItemListener(new ItemListener() { + + @Override + public void itemStateChanged(ItemEvent e) { + fireChanged(); + } }); initLookAndFeel(); lblRestart.setVisible(!NO_RESTART_ON_LAF_CHANGE); @@ -75,14 +81,21 @@ public class LafPanel extends javax.swing.JPanel { model.addElement( li.getName() ); } comboLaf.setModel( model ); - comboLaf.addItemListener((ItemEvent e) -> { - fireChanged(); + comboLaf.addItemListener( new ItemListener() { + + @Override + public void itemStateChanged( ItemEvent e ) { + fireChanged(); + } }); } private void fireChanged() { - boolean isChanged = checkMaximizeNativeLaF.isSelected() != prefs.getBoolean(WinSysPrefs.MAXIMIZE_NATIVE_LAF, false); - isChanged |= comboLaf.getSelectedIndex() != lafs.indexOf(isForcedLaF() ? getCurrentLaF() : getPreferredLaF()); + boolean isChanged = false; + if (checkMaximizeNativeLaF.isSelected() != prefs.getBoolean(WinSysPrefs.MAXIMIZE_NATIVE_LAF, false) + || comboLaf.getSelectedIndex() != lafs.indexOf(isForcedLaF() ? getCurrentLaF() : getPreferredLaF())) { + isChanged = true; + } controller.changed(isChanged); } @@ -242,31 +255,54 @@ public class LafPanel extends javax.swing.JPanel { void selectDarkLookAndFeel() { comboLaf.requestFocusInWindow(); - SwingUtilities.invokeLater(() -> { - comboLaf.setPopupVisible( true ); + SwingUtilities.invokeLater( new Runnable() { + + @Override + public void run() { + 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; - boolean ret = false; - Collection<? extends PreferredColorProfileSupport> supports = Lookup.getDefault().lookupAll(PreferredColorProfileSupport.class); - for (PreferredColorProfileSupport support : supports) { - ret |= !preferredProfile.equals(support.getCurrentProfileName()); + 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 } - return ret; + return false; } private void switchEditorColorsProfile() { if( !isChangeEditorColorsPossible() ) return; String preferredProfile = getPreferredColorProfile(); + + ClassLoader cl = Lookup.getDefault().lookup( ClassLoader.class ); + if( null == cl ) + cl = LafPanel.class.getClassLoader(); try { - Lookup.getDefault().lookupAll(PreferredColorProfileSupport.class).forEach((supp) -> { - supp.setPreferredProfile(preferredProfile); - }); + 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 ); } 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 deleted file mode 100644 index f4bb946..0000000 --- a/platform/core.windows/src/org/netbeans/core/windows/options/spi/PreferredColorProfileSupport.java +++ /dev/null @@ -1,50 +0,0 @@ -/* - * 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: [email protected] For additional commands, e-mail: [email protected] For further information about the NetBeans mailing lists, visit: https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists
