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

org.datacleaner.panels.RightInformationPanel Maven / Gradle / Ivy

/**
 * DataCleaner (community edition)
 * Copyright (C) 2014 Free Software Foundation, Inc.
 *
 * This copyrighted material is made available to anyone wishing to use, modify,
 * copy, or redistribute it subject to the terms and conditions of the GNU
 * Lesser General Public License, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
 * or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser General Public License
 * for more details.
 *
 * You should have received a copy of the GNU Lesser General Public License
 * along with this distribution; if not, write to:
 * Free Software Foundation, Inc.
 * 51 Franklin Street, Fifth Floor
 * Boston, MA  02110-1301  USA
 */
package org.datacleaner.panels;

import java.awt.CardLayout;
import java.awt.Color;

import javax.swing.JComponent;
import javax.swing.JPanel;
import javax.swing.Timer;
import javax.swing.border.CompoundBorder;
import javax.swing.border.EmptyBorder;
import javax.swing.border.LineBorder;

import org.datacleaner.actions.MoveComponentTimerActionListener;
import org.datacleaner.util.WidgetScreenResolutionAdjuster;
import org.datacleaner.util.WidgetUtils;

public class RightInformationPanel extends JPanel {

    private static final long serialVersionUID = 1L;

    private static final WidgetScreenResolutionAdjuster ADJUSTER = WidgetScreenResolutionAdjuster.get();
    private static final int WIDTH = ADJUSTER.adjust(360);
    private static final int HEIGHT = ADJUSTER.adjust(500);
    private static final int POSITION_Y = ADJUSTER.adjust(130);

    private final DCGlassPane _glassPane;
    private final CardLayout _carLayout = new CardLayout();
    private final Color _background = WidgetUtils.BG_COLOR_BRIGHTEST;
    private final Color _foreground = WidgetUtils.BG_COLOR_DARKEST;
    private final Color _borderColor = WidgetUtils.BG_COLOR_MEDIUM;

    private String openedCard = "";

    public RightInformationPanel(final DCGlassPane glassPane) {
        super();
        _glassPane = glassPane;

        final int pix20 = ADJUSTER.adjust(20);
        final int pix30 = ADJUSTER.adjust(30);

        setBorder(new CompoundBorder(new LineBorder(_borderColor, 1), new EmptyBorder(pix20, pix20, pix20, pix30)));
        setSize(WIDTH, HEIGHT);
        setLocation(getXWhenOut(), POSITION_Y);
        setLayout(_carLayout);
    }

    public void addTabToPane(final String panelTitle, final JComponent panel) {
        add(panel, panelTitle);
    }

    public void toggleWindow(final String tabTitle) {
        if (openedCard.equals(tabTitle)) {
            closeWindow();
        } else {
            openWindow(tabTitle);
        }
    }

    private void openWindow(final String tabTitle) {
        if (!openedCard.equals(tabTitle)) {
            moveOut();
        }
        _carLayout.show(this, tabTitle);
        moveIn();
        openedCard = tabTitle;
    }

    private void closeWindow() {
        moveOut();
        openedCard = "";
    }

    public String getOpenedCard() {
        return openedCard;
    }

    private int getXWhenOut() {
        return _glassPane.getSize().width + WIDTH + 10;
    }

    private int getXWhenIn() {
        return _glassPane.getSize().width - WIDTH + 10;
    }

    private void moveIn() {
        setLocation(getXWhenOut(), POSITION_Y);
        _glassPane.add(this);
        final Timer timer = new Timer(10, new MoveComponentTimerActionListener(this, getXWhenIn(), POSITION_Y, 40) {
            @Override
            protected void done() {
            }
        });
        timer.setInitialDelay(0);
        timer.start();
    }

    private void moveOut() {
        final Timer timer = new Timer(10, new MoveComponentTimerActionListener(this, getXWhenOut(), POSITION_Y, 40) {
            @Override
            protected void done() {
                final RightInformationPanel me = RightInformationPanel.this;
                _glassPane.remove(me);
            }
        });
        timer.setInitialDelay(0);
        timer.start();
    }

    @Override
    public Color getBackground() {
        return _background;
    }

    @Override
    public Color getForeground() {
        return _foreground;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy