/*
 * Copyright 2000-2016 Vaadin Ltd.
 *
 * Licensed 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 com.vaadin.ui;

import java.io.Serializable;
import java.util.Collection;
import java.util.Objects;

import org.jsoup.nodes.Attributes;
import org.jsoup.nodes.Element;

import com.vaadin.shared.ui.colorpicker.Color;
import com.vaadin.shared.ui.colorpicker.ColorPickerServerRpc;
import com.vaadin.shared.ui.colorpicker.AbstractColorPickerState;
import com.vaadin.ui.components.colorpicker.ColorPickerPopup;
import com.vaadin.ui.declarative.DesignAttributeHandler;
import com.vaadin.ui.declarative.DesignContext;

/**
 * An abstract class that defines default implementation for a color picker
 * component.
 *
 * @since 7.0.0
 */
public abstract class AbstractColorPicker extends AbstractField<Color> {

    /**
     * Interface for converting 2d-coordinates to a Color.
     */
    public interface Coordinates2Color extends Serializable {

        /**
         * Calculates a color from coordinates.
         *
         * @param x
         *            the x-coordinate
         * @param y
         *            the y-coordinate
         *
         * @return the color
         */
        public Color calculate(int x, int y);

        /**
         * Calculates coordinates from a color.
         *
         * @param c
         *            the c
         *
         * @return the integer array with the coordinates
         */
        public int[] calculate(Color c);
    }

    /**
     * The style of the color picker popup.
     */
    public enum PopupStyle {
        /** A full popup with all tabs visible. */
        POPUP_NORMAL("normal"),

        /** A simple popup with only the swatches (palette) tab. */
        POPUP_SIMPLE("simple");

        private final String style;

        PopupStyle(String styleName) {
            style = styleName;
        }

        @Override
        public String toString() {
            return style;
        }
    }

    private ColorPickerServerRpc rpc = this::showPopup;

    protected static final String STYLENAME_DEFAULT = "v-colorpicker";
    protected static final String STYLENAME_BUTTON = "v-button";
    protected static final String STYLENAME_AREA = "v-colorpicker-area";

    protected PopupStyle popupStyle = PopupStyle.POPUP_NORMAL;

    private ColorPickerPopup window;

    /** The currently selected color. */
    protected Color color;

    private UI parent;

    private String popupCaption = null;
    private int positionX = 0;
    private int positionY = 0;

    protected boolean rgbVisible = true;
    protected boolean hsvVisible = true;
    protected boolean swatchesVisible = true;
    protected boolean historyVisible = true;
    protected boolean textfieldVisible = true;

    /**
     * Instantiates a new color picker.
     */
    public AbstractColorPicker() {
        this("Colors", Color.WHITE);
    }

    /**
     * Instantiates a new color picker.
     *
     * @param popupCaption
     *            the caption of the popup window
     */
    public AbstractColorPicker(String popupCaption) {
        this(popupCaption, Color.WHITE);
    }

    /**
     * Instantiates a new color picker.
     *
     * @param popupCaption
     *            the caption of the popup window
     * @param initialColor
     *            the initial color
     */
    public AbstractColorPicker(String popupCaption, Color initialColor) {
        super();
        registerRpc(rpc);
        setValue(initialColor);
        this.popupCaption = popupCaption;
        setDefaultStyles();
        setCaption("");
    }

    /**
     * Returns the current selected color of this color picker.
     *
     * @return the selected color, not null
     */
    @Override
    public Color getValue() {
        return color;
    }

    /**
     * Sets the selected color of this color picker. If the new color is not
     * equal to getValue(), fires a {@link ValueChangeEvent}.
     *
     * @param color
     *            the new selected color, not null
     * @throws NullPointerException
     *             if {@code color} is {@code null}
     */
    @Override
    public void setValue(Color color) {
        Objects.requireNonNull(color, "color cannot be null");
        super.setValue(color);
    }

    /**
     * Set true if the component should show a default caption (css-code for the
     * currently selected color, e.g. #ffffff) when no other caption is
     * available.
     *
     * @param enabled
     *            {@code true} to enable the default caption, {@code false} to
     *            disable
     */
    public void setDefaultCaptionEnabled(boolean enabled) {
        getState().showDefaultCaption = enabled;
    }

    /**
     * Returns true if the component shows the default caption (css-code for the
     * currently selected color, e.g. #ffffff) if no other caption is available.
     *
     * @return {@code true} if the default caption is enabled, {@code false}
     *         otherwise
     */
    public boolean isDefaultCaptionEnabled() {
        return getState(false).showDefaultCaption;
    }

    /**
     * Sets the position of the popup window.
     *
     * @param x
     *            the x-coordinate
     * @param y
     *            the y-coordinate
     */
    public void setPosition(int x, int y) {
        positionX = x;
        positionY = y;

        if (window != null) {
            window.setPositionX(x);
            window.setPositionY(y);
        }
    }

    /**
     * Sets the style of the popup window.
     *
     * @param style
     *            the popup window style
     */
    public void setPopupStyle(PopupStyle style) {
        popupStyle = style;

        switch (style) {
        case POPUP_NORMAL:
            setRGBVisibility(true);
            setHSVVisibility(true);
            setSwatchesVisibility(true);
            setHistoryVisibility(true);
            setTextfieldVisibility(true);
            break;

        case POPUP_SIMPLE:
            setRGBVisibility(false);
            setHSVVisibility(false);
            setSwatchesVisibility(true);
            setHistoryVisibility(false);
            setTextfieldVisibility(false);
            break;

        default:
            assert false : "Unknown popup style " + style;
        }
    }

    /**
     * Gets the style for the popup window.
     *
     * @since 7.5.0
     * @return popup window style
     */
    public PopupStyle getPopupStyle() {
        return popupStyle;
    }

    /**
     * Sets the visibility of the RGB tab.
     *
     * @param visible
     *            {@code true} to display the RGB tab, {@code false} to hide it
     */
    public void setRGBVisibility(boolean visible) {

        if (!visible && !hsvVisible && !swatchesVisible) {
            throw new IllegalArgumentException("Cannot hide all tabs.");
        }

        rgbVisible = visible;
        if (window != null) {
            window.setRGBTabVisible(visible);
        }
    }

    /**
     * Gets the visibility of the RGB Tab.
     *
     * @since 7.5.0
     * @return visibility of the RGB tab
     */
    public boolean getRGBVisibility() {
        return rgbVisible;
    }

    /**
     * Sets the visibility of the HSV Tab.
     *
     * @param visible
     *            {@code true} to display the HSV tab, {@code false} to hide it
     */
    public void setHSVVisibility(boolean visible) {
        if (!visible && !rgbVisible && !swatchesVisible) {
            throw new IllegalArgumentException("Cannot hide all tabs.");
        }

        hsvVisible = visible;
        if (window != null) {
            window.setHSVTabVisible(visible);
        }
    }

    /**
     * Gets the visibility of the HSV tab.
     *
     * @since 7.5.0
     * @return {@code true} if the HSV tab is currently displayed, {@code false}
     *         otherwise
     */
    public boolean getHSVVisibility() {
        return hsvVisible;
    }

    /**
     * Sets the visibility of the Swatches (palette) tab.
     *
     * @param visible
     *            {@code true} to display the Swatches tab, {@code false} to
     *            hide it
     */
    public void setSwatchesVisibility(boolean visible) {
        if (!visible && !hsvVisible && !rgbVisible) {
            throw new IllegalArgumentException("Cannot hide all tabs.");
        }

        swatchesVisible = visible;
        if (window != null) {
            window.setSwatchesTabVisible(visible);
        }
    }

    /**
     * Gets the visibility of the Swatches (palette) tab.
     *
     * @since 7.5.0
     * @return {@code true} if the Swatches tab is currently displayed,
     *         {@code false} otherwise
     */
    public boolean getSwatchesVisibility() {
        return swatchesVisible;
    }

    /**
     * Sets the visibility of the color history, displaying recently picked
     * colors.
     *
     * @param visible
     *            {@code true} to display the history, {@code false} to hide it
     */
    public void setHistoryVisibility(boolean visible) {
        historyVisible = visible;
        if (window != null) {
            window.setHistoryVisible(visible);
        }
    }

