001: /*
002: * SalomeTMF is a Test Management Framework
003: * Copyright (C) 2005 France Telecom R&D
004: *
005: * This library is free software; you can redistribute it and/or
006: * modify it under the terms of the GNU Lesser General Public
007: * License as published by the Free Software Foundation; either
008: * version 2 of the License, or (at your option) any later version.
009: *
010: * This library is distributed in the hope that it will be useful,
011: * but WITHOUT ANY WARRANTY; without even the implied warranty of
012: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013: * Lesser General Public License for more details.
014: *
015: * You should have received a copy of the GNU Lesser General Public
016: * License along with this library; if not, write to the Free Software
017: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
018: *
019: * @author Fayçal SOUGRATI, Vincent Pautret, Marche Mikael
020: *
021: * Contact: mikael.marche@rd.francetelecom.com
022: */
023:
024: package salomeTMF_plug.lookAndfeel;
025:
026: import java.awt.Component;
027: import java.awt.event.ActionEvent;
028: import java.awt.event.ActionListener;
029: import java.net.URL;
030: import java.util.Enumeration;
031: import java.util.Hashtable;
032: import java.util.Properties;
033: import java.util.Vector;
034:
035: import javax.swing.JApplet;
036: import javax.swing.JCheckBoxMenuItem;
037: import javax.swing.JMenu;
038: import javax.swing.JTable;
039: import javax.swing.LookAndFeel;
040: import javax.swing.SwingUtilities;
041: import javax.swing.UIManager;
042: import javax.swing.table.JTableHeader;
043:
044: import org.java.plugin.Plugin;
045: import org.java.plugin.PluginDescriptor;
046: import org.java.plugin.PluginManager;
047: import org.objectweb.salome_tmf.api.Api;
048: import org.objectweb.salome_tmf.api.api2ihm.Utile;
049: import org.objectweb.salome_tmf.ihm.SalomeTMF;
050: import org.objectweb.salome_tmf.ihm.UICompCst;
051: import org.objectweb.salome_tmf.plugins.core.Common;
052:
053: import salomeTMF_plug.lookAndfeel.languages.Language;
054:
055: /**
056: *
057: * @author marchemi
058: */
059: public class LookAndFeelPlugin extends Plugin implements Common,
060: ActionListener {
061:
062: Properties laf_list = null;
063: JApplet ptrSalome;
064: Hashtable avaibleLAF;
065:
066: //Used to identify the windows platform.
067: private static final int WIN_ID = 1;
068:
069: // Used to discover the windows platform.
070: private static final String WIN_PREFIX = "Windows";
071:
072: //Used to discover the mac platform.
073: private static final String MAC_PREFIX = "Mac";
074:
075: //Used to discover the croos platform.
076: private static final String ALL_PREFIX = "All";
077:
078: //Used to discover the linux/unix platform.
079: private static final String UNIX_PREFIX = "Unix";
080:
081: //Used to identify the mac platform.
082: private static final int MAC_ID = 2;
083:
084: //Used to identify the linux/unix platform.
085: private static final int OTHER_ID = -1;
086:
087: JCheckBoxMenuItem defaultCheckItem;
088:
089: Vector componentToRevalidate = new Vector();
090:
091: String url_txt = null;
092:
093: /** Creates a new instance of weightingPlugin */
094: public LookAndFeelPlugin(PluginManager manager,
095: PluginDescriptor descr) {
096: super (manager, descr);
097: avaibleLAF = new Hashtable();
098: }
099:
100: /********************* extends Plugin**********************************/
101:
102: /**
103: * @see org.java.plugin.Plugin()
104: */
105: protected void doStart() throws Exception {
106: Api.log("[lookAndfeelPlugin:doStart] chargement du plugin");
107: }
108:
109: /**
110: * @see org.java.plugin.Plugin()
111: */
112: protected void doStop() throws Exception {
113: // no-op
114: }
115:
116: //********************* interface common ********************//
117:
118: public void activatePluginInCampToolsMenu(javax.swing.JMenu jMenu) {
119: }
120:
121: public void activatePluginInDataToolsMenu(javax.swing.JMenu jMenu) {
122: }
123:
124: public void activatePluginInDynamicComponent(Integer uiCompCst) {
125: Api
126: .log("[LookAndFeel]----------------> activatePluginInDynamicComponent");
127: }
128:
129: public void activatePluginInStaticComponent(Integer uiCompCst) {
130: Api.log("[LookAndFeel] activatePluginInStaticComponent");
131: componentToRevalidate.add(SalomeTMF.getUIComponent(uiCompCst));
132: }
133:
134: public void activatePluginInTestToolsMenu(javax.swing.JMenu jMenu) {
135: jMenu.addSeparator();
136: jMenu.add(createJMenu());
137: }
138:
139: public void freeze() {
140: }
141:
142: public java.util.Vector getUsedUIComponents() {
143: Vector uiComponentsUsed = new Vector();
144:
145: uiComponentsUsed.add(UICompCst.TEST_DYNAMIC_TREE);
146: uiComponentsUsed.add(UICompCst.TEST_SECOND_BUTTONS_PANEL);
147: uiComponentsUsed.add(UICompCst.TEST_CAMP_WORKSPACE_TABS_PANEL);
148:
149: uiComponentsUsed.add(UICompCst.FAMILY_WORKSPACE_PANEL_FOR_TABS);
150: uiComponentsUsed
151: .add(UICompCst.FAMILY_CAMP_WORKSPACE_TABS_PANEL);
152:
153: uiComponentsUsed
154: .add(UICompCst.AUTOMATED_TEST_WORKSPACE_PANEL_FOR_TABS);
155: uiComponentsUsed.add(UICompCst.AUTOMATED_TEST_SCRIPT_PANEL);
156: uiComponentsUsed
157: .add(UICompCst.AUTOMATED_TEST_SCRIPT_BUTTONS_PANEL);
158: uiComponentsUsed
159: .add(UICompCst.AUTOMATED_TEST_SCRIPT_FILENAME_PANEL);
160: uiComponentsUsed
161: .add(UICompCst.AUTOMATED_TEST_SCRIPT_CLASSNAME_PANEL);
162: uiComponentsUsed
163: .add(UICompCst.AUTOMATED_TEST_SCRIPT_EXTENSION_PANEL);
164:
165: uiComponentsUsed
166: .add(UICompCst.MANUAL_TEST_WORKSPACE_PANEL_FOR_TABS);
167: uiComponentsUsed
168: .add(UICompCst.MANUAL_TEST_ACTIONS_BUTTONS_PANEL);
169: uiComponentsUsed.add(UICompCst.MANUAL_TEST_ACTIONS_TABLE);
170: uiComponentsUsed.add(UICompCst.MANUAL_TEST_ACTIONS_PANEL);
171: uiComponentsUsed.add(UICompCst.MANUAL_TEST_ATTACHMENTS_PANEL);
172: uiComponentsUsed.add(UICompCst.MANUAL_TEST_ATTACHMENTS_TABLE);
173: uiComponentsUsed
174: .add(UICompCst.MANUAL_TEST_ATTACHMENTS_BUTTONS_PANEL);
175: uiComponentsUsed
176: .add(UICompCst.MANUAL_TEST_PARAMS_BUTTONS_PANEL);
177: uiComponentsUsed.add(UICompCst.MANUAL_TEST_PARAMS_TABLE);
178: uiComponentsUsed.add(UICompCst.MANUAL_TEST_PARAMS_PANEL);
179:
180: uiComponentsUsed.add(UICompCst.DATA_MANAGEMENT_BUTTONS_PANEL);
181: uiComponentsUsed.add(UICompCst.DATA_MANAGEMENT_ENV_TABLE);
182: uiComponentsUsed
183: .add(UICompCst.DATA_MANAGEMENT_ENV_BUTTONS_PANEL);
184: uiComponentsUsed.add(UICompCst.DATA_MANAGEMENT_REFRESH_ITEM);
185: uiComponentsUsed.add(UICompCst.DATA_PARAMS_BUTTONS_PANEL);
186: uiComponentsUsed.add(UICompCst.DATA_PARAMS_TABLE);
187: uiComponentsUsed.add(UICompCst.DATA_PARAMS_PANEL);
188:
189: uiComponentsUsed
190: .add(UICompCst.TESTLIST_WORKSPACE_PANEL_FOR_TABS);
191: uiComponentsUsed
192: .add(UICompCst.TESTLIST_CAMP_WORKSPACE_TABS_PANEL);
193: uiComponentsUsed.add(UICompCst.TESTLIST_ATTACHMENTS_PANEL);
194: uiComponentsUsed.add(UICompCst.TESTLIST_ATTACHMENTS_TABLE);
195: uiComponentsUsed
196: .add(UICompCst.TESTLIST_ATTACHMENTS_BUTTONS_PANEL);
197:
198: uiComponentsUsed
199: .add(UICompCst.AUTOMATED_TEST_PARAMS_BUTTONS_PANEL);
200: uiComponentsUsed.add(UICompCst.AUTOMATED_TEST_PARAMS_TABLE);
201: uiComponentsUsed.add(UICompCst.AUTOMATED_TEST_PARAMS_PANEL);
202: uiComponentsUsed
203: .add(UICompCst.AUTOMATED_TEST_ATTACHMENTS_BUTTONS_PANEL);
204: uiComponentsUsed
205: .add(UICompCst.AUTOMATED_TEST_ATTACHMENTS_PANEL);
206: uiComponentsUsed
207: .add(UICompCst.AUTOMATED_TEST_ATTACHMENTS_TABLE);
208:
209: uiComponentsUsed.add(UICompCst.PLUGINS_BUTTONS_PANEL);
210: uiComponentsUsed.add(UICompCst.PLUGINS_TABLE);
211: uiComponentsUsed.add(UICompCst.PLUGINS_PANEL);
212:
213: uiComponentsUsed
214: .add(UICompCst.CAMPAIGN_WORKSPACE_PANEL_FOR_TABS);
215: uiComponentsUsed.add(UICompCst.CAMPAIGN_DYNAMIC_TREE);
216: uiComponentsUsed.add(UICompCst.CAMP_EXECUTIONS_BUTTONS_PANEL);
217: uiComponentsUsed.add(UICompCst.CAMP_EXECUTIONS_TABLE);
218: uiComponentsUsed
219: .add(UICompCst.CAMP_EXECUTION_RESULTS_BUTTONS_PANEL);
220: uiComponentsUsed.add(UICompCst.CAMP_EXECUTION_RESULTS_TABLE);
221: uiComponentsUsed.add(UICompCst.CAMP_DATASET_BUTTONS_PANEL);
222: uiComponentsUsed.add(UICompCst.CAMP_DATASETS_TABLE);
223: uiComponentsUsed.add(UICompCst.CAMP_FIRST_BUTTONS_PANEL);
224: uiComponentsUsed.add(UICompCst.CAMP_SECOND_BUTTONS_PANEL);
225: uiComponentsUsed.add(UICompCst.CAMP_ATTACHMENTS_TABLE);
226: uiComponentsUsed.add(UICompCst.CAMP_ATTACHMENTS_BUTTONS_PANEL);
227: uiComponentsUsed.add(UICompCst.CAMP_ATTACHMENTS_PANEL);
228:
229: uiComponentsUsed.add(0, UICompCst.MAIN_TABBED_PANE);
230:
231: return uiComponentsUsed;
232: }
233:
234: public void init(Object pIhm) {
235: try {
236: ptrSalome = ((JApplet) pIhm);
237: String _urlSalome = SalomeTMF.urlSalome.toString();
238: url_txt = _urlSalome.substring(0, _urlSalome
239: .lastIndexOf("/"));
240: Api.log("[LookAndFeel] ressource url is " + url_txt
241: + "/plugins/lookAndfeel/resources/laf.properties");
242: laf_list = Utile.getPropertiesFile(new URL(url_txt
243: + "/plugins/lookAndfeel/resources/laf.properties"));
244: parseProperties();
245: } catch (Exception E) {
246: E.printStackTrace();
247: }
248: }
249:
250: public boolean isActivableInCampToolsMenu() {
251: return false;
252: }
253:
254: public boolean isActivableInDataToolsMenu() {
255: return false;
256: }
257:
258: public boolean isActivableInTestToolsMenu() {
259: return true;
260: }
261:
262: public boolean isFreezable() {
263: return false;
264: }
265:
266: public boolean isFreezed() {
267: return false;
268: }
269:
270: public void unFreeze() {
271: }
272:
273: public boolean usesOtherUIComponents() {
274: return true;
275: }
276:
277: /*************************************************************************************************/
278: /**
279: * Try to apply strclassLAF to salome
280: */
281: boolean applyLAF(String strclassLAF) {
282: try {
283: UIManager.setLookAndFeel(strclassLAF);
284: SwingUtilities.updateComponentTreeUI(ptrSalome);
285: ptrSalome.validate();
286: int nbRevalidateComp = componentToRevalidate.size();
287: for (int i = 0; i < nbRevalidateComp; i++) {
288: try {
289: Object pComponent = (Component) componentToRevalidate
290: .elementAt(i);
291: Api
292: .log("[LookAndFeel] Try to recvalidate LAF on static component "
293: + (Component) componentToRevalidate
294: .elementAt(i));
295: if (pComponent != null) {
296: SwingUtilities
297: .updateComponentTreeUI((Component) componentToRevalidate
298: .elementAt(i));
299: if (componentToRevalidate.elementAt(i) instanceof JTable) {
300: Api
301: .log("[LookAndFeel] Try to recvalidate a JTable");
302: JTable pJTable = (JTable) componentToRevalidate
303: .elementAt(i);
304: JTableHeader pJTableHeader = pJTable
305: .getTableHeader();
306: if (pJTableHeader != null) {
307: SwingUtilities
308: .updateComponentTreeUI(pJTableHeader);
309: pJTableHeader.validate();
310: }
311: pJTable.validate();
312: } else {
313: ((Component) componentToRevalidate
314: .elementAt(i)).validate();
315: }
316: }
317: } catch (Exception ex1) {
318: ex1.printStackTrace();
319: }
320: }
321: //SwingUtilities.updateComponentTreeUI(ManualActionView.actionsPanel);
322: return true;
323: } catch (Exception ex) {
324: Api.log("[LookAndFeel] applyLAF FAIL ");
325: return false;
326: }
327: }
328:
329: /**
330: * Parse the properties files to load LAF avaible
331: */
332: private void parseProperties() {
333: if (laf_list == null) {
334: return;
335: }
336: Enumeration e = laf_list.propertyNames();
337: Api.log("[LookAndFeel] Parse avaible LAF");
338: while (e.hasMoreElements()) {
339: String key = (String) e.nextElement();
340: Api.log("[LookAndFeel] Found " + key);
341: String value = laf_list.getProperty(key);
342: String[] info = value.split(":");
343: Api.log("[LookAndFeel] info length is " + info.length);
344: if (info.length == 2) {
345: if (isCompatibleLAF(info[0])) {
346: LAF pLAF = new LAF(key, info[1]);
347: JCheckBoxMenuItem pCheckboxMenuItem = new JCheckBoxMenuItem(
348: key, false);
349: pCheckboxMenuItem.addActionListener(this );
350: avaibleLAF.put(pCheckboxMenuItem, pLAF);
351: }
352: }
353: }
354: LookAndFeel pLookAndFeel = UIManager.getLookAndFeel();
355: if (pLookAndFeel != null) {
356: LAF pLAF = new LAF(pLookAndFeel.getName(), pLookAndFeel
357: .getClass().getName());
358: JCheckBoxMenuItem pCheckboxMenuItem = new JCheckBoxMenuItem(
359: pLookAndFeel.getName(), true);
360: pCheckboxMenuItem.addActionListener(this );
361: avaibleLAF.put(pCheckboxMenuItem, pLAF);
362: defaultCheckItem = pCheckboxMenuItem;
363: }
364: }
365:
366: /**
367: * Try to determine whether this application is running under Windows or
368: * some other platform by examing the "os.name" property.
369: *
370: * @return the ID of the platform
371: */
372: private static int getPlatform() {
373: String os = System.getProperty("os.name");
374: if (os != null && os.startsWith(WIN_PREFIX))
375: return WIN_ID;
376: if (os != null && os.startsWith(MAC_PREFIX))
377: return MAC_ID;
378: return OTHER_ID;
379: }
380:
381: /**
382: * Try to determine whether this laf is compatible under Windows or
383: * some other platform by comparing with the "os.name" property.
384: *
385: */
386: private boolean isCompatibleLAF(String key) {
387: int os = getPlatform();
388: Api.log("[LookAndFeel] is compatible " + key + " with " + os);
389: if (key.startsWith(ALL_PREFIX))
390: return true;
391: if (key.startsWith(WIN_PREFIX) && os == WIN_ID)
392: return true;
393: if (key.startsWith(MAC_PREFIX) && os == MAC_ID)
394: return true;
395: if (key.startsWith(UNIX_PREFIX) && os == OTHER_ID)
396: return true;
397:
398: return false;
399: }
400:
401: public void actionPerformed(ActionEvent e) {
402: Object source = e.getSource();
403: LAF pLAF = (LAF) avaibleLAF.get(source);
404: if (applyLAF(pLAF.classLAF)) {
405: //((SalomeTMF)ptrSalome).workSpaceTest.removeAll();
406: //TestMethods.refreshFromBase();
407: defaultCheckItem.setState(false);
408: defaultCheckItem = (JCheckBoxMenuItem) source;
409: defaultCheckItem.setState(true);
410: } else {
411: ((JCheckBoxMenuItem) source).setState(false);
412: }
413:
414: }
415:
416: private JMenu createJMenu() {
417: JMenu lookAndfeelSubMenu;
418: lookAndfeelSubMenu = new JMenu(Language.getInstance().getText(
419: "Modifier_laf_de_salome"));
420:
421: Enumeration pCheckboxMenuItems = avaibleLAF.keys();
422: while (pCheckboxMenuItems.hasMoreElements()) {
423: lookAndfeelSubMenu
424: .add((JCheckBoxMenuItem) pCheckboxMenuItems
425: .nextElement());
426: }
427:
428: return lookAndfeelSubMenu;
429: }
430: }
|