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

beta version of DockingInfoNode

parent 2537109d
No related branches found
No related tags found
No related merge requests found
<?xml version="1.0" encoding="UTF-8"?>
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>
<parent>
<artifactId>super-pom-java</artifactId>
<groupId>fr.soleil</groupId>
<version>RELEASE</version>
</parent>
<groupId>fr.soleil.lib</groupId>
<artifactId>DockingInfoNode</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Docking InfoNode</name>
<description>InfoNode implementation of DockingCore</description>
<developers>
<developer>
<id>girardot</id>
<name>Raphaël GIRARDOT</name>
<email>raphael.girardot@synchrotron-soleil.fr</email>
<organization>SOLEIL</organization>
<organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl>
<roles>
<role>Manager</role>
</roles>
<timezone>1</timezone>
</developer>
<developer>
<id>viguier</id>
<name>Grégory VIGUIER</name>
<email>gregory.viguier@synchrotron-soleil.fr</email>
<organization>SOLEIL</organization>
<organizationUrl>http://www.synchrotron-soleil.fr</organizationUrl>
<roles>
<role>Java Developer</role>
</roles>
<timezone>1</timezone>
</developer>
</developers>
<scm>
<connection>scm:svn:https://svn.code.sf.net/p/comete/code/trunk/DockingInfoNode</connection>
<developerConnection>scm:svn:https://svn.code.sf.net/p/comete/code/trunk/DockingInfoNode</developerConnection>
<url>https://svn.code.sf.net/p/comete/code/trunk/DockingInfoNode</url>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>UTF-8</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>fr.soleil.lib</groupId>
<artifactId>DockingCore</artifactId>
<version>0.0.1-SNAPSHOT</version>
</dependency>
<dependency>
<groupId>net.infonode</groupId>
<artifactId>idw-gpl</artifactId>
</dependency>
</dependencies>
</project>
package fr.soleil.docking.infonode;
import java.beans.PropertyChangeEvent;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import javax.swing.JComponent;
import javax.swing.JOptionPane;
import net.infonode.docking.RootWindow;
import net.infonode.docking.View;
import net.infonode.docking.ViewSerializer;
import net.infonode.docking.properties.DockingWindowProperties;
import net.infonode.docking.util.DockingUtil;
import net.infonode.util.Direction;
import fr.soleil.docking.ADockingManager;
import fr.soleil.docking.exception.DockingException;
import fr.soleil.docking.perspective.IPerspective;
import fr.soleil.docking.perspective.IPerspectiveFactory;
import fr.soleil.docking.view.IView;
import fr.soleil.docking.view.IViewFactory;
/**
* A class that prepares docking. Obtain your RootWindow from this class.
*
* @author HARDION
* @author GIRARDOT
*/
public class InfoNodeDockingManager extends ADockingManager {
protected RootWindow rootWindow;
public InfoNodeDockingManager(IViewFactory viewFactory, IPerspectiveFactory perspectiveFactory) {
super(viewFactory, perspectiveFactory);
}
@Override
public JComponent getDockingArea() {
if (rootWindow == null) {
rootWindow = (RootWindow) createNewDockingArea();
}
return rootWindow;
}
@Override
public JComponent createNewDockingArea() {
RootWindow result = new RootWindow(new MyViewSerializer(viewFactory));
for (IView view : viewFactory.getViews()) {
DockingUtil.addWindow((View) view, rootWindow);
}
result.getWindowBar(Direction.DOWN).setEnabled(true);
result.getRootWindowProperties().getDockingWindowProperties().setUndockEnabled(false);
return result;
}
@Override
public void loadPerspective(IPerspective perspective) throws DockingException {
DockingException dockingException = null;
if (perspective.getByteArray().length > 0) {
ObjectInputStream ois = null;
ByteArrayInputStream bais = null;
try {
bais = new ByteArrayInputStream(perspective.getByteArray());
ois = new ObjectInputStream(bais);
rootWindow.read(ois);
} catch (Exception e) {
dockingException = new DockingException("Perspective.load() :" + " Unexpected Error", e);
} finally {
try {
if (ois != null) {
ois.close();
}
// Actually there is no effect to close bais ...
} catch (IOException e) {
if (dockingException == null) {
dockingException = new DockingException("I/O Exception", e);
} else {
e.printStackTrace();
}
}
}
}
if (dockingException != null) {
throw dockingException;
}
}
@Override
protected void savePerspective(IPerspective perspective) {
ByteArrayOutputStream baos = null;
ObjectOutputStream ous = null;
baos = new ByteArrayOutputStream();
try {
ous = new ObjectOutputStream(baos);
rootWindow.write(ous, false);
} catch (IOException e) {
e.printStackTrace();
JOptionPane.showMessageDialog(rootWindow, "Perspective.save() :" + " Unexpected Error (see traces)",
"INFONODE Docking - Error", JOptionPane.ERROR_MESSAGE);
} finally {
try {
ous.close();
// Actually there is no effect to close baos ...
} catch (IOException e) {
e.printStackTrace();
}
}
perspective.setByteArray(baos.toByteArray());
}
@Override
protected void updateViews(PropertyChangeEvent evt) {
if (evt.getSource() == this.viewFactory) {
View newView = (View) evt.getNewValue();
View oldView = (View) evt.getOldValue();
if (newView == null) { // removed
oldView.close();
} else {
DockingUtil.addWindow(newView, rootWindow);
}
}
}
@Override
public void setEnabledDocking(boolean enabledDocking) {
RootWindow rootWindow = (RootWindow) getDockingArea();
rootWindow.getRootWindowProperties().getDockingWindowProperties().setCloseEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setDragEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setMaximizeEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setMinimizeEnabled(enabledDocking);
}
@Override
public boolean isEnabledDocking() {
DockingWindowProperties dwp = this.rootWindow.getRootWindowProperties().getDockingWindowProperties();
return dwp.getCloseEnabled() && dwp.getDragEnabled() && dwp.getMaximizeEnabled() && dwp.getMinimizeEnabled();
}
// ///////////// //
// Inner classes //
// ///////////// //
protected class MyViewSerializer implements ViewSerializer {
private final IViewFactory viewFactory;
/**
* Utility constructor that creates a map with a number of views. A view gets it's index in
* the array as id.
*
* @param views the views to add to the map
*/
public MyViewSerializer(IViewFactory viewFactory) {
this.viewFactory = viewFactory;
}
@Override
public View readView(ObjectInputStream in) throws IOException {
Object id = viewFactory.readViewId(in);
return (View) viewFactory.getView(id);
}
@Override
public void writeView(View view, ObjectOutputStream out) throws IOException {
viewFactory.writeViewId(((IView) view).getId(), out);
}
}
}
package fr.soleil.docking.infonode;
import java.awt.Color;
import java.awt.Component;
import java.util.List;
import javax.swing.Icon;
import net.infonode.docking.DockingWindow;
import net.infonode.docking.DockingWindowListener;
import net.infonode.docking.OperationAbortedException;
import net.infonode.docking.View;
import fr.soleil.docking.view.IView;
import fr.soleil.docking.view.IViewListener;
/**
* A dynamically created view containing an id.
*
* @author Hardion
* @author GIRARDOT
*/
public class InfoNodeView extends View implements IView {
private static final long serialVersionUID = -8766019787338480450L;
protected Object id;
/**
* Constructor.
*
* @param title the view title
* @param icon the view icon
* @param component the view component
* @param id the view id
*/
public InfoNodeView(String title, Icon icon, Component component, Object id) {
super(title, icon, component);
this.id = id;
}
@Override
public Object getId() {
return id;
}
@Override
public boolean isVisible() {
boolean visible;
if (super.isShowing()) {
visible = true;
} else if (super.getWindowParent() != null && super.getWindowParent().isRestorable()) {
visible = true;
} else {
visible = false;
}
return visible;
}
@Override
public void setVisible(boolean visible) {
if (visible) {
super.restore();
} else {
super.close();
}
super.setVisible(visible);
super.setEnabled(visible);
}
@Override
protected void update() {
super.update();
super.setVisible(true);
super.setEnabled(true);
}
@Override
public Color getViewBackground() {
return getBackground();
}
@Override
public void setViewBackground(Color bg) {
setComponentsBackground(getCustomTabComponents(), bg);
setComponentsBackground(getCustomTitleBarComponents(), bg);
setBackground(this, bg);
}
@Override
public Color getViewForeground() {
return getForeground();
}
@Override
public void setViewForeground(Color fg) {
setComponentsForeground(getCustomTabComponents(), fg);
setComponentsForeground(getCustomTitleBarComponents(), fg);
setForeground(this, fg);
}
/**
* Sets the background {@link Color} of a {@link DockingWindow}
*
* @param win The {@link DockingWindow}
* @param bg The background {@link Color} to set
*/
protected void setBackground(DockingWindow win, Color bg) {
win.setBackground(bg);
win.setBorder(null);
win.getWindowProperties().getTabProperties().getTitledTabProperties().getNormalProperties()
.getComponentProperties().setBackgroundColor(bg);
win.getWindowProperties().getTabProperties().getTitledTabProperties().getHighlightedProperties()
.getComponentProperties().setBackgroundColor(bg);
}
/**
* Sets the foreground {@link Color} of a {@link DockingWindow}
*
* @param win The {@link DockingWindow}
* @param fg The foreground {@link Color} to set
*/
protected void setForeground(DockingWindow win, Color fg) {
win.setForeground(fg);
win.getWindowProperties().getTabProperties().getTitledTabProperties().getNormalProperties()
.getComponentProperties().setForegroundColor(fg);
win.getWindowProperties().getTabProperties().getTitledTabProperties().getHighlightedProperties()
.getComponentProperties().setForegroundColor(fg);
}
/**
* Sets the background of all {@link Component}s in a given {@link List}
*
* @param components The {@link List}
* @param bg The background to set
*/
protected void setComponentsBackground(List<?> components, Color bg) {
if (components != null) {
for (Object comp : components) {
if (comp instanceof Component) {
((Component) comp).setBackground(bg);
}
}
}
}
/**
* Sets the foreground of all {@link Component}s in a given {@link List}
*
* @param components The {@link List}
* @param bg The foreground to set
*/
protected void setComponentsForeground(List<?> components, Color bg) {
if (components != null) {
for (Object comp : components) {
if (comp instanceof Component) {
((Component) comp).setForeground(bg);
}
}
}
}
@Override
public void setClosable(boolean closable) {
if (getWindowProperties() != null) {
getWindowProperties().getTabProperties().getNormalButtonProperties().getCloseButtonProperties()
.setVisible(closable);
getWindowProperties().getTabProperties().getHighlightedButtonProperties().getCloseButtonProperties()
.setVisible(closable);
getWindowProperties().setCloseEnabled(closable);
}
}
@Override
public void addViewListener(final IViewListener listener) {
addListener(new DockingWindowListener() {
@Override
public void windowUndocking(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowUndocked(DockingWindow window) {
// Not used yet.
}
@Override
public void windowShown(DockingWindow window) {
// Not used yet.
}
@Override
public void windowRestoring(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowRestored(DockingWindow window) {
// Not used yet.
}
@Override
public void windowRemoved(DockingWindow removedFromWindow, DockingWindow removedWindow) {
// Not used yet.
}
@Override
public void windowMinimizing(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowMinimized(DockingWindow window) {
// Not used yet.
}
@Override
public void windowMaximizing(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowMaximized(DockingWindow window) {
// Not used yet.
}
@Override
public void windowHidden(DockingWindow window) {
// Not used yet.
}
@Override
public void windowDocking(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowDocked(DockingWindow window) {
// Not used yet.
}
@Override
public void windowClosing(DockingWindow window) throws OperationAbortedException {
// Not used yet.
}
@Override
public void windowClosed(DockingWindow window) {
listener.viewClosed();
}
@Override
public void windowAdded(DockingWindow addedToWindow, DockingWindow addedWindow) {
// Not used yet.
}
@Override
public void viewFocusChanged(View previouslyFocusedView, View focusedView) {
// Not used yet.
}
});
}
}
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