<commit_before>//-----------------------------------------------------------------------//
//                                                                       //
//                         Z o o m e d P a n e l                         //
//                                                                       //
//  Copyright (C) <NAME> 2000-2005. All rights reserved.          //
//  This software is released under the terms of the GNU General Public  //
//  License. Please contact the author at <EMAIL>      //
//  to report bugs & suggestions.                                        //
//-----------------------------------------------------------------------//

package omr.ui;

import omr.constant.Constant;
import omr.constant.ConstantSet;
import omr.util.Logger;

import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Class <code>ZoomedPanel</code> is an abstract class meant to handle
 * recurrent tasks of a display with a magnifying lens, as provided by a
 * related {@link Zoom} entity.
 *
 * <p>Via the {@link PixelFocus} interface, we can ask this panel fo focus
 * on a specific point or rectangle.
 *
 * <p>Via the {@link MouseMonitor} interface, this panel traps the various
 * mouse actions.
 *
 * <p> This class is best used when enclosed in a scroll pane, so that the
 * zooming and focus features are really effective. </p>
 *
 * <p> Remark : this class cannot directly implement PixelSubject because
 * of several informations to be pushed. To be more thoroughly
 * investigated, TBD.
 *
 * @see RubberZoomedPanel
 *
 * @author <NAME>
 * @version $Id$
 */
