Le 28/07/2012 12:57, sebb a ecrit :
On 28 July 2012 12:29,<[email protected]> wrote:
Author: milamber
Date: Sat Jul 28 11:29:23 2012
New Revision: 1366644
URL: http://svn.apache.org/viewvc?rev=1366644&view=rev
Log:
Display 'Apache JMeter' title in app title bar in Gnome 3
Bugzilla Id: 53616
Modified:
jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
Modified: jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java
URL:
http://svn.apache.org/viewvc/jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java?rev=1366644&r1=1366643&r2=1366644&view=diff
==============================================================================
--- jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java (original)
+++ jmeter/trunk/src/core/org/apache/jmeter/gui/MainFrame.java Sat Jul 28
11:29:23 2012
@@ -23,6 +23,7 @@ import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
+import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
@@ -39,6 +40,7 @@ import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import java.io.File;
import java.io.IOException;
+import java.lang.reflect.Field;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@@ -101,9 +103,12 @@ public class MainFrame extends JFrame im
// The name is chosen to be an unlikely host-name
private static final String LOCAL = "*local*"; // $NON-NLS-1$
+ // The application name
+ private static final String DEFAULT_APP_NAME = "Apache JMeter"; //
$NON-NLS-1$
+
// The default title for the Menu bar
- private static final String DEFAULT_TITLE =
- "Apache JMeter ("+JMeterUtils.getJMeterVersion()+")"; // $NON-NLS-1$
$NON-NLS-2$
+ private static final String DEFAULT_TITLE = DEFAULT_APP_NAME +
+ " (" + JMeterUtils.getJMeterVersion() + ")"; // $NON-NLS-1$
$NON-NLS-2$
// Allow display/hide toolbar
private static final boolean DISPLAY_TOOLBAR =
@@ -491,6 +496,7 @@ public class MainFrame extends JFrame im
setTitle(DEFAULT_TITLE);
setIconImage(JMeterUtils.getImage("jmeter.jpg").getImage());//
$NON-NLS-1$
+ setWindowTitle(); // define AWT WM_CLASS string
}
@@ -776,4 +782,22 @@ public class MainFrame extends JFrame im
ActionRouter.getInstance().doActionNow(new
ActionEvent(event.getSource(), event.getID(),
ActionNames.LOGGER_PANEL_ENABLE_DISABLE));
}
}
+
+ /**
+ * Define AWT window title (WM_CLASS string) (useful on Gnome 3 / Linux)
+ */
+ private void setWindowTitle() {
+ Class<?> xtoolkit = Toolkit.getDefaultToolkit().getClass();
+ if (xtoolkit.getName().equals("sun.awt.X11.XToolkit")) { // $NON-NLS-1$
+ try {
+ final Field awtAppClassName =
xtoolkit.getDeclaredField("awtAppClassName"); // $NON-NLS-1$
+ awtAppClassName.setAccessible(true);
+ awtAppClassName.set(null, DEFAULT_APP_NAME);
Do we need to call
awtAppClassName.setAccessible(false);
to reset the state?
Yes to permit to set the app name (not work without)
Or perhaps fetch isAccessible() and use that to decide whether to call
setAccessible twice or not at all.
On my computer (Debian testing), isAccessible is always false.
I thinks that is not necessary to add a if statement on isAccessible
condition.
+ } catch (NoSuchFieldException nsfe) {
+ log.warn("Error awt title: " + nsfe); // $NON-NLS-1$
+ } catch (IllegalAccessException iae) {
+ log.warn("Error awt title: " + iae); // $NON-NLS-1$
+ }
Are there any other possible errors that can occur?
e.g. SecurityException ?
The conditions to raise a SecurityException seems not meet in this case
http://docs.oracle.com/javase/1.5.0/docs/api/java/lang/reflect/AccessibleObject.html#setAccessible(boolean)
But, I can modify the catch blocks with a unique catch block "Exception"
(or add a new block "SecurityException")
If this fix is only needed on some hosts, perhaps check the host type?
Or is the toolkit class name a sufficient indicator?
Yes I think.
On my Windows 7, JMeter don't enter in the If getName statement/
i.e. do all installations with that classname need the patch?
Yes, I suppose for all Linux/Unix with X11 and a window manager like
Gnome 3 or Unity (Ubuntu)
Milamber
+ }
+ }
}
\ No newline at end of file