source: josm/trunk/src/org/openstreetmap/josm/gui/preferences/imagery/CommonSettingsPanel.java@ 9414

Last change on this file since 9414 was 8861, checked in by wiktorn, 9 years ago

Remove MEMORY_SIZE based settings and fix high cpu usage when showing low-zoom
tiles.

  • Remove MEMORY_SIZE settings from common imagery settings panel.
  • When working with low-zoom high CPU might occured. This happend, because

border tiles were not added to MemoryTileCache. Now this is fixed

  • Property svn:eol-style set to native
File size: 5.9 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.preferences.imagery;
3
4import static org.openstreetmap.josm.tools.I18n.tr;
5
6import java.awt.Color;
7import java.awt.GridBagLayout;
8import java.awt.event.ActionEvent;
9import java.awt.event.ActionListener;
10
11import javax.swing.JButton;
12import javax.swing.JColorChooser;
13import javax.swing.JLabel;
14import javax.swing.JOptionPane;
15import javax.swing.JPanel;
16import javax.swing.JSlider;
17import javax.swing.JSpinner;
18import javax.swing.SpinnerNumberModel;
19
20import org.openstreetmap.josm.data.imagery.CachedTileLoaderFactory;
21import org.openstreetmap.josm.gui.layer.AbstractCachedTileSourceLayer;
22import org.openstreetmap.josm.gui.layer.AbstractTileSourceLayer;
23import org.openstreetmap.josm.gui.layer.ImageryLayer;
24import org.openstreetmap.josm.gui.widgets.JosmComboBox;
25import org.openstreetmap.josm.gui.widgets.JosmTextField;
26import org.openstreetmap.josm.tools.ColorHelper;
27import org.openstreetmap.josm.tools.GBC;
28
29/**
30 * {@code JPanel} giving access to common imagery settings.
31 * @since 5465
32 */
33public class CommonSettingsPanel extends JPanel {
34
35 // Common Settings
36 private final JButton btnFadeColor;
37 private final JSlider fadeAmount = new JSlider(0, 100);
38 private final JosmComboBox<String> sharpen;
39 private final JosmTextField tilecacheDir = new JosmTextField();
40 private final JSpinner maxElementsOnDisk;
41 private final JSlider tilesZoom = new JSlider(-2, 2, 0);
42
43
44 /**
45 * Constructs a new {@code CommonSettingsPanel}.
46 */
47 public CommonSettingsPanel() {
48 super(new GridBagLayout());
49
50 this.maxElementsOnDisk = new JSpinner(new SpinnerNumberModel(
51 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().intValue(), 0, Integer.MAX_VALUE, 1));
52
53
54 this.btnFadeColor = new JButton();
55
56 this.btnFadeColor.addActionListener(new ActionListener() {
57 @Override
58 public void actionPerformed(ActionEvent e) {
59 JColorChooser chooser = new JColorChooser(btnFadeColor.getBackground());
60 int answer = JOptionPane.showConfirmDialog(
61 CommonSettingsPanel.this, chooser,
62 tr("Choose a color for {0}", tr("imagery fade")),
63 JOptionPane.OK_CANCEL_OPTION,
64 JOptionPane.PLAIN_MESSAGE);
65 if (answer == JOptionPane.OK_OPTION) {
66 Color colFadeColor = chooser.getColor();
67 btnFadeColor.setBackground(colFadeColor);
68 btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
69 }
70 }
71 });
72
73 add(new JLabel(tr("Fade Color: ")), GBC.std());
74 add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
75 add(this.btnFadeColor, GBC.eol().fill(GBC.HORIZONTAL));
76
77 add(new JLabel(tr("Fade amount: ")), GBC.std());
78 add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
79 add(this.fadeAmount, GBC.eol().fill(GBC.HORIZONTAL));
80
81 this.sharpen = new JosmComboBox<>(new String[] {
82 tr("None"),
83 tr("Soft"),
84 tr("Strong")});
85 add(new JLabel(tr("Sharpen (requires layer re-add): ")));
86 add(GBC.glue(5, 0), GBC.std().fill(GBC.HORIZONTAL));
87 add(this.sharpen, GBC.eol().fill(GBC.HORIZONTAL));
88
89 add(new JLabel(tr("Tile cache directory: ")), GBC.std());
90 add(GBC.glue(5, 0), GBC.std());
91 add(tilecacheDir, GBC.eol().fill(GBC.HORIZONTAL));
92
93 add(new JLabel(tr("Maximum size of disk cache (per imagery) in MB: ")), GBC.std());
94 add(GBC.glue(5, 0), GBC.std());
95 add(this.maxElementsOnDisk, GBC.eol());
96
97 this.tilesZoom.setPaintLabels(true);
98 this.tilesZoom.setMajorTickSpacing(2);
99 this.tilesZoom.setMinorTickSpacing(1);
100 this.tilesZoom.setPaintTicks(true);
101 add(new JLabel(tr("Tiles zoom offset:")));
102 add(GBC.glue(5, 0), GBC.std());
103 add(this.tilesZoom, GBC.eol());
104 }
105
106 /**
107 * Loads the common settings.
108 */
109 public void loadSettings() {
110 Color colFadeColor = ImageryLayer.PROP_FADE_COLOR.get();
111 this.btnFadeColor.setBackground(colFadeColor);
112 this.btnFadeColor.setText(ColorHelper.color2html(colFadeColor));
113 this.fadeAmount.setValue(ImageryLayer.PROP_FADE_AMOUNT.get());
114 this.sharpen.setSelectedIndex(Math.max(0, Math.min(2, ImageryLayer.PROP_SHARPEN_LEVEL.get())));
115 this.tilecacheDir.setText(CachedTileLoaderFactory.PROP_TILECACHE_DIR.get());
116 this.maxElementsOnDisk.setValue(AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get());
117 this.tilesZoom.setValue(AbstractTileSourceLayer.ZOOM_OFFSET.get());
118 }
119
120 /**
121 * Saves the common settings.
122 * @return true when restart is required
123 */
124 public boolean saveSettings() {
125 ImageryLayer.PROP_FADE_AMOUNT.put(this.fadeAmount.getValue());
126 ImageryLayer.PROP_FADE_COLOR.put(this.btnFadeColor.getBackground());
127 ImageryLayer.PROP_SHARPEN_LEVEL.put(sharpen.getSelectedIndex());
128
129 boolean restartRequired = false;
130 if (!AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.get().equals(this.maxElementsOnDisk.getValue())) {
131 AbstractCachedTileSourceLayer.MAX_DISK_CACHE_SIZE.put((Integer) this.maxElementsOnDisk.getValue());
132 restartRequired = true;
133 }
134
135
136 if (!CachedTileLoaderFactory.PROP_TILECACHE_DIR.get().equals(this.tilecacheDir.getText())) {
137 restartRequired = true;
138 CachedTileLoaderFactory.PROP_TILECACHE_DIR.put(this.tilecacheDir.getText());
139 }
140
141 if (!AbstractTileSourceLayer.ZOOM_OFFSET.get().equals(this.tilesZoom.getValue())) {
142 // TODO: make warning about too small MEMORY_CACHE_SIZE?
143 AbstractTileSourceLayer.ZOOM_OFFSET.put(this.tilesZoom.getValue());
144 restartRequired = true;
145 }
146 return restartRequired;
147 }
148}
Note: See TracBrowser for help on using the repository browser.