kopia lustrzana https://github.com/JOSM/MapWithAI
Carry status of sources between download and preferences panel
Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
c5cb23a17b
commit
7fab30e4d0
|
@ -14,7 +14,6 @@ import org.openstreetmap.josm.data.Bounds;
|
||||||
import org.openstreetmap.josm.gui.bbox.BBoxChooser;
|
import org.openstreetmap.josm.gui.bbox.BBoxChooser;
|
||||||
import org.openstreetmap.josm.gui.download.DownloadDialog;
|
import org.openstreetmap.josm.gui.download.DownloadDialog;
|
||||||
import org.openstreetmap.josm.gui.download.DownloadSelection;
|
import org.openstreetmap.josm.gui.download.DownloadSelection;
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
|
|
||||||
import org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai.MapWithAIProvidersPanel;
|
import org.openstreetmap.josm.plugins.mapwithai.gui.preferences.mapwithai.MapWithAIProvidersPanel;
|
||||||
import org.openstreetmap.josm.tools.Destroyable;
|
import org.openstreetmap.josm.tools.Destroyable;
|
||||||
import org.openstreetmap.josm.tools.GBC;
|
import org.openstreetmap.josm.tools.GBC;
|
||||||
|
@ -34,7 +33,7 @@ public class MapWithAIDownloadOptions extends JPanel implements DownloadSelectio
|
||||||
JPanel infoHeader = new JPanel();
|
JPanel infoHeader = new JPanel();
|
||||||
infoHeader.add(new JLabel("Browse and download extra data sets to facilitate your mapping needs."));
|
infoHeader.add(new JLabel("Browse and download extra data sets to facilitate your mapping needs."));
|
||||||
optionPanel.add(infoHeader, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH));
|
optionPanel.add(infoHeader, GBC.eol().fill(GBC.HORIZONTAL).anchor(GBC.NORTH));
|
||||||
mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this, MapWithAILayerInfo.getInstance(), false);
|
mapwithaiProvidersPanel = new MapWithAIProvidersPanel(this);
|
||||||
optionPanel.add(mapwithaiProvidersPanel, GBC.eol().fill(GBC.BOTH).anchor(GBC.CENTER));
|
optionPanel.add(mapwithaiProvidersPanel, GBC.eol().fill(GBC.BOTH).anchor(GBC.CENTER));
|
||||||
mapwithaiProvidersPanel.defaultMap.addPropertyChangeListener(this);
|
mapwithaiProvidersPanel.defaultMap.addPropertyChangeListener(this);
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,7 +47,6 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting {
|
||||||
private final JSpinner maximumAdditionSpinner;
|
private final JSpinner maximumAdditionSpinner;
|
||||||
private final ReplacementPreferenceTable replacementPreferenceTable;
|
private final ReplacementPreferenceTable replacementPreferenceTable;
|
||||||
private final List<PrefEntry> replacementTableDisplayData;
|
private final List<PrefEntry> replacementTableDisplayData;
|
||||||
private MapWithAILayerInfo info;
|
|
||||||
private static final int MAX_SELECTED_TO_EDIT = 1;
|
private static final int MAX_SELECTED_TO_EDIT = 1;
|
||||||
|
|
||||||
public MapWithAIPreferences() {
|
public MapWithAIPreferences() {
|
||||||
|
@ -82,8 +81,7 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting {
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component getServerList(PreferenceTabbedPane gui) {
|
private Component getServerList(PreferenceTabbedPane gui) {
|
||||||
info = new MapWithAILayerInfo(MapWithAILayerInfo.instance);
|
return new MapWithAIProvidersPanel(gui, MapWithAIProvidersPanel.Options.SHOW_ACTIVE);
|
||||||
return new MapWithAIProvidersPanel(gui, info, true);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Component getSettingsPanel(PreferenceTabbedPane gui) {
|
private Component getSettingsPanel(PreferenceTabbedPane gui) {
|
||||||
|
@ -207,9 +205,9 @@ public class MapWithAIPreferences extends DefaultTabPreferenceSetting {
|
||||||
if (value instanceof Number) {
|
if (value instanceof Number) {
|
||||||
MapWithAIPreferenceHelper.setMaximumAddition(((Number) value).intValue(), true);
|
MapWithAIPreferenceHelper.setMaximumAddition(((Number) value).intValue(), true);
|
||||||
}
|
}
|
||||||
info.save();
|
MapWithAILayerInfo.getInstance().save();
|
||||||
MapWithAILayerInfo.instance.clear();
|
MapWithAILayerInfo.getInstance().clear();
|
||||||
MapWithAILayerInfo.instance.load(false);
|
MapWithAILayerInfo.getInstance().load(false);
|
||||||
MapWithAIPreferenceHelper.setReplacementTags(convertReplacementPrefToMap(replacementTableDisplayData));
|
MapWithAIPreferenceHelper.setReplacementTags(convertReplacementPrefToMap(replacementTableDisplayData));
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import java.util.function.BiConsumer;
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
import java.util.function.Function;
|
import java.util.function.Function;
|
||||||
import java.util.stream.Collectors;
|
import java.util.stream.Collectors;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
import javax.swing.AbstractAction;
|
import javax.swing.AbstractAction;
|
||||||
import javax.swing.Box;
|
import javax.swing.Box;
|
||||||
|
@ -77,6 +78,11 @@ import org.openstreetmap.josm.tools.Logging;
|
||||||
* @since 15115 (extracted from ImageryPreferences)
|
* @since 15115 (extracted from ImageryPreferences)
|
||||||
*/
|
*/
|
||||||
public class MapWithAIProvidersPanel extends JPanel {
|
public class MapWithAIProvidersPanel extends JPanel {
|
||||||
|
public enum Options {
|
||||||
|
/** Hide the active table */
|
||||||
|
SHOW_ACTIVE
|
||||||
|
}
|
||||||
|
|
||||||
private static final long serialVersionUID = -5876039771496409422L;
|
private static final long serialVersionUID = -5876039771496409422L;
|
||||||
// Public JTables and JosmMapViewer
|
// Public JTables and JosmMapViewer
|
||||||
/** The table of active providers **/
|
/** The table of active providers **/
|
||||||
|
@ -97,9 +103,11 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
|
|
||||||
// Public models
|
// Public models
|
||||||
/** The model of active providers **/
|
/** The model of active providers **/
|
||||||
public final MapWithAILayerTableModel activeModel;
|
private static final MapWithAILayerTableModel ACTIVE_MODEL = new MapWithAILayerTableModel();
|
||||||
|
public final MapWithAILayerTableModel activeModel = ACTIVE_MODEL;
|
||||||
/** The model of default providers **/
|
/** The model of default providers **/
|
||||||
public final MapWithAIDefaultLayerTableModel defaultModel;
|
private static final MapWithAIDefaultLayerTableModel DEFAULT_MODEL = new MapWithAIDefaultLayerTableModel();
|
||||||
|
public final MapWithAIDefaultLayerTableModel defaultModel = DEFAULT_MODEL;
|
||||||
|
|
||||||
// Public JToolbars
|
// Public JToolbars
|
||||||
/** The toolbar on the right of active providers **/
|
/** The toolbar on the right of active providers **/
|
||||||
|
@ -111,8 +119,9 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
|
|
||||||
// Private members
|
// Private members
|
||||||
private final JComponent gui;
|
private final JComponent gui;
|
||||||
private final transient MapWithAILayerInfo layerInfo;
|
|
||||||
private final transient ListenerList<AreaListener> areaListeners = ListenerList.create();
|
private final transient ListenerList<AreaListener> areaListeners = ListenerList.create();
|
||||||
|
/** Options that were passed to the constructor */
|
||||||
|
private final Options[] options;
|
||||||
|
|
||||||
private interface AreaListener {
|
private interface AreaListener {
|
||||||
void updateArea(Bounds area);
|
void updateArea(Bounds area);
|
||||||
|
@ -267,14 +276,13 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
* Constructs a new {@code MapWithAIProvidersPanel}.
|
* Constructs a new {@code MapWithAIProvidersPanel}.
|
||||||
*
|
*
|
||||||
* @param gui The parent preference tab pane
|
* @param gui The parent preference tab pane
|
||||||
* @param layerInfoArg The list of imagery entries to display
|
* @param options The options for this instance
|
||||||
* @param showActive If true, show selected entries along with custom entries.
|
|
||||||
*/
|
*/
|
||||||
public MapWithAIProvidersPanel(final JComponent gui, MapWithAILayerInfo layerInfoArg, boolean showActive) {
|
public MapWithAIProvidersPanel(final JComponent gui, Options... options) {
|
||||||
super(new GridBagLayout());
|
super(new GridBagLayout());
|
||||||
this.gui = gui;
|
this.gui = gui;
|
||||||
this.layerInfo = layerInfoArg;
|
this.options = options;
|
||||||
this.activeModel = new MapWithAILayerTableModel();
|
boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals);
|
||||||
|
|
||||||
activeTable = new JTable(activeModel) {
|
activeTable = new JTable(activeModel) {
|
||||||
private static final long serialVersionUID = -6136421378119093719L;
|
private static final long serialVersionUID = -6136421378119093719L;
|
||||||
|
@ -292,7 +300,6 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
};
|
};
|
||||||
activeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
activeTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
|
||||||
|
|
||||||
defaultModel = new MapWithAIDefaultLayerTableModel();
|
|
||||||
defaultTable = new JTable(defaultModel);
|
defaultTable = new JTable(defaultModel);
|
||||||
defaultTable.setAutoCreateRowSorter(true);
|
defaultTable.setAutoCreateRowSorter(true);
|
||||||
defaultFilter = new FilterField().filter(defaultTable, defaultModel);
|
defaultFilter = new FilterField().filter(defaultTable, defaultModel);
|
||||||
|
@ -300,7 +307,7 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
defaultModel.addTableModelListener(e -> activeTable.repaint());
|
defaultModel.addTableModelListener(e -> activeTable.repaint());
|
||||||
activeModel.addTableModelListener(e -> defaultTable.repaint());
|
activeModel.addTableModelListener(e -> defaultTable.repaint());
|
||||||
|
|
||||||
setupDefaultTable(this, defaultTable, showActive, areaListeners);
|
setupDefaultTable(this, defaultTable, options, areaListeners);
|
||||||
|
|
||||||
TableColumnModel mod = activeTable.getColumnModel();
|
TableColumnModel mod = activeTable.getColumnModel();
|
||||||
mod.getColumn(1).setPreferredWidth(800);
|
mod.getColumn(1).setPreferredWidth(800);
|
||||||
|
@ -404,8 +411,9 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void setupDefaultTable(MapWithAIProvidersPanel panel, JTable defaultTable, boolean showActive,
|
private static void setupDefaultTable(MapWithAIProvidersPanel panel, JTable defaultTable, Options[] options,
|
||||||
ListenerList<AreaListener> areaListeners) {
|
ListenerList<AreaListener> areaListeners) {
|
||||||
|
boolean showActive = Stream.of(options).anyMatch(Options.SHOW_ACTIVE::equals);
|
||||||
int tenXWidth = defaultTable.getFontMetrics(defaultTable.getFont()).stringWidth("XXXXXXXXXX");
|
int tenXWidth = defaultTable.getFontMetrics(defaultTable.getFont()).stringWidth("XXXXXXXXXX");
|
||||||
TableColumnModel mod = defaultTable.getColumnModel();
|
TableColumnModel mod = defaultTable.getColumnModel();
|
||||||
int urlWidth = (showActive ? 3 : 0) * tenXWidth;
|
int urlWidth = (showActive ? 3 : 0) * tenXWidth;
|
||||||
|
@ -732,6 +740,9 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
.sorted(Collections.reverseOrder()).forEach(activeModel::removeRow);
|
.sorted(Collections.reverseOrder()).forEach(activeModel::removeRow);
|
||||||
}
|
}
|
||||||
updateEnabledState();
|
updateEnabledState();
|
||||||
|
if (Stream.of(options).noneMatch(Options.SHOW_ACTIVE::equals)) {
|
||||||
|
MapWithAILayerInfo.getInstance().save();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -748,7 +759,7 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void actionPerformed(ActionEvent evt) {
|
public void actionPerformed(ActionEvent evt) {
|
||||||
layerInfo.loadDefaults(true, MainApplication.worker, false, () -> {
|
MapWithAILayerInfo.getInstance().loadDefaults(true, MainApplication.worker, false, () -> {
|
||||||
defaultModel.fireTableDataChanged();
|
defaultModel.fireTableDataChanged();
|
||||||
defaultTable.getSelectionModel().clearSelection();
|
defaultTable.getSelectionModel().clearSelection();
|
||||||
defaultTableListener.clearMap();
|
defaultTableListener.clearMap();
|
||||||
|
@ -757,5 +768,4 @@ public class MapWithAIProvidersPanel extends JPanel {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue