Ignore:
Timestamp:
2012-03-06T21:32:44+01:00 (12 years ago)
Author:
zverik
Message:

Something works :)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java

    r27986 r28008  
    1414 * @author zverik
    1515 */
    16 public class OffsetDialog extends JDialog {
     16public class OffsetDialog extends JDialog implements ActionListener {
    1717    private List<ImageryOffsetBase> offsets;
    18     private int selectedOffset;
     18    private ImageryOffsetBase selectedOffset;
    1919
    2020    public OffsetDialog( List<ImageryOffsetBase> offsets ) {
     
    2727        JPanel buttonPanel = new JPanel(new GridLayout(offsets.size() + 1, 1));
    2828        for( ImageryOffsetBase offset : offsets ) {
    29             buttonPanel.add(new OffsetDialogButton(offset));
     29            OffsetDialogButton button = new OffsetDialogButton(offset);
     30            button.addActionListener(this);
     31            buttonPanel.add(button);
    3032        }
    3133        JButton cancelButton = new JButton("Cancel");
    32         cancelButton.addActionListener(new ActionListener() {
    33             public void actionPerformed(ActionEvent e) {
    34                 selectedOffset = -1;
    35                 OffsetDialog.this.setVisible(false);
    36             }
    37         });
     34        cancelButton.addActionListener(this);
    3835        buttonPanel.add(cancelButton); // todo: proper button
    3936        setContentPane(buttonPanel);
     
    4340   
    4441    public ImageryOffsetBase showDialog() {
    45         selectedOffset = -1;
     42        selectedOffset = null;
    4643        prepareDialog();
    4744        setVisible(true);
    48         return selectedOffset < 0 ? null : offsets.get(selectedOffset);
     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);
    4954    }
    5055}
Note: See TracChangeset for help on using the changeset viewer.