Is this your first time here? SwingWiki is a Java Swing Developer community site with an big archive of Swing-related usenet groups and mailing lists, but also tips, tricks and articles and book reviews written by your colleagues from around the world. If you came here through a search engine and did not find what you were looking for, make sure to check the wiki table of contents.

Re: DND using XML

From:"Jeff Higgins" [oohiggins@masked-domain]
Sent on:Sun, 4 May 2008 15:33:47 -0400

steve wrote:
> On Sat, 3 May 2008 19:33:49 +0800, Jeff Higgins wrote
> (in article <k7YSj.3$[YZ4.1@masked-domain]>):
>
>> http://java.sun.com/docs/books/tutorial/uiswing/dnd/index.html
>
> gosh, did you figure that out all by yourself.
>

Pretty good tutorial, don't chathink?

>
> "This section has been updated to reflect features and conventions of the
> latest release, JDK 6.0, but it is not yet final. We've published this
> preliminary version so you can get the most current information now, and
> so
> you can tell us (please!) about errors, omissions, or improvements we can
> make to this tutorial."
>
>
> so you think the best way forward is to implement code...

Yep.

> that is not finalised yet?

So what's holding you up? Oh, ignorance!

>
>
>
> moron!

He, he!







import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import javax.swing.Action;
import javax.swing.JFrame;
import javax.swing.JPopupMenu;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.text.DefaultEditorKit;
import org.apache.batik.util.gui.xmleditor.XMLTextEditor;

public class Launcher {

public static void main(String[] args) {

EventQueue.invokeLater(new Runnable() {
public void run() {
new GUI();
}
});
}

public static class GUI {

JPopupMenu contextMenu;

public GUI() {

XMLTextEditor leftEditorPane =
new XMLTextEditor();
leftEditorPane.setPreferredSize
(new Dimension(400, 400));

XMLTextEditor rightEditorPane =
new XMLTextEditor();
rightEditorPane.setPreferredSize
(new Dimension(400, 400));

JScrollPane leftScrollPane =
new JScrollPane(leftEditorPane);
JScrollPane rightScrollPane =
new JScrollPane(rightEditorPane);

JSplitPane splitPane = new JSplitPane();

splitPane.setRightComponent(rightScrollPane);
splitPane.setLeftComponent(leftScrollPane);

JFrame frame = new JFrame("XML DND");
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
frame.setLocationByPlatform(true);

frame.add(splitPane);

View leftView = new View(leftEditorPane);
[@masked-domain]("unused")
View rightView = new View(rightEditorPane);
leftView.setText(
"<?xml version="1.0" encoding="UTF-8"?>n" +
"<jackass>n" +
"t<moron>So easy any moron can do it.</moron>n" +
"t<moron>Well, except maybe you; har har.</moron>n" +
"</jackass>");
frame.pack();
frame.setVisible(true);
}
}

public static class View{

XMLTextEditor editorPane;
JPopupMenu contextMenu;

public View(XMLTextEditor editorPane) {
this.editorPane = editorPane;
createMenu();
ContextMenuMouseListener contextMenuMouseListener =
new ContextMenuMouseListener();
editorPane.addMouseListener(contextMenuMouseListener);
editorPane.setDragEnabled(true);
}

public void setText(String text) {
editorPane.setText(text);
}

private void createMenu() {
Action a;
a = editorPane.getActionMap()
.get(DefaultEditorKit.cutAction);
a.putValue(Action.NAME, "Cut");

a = editorPane.getActionMap()
.get(DefaultEditorKit.copyAction);
a.putValue(Action.NAME, "Copy");

a = editorPane.getActionMap()
.get(DefaultEditorKit.pasteAction);
a.putValue(Action.NAME, "Paste");

a = editorPane.getActionMap()
.get(DefaultEditorKit.selectAllAction);
a.putValue(Action.NAME, "Select All");

contextMenu = new JPopupMenu();
contextMenu.add(editorPane.getActionMap()
.get(DefaultEditorKit.cutAction));
contextMenu.add(editorPane.getActionMap()
.get(DefaultEditorKit.copyAction));
contextMenu.add(editorPane.getActionMap()
.get(DefaultEditorKit.pasteAction));
contextMenu.add(editorPane.getActionMap()
.get(DefaultEditorKit.selectAllAction));
}

class ContextMenuMouseListener
extends MouseAdapter {
public void mousePressed(MouseEvent e) {
if (e.isPopupTrigger()) {
contextMenu.show(e.getComponent(),
e.getX(), e.getY());
}
}
public void mouseReleased(MouseEvent e) {
if (e.isPopupTrigger()) {
contextMenu.show(e.getComponent(),
e.getX(), e.getY());
}
}
}
}
}


Found what you were looking for? If not - continue at Wiki Index

 
Recent changes | RSS changes | Table of contents | News Archive | Terms And Conditions | Register | The Quest For Software++| Ruby Resources
FitNesse Resources