1 19 20 package org.netbeans.core.windows.view.ui.toolbars; 21 22 import org.openide.awt.Toolbar; 23 24 33 public class ToolbarDnDListener extends Object implements Toolbar.DnDListener { 34 35 private ToolbarConstraints draggedToolbar; 36 private ToolbarConfiguration configuration; 37 38 41 public ToolbarDnDListener (ToolbarConfiguration conf) { 42 configuration = conf; 43 } 44 45 49 protected void moveToolbar2EndHorizontally (ToolbarConstraints tc, int dx) { 50 if (dx == 0) return; 52 53 if (dx < 0) 54 tc.moveLeft2End (-dx); 55 if (dx > 0) 56 tc.moveRight2End (dx); 57 } 58 59 63 protected void moveToolbarHorizontally (ToolbarConstraints tc, int dx) { 64 if (dx == 0) return; 66 67 if (dx < 0) 68 tc.moveLeft (-dx); 69 if (dx > 0) 70 tc.moveRight (dx); 71 } 72 73 77 protected void moveToolbarVertically (ToolbarConstraints tc, int dy) { 78 if (dy == 0) return; 80 81 if (dy < 0) 82 moveUp (tc, -dy); 83 if (dy > 0) 84 moveDown (tc, dy); 85 } 86 87 91 protected void moveUp (ToolbarConstraints tc, int dy) { 92 if (dy < ((Toolbar.getBasicHeight() / 2) + 2)) 93 return; 94 95 int rI = tc.rowIndex(); 96 if (draggedToolbar.isAlone()) { if (rI == 0) return; 99 } 100 101 int pos = rI - 1; 102 tc.destroy(); 103 104 int plus = 0; 105 int rowCount = configuration.getRowCount(); 106 for (int i = pos; i < pos + tc.getRowCount(); i++) { 107 configuration.getRow (i + plus).addToolbar (tc, tc.getPosition()); 108 if (rowCount != configuration.getRowCount()) { 109 rowCount = configuration.getRowCount(); 110 plus++; 111 } 112 } 113 configuration.checkToolbarRows(); 114 configuration.updateBounds( configuration.getRow(0) ); 115 } 116 117 121 public void moveDown (ToolbarConstraints tc, int dy) { 122 int rI = tc.rowIndex(); 123 124 int step = ((Toolbar.getBasicHeight() / 2) + 2); 125 126 if (draggedToolbar.isAlone()) { if (rI == (configuration.getRowCount() - tc.getRowCount())) return; 129 step = ((Toolbar.getBasicHeight() / 4) + 2); 130 } 131 132 if (dy < step) 133 return; 134 135 int pos = rI + 1; 136 tc.destroy(); 137 138 for (int i = pos; i < pos + tc.getRowCount(); i++) 139 configuration.getRow (i).addToolbar (tc, tc.getPosition()); 140 141 configuration.checkToolbarRows(); 142 } 143 144 147 148 public void dragToolbar (Toolbar.DnDEvent e) { 149 if (draggedToolbar == null) { 150 draggedToolbar = configuration.getToolbarConstraints (e.getName()); 151 } 152 153 switch (e.getType()) { 154 case Toolbar.DnDEvent.DND_LINE: 155 return; case Toolbar.DnDEvent.DND_END: 159 moveToolbar2EndHorizontally (draggedToolbar, e.getDX()); 160 break; 161 case Toolbar.DnDEvent.DND_ONE: 162 moveToolbarVertically (draggedToolbar, e.getDY()); 163 break; 164 } 165 if (e.getType() == Toolbar.DnDEvent.DND_ONE) 166 moveToolbarHorizontally (draggedToolbar, e.getDX()); 167 168 draggedToolbar.updatePosition(); 169 170 configuration.revalidateWindow(); 171 } 172 173 174 public void dropToolbar (Toolbar.DnDEvent e) { 175 dragToolbar (e); 176 177 configuration.reflectChanges(); 178 draggedToolbar = null; 179 } 180 } 182 | Popular Tags |