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

net.sf.juife.swing.NavigationPane Maven / Gradle / Ivy

There is a newer version: 0.7
Show newest version
/*
 *   juife - Java User Interface Framework Extensions
 *
 *   Copyright (C) 2005-2011 Grigor Iliev 
 *
 *   This file is part of juife.
 *
 *   juife is free software; you can redistribute it and/or
 *   modify it under the terms of the GNU Lesser General Public
 *   License version 2.1 as published by the Free Software Foundation.
 *
 *   juife 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 juife; if not, write to the Free Software
 *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
 *   MA  02110-1301, USA
 */

package net.sf.juife.swing;

import java.awt.Color;

import javax.swing.JPanel;
import javax.swing.UIManager;

import net.sf.juife.swing.plaf.NavigationPaneUI;


/**
 * A component that allows the user to navigate through set of pages.
 * @author Grigor Iliev
 */
public class NavigationPane extends JPanel {
	static {
		// TODO: In future this must be done the right way
		UIManager.put("NavigationPaneUI", "net.sf.juife.swing.plaf.basic.BasicNavigationPaneUI");
	}
	private static final String uiClassID = "NavigationPaneUI";
	
	private NavigationHistoryModel model;
	private NavigationPage[] pages = new NavigationPage[0];
	
	private Color titleBackground;
	
	/**
	 * Creates a new instance of NavigationPane.
	 */
	public
	NavigationPane() { this(new DefaultNavigationHistoryModel()); }
	
	/**
	 * Creates a new instance of NavigationPane
	 * using the specified non-null model.
	 * @param model The navigation history model to be used by this
	 * NavigationPane.
	 * @throws IllegalArgumentException If model is null.
	 */
	public
	NavigationPane(NavigationHistoryModel model) {
		setModel(model);
	}
	
	/**
	 * Gets a string that specifies the name
	 * of the L&F class that renders this component.
	 * @return the string "NavigationPaneUI"
	 */
	public String
	getUIClassID() { return uiClassID; }
	
	/**
	 * Gets the L&F object that renders this component.
	 * @return The L&F object that renders this component.
	 */
	public NavigationPaneUI
	getUI() { return (NavigationPaneUI)ui; }
	
	/**
	 * Sets the L&F object that renders this component.
	 * @param ui The new UI delegate.
	 */
	public void
	setUI(NavigationPaneUI ui) { super.setUI(ui); }
	
	/**
	 * Resets the UI property to a value from the current look and feel.
	 */
	public void
	updateUI() { setUI((NavigationPaneUI)UIManager.getUI(this)); }
	
	/**
	 * Sets the pages that this NavigationPane will offer.
	 * @param pages The list of pages this NavigationPane will offer.
	 * @throws IllegalArgumentException If pages is null.
	 */
	public void
	setPages(NavigationPage[] pages) {
		if(pages == null) throw new IllegalArgumentException("pages must be non null");
		NavigationPage[] oldPages = this.pages;
		this.pages = pages;
		
		firePropertyChange("pages", oldPages, this.pages);
	}
	
	/**
	 * Gets the list of pages this NavigationPane offers.
	 * @return A list of NavigationPages this NavigationPane offers.
	 */
	public NavigationPage[]
	getPages() { return pages; }
	
	/**
	 * Gets the navigation history model of this pane.
	 * @return The navigation history model of this pane.
	 */
	public NavigationHistoryModel
	getModel() { return model; }
	
	/**
	 * Sets the navigation history model of this pane.
	 * @param model A non-null NavigationHistoryModel instance.
	 * @throws IllegalArgumentException If model is null.
	 */
	public void
	setModel(NavigationHistoryModel model) {
		if(model == null) throw new IllegalArgumentException("model must be non null");
		
		NavigationHistoryModel oldModel = this.model;
		this.model = model;
		firePropertyChange("model", oldModel, this.model);
	}
	
	/**
	 * Gets the current page in this navigation pane.
	 * @return The current page in this navigation pane or
	 * null if the history list is empty.
	 */
	public NavigationPage
	getCurrentPage() { return getModel().getCurrentPage(); }
	
	/**
	 * Gets the title's background color of this NavigationPane.
	 * @return The title's background color of this NavigationPane.
	 */
	public Color
	getTitleBackground() { return titleBackground; }
	
	/**
	 * Sets the title's background color of this NavigationPane.
	 * @param c The new title's background color of this NavigationPane.
	 */
	public void
	setTitleBackground(Color c) {
		Color oldColor = titleBackground;
		titleBackground = c;
		firePropertyChange("titleBackground", oldColor, titleBackground);
	}
	
	/**
	 * Determines whether the titlebar should be visible.
	 */
	public void
	setTitlebarVisiblie(boolean b) {
		getUI().setTitlebarVisiblie(b);
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy