Skip to content
Snippets Groups Projects
Commit a38c49ac authored by GIRARDOT Raphael's avatar GIRARDOT Raphael Committed by MADELA Patrick
Browse files

- better listeners management. Big change --> version set to 1.1.0-SNAPSHOT

- added the possibility to change IView's icon and title (JAVAAPI-262)
parent 21483447
No related branches found
No related tags found
No related merge requests found
......@@ -9,7 +9,7 @@
</parent>
<groupId>fr.soleil.lib</groupId>
<artifactId>DockingCore</artifactId>
<version>1.0.6-SNAPSHOT</version>
<version>1.1.0-SNAPSHOT</version>
<name>Docking Core</name>
<description>A project that defines some common abstractions in docking</description>
<developers>
......
package fr.soleil.docking.event;
import java.util.EventObject;
import fr.soleil.docking.view.IView;
/**
* An {@link EventObject} that describes the changes in an {@link IView}
*
* @author GIRARDOT
*/
public class DockingEvent extends EventObject {
private static final long serialVersionUID = -9107231208702875097L;
/**
* An <code>int</code> used to notify that the associated view was closed
*/
public static final int VIEW_CLOSED = 0;
/**
* An <code>int</code> used to notify that the associated view gained the focus
*/
public static final int FOCUS_GAINED = 1;
/**
* An <code>int</code> used to notify that the associated view lost the focus
*/
public static final int FOCUS_LOST = 2;
protected final int reason;
public DockingEvent(IView source, int reason) {
super(source);
this.reason = reason;
}
@Override
public IView getSource() {
return (IView) super.getSource();
}
/**
* Returns the reason of the changes
*
* @return An <code>int</code>
* @see #VIEW_CLOSED
* @see #FOCUS_GAINED
* @see #FOCUS_LOST
*/
public int getReason() {
return reason;
}
}
package fr.soleil.docking.listener;
import java.util.EventListener;
import fr.soleil.docking.event.DockingEvent;
import fr.soleil.docking.view.IView;
/**
* An {@link EventListener} that listens to the changes in an {@link IView}
*
* @author GIRARDOT
*/
public interface IViewListener extends EventListener {
/**
* Notifies this {@link IViewListener} for some changes in an {@link IView}
*
* @param event The {@link DockingEvent} that describes the concerned {@link IView} and changes
*/
public void dockingChanged(DockingEvent event);
}
package fr.soleil.docking.listener;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.WeakHashMap;
import fr.soleil.docking.event.DockingEvent;
/**
* A class delegated to {@link IViewListener}s management
*
* @author GIRARDOT
*/
public class ViewListenerDelegate {
protected final Collection<IViewListener> listeners;
public ViewListenerDelegate() {
listeners = Collections.newSetFromMap(new WeakHashMap<IViewListener, Boolean>());
}
/**
* Warns all {@link IViewListener}s for some changes
*
* @param event The {@link DockingEvent} that describes the changes
*/
public void warnListeners(DockingEvent event) {
List<IViewListener> copy;
synchronized (listeners) {
copy = new ArrayList<IViewListener>(listeners.size());
copy.addAll(listeners);
}
for (IViewListener listener : copy) {
if (listener != null) {
listener.dockingChanged(event);
}
}
copy.clear();
}
/**
* Adds a new {@link IViewListener}
*
* @param listener the {@link IViewListener} to add
*/
public void addViewListener(final IViewListener listener) {
if (listener != null) {
synchronized (listeners) {
listeners.add(listener);
}
}
}
/**
* Removes an {@link IViewListener}
*
* @param listener The {@link IViewListener} to remove
*/
public void removeViewListener(IViewListener listener) {
if (listener != null) {
synchronized (listeners) {
listeners.remove(listener);
}
}
}
}
......@@ -12,6 +12,8 @@ import java.awt.Component;
import javax.swing.Icon;
import fr.soleil.docking.listener.IViewListener;
/**
* A dynamically created view containing an id.
*
......@@ -57,11 +59,25 @@ public interface IView {
*/
public String getTitle();
/**
* Sets this {@link IView}'s title
*
* @param title The title to set
*/
public void setTitle(String title);
/**
* @return the icon
*/
public Icon getIcon();
/**
* Sets this {@link IView}'s icon
*
* @param icon The icon to set
*/
public void setIcon(Icon icon);
/**
* @return the component
*/
......@@ -109,4 +125,11 @@ public interface IView {
*/
public void addViewListener(IViewListener listener);
/**
* Removes an {@link IViewListener} from the view..
*
* @param listener The {@link IViewListener} to remove.
*/
public void removeViewListener(IViewListener listener);
}
/*******************************************************************************
* Copyright (c) 2008-2014 Synchrotron SOLEIL
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the GNU Lesser Public License v2.1
* which accompanies this distribution, and is available at
* http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html
******************************************************************************/
package fr.soleil.docking.view;
public interface IViewListener {
public void viewClosed();
public void focusGained();
public void focusLost();
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment