<commit_before>/*
 * Copyright (c) 2004, jMonkeyEngine - Mojo Monkey Coding
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this 
 * list of conditions and the following disclaimer. 
 * 
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the 
 * names of its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*
 * EDIT:  04/01/2004 - Check for null in getMouseInput(). GOP
 */

package com.jme.widget;

import java.util.Observer;

import com.jme.input.AbstractInputHandler;
import com.jme.input.Mouse;
import com.jme.input.MouseInput;
import com.jme.math.Vector2f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial;
import com.jme.widget.border.WidgetBorder;
import com.jme.widget.bounds.WidgetBoundingRectangle;
import com.jme.widget.bounds.WidgetViewRectangle;
import com.jme.widget.util.WidgetNotifier;

/**
 * <code>WidgetAbstractImpl</code>
 * @author <NAME>
 * @version
 */
public abstract class WidgetAbstractImpl extends Spatial implements Widget {

    public final static ColorRGBA defaultFgColor = new ColorRGBA(0, 0, 0, 1);
    protected ColorRGBA fgColor = defaultFgColor;

    public final static ColorRGBA defaultBgColor = new ColorRGBA(.8f, .8f, .8f, 1);
    protected ColorRGBA bgColor = defaultBgColor;

    protected final static int DEFAULT_COMP_WIDTH = 0;
    protected final static int DEFAULT_COMP_HEIGHT = 0;

    protected final static int DEFAULT_BORDER_SIZE = 0;
    protected WidgetBorder border = new WidgetBorder(DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE);

    protected WidgetBoundingRectangle localBound = new WidgetBoundingRectangle(true);
    protected Vector2f preferredSize = new Vector2f(DEFAULT_COMP_WIDTH, DEFAULT_COMP_HEIGHT);

    protected WidgetTextureCoords textureCoords;
    
    protected int zOrder;

    protected boolean visible;
    protected boolean opaque = true;

    protected WidgetAlignmentType alignment = WidgetAlignmentType.ALIGN_NONE;

    protected boolean cantOwnMouse;

    protected WidgetNotifier notifierMouseButtonDown = new WidgetNotifier();
    protected WidgetNotifier notifierMouseButtonUp = new WidgetNotifier();
    protected WidgetNotifier notifierMouseDrag = new WidgetNotifier();
    protected WidgetNotifier notifierMouseEnter = new WidgetNotifier();
    protected WidgetNotifier notifierMouseExit = new WidgetNotifier();
    protected WidgetNotifier notifierMouseMove = new WidgetNotifier();

    protected WidgetViewRectangle viewRectangle = new WidgetViewRectangle();
    private boolean applyOffsetX = true;
    private boolean applyOffsetY = true;

    private static AbstractInputHandler inputController;

    private static Widget mouseOwner;
    private static Widget widgetUnderMouse;
    private static Widget lastWidgetUnderMouse;

    private Widget owner;

    private WidgetRenderer renderer;

    public WidgetAbstractImpl() {
        super("");
        init();
    }

    public WidgetAbstractImpl(int width, int height) {
        this();
        setSize(width, height);
        setPreferredSize(new Vector2f(width, height));
        init();
    }

    private void init() {
        initWidgetRenderer();
        setVisible(true);
        updateWorldBound();
    }

    public MouseInput getMouseInput() {
        MouseInput mi = null;
        Mouse m = inputController.getMouse();
        
        if (m != null) {
            mi = m.getMouseInput();
        }
        
        return mi;
    }

    public AbstractInputHandler getInputController() {
        return inputController;
    }

    public void setInputController(AbstractInputHandler controller) {
        inputController = controller;
    }


    public Widget getMouseOwner() {
        return WidgetAbstractImpl.mouseOwner;
    }

    public void setMouseOwner(Widget widget) {
        WidgetAbstractImpl.mouseOwner = widget;
    }

