public DataPanelContainer(TrackPanel trackPanel) {
    super(trackPanel);

    DropTarget target = new DropTarget(this, new FileDropTargetListener(trackPanel));
    setDropTarget(target);
    target.setActive(true);
    this.setLayout(new DataPanelLayout());
    this.parent = trackPanel;
    createDataPanels();
  }
 private static void addListener(JComponent comp, DropTargetListener listener) {
   DropTarget target = comp.getDropTarget();
   if (target == null) {
     comp.setDropTarget(new DropTarget(comp, listener));
   } else {
     try {
       target.addDropTargetListener(listener);
     } catch (TooManyListenersException e) {
       Log.log(e);
     }
   }
 }
Beispiel #3
0
  public void initialiseClassView() throws Exception {
    loadProperties();

    options = new OWLVizViewOptions(); // options specific to this view

    selectionModel = new OWLVizSelectionModel();
    setupExportFormats();
    closableTabs = new HashSet();
    componentGroupMap = new HashMap<OWLVizGraphPanel, List<GraphComponent>>();
    graphComponents = new HashSet<GraphComponent>();
    createOWLVizTabUI();

    DropTarget dt = new DropTarget(this, this);
    dt.setActive(true);
  }
  private void makeDropTarget(
      final java.io.PrintStream out, final java.awt.Component c, boolean recursive) {
    // Make drop target
    final java.awt.dnd.DropTarget dt = new java.awt.dnd.DropTarget();
    try {
      dt.addDropTargetListener(dropListener);
    } // end try
    catch (java.util.TooManyListenersException e) {
      e.printStackTrace();
      log(
          out,
          "FileDrop: Drop will not work due to previous error. Do you have another listener attached?");
    } // end catch

    // Listen for hierarchy changes and remove the drop target when the parent gets cleared out.
    c.addHierarchyListener(
        new java.awt.event.HierarchyListener() {

          public void hierarchyChanged(java.awt.event.HierarchyEvent evt) {
            log(out, "FileDrop: Hierarchy changed.");
            java.awt.Component parent = c.getParent();
            if (parent == null) {
              c.setDropTarget(null);
              log(out, "FileDrop: Drop target cleared from component.");
            } // end if: null parent
            else {
              new java.awt.dnd.DropTarget(c, dropListener);
              log(out, "FileDrop: Drop target added to component.");
            } // end else: parent not null
          } // end hierarchyChanged
        }); // end hierarchy listener
    if (c.getParent() != null) {
      new java.awt.dnd.DropTarget(c, dropListener);
    }

    if (recursive && (c instanceof java.awt.Container)) {
      // Get the container
      java.awt.Container cont = (java.awt.Container) c;

      // Get it's components
      java.awt.Component[] comps = cont.getComponents();

      // Set it's components as listeners also
      for (int i = 0; i < comps.length; i++) {
        makeDropTarget(out, comps[i], recursive);
      }
    } // end if: recursively set components as listener
  } // end dropListener
  protected JTable buildPropertiesTable() {
    propertiesModel = getPropertyHolderTableModel();
    propertiesTable = new PropertiesHolderJTable();
    propertiesTable.setName(PROPERTIES_HOLDER_TABLE_NAME);
    propertiesTable.putClientProperty("terminateEditOnFocusLost", Boolean.TRUE);
    propertiesTable
        .getSelectionModel()
        .addListSelectionListener(
            new ListSelectionListener() {
              public void valueChanged(ListSelectionEvent e) {
                int selectedRow = propertiesTable.getSelectedRow();
                if (removePropertyAction != null) {
                  removePropertyAction.setEnabled(selectedRow != -1);
                }

                if (movePropertyUpAction != null) {
                  movePropertyUpAction.setEnabled(selectedRow > 0);
                }

                if (movePropertyDownAction != null) {
                  movePropertyDownAction.setEnabled(
                      selectedRow >= 0 && selectedRow < propertiesTable.getRowCount() - 1);
                }
              }
            });

    propertiesTable.setDragEnabled(true);
    propertiesTable.setTransferHandler(new TransferHandler("testProperty"));

    if (getHolder().getModelItem() != null) {
      DropTarget dropTarget =
          new DropTarget(propertiesTable, new PropertyHolderTablePropertyExpansionDropTarget());
      dropTarget.setDefaultActions(DnDConstants.ACTION_COPY_OR_MOVE);
    }

    // Set render this only for value column. In this cell render we handle password shadowing.
    propertiesTable
        .getColumnModel()
        .getColumn(1)
        .setCellRenderer(new PropertiesTableCellRenderer());
    return propertiesTable;
  }
  /** @return */
  private static Component getActiveArea() {
    if (activeArea == null) {
      activeArea =
          new BufferedImagePanel() {
            public void paintComponent(Graphics g) {
              super.paintComponent(g);
              if (onlyPDFs == null) {
                return;
              }

              // draw list of file names
              final Graphics2D g2d = (Graphics2D) g;
              g2d.setRenderingHints(GraphicsUtils.getBestRenderingHints());
              g2d.setColor(TRANSLUCENT_GRAY);
              g2d.setFont(FONT);
              int stringY = (int) ((activeArea.getHeight() - onlyPDFs.size() * 40) / 2.0);
              for (File f : onlyPDFs) {
                g2d.drawString(f.getName(), 50, stringY);
                stringY += 50;
              }
            }
          };
      activeArea.setBorder(BorderFactory.createMatteBorder(10, 10, 10, 10, Color.LIGHT_GRAY));
      activeArea.setBackground(Color.DARK_GRAY);
      fileTransferHandler = new FileTransferHandler();
      activeArea.setTransferHandler(fileTransferHandler);

      try {
        dropTarget = new DropTarget();
        dropTarget.setComponent(activeArea);
        dropTarget.addDropTargetListener(getDropTargetAdapter());
      } catch (TooManyListenersException e) {
        e.printStackTrace();
      }

      pdfLogo = ImageCache.loadBufferedImage(PaperToolkit.getDataFile("icons/pdfIcon.png"));
    }
    return activeArea;
  }
  public PropertyHolderTable(TestPropertyHolder holder) {
    super(new BorderLayout());
    this.holder = holder;

    loadPropertiesAction = new LoadPropertiesAction();
    JScrollPane scrollPane = new JScrollPane(buildPropertiesTable());

    if (getHolder().getModelItem() != null) {
      DropTarget dropTarget =
          new DropTarget(scrollPane, new PropertyHolderTablePropertyExpansionDropTarget());
      dropTarget.setDefaultActions(DnDConstants.ACTION_COPY_OR_MOVE);
    }

    add(scrollPane, BorderLayout.CENTER);
    add(buildToolbar(), BorderLayout.NORTH);

    projectListener =
        new ProjectListenerAdapter() {
          public void environmentSwitched(Environment environment) {
            getPropertiesModel().fireTableDataChanged();
          }
        };
  }
  public DragDropTest_ModeMemoryStream() throws Exception {
    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    this.setBounds(0, 0, 400, 300);
    this.setVisible(true);
    this.setTitle("Example for MODE_MEMORY_STREAM");

    JLabel txt = new JLabel("Drop here");
    this.getContentPane().add(txt);
    txt.setVisible(true);

    JButton button = new JButton("Paste from clipboard");
    this.getContentPane().add(button, "South");

    DropTarget dropTarget = new DropTarget();
    dropTarget.setComponent(this);
    dropTarget.addDropTargetListener(
        new DropTargetAdapter() {
          @Override
          public void dragEnter(java.awt.dnd.DropTargetDragEvent dtde) {
            boolean dropFiles =
                dtde.getTransferable().isDataFlavorSupported(DataFlavor.javaFileListFlavor);
            dropFiles |= OutlookDD.isDataAvail(); // true, if this is a D&D operation from Outlook
            System.out.println("enter: file list avail=" + dropFiles);
            super.dragEnter(dtde);
          };

          @Override
          public void dragOver(java.awt.dnd.DropTargetDragEvent dtde) {
            boolean dropFiles =
                dtde.getTransferable().isDataFlavorSupported(DataFlavor.javaFileListFlavor);
            dropFiles |= OutlookDD.isDataAvail(); // true, if this is a D&D operation from Outlook
            System.out.println("over: file list avail=" + dropFiles);

            int action = dtde.getDropAction();
            if (!dropFiles) action = DnDConstants.ACTION_NONE;

            // Un-comment this line, if you do not want to remove the Email from Outlook:
            // if (action == DnDConstants.ACTION_MOVE) action = DnDConstants.ACTION_COPY;

            dtde.acceptDrag(action);

            super.dragOver(dtde);
          };

          public void drop(DropTargetDropEvent dtde) {
            try {

              int action = dtde.getDropAction();

              // Un-comment this line, if you do not want to remove the Email from Outlook:
              // if (action == DnDConstants.ACTION_MOVE) action = DnDConstants.ACTION_COPY;

              dtde.acceptDrop(action);

              Transferable t = dtde.getTransferable();
              if (OutlookDD.isDataAvail()) { // true, if this is a D&D operation from Outlook
                try {
                  OutlookData outlData = OutlookDD.getData();
                  handleOutlookData(outlData);
                } finally {
                  OutlookDD.release();
                }

                //          // Test: other heavyweight components do not disturb the D&D
                // functionality
                //          SwingUtilities.invokeLater(new Runnable() {
                //            public void run() {
                //              for (int i = 0; i < 3; i++) {
                //                 JDialog dlg = new JDialog();
                //                 dlg.setBounds(10,10, 300, 300);
                //                 dlg.setTitle("Dialog");
                //                 JTextField txt = new JTextField();
                //                 dlg.add(txt);
                //                 dlg.setVisible(true);
                //              }
                //            }
                //           });

              } else if (t.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {

                List<?> list = (List<?>) t.getTransferData(DataFlavor.javaFileListFlavor);
                for (Object o : list) {
                  System.out.println("file=" + o);
                }
              }

            } catch (Exception e) {
              e.printStackTrace();
            } finally {
              dtde.dropComplete(true);
            }
          }
        });

    // On-click-handler for button "Paste..."
    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(ActionEvent evt) {

            // First check for Outlook clipboard data
            if (OutlookDD.isClipboardDataAvail()) {
              try {
                OutlookData outlData = OutlookDD.getClipboardData();
                handleOutlookData(outlData);
              } catch (Exception e) {
                e.printStackTrace();
              } finally {
                OutlookDD.release();
              }
            }

            // Handle other clipboard formats using the
            // AWT clipboard functions.
            else {
              String text = getTextFromSystemClipboard();
              System.out.println("text from clipboard=" + text);
            }
          }
        });
  }
  public GraphDesktopController(
      GraphDesktopListener listener,
      ISession session,
      GraphPlugin plugin,
      ModeManager modeManager,
      boolean showDndDesktopImageAtStartup) {
    _listener = listener;
    _session = session;
    _plugin = plugin;
    _graphPluginResources = new GraphPluginResources(_plugin);

    ImageIcon startUpImage = null;

    if (showDndDesktopImageAtStartup) {
      startUpImage = _graphPluginResources.getIcon(GraphPluginResources.IKeys.DND);
    }

    _desktopPane = new GraphDesktopPane(_session.getApplication(), startUpImage);
    _desktopPane.setBackground(Color.white);

    _modeManager = modeManager;

    DropTarget dt = new DropTarget();

    try {
      dt.addDropTargetListener(
          new DropTargetAdapter() {
            public void drop(DropTargetDropEvent dtde) {
              onTablesDroped(dtde);
            }
          });
    } catch (TooManyListenersException e) {
      throw new RuntimeException(e);
    }

    _desktopPane.setDropTarget(dt);

    _desktopPane.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            onMouseClicked(e);
          }

          public void mousePressed(MouseEvent e) {
            onMousePressed(e);
          }

          public void mouseReleased(MouseEvent e) {
            onMouseReleased(e);
          }
        });

    _desktopPane.addMouseMotionListener(
        new MouseMotionAdapter() {
          public void mouseDragged(MouseEvent e) {
            onMouseDragged(e);
          }
        });

    createPopUp();
  }