Solved

flowchart

Posted on 2006-11-26
13
501 Views
Last Modified: 2012-06-27
Hi I am wondering if there is any example of flowchart program in java that I can see? I tried looking up on the internet but I cannot find anything. I need some ideas how to create a flowchart in java with icons. I was thinking to add loops or if statement in my program. Any idea?
0
Comment
Question by:shahrine99
  • 6
  • 4
  • 2
  • +1
13 Comments
 
LVL 92

Expert Comment

by:objects
Comment Utility
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
http://www.jgraph.com/ comes with source code.
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
0
 

Author Comment

by:shahrine99
Comment Utility
girionis..i checked your link..its good. i like it how it comes with source code..is there any other websites that u might know?
0
 

Author Comment

by:shahrine99
Comment Utility
girionis the link you gave..i downloaded it and i tried compiling the migrate program and i got some errors..i tried fixing it but same error..here are the example of error messages i got..i am copying and pasting here:

-bash-3.00$ javac TransferHandler.java
TransferHandler.java:77: getTransferHandler() in org.jgraph.plaf.basic.TransferHandler.JAdapterComponent cannot override getTransferHandler() in javax.swing.JComponent; attempting to use incompatible return type
found   : org.jgraph.plaf.basic.TransferHandler
required: javax.swing.TransferHandler
        public TransferHandler getTransferHandler() {
                               ^
TransferHandler.java:325: warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
        value = reader.invoke(component, null);
                                         ^
Note: TransferHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
1 error
1 warning

Any clue?
0
 
LVL 14

Expert Comment

by:hoomanv
Comment Utility
Change this line
    public TransferHandler getTransferHandler() {
To
    public javax.swing.TransferHandler getTransferHandler() {
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 

Author Comment

by:shahrine99
Comment Utility
hey hoomany, i changed my line like you told me to and i got more errors..this is what i got after i changed and complied:

-bash-3.00$ javac TransferHandler.java
TransferHandler.java:50: org.jgraph.plaf.basic.TransferHandler.JAdapterComponent is not abstract and does not override abstract method getTransferHandler() in org.jgraph.plaf.basic.TransferHandler.JDNDAdapter
        public static class JAdapterComponent
                      ^
TransferHandler.java:77: getTransferHandler() in org.jgraph.plaf.basic.TransferHandler.JAdapterComponent cannot implement getTransferHandler() in org.jgraph.plaf.basic.TransferHandler.JDNDAdapter; attempting to use incompatible return type
found   : javax.swing.TransferHandler
required: org.jgraph.plaf.basic.TransferHandler
public javax.swing.TransferHandler getTransferHandler() {
                                   ^
TransferHandler.java:78: incompatible types
found   : org.jgraph.plaf.basic.TransferHandler
required: javax.swing.TransferHandler
                        return transfer;
                               ^
TransferHandler.java:325: warning: non-varargs call of varargs method with inexact argument type for last parameter;
cast to java.lang.Object for a varargs call
cast to java.lang.Object[] for a non-varargs call and to suppress this warning
        value = reader.invoke(component, null);
                                         ^
Note: TransferHandler.java uses unchecked or unsafe operations.
Note: Recompile with -Xlint:unchecked for details.
3 errors
1 warning
0
 

Author Comment

by:shahrine99
Comment Utility
To make it easier for you to help me, I have copied and pasted the program below. My message that I posted prior to this is what I need help.

package org.jgraph.plaf.basic;

import java.awt.datatransfer.Clipboard;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.awt.dnd.DnDConstants;
import java.awt.dnd.DragGestureEvent;
import java.awt.dnd.DragGestureListener;
import java.awt.dnd.DragGestureRecognizer;
import java.awt.dnd.DragSource;
import java.awt.dnd.DragSourceContext;
import java.awt.dnd.DragSourceDragEvent;
import java.awt.dnd.DragSourceDropEvent;
import java.awt.dnd.DragSourceEvent;
import java.awt.dnd.DragSourceListener;
import java.awt.dnd.DropTarget;
import java.awt.dnd.DropTargetDragEvent;
import java.awt.dnd.DropTargetDropEvent;
import java.awt.dnd.DropTargetEvent;
import java.awt.dnd.DropTargetListener;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.awt.event.MouseEvent;
import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.io.Serializable;
import java.lang.reflect.Method;
import java.util.TooManyListenersException;

import javax.swing.AbstractAction;
import javax.swing.Action;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.event.EventListenerList;
import javax.swing.plaf.UIResource;

/**
 * This compatibility class is required by JGraph for Java 1.3
 */

public class TransferHandler implements Serializable {

      // Adapter
      public static interface JDNDAdapter {

            TransferHandler getTransferHandler();

      }

      public static class JAdapterComponent
            extends JComponent
            implements JDNDAdapter {


            protected TransferHandler transfer = null;

            public void setTransferHandler(TransferHandler newHandler) {
                  TransferHandler oldHandler = transfer;
                  transfer = newHandler;

                  DropTarget dropHandler = getDropTarget();
                  if ((dropHandler == null) || (dropHandler instanceof UIResource)) {
                        if (newHandler == null) {
                              setDropTarget(null);
                        } else {
                              setDropTarget(new TransferHandler.SwingDropTarget(this));
                        }
                  }
                  firePropertyChange("transferHandler", oldHandler, transfer);
            }

            public TransferHandler getTransferHandler() {
                  return transfer;
            }

      }

      /**
       * An <code>int</code> representing no transfer action.
       */
      public static final int NONE = DnDConstants.ACTION_NONE;

      /**
       * An <code>int</code> representing a &quot;copy&quot; transfer action.
       * This value is used when data is copied to a clipboard
       * or copied elsewhere in a drag and drop operation.
       */
      public static final int COPY = DnDConstants.ACTION_COPY;

      /**
       * An <code>int</code> representing a &quot;move&quot; transfer action.
       * This value is used when data is moved to a clipboard (i.e. a cut)
       * or moved elsewhere in a drag and drop operation.
       */
      public static final int MOVE = DnDConstants.ACTION_MOVE;

      /**
       * An <code>int</code> representing a source action capability of either
       * &quot;copy&quot; or &quot;move&quot;.
       */
      public static final int COPY_OR_MOVE = DnDConstants.ACTION_COPY_OR_MOVE;

      /**
       * Returns an <code>Action</code> that behaves like a 'cut' operation.
       * That is, this will invoke <code>exportToClipboard</code> with
       * a <code>MOVE</code> argument on the <code>TransferHandler</code>
       * associated with the <code>JComponent</code> that is the source of
       * the <code>ActionEvent</code>.
       *
       * @return cut Action
       */
      public static Action getCutAction() {
            return cutAction;
      }

      /**
       * Returns an <code>Action</code> that behaves like a 'copy' operation.
       * That is, this will invoke <code>exportToClipboard</code> with
       * a <code>COPY</code> argument on the <code>TransferHandler</code>
       * associated with the <code>JComponent</code> that is the source of
       * the <code>ActionEvent</code>.
       *
       * @return cut Action
       */
      public static Action getCopyAction() {
            return copyAction;
      }

      /**
       * Returns an <code>Action</code> that behaves like a 'paste' operation.
       * That is, this will invoke <code>importData</code> on the
       * <code>TransferHandler</code>
       * associated with the <code>JComponent</code> that is the source of
       * the <code>ActionEvent</code>.
       *
       * @return cut Action
       */
      public static Action getPasteAction() {
            return pasteAction;
      }

      /**
       * Constructs a transfer handler that can transfer a Java Bean property
       * from one component to another via the clipboard or a drag and drop
       * operation.
       *
       * @param property  the name of the property to transfer; this can
       *  be <code>null</code> if there is no property associated with the transfer
       *  handler (a subclass that performs some other kind of transfer, for example)
       */
      public TransferHandler(String property) {
            propertyName = property;
      }

      /**
       * Convenience constructor for subclasses.
       */
      protected TransferHandler() {
            this(null);
      }

      /**
       * Causes the Swing drag support to be initiated.  This is called by
       * the various UI implementations in the <code>javax.swing.plaf.basic</code>
       * package if the dragEnabled property is set on the component.
       * This can be called by custom UI
       * implementations to use the Swing drag support.  This method can also be called
       * by a Swing extension written as a subclass of <code>JComponent</code>
       * to take advantage of the Swing drag support.
       * <p>
       * The transfer <em>will not necessarily</em> have been completed at the
       * return of this call (i.e. the call does not block waiting for the drop).
       * The transfer will take place through the Swing implementation of the
       * <code>java.awt.dnd</code> mechanism, requiring no further effort
       * from the developer. The <code>exportDone</code> method will be called
       * when the transfer has completed.
       *
       * @param comp  the component holding the data to be transferred; this
       *  argument is provided to enable sharing of <code>TransferHandler</code>s by
       *  multiple components
       * @param e     the event that triggered the transfer
       * @param action the transfer action initially requested; this should
       *  be a value of either <code>COPY</code> or <code>MOVE</code>;
       *  the value may be changed during the course of the drag operation
       */
      public void exportAsDrag(JComponent comp, InputEvent e, int action) {
            int srcActions = getSourceActions(comp);
            int dragAction = srcActions & action;
            if (!(e instanceof MouseEvent)) {
                  // only mouse events supported for drag operations
                  dragAction = NONE;
            }
            if (dragAction != NONE) { // && !GraphicsEnvironment.isHeadless()) {
                  if (recognizer == null) {
                        recognizer = new SwingDragGestureRecognizer(new DragHandler());
                  }
                  recognizer.gestured(comp, (MouseEvent) e, srcActions, dragAction);
            } else {
                  exportDone(comp, null, NONE);
            }
      }

      /**
       * Causes a transfer from the given component to the
       * given clipboard.  This method is called by the default cut and
       * copy actions registered in a component's action map.  
       * <p>
       * The transfer <em>will</em> have been completed at the
       * return of this call.  The transfer will take place using the
       * <code>java.awt.datatransfer</code> mechanism,
       * requiring no further effort from the developer.
       * The <code>exportDone</code> method will be called when the
       * transfer has completed.
       *
       * @param comp  the component holding the data to be transferred; this
       *  argument is provided to enable sharing of <code>TransferHandler</code>s by
       *  multiple components
       * @param clip  the clipboard to transfer the data into  
       * @param action the transfer action requested; this should
       *  be a value of either <code>COPY</code> or <code>MOVE</code>;
       *  the operation performed is the intersection  of the transfer
       *  capabilities given by getSourceActions and the requested action;
       *  the intersection may result in an action of <code>NONE</code>
       *  if the requested action isn't supported
       */
      public void exportToClipboard(
            JComponent comp,
            Clipboard clip,
            int action) {
            boolean exportSuccess = false;
            Transferable t = null;

            int clipboardAction = getSourceActions(comp) & action;
            if (clipboardAction != NONE) {
                  t = createTransferable(comp);
                  if (t != null) {
                        clip.setContents(t, null);
                        exportSuccess = true;
                  }
            }

            if (exportSuccess) {
                  exportDone(comp, t, clipboardAction);
            } else {
                  exportDone(comp, null, NONE);
            }
      }

      /**
       * Causes a transfer to a component from a clipboard or a
       * DND drop operation.  The <code>Transferable</code> represents
       * the data to be imported into the component.  
       *
       * @param comp  the component to receive the transfer; this
       *  argument is provided to enable sharing of <code>TransferHandler</code>s
       *  by multiple components
       * @param t     the data to import
       * @return  true if the data was inserted into the component, false otherwise
       */
      public boolean importData(JComponent comp, Transferable t) {
            PropertyDescriptor prop = getPropertyDescriptor(comp);
            if (prop != null) {
                  Method writer = prop.getWriteMethod();
                  if (writer == null) {
                        // read-only property. ignore
                        return false;
                  }
                  Class[] params = writer.getParameterTypes();
                  if (params.length != 1) {
                        // zero or more than one argument, ignore
                        return false;
                  }
                  DataFlavor flavor =
                        getPropertyDataFlavor(params[0], t.getTransferDataFlavors());
                  if (flavor != null) {
                        try {
                              Object value = t.getTransferData(flavor);
                              Object[] args = { value };
                              writer.invoke(comp, args);
                              return true;
                        } catch (Exception ex) {
                              System.err.println("Invocation failed");
                              // invocation code
                        }
                  }
            }
            return false;
      }

      /**
       * Indicates whether a component would accept an import of the given
       * set of data flavors prior to actually attempting to import it.
       *
       * @param comp  the component to receive the transfer; this
       *  argument is provided to enable sharing of <code>TransferHandlers</code>
       *  by multiple components
       * @param transferFlavors  the data formats available
       * @return  true if the data can be inserted into the component, false otherwise
       */
      public boolean canImport(JComponent comp, DataFlavor[] transferFlavors) {
            PropertyDescriptor prop = getPropertyDescriptor(comp);
            if (prop != null) {
                  Method writer = prop.getWriteMethod();
                  if (writer == null) {
                        // read-only property. ignore
                        return false;
                  }
                  Class[] params = writer.getParameterTypes();
                  if (params.length != 1) {
                        // zero or more than one argument, ignore
                        return false;
                  }
                  DataFlavor flavor =
                        getPropertyDataFlavor(params[0], transferFlavors);
                  if (flavor != null) {
                        return true;
                  }
            }
            return false;
      }

      /**
       * Returns the type of transfer actions supported by the source.
       * Some models are not mutable, so a transfer operation of <code>COPY</code>
       * only should be advertised in that case.
       *
       * @param c  the component holding the data to be transferred; this
       *  argument is provided to enable sharing of <code>TransferHandler</code>s
       *  by multiple components.
       * @return  <code>COPY</code> if the transfer property can be found,
       *  otherwise returns <code>NONE</code>; a return value of
       *  of <code>NONE</code> disables any transfers out of the component
       */
      public int getSourceActions(JComponent c) {
            PropertyDescriptor prop = getPropertyDescriptor(c);
            if (prop != null) {
                  return COPY;
            }
            return NONE;
      }

      /**
       * Returns an object that establishes the look of a transfer.  This is
       * useful for both providing feedback while performing a drag operation and for
       * representing the transfer in a clipboard implementation that has a visual
       * appearance.  The implementation of the <code>Icon</code> interface should
       * not alter the graphics clip or alpha level.
       * The icon implementation need not be rectangular or paint all of the
       * bounding rectangle and logic that calls the icons paint method should
       * not assume the all bits are painted. <code>null</code> is a valid return value
       * for this method and indicates there is no visual representation provided.
       * In that case, the calling logic is free to represent the
       * transferable however it wants.  
       * <p>
       * The default Swing logic will not do an alpha blended drag animation if
       * the return is <code>null</code>.
       *
       * @param t  the data to be transferred; this value is expected to have been
       *  created by the <code>createTransferable</code> method
       * @return  <code>null</code>, indicating
       *    there is no default visual representation
       */
      public Icon getVisualRepresentation(Transferable t) {
            return null;
      }

      /**
       * Creates a <code>Transferable</code> to use as the source for
       * a data transfer. Returns the representation of the data to
       * be transferred, or <code>null</code> if the component's
       * property is <code>null</code>
       *
       * @param c  the component holding the data to be transferred; this
       *  argument is provided to enable sharing of <code>TransferHandler</code>s
       *  by multiple components
       * @return  the representation of the data to be transferred, or
       *  <code>null</code> if the property associated with <code>c</code>
       *  is <code>null</code>
       *  
       */
      protected Transferable createTransferable(JComponent c) {
            PropertyDescriptor property = getPropertyDescriptor(c);
            if (property != null) {
                  return new PropertyTransferable(property, c);
            }
            return null;
      }

      /**
       * Invoked after data has been exported.  This method should remove
       * the data that was transferred if the action was <code>MOVE</code>.
       * <p>
       * This method is implemented to do nothing since <code>MOVE</code>
       * is not a supported action of this implementation
       * (<code>getSourceActions</code> does not include <code>MOVE</code>).
       *
       * @param source the component that was the source of the data
       * @param data   The data that was transferred or possibly null
       *               if the action is <code>NONE</code>.
       * @param action the actual action that was performed  
       */
      protected void exportDone(
            JComponent source,
            Transferable data,
            int action) {
      }

      /**
       * Fetches the property descriptor for the property assigned to this transfer
       * handler on the given component (transfer handler may be shared).  This
       * returns <code>null</code> if the property descriptor can't be found
       * or there is an error attempting to fetch the property descriptor.
       */
      private PropertyDescriptor getPropertyDescriptor(JComponent comp) {
            if (propertyName == null) {
                  return null;
            }
            Class k = comp.getClass();
            BeanInfo bi;
            try {
                  bi = Introspector.getBeanInfo(k);
            } catch (IntrospectionException ex) {
                  return null;
            }
            PropertyDescriptor props[] = bi.getPropertyDescriptors();
            for (int i = 0; i < props.length; i++) {
                  if (propertyName.equals(props[i].getName())) {
                        Method reader = props[i].getReadMethod();

                        if (reader != null) {
                              Class[] params = reader.getParameterTypes();

                              if (params == null || params.length == 0) {
                                    // found the desired descriptor
                                    return props[i];
                              }
                        }
                  }
            }
            return null;
      }

      /**
       * Fetches the data flavor from the array of possible flavors that
       * has data of the type represented by property type.  Null is
       * returned if there is no match.
       */
      private DataFlavor getPropertyDataFlavor(Class k, DataFlavor[] flavors) {
            for (int i = 0; i < flavors.length; i++) {
                  DataFlavor flavor = flavors[i];
                  if ("application".equals(flavor.getPrimaryType())
                        && "x-java-jvm-local-objectref".equals(flavor.getSubType())
                        && k.isAssignableFrom(flavor.getRepresentationClass())) {

                        return flavor;
                  }
            }
            return null;
      }

      private String propertyName;
      private static SwingDragGestureRecognizer recognizer = null;
      private static DropTargetListener dropLinkage = null;

      private static DropTargetListener getDropTargetListener() {
            if (dropLinkage == null) {
                  dropLinkage = new DropHandler();
            }
            return dropLinkage;
      }

      static class PropertyTransferable implements Transferable {

            PropertyTransferable(PropertyDescriptor p, JComponent c) {
                  property = p;
                  component = c;
            }

            // --- Transferable methods ----------------------------------------------

            /**
             * Returns an array of <code>DataFlavor</code> objects indicating the flavors the data
             * can be provided in.  The array should be ordered according to preference
             * for providing the data (from most richly descriptive to least descriptive).
             * @return an array of data flavors in which this data can be transferred
             */
            public DataFlavor[] getTransferDataFlavors() {
                  DataFlavor[] flavors = new DataFlavor[1];
                  Class propertyType = property.getPropertyType();
                  String mimeType =
                        DataFlavor.javaJVMLocalObjectMimeType
                              + ";class="
                              + propertyType.getName();
                  try {
                        flavors[0] = new DataFlavor(mimeType);
                  } catch (ClassNotFoundException cnfe) {
                        flavors = new DataFlavor[0];
                  }
                  return flavors;
            }

            /**
             * Returns whether the specified data flavor is supported for
             * this object.
             * @param flavor the requested flavor for the data
             * @return true if this <code>DataFlavor</code> is supported,
                 *   otherwise false
             */
            public boolean isDataFlavorSupported(DataFlavor flavor) {
                  Class propertyType = property.getPropertyType();
                  if ("application".equals(flavor.getPrimaryType())
                        && "x-java-jvm-local-objectref".equals(flavor.getSubType())
                        && flavor.getRepresentationClass().isAssignableFrom(
                              propertyType)) {

                        return true;
                  }
                  return false;
            }

            /**
             * Returns an object which represents the data to be transferred.  The class
             * of the object returned is defined by the representation class of the flavor.
             *
             * @param flavor the requested flavor for the data
             * @see DataFlavor#getRepresentationClass
             * @exception IOException                if the data is no longer available
             *              in the requested flavor.
             * @exception UnsupportedFlavorException if the requested data flavor is
             *              not supported.
             */
            public Object getTransferData(DataFlavor flavor)
                  throws UnsupportedFlavorException, IOException {
                  if (!isDataFlavorSupported(flavor)) {
                        throw new UnsupportedFlavorException(flavor);
                  }
                  Method reader = property.getReadMethod();
                  Object value = null;
                  try {
                        value = reader.invoke(component, null);
                  } catch (Exception ex) {
                        throw new IOException(
                              "Property read failed: " + property.getName());
                  }
                  return value;
            }

            JComponent component;
            PropertyDescriptor property;
      }

      /**
       * This is the default drop target for drag and drop operations if
       * one isn't provided by the developer.  <code>DropTarget</code>
       * only supports one <code>DropTargetListener</code> and doesn't
       * function properly if it isn't set.
       * This class sets the one listener as the linkage of drop handling
       * to the <code>TransferHandler</code>, and adds support for
       * additional listeners which some of the <code>ComponentUI</code>
       * implementations install to manipulate a drop insertion location.
       */
      public static class SwingDropTarget
            extends DropTarget
            implements UIResource {

            public SwingDropTarget(JComponent c) {
                  super();
                  setComponent(c);
                  try {
                        super.addDropTargetListener(getDropTargetListener());
                  } catch (TooManyListenersException tmle) {
                  }
            }

            public void addDropTargetListener(DropTargetListener dtl)
                  throws TooManyListenersException {
                  // Since the super class only supports one DropTargetListener,
                  // and we add one from the constructor, we always add to the
                  // extended list.
                  if (listenerList == null) {
                        listenerList = new EventListenerList();
                  }
                  listenerList.add(DropTargetListener.class, dtl);
            }

            public void removeDropTargetListener(DropTargetListener dtl) {
                  if (listenerList != null) {
                        listenerList.remove(DropTargetListener.class, dtl);
                  }
            }

            // --- DropTargetListener methods (multicast) --------------------------

            public void dragEnter(DropTargetDragEvent e) {
                  super.dragEnter(e);
                  if (listenerList != null) {
                        Object[] listeners = listenerList.getListenerList();
                        for (int i = listeners.length - 2; i >= 0; i -= 2) {
                              if (listeners[i] == DropTargetListener.class) {
                                    ((DropTargetListener) listeners[i + 1]).dragEnter(e);
                              }
                        }
                  }
            }

            public void dragOver(DropTargetDragEvent e) {
                  super.dragOver(e);
                  if (listenerList != null) {
                        Object[] listeners = listenerList.getListenerList();
                        for (int i = listeners.length - 2; i >= 0; i -= 2) {
                              if (listeners[i] == DropTargetListener.class) {
                                    ((DropTargetListener) listeners[i + 1]).dragOver(e);
                              }
                        }
                  }
            }

            public void dragExit(DropTargetEvent e) {
                  super.dragExit(e);
                  if (listenerList != null) {
                        Object[] listeners = listenerList.getListenerList();
                        for (int i = listeners.length - 2; i >= 0; i -= 2) {
                              if (listeners[i] == DropTargetListener.class) {
                                    ((DropTargetListener) listeners[i + 1]).dragExit(e);
                              }
                        }
                  }
            }

            public void drop(DropTargetDropEvent e) {
                  super.drop(e);
                  if (listenerList != null) {
                        Object[] listeners = listenerList.getListenerList();
                        for (int i = listeners.length - 2; i >= 0; i -= 2) {
                              if (listeners[i] == DropTargetListener.class) {
                                    ((DropTargetListener) listeners[i + 1]).drop(e);
                              }
                        }
                  }
            }

            public void dropActionChanged(DropTargetDragEvent e) {
                  super.dropActionChanged(e);
                  if (listenerList != null) {
                        Object[] listeners = listenerList.getListenerList();
                        for (int i = listeners.length - 2; i >= 0; i -= 2) {
                              if (listeners[i] == DropTargetListener.class) {
                                    (
                                          (DropTargetListener) listeners[i
                                                + 1]).dropActionChanged(
                                          e);
                              }
                        }
                  }
            }

            private EventListenerList listenerList;
      }

      private static class DropHandler
            implements DropTargetListener, Serializable {

            private boolean canImport;

            private boolean actionSupported(int action) {
                  return (action & COPY_OR_MOVE) != NONE;
            }

            // --- DropTargetListener methods -----------------------------------

            public void dragEnter(DropTargetDragEvent e) {
                  DataFlavor[] flavors = e.getCurrentDataFlavors();

                  JDNDAdapter c =
                        (JDNDAdapter) e.getDropTargetContext().getComponent();
                  TransferHandler importer = c.getTransferHandler();

                  if (importer != null
                        && importer.canImport((JComponent) c, flavors)) {
                        canImport = true;
                  } else {
                        canImport = false;
                  }

                  int dropAction = e.getDropAction();

                  if (canImport && actionSupported(dropAction)) {
                        e.acceptDrag(dropAction);
                  } else {
                        e.rejectDrag();
                  }
            }

            public void dragOver(DropTargetDragEvent e) {
                  int dropAction = e.getDropAction();

                  if (canImport && actionSupported(dropAction)) {
                        e.acceptDrag(dropAction);
                  } else {
                        e.rejectDrag();
                  }
            }

            public void dragExit(DropTargetEvent e) {
            }

            public void drop(DropTargetDropEvent e) {
                  int dropAction = e.getDropAction();

                  JDNDAdapter c =
                        (JDNDAdapter) e.getDropTargetContext().getComponent();
                  TransferHandler importer = c.getTransferHandler();

                  if (canImport && importer != null && actionSupported(dropAction)) {
                        e.acceptDrop(dropAction);

                        try {
                              Transferable t = e.getTransferable();
                              e.dropComplete(importer.importData((JComponent) c, t));
                        } catch (RuntimeException re) {
                              e.dropComplete(false);
                        }
                  } else {
                        e.rejectDrop();
                  }
            }

            public void dropActionChanged(DropTargetDragEvent e) {
                  int dropAction = e.getDropAction();

                  if (canImport && actionSupported(dropAction)) {
                        e.acceptDrag(dropAction);
                  } else {
                        e.rejectDrag();
                  }
            }
      }

      /**
       * This is the default drag handler for drag and drop operations that
       * use the <code>TransferHandler</code>.
       */
      private static class DragHandler
            implements DragGestureListener, DragSourceListener {

            private boolean scrolls;

            // --- DragGestureListener methods -----------------------------------

            /**
             * a Drag gesture has been recognized
             */
            public void dragGestureRecognized(DragGestureEvent dge) {
                  JDNDAdapter c = (JDNDAdapter) dge.getComponent();
                  TransferHandler th = c.getTransferHandler();
                  Transferable t = th.createTransferable((JComponent) c);
                  if (t != null) {
                        scrolls = ((JComponent) c).getAutoscrolls();
                        ((JComponent) c).setAutoscrolls(false);
                        try {
                              dge.startDrag(null, t, this);
                              return;
                        } catch (RuntimeException re) {
                              ((JComponent) c).setAutoscrolls(scrolls);
                        }
                  }

                  th.exportDone((JComponent) c, null, NONE);
            }

            // --- DragSourceListener methods -----------------------------------

            /**
             * as the hotspot enters a platform dependent drop site
             */
            public void dragEnter(DragSourceDragEvent dsde) {
            }

            /**
             * as the hotspot moves over a platform dependent drop site
             */
            public void dragOver(DragSourceDragEvent dsde) {
            }

            /**
             * as the hotspot exits a platform dependent drop site
             */
            public void dragExit(DragSourceEvent dsde) {
            }

            /**
             * as the operation completes
             */
            public void dragDropEnd(DragSourceDropEvent dsde) {
                  DragSourceContext dsc = dsde.getDragSourceContext();
                  JDNDAdapter c = (JDNDAdapter) dsc.getComponent();
                  if (dsde.getDropSuccess()) {
                        c.getTransferHandler().exportDone(
                              (JComponent) c,
                              dsc.getTransferable(),
                              dsde.getDropAction());
                  } else {
                        c.getTransferHandler().exportDone((JComponent) c, null, NONE);
                  }
                  ((JComponent) c).setAutoscrolls(scrolls);
            }

            public void dropActionChanged(DragSourceDragEvent dsde) {
            }
      }

      private static class SwingDragGestureRecognizer
            extends DragGestureRecognizer {

            SwingDragGestureRecognizer(DragGestureListener dgl) {
                  super(DragSource.getDefaultDragSource(), null, NONE, dgl);
            }

            void gestured(JComponent c, MouseEvent e, int srcActions, int action) {
                  setComponent(c);
                  setSourceActions(srcActions);
                  appendEvent(e);
                  fireDragGestureRecognized(action, e.getPoint());
            }

            /**
             * register this DragGestureRecognizer's Listeners with the Component
             */
            protected void registerListeners() {
            }

            /**
             * unregister this DragGestureRecognizer's Listeners with the Component
             *
             * subclasses must override this method
             */
            protected void unregisterListeners() {
            }

      }

      static final Action cutAction = new TransferAction("cut");
      static final Action copyAction = new TransferAction("copy");
      static final Action pasteAction = new TransferAction("paste");

      static class TransferAction extends AbstractAction implements UIResource {

            TransferAction(String name) {
                  super(name);
                  // Will cause the system clipboard state to be updated.
                  canAccessSystemClipboard = true;
                  canAccessSystemClipboard();
            }

            public void actionPerformed(ActionEvent e) {
                  Object src = e.getSource();
                  if (src instanceof JDNDAdapter) {
                        JDNDAdapter c = (JDNDAdapter) src;
                        TransferHandler th = c.getTransferHandler();
                        Clipboard clipboard = getClipboard((JComponent) c);
                        String name = (String) getValue(Action.NAME);
                        if ((clipboard != null) && (th != null) && (name != null)) {
                              if ("cut".equals(name)) {
                                    th.exportToClipboard((JComponent) c, clipboard, MOVE);
                              } else if ("copy".equals(name)) {
                                    th.exportToClipboard((JComponent) c, clipboard, COPY);
                              } else if ("paste".equals(name)) {
                                    Transferable trans = clipboard.getContents(null);
                                    if (trans != null) {
                                          th.importData((JComponent) c, trans);
                                    }
                              }
                        }
                  }
            }

            /**
             * Returns the clipboard to use for cut/copy/paste.
             */
            private Clipboard getClipboard(JComponent c) {
                  if (canAccessSystemClipboard()) {
                        return c.getToolkit().getSystemClipboard();
                  }
                  Clipboard clipboard =
                        (Clipboard) sun.awt.AppContext.getAppContext().get(
                              SandboxClipboardKey);
                  if (clipboard == null) {
                        clipboard = new Clipboard("Sandboxed Component Clipboard");
                        sun.awt.AppContext.getAppContext().put(
                              SandboxClipboardKey,
                              clipboard);
                  }
                  return clipboard;
            }

            /**
             * Returns true if it is safe to access the system Clipboard.
             * If the environment is headless or the security manager
             * does not allow access to the system clipboard, a private
             * clipboard is used.
             */
            private boolean canAccessSystemClipboard() {
                  if (canAccessSystemClipboard) {
                        if (false) { //(GraphicsEnvironment.isHeadless()) {
                              canAccessSystemClipboard = false;
                              return false;
                        }

                        SecurityManager sm = System.getSecurityManager();
                        if (sm != null) {
                              try {
                                    sm.checkSystemClipboardAccess();
                                    return true;
                              } catch (SecurityException se) {
                                    canAccessSystemClipboard = false;
                                    return false;
                              }
                        }
                        return true;
                  }
                  return false;
            }

            /**
             * Indicates if it is safe to access the system clipboard. Once false,
             * access will never be checked again.
             */
            private boolean canAccessSystemClipboard;

            /**
             * Key used in app context to lookup Clipboard to use if access to
             * System clipboard is denied.
             */
            private static Object SandboxClipboardKey = new Object();

      }

}
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
shahrine99 you have incompatibilites between the types you use. You need to specificalyl indicate which class you use by providing the full package name. For example here

TransferHandler.java:78: incompatible types
found   : org.jgraph.plaf.basic.TransferHandler
required: javax.swing.TransferHandler
                        return transfer;

you need to return either a javax.swing.TransferHandler or change the method to return a org.jgraph.plaf.basic.TransferHandler.
0
 

Author Comment

by:shahrine99
Comment Utility
huh?
0
 
LVL 35

Expert Comment

by:girionis
Comment Utility
It means that this line

> return transfer;

returns an object of type org.jgraph.plaf.basic.TransferHandler while you need to return an object of type javax.swing.TransferHandler.
0
 

Author Comment

by:shahrine99
Comment Utility
are saying instead of saying return transfer;
i should replace that to return javax.swing.TransferHandler; ?
0
 
LVL 35

Accepted Solution

by:
girionis earned 500 total points
Comment Utility
It depends on what you need to return. If you need to return a javax.swing.TransferHandler then you will have to change the methods signature to return this

public javax.swing.TransferHandler getTransferHandler() {
               return transfer;
          }

otherwise you will need to make your "transfer" object of type org.jgraph.plaf.basic.TransferHandler.

I think you are better off reading the basics of the java language first in order to understand what is going on: http://java.sun.com/docs/books/tutorial/java/index.html
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers will learn about arithmetic and Boolean expressions in Java and the logical operators used to create Boolean expressions. We will cover the symbols used for arithmetic expressions and define each logical operator and how to use them in Boole…
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.

744 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now