You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@netbeans.apache.org by GitBox <gi...@apache.org> on 2021/01/16 02:42:11 UTC

[GitHub] [netbeans] junichi11 opened a new pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

junichi11 opened a new pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681


   https://issues.apache.org/jira/browse/NETBEANS-5245
   
   - Show a PHP Version of project properties on the status bar
   - We click a specific version number of the version list, we can change the PHP Version to it without opening a project properties dialog
   
   ![netbeans-5245-php-version-on-status-bar](https://user-images.githubusercontent.com/738383/104795145-7fed7200-57ef-11eb-9f67-40f72414d185.png)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559180116



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       I meant - if this is slow and blocking the UI, we would need to:
   - show Loading text here
   - start a bg thread which would do the work
   - once finished, the Loading text would be replaced with the PHP version
   
   Is this what you meant? Or...? Thanks!
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761840978


   @junichi11 
   
   I see. Thanks!
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559149073



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       e.g. `setText(Bundle.loading_message())`?




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559094162



##########
File path: php/php.project/nbproject/project.xml
##########
@@ -147,6 +147,15 @@
                         <specification-version>1.20</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>3</release-version>
+                        <specification-version>4.18</specification-version>

Review comment:
       As discussed in another PR, the specification version of php.project module should be increased too.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559205373



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       Perfect, thank you!
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761840672


   @junichi11 
   
   There are some CI failures - could you please have a look? Feel free to merge this PR if they are unrelated. Thank you!
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559198470



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       I see. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559131290



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    PhpProjectProperties projectProperties = new PhpProjectProperties((PhpProject) project);
+                    projectProperties.setPhpVersion(phpVersion.name());
+                    projectProperties.save();

Review comment:
       Exactly.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761752426


   @junichi11 
   
   In general, I am OK with this change, thanks for it! The only thing - we should really save the project properties in a background thread to avoid blocking of the UI.
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559139376



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {

Review comment:
       Great, thank you.
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559136462



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {

Review comment:
       Yes, we have `PhpProjectUtils.getPhpProject(FileObject)`. Will fix it. Thanks.




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559132084



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       (Otherwise some kind of "Loading..." would need to be added.)
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559131440



##########
File path: php/php.project/nbproject/project.xml
##########
@@ -147,6 +147,15 @@
                         <specification-version>1.20</specification-version>
                     </run-dependency>
                 </dependency>
+                <dependency>
+                    <code-name-base>org.netbeans.modules.editor.lib</code-name-base>
+                    <build-prerequisite/>
+                    <compile-dependency/>
+                    <run-dependency>
+                        <release-version>3</release-version>
+                        <specification-version>4.18</specification-version>

Review comment:
       Yes, will fix. Thanks!




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761299856


   I've implemented this based on https://github.com/apache/netbeans/blob/master/ide/editor/src/org/netbeans/modules/editor/impl/crlf/CRLFStatus.java
   as the first prototype: https://github.com/junichi11/netbeans/commit/613f5008c261f4dc01ffee5d6a3aa4a174c901ac
   
   I've added the label of PHP Version as a static field in it. Instead of that, I've created `PhpVersionLabel` class in this PR.


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-762539171


   @tmysik Thank you for your review!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559094770



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    PhpProjectProperties projectProperties = new PhpProjectProperties((PhpProject) project);
+                    projectProperties.setPhpVersion(phpVersion.name());
+                    projectProperties.save();

Review comment:
       It would be perhaps better to save it in a background thread...
   

##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {

Review comment:
       Don't we have any utility code for this already? :thinking: 
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761840561


   @tmysik Fixed: https://github.com/apache/netbeans/compare/83533a66fe05bed7e8cad7d280ea554cbe016e1a..b35e55a0d72cd6ad847186c9433310f3fcb79ad4 
   Please let me know if I'm wrong. 
   Maybe, there is a conflict(spec version) between the other PR and this. I'll rebase this after the other PR is merged. Thanks!


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#issuecomment-761751251


   > I've implemented this based on https://github.com/apache/netbeans/blob/master/ide/editor/src/org/netbeans/modules/editor/impl/crlf/CRLFStatus.java
   
   Good. This was done by @jlahoda if I am not wrong and this guy knows what he is doing :)
   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik merged pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik merged pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681


   


----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] tmysik commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
tmysik commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r559094549



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {

Review comment:
       This is done in the UI thread... hmm, hopefully it will be fast, ideally always :)
   




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists


[GitHub] [netbeans] junichi11 commented on a change in pull request #2681: [NETBEANS-5245] Show and change the PHP Version of project properties on the status bar

Posted by GitBox <gi...@apache.org>.
junichi11 commented on a change in pull request #2681:
URL: https://github.com/apache/netbeans/pull/2681#discussion_r558779850



##########
File path: php/php.project/src/org/netbeans/modules/php/project/ui/PhpVersionStatusLineElementProvider.java
##########
@@ -0,0 +1,258 @@
+/*
+ * 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.modules.php.project.ui;
+
+import java.awt.AWTEvent;
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Component;
+import java.awt.Dimension;
+import java.awt.EventQueue;
+import java.awt.FontMetrics;
+import java.awt.Insets;
+import java.awt.Point;
+import java.awt.Toolkit;
+import java.awt.event.AWTEventListener;
+import java.awt.event.MouseAdapter;
+import java.awt.event.MouseEvent;
+import java.util.ArrayList;
+import java.util.Collection;
+import javax.swing.BorderFactory;
+import javax.swing.DefaultListModel;
+import javax.swing.JLabel;
+import javax.swing.JList;
+import javax.swing.JPanel;
+import javax.swing.JSeparator;
+import javax.swing.JToolTip;
+import javax.swing.Popup;
+import javax.swing.PopupFactory;
+import javax.swing.SwingConstants;
+import javax.swing.border.Border;
+import javax.swing.border.LineBorder;
+import javax.swing.event.ListSelectionEvent;
+import javax.swing.text.Document;
+import javax.swing.text.JTextComponent;
+import org.netbeans.api.editor.EditorRegistry;
+import org.netbeans.api.project.FileOwnerQuery;
+import org.netbeans.api.project.Project;
+import org.netbeans.modules.editor.NbEditorUtilities;
+import org.netbeans.modules.php.api.PhpVersion;
+import org.netbeans.modules.php.project.PhpProject;
+import org.netbeans.modules.php.project.api.PhpLanguageProperties;
+import org.netbeans.modules.php.project.ui.customizer.PhpProjectProperties;
+import org.openide.awt.StatusLineElementProvider;
+import org.openide.filesystems.FileObject;
+import org.openide.util.lookup.ServiceProvider;
+
+/**
+ * Show a PHP Version of project properties on the status line.
+ *
+ * Available version numbers are shown when a version number is clicked. We
+ * click a specific version number of the version list, we can change the PHP
+ * Version to it without opening a project properties dialog.
+ */
+@ServiceProvider(service = StatusLineElementProvider.class)
+public class PhpVersionStatusLineElementProvider implements StatusLineElementProvider {
+
+    @Override
+    public Component getStatusLineElement() {
+        return panelWithSeparator(PhpVersionLabel.getInstance());
+    }
+
+    private static Component panelWithSeparator(JLabel cell) {
+        JSeparator separator = new JSeparator(SwingConstants.VERTICAL) {
+            private static final long serialVersionUID = 4857471448025818174L;
+
+            @Override
+            public Dimension getPreferredSize() {
+                return new Dimension(3, 3); // Y-unimportant -> gridlayout will stretch it
+            }
+        };
+        separator.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1));
+
+        JPanel panel = new JPanel(new BorderLayout());
+        panel.add(separator, BorderLayout.WEST);
+        panel.add(cell);
+        return panel;
+    }
+
+    //~ Inner classes
+    private static final class PhpVersionLabel extends JLabel {
+
+        private static final Insets NULL_INSETS = new Insets(0, 0, 0, 0);
+        private static final PhpVersionLabel INSTANCE = new PhpVersionLabel();
+        private static final long serialVersionUID = -3407578574821051662L;
+
+        static {
+            EditorRegistry.addPropertyChangeListener(propertyChangeEvent -> getInstance().updatePhpVersion());
+        }
+
+        private PhpVersionLabel() {
+            // show the version list when the label is clicked
+            addMouseListener(new MouseAdapterImpl());
+            initMinDimension(getPhpVersionStrings());
+        }
+
+        public static PhpVersionLabel getInstance() {
+            return INSTANCE;
+        }
+
+        @Override
+        public Point getToolTipLocation(MouseEvent event) {
+            // show the tooltip left side of the label
+            String toolTipText = getToolTipText(event);
+            JToolTip jToolTip = new JToolTip();
+            jToolTip.setTipText(toolTipText);
+            return new Point(-5 - jToolTip.getPreferredSize().width, 0);
+        }
+
+        private Collection<String> getPhpVersionStrings() {
+            Collection<String> phpVersionStrings = new ArrayList<>();
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                phpVersionStrings.add(phpVersion.getDisplayName());
+            }
+            return phpVersionStrings;
+        }
+
+        private void initMinDimension(Iterable<? extends String> maxStrings) {
+            FontMetrics fontMetrics = getFontMetrics(getFont());
+            int minWidth = 0;
+            for (String string : maxStrings) {
+                minWidth = Math.max(minWidth, fontMetrics.stringWidth(string));
+            }
+            Border border = getBorder();
+            Insets insets = (border != null) ? border.getBorderInsets(this) : NULL_INSETS;
+            minWidth += insets.left + insets.right;
+            int minHeight = fontMetrics.getHeight() + insets.top + insets.bottom;
+            setMinimumSize(new Dimension(minWidth, minHeight));
+            setPreferredSize(new Dimension(minWidth, minHeight));
+        }
+
+        private void updatePhpVersion() {
+            assert EventQueue.isDispatchThread();
+            final JTextComponent comp = EditorRegistry.focusedComponent();
+            if (comp != null) {
+                showPhpVersion(comp.getDocument());
+            } else {
+                clear();
+            }
+        }
+
+        private void showPhpVersion(Document document) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(document);
+            PhpVersion phpVersion = null;
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+                    if (phpVersion != null) {
+                        setToolTipText(((PhpProject) project).getName());
+                        setText(phpVersion.getDisplayName());
+                        setVisible(true);
+                    }
+                }
+            }
+            if (phpVersion == null) {
+                clear();
+            }
+        }
+
+        private void clear() {
+            setToolTipText(null);
+            setText(""); // NOI18N
+            setVisible(false);
+        }
+
+        private JList<PhpVersion> createPhpVersionList(JTextComponent component, FileObject fileObject) {
+            JList<PhpVersion> phpVersionList = new JList<>();
+            DefaultListModel<PhpVersion> model = new DefaultListModel<>();
+
+            for (PhpVersion phpVersion : PhpVersion.values()) {
+                model.addElement(phpVersion);
+            }
+
+            phpVersionList.setModel(model);
+            PhpVersion phpVersion = PhpLanguageProperties.forFileObject(fileObject).getPhpVersion();
+            phpVersionList.setSelectedValue(phpVersion, true);
+            phpVersionList.setBorder(new LineBorder(Color.GRAY, 1));
+
+            phpVersionList.addListSelectionListener((ListSelectionEvent e) -> {
+                savePhpVersion(component, phpVersionList.getSelectedValue());
+                showPhpVersion(component.getDocument());
+            });
+            return phpVersionList;
+        }
+
+        void showPhpVersionList() {
+            final JTextComponent component = EditorRegistry.focusedComponent();
+            if (component == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject == null) {
+                Toolkit.getDefaultToolkit().beep();
+                return;
+            }
+            final JList<PhpVersion> phpVersionList = createPhpVersionList(component, fileObject);
+            final Popup popup = getPopup(phpVersionList);
+            popup.show();
+        }
+
+        private Popup getPopup(JList<PhpVersion> phpVersionList) {
+            Point labelStart = getLocationOnScreen();
+            int x = Math.min(labelStart.x, labelStart.x + getSize().width - phpVersionList.getPreferredSize().width);
+            int y = labelStart.y - phpVersionList.getPreferredSize().height;
+
+            final Popup popup = PopupFactory.getSharedInstance().getPopup(this, phpVersionList, x, y);
+            final AWTEventListener multicastListener = new AWTEventListener() {
+                @Override
+                public void eventDispatched(AWTEvent event) {
+                    if (event instanceof MouseEvent && ((MouseEvent) event).getClickCount() > 0) {
+                        popup.hide();
+                        Toolkit.getDefaultToolkit().removeAWTEventListener(this);
+                    }
+                }
+            };
+            Toolkit.getDefaultToolkit().addAWTEventListener(multicastListener, AWTEvent.MOUSE_EVENT_MASK);
+            return popup;
+        }
+
+        private void savePhpVersion(JTextComponent component, PhpVersion phpVersion) {
+            FileObject fileObject = NbEditorUtilities.getFileObject(component.getDocument());
+            if (fileObject != null) {
+                Project project = FileOwnerQuery.getOwner(fileObject);
+                if (project instanceof PhpProject) {
+                    PhpProjectProperties projectProperties = new PhpProjectProperties((PhpProject) project);
+                    projectProperties.setPhpVersion(phpVersion.name());
+                    projectProperties.save();

Review comment:
       @tmysik I'm not sure whether this is OK/correct for you...




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
users@infra.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@netbeans.apache.org
For additional commands, e-mail: notifications-help@netbeans.apache.org

For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists