Commit 6c18ec87 authored by Matt Tucker's avatar Matt Tucker Committed by matt

Fixed launcher bugs around drag and drop install of plugins (JM-268, JM-269).


git-svn-id: http://svn.igniterealtime.org/svn/repos/messenger/trunk@1298 b35dd754-fafc-0310-a699-88a17e54d16e
parent aef7183f
......@@ -198,9 +198,23 @@
<variables />
<customScriptLines />
</unixArchive>
<win32Archive name="Windows Archive" id="31" mediaFileName="" installDir="%APP_SHORT_NAME%" allLaunchers="false" includedJRE="" manualJREEntry="false">
<selectedLaunchers>
<launcher id="2" />
<launcher id="12" />
<launcher id="15" />
</selectedLaunchers>
<messageSet language="English" />
<exclude>
<entry location="bin/extra" launcher="false" />
<entry location="bin/messenger.bat" launcher="false" />
<entry location="bin/messenger.sh" launcher="false" />
</exclude>
<variables />
</win32Archive>
</mediaSets>
<buildIds buildAll="true">
<mediaSet refId="18" />
<mediaSet refId="31" />
</buildIds>
</install4j>
......@@ -16,36 +16,27 @@ import javax.swing.JFrame;
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.DragSource;
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.dnd.*;
import java.io.File;
import java.io.IOException;
import java.util.Iterator;
import java.util.List;
/**
* Creates a DroppableFrame. A droppable frame allows for DnD of file objects from the OS onto the actual frame
* via <code>File</code>
* A droppable frame allows for DnD of file objects from the OS onto the actual
* frame via <code>File</code>.
*/
public class DroppableFrame extends JFrame implements DropTargetListener, DragSourceListener, DragGestureListener {
private DropTarget dropTarget = new DropTarget(this, this);
public class DroppableFrame extends JFrame implements DropTargetListener, DragSourceListener,
DragGestureListener
{
private DragSource dragSource = DragSource.getDefaultDragSource();
/**
* Creates an Instance of the Droppable Frame.
* Creates a droppable rame.
*/
public DroppableFrame() {
new DropTarget(this, this);
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
......
/**
* $RCSfile$
* $Revision$
* $Date$
*
* Copyright (C) 2005 Jive Software. All rights reserved.
*
* This software is published under the terms of the GNU Public License (GPL),
* a copy of which is included in this distribution.
*/
package org.jivesoftware.messenger.launcher;
import javax.swing.*;
import java.awt.dnd.*;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.util.List;
import java.util.Iterator;
import java.io.File;
import java.io.IOException;
/**
* A droppable text pane allows for DnD of file objects from the OS onto the actual
* pane via <code>File</code>.
*
* @author Matt Tucker
*/
public abstract class DroppableTextPane extends JTextPane implements DropTargetListener,
DragSourceListener, DragGestureListener
{
private DragSource dragSource = DragSource.getDefaultDragSource();
/**
* Creates a droppable text pane.
*/
public DroppableTextPane() {
new DropTarget(this, this);
dragSource.createDefaultDragGestureRecognizer(this, DnDConstants.ACTION_COPY_OR_MOVE, this);
}
public void dragDropEnd(DragSourceDropEvent DragSourceDropEvent) {
}
public void dragEnter(DragSourceDragEvent DragSourceDragEvent) {
}
public void dragExit(DragSourceEvent DragSourceEvent) {
}
public void dragOver(DragSourceDragEvent DragSourceDragEvent) {
}
public void dropActionChanged(DragSourceDragEvent DragSourceDragEvent) {
}
public void dragEnter(DropTargetDragEvent dropTargetDragEvent) {
dropTargetDragEvent.acceptDrag(DnDConstants.ACTION_COPY_OR_MOVE);
}
public void dragExit(DropTargetEvent dropTargetEvent) {
}
public void dragOver(DropTargetDragEvent dropTargetDragEvent) {
}
public void dropActionChanged(DropTargetDragEvent dropTargetDragEvent) {
}
public void drop(DropTargetDropEvent dropTargetDropEvent) {
try {
Transferable transferable = dropTargetDropEvent.getTransferable();
if (transferable.isDataFlavorSupported(DataFlavor.javaFileListFlavor)) {
dropTargetDropEvent.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
List fileList = (List) transferable.getTransferData(DataFlavor.javaFileListFlavor);
Iterator iterator = fileList.iterator();
while (iterator.hasNext()) {
File file = (File) iterator.next();
if (file.isFile()) {
fileDropped(file);
}
if (file.isDirectory()) {
directoryDropped(file);
}
}
dropTargetDropEvent.getDropTargetContext().dropComplete(true);
}
else {
dropTargetDropEvent.rejectDrop();
}
}
catch (IOException io) {
io.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
catch (UnsupportedFlavorException ufe) {
ufe.printStackTrace();
dropTargetDropEvent.rejectDrop();
}
}
public void dragGestureRecognized(DragGestureEvent dragGestureEvent) {
}
/**
* Notified when a file has been dropped onto the frame.
*
* @param file the file that has been dropped.
*/
public void fileDropped(File file){
}
/**
* Notified when a directory has been dropped onto the frame.
*
* @param file the directory that has been dropped.
*/
public void directoryDropped(File file){
}
}
\ No newline at end of file
......@@ -13,7 +13,6 @@ package org.jivesoftware.messenger.launcher;
import org.jdesktop.jdic.tray.SystemTray;
import org.jdesktop.jdic.tray.TrayIcon;
import org.jivesoftware.util.JiveGlobals;
import org.jivesoftware.util.WebManager;
import org.jivesoftware.util.XMLProperties;
......@@ -136,7 +135,6 @@ public class Launcher {
catch (Exception e) {
}
mainPanel.setLayout(new BorderLayout());
cardPanel.setBackground(Color.white);
......@@ -312,7 +310,7 @@ public class Launcher {
// Setup command area
final ImageIcon icon = new ImageIcon(getClass().getClassLoader().getResource("splash2.gif"));
pane = new JTextPane() {
pane = new DroppableTextPane() {
public void paintComponent(Graphics g) {
final Dimension size = pane.getSize();
......@@ -327,6 +325,13 @@ public class Launcher {
setOpaque(false);
super.paintComponent(g);
}
public void fileDropped(File file) {
String fileName = file.getName();
if (fileName.endsWith(".jar") || fileName.endsWith(".war")) {
installPlugin(file);
}
}
};
pane.setEditable(false);
......@@ -391,7 +396,8 @@ public class Launcher {
while ((c = in.read()) != -1) {
try {
StyleConstants.setFontFamily(styles, "courier new");
pane.getDocument().insertString(pane.getDocument().getLength(), "" + (char)c, styles);
pane.getDocument().insertString(pane.getDocument().getLength(),
"" + (char)c, styles);
}
catch (BadLocationException e) {
}
......@@ -492,7 +498,7 @@ public class Launcher {
final SwingWorker installerThread = new SwingWorker() {
public Object construct() {
File pluginsDir = new File(JiveGlobals.getHomeDirectory(), "plugins");
File pluginsDir = new File(binDir.getParentFile(), "plugins");
String tempName = plugin.getName() + ".part";
File tempPluginsFile = new File(pluginsDir, tempName);
......
......@@ -243,46 +243,46 @@ public class WebManager extends WebBean {
}
/**
* Copies the contents at <CODE>src</CODE> to <CODE>dst</CODE>.
*/
public static void copy(URL src, File dst) throws IOException {
InputStream in = null;
OutputStream out = null;
* Copies the contents at <CODE>src</CODE> to <CODE>dst</CODE>.
*/
public static void copy(URL src, File dst) throws IOException {
InputStream in = null;
OutputStream out = null;
try {
in = src.openStream();
out = new FileOutputStream(dst);
dst.mkdirs();
copy(in, out);
}
finally {
try {
in = src.openStream();
out = new FileOutputStream(dst);
dst.mkdirs();
copy(in, out);
}
finally {
try {
if (in != null) in.close();
if (in != null) {
in.close();
}
catch (IOException e) {
}
try {
if (out != null) out.close();
}
catch (IOException e) {
}
catch (IOException e) { }
try {
if (out != null) {
out.close();
}
}
catch (IOException e) { }
}
}
/**
* Common code for copy routines. By convention, the streams are
* closed in the same method in which they were opened. Thus,
* this method does not close the streams when the copying is done.
*/
private static void copy(InputStream in, OutputStream out)
throws IOException {
final byte[] buffer = new byte[4096];
while (true) {
final int bytesRead = in.read(buffer);
if (bytesRead < 0) {
break;
}
out.write(buffer, 0, bytesRead);
/**
* Common code for copy routines. By convention, the streams are
* closed in the same method in which they were opened. Thus,
* this method does not close the streams when the copying is done.
*/
private static void copy(InputStream in, OutputStream out) throws IOException {
byte[] buffer = new byte[4096];
while (true) {
int bytesRead = in.read(buffer);
if (bytesRead < 0) {
break;
}
out.write(buffer, 0, bytesRead);
}
}
}
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment