/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package pdfdb.gui.panels;
import java.awt.*;
import java.awt.image.BufferedImage;
import java.io.IOException;
import java.util.Hashtable;
import javax.swing.*;
import pdfdb.app.EventController;
import pdfdb.gui.customcomponents.MultilineLabel;
import pdfdb.indexing.plugins.ThumbnailCapableIndexer;
import pdfdb.structure.IndexableFile;
/** The summary panel that hosts the thumbnail panel.
* @author ug22cmg */
public class SummaryPanel extends JPanel
{
private ThumbnailPanel thumbnailPanel = new ThumbnailPanel();
private MultilineLabel label = new MultilineLabel();
/** Initializes the summary panel. */
public SummaryPanel()
{
JScrollPane scrollPane = null;
JPanel panel = new JPanel();
this.label = new MultilineLabel();
this.label.setOpaque(false);
this.label.setFont(new Font("Arial", Font.PLAIN, 14));
this.label.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
this.thumbnailPanel = new ThumbnailPanel();
scrollPane = new JScrollPane(label);
scrollPane.setViewportBorder(BorderFactory.createEmptyBorder());
scrollPane.setOpaque(false);
panel.setLayout(new BorderLayout());
panel.add(scrollPane, BorderLayout.CENTER);
panel.setOpaque(false);
panel.setBorder(BorderFactory.createEmptyBorder(10, 0, 0, 0));
super.setOpaque(false);
super.setLayout(new BorderLayout());
super.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10));
super.add(panel, BorderLayout.CENTER);
super.add(new ButtonPanel(), BorderLayout.SOUTH);
super.add(this.thumbnailPanel, BorderLayout.NORTH);
try
{
this.updateData(null);
}
catch (IOException ex)
{
}
}
/** Updates the panel with the specified file's properties.
* @param file The file to update the panel with.
* @throws java.io.IOException If an error occurs. */
public void updateData(IndexableFile file) throws IOException
{
if (file == null)
{
this.label.setText("No file selected");
this.label.setForeground(Color.LIGHT_GRAY);
this.thumbnailPanel.setThumbnail(null);
}
else
{
Hashtable<String, String> properties = file.getProperties();
String thumbnailString = properties.get("THUMBNAIL");
String summary = properties.get("SUMMARY");
if (thumbnailString != null)
{
BufferedImage image = null;
try
{
image = ThumbnailCapableIndexer.getThumbnail(thumbnailString);
}
catch (IOException ioe)
{
}
thumbnailPanel.setThumbnail(image);
}
this.label.setForeground(Color.BLACK);
this.label.setText(summary == null ? "No summary" : summary);
this.label.repaint();
}
}
/** Bottom panel holding the open button */
private class ButtonPanel extends JPanel
{
/** Initializes the panel */
public ButtonPanel()
{
JButton button = new JButton("Open");
button.setActionCommand(String.valueOf(EventController.OP_PDF_OPEN));
button.addActionListener(EventController.getActionListener());
button.setSize(new Dimension(120, 40));
button.setPreferredSize(new Dimension(120, 40));
super.setLayout(new FlowLayout(FlowLayout.RIGHT));
super.add(button);
super.setOpaque(false);
}
}
}