Changeset 25350 in osm for applications/editors/josm/plugins/pdfimport
- Timestamp:
- 2011-02-18T09:44:49+01:00 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/pdfimport/src/pdfimport/LoadPdfDialog.java
r25349 r25350 1 1 package pdfimport; 2 2 3 import java.awt.BorderLayout; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 4 5 5 6 import java.awt.Color; 7 import java.awt.Component; 6 8 import java.awt.Cursor; 9 import java.awt.Dimension; 10 import java.awt.FlowLayout; 7 11 import java.awt.GridBagConstraints; 8 12 import java.awt.GridBagLayout; … … 10 14 import java.awt.event.ActionEvent; 11 15 import java.awt.event.ActionListener; 16 import java.awt.event.KeyEvent; 12 17 import java.awt.event.WindowAdapter; 13 18 import java.awt.event.WindowEvent; … … 19 24 import java.util.Collection; 20 25 import java.util.Properties; 26 import javax.swing.AbstractAction; 21 27 22 28 import javax.swing.BorderFactory; 29 import javax.swing.BoxLayout; 23 30 import javax.swing.JButton; 24 31 import javax.swing.JCheckBox; 25 32 import javax.swing.JComboBox; 33 import javax.swing.JComponent; 34 import javax.swing.JDialog; 26 35 import javax.swing.JFileChooser; 27 36 import javax.swing.JFrame; … … 31 40 import javax.swing.JProgressBar; 32 41 import javax.swing.JTextField; 42 import javax.swing.KeyStroke; 33 43 import javax.swing.SwingUtilities; 34 44 import javax.swing.filechooser.FileFilter; … … 42 52 import org.openstreetmap.josm.data.projection.Projection; 43 53 import org.openstreetmap.josm.data.projection.Projections; 54 import org.openstreetmap.josm.data.projection.ProjectionSubPrefs; 44 55 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 45 56 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 46 57 import org.openstreetmap.josm.gui.progress.ProgressRenderer; 47 58 import org.openstreetmap.josm.gui.progress.SwingRenderingProgressMonitor; 59 import org.openstreetmap.josm.gui.SideButton; 60 import org.openstreetmap.josm.gui.help.ContextSensitiveHelpAction; 48 61 import org.openstreetmap.josm.io.OsmExporter; 62 import org.openstreetmap.josm.tools.ImageProvider; 63 import org.openstreetmap.josm.tools.WindowGeometry; 49 64 50 65 import pdfimport.pdfbox.PdfBoxParser; … … 103 118 */ 104 119 private JComboBox projectionCombo; 120 private JButton projectionPreferencesButton; 105 121 private JTextField minXField; 106 122 private JTextField minYField; … … 151 167 private void addListeners() { 152 168 169 this.projectionCombo.addActionListener(new ActionListener() { 170 public void actionPerformed(ActionEvent e) { 171 updateProjectionPrefButton(); 172 } 173 174 }); 175 this.projectionPreferencesButton.addActionListener(new ActionListener() { 176 public void actionPerformed(ActionEvent e) { 177 showProjectionPreferences(); 178 } 179 }); 180 153 181 this.loadFileButton.addActionListener(new ActionListener() { 154 182 public void actionPerformed(ActionEvent e) { … … 208 236 209 237 this.projectionCombo = new JComboBox(); 210 this.projectionCombo.addItem("Select projection..."); 238 this.projectionCombo.addItem(tr("Select projection...")); 211 239 for (Projection p: Projections.getProjections()) { 212 240 this.projectionCombo.addItem(p); 213 241 } 242 243 this.projectionPreferencesButton = new JButton(tr("Prefs")); 244 updateProjectionPrefButton(); 214 245 215 246 this.loadFileButton = new JButton(tr("Load file...")); … … 318 349 projectionPanel.setBorder(BorderFactory.createTitledBorder(tr("Bind to coordinates"))); 319 350 320 c.gridx = 0; c.gridy = 0; c.gridwidth = 1; 321 projectionPanel.add(new JLabel(tr("Projection:")), c); 322 c.gridx = 1; c.gridy = 0; c.gridwidth = 1; 323 projectionPanel.add(this.projectionCombo); 351 JPanel projectionSubPanel = new JPanel(); 352 projectionSubPanel.setLayout(new BoxLayout(projectionSubPanel, BoxLayout.X_AXIS)); 353 354 projectionSubPanel.add(new JLabel(tr("Projection:"))); 355 projectionSubPanel.add(this.projectionCombo); 356 projectionSubPanel.add(this.projectionPreferencesButton); 357 c.gridx = 0; c.gridy = 0; c.gridwidth = 3; 358 projectionPanel.add(projectionSubPanel, c); 324 359 325 360 c.gridx = 0; c.gridy = 1; c.gridwidth = 2; … … 383 418 } 384 419 420 private class ProjectionSubPrefsDialog extends JDialog { 421 private ProjectionSubPrefs projPref; 422 private OKAction actOK; 423 private CancelAction actCancel; 424 private JPanel projPrefPanel; 425 426 public ProjectionSubPrefsDialog(Component parent, ProjectionSubPrefs pr) { 427 super(JOptionPane.getFrameForComponent(parent), ModalityType.DOCUMENT_MODAL); 428 429 projPref = pr; 430 431 setTitle(tr("Projection Preferences")); 432 setDefaultCloseOperation(DISPOSE_ON_CLOSE); 433 434 build(); 435 } 436 437 protected void makeButtonRespondToEnter(SideButton btn) { 438 btn.setFocusable(true); 439 btn.getInputMap(JComponent.WHEN_FOCUSED).put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER,0), "enter"); 440 btn.getActionMap().put("enter", btn.getAction()); 441 } 442 443 protected JPanel buildInputForm() { 444 JPanel pnl = new JPanel(); 445 projPref.setupPreferencePanel(pnl, null); 446 return pnl; 447 } 448 449 protected JPanel buildButtonRow() { 450 JPanel pnl = new JPanel(new FlowLayout()); 451 452 actOK = new OKAction(); 453 actCancel = new CancelAction(); 454 455 SideButton btn; 456 pnl.add(btn = new SideButton(actOK)); 457 makeButtonRespondToEnter(btn); 458 pnl.add(btn = new SideButton(actCancel)); 459 makeButtonRespondToEnter(btn); 460 return pnl; 461 } 462 463 protected void build() { 464 projPrefPanel = buildInputForm(); 465 getContentPane().setLayout(new BorderLayout()); 466 getContentPane().add(projPrefPanel, BorderLayout.CENTER); 467 getContentPane().add(buildButtonRow(), BorderLayout.SOUTH); 468 pack(); 469 470 // make dialog respond to ESCAPE 471 getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "escape"); 472 getRootPane().getActionMap().put("escape", actCancel); 473 } 474 475 class OKAction extends AbstractAction { 476 public OKAction() { 477 putValue(NAME, tr("OK")); 478 putValue(SHORT_DESCRIPTION, tr("Close the dialog and apply projection preferences")); 479 putValue(SMALL_ICON, ImageProvider.get("ok")); 480 } 481 482 public void actionPerformed(ActionEvent e) { 483 projPref.setPreferences(projPref.getPreferences(projPrefPanel)); 484 setVisible(false); 485 } 486 } 487 488 class CancelAction extends AbstractAction { 489 public CancelAction() { 490 putValue(NAME, tr("Cancel")); 491 putValue(SHORT_DESCRIPTION, tr("Close the dialog, discard projection preference changes")); 492 putValue(SMALL_ICON, ImageProvider.get("cancel")); 493 } 494 495 public void actionPerformed(ActionEvent e) { 496 setVisible(false); 497 } 498 } 499 500 @Override 501 public void setVisible(boolean visible) { 502 if (visible) { 503 new WindowGeometry( 504 getClass().getName() + ".geometry", 505 WindowGeometry.centerOnScreen(new Dimension(400, 300))).applySafe(this); 506 } else { 507 new WindowGeometry(this).remember(getClass().getName() + ".geometry"); 508 } 509 super.setVisible(visible); 510 } 511 } 512 513 private void updateProjectionPrefButton() { 514 Object proj = projectionCombo.getSelectedItem(); 515 516 // Enable/disable pref button 517 if(!(proj instanceof ProjectionSubPrefs)) { 518 projectionPreferencesButton.setEnabled(false); 519 } else { 520 projectionPreferencesButton.setEnabled(true); 521 } 522 } 523 524 private void showProjectionPreferences() { 525 Object proj = projectionCombo.getSelectedItem(); 526 527 if(proj instanceof ProjectionSubPrefs) { 528 ProjectionSubPrefsDialog dlg = 529 new ProjectionSubPrefsDialog(this, (ProjectionSubPrefs)proj); 530 dlg.setVisible(true); 531 } 532 } 385 533 386 534 private void loadFilePressed() {
Note:
See TracChangeset
for help on using the changeset viewer.