Example usage for java.awt.dnd DropTarget DropTarget

List of usage examples for java.awt.dnd DropTarget DropTarget

Introduction

In this page you can find the example usage for java.awt.dnd DropTarget DropTarget.

Prototype

public DropTarget(Component c, int ops, DropTargetListener dtl) throws HeadlessException 

Source Link

Document

Creates a DropTarget given the Component to associate itself with, an int representing the default acceptable action(s) to support, and a DropTargetListener to handle event processing.

Usage

From source file:Main.java

Main(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    source.setForeground(Color.red);
    getContentPane().add(source, BorderLayout.NORTH);

    target.addActionListener(this);
    getContentPane().add(target, BorderLayout.SOUTH);

    new DropTarget(target, DnDConstants.ACTION_COPY_OR_MOVE, this);

    setSize(205, 100);/*from   w w w.  j  a  v a2 s  . co  m*/

    setVisible(true);
}

From source file:Main.java

public Main(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    source.setForeground(Color.red);
    getContentPane().add(source, BorderLayout.NORTH);

    target.addActionListener(this);
    getContentPane().add(target, BorderLayout.SOUTH);

    new DropTarget(target, DnDConstants.ACTION_COPY_OR_MOVE, this);

    setSize(205, 100);//from   w w  w  . j  a va2 s  . c o  m

    setVisible(true);
}

From source file:MainClass.java

MainClass(String title) {
    super(title);
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    source.setForeground(Color.red);
    getContentPane().add(source, BorderLayout.NORTH);

    target.addActionListener(this);
    getContentPane().add(target, BorderLayout.SOUTH);

    new DropTarget(target, DnDConstants.ACTION_COPY_OR_MOVE, this);

    setSize(205, 100);/* w ww  .  j av a  2 s .  c om*/

    setVisible(true);
}

From source file:net.sf.jabref.external.ExternalFilePanel.java

public ExternalFilePanel(final JabRefFrame frame, final MetaData metaData, final EntryEditor entryEditor,
        final String fieldName, final OpenFileFilter off, final FieldEditor editor) {

    this.frame = frame;
    this.metaData = metaData;
    this.off = off;
    this.entryEditor = entryEditor;

    setLayout(new GridLayout(2, 2));

    JButton browseBut = new JButton(Localization.lang("Browse"));
    JButton download = new JButton(Localization.lang("Download"));
    JButton auto = new JButton(Localization.lang("Auto"));
    JButton xmp = new JButton(Localization.lang("Write XMP"));
    xmp.setToolTipText(Localization.lang("Write BibtexEntry as XMP-metadata to PDF."));

    browseBut.addActionListener(new ActionListener() {

        @Override/*from w  ww .  ja  v  a2 s . co  m*/
        public void actionPerformed(ActionEvent e) {
            browseFile(fieldName, editor);
            // editor.setText(chosenValue);
            entryEditor.storeFieldAction.actionPerformed(new ActionEvent(editor, 0, ""));
        }
    });

    download.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            downLoadFile(fieldName, editor, frame);
        }
    });

    auto.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            JabRefExecutorService.INSTANCE.execute(autoSetFile(fieldName, editor));
        }
    });
    xmp.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            pushXMP(fieldName, editor);
        }
    });

    add(browseBut);
    add(download);
    add(auto);
    add(xmp);

    // Add drag and drop support to the field
    if (editor != null) {
        ((JComponent) editor).setDropTarget(new DropTarget((Component) editor, DnDConstants.ACTION_NONE,
                new UrlDragDrop(entryEditor, frame, editor)));
    }
}

From source file:org.fanhongtao.filetools.HexViewPanel.java

public HexViewPanel() {
    super(new BorderLayout());

    textArea = new JTextArea();
    JScrollPane scrollPane = new JScrollPane(textArea);
    add(scrollPane);//w  w w.j a va  2  s .c o  m

    textArea.setEditable(false);
    textArea.append("Drop a file to here\n");
    textArea.setFont(new Font("Consolas", Font.PLAIN, 16));
    //         textArea.setFont(new Font("Courier New", Font.PLAIN, 16));
    new DropTarget(textArea, DnDConstants.ACTION_COPY, new FileDropper(new FileDropListener() {

        @Override
        public void onDropFile(File file) {
            showHex(file);
        }
    }));
}

