File: ImagePreviewPanel.java

package info (click to toggle)
gpsprune 17-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 3,984 kB
  • ctags: 5,218
  • sloc: java: 39,403; sh: 25; makefile: 17; python: 15
file content (98 lines) | stat: -rw-r--r-- 2,429 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package tim.prune.save;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;

import javax.swing.JPanel;

import tim.prune.I18nManager;

/**
 * GUI component to display an image preview for the POV export
 * and for the image export
 */
public class ImagePreviewPanel extends JPanel
{
	/** Base image */
	private GroutedImage _baseImage = null;
	/** Loading flag */
	private boolean _loading = false;

	/** String to show before image is loaded */
	private static final String LOADING_STRING = I18nManager.getText("details.photo.loading") + " ...";
	/** Colour to use if there aren't any tiles at all (same as colour of POV export without image) */
	private static final Color EMPTY_IMAGE_COLOUR = new Color(0.5f, 0.75f, 0.8f);


	/** Set the base image */
	public void setImage(GroutedImage inImage)
	{
		_baseImage = inImage;
		_loading = false;
		repaint();
	}

	/** Inform that a load is starting */
	public void startLoading()
	{
		_baseImage = null;
		_loading = true;
		repaint();
	}

	/** Get minimum size */
	public Dimension getMinimumSize() {
		return new Dimension(200, 200);
	}
	/** Preferred size */
	public Dimension getPreferredSize() {
		return getMinimumSize();
	}

	/**
	 * Override paint method
	 * @see javax.swing.JComponent#paint(java.awt.Graphics)
	 */
	public void paint(Graphics inG)
	{
		super.paint(inG);
		if (_loading)
		{
			inG.setColor(Color.BLACK);
			inG.drawString(LOADING_STRING, 10, 30);
		}
		else if (_baseImage != null)
		{
			final int width = getWidth();
			final int height = getHeight();
			final int previewSize = Math.min(width, height);
			if (previewSize > 1)
			{
				if (_baseImage.isValid())
				{
					inG.drawImage(_baseImage.getImage(),
						(width-previewSize)/2, (height-previewSize)/2, previewSize, previewSize, this);
				}
				else
				{
					// No content found at all
					inG.setColor(EMPTY_IMAGE_COLOUR);
					inG.fillRect((width-previewSize)/2, (height-previewSize)/2, previewSize, previewSize);
				}
				// draw frame around it to make it more obvious
				inG.setColor(Color.BLACK);
				inG.drawRect((width-previewSize)/2, (height-previewSize)/2, previewSize-1, previewSize-1);
			}
		}
	}

	/**
	 * @return true if there is an image to use and it contains map tiles
	 */
	public boolean getTilesFound()
	{
		return _baseImage != null && _baseImage.isValid() && _baseImage.getImageSize() > 1
			&& _baseImage.getNumTilesUsed() > 0;
	}
}