Package view

Source Code of view.Window

package view;

import java.awt.BorderLayout;
import java.awt.CardLayout;
import java.awt.Dimension;
import java.awt.Toolkit;

import javax.swing.JFrame;
import javax.swing.JPanel;

import model.array.HistoryArray;
import model.array.interfaces.CurrentChangedListener;
import view.bar.ProgressBar;
import view.buttons.BackwardButton;
import view.buttons.ForwardButton;
import view.menu.MenuLine;
import view.panels.HistoryPanel;
import view.panels.StartPageView;
import view.textfield.SearchField;

public class Window extends JFrame implements CurrentChangedListener {
  private static final long serialVersionUID = -3739008754324139579L;

  private static final int WIDTH = 568;
  private static final int HEIGHT = 686;
  private static final String TITLE = "H2MDb";

  private int panelCount;
  private JPanel container;
  private JPanel searchPanel;
  private HistoryArray history;
  private JPanel panelContainer;
  private CardLayout cardLayout;
  private SearchField searchField;
  private StartPageView startPage;
  private ProgressBar progressBar;
  private ForwardButton forwardButton;
  private BackwardButton backwardButton;

  public Window() {
    super(TITLE);
    panelCount = -1;

    history = new HistoryArray();
    history.addCurrentChangedListener(this);
   
    searchField = new SearchField();
    forwardButton = new ForwardButton(history);
    backwardButton = new BackwardButton(history);
   
    startPage = new StartPageView(getPanelCount());
   
    searchPanel = new JPanel();
    searchPanel.add(backwardButton);
    searchPanel.add(forwardButton);
    searchPanel.add(searchField);

    cardLayout = new CardLayout();
    panelContainer = new JPanel(cardLayout);
    panelContainer.add(startPage, startPage.getPanelNumberText());
   
    progressBar = new ProgressBar();
   
    container = new JPanel(new BorderLayout());
    container.add(searchPanel, BorderLayout.NORTH);
    container.add(panelContainer, BorderLayout.CENTER);
    container.add(progressBar, BorderLayout.SOUTH);

    history.add(startPage);
   
    add(container);
    setJMenuBar(new MenuLine());

    setVisible(true);
    setSize(WIDTH, HEIGHT);
   
    setPosition();
    setResizable(false);
    setDefaultCloseOperation(EXIT_ON_CLOSE);
  }

  public int getPanelCount() {
    return ++panelCount;
  }
 
  public SearchField getSearchBar() {
    return searchField;
  }
 
  public ProgressBar getProgessBar() {
    return progressBar;
  }
 
  public HistoryArray getHistory()  {
    return history;
  }
 
  private void setPosition() {
    Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();

    int xPos = screen.width/2 - getWidth()/2;
    int yPos = screen.height/2 - getHeight()/2;

    setLocation(xPos, yPos);
  }
 
  @Override
  public void currentChanged(HistoryPanel h) {
    panelContainer.add(h, h.getPanelNumberText());
    cardLayout.show(panelContainer, h.getPanelNumberText());
  }
}
TOP

Related Classes of view.Window

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.