source: josm/trunk/src/org/openstreetmap/josm/gui/conflict/tags/RelationMemberConflictResolver.java@ 2726

Last change on this file since 2726 was 2726, checked in by framm, 14 years ago

fix message text

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