Changeset 29376 in osm for applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
- Timestamp:
- 2013-03-19T20:46:10+01:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/imagery_offset_db/src/iodb/OffsetDialog.java
r29371 r29376 1 1 package iodb; 2 2 3 import java.awt.FlowLayout; 3 4 import java.awt.GridLayout; 5 import java.awt.Insets; 4 6 import java.awt.event.ActionEvent; 5 7 import java.awt.event.ActionListener; 6 import java.util.List; 8 import java.awt.event.KeyEvent; 9 import java.util.*; 7 10 import javax.swing.*; 11 import javax.swing.border.CompoundBorder; 12 import javax.swing.border.EmptyBorder; 8 13 import org.openstreetmap.josm.Main; 9 14 import static org.openstreetmap.josm.tools.I18n.tr; … … 15 20 */ 16 21 public 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 17 25 private List<ImageryOffsetBase> offsets; 18 26 private ImageryOffsetBase selectedOffset; 27 private JPanel buttonPanel; 19 28 20 29 public OffsetDialog( List<ImageryOffsetBase> offsets ) { 21 super(JOptionPane.getFrameForComponent(Main.parent), tr("ImageryOffset"), ModalityType.DOCUMENT_MODAL);30 super(JOptionPane.getFrameForComponent(Main.parent), ImageryOffsetTools.DIALOG_TITLE, ModalityType.DOCUMENT_MODAL); 22 31 setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); 32 setResizable(false); 23 33 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); 24 39 } 25 40 26 41 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 ) { 29 85 OffsetDialogButton button = new OffsetDialogButton(offset); 30 86 button.addActionListener(this); 31 /*JPopupMenu popupMenu = new JPopupMenu();87 JPopupMenu popupMenu = new JPopupMenu(); 32 88 popupMenu.add(new OffsetInfoAction(offset)); 33 89 if( !offset.isDeprecated() ) 34 90 popupMenu.add(new DeprecateOffsetAction(offset)); 35 button. add(popupMenu);*/91 button.setComponentPopupMenu(popupMenu); 36 92 buttonPanel.add(button); 37 93 } 38 // todo: calibration objects and deprecated offsets button39 JButton cancelButton = new JButton("Cancel");40 cancelButton.addActionListener(this);41 buttonPanel.add(cancelButton); // todo: proper button42 setContentPane(buttonPanel);43 94 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; 45 109 } 46 110
Note:
See TracChangeset
for help on using the changeset viewer.
