3 import java.awt.BorderLayout;
4 import java.awt.event.ActionEvent;
5 import java.awt.event.ActionListener;
7 import javax.swing.BorderFactory;
8 import javax.swing.JButton;
9 import javax.swing.JDialog;
10 import javax.swing.JLabel;
11 import javax.swing.JPanel;
12 import javax.swing.border.EtchedBorder;
14 import tim.prune.I18nManager;
15 import tim.prune.data.Track;
16 import tim.prune.gui.map.MapSource;
17 import tim.prune.gui.map.MapSourceLibrary;
18 import tim.prune.save.BaseImageConfigDialog;
19 import tim.prune.save.BaseImageConsumer;
20 import tim.prune.save.MapGrouter;
21 import tim.prune.threedee.ImageDefinition;
24 * Panel used to show the current base image details
25 * and an edit button to change the definition
27 public class BaseImageDefinitionPanel extends JPanel implements BaseImageConsumer
29 /** Parent object (if any) */
30 private BaseImageConsumer _parent = null;
31 /** Label to describe the current settings */
32 private JLabel _baseImageLabel = null;
33 /** Button for changing the definition */
34 private JButton _editButton = null;
35 /** Dialog called by the "Edit" button to change the settings */
36 private BaseImageConfigDialog _baseImageConfig = null;
41 * @param inParent parent object to inform about changes
42 * @param inParentDialog parent dialog
43 * @param inTrack track object
45 public BaseImageDefinitionPanel(BaseImageConsumer inParent, JDialog inParentDialog,
49 _baseImageConfig = new BaseImageConfigDialog(this, inParentDialog, inTrack);
52 setBorder(BorderFactory.createCompoundBorder(
53 BorderFactory.createEtchedBorder(EtchedBorder.LOWERED), BorderFactory.createEmptyBorder(4, 4, 4, 4))
55 setLayout(new BorderLayout());
58 JPanel subPanel = new JPanel();
59 subPanel.setLayout(new BorderLayout(10, 4));
60 subPanel.add(new JLabel(I18nManager.getText("dialog.exportpov.baseimage") + ": "), BorderLayout.WEST);
61 _baseImageLabel = new JLabel("Typical sourcename");
62 subPanel.add(_baseImageLabel, BorderLayout.CENTER);
63 _editButton = new JButton(I18nManager.getText("button.edit"));
64 _editButton.addActionListener(new ActionListener() {
65 public void actionPerformed(ActionEvent event) {
69 subPanel.add(_editButton, BorderLayout.EAST);
70 add(subPanel, BorderLayout.NORTH);
74 * @param inDefinition image definition from interactive step
76 public void initImageParameters(ImageDefinition inDefinition)
78 _baseImageConfig.setImageDefinition(inDefinition);
82 * Change the base image by calling the BaseImageConfigDialog
84 private void changeBaseImage()
86 // Check if there is a cache to use
87 if (BaseImageConfigDialog.isImagePossible())
89 // Show new dialog to choose image details
90 _baseImageConfig.begin();
92 // TODO: What if it isn't possible? Should the caller show the error message?
94 // _app.showErrorMessage(getNameKey(), "dialog.exportimage.noimagepossible");
99 * Callback from base image config dialog
101 public void baseImageChanged()
103 updateBaseImageDetails();
104 if (_parent != null) {
105 _parent.baseImageChanged();
110 * Update the description label according to the selected base image details
112 public void updateBaseImageDetails()
115 ImageDefinition imageDef = _baseImageConfig.getImageDefinition();
116 // Check if selected zoom level is suitable or not, if not then set image to no
117 if (imageDef.getUseImage() && !_baseImageConfig.isSelectedZoomValid()) {
118 imageDef.setUseImage(false, imageDef.getSourceIndex(), 5);
120 // Make a description for the label
121 if (imageDef.getUseImage())
123 MapSource source = MapSourceLibrary.getSource(imageDef.getSourceIndex());
126 desc = source.getName() + " (" + imageDef.getZoom() + ")";
130 desc = I18nManager.getText("dialog.about.no");
132 _baseImageLabel.setText(desc);
133 _editButton.setEnabled(BaseImageConfigDialog.isImagePossible());
137 * @return the grouter object for reuse of the prepared images
139 public MapGrouter getGrouter()
141 return _baseImageConfig.getGrouter();
145 * @return image definition
147 public ImageDefinition getImageDefinition() {
148 return _baseImageConfig.getImageDefinition();
152 * @return true if any tiles were found
154 public boolean getFoundData() {
155 return _baseImageConfig.getFoundData();