1 | // License: GPL. For details, see LICENSE file.
|
---|
2 | package mergeoverlap.hack;
|
---|
3 |
|
---|
4 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.trc;
|
---|
6 |
|
---|
7 | import java.awt.BorderLayout;
|
---|
8 | import java.awt.FlowLayout;
|
---|
9 | import java.awt.GridBagConstraints;
|
---|
10 | import java.awt.GridBagLayout;
|
---|
11 | import java.awt.Insets;
|
---|
12 | import java.awt.event.ActionEvent;
|
---|
13 | import java.awt.event.FocusAdapter;
|
---|
14 | import java.awt.event.FocusEvent;
|
---|
15 | import java.util.Collection;
|
---|
16 |
|
---|
17 | import javax.swing.AbstractAction;
|
---|
18 | import javax.swing.AbstractButton;
|
---|
19 | import javax.swing.BoxLayout;
|
---|
20 | import javax.swing.ButtonModel;
|
---|
21 | import javax.swing.JButton;
|
---|
22 | import javax.swing.JCheckBox;
|
---|
23 | import javax.swing.JLabel;
|
---|
24 | import javax.swing.JPanel;
|
---|
25 | import javax.swing.JScrollPane;
|
---|
26 | import javax.swing.UIManager;
|
---|
27 | import javax.swing.event.ChangeEvent;
|
---|
28 | import javax.swing.event.ChangeListener;
|
---|
29 |
|
---|
30 | import org.openstreetmap.josm.Main;
|
---|
31 | import org.openstreetmap.josm.command.ChangePropertyCommand;
|
---|
32 | import org.openstreetmap.josm.command.Command;
|
---|
33 | import org.openstreetmap.josm.data.osm.OsmPrimitive;
|
---|
34 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField;
|
---|
35 | import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionList;
|
---|
36 | import org.openstreetmap.josm.gui.widgets.JMultilineLabel;
|
---|
37 | import org.openstreetmap.josm.tools.ImageProvider;
|
---|
38 |
|
---|
39 | public class MyRelationMemberConflictResolver extends JPanel {
|
---|
40 |
|
---|
41 | private AutoCompletingTextField tfRole;
|
---|
42 | private AutoCompletingTextField tfKey;
|
---|
43 | private AutoCompletingTextField tfValue;
|
---|
44 | private JCheckBox cbTagRelations;
|
---|
45 | private MyRelationMemberConflictResolverModel model;
|
---|
46 | private MyRelationMemberConflictResolverTable tblResolver;
|
---|
47 | private JMultilineLabel lblHeader;
|
---|
48 |
|
---|
49 | protected void build() {
|
---|
50 | setLayout(new GridBagLayout());
|
---|
51 | JPanel pnl = new JPanel();
|
---|
52 | pnl.setLayout(new BorderLayout());
|
---|
53 | pnl.add(lblHeader = new JMultilineLabel(""));
|
---|
54 | GridBagConstraints gc = new GridBagConstraints();
|
---|
55 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
56 | gc.weighty = 0.0;
|
---|
57 | gc.weightx = 1.0;
|
---|
58 | gc.insets = new Insets(5,5,5,5);
|
---|
59 | add(pnl, gc);
|
---|
60 | model = new MyRelationMemberConflictResolverModel();
|
---|
61 |
|
---|
62 | gc.gridy = 1;
|
---|
63 | gc.weighty = 1.0;
|
---|
64 | gc.fill = GridBagConstraints.BOTH;
|
---|
65 | gc.insets = new Insets(0,0,0,0);
|
---|
66 | add(new JScrollPane(tblResolver = new MyRelationMemberConflictResolverTable(model)), gc);
|
---|
67 | pnl = new JPanel();
|
---|
68 | pnl.setLayout(new BoxLayout(pnl, BoxLayout.Y_AXIS));
|
---|
69 | pnl.add(buildRoleEditingPanel());
|
---|
70 | pnl.add(buildTagRelationsPanel());
|
---|
71 | gc.gridy = 2;
|
---|
72 | gc.weighty = 0.0;
|
---|
73 | gc.fill = GridBagConstraints.HORIZONTAL;
|
---|
74 | add(pnl,gc);
|
---|
75 | }
|
---|
76 |
|
---|
77 | protected JPanel buildRoleEditingPanel() {
|
---|
78 | JPanel pnl = new JPanel();
|
---|
79 | pnl.setLayout(new FlowLayout(FlowLayout.LEFT));
|
---|
80 | pnl.add(new JLabel(tr("Role:")));
|
---|
81 | pnl.add(tfRole = new AutoCompletingTextField(10));
|
---|
82 | tfRole.setToolTipText(tr("Enter a role for all relation memberships"));
|
---|
83 | pnl.add(new JButton(new ApplyRoleAction()));
|
---|
84 | tfRole.addActionListener(new ApplyRoleAction());
|
---|
85 | tfRole.addFocusListener(
|
---|
86 | new FocusAdapter() {
|
---|
87 | @Override
|
---|
88 | public void focusGained(FocusEvent e) {
|
---|
89 | tfRole.selectAll();
|
---|
90 | }
|
---|
91 | }
|
---|
92 | );
|
---|
93 | return pnl;
|
---|
94 | }
|
---|
95 |
|
---|
96 | protected JPanel buildTagRelationsPanel() {
|
---|
97 | JPanel pnl = new JPanel();
|
---|
98 | pnl.setLayout(new FlowLayout(FlowLayout.LEFT));
|
---|
99 | cbTagRelations = new JCheckBox(tr("Tag modified relations with "));
|
---|
100 | cbTagRelations.addChangeListener(new ToggleTagRelationsAction());
|
---|
101 | cbTagRelations.setToolTipText(
|
---|
102 | tr("<html>Select to enable entering a tag which will be applied<br>"
|
---|
103 | + "to all modified relations.</html>"));
|
---|
104 | pnl.add(cbTagRelations);
|
---|
105 | pnl.add(new JLabel(trc("tag", "Key:")));
|
---|
106 | pnl.add(tfKey = new AutoCompletingTextField(10));
|
---|
107 | tfKey.setToolTipText(tr("<html>Enter a tag key, i.e. <strong><tt>fixme</tt></strong></html>"));
|
---|
108 | pnl.add(new JLabel(tr("Value:")));
|
---|
109 | pnl.add(tfValue = new AutoCompletingTextField(10));
|
---|
110 | tfValue.setToolTipText(tr("<html>Enter a tag value, i.e. <strong><tt>check members</tt></strong></html>"));
|
---|
111 | cbTagRelations.setSelected(false);
|
---|
112 | tfKey.setEnabled(false);
|
---|
113 | tfValue.setEnabled(false);
|
---|
114 | return pnl;
|
---|
115 | }
|
---|
116 |
|
---|
117 | public MyRelationMemberConflictResolver() {
|
---|
118 | build();
|
---|
119 | }
|
---|
120 |
|
---|
121 | public void initForWayCombining() {
|
---|
122 | lblHeader.setText(tr("<html>The combined ways are members in one ore more relations. "
|
---|
123 | + "Please decide whether you want to <strong>keep</strong> these memberships "
|
---|
124 | + "for the combined way or whether you want to <strong>remove</strong> them.<br>"
|
---|
125 | + "The default is to <strong>keep</strong> the first way and <strong>remove</strong> "
|
---|
126 | + "the other ways that are members of the same relation: the combined way will "
|
---|
127 | + "take the place of the original way in the relation."
|
---|
128 | + "</html>"));
|
---|
129 | invalidate();
|
---|
130 | }
|
---|
131 |
|
---|
132 | public void initForNodeMerging() {
|
---|
133 | lblHeader.setText(tr("<html>The merged nodes are members in one ore more relations. "
|
---|
134 | + "Please decide whether you want to <strong>keep</strong> these memberships "
|
---|
135 | + "for the target node or whether you want to <strong>remove</strong> them.<br>"
|
---|
136 | + "The default is to <strong>keep</strong> the first node and <strong>remove</strong> "
|
---|
137 | + "the other nodes that are members of the same relation: the target node will "
|
---|
138 | + "take the place of the original node in the relation."
|
---|
139 | + "</html>"));
|
---|
140 | invalidate();
|
---|
141 | }
|
---|
142 |
|
---|
143 | class ApplyRoleAction extends AbstractAction {
|
---|
144 | public ApplyRoleAction() {
|
---|
145 | putValue(NAME, tr("Apply"));
|
---|
146 | putValue(SMALL_ICON, ImageProvider.get("ok"));
|
---|
147 | putValue(SHORT_DESCRIPTION, tr("Apply this role to all members"));
|
---|
148 | }
|
---|
149 |
|
---|
150 | @Override
|
---|
151 | public void actionPerformed(ActionEvent e) {
|
---|
152 | model.applyRole(tfRole.getText());
|
---|
153 | }
|
---|
154 | }
|
---|
155 |
|
---|
156 | class ToggleTagRelationsAction implements ChangeListener {
|
---|
157 | @Override
|
---|
158 | public void stateChanged(ChangeEvent e) {
|
---|
159 | ButtonModel buttonModel = ((AbstractButton) e.getSource()).getModel();
|
---|
160 | tfKey.setEnabled(buttonModel.isSelected());
|
---|
161 | tfValue.setEnabled(buttonModel.isSelected());
|
---|
162 | tfKey.setBackground(buttonModel.isSelected() ? UIManager.getColor("TextField.background") : UIManager
|
---|
163 | .getColor("Panel.background"));
|
---|
164 | tfValue.setBackground(buttonModel.isSelected() ? UIManager.getColor("TextField.background") : UIManager
|
---|
165 | .getColor("Panel.background"));
|
---|
166 | }
|
---|
167 | }
|
---|
168 |
|
---|
169 | public MyRelationMemberConflictResolverModel getModel() {
|
---|
170 | return model;
|
---|
171 | }
|
---|
172 |
|
---|
173 | public Command buildTagApplyCommands(Collection<? extends OsmPrimitive> primitives) {
|
---|
174 | if (!cbTagRelations.isSelected())
|
---|
175 | return null;
|
---|
176 | if (tfKey.getText().trim().equals(""))
|
---|
177 | return null;
|
---|
178 | if (tfValue.getText().trim().equals(""))
|
---|
179 | return null;
|
---|
180 | if (primitives == null || primitives.isEmpty())
|
---|
181 | return null;
|
---|
182 | return new ChangePropertyCommand(primitives, tfKey.getText(), tfValue.getText());
|
---|
183 | }
|
---|
184 |
|
---|
185 | public void prepareForEditing() {
|
---|
186 | AutoCompletionList acList = new AutoCompletionList();
|
---|
187 | Main.main.getEditLayer().data.getAutoCompletionManager().populateWithMemberRoles(acList);
|
---|
188 | tfRole.setAutoCompletionList(acList);
|
---|
189 | AutoCompletingTextField editor = (AutoCompletingTextField) tblResolver.getColumnModel().getColumn(2).getCellEditor();
|
---|
190 | if (editor != null) {
|
---|
191 | editor.setAutoCompletionList(acList);
|
---|
192 | }
|
---|
193 | AutoCompletionList acList2 = new AutoCompletionList();
|
---|
194 | Main.main.getEditLayer().data.getAutoCompletionManager().populateWithKeys(acList2);
|
---|
195 | tfKey.setAutoCompletionList(acList2);
|
---|
196 | }
|
---|
197 | }
|
---|