1 | package iodb;
|
---|
2 |
|
---|
3 | import java.awt.GridLayout;
|
---|
4 | import java.awt.event.ActionEvent;
|
---|
5 | import java.awt.event.ActionListener;
|
---|
6 | import java.util.List;
|
---|
7 | import javax.swing.*;
|
---|
8 | import org.openstreetmap.josm.Main;
|
---|
9 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
10 |
|
---|
11 | /**
|
---|
12 | * The dialog which presents a choice between imagery align options.
|
---|
13 | *
|
---|
14 | * @author zverik
|
---|
15 | */
|
---|
16 | public class OffsetDialog extends JDialog implements ActionListener {
|
---|
17 | private List<ImageryOffsetBase> offsets;
|
---|
18 | private ImageryOffsetBase selectedOffset;
|
---|
19 |
|
---|
20 | public OffsetDialog( List<ImageryOffsetBase> offsets ) {
|
---|
21 | super(JOptionPane.getFrameForComponent(Main.parent), tr("Imagery Offset"), ModalityType.DOCUMENT_MODAL);
|
---|
22 | setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
|
---|
23 | this.offsets = offsets;
|
---|
24 | }
|
---|
25 |
|
---|
26 | private void prepareDialog() {
|
---|
27 | JPanel buttonPanel = new JPanel(new GridLayout(offsets.size() + 1, 1));
|
---|
28 | for( ImageryOffsetBase offset : offsets ) {
|
---|
29 | OffsetDialogButton button = new OffsetDialogButton(offset);
|
---|
30 | button.addActionListener(this);
|
---|
31 | buttonPanel.add(button);
|
---|
32 | }
|
---|
33 | JButton cancelButton = new JButton("Cancel");
|
---|
34 | cancelButton.addActionListener(this);
|
---|
35 | buttonPanel.add(cancelButton); // todo: proper button
|
---|
36 | setContentPane(buttonPanel);
|
---|
37 | pack();
|
---|
38 | setLocationRelativeTo(Main.parent);
|
---|
39 | }
|
---|
40 |
|
---|
41 | public ImageryOffsetBase showDialog() {
|
---|
42 | selectedOffset = null;
|
---|
43 | prepareDialog();
|
---|
44 | setVisible(true);
|
---|
45 | return selectedOffset;
|
---|
46 | }
|
---|
47 |
|
---|
48 | public void actionPerformed( ActionEvent e ) {
|
---|
49 | if( e.getSource() instanceof OffsetDialogButton ) {
|
---|
50 | selectedOffset = ((OffsetDialogButton)e.getSource()).getOffset();
|
---|
51 | } else
|
---|
52 | selectedOffset = null;
|
---|
53 | setVisible(false);
|
---|
54 | }
|
---|
55 | }
|
---|