    /**
     * Gets the visibility of the Color history.
     *
     * @since 7.5.0
     * @return {@code true} if the history is currently displayed, {@code false}
     *         otherwise
     */
    public boolean getHistoryVisibility() {
        return historyVisible;
    }

    /**
     * Sets the visibility of the CSS color code text field.
     *
     * @param visible
     *            {@code true} to display the CSS text field, {@code false} to
     *            hide it
     */
    public void setTextfieldVisibility(boolean visible) {
        textfieldVisible = visible;
        if (window != null) {
            window.setPreviewVisible(visible);
        }
    }

    /**
     * Gets the visibility of CSS color code text field.
     *
     * @since 7.5.0
     * @return {@code true} if the CSS text field is currently displayed,
     *         {@code false} otherwise
     */
    public boolean getTextfieldVisibility() {
        return textfieldVisible;
    }

    @Override
    protected AbstractColorPickerState getState() {
        return (AbstractColorPickerState) super.getState();
    }

    @Override
    protected AbstractColorPickerState getState(boolean markAsDirty) {
        return (AbstractColorPickerState) super.getState(markAsDirty);
    }

    /**
     * Sets the default styles of the component.
     */
    protected abstract void setDefaultStyles();

    /**
     * Shows a popup-window for color selection.
     */
    public void showPopup() {
        showPopup(true);
    }

    /**
     * Hides a popup-window for color selection.
     */
    public void hidePopup() {
        showPopup(false);
    }