From source file:org.pentaho.reporting.designer.core.ReportDesignerFrame.java

public ReportDesignerFrame() throws XulException {
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    final ImageIcon icon = IconLoader.getInstance().getProductIcon();
    if (icon != null) {
        setIconImage(icon.getImage());//from   ww w . jav a 2s  .  c o m
    }

    setTitle(Messages.getString("ReportDesignerFrame.Title"));
    addWindowListener(new WindowCloseHandler());

    viewController = new FrameViewController(this);
    context = new DefaultReportDesignerContext(viewController);
    viewController.initializeXulDesignerFrame(context);

    welcomePane = new WelcomePane(ReportDesignerFrame.this, getContext());
    fieldSelectorPaletteDialog = new FieldSelectorPaletteDialog(ReportDesignerFrame.this, getContext());

    statusBar = new StatusBar(context);

    reportEditorPane = new FancyTabbedPane();
    reportEditorPane.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT);
    reportEditorPane.getModel().addChangeListener(new ReportTabActivationHandler());
    reportEditorPane.addMouseListener(new ReportTabPanePopupHandler());

    dockingPane = new GlobalPane(false);
    dockingPane.setMainComponent(reportEditorPane);

    attributeEditorPanel = new ElementPropertiesPanel();
    attributeEditorPanel.setAllowAttributeCard(true);
    attributeEditorPanel.setReportDesignerContext(context);

    treePanel = new TreeSidePanel(context, attributeEditorPanel);

    initializeToolWindows();

    paletteToolBar = createPaletteToolBar();

    final JPanel contentPane = new JPanel();
    contentPane.setLayout(new BorderLayout());
    contentPane.add(context.getToolBar("main-toolbar"), BorderLayout.NORTH); // NON-NLS
    contentPane.add(dockingPane, BorderLayout.CENTER);
    contentPane.add(statusBar, BorderLayout.SOUTH);
    contentPane.add(paletteToolBar, BorderLayout.WEST);
    setContentPane(contentPane);

    setJMenuBar(createMenuBar());
    setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY_OR_MOVE, new DefaultDropTargetListener()));

    context.addPropertyChangeListener(ReportDesignerContext.ACTIVE_CONTEXT_PROPERTY,
            new ReportTabActivationHandler());
    context.addPropertyChangeListener(ReportDesignerContext.STATUS_TEXT_PROPERTY, new StatusTextHandler());
    context.addPropertyChangeListener(ReportDesignerContext.PAGE_PROPERTY, new PageTextHandler());
    context.addPropertyChangeListener(ReportDesignerContext.REPORT_RENDER_CONTEXT_PROPERTY,
            new ReportEditorContextHandler());

    Toolkit.getDefaultToolkit().addAWTEventListener(new DragSelectionToggleHandler(), AWTEvent.KEY_EVENT_MASK);

    if (MacOSXIntegration.MAC_OS_X) {
        try {
            final AboutAction aboutAction = new AboutAction();
            aboutAction.setReportDesignerContext(context);

            final SettingsAction settingsAction = new SettingsAction();
            settingsAction.setReportDesignerContext(context);

            final QuitAction quitAction = new QuitAction();
            quitAction.setReportDesignerContext(context);

            final OpenReportAction openReportAction = new OpenReportAction();
            openReportAction.setReportDesignerContext(context);

            MacOSXIntegration.setOpenFileAction(openReportAction);
            MacOSXIntegration.setAboutAction(aboutAction);
            MacOSXIntegration.setPreferencesAction(settingsAction);
            MacOSXIntegration.setQuitAction(quitAction);
        } catch (Throwable e) {
            DebugLog.log("Failed to activate MacOS-X integration", e); // NON-NLS
        }
    }

    visibleElementsUpdateHandler = new VisibleElementsUpdateHandler();
    WorkspaceSettings.getInstance().addSettingsListener(visibleElementsUpdateHandler);
}

From source file:org.rdv.datapanel.AbstractDataPanel.java

