/*
 * Autopsy Forensic Browser
 *
 * Copyright 2011 Basis Technology Corp.
 * Contact: carrier <at> sleuthkit <dot> org
 *
 * 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 org.sleuthkit.autopsy.ingest;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.event.ComponentEvent;
import java.awt.event.ComponentListener;
import java.util.logging.Level;
import org.sleuthkit.autopsy.coreutils.Logger;
import javax.swing.BoxLayout;
import javax.swing.JLayeredPane;

/**
 * the main layered pane container for messages table (IngestMessagePanel)
 * and details view (IngestMessageDetailsPanel)
 */
public class IngestMessageMainPanel extends JLayeredPane {

    private IngestMessagePanel messagePanel;
    private IngestMessageDetailsPanel detailsPanel;
    private Logger logger = Logger.getLogger(IngestMessageMainPanel.class.getName());
    //private JLayeredPane layeredPane;

    /** Creates new form IngestMessageMainPanel */
    public IngestMessageMainPanel() {
        initComponents();
        customizeComponents();
    }

    private void customizeComponents() {
        messagePanel = new IngestMessagePanel(this);
        detailsPanel = new IngestMessageDetailsPanel(this);

        //we need to handle resizing ourselves due to absence of layout manager
        //in layered layout
        this.addComponentListener(new ComponentListener() {

            @Override
            public void componentHidden(ComponentEvent e) {
            }

            @Override
            public void componentMoved(ComponentEvent e) {
            }

            @Override
            public void componentShown(ComponentEvent e) {
                //doResize();
            }

            @Override
            public void componentResized(ComponentEvent e) {
                //we need to handle resizing ourselves due to absence of layout manager
                //in layered layout
                doResize();

            }
        });

        messagePanel.setOpaque(true);
        detailsPanel.setOpaque(true);
        add(messagePanel, JLayeredPane.PALETTE_LAYER);
        add(detailsPanel, JLayeredPane.DEFAULT_LAYER);
        this.setOpaque(true);
    }

    void doResize() {
        Dimension dim = getSize();
        messagePanel.setPreferredSize(dim);
        detailsPanel.setPreferredSize(dim);
        messagePanel.setBounds(0, 0, dim.width, dim.height);
        detailsPanel.setBounds(0, 0, dim.width, dim.height);
        revalidate();
    }

    IngestMessagePanel getMessagePanel() {
        return messagePanel;
    }

    IngestMessageDetailsPanel getDetailsPanel() {
        return detailsPanel;
    }

    void showMessages() {
        setLayer(detailsPanel, JLayeredPane.DEFAULT_LAYER);
        setLayer(messagePanel, JLayeredPane.PALETTE_LAYER);
    }

    void showDetails(int rowNumber) {
        detailsPanel.showDetails(rowNumber);

        setLayer(detailsPanel, JLayeredPane.PALETTE_LAYER);
        setLayer(messagePanel, JLayeredPane.DEFAULT_LAYER);

    }

    public void addMessage(IngestMessage ingestMessage) {
        messagePanel.addMessage(ingestMessage);
    }

    public void clearMessages() {
        messagePanel.clearMessages();
    }
    
     public int getMessagesCount() {
        return messagePanel.getMessagesCount();
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">
    private void initComponents() {

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 454, Short.MAX_VALUE));
        layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING).addGap(0, 309, Short.MAX_VALUE));
    }// </editor-fold>
    // Variables declaration - do not modify
    // End of variables declaration
}
