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

bibliothek.notes.view.menu.ThemeMenu Maven / Gradle / Ivy

package bibliothek.notes.view.menu;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import javax.swing.JRadioButtonMenuItem;

import bibliothek.gui.DockFrontend;
import bibliothek.gui.DockTheme;
import bibliothek.gui.dock.themes.NoStackTheme;
import bibliothek.notes.view.themes.*;
import bibliothek.util.xml.XElement;

/**
 * A menu that allows the selection of a new {@link DockTheme}.
 * @author Benjamin Sigg
 *
 */
public class ThemeMenu extends JMenu{
    /** the root of the dock-tree */
	private DockFrontend frontend;
	/** ensures that only one of the radio-items is selected */
	private ButtonGroup group;
	
	/** the children of this menu */
	private List items = new ArrayList();
	/** the themes available to the user */
	private List themes = new ArrayList();
	
	/**
	 * Creates a new menu
	 * @param frontend the root of the dock-tree
	 */
	public ThemeMenu( DockFrontend frontend ){
		this.frontend = frontend;
		setText( "Theme" );
		
		group = new ButtonGroup();
		
		add( createItem( "BasicTheme", new NoteBasicTheme() ));
		add( createItem( "NoStack-BasicTheme", new NoStackTheme( new NoteBasicTheme() ) ));
		add( createItem( "SmoothTheme", new NoteSmoothTheme() ));
		add( createItem( "NoStack-SmoothTheme", new NoStackTheme( new NoteSmoothTheme() )));
		add( createItem( "FlatTheme", new NoteFlatTheme() ));
		add( createItem( "NoStack-FlatTheme", new NoStackTheme( new NoteFlatTheme() )));
		add( createItem( "BubbleTheme", new NoteBubbleTheme() ));
		add( createItem( "NoStack-BubbleTheme", new NoStackTheme( new NoteBubbleTheme() )));
		add( createItem( "Eclipse", new NoteEclipseTheme() ));
	}
	
	/**
	 * Creates a new item of this menu. The new item allows to select
	 * the {@link DockTheme} theme.
	 * @param title the text of the item
	 * @param theme the theme that can be selected by clicking onto the new item
	 * @return the new item
	 */
	private JMenuItem createItem( String title, final DockTheme theme ){
		JRadioButtonMenuItem item = new JRadioButtonMenuItem( title );
		items.add( item );
		themes.add( theme );
		
		group.add( item );
		item.addActionListener( new ActionListener(){
			public void actionPerformed( ActionEvent e ){
				frontend.getController().setTheme( theme );
			}
		});
		return item;
	}
	
	/**
     * Writes which theme is currently selected.
     * @param out the stream to write into
     * @throws IOException if the method can't write into out
     */
    public void write( DataOutputStream out ) throws IOException{
        int index = -1;
        for( int i = 0, n = items.size(); iin can't be read
	 */
	public void read( DataInputStream in ) throws IOException{
		int index = in.readInt();
		if( index < 0 )
			index = 0;
		
		items.get( index ).setSelected( true );
		frontend.getController().setTheme( themes.get( index ) );
	}
	
	/**
     * Writes which theme is currently selected.
     * @params element the xml-element to write into
     */
    public void writeXML( XElement element ){
        int index = -1;
        for( int i = 0, n = items.size(); i




© 2015 - 2024 Weber Informatics LLC | Privacy Policy