220N/A/*
2362N/A * Copyright (c) 2004, 2008, Oracle and/or its affiliates. All rights reserved.
220N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
220N/A *
220N/A * This code is free software; you can redistribute it and/or modify it
220N/A * under the terms of the GNU General Public License version 2 only, as
220N/A * published by the Free Software Foundation.
220N/A *
220N/A * This code is distributed in the hope that it will be useful, but WITHOUT
220N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
220N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
220N/A * version 2 for more details (a copy is included in the LICENSE file that
220N/A * accompanied this code).
220N/A *
220N/A * You should have received a copy of the GNU General Public License version
220N/A * 2 along with this work; if not, write to the Free Software Foundation,
220N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
220N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
220N/A */
220N/A
220N/Aimport java.awt.*;
220N/Aimport sun.awt.*;
220N/Aimport java.awt.event.*;
220N/Aimport java.lang.reflect.*;
220N/Aimport java.awt.dnd.*;
220N/Aimport java.awt.datatransfer.*;
220N/A
220N/Apublic class JavaClient {
220N/A ClientContainer cont;
220N/A public static void main(String[] args) {
220N/A if (System.getProperty("os.name").toLowerCase().startsWith("win")) {
220N/A return;
220N/A }
220N/A
220N/A // Enable testing extensions in XEmbed server
220N/A System.setProperty("sun.awt.xembed.testing", "true");
220N/A
220N/A boolean xtoolkit = "sun.awt.X11.XToolkit".equals(Toolkit.getDefaultToolkit().getClass().getName());
220N/A final EmbeddedFrame ef = createEmbeddedFrame(xtoolkit, Long.parseLong(args[0]));
220N/A ef.setBackground(new Color(100, 100, 200));
220N/A ef.setLayout(new BorderLayout());
220N/A ef.add(new ClientContainer(ef), BorderLayout.CENTER);
220N/A ef.pack();
220N/A ef.registerListeners();
220N/A ef.setVisible(true);
220N/A }
220N/A private static EmbeddedFrame createEmbeddedFrame(boolean xtoolkit, long window) {
220N/A try {
220N/A Class cl = (xtoolkit?Class.forName("sun.awt.X11.XEmbeddedFrame"):Class.forName("sun.awt.motif.MEmbeddedFrame"));
220N/A Constructor cons = cl.getConstructor(new Class[]{Long.TYPE, Boolean.TYPE});
220N/A return (EmbeddedFrame)cons.newInstance(new Object[] {window, true});
220N/A } catch (Exception e) {
220N/A e.printStackTrace();
220N/A throw new RuntimeException("Can't create embedded frame");
220N/A }
220N/A }
220N/A}
220N/A
220N/Aclass ClientContainer extends Container {
220N/A Window parent;
220N/A int width, height;
220N/A public ClientContainer(Window w) {
220N/A parent = w;
220N/A width = 500;
220N/A height = 50;
220N/A final TextField tf = new TextField(30);
220N/A
220N/A DragSource ds = new DragSource();
220N/A final DragSourceListener dsl = new DragSourceAdapter() {
220N/A public void dragDropEnd(DragSourceDropEvent dsde) {
220N/A }
220N/A };
220N/A final DragGestureListener dgl = new DragGestureListener() {
220N/A public void dragGestureRecognized(DragGestureEvent dge) {
220N/A dge.startDrag(null, new StringSelection(tf.getText()), dsl);
220N/A }
220N/A };
220N/A ds.createDefaultDragGestureRecognizer(tf, DnDConstants.ACTION_COPY, dgl);
220N/A
220N/A final DropTargetListener dtl = new DropTargetAdapter() {
220N/A public void drop(DropTargetDropEvent dtde) {
220N/A dtde.acceptDrop(DnDConstants.ACTION_COPY);
220N/A try {
220N/A tf.setText(tf.getText() + (String)dtde.getTransferable().getTransferData(DataFlavor.stringFlavor));
220N/A } catch (Exception e) {
220N/A }
220N/A }
220N/A };
220N/A final DropTarget dt = new DropTarget(tf, dtl);
220N/A
220N/A setLayout(new FlowLayout());
220N/A add(tf);
220N/A Button close = new Button("Close");
220N/A close.addActionListener(new ActionListener() {
220N/A public void actionPerformed(ActionEvent e) {
220N/A parent.dispose();
220N/A }
220N/A });
220N/A Button inc = new Button("Increase size");
220N/A inc.addActionListener(new ActionListener() {
220N/A public void actionPerformed(ActionEvent e) {
220N/A changeSize(10);
220N/A }
220N/A });
220N/A Button dec = new Button("Decrease size");
220N/A dec.addActionListener(new ActionListener() {
220N/A public void actionPerformed(ActionEvent e) {
220N/A changeSize(-10);
220N/A }
220N/A });
220N/A add(close);
220N/A add(inc);
220N/A add(dec);
220N/A }
220N/A void changeSize(int step) {
220N/A width += step;
220N/A height += step;
220N/A parent.pack();
220N/A }
220N/A public Dimension getPreferredSize() {
220N/A return new Dimension(width, height);
220N/A }
220N/A}