summaryrefslogtreecommitdiff
path: root/wizards
diff options
context:
space:
mode:
authorNoel Grandin <noel@peralex.com>2014-11-18 13:07:45 +0200
committerNoel Grandin <noelgrandin@gmail.com>2014-11-24 11:58:23 +0000
commit926744de7a9bb9375f41972f977bfa25fc837c15 (patch)
tree8ab8c99bb4eb8d23e468b9611adba915b5e8bdda /wizards
parentb7f67f24bbe9ced0dfefda674d96fa1d41cdf062 (diff)
merge AbstractListener into CommonListener
since CommonListener is the only subclass Change-Id: If10ccb29991d7c48e2c20fc41330572a669f1497 Reviewed-on: https://gerrit.libreoffice.org/13094 Reviewed-by: Noel Grandin <noelgrandin@gmail.com> Tested-by: Noel Grandin <noelgrandin@gmail.com>
Diffstat (limited to 'wizards')
-rw-r--r--wizards/Jar_commonwizards.mk1
-rw-r--r--wizards/com/sun/star/wizards/ui/UnoDialog.java2
-rw-r--r--wizards/com/sun/star/wizards/ui/UnoDialog2.java21
-rw-r--r--wizards/com/sun/star/wizards/ui/WizardDialog.java5
-rw-r--r--wizards/com/sun/star/wizards/ui/event/AbstractListener.java119
-rw-r--r--wizards/com/sun/star/wizards/ui/event/CommonListener.java97
6 files changed, 108 insertions, 137 deletions
diff --git a/wizards/Jar_commonwizards.mk b/wizards/Jar_commonwizards.mk
index a13a114162ff..f0945e3d6526 100644
--- a/wizards/Jar_commonwizards.mk
+++ b/wizards/Jar_commonwizards.mk
@@ -75,7 +75,6 @@ $(eval $(call gb_Jar_add_sourcefiles,commonwizards,\
wizards/com/sun/star/wizards/db/TableDescriptor \
wizards/com/sun/star/wizards/db/SQLQueryComposer \
wizards/com/sun/star/wizards/db/DatabaseObjectWizard \
- wizards/com/sun/star/wizards/ui/event/AbstractListener \
wizards/com/sun/star/wizards/ui/event/CommonListener \
wizards/com/sun/star/wizards/ui/event/DataAware \
wizards/com/sun/star/wizards/ui/event/DataAwareFields \
diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog.java b/wizards/com/sun/star/wizards/ui/UnoDialog.java
index d5a0d8e6abec..115f727eed3f 100644
--- a/wizards/com/sun/star/wizards/ui/UnoDialog.java
+++ b/wizards/com/sun/star/wizards/ui/UnoDialog.java
@@ -55,7 +55,7 @@ public class UnoDialog implements EventNames
public Resource m_oResource;
public XWindowPeer xWindowPeer = null;
private PeerConfig m_oPeerConfig;
- protected final AbstractListener guiEventListener = new CommonListener();
+ protected final CommonListener guiEventListener = new CommonListener();
public UnoDialog(XMultiServiceFactory xMSF)
{
diff --git a/wizards/com/sun/star/wizards/ui/UnoDialog2.java b/wizards/com/sun/star/wizards/ui/UnoDialog2.java
index ab41e0e5eded..02684744a83b 100644
--- a/wizards/com/sun/star/wizards/ui/UnoDialog2.java
+++ b/wizards/com/sun/star/wizards/ui/UnoDialog2.java
@@ -25,7 +25,6 @@ import com.sun.star.wizards.common.Desktop;
import com.sun.star.wizards.common.Helper;
import com.sun.star.wizards.common.PropertyNames;
import com.sun.star.wizards.common.SystemDialog;
-import com.sun.star.wizards.ui.event.*;
/**
* This class contains convenience methods for inserting components to a dialog.
@@ -33,7 +32,7 @@ import com.sun.star.wizards.ui.event.*;
* description files to a Java class which builds the same dialog through the UNO API.</p>
* <p>It uses an Event-Listener method, which calls a method through reflection
* when an event on a component is triggered.
- * see the classes AbstractListener, CommonListener, MethodInvocation for details.</p>
+ * see the classes CommonListener, MethodInvocation for details.</p>
*/
public class UnoDialog2 extends UnoDialog
{
@@ -50,7 +49,7 @@ public class UnoDialog2 extends UnoDialog
if (actionPerformed != null)
{
- xButton.addActionListener((XActionListener) guiEventListener);
+ xButton.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
}
return xButton;
@@ -85,7 +84,7 @@ public class UnoDialog2 extends UnoDialog
if (itemChanged != null)
{
- xCheckBox.addItemListener((XItemListener) guiEventListener);
+ xCheckBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
}
return xCheckBox;
@@ -101,18 +100,18 @@ public class UnoDialog2 extends UnoDialog
XComboBox xComboBox = (XComboBox) insertControlModel2("com.sun.star.awt.UnoControlComboBoxModel", sName, sPropNames, oPropValues, XComboBox.class);
if (actionPerformed != null)
{
- xComboBox.addActionListener((XActionListener) guiEventListener);
+ xComboBox.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
}
if (itemChanged != null)
{
- xComboBox.addItemListener((XItemListener) guiEventListener);
+ xComboBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
}
if (textChanged != null)
{
XTextComponent xTextComponent = UnoRuntime.queryInterface(XTextComponent.class, xComboBox);
- xTextComponent.addTextListener((XTextListener) guiEventListener);
+ xTextComponent.addTextListener(guiEventListener);
guiEventListener.add(sName, EVENT_TEXT_CHANGED, textChanged, eventTarget);
}
return xComboBox;
@@ -128,12 +127,12 @@ public class UnoDialog2 extends UnoDialog
XListBox xListBox = (XListBox) insertControlModel2("com.sun.star.awt.UnoControlListBoxModel", sName, sPropNames, oPropValues, XListBox.class);
if (actionPerformed != null)
{
- xListBox.addActionListener((XActionListener) guiEventListener);
+ xListBox.addActionListener(guiEventListener);
guiEventListener.add(sName, EVENT_ACTION_PERFORMED, actionPerformed, eventTarget);
}
if (itemChanged != null)
{
- xListBox.addItemListener((XItemListener) guiEventListener);
+ xListBox.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
}
return xListBox;
@@ -149,7 +148,7 @@ public class UnoDialog2 extends UnoDialog
XRadioButton xRadioButton = (XRadioButton) insertControlModel2("com.sun.star.awt.UnoControlRadioButtonModel", sName, sPropNames, oPropValues, XRadioButton.class);
if (itemChanged != null)
{
- xRadioButton.addItemListener((XItemListener) guiEventListener);
+ xRadioButton.addItemListener(guiEventListener);
guiEventListener.add(sName, EVENT_ITEM_CHANGED, itemChanged, eventTarget);
}
return xRadioButton;
@@ -205,7 +204,7 @@ public class UnoDialog2 extends UnoDialog
XTextComponent xField = (XTextComponent) insertControlModel2(sModelClass, sName, sPropNames, oPropValues, XTextComponent.class);
if (sTextChanged != null)
{
- xField.addTextListener((XTextListener) guiEventListener);
+ xField.addTextListener(guiEventListener);
guiEventListener.add(sName, EVENT_TEXT_CHANGED, sTextChanged, eventTarget);
}
return UnoRuntime.queryInterface(type, xField);
diff --git a/wizards/com/sun/star/wizards/ui/WizardDialog.java b/wizards/com/sun/star/wizards/ui/WizardDialog.java
index 3b8d74f0fbc5..3b0136ccf4b7 100644
--- a/wizards/com/sun/star/wizards/ui/WizardDialog.java
+++ b/wizards/com/sun/star/wizards/ui/WizardDialog.java
@@ -19,7 +19,6 @@ package com.sun.star.wizards.ui;
import java.beans.*;
-import com.sun.star.wizards.ui.event.CommonListener;
import com.sun.star.wizards.ui.event.EventNames;
import com.sun.star.wizards.ui.event.MethodInvocation;
import com.sun.star.uno.UnoRuntime;
@@ -246,7 +245,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
guiEventListener.add("rdmNavi", EventNames.EVENT_ITEM_CHANGED, mi);
xRoadmapControl = this.xDlgContainer.getControl("rdmNavi");
xRoadmapBroadcaster = UnoRuntime.queryInterface(XItemEventBroadcaster.class, xRoadmapControl);
- xRoadmapBroadcaster.addItemListener((XItemListener) guiEventListener);
+ xRoadmapBroadcaster.addItemListener(guiEventListener);
Helper.setUnoPropertyValue(oRoadmap, "Text", oWizardResource.getResText(UIConsts.RID_COMMON + 16));
}
@@ -483,7 +482,7 @@ public abstract class WizardDialog extends UnoDialog2 implements VetoableChangeL
// if the user used "escape" key to
// close the dialog.
MethodInvocation windowHidden = new MethodInvocation("windowHidden", this);
- xWindow.addWindowListener((CommonListener) guiEventListener);
+ xWindow.addWindowListener(guiEventListener);
String dialogName = (String) Helper.getUnoPropertyValue(xDialogModel, PropertyNames.PROPERTY_NAME);
guiEventListener.add(dialogName, EVENT_ACTION_PERFORMED, windowHidden);
diff --git a/wizards/com/sun/star/wizards/ui/event/AbstractListener.java b/wizards/com/sun/star/wizards/ui/event/AbstractListener.java
deleted file mode 100644
index 488c9fd4c580..000000000000
--- a/wizards/com/sun/star/wizards/ui/event/AbstractListener.java
+++ /dev/null
@@ -1,119 +0,0 @@
-/*
- * This file is part of the LibreOffice project.
- *
- * This Source Code Form is subject to the terms of the Mozilla Public
- * License, v. 2.0. If a copy of the MPL was not distributed with this
- * file, You can obtain one at http://mozilla.org/MPL/2.0/.
- *
- * This file incorporates work covered by the following license notice:
- *
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed
- * with this work for additional information regarding copyright
- * ownership. The ASF licenses this file to you under the Apache
- * License, Version 2.0 (the "License"); you may not use this file
- * except in compliance with the License. You may obtain a copy of
- * the License at http://www.apache.org/licenses/LICENSE-2.0 .
- */
-package com.sun.star.wizards.ui.event;
-
-import com.sun.star.awt.XControl;
-import com.sun.star.lang.EventObject;
-import com.sun.star.uno.UnoRuntime;
-import com.sun.star.wizards.common.Helper;
-import com.sun.star.wizards.common.PropertyNames;
-
-import java.lang.reflect.InvocationTargetException;
-import java.util.HashMap;
-
-/**
- * This class is a base class for listener classes.
- * <p>It uses a hashtable to map between a ComponentName, EventName and a MethodInvokation Object.
- * To use this class do the following:</p>
- * <ul>
- * <li>Write a subclass which implements the needed Listener(s).</li>
- * <li>In the even methods, use invoke(...).</li>
- * <li>When instantiating the component, register the subclass as the event listener.</li>
- * <li>Write the methods which should be performed when the event occurs.</li>
- * <li>call the "add" method, to define a component-event-action mapping.</li>
- * </ul>
- */
-public class AbstractListener
-{
-
- private final HashMap<String,MethodInvocation> mHashtable = new HashMap<String,MethodInvocation>();
-
- public void add(String componentName, String eventName, String methodName, Object target)
- {
- try
- {
- add(componentName, eventName, new MethodInvocation(methodName, target));
- }
- catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- public void add(String componentName, String eventName, MethodInvocation mi)
- {
- mHashtable.put(componentName + eventName, mi);
- }
-
- public MethodInvocation get(String componentName, String eventName)
- {
- return mHashtable.get(componentName + eventName);
- }
-
- public Object invoke(String componentName, String eventName, Object param)
- {
- try
- {
- MethodInvocation mi = get(componentName, eventName);
- if (mi != null)
- {
- return mi.invoke(param);
- }
- else
- {
- return null;
- }
- }
- catch (InvocationTargetException ite)
- {
-
- System.out.println("=======================================================");
- System.out.println("=== Note: An Exception was thrown which should have ===");
- System.out.println("=== caused a crash. I caught it. Please report this ===");
- System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
- System.out.println("=======================================================");
-
- ite.printStackTrace();
-
- }
- catch (IllegalAccessException iae)
- {
- iae.printStackTrace();
- }
- catch (Exception ex)
- {
- System.out.println("=======================================================");
- System.out.println("=== Note: An Exception was thrown which should have ===");
- System.out.println("=== caused a crash. I caught it. Please report this ===");
- System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
- System.out.println("=======================================================");
- ex.printStackTrace();
- }
-
- return null;
- }
-
- /**
- * Rerurns the property "name" of the Object which is the source of the event.
- */
- public static String getEventSourceName(EventObject eventObject)
- {
- XControl xControl = UnoRuntime.queryInterface(XControl.class, eventObject.Source);
- return (String) Helper.getUnoPropertyValue(xControl.getModel(), PropertyNames.PROPERTY_NAME, String.class);
- }
-}
diff --git a/wizards/com/sun/star/wizards/ui/event/CommonListener.java b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
index 8b455b517d44..7723e4bd8d7a 100644
--- a/wizards/com/sun/star/wizards/ui/event/CommonListener.java
+++ b/wizards/com/sun/star/wizards/ui/event/CommonListener.java
@@ -17,12 +17,105 @@
*/
package com.sun.star.wizards.ui.event;
+import java.lang.reflect.InvocationTargetException;
+import java.util.HashMap;
+
import com.sun.star.awt.*;
import com.sun.star.lang.EventObject;
-
-public class CommonListener extends AbstractListener implements XActionListener, XItemListener, XTextListener, EventNames, XWindowListener, XMouseListener, XFocusListener, XKeyListener
+import com.sun.star.uno.UnoRuntime;
+import com.sun.star.wizards.common.Helper;
+import com.sun.star.wizards.common.PropertyNames;
+
+/**
+ * <p>It uses a hashtable to map between a ComponentName, EventName and a MethodInvokation Object.
+ * To use this class do the following:</p>
+ * <ul>
+ * <li>Write a subclass which implements the needed Listener(s).</li>
+ * <li>In the even methods, use invoke(...).</li>
+ * <li>When instantiating the component, register the subclass as the event listener.</li>
+ * <li>Write the methods which should be performed when the event occurs.</li>
+ * <li>call the "add" method, to define a component-event-action mapping.</li>
+ * </ul>
+ */
+public class CommonListener implements XActionListener, XItemListener, XTextListener, EventNames, XWindowListener, XMouseListener, XFocusListener, XKeyListener
{
+ private final HashMap<String,MethodInvocation> mHashtable = new HashMap<String,MethodInvocation>();
+
+ public void add(String componentName, String eventName, String methodName, Object target)
+ {
+ try
+ {
+ add(componentName, eventName, new MethodInvocation(methodName, target));
+ }
+ catch (Exception ex)
+ {
+ ex.printStackTrace();
+ }
+ }
+
+ public void add(String componentName, String eventName, MethodInvocation mi)
+ {
+ mHashtable.put(componentName + eventName, mi);
+ }
+
+ private MethodInvocation get(String componentName, String eventName)
+ {
+ return mHashtable.get(componentName + eventName);
+ }
+
+ private Object invoke(String componentName, String eventName, Object param)
+ {
+ try
+ {
+ MethodInvocation mi = get(componentName, eventName);
+ if (mi != null)
+ {
+ return mi.invoke(param);
+ }
+ else
+ {
+ return null;
+ }
+ }
+ catch (InvocationTargetException ite)
+ {
+
+ System.out.println("=======================================================");
+ System.out.println("=== Note: An Exception was thrown which should have ===");
+ System.out.println("=== caused a crash. I caught it. Please report this ===");
+ System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
+ System.out.println("=======================================================");
+
+ ite.printStackTrace();
+
+ }
+ catch (IllegalAccessException iae)
+ {
+ iae.printStackTrace();
+ }
+ catch (Exception ex)
+ {
+ System.out.println("=======================================================");
+ System.out.println("=== Note: An Exception was thrown which should have ===");
+ System.out.println("=== caused a crash. I caught it. Please report this ===");
+ System.out.println("=== to https://www.libreoffice.org/get-help/bug/ ===");
+ System.out.println("=======================================================");
+ ex.printStackTrace();
+ }
+
+ return null;
+ }
+
+ /**
+ * Returns the property "name" of the Object which is the source of the event.
+ */
+ private static String getEventSourceName(EventObject eventObject)
+ {
+ XControl xControl = UnoRuntime.queryInterface(XControl.class, eventObject.Source);
+ return (String) Helper.getUnoPropertyValue(xControl.getModel(), PropertyNames.PROPERTY_NAME, String.class);
+ }
+
/**
* Implementation of com.sun.star.awt.XActionListener
*/