Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

「保存」ボタンでProsetsリストが更新されるようにしました #43

Merged
merged 10 commits into from
Jul 21, 2020
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.classpath
.project
.settings/
.externalToolBuilders/
/javadoc/
/build/
14 changes: 10 additions & 4 deletions src/org/maripo/josm/easypresets/EasyPresetsPlugin.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,27 +5,33 @@

import org.maripo.josm.easypresets.data.EasyPresets;
import org.maripo.josm.easypresets.ui.CreatePresetAction;
import org.maripo.josm.easypresets.ui.GroupPresetMenu;
import org.maripo.josm.easypresets.ui.ManagePresetsAction;
import org.openstreetmap.josm.gui.MainApplication;
import org.openstreetmap.josm.gui.MainMenu;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetMenu;
import org.openstreetmap.josm.plugins.Plugin;
import org.openstreetmap.josm.plugins.PluginInformation;

public class EasyPresetsPlugin extends Plugin {
public static EasyPresets presets;
public static GroupPresetMenu groupMenu;

@SuppressWarnings("deprecation")
public EasyPresetsPlugin (PluginInformation info) {
super(info);

presets = EasyPresets.getInstance();
presets.load();

// Add custom presets to "Presets" menu
JMenu menu = MainApplication.getMenu().presetsMenu;
menu.add(new JSeparator());
MainMenu.add(menu, new CreatePresetAction());
MainMenu.add(menu, new ManagePresetsAction());

// Group for all custom presets
TaggingPresetMenu groupMenu = EasyPresets.getInstance().createGroupMenu();
EasyPresets.getInstance().load();
groupMenu = new GroupPresetMenu();
groupMenu.updatePresetListMenu(presets);
menu.add(groupMenu.menu);
}

}
109 changes: 109 additions & 0 deletions src/org/maripo/josm/easypresets/data/EasyPreset.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,109 @@
package org.maripo.josm.easypresets.data;

import static org.openstreetmap.josm.tools.I18n.tr;

import java.util.EnumSet;

import org.openstreetmap.josm.gui.tagging.presets.TaggingPreset;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetItem;
import org.openstreetmap.josm.gui.tagging.presets.TaggingPresetType;
import org.openstreetmap.josm.gui.tagging.presets.items.Check;
import org.openstreetmap.josm.gui.tagging.presets.items.Combo;
import org.openstreetmap.josm.gui.tagging.presets.items.Key;
import org.openstreetmap.josm.gui.tagging.presets.items.Label;
import org.openstreetmap.josm.gui.tagging.presets.items.Link;
import org.openstreetmap.josm.gui.tagging.presets.items.MultiSelect;
import org.openstreetmap.josm.gui.tagging.presets.items.Text;

public class EasyPreset extends TaggingPreset implements Cloneable {
private static final long serialVersionUID = -7626914563011340418L;

public EasyPreset() {
super();
}

public static EasyPreset copy(TaggingPreset src) {
EasyPreset preset = EasyPreset.clone(src);
preset.name = tr("Copy of {0}", src.name);
return preset;
}

public static EasyPreset getInstance(TaggingPreset src) {
return EasyPreset.clone(src);
}

@Override
public EasyPreset clone() {
return EasyPreset.clone(this);
}

public static EasyPreset clone(TaggingPreset src) {
EasyPreset preset = new EasyPreset();
preset.name = src.name;
preset.setIcon(src.iconName);
for (TaggingPresetItem fromItem: src.data) {
TaggingPresetItem item = clonePresetTag(fromItem);
if (item != null) {
preset.data.add(item);
}
}
preset.types = EnumSet.noneOf(TaggingPresetType.class);
if (src.types != null) {
preset.types.addAll(src.types);
}
return preset;
}

private static TaggingPresetItem clonePresetTag(TaggingPresetItem itemFrom) {
if (itemFrom instanceof Label) {
Label itemTo = new Label();
itemTo.text = ((Label) itemFrom).text;
return itemTo;
}
else if (itemFrom instanceof Key) {
Key key = (Key) itemFrom;
Key itemTo = new Key();
itemTo.key = key.key;
itemTo.value = key.value;
return itemTo;
}
else if (itemFrom instanceof Text) {
Text text = (Text)itemFrom;
Text itemTo = new Text();
itemTo.text = text.text;
itemTo.key = text.key;
itemTo.default_ = text.default_;
return itemTo;
}
else if (itemFrom instanceof Combo) {
Combo combo = (Combo)itemFrom;
Combo itemTo = new Combo();
itemTo.text = combo.text;
itemTo.key = combo.key;
itemTo.values = combo.values;
return itemTo;
}
else if (itemFrom instanceof MultiSelect) {
MultiSelect multiselect = (MultiSelect)itemFrom;
MultiSelect itemTo = new MultiSelect();
itemTo.text = multiselect.text;
itemTo.key = multiselect.key;
itemTo.values = multiselect.values;
return itemTo;
}
else if (itemFrom instanceof Check) {
Check key = (Check) itemFrom;
Check itemTo = new Check();
itemTo.text = key.text;
itemTo.key = key.key;
return itemTo;
}
else if (itemFrom instanceof Link) {
Link link = (Link)itemFrom;
Link itemTo = new Link();
itemTo.href = link.href;
return itemTo;
}
return null;
}
}
Loading