1 32 33 package it.businesslogic.ireport.gui.docking; 34 35 import it.businesslogic.ireport.gui.MainFrame; 36 import java.awt.datatransfer.DataFlavor ; 37 import java.awt.datatransfer.Transferable ; 38 import java.awt.dnd.DnDConstants ; 39 import java.awt.dnd.DragGestureEvent ; 40 import java.awt.dnd.DragGestureListener ; 41 import java.awt.dnd.DragSource ; 42 import java.awt.dnd.DragSourceContext ; 43 import java.awt.dnd.DragSourceDragEvent ; 44 import java.awt.dnd.DragSourceDropEvent ; 45 import java.awt.dnd.DragSourceEvent ; 46 import java.awt.dnd.DragSourceListener ; 47 import java.awt.dnd.DropTarget ; 48 import java.awt.dnd.DropTargetContext ; 49 import java.awt.dnd.DropTargetDragEvent ; 50 import java.awt.dnd.DropTargetDropEvent ; 51 import java.awt.dnd.DropTargetEvent ; 52 import java.awt.dnd.DropTargetListener ; 53 import java.awt.dnd.InvalidDnDOperationException ; 54 import java.awt.event.MouseAdapter ; 55 import javax.swing.JPopupMenu ; 56 import javax.swing.JTabbedPane ; 57 import it.businesslogic.ireport.util.LanguageChangedEvent; 58 import it.businesslogic.ireport.util.I18n; 59 import it.businesslogic.ireport.util.*; 60 61 65 public class JDraggableTabbedPane extends ExtendedTabbedPane implements LanguageChangedListener { 66 67 private javax.swing.JMenuItem jMenuItemMerge; 68 private javax.swing.JMenuItem jMenuItemUnmerge; 69 private javax.swing.JPopupMenu jPopupMenu; 70 71 72 73 private DockingContainer dockingContainer = null; 74 private int position = 0; 75 76 77 public JDraggableTabbedPane() { 78 super(); 79 it.businesslogic.ireport.util.I18n.setCurrentLocale( System.getProperty("Language"), System.getProperty("Country") ); 80 this.dragSource = DragSource.getDefaultDragSource(); 81 this.dgListener = new DGListener(); 82 this.dsListener = new DSListener((int)(1000*Math.random())) ; 83 this.dtListener = new GenericDragTargetListener(); 84 85 this.dropTarget = new DropTarget (this, 87 this.acceptableActions, 88 this.dtListener, 89 true); 90 91 this.dragSource.createDefaultDragGestureRecognizer( 93 this, 94 this.dragAction, 95 this.dgListener); 96 97 jPopupMenu = new JPopupMenu (); 98 99 jMenuItemMerge = new javax.swing.JMenuItem (); 100 jMenuItemMerge.setText("Merge panels"); 101 jMenuItemMerge.setEnabled(true); 102 jMenuItemMerge.addActionListener(new java.awt.event.ActionListener () { 103 public void actionPerformed(java.awt.event.ActionEvent evt) { 104 jMenuItemMergeActionPerformed(evt); 105 } 106 }); 107 108 jPopupMenu.add(jMenuItemMerge); 109 110 jMenuItemUnmerge = new javax.swing.JMenuItem (); 111 jMenuItemUnmerge.setText("Separate panel"); 112 jMenuItemUnmerge.setEnabled(true); 113 jMenuItemUnmerge.addActionListener(new java.awt.event.ActionListener () { 114 public void actionPerformed(java.awt.event.ActionEvent evt) { 115 jMenuItemUnmergeActionPerformed(evt); 116 } 117 }); 118 119 jPopupMenu.add(jMenuItemUnmerge); 120 121 this.addMouseListener(new java.awt.event.MouseAdapter () { 122 public void mouseClicked(java.awt.event.MouseEvent evt) { 123 onMouseClicked(evt); 124 } 125 }); 126 127 this.setOpaque(true); 128 129 I18n.addOnLanguageChangedListener( this ); 130 131 } 132 133 private void jMenuItemUnmergeActionPerformed(java.awt.event.ActionEvent evt) { 134 135 PanelView pv = new PanelView( JDraggableTabbedPane.this.getTitleAt( JDraggableTabbedPane.this.getSelectedIndex() ), 136 JDraggableTabbedPane.this.getSelectedComponent(), 137 JDraggableTabbedPane.this.getPosition(), 138 JDraggableTabbedPane.this.isClosable( JDraggableTabbedPane.this.getSelectedIndex() ) 139 ); 140 getDockingContainer().moveComponent(pv, pv.getPosition(), DockingContainer.INSERT_MODE_NEWPOSITION); 141 } 142 143 144 145 private void jMenuItemMergeActionPerformed(java.awt.event.ActionEvent evt) { 146 getDockingContainer().mergePosition( this.getPosition() ); 147 } 148 149 public void onMouseClicked(java.awt.event.MouseEvent evt) 150 { 151 if (evt.getButton() == evt.BUTTON3 && evt.getClickCount() == 1) { 152 this.jPopupMenu.show(this, evt.getPoint().x, evt.getPoint().y); 153 } 154 } 155 156 164 class DGListener implements DragGestureListener { 165 171 public void dragGestureRecognized(DragGestureEvent e) { 172 173 if((e.getDragAction() & JDraggableTabbedPane.this.dragAction) == 0) 176 return; 177 178 if (JDraggableTabbedPane.this.getSelectedIndex() < 0) return; 181 182 PanelView pv = new PanelView( JDraggableTabbedPane.this.getTitleAt( JDraggableTabbedPane.this.getSelectedIndex() ), 183 JDraggableTabbedPane.this.getSelectedComponent(), 184 JDraggableTabbedPane.this.getPosition(), 185 JDraggableTabbedPane.this.isClosable( JDraggableTabbedPane.this.getSelectedIndex() )); 186 pv.setDockingContainer( JDraggableTabbedPane.this.getDockingContainer()); 187 Transferable transferable = new PanelTransferable( pv); 188 189 try { 191 e.startDrag(DragSource.DefaultCopyNoDrop, 193 transferable, 194 JDraggableTabbedPane.this.dsListener); 195 196 199 200 202 207 208 }catch( InvalidDnDOperationException idoe ) { 209 } 210 } 211 } 212 213 221 class DSListener implements DragSourceListener { 222 223 public int myId = 0; 224 public DSListener(int id) 225 { 226 super(); 227 myId = id; 228 } 229 230 233 public void dragDropEnd(DragSourceDropEvent e) { 234 235 if (GenericDragTargetListener.lastDp != null) 236 { 237 GenericDragTargetListener.lastDp.repaint(); 238 GenericDragTargetListener.lastDp = null; 239 } 240 } 241 242 245 public void dragEnter(DragSourceDragEvent e) { 246 DragSourceContext context = e.getDragSourceContext(); 247 int myaction = e.getDropAction(); 249 if( (myaction & JDraggableTabbedPane.this.dragAction) != 0) { 250 context.setCursor(DragSource.DefaultCopyDrop); 251 } else { 252 context.setCursor(DragSource.DefaultCopyNoDrop); 253 } 254 } 255 258 public void dragOver(DragSourceDragEvent e) { 259 DragSourceContext context = e.getDragSourceContext(); 260 int sa = context.getSourceActions(); 261 int ua = e.getUserAction(); 262 int da = e.getDropAction(); 263 int ta = e.getTargetActions(); 264 265 } 266 269 public void dragExit(DragSourceEvent e) { 270 } 271 272 277 public void dropActionChanged (DragSourceDragEvent e) { 278 DragSourceContext context = e.getDragSourceContext(); 279 context.setCursor(DragSource.DefaultCopyNoDrop); 280 } 281 } 282 283 284 285 286 private DragSource dragSource; 287 private DragGestureListener dgListener; 288 private DragSourceListener dsListener; 289 private DropTarget dropTarget; 290 private DropTargetListener dtListener; 291 private int dragAction = DnDConstants.ACTION_MOVE; 292 private int acceptableActions = DnDConstants.ACTION_MOVE; 293 294 public DockingContainer getDockingContainer() { 295 return dockingContainer; 296 } 297 298 public void setDockingContainer(DockingContainer dockingContainer) { 299 this.dockingContainer = dockingContainer; 300 } 301 302 public int getPosition() { 303 return position; 304 } 305 306 public void setPosition(int position) { 307 this.position = position; 308 } 309 public void applyI18n(){ 311 jMenuItemMerge.setText(it.businesslogic.ireport.util.I18n.getString("mergePanels","Merge panels")); 314 jMenuItemUnmerge.setText(it.businesslogic.ireport.util.I18n.getString("unmergePanel","Seperate panel")); 315 } 316 317 public void languageChanged(LanguageChangedEvent evt) { 318 applyI18n(); 319 } 320 } 322 | Popular Tags |