001: /**
002: * LibreSource
003: * Copyright (C) 2004-2008 Artenum SARL / INRIA
004: * http://www.libresource.org - contact@artenum.com
005: *
006: * This file is part of the LibreSource software,
007: * which can be used and distributed under license conditions.
008: * The license conditions are provided in the LICENSE.TXT file
009: * at the root path of the packaging that enclose this file.
010: * More information can be found at
011: * - http://dev.libresource.org/home/license
012: *
013: * Initial authors :
014: *
015: * Guillaume Bort / INRIA
016: * Francois Charoy / Universite Nancy 2
017: * Julien Forest / Artenum
018: * Claude Godart / Universite Henry Poincare
019: * Florent Jouille / INRIA
020: * Sebastien Jourdain / INRIA / Artenum
021: * Yves Lerumeur / Artenum
022: * Pascal Molli / Universite Henry Poincare
023: * Gerald Oster / INRIA
024: * Mariarosa Penzi / Artenum
025: * Gerard Sookahet / Artenum
026: * Raphael Tani / INRIA
027: *
028: * Contributors :
029: *
030: * Stephane Bagnier / Artenum
031: * Amadou Dia / Artenum-IUP Blois
032: * ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
033: */package org.libresource.so6.core.ui;
034:
035: import org.libresource.so6.core.interfaces.Closer;
036: import org.libresource.so6.core.ui.util.StyledUI;
037:
038: import java.awt.Color;
039: import java.awt.Component;
040: import java.awt.event.ActionEvent;
041: import java.awt.event.ActionListener;
042:
043: import java.util.ArrayList;
044: import java.util.Iterator;
045:
046: import javax.swing.JMenu;
047: import javax.swing.JMenuBar;
048: import javax.swing.JMenuItem;
049:
050: /**
051: * @author smack
052: */
053: public class BasicMenu extends JMenuBar implements StyledUI,
054: ActionListener {
055: private ArrayList components;
056: private BasicProgressView view;
057: private Closer closer;
058:
059: public BasicMenu() {
060: super ();
061: components = new ArrayList();
062:
063: JMenu menu = new JMenu("File");
064: JMenuItem item = new JMenuItem("Quit");
065: item.setActionCommand("EXIT");
066: item.addActionListener(this );
067: components.add(item);
068: menu.add(item);
069: components.add(menu);
070: add(menu);
071: menu = new JMenu("View");
072: item = new JMenuItem("Show/Hide log");
073: item.setActionCommand("LOG");
074: item.addActionListener(this );
075: components.add(item);
076: menu.add(item);
077: components.add(menu);
078: add(menu);
079: }
080:
081: public void setCloser(Closer closer) {
082: this .closer = closer;
083: }
084:
085: public void setProgressView(BasicProgressView view) {
086: this .view = view;
087: }
088:
089: public void setStyle(Color back, Color forground) {
090: setBackground(back);
091:
092: for (Iterator i = components.iterator(); i.hasNext();) {
093: ((Component) i.next()).setBackground(back);
094: }
095: }
096:
097: public void actionPerformed(ActionEvent e) {
098: String command = e.getActionCommand();
099:
100: if (command.equals("EXIT")) {
101: if (closer != null) {
102: closer.exit();
103: } else {
104: System.exit(0);
105: }
106: } else if (command.equals("LOG")) {
107: if (view.isLogShow()) {
108: view.hideLog();
109: } else {
110: view.showLog();
111: }
112: }
113: }
114: }
|