Changeset 5965 in josm for trunk/src/org/openstreetmap/josm/gui/MapStatus.java
- Timestamp:
- 2013-05-17T20:45:17+02:00 (11 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MapStatus.java
r5909 r5965 6 6 7 7 import java.awt.AWTEvent; 8 import java.awt.Color;9 8 import java.awt.Component; 10 9 import java.awt.Cursor; … … 17 16 import java.awt.Toolkit; 18 17 import java.awt.event.AWTEventListener; 18 import java.awt.event.ActionEvent; 19 19 import java.awt.event.InputEvent; 20 20 import java.awt.event.KeyAdapter; … … 29 29 import java.util.List; 30 30 31 import javax.swing.AbstractAction; 31 32 import javax.swing.BorderFactory; 33 import javax.swing.JButton; 34 import javax.swing.JCheckBoxMenuItem; 32 35 import javax.swing.JLabel; 36 import javax.swing.JMenuItem; 33 37 import javax.swing.JPanel; 38 import javax.swing.JPopupMenu; 34 39 import javax.swing.JProgressBar; 35 40 import javax.swing.JScrollPane; … … 37 42 import javax.swing.PopupFactory; 38 43 import javax.swing.UIManager; 44 import javax.swing.event.PopupMenuEvent; 45 import javax.swing.event.PopupMenuListener; 39 46 40 47 import org.openstreetmap.josm.Main; … … 47 54 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor.ProgressMonitorDialog; 48 55 import org.openstreetmap.josm.gui.util.GuiHelper; 56 import org.openstreetmap.josm.gui.widgets.ImageLabel; 57 import org.openstreetmap.josm.gui.widgets.JosmTextField; 49 58 import org.openstreetmap.josm.tools.GBC; 50 59 import org.openstreetmap.josm.tools.ImageProvider; 51 import org.openstreetmap.josm.gui.widgets.JosmTextField;52 60 53 61 /** … … 72 80 final Collector collector; 73 81 74 /**75 * A small user interface component that consists of an image label and76 * a fixed text content to the right of the image.77 */78 static class ImageLabel extends JPanel {79 static Color backColor = Color.decode("#b8cfe5");80 static Color backColorActive = Color.decode("#aaff5e");81 82 private JLabel tf;83 private int chars;84 public ImageLabel(String img, String tooltip, int chars) {85 super();86 setLayout(new GridBagLayout());87 setBackground(backColor);88 add(new JLabel(ImageProvider.get("statusline/"+img+".png")), GBC.std().anchor(GBC.WEST).insets(0,1,1,0));89 add(tf = new JLabel(), GBC.std().fill(GBC.BOTH).anchor(GBC.WEST).insets(2,1,1,0));90 setToolTipText(tooltip);91 this.chars = chars;92 }93 public void setText(String t) {94 tf.setText(t);95 }96 @Override public Dimension getPreferredSize() {97 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getPreferredSize().height);98 }99 @Override public Dimension getMinimumSize() {100 return new Dimension(25 + chars*tf.getFontMetrics(tf.getFont()).charWidth('0'), super.getMinimumSize().height);101 }102 }103 104 82 public class BackgroundProgressMonitor implements ProgressMonitorDialog { 105 83 … … 115 93 } 116 94 95 @Override 117 96 public void setVisible(boolean visible) { 118 97 progressBar.setVisible(visible); 119 98 } 120 99 100 @Override 121 101 public void updateProgress(int progress) { 122 102 progressBar.setValue(progress); … … 125 105 } 126 106 107 @Override 127 108 public void setCustomText(String text) { 128 109 this.customText = text; … … 130 111 } 131 112 113 @Override 132 114 public void setCurrentAction(String text) { 133 115 this.title = text; … … 135 117 } 136 118 119 @Override 137 120 public void setIndeterminate(boolean newValue) { 138 121 UIManager.put("ProgressBar.cycleTime", UIManager.getInt("ProgressBar.repaintInterval") * 100); … … 218 201 * Execution function for the Collector. 219 202 */ 203 @Override 220 204 public void run() { 221 205 registerListeners(); … … 281 265 // Set the text label in the bottom status bar 282 266 // "if mouse moved only" was added to stop heap growing 283 if (!mouseNotMoved) statusBarElementUpdate(ms); 267 if (!mouseNotMoved) { 268 statusBarElementUpdate(ms); 269 } 284 270 285 271 … … 363 349 * @return popup 364 350 */ 365 private finalPopup popupCreatePopup(Component content, MouseState ms) {351 private Popup popupCreatePopup(Component content, MouseState ms) { 366 352 Point p = mv.getLocationOnScreen(); 367 353 Dimension scrn = Toolkit.getDefaultToolkit().getScreenSize(); … … 399 385 * @param ms 400 386 */ 401 private finalvoid statusBarElementUpdate(MouseState ms) {387 private void statusBarElementUpdate(MouseState ms) { 402 388 final OsmPrimitive osmNearest = mv.getNearestNodeOrWay(ms.mousePos, OsmPrimitive.isUsablePredicate, false); 403 389 if (osmNearest != null) { … … 414 400 * @param mods modifiers (i.e. control keys) 415 401 */ 416 private finalvoid popupCycleSelection(Collection<OsmPrimitive> osms, int mods) {402 private void popupCycleSelection(Collection<OsmPrimitive> osms, int mods) { 417 403 DataSet ds = Main.main.getCurrentDataSet(); 418 404 // Find some items that are required for cycling through … … 453 439 * Tries to hide the given popup 454 440 */ 455 private finalvoid popupHidePopup() {441 private void popupHidePopup() { 456 442 popupLabels = null; 457 443 if(popup == null) … … 460 446 popup = null; 461 447 EventQueue.invokeLater(new Runnable(){ 462 public void run() { staticPopup.hide(); }}); 448 public void run() { 449 staticPopup.hide(); 450 }}); 463 451 } 464 452 … … 469 457 * @param lbls lables to show (see {@link #popupLabels}) 470 458 */ 471 private finalvoid popupShowPopup(Popup newPopup, List<JLabel> lbls) {459 private void popupShowPopup(Popup newPopup, List<JLabel> lbls) { 472 460 final Popup staticPopup = newPopup; 473 461 if(this.popup != null) { … … 476 464 final Popup staticOldPopup = this.popup; 477 465 EventQueue.invokeLater(new Runnable(){ 478 public void run() {466 @Override public void run() { 479 467 staticPopup.show(); 480 468 staticOldPopup.hide(); … … 484 472 // There is no old popup 485 473 EventQueue.invokeLater(new Runnable(){ 486 public void run() { staticPopup.show(); }});474 @Override public void run() { staticPopup.show(); }}); 487 475 } 488 476 this.popupLabels = lbls; … … 495 483 * user clicks on the map instead of the popup. 496 484 */ 497 private finalvoid popupUpdateLabels() {485 private void popupUpdateLabels() { 498 486 if(this.popup == null || this.popupLabels == null) 499 487 return; … … 510 498 * @param osm The primitive to derive the colors from 511 499 */ 512 private finalvoid popupSetLabelColors(JLabel lbl, OsmPrimitive osm) {500 private void popupSetLabelColors(JLabel lbl, OsmPrimitive osm) { 513 501 DataSet ds = Main.main.getCurrentDataSet(); 514 502 if(ds.isSelected(osm)) { … … 527 515 * @return labels for info popup 528 516 */ 529 private finalJLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) {517 private JLabel popupBuildPrimitiveLabels(final OsmPrimitive osm) { 530 518 final StringBuilder text = new StringBuilder(); 531 519 String name = osm.getDisplayName(DefaultNameFormatter.getInstance()); … … 587 575 // can correct this defect. 588 576 l.addMouseMotionListener(new MouseMotionListener() { 589 public void mouseMoved(MouseEvent e) {577 @Override public void mouseMoved(MouseEvent e) { 590 578 l.setBackground(SystemColor.info); 591 579 l.setForeground(SystemColor.infoText); 592 580 } 593 public void mouseDragged(MouseEvent e) {581 @Override public void mouseDragged(MouseEvent e) { 594 582 l.setBackground(SystemColor.info); 595 583 l.setForeground(SystemColor.infoText); … … 614 602 615 603 private AWTEventListener awtListener = new AWTEventListener() { 616 public void eventDispatched(AWTEvent event) { 604 @Override 605 public void eventDispatched(AWTEvent event) { 617 606 if (event instanceof InputEvent && 618 607 ((InputEvent)event).getComponent() == mv) { … … 629 618 630 619 private MouseMotionListener mouseMotionListener = new MouseMotionListener() { 620 @Override 631 621 public void mouseMoved(MouseEvent e) { 632 622 synchronized (collector) { … … 637 627 } 638 628 629 @Override 639 630 public void mouseDragged(MouseEvent e) { 640 631 mouseMoved(e); … … 686 677 this.collector = new Collector(mapFrame); 687 678 688 lonText.addMouseListener(Main.main.menu.jumpToAct); 689 latText.addMouseListener(Main.main.menu.jumpToAct); 690 679 // Context menu of status bar 680 setComponentPopupMenu(new JPopupMenu() { 681 JCheckBoxMenuItem doNotHide = new JCheckBoxMenuItem(new AbstractAction(tr("Do not hide status bar")) { 682 @Override public void actionPerformed(ActionEvent e) { 683 boolean sel = ((JCheckBoxMenuItem) e.getSource()).getState(); 684 Main.pref.put("statusbar.always-visible", sel); 685 } 686 }); 687 JMenuItem jumpButton; 688 { 689 jumpButton = add(Main.main.menu.jumpToAct); 690 addPopupMenuListener(new PopupMenuListener() { 691 @Override 692 public void popupMenuWillBecomeVisible(PopupMenuEvent e) { 693 Component invoker = ((JPopupMenu)e.getSource()).getInvoker(); 694 jumpButton.setVisible(invoker == latText || invoker == lonText); 695 doNotHide.setSelected(Main.pref.getBoolean("statusbar.always-visible", true)); 696 } 697 @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {} 698 @Override public void popupMenuCanceled(PopupMenuEvent e) {} 699 }); 700 add(doNotHide); 701 } 702 }); 703 691 704 // Listen for mouse movements and set the position text field 692 705 mv.addMouseMotionListener(new MouseMotionListener(){ 706 @Override 693 707 public void mouseDragged(MouseEvent e) { 694 708 mouseMoved(e); 695 709 } 710 @Override 696 711 public void mouseMoved(MouseEvent e) { 697 712 if (mv.center == null) … … 709 724 setLayout(new GridBagLayout()); 710 725 setBorder(BorderFactory.createEmptyBorder(5,5,5,5)); 726 727 latText.setInheritsPopupMenu(true); 728 lonText.setInheritsPopupMenu(true); 729 headingText.setInheritsPopupMenu(true); 730 //angleText.setInheritsPopupMenu(true); 731 distText.setInheritsPopupMenu(true); 732 nameText.setInheritsPopupMenu(true); 733 //helpText.setInheritsPopupMenu(true); 734 //progressBar.setInheritsPopupMenu(true); 711 735 712 736 add(latText, GBC.std()); … … 745 769 } 746 770 771 @Override 747 772 public String helpTopic() { 748 773 return ht("/Statusline");
Note:
See TracChangeset
for help on using the changeset viewer.