summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-11-19 09:41:16 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-11-25 06:07:04 +0000
commit41d3adbe47610efc1e7bc848c129024a2ec19f9a (patch)
tree555130049656ef35cd12ac0c924765d76ee2fda5
parent58eab57648e222e5a3e488087afd44eea6efd591 (diff)
java: simplify the CommonListener stuff
by moving the MethodInvocation to be purely an internal detail Change-Id: Id7863261abd5ebd30b7596bac756ca5360119283 Reviewed-on: https://gerrit.libreoffice.org/13100 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
-rw-r--r--wizards/com/sun/star/wizards/ui/ImageList.java12
-rw-r--r--wizards/com/sun/star/wizards/ui/WizardDialog.java11
-rw-r--r--wizards/com/sun/star/wizards/ui/event/CommonListener.java12
-rw-r--r--wizards/com/sun/star/wizards/ui/event/MethodInvocation.java44
4 files changed, 30 insertions, 49 deletions
diff --git a/wizards/com/sun/star/wizards/ui/ImageList.java b/wizards/com/sun/star/wizards/ui/ImageList.java
index 0ae99b776218..342f264c8e54 100644
--- a/wizards/com/sun/star/wizards/ui/ImageList.java
+++ b/wizards/com/sun/star/wizards/ui/ImageList.java
@@ -80,7 +80,6 @@ public class ImageList implements XItemEventBroadcaster, ListDataListener
private final static Short HIDE_PAGE = Short.valueOf((short) 99);
private final static Integer TRANSPARENT = Integer.valueOf(-1);
private final static int LINE_HEIGHT = 8;
- private MethodInvocation METHOD_MOUSE_PRESSED;
/** Getter for property imageSize.
* @return Value of property imageSize.
@@ -272,15 +271,6 @@ public class ImageList implements XItemEventBroadcaster, ListDataListener
m_aImages = new XControl[rows * cols];
- try
- {
- METHOD_MOUSE_PRESSED = new MethodInvocation("mousePressed", this, Object.class);
- }
- catch (NoSuchMethodException e)
- {
- e.printStackTrace();
- }
-
m_imageHeight = Integer.valueOf(imageSize.Height);
m_imageWidth = Integer.valueOf(imageSize.Width);
@@ -337,7 +327,7 @@ public class ImageList implements XItemEventBroadcaster, ListDataListener
XWindow win = UnoRuntime.queryInterface(XWindow.class, image);
win.addMouseListener(uiEventListener);
win.addKeyListener(imageKeyListener);
- uiEventListener.add(imageName, EventNames.MOUSE_PRESSED, METHOD_MOUSE_PRESSED);
+ uiEventListener.add(imageName, EventNames.MOUSE_PRESSED, "mousePressed", this, Object.class);
return image;
}
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.java b/wizards/com/sun/star/wizards/ui/WizardDialog.java
index 8b8e079c6550..dd64b9272de6 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.java
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.java
@@ -20,7 +20,6 @@ package com.sun.star.wizards.ui;
import java.beans.*;
import com.sun.star.wizards.ui.event.EventNames;
-import com.sun.star.wizards.ui.event.MethodInvocation;
import com.sun.star.uno.UnoRuntime;
import com.sun.star.awt.*;
import com.sun.star.uno.AnyConverter;
@@ -241,18 +240,13 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
xSSFRoadmap = UnoRuntime.queryInterface(XSingleServiceFactory.class, oRoadmap);
xIndexContRoadmap = UnoRuntime.queryInterface(XIndexContainer.class, oRoadmap);
- MethodInvocation mi = new MethodInvocation("itemStateChanged", this, com.sun.star.awt.ItemEvent.class);
- guiEventListener.add("rdmNavi", EventNames.ITEM_CHANGED, mi);
+ guiEventListener.add("rdmNavi", EventNames.ITEM_CHANGED, "itemStateChanged", this, com.sun.star.awt.ItemEvent.class);
xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl);
xRoadmapBroadcaster.addItemListener(guiEventListener);
Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16));
}
- catch (NoSuchMethodException ex)
- {
- Resource.showCommonResourceError(xMSF);
- }
catch (java.lang.Exception jexception)
{
jexception.printStackTrace(System.err);
@@ -481,10 +475,9 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
// add a window listener, to know
// if the user used "escape" key to
// close the dialog.
- MethodInvocation windowHidden = new MethodInvocation("windowHidden", this);
xWindow.addWindowListener(guiEventListener);
String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_NAME);
- guiEventListener.add(dialogName, EventNames.ACTION_PERFORMED, windowHidden);
+ guiEventListener.add(dialogName, EventNames.ACTION_PERFORMED, "windowHidden", this);
}
catch (java.lang.Exception jexception)
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.java b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
index d75a24f17ffd..cff92812d129 100644
--- a/wizards/com/sun/star/wizards/ui/event/CommonListener.java
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
@@ -54,6 +54,18 @@ public class CommonListener implements XActionListener, XItemListener, XTextList
}
}
+ public void add(String componentName, EventNames eventName, String methodName, Object target, Class<?> paramClass)
+ {
+ try
+ {
+ add(componentName, eventName, new MethodInvocation(methodName, target, paramClass));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
public void add(String componentName, EventNames eventName, MethodInvocation mi)
{
mHashtable.put(componentName + eventName, mi);
diff --git a/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java b/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java
index 5ac4f0e56a6f..fb834b45d1d3 100644
--- a/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java
+++ b/wizards/com/sun/star/wizards/ui/event/MethodInvocation.java
@@ -30,35 +30,29 @@ import java.lang.reflect.Method;
* You can trick this class how much you want: it will all throw exceptions
* on the java level. i throw no error warnings or my own exceptions...</p>
*/
-public class MethodInvocation
+final class MethodInvocation
{
//the method to invoke.
- Method mMethod;
+ private final Method mMethod;
//the object to invoke the method on.
- Object mObject;
+ private final Object mTargetObject;
//with one Parameter / without
- boolean mWithParam;
+ private final boolean mWithParam;
/** Creates a new instance of MethodInvokation */
- public MethodInvocation(String methodName, Object obj) throws NoSuchMethodException
+ public MethodInvocation(String methodName, Object target) throws NoSuchMethodException
{
- this(methodName, obj, null);
+ this(methodName, target, null);
}
- public MethodInvocation(Method method, Object obj)
+ public MethodInvocation(String methodName, Object target, Class<?> paramClass) throws NoSuchMethodException
{
- this(method, obj, null);
- }
-
- public MethodInvocation(String methodName, Object obj, Class<?> paramClass) throws NoSuchMethodException
- {
- this(paramClass == null ? obj.getClass().getMethod(methodName) : obj.getClass().getMethod(methodName, paramClass), obj, paramClass);
- }
-
- public MethodInvocation(Method method, Object obj, Class<?> paramClass)
- {
- mMethod = method;
- mObject = obj;
+ if (paramClass == null) {
+ mMethod = target.getClass().getMethod(methodName);
+ } else {
+ mMethod = target.getClass().getMethod(methodName, paramClass);
+ }
+ mTargetObject = target;
mWithParam = paramClass != null;
}
@@ -69,20 +63,12 @@ public class MethodInvocation
{
if (mWithParam)
{
- return mMethod.invoke(mObject, param);
+ return mMethod.invoke(mTargetObject, param);
}
else
{
- return mMethod.invoke(mObject);
+ return mMethod.invoke(mTargetObject);
}
}
- /**
- * This method is a convenience method.
- * It is the same as calling invoke(null);
- */
- public Object invoke() throws IllegalAccessException, InvocationTargetException
- {
- return invoke(null);
- }
}