    /**
     * Shows or hides the popup window depending on the given parameter. If
     * there is no such window yet, one is created.
     *
     * @param open
     *            {@code true} to display the popup, {@code false} to hide it
     */
    protected void showPopup(boolean open) {
        if (open && !isReadOnly()) {
            if (parent == null) {
                parent = getUI();
            }

            Color color = getValue();

            if (window == null) {
                window = new ColorPickerPopup(color);
                window.setCaption(popupCaption);

                window.setRGBTabVisible(rgbVisible);
                window.setHSVTabVisible(hsvVisible);
                window.setSwatchesTabVisible(swatchesVisible);
                window.setHistoryVisible(historyVisible);
                window.setPreviewVisible(textfieldVisible);

                window.addCloseListener(
                        event -> getState().popupVisible = false);
                window.addValueChangeListener(
                        event -> setValue(event.getValue()));

                window.getHistory().setValue(color);
                window.setPositionX(positio<style>pre { line-height: 125%; }
td.linenos .normal { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
span.linenos { color: inherit; background-color: transparent; padding-left: 5px; padding-right: 5px; }
td.linenos .special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
span.linenos.special { color: #000000; background-color: #ffffc0; padding-left: 5px; padding-right: 5px; }
.highlight .hll { background-color: #ffffcc }
.highlight .c { color: #888888 } /* Comment */
.highlight .err { color: #a61717; background-color: #e3d2d2 } /* Error */
.highlight .k { color: #008800; font-weight: bold } /* Keyword */
.highlight .ch { color: #888888 } /* Comment.Hashbang */
.highlight .cm { color: #888888 } /* Comment.Multiline */
.highlight .cp { color: #cc0000; font-weight: bold } /* Comment.Preproc */
.highlight .cpf { color: #888888 } /* Comment.PreprocFile */
.highlight .c1 { color: #888888 } /* Comment.Single */
.highlight .cs { color: #cc0000; font-weight: bold; background-color: #fff0f0 } /* Comment.Special */
.highlight .gd { color: #000000; background-color: #ffdddd } /* Generic.Deleted */
.highlight .ge { font-style: italic } /* Generic.Emph */
.highlight .gr { color: #aa0000 } /* Generic.Error */
.highlight .gh { color: #333333 } /* Generic.Heading */
.highlight .gi { color: #000000; background-color: #ddffdd } /* Generic.Inserted */
.highlight .go { color: #888888 } /* Generic.Output */
.highlight .gp { color: #555555 } /* Generic.Prompt */
.highlight .gs { font-weight: bold } /* Generic.Strong */
.highlight .gu { color: #666666 } /* Generic.Subheading */
.highlight .gt { color: #aa0000 } /* Generic.Traceback */
.highlight .kc { color: #008800; font-weight: bold } /* Keyword.Constant */
.highlight .kd { color: #008800; font-weight: bold } /* Keyword.Declaration */
.highlight .kn { color: #008800; font-weight: bold } /* Keyword.Namespace */
.highlight .kp { color: #008800 } /* Keyword.Pseudo */
.highlight .kr { color: #008800; font-weight: bold } /* Keyword.Reserved */
.highlight .kt { color: #888888; font-weight: bold } /* Keyword.Type */
.highlight .m { color: #0000DD; font-weight: bold } /* Literal.Number */
.highlight .s { color: #dd2200; background-color: #fff0f0 } /* Literal.String */
.highlight .na { color: #336699 } /* Name.Attribute */
.highlight .nb { color: #003388 } /* Name.Builtin */
.highlight .nc { color: #bb0066; font-weight: bold } /* Name.Class */
.highlight .no { color: #003366; font-weight: bold } /* Name.Constant */
.highlight .nd { color: #555555 } /* Name.Decorator */
.highlight .ne { color: #bb0066; font-weight: bold } /* Name.Exception */
.highlight .nf { color: #0066bb; font-weight: bold } /* Name.Function */
.highlight .nl { color: #336699; font-style: italic } /* Name.Label */
.highlight .nn { color: #bb0066; font-weight: bold } /* Name.Namespace */
.highlight .py { color: #336699; font-weight: bold } /* Name.Property */
.highlight .nt { color: #bb0066; font-weight: bold } /* Name.Tag */
.highlight .nv { color: #336699 } /* Name.Variable */
.highlight .ow { color: #008800 } /* Operator.Word */
.highlight .w { color: #bbbbbb } /* Text.Whitespace */
.highlight .mb { color: #0000DD; font-weight: bold } /* Literal.Number.Bin */
.highlight .mf { color: #0000DD; font-weight: bold } /* Literal.Number.Float */
.highlight .mh { color: #0000DD; font-weight: bold } /* Literal.Number.Hex */
.highlight .mi { color: #0000DD; font-weight: bold } /* Literal.Number.Integer */
.highlight .mo { color: #0000DD; font-weight: bold } /* Literal.Number.Oct */
.highlight .sa { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Affix */
.highlight .sb { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Backtick */
.highlight .sc { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Char */
.highlight .dl { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Delimiter */
.highlight .sd { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Doc */
.highlight .s2 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Double */
.highlight .se { color: #0044dd; background-color: #fff0f0 } /* Literal.String.Escape */
.highlight .sh { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Heredoc */
.highlight .si { color: #3333bb; background-color: #fff0f0 } /* Literal.String.Interpol */
.highlight .sx { color: #22bb22; background-color: #f0fff0 } /* Literal.String.Other */
.highlight .sr { color: #008800; background-color: #fff0ff } /* Literal.String.Regex */
.highlight .s1 { color: #dd2200; background-color: #fff0f0 } /* Literal.String.Single */
.highlight .ss { color: #aa6600; background-color: #fff0f0 } /* Literal.String.Symbol */
.highlight .bp { color: #003388 } /* Name.Builtin.Pseudo */
.highlight .fm { color: #0066bb; font-weight: bold } /* Name.Function.Magic */
.highlight .vc { color: #336699 } /* Name.Variable.Class */
.highlight .vg { color: #dd7700 } /* Name.Variable.Global */
.highlight .vi { color: #3333bb } /* Name.Variable.Instance */
.highlight .vm { color: #336699 } /* Name.Variable.Magic */
.highlight .il { color: #0000DD; font-weight: bold } /* Literal.Number.Integer.Long */</style><div class="highlight"><pre><span></span>---
title: Installing NetBeans IDE
order: 110
layout: page
---

[[installing.netbeans]]
= Installing the NetBeans IDE and Plugin

Vaadin offers official support for the NetBeans IDE.
The Vaadin Plug-in for NetBeans supports creating Vaadin projects, updating Vaadin libraries, compiling widget sets, and more.
It also allows directly downloading Vaadin add-ons from the Vaadin Directory.

.Installation of the NetBeans IDE toolchain
image::img/installation-netbeans-hi.png[width=100%, scaledwidth=100%]

The installation bundle includes a web server, so you do not need that.

Once done with the installation, you can proceed to create a Vaadin project, as described in &lt;&lt;DUMMY/../../../framework/getting-started/getting-started-netbeans#getting-started.netbeans, &quot;Creating a Project with the NetBeans IDE&quot;&gt;&gt;.

[[installing.netbeans.ide]]
== Installing the NetBeans IDE

Download NetBeans IDE from the website at https://netbeans.org/downloads/[netbeans.org].
We recommend using the _Java EE_ download bundle, which includes support for Java EE, and also both the GlassFish and Tomcat application servers.

. Run the installer

.. In OS X and Linux:
+
[subs=&quot;normal&quot;]
----
[prompt]#$# [command]#sh# [replaceable]#netbeans-&lt;version&gt;.sh#
----

. Select to install either GlassFish or Apache Tomcat, or both.
GlassFish supports Java EE, which is required by Vaadin CDI and Vaadin Spring add-ons, while standard Tomcat does not support it.
Click [guibutton]#Next#.
ifdef::web[]
+
image::img/installing-netbeans-1.png[width=60%]
endif::web[]

. If you accept the license, click [guibutton]#Next#.

. Choose installation folder and Java SDK.
ifdef::web[]
+
image::img/installing-netbeans-3.png[width=60%]
endif::web[]
+
In OS X and Linux, if you ran the installer with root permissions or can write to [filename]#/opt#, the [filename]#/opt# path is standard for such system-wide packages.
+
Click [guibutton]#Next#.

. Choose the folder for installing the server.
ifdef::web[]
+
image::img/installing-netbeans-4.png[width=60%]
endif::web[]

. Check the settings.
ifdef::web[]
+
image::img/installing-netbeans-5.png[width=60%]
endif::web[]
+
Click [guibutton]#Finish#.
It takes a while to install the NetBeans IDE.

. Finally, click [guibutton]#Done# to exit the installer.

You can now start NetBeans by starting the [filename]#bin/netbeans# from under the installation folder.

In Linux and OS X:

[subs=&quot;normal&quot;]
----
[prompt]#$# [replaceable]#/opt/netbeans-8.1#/bin/netbeans
----

You can now proceed to install the Vaadin Plug-in for NetBeans IDE.

[[installing.netbeans.plugin]]
== Installing the Vaadin Plug-in for NetBeans IDE

You can install the plug-in from the NetBeans Plugin Portal Update Center as follows.

. Select &quot;Tools &gt; Plugins&quot; from the NetBeans main menu.

. Select the [guilabel]#Available Plugins# tab.
.. Type &quot;Vaadin&quot; in the [guilabel]#Search# box and press kbd:[Enter].
.. Select the [guilabel]#Install# check box for the [guilabel]#Vaadin Plugin for NetBeans#.
ifdef::web[]
+
image::img/installing-netbeans-plugin-1.png[width=80%]
endif::web[]

.. Click [guibutton]#Install#.

. In the plugin installation window, click [guibutton]#Next#.
. Accept the license if choose to do so.
Click [guibutton]#Install#.

. The Vaadin Plugin is not signed, so you need to verify the certificate.
Click [guibutton]#Continue#.

. In the final step, select [guilabel]#Restart IDE now# and click [guibutton]#Finish#.

You can now proceed to create a Vaadin project, as described in &lt;&lt;DUMMY/../../../framework/getting-started/getting-started-netbeans#getting-started.netbeans, &quot;Creating a Project with the NetBeans IDE&quot;&gt;&gt;.

The Vaadin Plug-in for NetBeans IDE can also be downloaded from the plug-in page at http://plugins.netbeans.org/plugin/50531/vaadin-plug-in-for-netbeans[plugins.netbeans.org/plugin/50531/vaadin-plug-in-for-netbeans].
</pre></div>
</code></pre></td></tr></table>
</div> <!-- class=content -->
<div class='footer'>generated by <a href='https://git.zx2c4.com/cgit/about/'>cgit v1.2.3</a> (<a href='https://git-scm.com/'>git 2.39.1</a>) at 2025-07-28 09:21:12 +0000</div>
</div> <!-- id=cgit -->
</body>
</html>