/**
 * Setup the drop target for channel subscription via drag-and-drop.
 *
 * @since  1.2/*w ww . j ava 2  s .c o  m*/
 */
void initDropTarget() {
    new DropTarget(component, DnDConstants.ACTION_LINK, this);
}

From source file:unikn.dbis.univis.visualization.graph.VGraph.java

/**
 * Creates a new VGraph with drop target action and a
 * tree layout cache.//from   w w  w .  j a v a2  s .  c o  m
 */
public VGraph() {
    setUI(new VGraphUI());

    setDropTarget(new DropTarget(this, DnDConstants.ACTION_COPY, new VGraphDropTargetListener()));

    setModel(model);
    setGraphLayoutCache(cache);
    setEditable(false);
    setMoveable(false);
    setSelectionEnabled(true);

    layout.setOrientation(SwingConstants.NORTH);
}

From source file:unikn.dbis.univis.visualization.pivottable.VPivotTable.java

public VPivotTable() {
    setBorder(new EtchedBorder());
    setPreferredSize(new Dimension(1000, 700));
    setLayout(new BorderLayout());
    setBackground(Color.white);//from  www .j  a  v  a2s .c  om

    /* *** First Row *** */
    JLabel jlabelMeasure = new JLabel("Measure:");
    jlabelMeasure.setVisible(false);
    JLabel jlabelX = new JLabel("X-Axis Elements:");
    JLabel forVerticalSpace = new JLabel(" ");
    panelFirstRow = new JPanel(new VTableLayout(3, 2, 3, 3));

    dropAreaMeasure = new JTextArea(textInMeasureBox);
    dropAreaMeasure.setToolTipText(textInMeasureBox);
    dropAreaMeasure.setForeground(Color.LIGHT_GRAY);
    dropAreaMeasure.setEditable(false);
    dropAreaMeasure.setPreferredSize(new Dimension(100, 20));
    dropAreaMeasure.setBorder(BorderFactory.createEtchedBorder(Color.WHITE, Color.LIGHT_GRAY));
    dropAreaMeasure.setVisible(false);

    dropAreaX = new JTextArea(textInXYBox);
    dropAreaX.setToolTipText(textInXYBox);
    dropAreaX.setForeground(Color.LIGHT_GRAY);
    dropAreaX.setEditable(false);
    dropAreaX.setPreferredSize(new Dimension(400, 20));
    dropAreaX.setBorder(BorderFactory.createEtchedBorder(Color.WHITE, Color.LIGHT_GRAY));

    panelFirstRow.add(jlabelMeasure);
    panelFirstRow.add(jlabelX);
    panelFirstRow.add(dropAreaMeasure);
    panelFirstRow.add(dropAreaX);
    panelFirstRow.add(forVerticalSpace);
    add(panelFirstRow, BorderLayout.NORTH);

    /* *** Second Row *** */
    JLabel jlabelY1 = new JLabel("Y-Axis");
    JLabel jlabelY2 = new JLabel("Elements:");
    panelSecondRow = new JPanel(new VTableLayout(1, 2, 3, 3));

    dropAreaY = new JTextArea(textInXYBox);
    dropAreaY.setToolTipText(textInXYBox);
    dropAreaY.setForeground(Color.LIGHT_GRAY);
    dropAreaY.setEditable(false);
    dropAreaY.setLineWrap(true);
    dropAreaY.setWrapStyleWord(true);
    dropAreaY.setPreferredSize(new Dimension(100, 400));
    dropAreaY.setBorder(BorderFactory.createEtchedBorder(Color.WHITE, Color.LIGHT_GRAY));

    JPanel panelY = new JPanel(new VTableLayout(3, 1, 1, 1));
    panelY.add(jlabelY1);
    panelY.add(jlabelY2);
    panelY.add(dropAreaY);
    panelSecondRow.add(panelY);
    add(panelSecondRow, BorderLayout.WEST);

    new DropTarget(dropAreaX, DnDConstants.ACTION_COPY_OR_MOVE, this);
    new DropTarget(dropAreaY, DnDConstants.ACTION_COPY_OR_MOVE, this);
}