public abstract class ZoomedPanel
    extends JPanel
    implements ChangeListener,
               MouseMonitor,
               PixelFocus
{
    //~ Static variables/initializers -------------------------------------

    private static final Logger logger = Logger.getLogger(ZoomedPanel.class);
    private static final Constants constants = new Constants();

    //~ Instance variables ------------------------------------------------

    /** Model size (independent of display zoom) */
    protected Dimension modelSize;

    /** Current display zoom */
    protected Zoom zoom;

    /** Subject for pixel observers if any */
    protected DefaultPixelSubject pixelSubject
        = new DefaultPixelSubject();

    //~ Constructors ------------------------------------------------------

    //-------------//
    // ZoomedPanel //
    //-------------//
    /**
     * Create a bare zoomed panel, assuming zoom will be assigned later
     */
    public ZoomedPanel ()
    {
    }

    //-------------//
    // ZoomedPanel //
    //-------------//
    /**
     * Create a zoomed panel
     */
    public ZoomedPanel (Zoom zoom)
    {
        setZoom(zoom);
    }

    //~ Methods -----------------------------------------------------------

    //----------------//
    // getPanelCenter //
    //----------------//
    /**
     * Retrieve the current center of the display, and report its
     * corresponding model location.
     *
     * @return the unscaled coordinates of the panel center
     */
    public Point getPanelCenter ()
    {
        Rectangle vr = getVisibleRect();
        Point pt = new Point(zoom.unscaled(vr.x + (vr.width / 2)),
                             zoom.unscaled(vr.y + (vr.height / 2)));

        if (logger.isDebugEnabled()) {
            logger.debug("getPanelCenter=" + pt);
        }

        return pt;
    }

    //---------//
    // getZoom //
    //---------//
    /**
     * Return the current zoom
     *
     * @return the used zoom
     */
    public Zoom getZoom ()
    {
        return zoom;
    }

    //-----------------//
    // contextSelected //
    //-----------------//
    public void contextSelected (MouseEvent e,
                                 Point pt)
    {
        // Nothing by default
    }

    //---------------//
    // pointSelected //
    //---------------//
    public void pointSelected (MouseEvent e,
                               Point pt)
    {
        notifyObservers(pt);
    }

    //------------//
    // pointAdded //
    //------------//
    public void pointAdded (MouseEvent e,
                            Point pt)
    {
        pointSelected(e, pt);
    }

    //-----------//
    // reDisplay //
    //-----------//
    /**
     * Redisplay, keeping the focus of the display, that is the focus
     * (point of interest) remains visible.
     */
    public void reDisplay ()
    {<commit_msg>More documentation<commit_after>//-----------------------------------------------------------------------//
//                                                                       //
//                         Z o o m e d P a n e l                         //
//                                                                       //
//  Copyright (C) <NAME>teur 2000-2005. All rights reserved.          //
//  This software is released under the terms of the GNU General Public  //
//  License. Please contact the author at <EMAIL>      //
//  to report bugs & suggestions.                                        //
//-----------------------------------------------------------------------//

package omr.ui;

import omr.constant.Constant;
import omr.constant.ConstantSet;
import omr.util.Logger;

import java.awt.*;
import java.awt.event.MouseEvent;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;

/**
 * Class <code>ZoomedPanel</code> is an abstract class meant to handle
 * recurrent tasks of a display with a magnifying lens, as provided by a
 * related {@link Zoom} entity.
 *
 * <p>Via the {@link PixelFocus} interface, we can ask this panel fo focus
 * on a specific point or rectangle.
 *
 * <p>Via the {@link MouseMonitor} interface, this panel traps the various
 * mouse actions.
 *
 * <p> This class is best used when enclosed in a scroll pane, so that the
 * zooming and focus features are really effective. </p>
 *
 * <p> Remark : this class cannot directly implement PixelSubject because
 * of several informations to be pushed. To be more thoroughly
 * investigated, TBD.
 *
 * @see RubberZoomedPanel
 *
 * @author <NAME>
 * @version $Id$
 */
public abstract class ZoomedPanel
    extends JPanel
    implements ChangeListener,
               MouseMonitor,
               PixelFocus
{
    //~ Static variables/initializers -------------------------------------

    private static final Logger logger = Logger.getLogger(ZoomedPanel.class);
    private static final Constants constants = new Constants();

    //~ Instance variables ------------------------------------------------

    /** Model size (independent of display zoom) */
    protected Dimension modelSize;

    /** Current display zoom */
    protected Zoom zoom;

    /** Subject for pixel observers if any */
    protected DefaultPixelSubject pixelSubject
        = new DefaultPixelSubject();

    //~ Constructors ------------------------------------------------------

    //-------------//
    // ZoomedPanel //
    //-------------//
    /**
     * Create a bare zoomed panel, assuming zoom will be assigned later
     */
    public ZoomedPanel ()
    {
    }

    //-------------//
    // ZoomedPanel //
    //-------------//
    /**
     * Create a zoomed panel
     */
    public ZoomedPanel (Zoom zoom)
    {
        setZoom(zoom);
    }

    //~ Methods -----------------------------------------------------------

    //----------------//
    // getPanelCenter //
    //----------------//
    /**
     * Retrieve the current center of the display, and report its
     * corresponding model location.
     *
     * @return the unscaled coordinates of the panel center
     */
    public Point getPanelCenter ()
    {
        Rectangle vr = getVisibleRect();
        Point pt = new Point(zoom.unscaled(vr.x + (vr.width / 2)),
                             zoom.unscaled(vr.y + (vr.height / 2)));

        if (logger.isDebugEnabled()) {
            logger.debug("getPanelCenter=" + pt);
        }

        return pt;
    }

    //---------//
    // getZoom //
    //---------//
    /**
     * Return the current zoom
     *
     * @return the used zoom
     */
    public Zoom getZoom ()
    {
        return zoom;
    }

    //-----------------//
    // contextSelected //
    //-----------------//
    public void contextSelected (MouseEvent e,
                                 Point pt)
    {
        // Nothing by default
    }

    //---------------//
    // pointSelected //
    //---------------//
    /**
     * Point designation, which does nothing except notifying registered
     * observers about the designated point.
     *
     * @param e the mouse event
     * @param pt the selected point in model pixel coordinates
     */
    public void pointSelected (MouseEvent e,
                               Point pt)
    {
        notifyObservers(pt);
    }

    //------------//
    // pointAdded //
    //------------//
    public void pointAdded (MouseEvent e,
                            Point pt)
    {
        pointSelected(e, pt);
    }

    //-----------//
    // reDisplay //
    //-----------//
    /**
     * Redisplay, keeping the focus of the display, that is the focus
     * (point of interest) remains visible.
     */
    public void reDisplay ()
    {
{'fraction_non_alphanumeric': 0.21117615753060137, 'fraction_numerical': 0.0021287919105907396, 'mean_word_length': 1.1634814644255123, 'pattern_counts': {'":': 0, '<': 23, '<?xml version=': 0, '>': 23, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 22, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6416935', 'n_tokens_mistral': 2299, 'n_tokens_neox': 2226, 'n_words': 734}