Ignore:
Timestamp:
2013-03-19T20:46:10+01:00 (13 years ago)
Author:
zverik
Message:

another iteration

File:
1 edited

Legend:

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

    r29371 r29376  
    11package iodb;
    22
     3import java.awt.FlowLayout;
    34import java.awt.GridLayout;
     5import java.awt.Insets;
    46import java.awt.event.ActionEvent;
    57import java.awt.event.ActionListener;
    6 import java.util.List;
     8import java.awt.event.KeyEvent;
     9import java.util.*;
    710import javax.swing.*;
     11import javax.swing.border.CompoundBorder;
     12import javax.swing.border.EmptyBorder;
    813import org.openstreetmap.josm.Main;
    914import static org.openstreetmap.josm.tools.I18n.tr;
     
    1520 */
    1621public class OffsetDialog extends JDialog implements ActionListener {
     22    protected static final String PREF_CALIBRATION = "iodb.show.calibration";
     23    protected static final String PREF_DEPRECATED = "iodb.show.deprecated";
     24
    1725    private List<ImageryOffsetBase> offsets;
    1826    private ImageryOffsetBase selectedOffset;
     27    private JPanel buttonPanel;
    1928
    2029    public OffsetDialog( List<ImageryOffsetBase> offsets ) {
    21         super(JOptionPane.getFrameForComponent(Main.parent), tr("Imagery Offset"), ModalityType.DOCUMENT_MODAL);
     30        super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL);
    2231        setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
     32        setResizable(false);
    2333        this.offsets = offsets;
     34
     35        // make this dialog close on "escape"
     36        getRootPane().registerKeyboardAction(this,
     37                KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
     38                JComponent.WHEN_IN_FOCUSED_WINDOW);
    2439    }
    2540   
    2641    private void prepareDialog() {
    27         JPanel buttonPanel = new JPanel(new GridLayout(offsets.size() + 1, 1));
    28         for( ImageryOffsetBase offset : offsets ) {
     42        Box dialog = new Box(BoxLayout.Y_AXIS);
     43        updateButtonPanel();
     44        // todo: calibration objects and deprecated offsets button
     45        final JCheckBox calibrationBox = new JCheckBox(tr("Hide calibration geometries"));
     46        calibrationBox.setSelected(Main.pref.getBoolean(PREF_CALIBRATION, true));
     47        calibrationBox.addActionListener(new ActionListener() {
     48            public void actionPerformed( ActionEvent e ) {
     49                Main.pref.put(PREF_CALIBRATION, calibrationBox.isSelected());
     50                updateButtonPanel();
     51            }
     52        });
     53        final JCheckBox deprecatedBox = new JCheckBox(tr("Show deprecated offsets"));
     54        deprecatedBox.setSelected(Main.pref.getBoolean(PREF_DEPRECATED, false));
     55        deprecatedBox.addActionListener(new ActionListener() {
     56            public void actionPerformed( ActionEvent e ) {
     57                Main.pref.put(PREF_DEPRECATED, deprecatedBox.isSelected());
     58                updateButtonPanel();
     59            }
     60        });
     61        Box checkBoxPanel = new Box(BoxLayout.X_AXIS);
     62        checkBoxPanel.add(calibrationBox);
     63        checkBoxPanel.add(deprecatedBox);
     64        JButton cancelButton = new JButton("Cancel");
     65        cancelButton.addActionListener(this);
     66        cancelButton.setAlignmentX(CENTER_ALIGNMENT);
     67
     68        dialog.add(buttonPanel);
     69        dialog.add(checkBoxPanel);
     70        dialog.add(cancelButton);
     71
     72        dialog.setBorder(new CompoundBorder(dialog.getBorder(), new EmptyBorder(5, 5, 5, 5)));
     73        setContentPane(dialog);
     74        pack();
     75        setLocationRelativeTo(Main.parent);
     76    }
     77
     78    private void updateButtonPanel() {
     79        List<ImageryOffsetBase> filteredOffsets = filterOffsets();
     80        if( buttonPanel == null )
     81            buttonPanel = new JPanel();
     82        buttonPanel.removeAll();
     83        buttonPanel.setLayout(new GridLayout(filteredOffsets.size(), 1, 0, 5));
     84        for( ImageryOffsetBase offset : filteredOffsets ) {
    2985            OffsetDialogButton button = new OffsetDialogButton(offset);
    3086            button.addActionListener(this);
    31 /*            JPopupMenu popupMenu = new JPopupMenu();
     87            JPopupMenu popupMenu = new JPopupMenu();
    3288            popupMenu.add(new OffsetInfoAction(offset));
    3389            if( !offset.isDeprecated() )
    3490                popupMenu.add(new DeprecateOffsetAction(offset));
    35             button.add(popupMenu);*/
     91            button.setComponentPopupMenu(popupMenu);
    3692            buttonPanel.add(button);
    3793        }
    38         // todo: calibration objects and deprecated offsets button
    39         JButton cancelButton = new JButton("Cancel");
    40         cancelButton.addActionListener(this);
    41         buttonPanel.add(cancelButton); // todo: proper button
    42         setContentPane(buttonPanel);
    4394        pack();
    44         setLocationRelativeTo(Main.parent);
     95    }
     96
     97    private List<ImageryOffsetBase> filterOffsets() {
     98        boolean showCalibration = Main.pref.getBoolean(PREF_CALIBRATION, true);
     99        boolean showDeprecated = Main.pref.getBoolean(PREF_DEPRECATED, false);
     100        List<ImageryOffsetBase> filteredOffsets = new ArrayList<ImageryOffsetBase>();
     101        for( ImageryOffsetBase offset : offsets ) {
     102            if( offset.isDeprecated() && !showDeprecated )
     103                continue;
     104            if( offset instanceof CalibrationObject && !showCalibration )
     105                continue;
     106            filteredOffsets.add(offset);
     107        }
     108        return filteredOffsets;
    45109    }
    46110   
Note: See TracChangeset for help on using the changeset viewer.