Changeset 1742 in josm
- Timestamp:
- 2009-07-07T09:04:00+02:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 19 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/PreferencesAction.java
r1733 r1742 79 79 if (pane.getValue() instanceof Integer && (Integer)pane.getValue() == JOptionPane.OK_OPTION) 80 80 prefDlg.ok(); 81 dlg.dispose(); 81 82 } 82 83 } -
trunk/src/org/openstreetmap/josm/gui/preferences/AdvancedPreference.java
r1729 r1742 33 33 34 34 public class AdvancedPreference implements PreferenceSetting { 35 36 public static class Factory implements PreferenceSettingFactory { 37 public PreferenceSetting createPreferenceSetting() { 38 return new AdvancedPreference(); 39 } 40 } 35 41 36 42 private Map<String,String> orig; -
trunk/src/org/openstreetmap/josm/gui/preferences/AudioPreference.java
r1572 r1742 24 24 25 25 public class AudioPreference implements PreferenceSetting { 26 27 public static class Factory implements PreferenceSettingFactory { 28 public PreferenceSetting createPreferenceSetting() { 29 return new AudioPreference(); 30 } 31 } 32 26 33 private JCheckBox audioMenuVisible = new JCheckBox(tr("Display the Audio menu.")); 27 34 private JCheckBox markerButtonLabels = new JCheckBox(tr("Label audio (and image and web) markers.")); -
trunk/src/org/openstreetmap/josm/gui/preferences/ColorPreference.java
r1505 r1742 10 10 import java.awt.event.ActionEvent; 11 11 import java.awt.event.ActionListener; 12 import java.util.regex.Matcher;13 import java.util.regex.Pattern;14 12 import java.util.ArrayList; 15 13 import java.util.HashMap; 16 14 import java.util.Map; 17 import java.util.Map.Entry;18 15 import java.util.TreeMap; 19 16 import java.util.Vector; 20 17 import java.util.Map.Entry; 18 import java.util.regex.Matcher; 19 import java.util.regex.Pattern; 20 21 import javax.swing.BorderFactory; 21 22 import javax.swing.Box; 22 23 import javax.swing.JButton; … … 31 32 import javax.swing.table.DefaultTableModel; 32 33 import javax.swing.table.TableCellRenderer; 33 import javax.swing.BorderFactory;34 34 35 35 import org.openstreetmap.josm.Main; 36 36 import org.openstreetmap.josm.data.osm.visitor.MapPaintVisitor; 37 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer;38 37 import org.openstreetmap.josm.gui.MapScaler; 39 38 import org.openstreetmap.josm.gui.dialogs.ConflictDialog; 39 import org.openstreetmap.josm.gui.layer.markerlayer.MarkerLayer; 40 40 import org.openstreetmap.josm.tools.ColorHelper; 41 41 import org.openstreetmap.josm.tools.GBC; 42 42 43 43 public class ColorPreference implements PreferenceSetting { 44 45 public static class Factory implements PreferenceSettingFactory { 46 public PreferenceSetting createPreferenceSetting() { 47 return new ColorPreference(); 48 } 49 } 50 44 51 45 52 private DefaultTableModel tableModel; -
trunk/src/org/openstreetmap/josm/gui/preferences/DrawingPreference.java
r1577 r1742 5 5 6 6 import java.awt.Dimension; 7 import java.awt.GridBagLayout; 7 8 import java.awt.event.ActionEvent; 8 9 import java.awt.event.ActionListener; 9 import java.awt.GridBagLayout;10 10 11 11 import javax.swing.BorderFactory; 12 import javax.swing.Box; 12 13 import javax.swing.ButtonGroup; 13 14 import javax.swing.JCheckBox; 14 15 import javax.swing.JComboBox; 15 16 import javax.swing.JLabel; 17 import javax.swing.JPanel; 16 18 import javax.swing.JRadioButton; 19 import javax.swing.JScrollPane; 17 20 import javax.swing.JTextField; 18 import javax.swing.JScrollPane;19 import javax.swing.JPanel;20 import javax.swing.Box;21 21 import javax.swing.event.ChangeEvent; 22 22 import javax.swing.event.ChangeListener; … … 26 26 27 27 public class DrawingPreference implements PreferenceSetting { 28 29 public static class Factory implements PreferenceSettingFactory { 30 public PreferenceSetting createPreferenceSetting() { 31 return new DrawingPreference(); 32 } 33 } 28 34 29 35 private ButtonGroup gpsLinesGroup; -
trunk/src/org/openstreetmap/josm/gui/preferences/FilePreferences.java
r1180 r1742 19 19 public class FilePreferences implements PreferenceSetting { 20 20 21 public static class Factory implements PreferenceSettingFactory { 22 public PreferenceSetting createPreferenceSetting() { 23 return new FilePreferences(); 24 } 25 } 26 21 27 private JCheckBox keepBackup = new JCheckBox(tr("Keep backup files")); 22 28 -
trunk/src/org/openstreetmap/josm/gui/preferences/LafPreference.java
r1405 r1742 24 24 25 25 public class LafPreference implements PreferenceSetting { 26 27 public static class Factory implements PreferenceSettingFactory { 28 public PreferenceSetting createPreferenceSetting() { 29 return new LafPreference(); 30 } 31 } 26 32 27 33 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/LanguagePreference.java
r1415 r1742 20 20 21 21 public class LanguagePreference implements PreferenceSetting { 22 23 public static class Factory implements PreferenceSettingFactory { 24 public PreferenceSetting createPreferenceSetting() { 25 return new LanguagePreference(); 26 } 27 } 28 22 29 /** 23 30 * ComboBox with all available Translations … … 54 61 }); 55 62 56 JPanel panel = null; 57 for(PreferenceSetting s : PreferenceDialog.settings) 58 { 59 if(s instanceof LafPreference) 60 panel = ((LafPreference)s).panel; 61 } 63 LafPreference lafPreference = gui.getSetting(LafPreference.class); 64 JPanel panel = lafPreference.panel; 62 65 panel.add(new JLabel(tr("Language")), GBC.std().insets(20, 0, 0, 0)); 63 66 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); -
trunk/src/org/openstreetmap/josm/gui/preferences/MapPaintPreference.java
r1180 r1742 5 5 6 6 public class MapPaintPreference implements PreferenceSetting { 7 8 public static class Factory implements PreferenceSettingFactory { 9 public PreferenceSetting createPreferenceSetting() { 10 return new MapPaintPreference(); 11 } 12 } 7 13 8 14 public void addGui(final PreferenceDialog gui) { -
trunk/src/org/openstreetmap/josm/gui/preferences/PluginPreference.java
r1648 r1742 27 27 28 28 public class PluginPreference implements PreferenceSetting { 29 30 public static class Factory implements PreferenceSettingFactory { 31 public PreferenceSetting createPreferenceSetting() { 32 return new PluginPreference(); 33 } 34 } 29 35 30 36 private JPanel plugin; … … 117 123 } 118 124 119 class NoHorizontalScrollPanel extends JPanel implements Scrollable {125 private static class NoHorizontalScrollPanel extends JPanel implements Scrollable { 120 126 public NoHorizontalScrollPanel(GridBagLayout gridBagLayout) { 121 127 super(gridBagLayout); -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r1415 r1742 7 7 import java.awt.GridBagLayout; 8 8 import java.awt.ScrollPane; 9 import java.util.ArrayList; 9 10 import java.util.Collection; 10 11 import java.util.Iterator; 11 12 import java.util.LinkedList; 13 import java.util.List; 12 14 13 15 import javax.swing.BorderFactory; … … 33 35 public class PreferenceDialog extends JTabbedPane { 34 36 35 public final static Collection<PreferenceSetting> settings = new LinkedList<PreferenceSetting>(); 37 private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>(); 38 private final List<PreferenceSetting> settings = new ArrayList<PreferenceSetting>(); 36 39 37 40 // some common tabs … … 41 44 public final JPanel audio = createPreferenceTab("audio", I18n.tr("Audio Settings"), I18n.tr("Settings for the audio player and audio markers.")); 42 45 43 public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane();46 public final javax.swing.JTabbedPane displaycontent = new javax.swing.JTabbedPane(); 44 47 45 48 /** … … 105 108 public PreferenceDialog() { 106 109 super(JTabbedPane.LEFT, JTabbedPane.SCROLL_TAB_LAYOUT); 110 111 for (PreferenceSettingFactory factory:settingsFactory) { 112 113 PreferenceSetting setting = factory.createPreferenceSetting(); 114 if (setting != null) { 115 settings.add(factory.createPreferenceSetting()); 116 } 117 } 118 107 119 display.add(displaycontent, GBC.eol().fill(GBC.BOTH)); 108 120 for (Iterator<PreferenceSetting> it = settings.iterator(); it.hasNext();) { … … 118 130 } 119 131 132 public List<PreferenceSetting> getSettings() { 133 return settings; 134 } 135 136 @SuppressWarnings("unchecked") 137 public <T> T getSetting(Class<? extends T> clazz) { 138 for (PreferenceSetting setting:settings) { 139 if (clazz.isAssignableFrom(setting.getClass())) { 140 return (T)setting; 141 } 142 } 143 return null; 144 } 145 120 146 static { 121 147 // order is important! 122 settings .add(new DrawingPreference());123 settings .add(new ColorPreference());124 settings .add(new LafPreference());125 settings .add(new LanguagePreference());126 settings .add(new MapPaintPreference());127 settings .add(new ServerAccessPreference());128 settings .add(new FilePreferences());129 settings .add(new ProxyPreferences());130 settings .add(new ProjectionPreference());131 settings .add(new TaggingPresetPreference());132 settings .add(new PluginPreference());133 settings .add(Main.toolbar);134 settings .add(new AudioPreference());135 settings .add(new ShortcutPreference());148 settingsFactory.add(new DrawingPreference.Factory()); 149 settingsFactory.add(new ColorPreference.Factory()); 150 settingsFactory.add(new LafPreference.Factory()); 151 settingsFactory.add(new LanguagePreference.Factory()); 152 settingsFactory.add(new MapPaintPreference.Factory()); 153 settingsFactory.add(new ServerAccessPreference.Factory()); 154 settingsFactory.add(new FilePreferences.Factory()); 155 settingsFactory.add(new ProxyPreferences.Factory()); 156 settingsFactory.add(new ProjectionPreference.Factory()); 157 settingsFactory.add(new TaggingPresetPreference.Factory()); 158 settingsFactory.add(new PluginPreference.Factory()); 159 settingsFactory.add(Main.toolbar); 160 settingsFactory.add(new AudioPreference.Factory()); 161 settingsFactory.add(new ShortcutPreference.Factory()); 136 162 137 PluginHandler.getPreferenceSetting(settings );163 PluginHandler.getPreferenceSetting(settingsFactory); 138 164 139 165 // always the last: advanced tab 140 settings .add(new AdvancedPreference());166 settingsFactory.add(new AdvancedPreference.Factory()); 141 167 } 142 168 } -
trunk/src/org/openstreetmap/josm/gui/preferences/ProjectionPreference.java
r1722 r1742 13 13 14 14 import org.openstreetmap.josm.Main; 15 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat; 16 import org.openstreetmap.josm.data.osm.Node; 15 17 import org.openstreetmap.josm.data.projection.Mercator; 16 18 import org.openstreetmap.josm.data.projection.Projection; 17 import org.openstreetmap.josm.data.coor.LatLon.CoordinateFormat;18 import org.openstreetmap.josm.data.osm.Node;19 19 import org.openstreetmap.josm.tools.GBC; 20 20 21 21 public class ProjectionPreference implements PreferenceSetting { 22 23 public static class Factory implements PreferenceSettingFactory { 24 public PreferenceSetting createPreferenceSetting() { 25 return new ProjectionPreference(); 26 } 27 } 22 28 23 29 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/ProxyPreferences.java
r1180 r1742 19 19 20 20 public class ProxyPreferences implements PreferenceSetting { 21 22 public static class Factory implements PreferenceSettingFactory { 23 public PreferenceSetting createPreferenceSetting() { 24 return new ProxyPreferences(); 25 } 26 } 21 27 22 28 public static final String PROXY_ENABLE = "proxy.enable"; -
trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java
r1688 r1742 14 14 15 15 public class ServerAccessPreference implements PreferenceSetting { 16 17 public static class Factory implements PreferenceSettingFactory { 18 public PreferenceSetting createPreferenceSetting() { 19 return new ServerAccessPreference(); 20 } 21 } 16 22 17 23 /** -
trunk/src/org/openstreetmap/josm/gui/preferences/ShortcutPreference.java
r1180 r1742 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.Collection; 7 6 8 import javax.swing.JPanel; 7 9 import javax.swing.table.AbstractTableModel; 8 10 9 import java.util.Collection;10 11 11 import org.openstreetmap.josm.tools.GBC; 12 12 import org.openstreetmap.josm.tools.Shortcut; 13 import org.openstreetmap.josm.gui.preferences.prefJPanel;14 13 15 14 public class ShortcutPreference implements PreferenceSetting { 15 16 public static class Factory implements PreferenceSettingFactory { 17 public PreferenceSetting createPreferenceSetting() { 18 return new ShortcutPreference(); 19 } 20 } 16 21 17 22 public void addGui(PreferenceDialog gui) { … … 35 40 36 41 // Maybe move this to prefPanel? There's no need for it to be here. 37 private class scListModel extends AbstractTableModel {42 private static class scListModel extends AbstractTableModel { 38 43 // private String[] columnNames = new String[]{tr("Action"), tr("Shortcut"), tr("Group"), tr("ID")}; 39 44 private String[] columnNames = new String[]{tr("Action"), tr("Shortcut")}; -
trunk/src/org/openstreetmap/josm/gui/preferences/TaggingPresetPreference.java
r1579 r1742 33 33 34 34 public class TaggingPresetPreference implements PreferenceSetting { 35 36 public static class Factory implements PreferenceSettingFactory { 37 public PreferenceSetting createPreferenceSetting() { 38 return new TaggingPresetPreference(); 39 } 40 } 35 41 36 42 public static Collection<TaggingPreset> taggingPresets; -
trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
r1571 r1742 54 54 import org.openstreetmap.josm.tools.ImageProvider; 55 55 56 public class ToolbarPreferences implements PreferenceSetting { 57 58 private final class Move implements ActionListener { 59 public void actionPerformed(ActionEvent e) { 60 if (e.getActionCommand().equals("<") && actionsTree.getSelectionCount() > 0) { 61 62 int leadItem = selected.getSize(); 63 if (selectedList.getSelectedIndex() != -1) { 64 int[] indices = selectedList.getSelectedIndices(); 65 leadItem = indices[indices.length - 1]; 66 } 67 for (TreePath selectedAction : actionsTree.getSelectionPaths()) { 68 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedAction.getLastPathComponent(); 69 if (node.getUserObject() == null) 70 selected.add(leadItem++, null); 71 else if (node.getUserObject() == null || node.getUserObject() instanceof Action) 72 selected.add(leadItem++, ((Action)node.getUserObject()).getValue("toolbar")); 73 } 74 } else if (e.getActionCommand().equals(">") && selectedList.getSelectedIndex() != -1) { 75 while (selectedList.getSelectedIndex() != -1) { 76 selected.remove(selectedList.getSelectedIndex()); 77 } 78 } else if (e.getActionCommand().equals("up")) { 79 int i = selectedList.getSelectedIndex(); 80 Object o = selected.get(i); 81 if (i != 0) { 82 selected.remove(i); 83 selected.add(i-1, o); 84 selectedList.setSelectedIndex(i-1); 85 } 86 } else if (e.getActionCommand().equals("down")) { 87 int i = selectedList.getSelectedIndex(); 88 Object o = selected.get(i); 89 if (i != selected.size()-1) { 90 selected.remove(i); 91 selected.add(i+1, o); 92 selectedList.setSelectedIndex(i+1); 93 } 94 } 95 } 96 } 97 private Move moveAction = new Move(); 56 public class ToolbarPreferences implements PreferenceSettingFactory { 98 57 99 58 /** … … 104 63 private Map<String, Action> regactions = new HashMap<String, Action>(); 105 64 106 private DefaultListModel selected = new DefaultListModel();107 108 65 private DefaultMutableTreeNode rootActionsNode = new DefaultMutableTreeNode("Actions"); 109 private DefaultTreeModel actionsTreeModel = new DefaultTreeModel(rootActionsNode);110 private JTree actionsTree = new JTree(actionsTreeModel);111 private JList selectedList = new JList(selected);112 113 private String movingComponent;114 66 115 67 public JToolBar control = new JToolBar(); 116 68 117 private JButton upButton; 118 private JButton downButton; 69 public PreferenceSetting createPreferenceSetting() { 70 return new Settings(rootActionsNode); 71 } 72 73 public static class Settings implements PreferenceSetting { 74 75 private final class Move implements ActionListener { 76 public void actionPerformed(ActionEvent e) { 77 if (e.getActionCommand().equals("<") && actionsTree.getSelectionCount() > 0) { 78 79 int leadItem = selected.getSize(); 80 if (selectedList.getSelectedIndex() != -1) { 81 int[] indices = selectedList.getSelectedIndices(); 82 leadItem = indices[indices.length - 1]; 83 } 84 for (TreePath selectedAction : actionsTree.getSelectionPaths()) { 85 DefaultMutableTreeNode node = (DefaultMutableTreeNode) selectedAction.getLastPathComponent(); 86 if (node.getUserObject() == null) 87 selected.add(leadItem++, null); 88 else if (node.getUserObject() == null || node.getUserObject() instanceof Action) 89 selected.add(leadItem++, ((Action)node.getUserObject()).getValue("toolbar")); 90 } 91 } else if (e.getActionCommand().equals(">") && selectedList.getSelectedIndex() != -1) { 92 while (selectedList.getSelectedIndex() != -1) { 93 selected.remove(selectedList.getSelectedIndex()); 94 } 95 } else if (e.getActionCommand().equals("up")) { 96 int i = selectedList.getSelectedIndex(); 97 Object o = selected.get(i); 98 if (i != 0) { 99 selected.remove(i); 100 selected.add(i-1, o); 101 selectedList.setSelectedIndex(i-1); 102 } 103 } else if (e.getActionCommand().equals("down")) { 104 int i = selectedList.getSelectedIndex(); 105 Object o = selected.get(i); 106 if (i != selected.size()-1) { 107 selected.remove(i); 108 selected.add(i+1, o); 109 selectedList.setSelectedIndex(i+1); 110 } 111 } 112 } 113 } 114 115 private static class ActionTransferable implements Transferable { 116 117 private DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR }; 118 119 private Object[] actions; 120 121 public ActionTransferable(Action action) { 122 this.actions = new Action[] { action }; 123 } 124 125 public ActionTransferable(Object[] actions) { 126 this.actions = actions; 127 } 128 129 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException { 130 return actions; 131 } 132 133 public DataFlavor[] getTransferDataFlavors() { 134 return flavors; 135 } 136 137 public boolean isDataFlavorSupported(DataFlavor flavor) { 138 return flavors[0] == flavor; 139 } 140 } 141 142 private final Move moveAction = new Move(); 143 144 private final DefaultListModel selected = new DefaultListModel(); 145 private final JList selectedList = new JList(selected); 146 147 private final DefaultTreeModel actionsTreeModel; 148 private final JTree actionsTree; 149 150 private JButton upButton; 151 private JButton downButton; 152 153 private String movingComponent; 154 155 public Settings(DefaultMutableTreeNode rootActionsNode) { 156 actionsTreeModel = new DefaultTreeModel(rootActionsNode); 157 actionsTree = new JTree(actionsTreeModel); 158 } 159 160 private JButton createButton(String name) { 161 JButton b = new JButton(); 162 if (name.equals("up")) 163 b.setIcon(ImageProvider.get("dialogs", "up")); 164 else if (name.equals("down")) 165 b.setIcon(ImageProvider.get("dialogs", "down")); 166 else 167 b.setText(name); 168 b.addActionListener(moveAction); 169 b.setActionCommand(name); 170 return b; 171 } 172 173 public void addGui(PreferenceDialog gui) { 174 actionsTree.setCellRenderer(new DefaultTreeCellRenderer() { 175 @Override 176 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, 177 boolean leaf, int row, boolean hasFocus) { 178 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 179 JLabel comp = (JLabel) super.getTreeCellRendererComponent( 180 tree, value, sel, expanded, leaf, row, hasFocus); 181 if (node.getUserObject() == null) { 182 comp.setText(tr("Separator")); 183 comp.setIcon(ImageProvider.get("preferences/separator")); 184 } 185 else if (node.getUserObject() instanceof Action) { 186 Action action = (Action) node.getUserObject(); 187 comp.setText((String) action.getValue(Action.NAME)); 188 comp.setIcon((Icon) action.getValue(Action.SMALL_ICON)); 189 } 190 return comp; 191 } 192 }); 193 194 ListCellRenderer renderer = new DefaultListCellRenderer(){ 195 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 196 String s; 197 Icon i; 198 if (value != null) { 199 Action action = Main.toolbar.getAction((String)value); 200 s = (String) action.getValue(Action.NAME); 201 i = (Icon) action.getValue(Action.SMALL_ICON); 202 } else { 203 i = ImageProvider.get("preferences/separator"); 204 s = tr("Separator"); 205 } 206 JLabel l = (JLabel)super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus); 207 l.setIcon(i); 208 return l; 209 } 210 }; 211 selectedList.setCellRenderer(renderer); 212 selectedList.addListSelectionListener(new ListSelectionListener(){ 213 public void valueChanged(ListSelectionEvent e) { 214 boolean sel = selectedList.getSelectedIndex() != -1; 215 if (sel) 216 actionsTree.clearSelection(); 217 upButton.setEnabled(sel); 218 downButton.setEnabled(sel); 219 } 220 }); 221 222 selectedList.setDragEnabled(true); 223 selectedList.setTransferHandler(new TransferHandler() { 224 @Override 225 protected Transferable createTransferable(JComponent c) { 226 return new ActionTransferable(((JList)c).getSelectedValues()); 227 } 228 229 @Override 230 public int getSourceActions(JComponent c) { 231 return TransferHandler.MOVE; 232 } 233 234 @Override 235 public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { 236 for (DataFlavor f : transferFlavors) { 237 if (ACTION_FLAVOR.equals(f)) { 238 return true; 239 } 240 } 241 return false; 242 } 243 244 @Override 245 public void exportAsDrag(JComponent comp, InputEvent e, int action) { 246 super.exportAsDrag(comp, e, action); 247 movingComponent = "list"; 248 } 249 250 @Override 251 public boolean importData(JComponent comp, Transferable t) { 252 try { 253 int dropIndex = selectedList.locationToIndex(selectedList.getMousePosition(true)); 254 Object[] draggedData = (Object[]) t.getTransferData(ACTION_FLAVOR); 255 256 Object leadItem = dropIndex >= 0 ? selected.elementAt(dropIndex) : null; 257 int dataLength = draggedData.length; 258 259 if (leadItem != null) 260 for (int i = 0; i < dataLength; i++) 261 if (leadItem.equals(draggedData[i])) 262 return false; 263 264 int dragLeadIndex = -1; 265 boolean localDrop = "list".equals(movingComponent); 266 267 if (localDrop) { 268 dragLeadIndex = selected.indexOf(draggedData[0]); 269 for (int i = 0; i < dataLength; i++) 270 selected.removeElement(draggedData[i]); 271 } 272 int[] indices = new int[dataLength]; 273 274 if (localDrop) { 275 int adjustedLeadIndex = selected.indexOf(leadItem); 276 int insertionAdjustment = dragLeadIndex <= adjustedLeadIndex ? 1 : 0; 277 for (int i = 0; i < dataLength; i++) { 278 selected.insertElementAt(draggedData[i], adjustedLeadIndex + insertionAdjustment + i); 279 indices[i] = adjustedLeadIndex + insertionAdjustment + i; 280 } 281 } else { 282 for (int i = 0; i < dataLength; i++) { 283 selected.add(dropIndex, draggedData[i]); 284 indices[i] = dropIndex + i; 285 } 286 } 287 selectedList.clearSelection(); 288 selectedList.setSelectedIndices(indices); 289 movingComponent = ""; 290 return true; 291 } catch (Exception e) { 292 e.printStackTrace(); 293 } 294 return false; 295 } 296 297 @Override 298 protected void exportDone(JComponent source, Transferable data, int action) { 299 if (movingComponent.equals("list")) { 300 try { 301 Object[] draggedData = (Object[]) data.getTransferData(ACTION_FLAVOR); 302 boolean localDrop = selected.contains(draggedData[0]); 303 if (localDrop) { 304 int[] indices = selectedList.getSelectedIndices(); 305 Arrays.sort(indices); 306 for (int i = indices.length - 1; i >= 0; i--) { 307 selected.remove(indices[i]); 308 } 309 } 310 } catch (Exception e) { 311 e.printStackTrace(); 312 } 313 movingComponent = ""; 314 } 315 } 316 }); 317 318 actionsTree.setTransferHandler(new TransferHandler() { 319 private static final long serialVersionUID = 1L; 320 321 @Override 322 public int getSourceActions( JComponent c ){ 323 return TransferHandler.MOVE; 324 } 325 326 @Override 327 protected void exportDone(JComponent source, Transferable data, int action) { 328 } 329 330 @Override 331 protected Transferable createTransferable(JComponent c) { 332 TreePath[] paths = actionsTree.getSelectionPaths(); 333 List<String> dragActions = new LinkedList<String>(); 334 for (TreePath path : paths) { 335 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 336 Object obj = node.getUserObject(); 337 if (obj == null) { 338 dragActions.add(null); 339 } 340 else if (obj instanceof Action) { 341 dragActions.add((String) ((Action) obj).getValue("toolbar")); 342 } 343 } 344 return new ActionTransferable(dragActions.toArray()); 345 } 346 }); 347 actionsTree.setDragEnabled(true); 348 349 final JPanel left = new JPanel(new GridBagLayout()); 350 left.add(new JLabel(tr("Toolbar")), GBC.eol()); 351 left.add(new JScrollPane(selectedList), GBC.std().fill(GBC.BOTH)); 352 353 final JPanel right = new JPanel(new GridBagLayout()); 354 right.add(new JLabel(tr("Available")), GBC.eol()); 355 right.add(new JScrollPane(actionsTree), GBC.eol().fill(GBC.BOTH)); 356 357 final JPanel buttons = new JPanel(new GridLayout(6,1)); 358 buttons.add(upButton = createButton("up")); 359 buttons.add(createButton("<")); 360 buttons.add(createButton(">")); 361 buttons.add(downButton = createButton("down")); 362 upButton.setEnabled(false); 363 downButton.setEnabled(false); 364 365 final JPanel p = new JPanel(); 366 p.setLayout(new LayoutManager(){ 367 public void addLayoutComponent(String name, Component comp) {} 368 public void removeLayoutComponent(Component comp) {} 369 public Dimension minimumLayoutSize(Container parent) { 370 Dimension l = left.getMinimumSize(); 371 Dimension r = right.getMinimumSize(); 372 Dimension b = buttons.getMinimumSize(); 373 return new Dimension(l.width+b.width+10+r.width,l.height+b.height+10+r.height); 374 } 375 public Dimension preferredLayoutSize(Container parent) { 376 Dimension l = new Dimension(200, 200); //left.getPreferredSize(); 377 Dimension r = new Dimension(200, 200); //right.getPreferredSize(); 378 return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width,Math.max(l.height, r.height)); 379 } 380 public void layoutContainer(Container parent) { 381 Dimension d = p.getSize(); 382 Dimension b = buttons.getPreferredSize(); 383 int width = (d.width-10-b.width)/2; 384 left.setBounds(new Rectangle(0,0,width,d.height)); 385 right.setBounds(new Rectangle(width+10+b.width,0,width,d.height)); 386 buttons.setBounds(new Rectangle(width+5, d.height/2-b.height/2, b.width, b.height)); 387 } 388 }); 389 p.add(left); 390 p.add(buttons); 391 p.add(right); 392 393 JPanel panel = gui.createPreferenceTab("toolbar", tr("Toolbar customization"), 394 tr("Customize the elements on the toolbar."), false); 395 panel.add(p, GBC.eol().fill(GBC.BOTH)); 396 397 selected.removeAllElements(); 398 for (String s : getToolString()) { 399 if (s.equals("|")) 400 selected.addElement(null); 401 else if (Main.toolbar.getAction(s) != null) 402 selected.addElement(s); 403 } 404 } 405 406 public boolean ok() { 407 Collection<String> t = new LinkedList<String>(); 408 for (int i = 0; i < selected.size(); ++i) { 409 if (selected.get(i) == null) 410 t.add("|"); 411 else 412 t.add((String)((Main.toolbar.getAction((String)selected.get(i))).getValue("toolbar"))); 413 } 414 Main.pref.putCollection("toolbar", t); 415 Main.toolbar.refreshToolbarControl(); 416 return false; 417 } 418 419 } 119 420 120 421 public ToolbarPreferences() { 121 422 control.setFloatable(false); 122 123 actionsTree.setCellRenderer(new DefaultTreeCellRenderer() { 124 @Override 125 public Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel, boolean expanded, 126 boolean leaf, int row, boolean hasFocus) { 127 DefaultMutableTreeNode node = (DefaultMutableTreeNode) value; 128 JLabel comp = (JLabel) super.getTreeCellRendererComponent( 129 tree, value, sel, expanded, leaf, row, hasFocus); 130 if (node.getUserObject() == null) { 131 comp.setText(tr("Separator")); 132 comp.setIcon(ImageProvider.get("preferences/separator")); 133 } 134 else if (node.getUserObject() instanceof Action) { 135 Action action = (Action) node.getUserObject(); 136 comp.setText((String) action.getValue(Action.NAME)); 137 comp.setIcon((Icon) action.getValue(Action.SMALL_ICON)); 138 } 139 return comp; 140 } 141 }); 142 143 ListCellRenderer renderer = new DefaultListCellRenderer(){ 144 @Override public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 145 String s; 146 Icon i; 147 if (value != null) { 148 Action action = getAction((String)value); 149 s = (String) action.getValue(Action.NAME); 150 i = (Icon) action.getValue(Action.SMALL_ICON); 151 } else { 152 i = ImageProvider.get("preferences/separator"); 153 s = tr("Separator"); 154 } 155 JLabel l = (JLabel)super.getListCellRendererComponent(list, s, index, isSelected, cellHasFocus); 156 l.setIcon(i); 157 return l; 158 } 159 }; 160 selectedList.setCellRenderer(renderer); 161 selectedList.addListSelectionListener(new ListSelectionListener(){ 162 public void valueChanged(ListSelectionEvent e) { 163 boolean sel = selectedList.getSelectedIndex() != -1; 164 if (sel) 165 actionsTree.clearSelection(); 166 upButton.setEnabled(sel); 167 downButton.setEnabled(sel); 168 } 169 }); 170 171 selectedList.setDragEnabled(true); 172 selectedList.setTransferHandler(new TransferHandler() { 173 @Override 174 protected Transferable createTransferable(JComponent c) { 175 return new ActionTransferable(((JList)c).getSelectedValues()); 176 } 177 178 @Override 179 public int getSourceActions(JComponent c) { 180 return TransferHandler.MOVE; 181 } 182 183 @Override 184 public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) { 185 for (DataFlavor f : transferFlavors) { 186 if (ACTION_FLAVOR.equals(f)) { 187 return true; 188 } 189 } 190 return false; 191 } 192 193 @Override 194 public void exportAsDrag(JComponent comp, InputEvent e, int action) { 195 super.exportAsDrag(comp, e, action); 196 movingComponent = "list"; 197 } 198 199 @Override 200 public boolean importData(JComponent comp, Transferable t) { 201 try { 202 int dropIndex = selectedList.locationToIndex(selectedList.getMousePosition(true)); 203 Object[] draggedData = (Object[]) t.getTransferData(ACTION_FLAVOR); 204 205 Object leadItem = dropIndex >= 0 ? selected.elementAt(dropIndex) : null; 206 int dataLength = draggedData.length; 207 208 if (leadItem != null) 209 for (int i = 0; i < dataLength; i++) 210 if (leadItem.equals(draggedData[i])) 211 return false; 212 213 int dragLeadIndex = -1; 214 boolean localDrop = "list".equals(movingComponent); 215 216 if (localDrop) { 217 dragLeadIndex = selected.indexOf(draggedData[0]); 218 for (int i = 0; i < dataLength; i++) 219 selected.removeElement(draggedData[i]); 220 } 221 int[] indices = new int[dataLength]; 222 223 if (localDrop) { 224 int adjustedLeadIndex = selected.indexOf(leadItem); 225 int insertionAdjustment = dragLeadIndex <= adjustedLeadIndex ? 1 : 0; 226 for (int i = 0; i < dataLength; i++) { 227 selected.insertElementAt(draggedData[i], adjustedLeadIndex + insertionAdjustment + i); 228 indices[i] = adjustedLeadIndex + insertionAdjustment + i; 229 } 230 } else { 231 for (int i = 0; i < dataLength; i++) { 232 selected.add(dropIndex, draggedData[i]); 233 indices[i] = dropIndex + i; 234 } 235 } 236 selectedList.clearSelection(); 237 selectedList.setSelectedIndices(indices); 238 movingComponent = ""; 239 return true; 240 } catch (Exception e) { 241 e.printStackTrace(); 242 } 243 return false; 244 } 245 246 @Override 247 protected void exportDone(JComponent source, Transferable data, int action) { 248 if (movingComponent.equals("list")) { 249 try { 250 Object[] draggedData = (Object[]) data.getTransferData(ACTION_FLAVOR); 251 boolean localDrop = selected.contains(draggedData[0]); 252 if (localDrop) { 253 int[] indices = selectedList.getSelectedIndices(); 254 Arrays.sort(indices); 255 for (int i = indices.length - 1; i >= 0; i--) { 256 selected.remove(indices[i]); 257 } 258 } 259 } catch (Exception e) { 260 e.printStackTrace(); 261 } 262 movingComponent = ""; 263 } 264 } 265 }); 266 267 actionsTree.setTransferHandler(new TransferHandler() { 268 private static final long serialVersionUID = 1L; 269 270 @Override 271 public int getSourceActions( JComponent c ){ 272 return TransferHandler.MOVE; 273 } 274 275 @Override 276 protected void exportDone(JComponent source, Transferable data, int action) { 277 } 278 279 @Override 280 protected Transferable createTransferable(JComponent c) { 281 TreePath[] paths = actionsTree.getSelectionPaths(); 282 List<String> dragActions = new LinkedList<String>(); 283 for (TreePath path : paths) { 284 DefaultMutableTreeNode node = (DefaultMutableTreeNode) path.getLastPathComponent(); 285 Object obj = node.getUserObject(); 286 if (obj == null) { 287 dragActions.add(null); 288 } 289 else if (obj instanceof Action) { 290 dragActions.add((String) ((Action) obj).getValue("toolbar")); 291 } 292 } 293 return new ActionTransferable(dragActions.toArray()); 294 } 295 }); 296 actionsTree.setDragEnabled(true); 297 } 298 299 public void addGui(PreferenceDialog gui) { 300 final JPanel left = new JPanel(new GridBagLayout()); 301 left.add(new JLabel(tr("Toolbar")), GBC.eol()); 302 left.add(new JScrollPane(selectedList), GBC.std().fill(GBC.BOTH)); 303 304 final JPanel right = new JPanel(new GridBagLayout()); 305 right.add(new JLabel(tr("Available")), GBC.eol()); 306 right.add(new JScrollPane(actionsTree), GBC.eol().fill(GBC.BOTH)); 307 308 final JPanel buttons = new JPanel(new GridLayout(6,1)); 309 buttons.add(upButton = createButton("up")); 310 buttons.add(createButton("<")); 311 buttons.add(createButton(">")); 312 buttons.add(downButton = createButton("down")); 313 upButton.setEnabled(false); 314 downButton.setEnabled(false); 315 316 final JPanel p = new JPanel(); 317 p.setLayout(new LayoutManager(){ 318 public void addLayoutComponent(String name, Component comp) {} 319 public void removeLayoutComponent(Component comp) {} 320 public Dimension minimumLayoutSize(Container parent) { 321 Dimension l = left.getMinimumSize(); 322 Dimension r = right.getMinimumSize(); 323 Dimension b = buttons.getMinimumSize(); 324 return new Dimension(l.width+b.width+10+r.width,l.height+b.height+10+r.height); 325 } 326 public Dimension preferredLayoutSize(Container parent) { 327 Dimension l = new Dimension(200, 200); //left.getPreferredSize(); 328 Dimension r = new Dimension(200, 200); //right.getPreferredSize(); 329 return new Dimension(l.width+r.width+10+buttons.getPreferredSize().width,Math.max(l.height, r.height)); 330 } 331 public void layoutContainer(Container parent) { 332 Dimension d = p.getSize(); 333 Dimension b = buttons.getPreferredSize(); 334 int width = (d.width-10-b.width)/2; 335 left.setBounds(new Rectangle(0,0,width,d.height)); 336 right.setBounds(new Rectangle(width+10+b.width,0,width,d.height)); 337 buttons.setBounds(new Rectangle(width+5, d.height/2-b.height/2, b.width, b.height)); 338 } 339 }); 340 p.add(left); 341 p.add(buttons); 342 p.add(right); 343 344 JPanel panel = gui.createPreferenceTab("toolbar", tr("Toolbar customization"), 345 tr("Customize the elements on the toolbar."), false); 346 panel.add(p, GBC.eol().fill(GBC.BOTH)); 347 348 selected.removeAllElements(); 349 for (String s : getToolString()) { 350 if (s.equals("|")) 351 selected.addElement(null); 352 else if (getAction(s) != null) 353 selected.addElement(s); 354 } 355 } 423 } 424 356 425 357 426 private void loadAction(DefaultMutableTreeNode node, MenuElement menu) { … … 396 465 } 397 466 rootActionsNode.add(new DefaultMutableTreeNode(null)); 398 actionsTree.updateUI();399 actionsTree.setRootVisible(false);400 actionsTree.expandPath(new TreePath(rootActionsNode));401 467 } 402 468 … … 404 470 "download", "upload", "|", "undo", "redo", "|", "preference"}; 405 471 406 private Collection<String> getToolString() {472 private static Collection<String> getToolString() { 407 473 return Main.pref.getCollection("toolbar", Arrays.asList(deftoolbar)); 408 }409 410 private JButton createButton(String name) {411 JButton b = new JButton();412 if (name.equals("up"))413 b.setIcon(ImageProvider.get("dialogs", "up"));414 else if (name.equals("down"))415 b.setIcon(ImageProvider.get("dialogs", "down"));416 else417 b.setText(name);418 b.addActionListener(moveAction);419 b.setActionCommand(name);420 return b;421 }422 423 public boolean ok() {424 Collection<String> t = new LinkedList<String>();425 for (int i = 0; i < selected.size(); ++i) {426 if (selected.get(i) == null)427 t.add("|");428 else429 t.add((String)((getAction((String)selected.get(i))).getValue("toolbar")));430 }431 Main.pref.putCollection("toolbar", t);432 refreshToolbarControl();433 return false;434 474 } 435 475 … … 463 503 AbstractAction.class, "ActionItem"); 464 504 465 private class ActionTransferable implements Transferable {466 467 private DataFlavor[] flavors = new DataFlavor[] { ACTION_FLAVOR };468 469 private Object[] actions;470 471 public ActionTransferable(Action action) {472 this.actions = new Action[] { action };473 }474 475 public ActionTransferable(Object[] actions) {476 this.actions = actions;477 }478 479 public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {480 return actions;481 }482 483 public DataFlavor[] getTransferDataFlavors() {484 return flavors;485 }486 487 public boolean isDataFlavorSupported(DataFlavor flavor) {488 return flavors[0] == flavor;489 }490 }491 505 } -
trunk/src/org/openstreetmap/josm/gui/preferences/prefJPanel.java
r1244 r1742 86 86 String s = KeyEvent.getKeyText(i); 87 87 if (s != null && s.length() > 0 && !s.contains("Unknown")) { 88 list.put( new Integer(i), s);88 list.put(Integer.valueOf(i), s); 89 89 //System.out.println(i+": "+s); 90 90 } 91 91 } 92 list.put( new Integer(-1), "");92 list.put(Integer.valueOf(-1), ""); 93 93 return list; 94 94 } -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r1645 r1742 9 9 import java.net.URL; 10 10 import java.net.URLClassLoader; 11 import java.util.ArrayList; 11 12 import java.util.Arrays; 12 import java.util.ArrayList;13 13 import java.util.Collection; 14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 import java.util.Map.Entry;17 16 import java.util.SortedMap; 18 17 import java.util.TreeMap; 18 import java.util.Map.Entry; 19 19 20 20 import javax.swing.AbstractAction; … … 31 31 import org.openstreetmap.josm.Main; 32 32 import org.openstreetmap.josm.actions.AboutAction; 33 import org.openstreetmap.josm.gui.ExtendedDialog; 33 34 import org.openstreetmap.josm.gui.MapFrame; 34 35 import org.openstreetmap.josm.gui.download.DownloadSelection; 35 import org.openstreetmap.josm.gui.ExtendedDialog; 36 import org.openstreetmap.josm.gui.preferences.PreferenceSetting; 36 import org.openstreetmap.josm.gui.preferences.PreferenceSettingFactory; 37 37 import org.openstreetmap.josm.tools.GBC; 38 38 import org.openstreetmap.josm.tools.ImageProvider; … … 176 176 p.addDownloadSelection(downloadSelections); 177 177 } 178 public static void getPreferenceSetting(Collection<PreferenceSetting > settings)178 public static void getPreferenceSetting(Collection<PreferenceSettingFactory> settings) 179 179 { 180 180 for (PluginProxy plugin : pluginList) { 181 PreferenceSetting p = plugin.getPreferenceSetting(); 182 if (p != null) 183 settings.add(p); 181 settings.add(new PluginPreferenceFactory(plugin)); 184 182 } 185 183 }
Note:
See TracChangeset
for help on using the changeset viewer.