Changeset 3816 in josm
- Timestamp:
- 2011-01-25T16:36:56+01:00 (14 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 2 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/ImageryPreference.java
r3779 r3816 21 21 import java.util.Locale; 22 22 23 import javax.swing.AbstractAction; 23 24 import javax.swing.BorderFactory; 24 25 import javax.swing.Box; … … 38 39 import javax.swing.JTable; 39 40 import javax.swing.JTextField; 41 import javax.swing.JToolBar; 40 42 import javax.swing.SpinnerNumberModel; 43 import javax.swing.event.ListSelectionEvent; 44 import javax.swing.event.ListSelectionListener; 41 45 import javax.swing.table.DefaultTableModel; 42 46 import javax.swing.table.TableColumnModel; … … 53 57 import org.openstreetmap.josm.tools.ColorHelper; 54 58 import org.openstreetmap.josm.tools.GBC; 59 import org.openstreetmap.josm.tools.ImageProvider; 55 60 56 61 public class ImageryPreference implements PreferenceSetting { … … 349 354 static class ImageryProvidersPanel extends JPanel { 350 355 final ImageryLayerTableModel model; 356 final ImageryDefaultLayerTableModel modeldef; 351 357 private final ImageryLayerInfo layerInfo; 358 private JTable listActive; 359 final JTable listdef; 360 final PreferenceTabbedPane gui; 352 361 353 362 public ImageryProvidersPanel(final PreferenceTabbedPane gui, ImageryLayerInfo layerInfo) { 354 363 super(new GridBagLayout()); 364 this.gui = gui; 355 365 this.layerInfo = layerInfo; 356 366 this.model = new ImageryLayerTableModel(); 357 367 358 final JTable list= new JTable(model) {368 listActive = new JTable(model) { 359 369 @Override 360 370 public String getToolTipText(MouseEvent e) { … … 363 373 } 364 374 }; 365 JScrollPane scroll = new JScrollPane(list); 366 add(scroll, GBC.eol().fill(GridBagConstraints.BOTH)); 367 scroll.setPreferredSize(new Dimension(200, 200)); 368 369 final ImageryDefaultLayerTableModel modeldef = new ImageryDefaultLayerTableModel(); 370 final JTable listdef = new JTable(modeldef) { 375 376 modeldef = new ImageryDefaultLayerTableModel(); 377 listdef = new JTable(modeldef) { 371 378 @Override 372 379 public String getToolTipText(MouseEvent e) { … … 375 382 } 376 383 }; 377 JScrollPane scrolldef = new JScrollPane(listdef);378 // scrolldef is added after the buttons so it's clearer the buttons379 // control the top list and not the default one380 scrolldef.setPreferredSize(new Dimension(200, 200));381 384 382 385 TableColumnModel mod = listdef.getColumnModel(); 383 386 mod.getColumn(1).setPreferredWidth(800); 384 387 mod.getColumn(0).setPreferredWidth(200); 385 mod = list .getColumnModel();388 mod = listActive.getColumnModel(); 386 389 mod.getColumn(2).setPreferredWidth(50); 387 390 mod.getColumn(1).setPreferredWidth(800); 388 391 mod.getColumn(0).setPreferredWidth(200); 389 392 390 JPanel buttonPanel = new JPanel(new FlowLayout()); 391 392 JButton add = new JButton(tr("Add")); 393 buttonPanel.add(add, GBC.std().insets(0, 5, 0, 0)); 394 add.addActionListener(new ActionListener() { 395 @Override 396 public void actionPerformed(ActionEvent e) { 397 AddWMSLayerPanel p = new AddWMSLayerPanel(); 398 int answer = JOptionPane.showConfirmDialog( 399 gui, p, 400 tr("Add Imagery URL"), 401 JOptionPane.OK_CANCEL_OPTION); 402 if (answer == JOptionPane.OK_OPTION) { 403 model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl())); 404 } 405 } 406 }); 407 408 JButton delete = new JButton(tr("Delete")); 409 buttonPanel.add(delete, GBC.std().insets(0, 5, 0, 0)); 410 delete.addActionListener(new ActionListener() { 411 @Override 412 public void actionPerformed(ActionEvent e) { 413 if (list.getSelectedRow() == -1) { 414 JOptionPane.showMessageDialog(gui, tr("Please select the row to delete.")); 415 } else { 416 Integer i; 417 while ((i = list.getSelectedRow()) != -1) { 418 model.removeRow(i); 393 RemoveEntryAction remove = new RemoveEntryAction(); 394 listActive.getSelectionModel().addListSelectionListener(remove); 395 396 add(new JLabel(tr("Available default entries:")), GBC.eol().insets(5, 5, 0, 0)); 397 // Add default item list 398 JScrollPane scrolldef = new JScrollPane(listdef); 399 scrolldef.setPreferredSize(new Dimension(200, 200)); 400 add(scrolldef, GBC.std().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH).weight(1.0, 0.6).insets(5, 0, 0, 0)); 401 402 JToolBar tb = new JToolBar(JToolBar.VERTICAL); 403 tb.setFloatable(false); 404 tb.setBorderPainted(false); 405 tb.setOpaque(false); 406 tb.add(new ReloadAction()); 407 add(tb, GBC.eol().anchor(GBC.SOUTH).insets(0, 0, 5, 0)); 408 409 ActivateAction activate = new ActivateAction(); 410 listdef.getSelectionModel().addListSelectionListener(activate); 411 JButton btnActivate = new JButton(activate); 412 413 JToolBar tb2 = new JToolBar(JToolBar.VERTICAL); 414 tb2.setFloatable(false); 415 tb2.setBorderPainted(false); 416 tb2.setOpaque(false); 417 tb2.add(btnActivate); 418 add(tb2, GBC.eol().anchor(GBC.CENTER).insets(5, 15, 5, 0)); 419 420 add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 421 422 add(new JLabel(tr("Selected entries:")), GBC.eol().insets(5, 0, 0, 0)); 423 JScrollPane scroll = new JScrollPane(listActive); 424 add(scroll, GBC.std().fill(GridBagConstraints.BOTH).weight(1.0, 0.4).insets(5, 0, 0, 5)); 425 scroll.setPreferredSize(new Dimension(200, 200)); 426 427 JToolBar sideButtonTB = new JToolBar(JToolBar.VERTICAL); 428 sideButtonTB.setFloatable(false); 429 sideButtonTB.setBorderPainted(false); 430 sideButtonTB.setOpaque(false); 431 sideButtonTB.add(new NewEntryAction()); 432 //sideButtonTB.add(edit); TODO 433 sideButtonTB.add(remove); 434 add(sideButtonTB, GBC.eol().anchor(GBC.NORTH).insets(0, 0, 5, 5)); 435 436 } 437 438 class NewEntryAction extends AbstractAction { 439 public NewEntryAction() { 440 putValue(NAME, tr("New")); 441 putValue(SHORT_DESCRIPTION, tr("add a new wms/tms entry by entering the url")); 442 putValue(SMALL_ICON, ImageProvider.get("dialogs", "add")); 443 } 444 445 public void actionPerformed(ActionEvent evt) { 446 AddWMSLayerPanel p = new AddWMSLayerPanel(); 447 int answer = JOptionPane.showConfirmDialog( 448 gui, p, 449 tr("Add Imagery URL"), 450 JOptionPane.OK_CANCEL_OPTION); 451 if (answer == JOptionPane.OK_OPTION) { 452 model.addRow(new ImageryInfo(p.getUrlName(), p.getUrl())); 453 } 454 } 455 } 456 457 class RemoveEntryAction extends AbstractAction implements ListSelectionListener { 458 459 public RemoveEntryAction() { 460 putValue(NAME, tr("Remove")); 461 putValue(SHORT_DESCRIPTION, tr("remove entry")); 462 putValue(SMALL_ICON, ImageProvider.get("dialogs", "delete")); 463 updateEnabledState(); 464 } 465 466 protected void updateEnabledState() { 467 setEnabled(listActive.getSelectedRowCount() > 0); 468 } 469 470 @Override 471 public void valueChanged(ListSelectionEvent e) { 472 updateEnabledState(); 473 } 474 475 @Override 476 public void actionPerformed(ActionEvent e) { 477 Integer i; 478 while ((i = listActive.getSelectedRow()) != -1) { 479 model.removeRow(i); 480 } 481 } 482 } 483 484 class ActivateAction extends AbstractAction implements ListSelectionListener { 485 public ActivateAction() { 486 putValue(NAME, tr("Activate")); 487 putValue(SHORT_DESCRIPTION, tr("copy selected defaults")); 488 putValue(SMALL_ICON, ImageProvider.get("preferences", "activate-down")); 489 } 490 491 protected void updateEnabledState() { 492 setEnabled(listdef.getSelectedRowCount() > 0); 493 } 494 495 @Override 496 public void valueChanged(ListSelectionEvent e) { 497 updateEnabledState(); 498 } 499 500 @Override 501 public void actionPerformed(ActionEvent e) { 502 int[] lines = listdef.getSelectedRows(); 503 if (lines.length == 0) { 504 JOptionPane.showMessageDialog( 505 gui, 506 tr("Please select at least one row to copy."), 507 tr("Information"), 508 JOptionPane.INFORMATION_MESSAGE); 509 return; 510 } 511 512 outer: for (int i = 0; i < lines.length; i++) { 513 ImageryInfo info = modeldef.getRow(lines[i]); 514 515 // Check if an entry with exactly the same values already 516 // exists 517 for (int j = 0; j < model.getRowCount(); j++) { 518 if (info.equalsBaseValues(model.getRow(j))) { 519 // Select the already existing row so the user has 520 // some feedback in case an entry exists 521 listActive.getSelectionModel().setSelectionInterval(j, j); 522 listActive.scrollRectToVisible(listActive.getCellRect(j, 0, true)); 523 continue outer; 419 524 } 420 525 } 421 } 422 }); 423 424 JButton copy = new JButton(tr("Copy Selected Default(s)")); 425 buttonPanel.add(copy, GBC.std().insets(0, 5, 0, 0)); 426 copy.addActionListener(new ActionListener() { 427 @Override 428 public void actionPerformed(ActionEvent e) { 429 int[] lines = listdef.getSelectedRows(); 430 if (lines.length == 0) { 431 JOptionPane.showMessageDialog( 432 gui, 433 tr("Please select at least one row to copy."), 434 tr("Information"), 435 JOptionPane.INFORMATION_MESSAGE); 436 return; 526 527 if (info.eulaAcceptanceRequired != null) { 528 if (!confirmEulaAcceptance(gui, info.eulaAcceptanceRequired)) { 529 continue outer; 530 } 437 531 } 438 532 439 outer: for (int i = 0; i < lines.length; i++) { 440 ImageryInfo info = modeldef.getRow(lines[i]); 441 442 // Check if an entry with exactly the same values already 443 // exists 444 for (int j = 0; j < model.getRowCount(); j++) { 445 if (info.equalsBaseValues(model.getRow(j))) { 446 // Select the already existing row so the user has 447 // some feedback in case an entry exists 448 list.getSelectionModel().setSelectionInterval(j, j); 449 list.scrollRectToVisible(list.getCellRect(j, 0, true)); 450 continue outer; 451 } 452 } 453 454 if (info.eulaAcceptanceRequired != null) { 455 if (!confirmEulaAcceptance(gui, info.eulaAcceptanceRequired)) { 456 continue outer; 457 } 458 } 459 460 model.addRow(new ImageryInfo(info)); 461 int lastLine = model.getRowCount() - 1; 462 list.getSelectionModel().setSelectionInterval(lastLine, lastLine); 463 list.scrollRectToVisible(list.getCellRect(lastLine, 0, true)); 464 } 465 } 466 }); 467 468 add(buttonPanel); 469 add(Box.createHorizontalGlue(), GBC.eol().fill(GridBagConstraints.HORIZONTAL)); 470 // Add default item list 471 add(scrolldef, GBC.eol().insets(0, 5, 0, 0).fill(GridBagConstraints.BOTH)); 533 model.addRow(new ImageryInfo(info)); 534 int lastLine = model.getRowCount() - 1; 535 listActive.getSelectionModel().setSelectionInterval(lastLine, lastLine); 536 listActive.scrollRectToVisible(listActive.getCellRect(lastLine, 0, true)); 537 } 538 } 539 } 540 541 class ReloadAction extends AbstractAction { 542 public ReloadAction() { 543 putValue(SHORT_DESCRIPTION, tr("reload defaults")); 544 putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh")); 545 } 546 547 public void actionPerformed(ActionEvent evt) { 548 layerInfo.load(); 549 modeldef.fireTableDataChanged(); 550 } 472 551 } 473 552 -
trunk/src/org/openstreetmap/josm/gui/preferences/SourceEditor.java
r3797 r3816 219 219 gbc.insets = new Insets(0, 11, 0, 0); 220 220 221 JToolBar bottomLeftTB = new JToolBar( JToolBar.VERTICAL);221 JToolBar bottomLeftTB = new JToolBar(); 222 222 bottomLeftTB.setFloatable(false); 223 223 bottomLeftTB.setBorderPainted(false); 224 224 bottomLeftTB.setOpaque(false); 225 225 bottomLeftTB.add(new ReloadSourcesAction(availableSourcesUrl)); 226 middleTB.add(Box.createHorizontalGlue());226 bottomLeftTB.add(Box.createHorizontalGlue()); 227 227 add(bottomLeftTB, gbc); 228 228 … … 757 757 public ActivateSourcesAction() { 758 758 putValue(SHORT_DESCRIPTION, getStr(I18nString.ACTIVATE_TOOLTIP)); 759 putValue(SMALL_ICON, ImageProvider.get("preferences", "activate style"));759 putValue(SMALL_ICON, ImageProvider.get("preferences", "activate-right")); 760 760 updateEnabledState(); 761 761 } … … 793 793 putValue(NAME, tr("Reload")); 794 794 putValue(SHORT_DESCRIPTION, tr(getStr(I18nString.RELOAD_ALL_AVAILABLE), url)); 795 putValue(SMALL_ICON, ImageProvider.get("dialogs /refresh"));795 putValue(SMALL_ICON, ImageProvider.get("dialogs", "refresh")); 796 796 this.url = url; 797 797 }
Note:
See TracChangeset
for help on using the changeset viewer.