Skip to content
Snippets Groups Projects
Commit 410bfb99 authored by aburn's avatar aburn
Browse files

Added image editor for ROIs in AT

parent d3001bd5
Branches
No related merge requests found
......@@ -12,58 +12,65 @@ In this respect, the user's attention is drawn to the risks associated with load
The fact that you are presently reading this means that you have had knowledge of the CeCILL license and that you accept its terms.
*/
package org.interreg.docexplore.authoring.rois;
import java.awt.Color;
import java.awt.Dimension;
package org.interreg.docexplore.authoring.rois;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.image.BufferedImage;
import javax.swing.JLabel;
import org.interreg.docexplore.manuscript.MetaData;
@SuppressWarnings("serial")
public class ImageElement extends InfoElement
{
BufferedImage image;
public ImageElement(RegionSidePanel editor, int width, MetaData md) throws Exception
{
super(editor, md);
image = md.getImage();
JLabel canvas = new JLabel()
{
public void paintComponent(Graphics g)
{
g.drawImage(image, 0, 0, getWidth(), getHeight(), 0, 0, image.getWidth(), image.getHeight(), null);
}
};
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.awt.image.BufferedImage;
import javax.swing.JLabel;
import org.interreg.docexplore.manuscript.MetaData;
@SuppressWarnings("serial")
public class ImageElement extends InfoElement
{
BufferedImage image;
public ImageElement(RegionSidePanel editor, int width, MetaData md) throws Exception
{
super(editor, md);
image = md.getImage();
JLabel canvas = new JLabel()
{
public void paintComponent(Graphics g)
{
g.drawImage(image, 0, 0, getWidth(), getHeight(), 0, 0, image.getWidth(), image.getHeight(), null);
}
};
canvas.setPreferredSize(new Dimension(width, (image.getHeight()*width)/image.getWidth()));
add(canvas);
}
public int getReaderWidth(int maxWidth)
{
if (image.getWidth() > maxWidth)
return maxWidth;
int minDim = maxWidth/3;
if (image.getWidth() < minDim && image.getHeight() < minDim)
return minDim*image.getWidth()/Math.max(image.getWidth(), image.getHeight());
return image.getWidth();
}
public int getReaderHeight(int width)
{
return image.getHeight()*width/image.getWidth();
}
public BufferedImage getPreview(int width, Color back)
{
int iw = getReaderWidth(width);
int ih = getReaderHeight(iw);
BufferedImage res = new BufferedImage(iw, ih, BufferedImage.TYPE_3BYTE_BGR);
res.createGraphics().drawImage(image, 0, 0, iw, ih, 0, 0, image.getWidth(), image.getHeight(), null);
return res;
}
}
canvas.addMouseListener(new MouseAdapter() {@Override public void mouseClicked(MouseEvent e)
{
if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2)
editor.host.addDocument(md, editor.document);
}});
add(canvas);
}
public int getReaderWidth(int maxWidth)
{
if (image.getWidth() > maxWidth)
return maxWidth;
int minDim = maxWidth/3;
if (image.getWidth() < minDim && image.getHeight() < minDim)
return minDim*image.getWidth()/Math.max(image.getWidth(), image.getHeight());
return image.getWidth();
}
public int getReaderHeight(int width)
{
return image.getHeight()*width/image.getWidth();
}
public BufferedImage getPreview(int width, Color back)
{
int iw = getReaderWidth(width);
int ih = getReaderHeight(iw);
BufferedImage res = new BufferedImage(iw, ih, BufferedImage.TYPE_3BYTE_BGR);
res.createGraphics().drawImage(image, 0, 0, iw, ih, 0, 0, image.getWidth(), image.getHeight(), null);
return res;
}
}
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