Commit 7e816df1 authored by Vojtech Moravec's avatar Vojtech Moravec
Browse files

Allow the usage of QCMP compression.

If the dataset support qcmp compression (the information is returned in the dataset request) the dialog is shown to the user.
If user chooses to use the compression, the BigDataViewer is transfering compressed data.
parent 6c5fd887
package bdv.ij;
import bdv.BigDataViewer;
import bdv.ij.util.ProgressWriterIJ;
import com.google.gson.stream.JsonReader;
import ij.IJ;
import ij.ImageJ;
import mpicbg.spim.data.SpimDataException;
import org.apache.commons.lang.StringUtils;
import org.scijava.command.Command;
import org.scijava.plugin.Plugin;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import javax.imageio.ImageIO;
import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
......@@ -17,20 +25,6 @@ import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.imageio.ImageIO;
import javax.swing.*;
import org.apache.commons.lang.StringUtils;
import org.scijava.command.Command;
import org.scijava.plugin.Plugin;
import bdv.BigDataViewer;
import bdv.ij.util.ProgressWriterIJ;
import bdv.viewer.ViewerOptions;
import ij.IJ;
import ij.ImageJ;
import mpicbg.spim.data.SpimDataException;
/**
* @author HongKee Moon <moon@mpi-cbg.de>
*/
......@@ -38,9 +32,41 @@ import mpicbg.spim.data.SpimDataException;
menuPath = "Plugins>BigDataViewer>Browse BigDataServer")
public class BigDataBrowserPlugIn implements Command
{
private final Map< String, ImageIcon > imageMap = new HashMap<>();
private final Map< String, String > datasetUrlMap = new HashMap<>();
private static class BigDataBrowserDataset {
private boolean qcmpSupported;
private ImageIcon imageIcon;
private String url;
public void setQcmpSupported(boolean qcmpSupported) {
this.qcmpSupported = qcmpSupported;
}
public void setImageIcon(ImageIcon imageIcon) {
this.imageIcon = imageIcon;
}
public void setUrl(String url) {
this.url = url;
}
public ImageIcon getImageIcon() {
return imageIcon;
}
public String getUrl() {
return url;
}
public boolean isQcmpSupported() {
return qcmpSupported;
}
}
private final Map<String,BigDataBrowserDataset> datasetMap = new HashMap<>();
// private final Map< String, ImageIcon > imageMap = new HashMap<>();
// private final Map< String, String > datasetUrlMap = new HashMap<>();
public static String serverUrl = "http://";
......@@ -99,6 +125,7 @@ public class BigDataBrowserPlugIn implements Command
reader.beginObject();
String id = null, description = null, thumbnailUrl = null, datasetUrl = null;
boolean qcmpSupported = false;
while ( reader.hasNext() )
{
final String name = reader.nextName();
......@@ -110,6 +137,8 @@ public class BigDataBrowserPlugIn implements Command
thumbnailUrl = reader.nextString();
else if ( name.equals( "datasetUrl" ) )
datasetUrl = reader.nextString();
else if (name.equals("qcmpSupported"))
qcmpSupported = reader.nextBoolean();
else
reader.skipValue();
}
......@@ -117,10 +146,15 @@ public class BigDataBrowserPlugIn implements Command
if ( id != null )
{
nameList.add( id );
if ( thumbnailUrl != null && StringUtils.isNotEmpty( thumbnailUrl ) )
imageMap.put( id, new ImageIcon( new URL( thumbnailUrl ) ) );
if ( datasetUrl != null )
datasetUrlMap.put( id, datasetUrl );
BigDataBrowserDataset dataBrowserDataset = new BigDataBrowserDataset();
dataBrowserDataset.setQcmpSupported(qcmpSupported);
if (StringUtils.isNotEmpty(thumbnailUrl))
dataBrowserDataset.setImageIcon(new ImageIcon(new URL(thumbnailUrl)));
if (datasetUrl != null)
dataBrowserDataset.setUrl(datasetUrl);
datasetMap.put(id, dataBrowserDataset);
}
reader.endObject();
......@@ -135,36 +169,43 @@ public class BigDataBrowserPlugIn implements Command
private void createDatasetListUI( final String remoteUrl, final Object[] values )
{
final JList< ? > list = new JList<>( values );
list.setCellRenderer( new ThumbnailListRenderer() );
list.addMouseListener( new MouseAdapter()
{
@Override
public void mouseClicked(final MouseEvent evt) {
final JList<?> list = (JList<?>) evt.getSource();
if (evt.getClickCount() == 2) {
final int index = list.locationToIndex(evt.getPoint());
final String key = String.valueOf(list.getModel().getElementAt(index));
final int qcmpDialogResult = JOptionPane.showConfirmDialog(null,
String.format("Enable QCMP compression for %s", key),
"QCMP compression",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null);
final boolean enableQcmp = qcmpDialogResult == JOptionPane.YES_OPTION;
System.out.printf("%s, qcmp: %s\n", key, (enableQcmp ? "Enabled" : "Disabled"));
try {
final String filename = datasetUrlMap.get(key);
final String title = new File(filename).getName();
BigDataViewer.open(filename, title, new ProgressWriterIJ(), ViewerOptions.options());
} catch (final SpimDataException e) {
e.printStackTrace();
}
}
}
} );
final JList<?> list = new JList<>(values);
list.setCellRenderer(new ThumbnailListRenderer());
list.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(final MouseEvent evt) {
final JList<?> list = (JList<?>) evt.getSource();
if (evt.getClickCount() == 2) {
final int index = list.locationToIndex(evt.getPoint());
final String key = String.valueOf(list.getModel().getElementAt(index));
final BigDataBrowserDataset dataset = datasetMap.get(key);
boolean enableQcmp = false;
if (dataset.isQcmpSupported()) {
final String msg = String.format("QCMP compression is available for '%s'. Do you want to use it?", key);
final int qcmpDialogResult = JOptionPane.showConfirmDialog(null,
msg,
"QCMP compression",
JOptionPane.YES_NO_OPTION,
JOptionPane.QUESTION_MESSAGE,
null);
enableQcmp = qcmpDialogResult == JOptionPane.YES_OPTION;
}
System.out.printf("%s, qcmp: %s\n", key, (enableQcmp ? "Enabled" : "Disabled"));
try {
final String filename = dataset.getUrl();
final String title = new File(filename).getName();
BigDataViewer.open(filename, title, new ProgressWriterIJ(), enableQcmp);
} catch (final SpimDataException e) {
e.printStackTrace();
}
}
}
});
final JScrollPane scroll = new JScrollPane( list );
scroll.setPreferredSize( new Dimension( 600, 800 ) );
......@@ -191,7 +232,8 @@ public class BigDataBrowserPlugIn implements Command
{
final JLabel label = ( JLabel ) super.getListCellRendererComponent(
list, value, index, isSelected, cellHasFocus );
label.setIcon( imageMap.get( value ) );
label.setIcon( datasetMap.get((String)value).getImageIcon() );
label.setHorizontalTextPosition( JLabel.RIGHT );
label.setFont( font );
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment