Skip to content

Commit

Permalink
Remove use of System.out and System.err in favor of regular logging
Browse files Browse the repository at this point in the history
  • Loading branch information
matthiasblaesing committed Nov 25, 2018
1 parent e5b34ec commit e67cd22
Show file tree
Hide file tree
Showing 11 changed files with 3,625 additions and 1,973 deletions.
3 changes: 2 additions & 1 deletion CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ Release 5.1.1 (Next release)

Features
--------
* [#1038](https://github.com/java-native-access/jna/issues/1038): Improve exception when native library loading fails by preserving the original exceptions and messages - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#1038](https://github.com/java-native-access/jna/pull/1038): Improve exception when native library loading fails by preserving the original exceptions and messages - [@matthiasblaesing](https://github.com/matthiasblaesing).
* [#????](https://github.com/java-native-access/jna/pull/????): Remove use of `System.out` and `System.err` in favor of regular logging - [@matthiasblaesing](https://github.com/matthiasblaesing).

Bug Fixes
---------
Expand Down
7 changes: 6 additions & 1 deletion contrib/platform/src/com/sun/jna/platform/WindowUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@
import com.sun.jna.ptr.ByteByReference;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
* Provides additional features on a Java {@link Window}.
Expand Down Expand Up @@ -159,6 +161,8 @@
// 50% threshold, some might want zero/non-zero
public class WindowUtils {

private static final Logger LOG = Logger.getLogger(WindowUtils.class.getName());

private static final String TRANSPARENT_OLD_BG = "transparent-old-bg";
private static final String TRANSPARENT_OLD_OPAQUE = "transparent-old-opaque";
private static final String TRANSPARENT_ALPHA = "transparent-alpha";
Expand Down Expand Up @@ -1365,7 +1369,8 @@ private void fixWindowDragging(Window w, String context) {
if (oldDraggable == null) {
p.putClientProperty(WDRAG, Boolean.FALSE);
if (w.isDisplayable()) {
System.err.println(context + "(): To avoid content dragging, " + context + "() must be called before the window is realized, or " + WDRAG + " must be set to Boolean.FALSE before the window is realized. If you really want content dragging, set " + WDRAG + " on the window's root pane to Boolean.TRUE before calling " + context + "() to hide this message.");
LOG.log(Level.WARNING, "{0}(): To avoid content dragging, {1}() must be called before the window is realized, or " + WDRAG + " must be set to Boolean.FALSE before the window is realized. If you really want content dragging, set " + WDRAG + " on the window''s root pane to Boolean.TRUE before calling {2}() to hide this message.",
new Object[]{context, context, context});
}
}
}
Expand Down
55 changes: 36 additions & 19 deletions contrib/platform/src/com/sun/jna/platform/dnd/DragHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
package com.sun.jna.platform.dnd;

import com.sun.jna.Platform;
import java.awt.AlphaComposite;
import java.awt.Component;
import java.awt.Cursor;
Expand All @@ -49,6 +50,8 @@
import java.awt.dnd.InvalidDnDOperationException;
import java.awt.event.InputEvent;
import java.awt.image.BufferedImage;
import java.util.logging.Level;
import java.util.logging.Logger;

import javax.swing.Icon;
import javax.swing.JColorChooser;
Expand Down Expand Up @@ -110,6 +113,8 @@
public abstract class DragHandler
implements DragSourceListener, DragSourceMotionListener, DragGestureListener {

private static final Logger LOG = Logger.getLogger(DragHandler.class.getName());

/** Default maximum size for ghosted images. */
public static final Dimension MAX_GHOST_SIZE = new Dimension(250, 250);

Expand Down Expand Up @@ -138,8 +143,7 @@ public abstract class DragHandler
// w32 others: copy=ctrl
/** Modifier mask for a user-requested move. */
static final int MOVE_MASK = InputEvent.SHIFT_DOWN_MASK;
static final boolean OSX =
System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
static final boolean OSX = Platform.isMac();
/** Modifier mask for a user-requested copy. */
static final int COPY_MASK =
OSX ? InputEvent.ALT_DOWN_MASK : InputEvent.CTRL_DOWN_MASK;
Expand Down Expand Up @@ -175,16 +179,12 @@ static int getModifiers() {
public static Transferable getTransferable(DropTargetEvent e) {
if (e instanceof DropTargetDragEvent) {
try {
// getTransferable is available during drag only on 1.5+
return (Transferable)
e.getClass().getMethod("getTransferable", (Class[])null).invoke(e, (Object[])null);
}
catch(Exception ex) {
return ((DropTargetDragEvent) e).getTransferable();
} catch (Exception ex) {
// Method not available
}
}
else if (e instanceof DropTargetDropEvent) {
return ((DropTargetDropEvent)e).getTransferable();
} else if (e instanceof DropTargetDropEvent) {
return ((DropTargetDropEvent) e).getTransferable();
}
return transferable;
}
Expand Down Expand Up @@ -309,6 +309,7 @@ protected void dragStarted(DragGestureEvent e) { }
* responsible for initiating the drag operation.
* @param e event
*/
@Override
public void dragGestureRecognized(DragGestureEvent e) {
if ((e.getDragAction() & supportedActions) != 0
&& canDrag(e)) {
Expand Down Expand Up @@ -489,26 +490,37 @@ static String actionString(int action) {
}
private String lastAction;
private void describe(String type, DragSourceEvent e) {
if (false) {
if (LOG.isLoggable(Level.FINE)) {
StringBuilder msgBuilder = new StringBuilder();
msgBuilder.append("drag: ");
msgBuilder.append(type);
DragSourceContext ds = e.getDragSourceContext();
String msg = "drag: " + type;
if (e instanceof DragSourceDragEvent) {
DragSourceDragEvent ev = (DragSourceDragEvent)e;
msg += ": src=" + actionString(ds.getSourceActions())
+ " usr=" + actionString(ev.getUserAction())
+ " tgt=" + actionString(ev.getTargetActions())
+ " act=" + actionString(ev.getDropAction())
+ " mods=" + ev.getGestureModifiersEx();
msgBuilder.append(": src=");
msgBuilder.append(actionString(ds.getSourceActions()));
msgBuilder.append(" usr=");
msgBuilder.append(actionString(ev.getUserAction()));
msgBuilder.append(" tgt=");
msgBuilder.append(actionString(ev.getTargetActions()));
msgBuilder.append(" act=");
msgBuilder.append(actionString(ev.getDropAction()));
msgBuilder.append(" mods=");
msgBuilder.append(ev.getGestureModifiersEx());
}
else {
msg += ": e=" + e;
msgBuilder.append(": e=");
msgBuilder.append(e);
}
String msg = msgBuilder.toString();
if (!msg.equals(lastAction)) {
System.out.println(lastAction = msg);
LOG.log(Level.FINE, msg);
lastAction = msg;
}
}
}

@Override
public void dragDropEnd(DragSourceDropEvent e) {
describe("end", e);
setModifiers(UNKNOWN_MODIFIERS);
Expand All @@ -532,6 +544,7 @@ private Point getImageLocation(Point where) {
return where;
}

@Override
public void dragEnter(DragSourceDragEvent e) {
describe("enter", e);
if (ghost != null) {
Expand All @@ -544,6 +557,7 @@ public void dragEnter(DragSourceDragEvent e) {
// which has reports "0" for the available target actions (1.4+?)
// filed a bug for this
private boolean moved;
@Override
public void dragMouseMoved(DragSourceDragEvent e) {
describe("move", e);
if (ghost != null) {
Expand All @@ -554,6 +568,7 @@ public void dragMouseMoved(DragSourceDragEvent e) {
moved = true;
}

@Override
public void dragOver(DragSourceDragEvent e) {
describe("over", e);
if (ghost != null) {
Expand All @@ -562,10 +577,12 @@ public void dragOver(DragSourceDragEvent e) {
updateCursor(e);
}

@Override
public void dragExit(DragSourceEvent e) {
describe("exit", e);
}

@Override
public void dropActionChanged(DragSourceDragEvent e) {
describe("change", e);
setModifiers(e.getGestureModifiersEx() & KEY_MASK);
Expand Down
45 changes: 31 additions & 14 deletions contrib/platform/src/com/sun/jna/platform/dnd/DropHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.logging.Level;
import java.util.logging.Logger;

/** Provides simplified drop handling for a component.
* Usage:<br>
Expand Down Expand Up @@ -97,6 +99,8 @@
// the TransferHandler to drop
public abstract class DropHandler implements DropTargetListener {

private static final Logger LOG = Logger.getLogger(DropHandler.class.getName());

private int acceptedActions;
private List<DataFlavor> acceptedFlavors;
private DropTarget dropTarget;
Expand Down Expand Up @@ -275,26 +279,36 @@ protected boolean modifiersActive(int dropAction) {

private String lastAction;
private void describe(String type, DropTargetEvent e) {
if (false) {
String msg = "drop: " + type;
if(LOG.isLoggable(Level.FINE)) {
StringBuilder msgBuilder = new StringBuilder();
msgBuilder.append("drop: ");
msgBuilder.append(type);
if (e instanceof DropTargetDragEvent) {
DropTargetContext dtc = e.getDropTargetContext();
DropTarget dt = dtc.getDropTarget();
DropTargetDragEvent ev = (DropTargetDragEvent)e;
msg += ": src=" + DragHandler.actionString(ev.getSourceActions())
+ " tgt=" + DragHandler.actionString(dt.getDefaultActions())
+ " act=" + DragHandler.actionString(ev.getDropAction());
DropTargetDragEvent ev = (DropTargetDragEvent) e;
msgBuilder.append(": src=");
msgBuilder.append(DragHandler.actionString(ev.getSourceActions()));
msgBuilder.append(" tgt=");
msgBuilder.append(DragHandler.actionString(dt.getDefaultActions()));
msgBuilder.append(" act=");
msgBuilder.append(DragHandler.actionString(ev.getDropAction()));
}
else if (e instanceof DropTargetDropEvent) {
DropTargetContext dtc = e.getDropTargetContext();
DropTarget dt = dtc.getDropTarget();
DropTargetDropEvent ev = (DropTargetDropEvent)e;
msg += ": src=" + DragHandler.actionString(ev.getSourceActions())
+ " tgt=" + DragHandler.actionString(dt.getDefaultActions())
+ " act=" + DragHandler.actionString(ev.getDropAction());
msgBuilder.append(": src=");
msgBuilder.append(DragHandler.actionString(ev.getSourceActions()));
msgBuilder.append(" tgt=");
msgBuilder.append(DragHandler.actionString(dt.getDefaultActions()));
msgBuilder.append(" act=");
msgBuilder.append(DragHandler.actionString(ev.getDropAction()));
}
String msg = msgBuilder.toString();
if (!msg.equals(lastAction)) {
System.out.println(lastAction = msg);
LOG.log(Level.FINE, msg);
lastAction = msg;
}
}
}
Expand All @@ -317,23 +331,27 @@ protected int acceptOrReject(DropTargetDragEvent e) {
return action;
}

@Override
public void dragEnter(DropTargetDragEvent e) {
describe("enter(tgt)", e);
int action = acceptOrReject(e);
paintDropTarget(e, action, e.getLocation());
}

@Override
public void dragOver(DropTargetDragEvent e) {
describe("over(tgt)", e);
int action = acceptOrReject(e);
paintDropTarget(e, action, e.getLocation());
}

@Override
public void dragExit(DropTargetEvent e) {
describe("exit(tgt)", e);
paintDropTarget(e, DragHandler.NONE, null);
}

@Override
public void dropActionChanged(DropTargetDragEvent e) {
describe("change(tgt)", e);
int action = acceptOrReject(e);
Expand All @@ -344,6 +362,7 @@ public void dropActionChanged(DropTargetDragEvent e) {
* standard drop validity checking and handling, then invokes
* {@link #drop(DropTargetDropEvent,int)} if the drop looks acceptable.
*/
@Override
public void drop(DropTargetDropEvent e) {
describe("drop(tgt)", e);
int action = getDropAction(e);
Expand All @@ -353,12 +372,10 @@ public void drop(DropTargetDropEvent e) {
drop(e, action);
// Just in case this hasn't been done yet
e.dropComplete(true);
}
catch (Exception ex) {
} catch (Exception ex) {
e.dropComplete(false);
}
}
else {
} else {
e.rejectDrop();
}
paintDropTarget(e, DragHandler.NONE, e.getLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,13 @@
import com.sun.jna.platform.win32.WinNT.HANDLE;
import com.sun.jna.ptr.IntByReference;
import com.sun.jna.ptr.PointerByReference;
import java.util.logging.Level;
import java.util.logging.Logger;

public class W32FileMonitor extends FileMonitor {

private static final Logger LOG = Logger.getLogger(W32FileMonitor.class.getName());

private static final int BUFFER_SIZE = 4096;

private class FileInfo {
Expand Down Expand Up @@ -90,7 +94,7 @@ private void handleChanges(FileInfo finfo) throws IOException {
break;
default:
// TODO: other actions...
System.err.println("Unrecognized file action '" + fni.Action + "'");
LOG.log(Level.WARNING, "Unrecognized file action ''{0}''", fni.Action);
}

if (event != null) {
Expand Down
12 changes: 12 additions & 0 deletions contrib/platform/test/com/sun/jna/platform/TestNativeLoad.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@

package com.sun.jna.platform;

import com.sun.jna.NativeLibrary;

public class TestNativeLoad {
public static void main(String[] args) {
System.setProperty("jna.debug_load", "true");
NativeLibrary.addSearchPath("test", "/home/matthias/src/jnalib/");
NativeLibrary.getInstance("test");
}
}
Empty file added libtest.so
Empty file.
Loading

0 comments on commit e67cd22

Please sign in to comment.