<commit_before>package fi.csc.microarray.client.visualisation.methods;

import java.io.InputStream;

import javax.swing.JComponent;
import javax.swing.JPanel;

import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;
import org.icepdf.ri.common.views.DocumentViewControllerImpl;

import fi.csc.microarray.client.visualisation.Visualisation;
import fi.csc.microarray.client.visualisation.VisualisationFrame;
import fi.csc.microarray.databeans.DataBean;
import fi.csc.microarray.databeans.DataBean.DataNotAvailableHandling;
import fi.csc.microarray.databeans.DataManager.StorageMethod;
import fi.csc.microarray.exception.MicroarrayException;

public class PDFViewer extends Visualisation {

	public void initialise(VisualisationFrame frame) throws Exception {
		super.initialise(frame);
	}

	@Override
	public boolean canVisualise(DataBean bean) throws MicroarrayException {
		return bean.isContentTypeCompatitible("application/pdf");
		
	}

	@Override
	public JComponent getVisualisation(DataBean data) throws Exception {

		// build a controller
		SwingController controller = new SwingController();

		// Build a SwingViewFactory configured with the controller
		SwingViewBuilder factory = new SwingViewBuilder(controller);

		// Use the factory to build a JPanel that is pre-configured
		//with a complete, active Viewer UI.
		JPanel viewerComponentPanel = factory.buildViewerPanel();

		// Open a PDF document to view
		InputStream in = data.getContentStream(DataNotAvailableHandling.NULL_ON_NA);
		if (in != null) {
			controller.openDocument(in, data.getName(), data.getContentLocation(StorageMethod.LOCAL_FILE_METHODS).getUrl().toString());

			// Set view mode
			controller.setPageViewMode(DocumentViewControllerImpl.ONE_COLUMN_VIEW, true);
		}
		
		return viewerComponentPanel;
	}
}<commit_msg>Create a local copy for the pdf viewer.<commit_after>package fi.csc.microarray.client.visualisation.methods;

import java.io.File;

import javax.swing.JComponent;
import javax.swing.JPanel;

import org.icepdf.ri.common.SwingController;
import org.icepdf.ri.common.SwingViewBuilder;

import fi.csc.microarray.client.visualisation.Visualisation;
import fi.csc.microarray.client.visualisation.VisualisationFrame;
import fi.csc.microarray.databeans.DataBean;
import fi.csc.microarray.exception.MicroarrayException;

public class PDFViewer extends Visualisation {

	public void initialise(VisualisationFrame frame) throws Exception {
		super.initialise(frame);
	}

	@Override
	public boolean canVisualise(DataBean bean) throws MicroarrayException {
		return bean.isContentTypeCompatitible("application/pdf");
		
	}

	@Override
	public JComponent getVisualisation(DataBean data) throws Exception {

		// build a controller
		SwingController controller = new SwingController();

		// Build a SwingViewFactory configured with the controller
		SwingViewBuilder factory = new SwingViewBuilder(controller);

		// Use the factory to build a JPanel that is pre-configured
		//with a complete, active Viewer UI.
		JPanel viewerComponentPanel = factory.buildViewerPanel();
		
//the pdf reader can't read file over http but says the file is corrupted
//		
//		// Open a PDF document to view
//		InputStream in = data.getContentStream(DataNotAvailableHandling.NULL_ON_NA);
//		if (in != null) {
//			
//			controller.openDocument(in, data.getName(), data.getContentLocation(StorageMethod.LOCAL_FILE_METHODS).getUrl().toString());
//			
//			// Set view mode
//			controller.setPageViewMode(DocumentViewControllerImpl.ONE_COLUMN_VIEW, true);
//		}
		
		//use local file for now
		File file = application.getDataManager().getLocalFile(data);
		controller.openDocument(file.getPath());
		
		return viewerComponentPanel;
	}
}
{'fraction_non_alphanumeric': 0.09222133119486768, 'fraction_numerical': 0.0, 'mean_word_length': 5.104404567699837, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3142952', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1072, 'n_words': 250}