Changeset 1742 in josm for trunk/src/org/openstreetmap/josm/gui/preferences/ToolbarPreferences.java
- Timestamp:
- 2009-07-07T09:04:00+02:00 (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
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 }
Note:
See TracChangeset
for help on using the changeset viewer.