Skip to content
Snippets Groups Projects
Commit 0c0acaeb authored by Patrick MADELA's avatar Patrick MADELA
Browse files

Merge dockinginfonode into docking

parents a29cd448 9dc538e8
Branches
Tags
No related merge requests found
.project
.classpath
.settings
target
This diff is collapsed.
<?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>
<groupId>fr.soleil.maven.parent</groupId>
<artifactId>java-updated-versions</artifactId>
<version>0-SNAPSHOT</version>
</parent>
<groupId>fr.soleil.lib</groupId>
<artifactId>DockingInfoNode</artifactId>
<version>1.1.2</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:git:git@gitlab.synchrotron-soleil.fr:software-control-system/libraries/java/dockinginfonode.git</connection>
<developerConnection>scm:git:git@gitlab.synchrotron-soleil.fr:software-control-system/libraries/java/dockinginfonode.git</developerConnection>
<url>https://gitlab.synchrotron-soleil.fr/software-control-system/libraries/java/dockinginfonode</url>
</scm>
<build>
<plugins>
<plugin>
<artifactId>maven-resources-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<encoding>${project.build.sourceEncoding}</encoding>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>fr.soleil.lib</groupId>
<artifactId>DockingCore</artifactId>
</dependency>
<dependency>
<groupId>net.infonode</groupId>
<artifactId>idw-gpl</artifactId>
</dependency>
</dependencies>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
</project>
/*******************************************************************************
* Copyright (c) 2008-2019 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.infonode;
import java.awt.Color;
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 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.infonode.view.InfoNodeViewFactory;
import fr.soleil.docking.perspective.IPerspective;
import fr.soleil.docking.perspective.IPerspectiveFactory;
import fr.soleil.docking.perspective.PerspectiveFactory;
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() {
this(new InfoNodeViewFactory(), new PerspectiveFactory());
}
public InfoNodeDockingManager(IViewFactory viewFactory) {
this(viewFactory, new PerspectiveFactory());
}
public InfoNodeDockingManager(IViewFactory viewFactory, IPerspectiveFactory perspectiveFactory) {
super(viewFactory, perspectiveFactory);
}
@Override
protected void initDockingArea() {
rootWindow = (RootWindow) createNewDockingArea(null);
}
@Override
public JComponent getDockingArea() {
if (rootWindow == null) {
initDockingArea();
}
return rootWindow;
}
@Override
public JComponent createNewDockingArea(Color background) {
RootWindow result = generateRootWindow();
if (background != null) {
result.getRootWindowProperties().getWindowAreaProperties().setBackgroundColor(background);
}
updateRootWindowAfterViewAdding(result);
return result;
}
protected RootWindow generateRootWindow() {
return new RootWindow(new MyViewSerializer(viewFactory));
}
protected void updateRootWindowAfterViewAdding(RootWindow window) {
window.getWindowBar(Direction.DOWN).setEnabled(true);
window.getRootWindowProperties().getDockingWindowProperties().setUndockEnabled(false);
}
@Override
public void setDockingAreaBeackground(JComponent dockingArea, Color areaBackground) {
if (dockingArea instanceof RootWindow) {
RootWindow rootWindow = (RootWindow) dockingArea;
rootWindow.getRootWindowProperties().getWindowAreaProperties().setBackgroundColor(areaBackground);
}
}
@Override
public void applyPerspective(IPerspective perspective, JComponent dockingArea) throws DockingException {
DockingException dockingException = null;
if ((perspective != null) && (perspective.getByteArray() != null) && (perspective.getByteArray().length > 0)
&& (dockingArea instanceof RootWindow)) {
RootWindow rootWindow = (RootWindow) dockingArea;
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(getClass().getSimpleName()
+ ".applyPerspective(): 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
public void updatePerspective(IPerspective perspective, JComponent dockingArea) throws DockingException {
DockingException dockingException = null;
if ((perspective != null) && (dockingArea instanceof RootWindow)) {
RootWindow rootWindow = (RootWindow) dockingArea;
ByteArrayOutputStream baos = null;
ObjectOutputStream ous = null;
baos = new ByteArrayOutputStream();
try {
ous = new ObjectOutputStream(baos);
rootWindow.write(ous, false);
} catch (IOException e) {
dockingException = new DockingException(getClass().getSimpleName()
+ ".updatePerspective(): Unexpected Error", e);
} finally {
try {
ous.close();
// Actually there is no effect to close baos ...
} catch (IOException e) {
if (dockingException == null) {
dockingException = new DockingException("I/O Exception", e);
} else {
e.printStackTrace();
}
}
}
perspective.setByteArray(baos.toByteArray());
}
if (dockingException != null) {
throw dockingException;
}
}
@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, JComponent dockingArea) {
if (dockingArea instanceof RootWindow) {
RootWindow rootWindow = (RootWindow) dockingArea;
rootWindow.getRootWindowProperties().getDockingWindowProperties().setCloseEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setDragEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setMaximizeEnabled(enabledDocking);
rootWindow.getRootWindowProperties().getDockingWindowProperties().setMinimizeEnabled(enabledDocking);
}
}
@Override
public boolean isEnabledDocking(JComponent dockingArea) {
boolean enabled;
if (dockingArea instanceof RootWindow) {
RootWindow rootWindow = (RootWindow) dockingArea;
DockingWindowProperties dwp = rootWindow.getRootWindowProperties().getDockingWindowProperties();
enabled = dwp.getCloseEnabled() && dwp.getDragEnabled() && dwp.getMaximizeEnabled()
&& dwp.getMinimizeEnabled();
} else {
enabled = false;
}
return enabled;
}
@Override
public void setUndockEnabled(boolean enabled, JComponent dockingArea) {
if (dockingArea instanceof RootWindow) {
RootWindow rootWindow = (RootWindow) dockingArea;
rootWindow.getRootWindowProperties().getDockingWindowProperties().setUndockEnabled(enabled);
}
}
@Override
public boolean isUndockEnabled(JComponent dockingArea) {
boolean enabled;
if (dockingArea instanceof RootWindow) {
RootWindow rootWindow = (RootWindow) dockingArea;
enabled = rootWindow.getRootWindowProperties().getDockingWindowProperties().getUndockEnabled();
} else {
enabled = false;
}
return enabled;
}
@Override
public boolean canRestoreExactViewPosition() {
return true;
}
// ///////////// //
// 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);
}
}
}
/*******************************************************************************
* Copyright (c) 2008-2019 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.infonode.view;
import java.awt.Color;
import java.awt.Component;
import java.util.List;
import javax.swing.Icon;
import net.infonode.docking.AbstractTabWindow;
import net.infonode.docking.DockingWindow;
import net.infonode.docking.DockingWindowAdapter;
import net.infonode.docking.RootWindow;
import net.infonode.docking.View;
import fr.soleil.docking.event.ViewEvent;
import fr.soleil.docking.listener.IViewListener;
import fr.soleil.docking.listener.ViewListenerDelegate;
import fr.soleil.docking.view.IView;
/**
* A dynamically created view containing an id.
*
* @author Hardion
* @author GIRARDOT
*/
public class InfoNodeView extends View implements IView {
private static final long serialVersionUID = 6381456606851418094L;
protected Object id;
protected final ViewListenerDelegate delegate;
/**
* 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;
delegate = new ViewListenerDelegate();
addListener(new DockingWindowAdapter() {
@Override
public void windowClosed(DockingWindow window) {
delegate.warnListeners(new ViewEvent(InfoNodeView.this, ViewEvent.VIEW_CLOSED));
}
@Override
public void viewFocusChanged(View previouslyFocusedView, View focusedView) {
if (InfoNodeView.this.equals(focusedView)) {
delegate.warnListeners(new ViewEvent(InfoNodeView.this, ViewEvent.FOCUS_GAINED));
} else {
delegate.warnListeners(new ViewEvent(InfoNodeView.this, ViewEvent.FOCUS_LOST));
}
}
});
}
@Override
public Object getId() {
return id;
}
@Override
public boolean isVisible() {
boolean visible;
if (isShowing()) {
visible = true;
} else if ((getWindowParent() != null) && 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
public void select() {
recursiveSelect(this);
// requestFocusInWindow();
// Component comp = getComponent();
// if (comp != null) {
// comp.requestFocusInWindow();
// }
}
protected static void recursiveSelect(DockingWindow window) {
if (window != null) {
DockingWindow parent = window.getWindowParent();
if (parent instanceof AbstractTabWindow) {
AbstractTabWindow tabWindow = (AbstractTabWindow) parent;
int index = parent.getChildWindowIndex(window);
if (index > -1) {
tabWindow.setSelectedTab(index);
}
}
recursiveSelect(parent);
}
}
@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) {
setClosable(this, closable, true);
}
/**
* Methods that allow or not a {@link DockingWindow} to be closable. If the {@link DockingWindow} is set as not
* closable, all its ancestors will be set as unclosable too.
*
* @param window The {@link DockingWindow} to set closable/unclosable
* @param closable Whether the {@link DockingWindow} should be closable
* @param updateRootWindowToo Whether to update root window properties too. Will have effect only if
* <code>closable</code> is <code>false</code>.
*/
protected static void setClosable(DockingWindow window, boolean closable, boolean updateRootWindowToo) {
if ((window != null) && (window.getWindowProperties() != null)) {
window.getWindowProperties().getTabProperties().getNormalButtonProperties().getCloseButtonProperties()
.setVisible(closable);
window.getWindowProperties().getTabProperties().getHighlightedButtonProperties().getCloseButtonProperties()
.setVisible(closable);
window.getWindowProperties().setCloseEnabled(closable);
if (!closable) {
if (updateRootWindowToo) {
RootWindow rootWindow = window.getRootWindow();
if ((rootWindow != null) && (rootWindow.getRootWindowProperties() != null)) {
rootWindow.getRootWindowProperties().getDockingWindowProperties().setCloseEnabled(closable);
}
}
setClosable(window.getWindowParent(), closable, false);
}
}
}
@Override
public void addViewListener(final IViewListener listener) {
delegate.addViewListener(listener);
}
@Override
public void removeViewListener(IViewListener listener) {
delegate.removeViewListener(listener);
}
@Override
public void setTitle(String title) {
getViewProperties().setTitle(title == null ? "" : title);
RootWindow rootWindow = getRootWindow();
if (rootWindow != null) {
rootWindow.repaint();
}
}
@Override
public void setIcon(Icon icon) {
getViewProperties().setIcon(icon);
RootWindow rootWindow = getRootWindow();
if (rootWindow != null) {
rootWindow.repaint();
}
}
}
/*******************************************************************************
* Copyright (c) 2008-2019 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.infonode.view;
import java.awt.Component;
import javax.swing.Icon;
import javax.swing.JComponent;
import net.infonode.docking.RootWindow;
import net.infonode.docking.util.DockingUtil;
import fr.soleil.docking.ADockingManager;
import fr.soleil.docking.infonode.InfoNodeDockingManager;
import fr.soleil.docking.view.AbstractViewFactory;
import fr.soleil.docking.view.IView;
/**
* InfoNode implementation of {@link AbstractViewFactory}
*
* @author girardot
*/
public class InfoNodeViewFactory extends AbstractViewFactory {
public InfoNodeViewFactory() {
super();
}
@Override
protected IView createView(String title, Icon icon, Component component, Object id) {
return new InfoNodeView(title, icon, component, id);
}
@Override
protected void updateViewForDockingArea(IView view, JComponent dockingArea) {
if ((view instanceof InfoNodeView) && (dockingArea instanceof RootWindow)) {
InfoNodeView infoNodeView = (InfoNodeView) view;
RootWindow rootWindow = (RootWindow) dockingArea;
infoNodeView.getWindowProperties().getTabProperties().getNormalButtonProperties()
.getCloseButtonProperties().setVisible(false);
infoNodeView.getWindowProperties().getTabProperties().getHighlightedButtonProperties()
.getCloseButtonProperties().setVisible(false);
DockingUtil.addWindow(infoNodeView, rootWindow);
}
}
@Override
public ADockingManager generateDockingManager() {
return new InfoNodeDockingManager(this);
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment