Package getfacts.full

Source Code of getfacts.full.DefaultFrontPageRenderer

/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package getfacts.full;

import getfacts.Article;
import getfacts.FrontPage;
import getfacts.IDisposable;
import java.awt.Color;
import java.awt.Component;
import java.awt.Container;
import java.awt.GridLayout;
import javax.swing.BoxLayout;
import javax.swing.JPanel;

/**
*
* @author jmc15
*/
public class DefaultFrontPageRenderer
extends javax.swing.JPanel
implements IDisposable
{
    private FrontPage frontPage;
    private DefaultFrontPagePane frontPagePane;
    private Container articlesPane;
    private int orientation;
    /**
     * Creates new form DefaultFrontPageRenderer
     */
    public DefaultFrontPageRenderer(FrontPage fp, int o)
    {
        frontPage = fp;
        orientation = o;
       
        initComponents();
        setLayout( new OneTwoThirdsLayoutManager(orientation) );
       
        frontPagePane = CreateFrontPagePane(fp);
       
        articlesPane = CreateArticlesPane();
       
        this.add(frontPagePane, OneTwoThirdsLayoutManager.ONE_THIRD);
        this.add(articlesPane, OneTwoThirdsLayoutManager.TWO_THIRDS);
    }
   
    protected Container CreateArticlesPane()
    {
        JPanel pane = new JPanel();
        pane.setBackground(Color.YELLOW);
        //BoxLayout layout = new BoxLayout(pane, BoxLayout.PAGE_AXIS);
        GridLayout layout = new GridLayout(3,1);
        pane.setLayout(layout);  
        return pane;
    }
   
    protected DefaultFrontPagePane CreateFrontPagePane(FrontPage fp)
    {
        return new DefaultFrontPagePane(fp);
    }


    int showNews()
    {
        int count = 0;
        //articlesPane.removeAll();
        int max = Math.min(3, frontPage.getArticlesCount());
        for(int i=0; i<max; i++)
        {
            Article article = frontPage.getArticle(i);
            Component articlePane = CreateDefaultArticlePane(article);
            articlesPane.add(articlePane);
            count ++;
        }
        articlesPane.validate();
        articlesPane.repaint();
        return count;
    }
   
    protected Component CreateDefaultArticlePane(Article a)
    {
        DefaultArticlePane articlePane = new DefaultArticlePane(a, orientation);
        return articlePane;
    }
   
   
    public void dispose()
    {
        for(Component c : articlesPane.getComponents() )
        {
            if( c instanceof IDisposable)
            {
                IDisposable i = (IDisposable)c;
                i.dispose();
            }
        }
        frontPage.dispose();
    }
   
    public void addControlsListener(ControlsListener l)
    {
        frontPagePane.addControlsListener(l);
    }
   
    public void removeControlsListener(ControlsListener l)
    {
        frontPagePane.removeControlsListener(l);
    }
   
   
    /**
     * 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">//GEN-BEGIN:initComponents
    private void initComponents() {

        setBackground(new java.awt.Color(153, 255, 153));

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

}
TOP

Related Classes of getfacts.full.DefaultFrontPageRenderer

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.