From: Christian S. <ch...@us...> - 2008-02-29 21:07:31
|
Update of /cvsroot/nmedit/nmedit/libs/jtheme/src/net/sf/nmedit/jtheme/component/plaf/mcui In directory sc8-pr-cvs16.sourceforge.net:/tmp/cvs-serv9006/jtheme/src/net/sf/nmedit/jtheme/component/plaf/mcui Modified Files: JTModuleContainerUI.java Log Message: +SelectionPainter class for painting all selection related stuff +TODO: choose better colors +fixed: selection bounding box was not painted while draggin into different module container Index: JTModuleContainerUI.java =================================================================== RCS file: /cvsroot/nmedit/nmedit/libs/jtheme/src/net/sf/nmedit/jtheme/component/plaf/mcui/JTModuleContainerUI.java,v retrieving revision 1.5 retrieving revision 1.6 diff -C2 -d -r1.5 -r1.6 *** JTModuleContainerUI.java 25 Feb 2008 20:56:13 -0000 1.5 --- JTModuleContainerUI.java 29 Feb 2008 21:07:27 -0000 1.6 *************** *** 52,56 **** import java.util.Collection; import java.util.HashSet; - import java.util.Set; import javax.swing.JComponent; --- 52,55 ---- *************** *** 68,72 **** import net.sf.nmedit.jtheme.component.JTModule; import net.sf.nmedit.jtheme.component.JTModuleContainer; ! import net.sf.nmedit.jtheme.component.JTPatch; import net.sf.nmedit.jtheme.dnd.JTDragDrop; import net.sf.nmedit.jtheme.dnd.JTModuleTransferData; --- 67,71 ---- import net.sf.nmedit.jtheme.component.JTModule; import net.sf.nmedit.jtheme.component.JTModuleContainer; ! import net.sf.nmedit.jtheme.component.plaf.SelectionPainter; import net.sf.nmedit.jtheme.dnd.JTDragDrop; import net.sf.nmedit.jtheme.dnd.JTModuleTransferData; *************** *** 153,174 **** public void paintChildrenHack(Graphics g) { ! if (selectBoxActive) { ! g.setColor(Color.BLUE); Rectangle r = selectRectangle; ! g.drawRect(r.x, r.y, r.width - 1, r.height - 1); } Rectangle box = dndBox; ! if (box == null) return; ! ! if (jtc.getSelectionSize()>0) { ! if (transferData == null) ! return; ! Rectangle bbox = transferData.getBoundingBox(); ! g.setColor(Color.BLUE); ! for (JTModule m : transferData.getModules()) { ! g.drawRect(box.x + m.getX() - bbox.x, box.y + m.getY() - bbox.y, ! m.getWidth() - 1, m.getHeight() - 1); } } --- 152,177 ---- public void paintChildrenHack(Graphics g) { ! if (selectBoxActive) ! { Rectangle r = selectRectangle; ! SelectionPainter.paintSelectionBox(g, ! r.x, r.y, r.width, r.height); } Rectangle box = dndBox; ! if (box != null) { ! JTModuleTransferDataWrapper transfer = getCurrentTransfer(); ! if (transfer != null) ! { ! Collection<? extends JTModule> components = transfer.getModules(); ! if (!components.isEmpty()) ! { ! Rectangle bbox = transfer.getBoundingBox(); ! SelectionPainter.paintSelectionBox(g, ! transfer.getModules(), ! box.x - bbox.x, ! box.y - bbox.y ); ! } } } *************** *** 178,186 **** private transient Point dndInitialScrollLocation; protected EventHandler eventHandler; ! public JTModuleTransferDataWrapper transferData; public boolean selectBoxActive; public Point selectStartPoint; public Rectangle selectRectangle; public void updateDnDBoundingBox(Rectangle box) { --- 181,204 ---- private transient Point dndInitialScrollLocation; protected EventHandler eventHandler; ! private JTModuleTransferDataWrapper currentTransferData; public boolean selectBoxActive; public Point selectStartPoint; public Rectangle selectRectangle; + private void setCurrentTransfer(JTModuleTransferDataWrapper transfer) + { + this.currentTransferData = transfer; + updateDnDBoundingBox(null); + } + + private JTModuleTransferDataWrapper getCurrentTransfer() + { + return currentTransferData; + } + + + + + public void updateDnDBoundingBox(Rectangle box) { *************** *** 429,447 **** DataFlavor flavors[] = dtde.getTransferable().getTransferDataFlavors(); ! if (jtcUI.transferData == null) { Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(JTDragDrop.ModuleSelectionFlavor)) { try { ! jtcUI.transferData = (JTModuleTransferDataWrapper)t.getTransferData(JTDragDrop.ModuleSelectionFlavor); ! jtcUI.updateDnDBoundingBox(null); } catch (Throwable e) { ! jtcUI.transferData = null; } } else { ! System.out.println("falvor not supported"); } } - if (isMDDropOk(dtde.getDropAction(), dtde.getTransferable())) { dtde.acceptDrag(DnDConstants.ACTION_COPY); --- 447,466 ---- DataFlavor flavors[] = dtde.getTransferable().getTransferDataFlavors(); ! JTModuleTransferDataWrapper transfer = jtcUI.getCurrentTransfer(); ! ! if (transfer == null) { Transferable t = dtde.getTransferable(); if (t.isDataFlavorSupported(JTDragDrop.ModuleSelectionFlavor)) { try { ! transfer = (JTModuleTransferDataWrapper)t.getTransferData(JTDragDrop.ModuleSelectionFlavor); ! jtcUI.setCurrentTransfer(transfer); } catch (Throwable e) { ! jtcUI.setCurrentTransfer(null); } } else { ! // System.out.println("flavor not supported"); } } if (isMDDropOk(dtde.getDropAction(), dtde.getTransferable())) { dtde.acceptDrag(DnDConstants.ACTION_COPY); *************** *** 455,460 **** public void dragExit(DropTargetEvent dte) { ! jtcUI.updateDnDBoundingBox(null); ! jtcUI.transferData = null; } --- 474,478 ---- public void dragExit(DropTargetEvent dte) { ! jtcUI.setCurrentTransfer(null); } *************** *** 519,524 **** public void drop(DropTargetDropEvent dtde) { ! jtcUI.updateDnDBoundingBox(null); ! jtcUI.transferData = null; DataFlavor chosen = null; --- 537,541 ---- public void drop(DropTargetDropEvent dtde) { ! jtcUI.setCurrentTransfer(null); DataFlavor chosen = null; *************** *** 708,713 **** } ! jtcUI.transferData = new JTModuleTransferDataWrapper(this, jtc.getSelectedModules(), dndOrigin); ! dge.startDrag(DragSource.DefaultMoveDrop, jtcUI.transferData, this); } } --- 725,732 ---- } ! JTModuleTransferDataWrapper transfer = ! new JTModuleTransferDataWrapper(this, jtc.getSelectedModules(), dndOrigin); ! jtcUI.setCurrentTransfer(transfer); ! dge.startDrag(DragSource.DefaultMoveDrop, transfer, this); } } |