    /**<commit_msg>Renamed methods get/setInputController to get/setInputHandler. Renamed attribute inputController to inputHandler.<commit_after>/*
 * Copyright (c) 2004, jMonkeyEngine - Mojo Monkey Coding
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without 
 * modification, are permitted provided that the following conditions are met:
 *
 * Redistributions of source code must retain the above copyright notice, this 
 * list of conditions and the following disclaimer. 
 * 
 * Redistributions in binary form must reproduce the above copyright notice, 
 * this list of conditions and the following disclaimer in the documentation 
 * and/or other materials provided with the distribution. 
 * 
 * Neither the name of the Mojo Monkey Coding, jME, jMonkey Engine, nor the 
 * names of its contributors may be used to endorse or promote products derived 
 * from this software without specific prior written permission. 
 * 
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE 
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 
 * POSSIBILITY OF SUCH DAMAGE.
 *
 */

/*
 * EDIT:  04/01/2004 - Check for null in getMouseInput(). GOP
 * EDIT:  04/02/2004 - Renamed methods get/setInputController to get/setInputHandler. GOP
 * EDIT:  04/02/2004 - Renamed attribute inputController to inputHandler. GOP
 */

package com.jme.widget;

import java.util.Observer;

import com.jme.input.AbstractInputHandler;
import com.jme.input.Mouse;
import com.jme.input.MouseInput;
import com.jme.math.Vector2f;
import com.jme.renderer.ColorRGBA;
import com.jme.renderer.Renderer;
import com.jme.scene.Spatial;
import com.jme.widget.border.WidgetBorder;
import com.jme.widget.bounds.WidgetBoundingRectangle;
import com.jme.widget.bounds.WidgetViewRectangle;
import com.jme.widget.util.WidgetNotifier;

/**
 * <code>WidgetAbstractImpl</code>
 * @author <NAME>
 * @version
 */
public abstract class WidgetAbstractImpl extends Spatial implements Widget {

    public final static ColorRGBA defaultFgColor = new ColorRGBA(0, 0, 0, 1);
    protected ColorRGBA fgColor = defaultFgColor;

    public final static ColorRGBA defaultBgColor = new ColorRGBA(.8f, .8f, .8f, 1);
    protected ColorRGBA bgColor = defaultBgColor;

    protected final static int DEFAULT_COMP_WIDTH = 0;
    protected final static int DEFAULT_COMP_HEIGHT = 0;

    protected final static int DEFAULT_BORDER_SIZE = 0;
    protected WidgetBorder border = new WidgetBorder(DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE, DEFAULT_BORDER_SIZE);

    protected WidgetBoundingRectangle localBound = new WidgetBoundingRectangle(true);
    protected Vector2f preferredSize = new Vector2f(DEFAULT_COMP_WIDTH, DEFAULT_COMP_HEIGHT);

    protected WidgetTextureCoords textureCoords;
    
    protected int zOrder;

    protected boolean visible;
    protected boolean opaque = true;

    protected WidgetAlignmentType alignment = WidgetAlignmentType.ALIGN_NONE;

    protected boolean cantOwnMouse;

    protected WidgetNotifier notifierMouseButtonDown = new WidgetNotifier();
    protected WidgetNotifier notifierMouseButtonUp = new WidgetNotifier();
    protected WidgetNotifier notifierMouseDrag = new WidgetNotifier();
    protected WidgetNotifier notifierMouseEnter = new WidgetNotifier();
    protected WidgetNotifier notifierMouseExit = new WidgetNotifier();
    protected WidgetNotifier notifierMouseMove = new WidgetNotifier();

    protected WidgetViewRectangle viewRectangle = new WidgetViewRectangle();
    private boolean applyOffsetX = true;
    private boolean applyOffsetY = true;

    private static AbstractInputHandler inputHandler;

    private static Widget mouseOwner;
    private static Widget widgetUnderMouse;
    private static Widget lastWidgetUnderMouse;

    private Widget owner;

    private WidgetRenderer renderer;

    public WidgetAbstractImpl() {
        super("");
        init();
    }

    public WidgetAbstractImpl(int width, int height) {
        this();
        setSize(width, height);
        setPreferredSize(new Vector2f(width, height));
        init();
    }

    private void init() {
        initWidgetRenderer();
        setVisible(true);
        updateWorldBound();
    }

    public MouseInput getMouseInput() {
        MouseInput mi = null;
        Mouse m = inputHandler.getMouse();
        
        if (m != null) {
            mi = m.getMouseInput();
        }
        
        return mi;
    }

    public AbstractInputHandler getInputHandler() {
        return inputHandler;
    }

    public void setInputHandler(AbstractInputHandler ih) {
        inputHandler = ih;
    }


    public Widget getMouseOwner() {
        return WidgetAbstractImpl.mouseOwner;
    }

    public void setMouseOwner(Widget widget) {
        WidgetAbstractImpl.mouseOwner = widget;
    }

    /**
{'fraction_non_alphanumeric': 0.06684092606422704, 'fraction_numerical': 0.006534727408513816, 'mean_word_length': 3.7698130008904718, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2755101', 'n_tokens_mistral': 2946, 'n_tokens_neox': 2768, 'n_words': 993}