View Javadoc

1   /*
2    * XMLCV - Gestion de CV sous forme XML
3    * 
4    * Copyright (C) 2004-2005, Damien Raude-Morvan
5    * 
6    * This file is part of XMLCV.
7    *
8    * XMLCV is free software; you can redistribute it and/or modify
9    * it under the terms of the GNU General Public License as published by
10   * the Free Software Foundation; either version 2 of the License, or
11   * (at your option) any later version.
12   *
13   * XMLCV is distributed in the hope that it will be useful,
14   * but WITHOUT ANY WARRANTY; without even the implied warranty of
15   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   * GNU General Public License for more details.
17   *
18   * You should have received a copy of the GNU General Public License
19   * along with XMLCV; if not, write to the Free Software
20   * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
21   * 
22   * Contacts :
23   * - Sébastien Mathy <smathy@tuxfamily.org>
24   * - Emmanuel Berre <eberre@tuxfamily.org>
25   * - Damien Raude-Morvan <drazzib@drazzib.com>
26   */
27  package org.xmlcv.gui;
28  
29  import javax.swing.JInternalFrame;
30  import javax.swing.JTabbedPane;
31  import javax.swing.SwingConstants;
32  import javax.swing.event.ChangeEvent;
33  import javax.swing.event.ChangeListener;
34  
35  import org.xmlcv.CVModel;
36  import org.xmlcv.XmlCVException;
37  import org.xmlcv.gui.listeners.CVInternalFrameListener;
38  import org.xmlcv.gui.tabs.AbstractTab;
39  import org.xmlcv.gui.tabs.TabConferences;
40  import org.xmlcv.gui.tabs.TabEducation;
41  import org.xmlcv.gui.tabs.TabExperience;
42  import org.xmlcv.gui.tabs.TabHoobies;
43  import org.xmlcv.gui.tabs.TabIdentity;
44  import org.xmlcv.gui.tabs.TabKnowledge;
45  import org.xmlcv.gui.tabs.TabProjects;
46  import org.xmlcv.util.I18n;
47  
48  /***
49   * Internal frame for each CV
50   * 
51   * @version $Revision: 114 $
52   * @author <a href="mailto:drazzib@drazzib.com">Damien Raude-Morvan </a>
53   */
54  public class CViFrame extends JInternalFrame {
55  
56  	/*** Tabs */
57  	private JTabbedPane _mainTabPane;
58  
59  	private TabIdentity _identiteTabPane;
60  
61  	private TabEducation _educationTabPane;
62  
63  	private TabExperience _experienceTabPane;
64  
65  	private TabKnowledge _knowledgeTabPane;
66  
67  	private TabProjects _projectsTabPane;
68  
69  	private TabConferences _conferencesTabPane;
70  
71  	private TabHoobies _hoobiesTabPane;
72  
73  	/*** CVDocumentBean (XMLBeans mapping to XML) */
74  	private CVModel _bean;
75  
76  	public CViFrame() {
77  
78  		// Create a new bean
79  		this._bean = new CVModel();
80  
81  		// Use the bean to initialise some UI Components
82  		init();
83  
84  		// Title of this internal frame
85  		this.setTitle(I18n.getString("CvIFrame.newCV")); //$NON-NLS-1$
86  
87  	}
88  
89  	public CViFrame(String absolutePath) throws XmlCVException {
90  
91  		// Load the bean from the file.
92  		this._bean = new CVModel(absolutePath);
93  
94  		// System.out.println("FRAME"+this.bean.getCV());
95  
96  		// Use the bean to initialise some UI Components
97  		init();
98  
99  		// Title of this internal frame
100 		this.setTitle(I18n.getString("CvIFrame.CV") + absolutePath); //$NON-NLS-1$
101 	}
102 
103 	private void init() {
104 
105 		// System.out.println("FRAME"+this.bean.getCV());
106 
107 		// init Panes
108 		this._identiteTabPane = new TabIdentity(this._bean.getCV());
109 		this._educationTabPane = new TabEducation(this._bean.getCV());
110 		this._experienceTabPane = new TabExperience(this._bean.getCV());
111 		this._knowledgeTabPane = new TabKnowledge(this._bean.getCV());
112 		this._projectsTabPane = new TabProjects(this._bean.getCV());
113 		this._conferencesTabPane = new TabConferences(this._bean.getCV());
114 		this._hoobiesTabPane = new TabHoobies(this._bean.getCV());
115 
116 		// add Panes to this TabbedPane
117 		this._mainTabPane = new JTabbedPane();
118 		this._mainTabPane.setTabPlacement(SwingConstants.LEFT);
119 		this._mainTabPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
120 		this._mainTabPane
121 				.insertTab(
122 						I18n.getString("CvIFrame.Identity"), null, this._identiteTabPane, I18n.getString("CvIFrame.Identity"), 0); //$NON-NLS-1$ //$NON-NLS-2$
123 		this._mainTabPane
124 				.insertTab(
125 						I18n.getString("CvIFrame.Formation"), null, this._educationTabPane, I18n.getString("CvIFrame.Formation"), 1); //$NON-NLS-1$ //$NON-NLS-2$
126 		this._mainTabPane
127 				.insertTab(
128 						I18n.getString("CvIFrame.Experience"), null, this._experienceTabPane, I18n.getString("CvIFrame.Experience"), 2); //$NON-NLS-1$ //$NON-NLS-2$
129 		this._mainTabPane
130 				.insertTab(
131 						I18n.getString("CvIFrame.Knowledge"), null, this._knowledgeTabPane, I18n.getString("CvIFrame.Knowledge"), 3); //$NON-NLS-1$ //$NON-NLS-2$
132 		this._mainTabPane
133 				.insertTab(
134 						I18n.getString("CvIFrame.Projects"), null, this._projectsTabPane, I18n.getString("CvIFrame.Projects"), 4); //$NON-NLS-1$ //$NON-NLS-2$
135 		this._mainTabPane
136 				.insertTab(
137 						I18n.getString("CvIFrame.Conferences"), null, this._conferencesTabPane, I18n.getString("CvIFrame.Conferences"), 5); //$NON-NLS-1$ //$NON-NLS-2$
138 		this._mainTabPane
139 				.insertTab(
140 						I18n.getString("CvIFrame.Hoobies"), null, this._hoobiesTabPane, I18n.getString("CvIFrame.Hoobies"), 6); //$NON-NLS-1$ //$NON-NLS-2$
141 
142 		// Register a change listener
143 		this._mainTabPane.addChangeListener(new ChangeListener() {
144 			// This method is called whenever the selected tab changes
145 			public void stateChanged(ChangeEvent evt) {
146 				JTabbedPane pane = (JTabbedPane) evt.getSource();
147 
148 				// Get current tab
149 				AbstractTab currentTab = (AbstractTab) pane
150 						.getSelectedComponent();
151 				//currentTab.saveChangedData();
152 
153 				// FIXME
154 			}
155 		});
156 
157 		// add TabbedPane to main Pane
158 		this.getContentPane().add(this._mainTabPane);
159 
160 		// Add the listener on this new internal frame
161 		this.addInternalFrameListener(new CVInternalFrameListener());
162 
163 		this.setResizable(true);
164 		this.setClosable(true);
165 		this.setMaximizable(true);
166 		this.setIconifiable(false);
167 	}
168 
169 	/***
170 	 * @return Returns the CV bean.
171 	 */
172 	public CVModel getBean() {
173 		return this._bean;
174 	}
175 
176 	/***
177 	 * @param pBean
178 	 *            The CV bean to set.
179 	 */
180 	public void setBean(CVModel pBean) {
181 		this._bean = pBean;
182 	}
183 }