All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.flexdock.dockbar.ViewPane Maven / Gradle / Ivy

/*
 * Permission is hereby granted, free of charge, to any person obtaining a copy
 * of this software and associated documentation files (the "Software"), to deal
 * in the Software without restriction, including without limitation the rights
 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the Software is
 * furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
 * SOFTWARE.
 */
package org.flexdock.dockbar;

import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Cursor;
import java.awt.Dimension;

import javax.swing.JPanel;
import javax.swing.border.Border;
import javax.swing.event.MouseInputAdapter;

import org.flexdock.dockbar.event.ResizeListener;
import org.flexdock.docking.Dockable;
import org.flexdock.docking.state.MinimizationManager;
import org.flexdock.plaf.common.border.SlideoutBorder;

/**
 * @author Christopher Butler
 */
public class ViewPane extends JPanel {
    private static final Dimension RESIZE_DIMS = new Dimension(3, 3);
    private static final MouseInputAdapter EMPTY_MOUSE_LISTENER = new MouseInputAdapter() {};
    public static final int UNSPECIFIED_PREFERRED_SIZE = -1;
    private DockbarManager manager;
    private JPanel dragEdge;
    private int prefSize;
    private boolean locked;


    public ViewPane(DockbarManager mgr) {
        super(new BorderLayout(0, 0));
        setBorder(new SlideoutBorder());

        manager = mgr;
        prefSize = UNSPECIFIED_PREFERRED_SIZE;

        dragEdge = new JPanel();
        dragEdge.setPreferredSize(RESIZE_DIMS);

        ResizeListener listener = new ResizeListener(mgr);
        dragEdge.addMouseListener(listener);
        dragEdge.addMouseMotionListener(listener);

        updateOrientation();

        // intercept rouge mouse events so they don't fall
        // through to the content pane
        addMouseListener(EMPTY_MOUSE_LISTENER);
        addMouseMotionListener(EMPTY_MOUSE_LISTENER);
    }

    public void updateContents() {
        // remove the currently docked component
        Component[] children = getComponents();
        for(int i=0; i




© 2015 - 2025 Weber Informatics LLC | Privacy Policy