Modified google code format

This commit is contained in:
nathan 2014-11-24 17:40:06 +01:00
parent f48754838a
commit 462e15a291
8 changed files with 1059 additions and 954 deletions

View File

@ -1,6 +1,20 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray; package dorkbox.util.tray;
public interface FailureCallback { public interface FailureCallback {
public void createTrayFailed(); public void createTrayFailed();
} }

View File

@ -1,8 +1,20 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray; package dorkbox.util.tray;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.File; import java.io.File;
import java.io.FileOutputStream; import java.io.FileOutputStream;
import java.io.IOException; import java.io.IOException;
@ -18,6 +30,9 @@ import java.security.SecureRandom;
import java.util.concurrent.ExecutorService; import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import dorkbox.util.NamedThreadFactory; import dorkbox.util.NamedThreadFactory;
import dorkbox.util.OS; import dorkbox.util.OS;
import dorkbox.util.jna.linux.GtkSupport; import dorkbox.util.jna.linux.GtkSupport;
@ -37,12 +52,12 @@ public abstract class SystemTray {
protected static final Logger logger = LoggerFactory.getLogger(SystemTray.class); protected static final Logger logger = LoggerFactory.getLogger(SystemTray.class);
/** /**
* Size of the icon * * Size of the icon
*/ */
public static int ICON_SIZE = 22; public static int ICON_SIZE = 22;
/** /**
* Location of the icon * * Location of the icon
*/ */
public static String ICON_PATH = ""; public static String ICON_PATH = "";
@ -82,9 +97,7 @@ public abstract class SystemTray {
} }
} }
protected final ExecutorService protected final ExecutorService callbackExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("SysTrayExecutor", false));
callbackExecutor =
Executors.newSingleThreadExecutor(new NamedThreadFactory("SysTrayExecutor", false));
protected volatile FailureCallback failureCallback; protected volatile FailureCallback failureCallback;
protected volatile boolean active = false; protected volatile boolean active = false;

View File

@ -1,7 +1,20 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray; package dorkbox.util.tray;
public interface SystemTrayMenuAction { public interface SystemTrayMenuAction {
void onClick(SystemTray systemTray); void onClick(SystemTray systemTray);
} }

View File

@ -1,15 +1,17 @@
package dorkbox.util.tray; package dorkbox.util.tray;
import java.awt.*; import java.awt.Dimension;
import java.awt.MouseInfo;
import java.awt.Point;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent; import java.awt.event.MouseEvent;
import javax.swing.*; import javax.swing.JPopupMenu;
import javax.swing.SwingUtilities;
import dorkbox.util.DelayTimer; import dorkbox.util.DelayTimer;
public class SystemTrayMenuPopup extends JPopupMenu { public class SystemTrayMenuPopup extends JPopupMenu {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
private DelayTimer timer; private DelayTimer timer;
@ -28,8 +30,9 @@ public class SystemTrayMenuPopup extends JPopupMenu {
Point locationOnScreen = getLocationOnScreen(); Point locationOnScreen = getLocationOnScreen();
Dimension size = getSize(); Dimension size = getSize();
if (location.x >= locationOnScreen.x && location.x < locationOnScreen.x + size.width && if (location.x >= locationOnScreen.x && location.x < locationOnScreen.x + size.width
location.y >= locationOnScreen.y && location.y < locationOnScreen.y + size.height) { && location.y >= locationOnScreen.y && location.y < locationOnScreen.y + size.height) {
SystemTrayMenuPopup.this.timer.delay(SystemTrayMenuPopup.this.timer.getDelay()); SystemTrayMenuPopup.this.timer.delay(SystemTrayMenuPopup.this.timer.getDelay());
} else { } else {
setVisible(false); setVisible(false);

View File

@ -1,13 +1,28 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray.linux; package dorkbox.util.tray.linux;
import com.sun.jna.Pointer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import com.sun.jna.Pointer;
import dorkbox.util.jna.linux.AppIndicator; import dorkbox.util.jna.linux.AppIndicator;
import dorkbox.util.jna.linux.Gobject; import dorkbox.util.jna.linux.Gobject;
import dorkbox.util.jna.linux.Gtk; import dorkbox.util.jna.linux.Gtk;
@ -15,7 +30,6 @@ import dorkbox.util.jna.linux.GtkSupport;
import dorkbox.util.tray.SystemTray; import dorkbox.util.tray.SystemTray;
import dorkbox.util.tray.SystemTrayMenuAction; import dorkbox.util.tray.SystemTrayMenuAction;
/** /**
* Class for handling all system tray interactions. * Class for handling all system tray interactions.
* *
@ -26,7 +40,6 @@ import dorkbox.util.tray.SystemTrayMenuAction;
* Lantern: https://github.com/getlantern/lantern/ Apache 2.0 License Copyright 2010 Brave New Software Project, Inc. * Lantern: https://github.com/getlantern/lantern/ Apache 2.0 License Copyright 2010 Brave New Software Project, Inc.
*/ */
public class AppIndicatorTray extends SystemTray { public class AppIndicatorTray extends SystemTray {
private static final AppIndicator libappindicator = AppIndicator.INSTANCE; private static final AppIndicator libappindicator = AppIndicator.INSTANCE;
private static final Gobject libgobject = Gobject.INSTANCE; private static final Gobject libgobject = Gobject.INSTANCE;
private static final Gtk libgtk = Gtk.INSTANCE; private static final Gtk libgtk = Gtk.INSTANCE;
@ -43,24 +56,21 @@ public class AppIndicatorTray extends SystemTray {
private final List<Pointer> widgets = new ArrayList<Pointer>(4); private final List<Pointer> widgets = new ArrayList<Pointer>(4);
public AppIndicatorTray() { public AppIndicatorTray() {}
}
@Override @Override
public void createTray(String iconName) { public void createTray(String iconName) {
this.appIndicator = this.appIndicator =
libappindicator libappindicator.app_indicator_new(this.appName, "indicator-messages-new", AppIndicator.CATEGORY_APPLICATION_STATUS);
.app_indicator_new(this.appName, "indicator-messages-new", AppIndicator.CATEGORY_APPLICATION_STATUS);
/* basically a hack -- we should subclass the AppIndicator /*
type and override the fallback entry in the 'vtable', instead we just * basically a hack -- we should subclass the AppIndicator type and override the fallback entry in the 'vtable', instead we just
hack the app indicator class itself. Not an issue unless we need other * hack the app indicator class itself. Not an issue unless we need other appindicators.
appindicators.
*/ */
AppIndicator.AppIndicatorClassStruct AppIndicator.AppIndicatorClassStruct aiclass =
aiclass =
new AppIndicator.AppIndicatorClassStruct(this.appIndicator.parent.g_type_instance.g_class); new AppIndicator.AppIndicatorClassStruct(this.appIndicator.parent.g_type_instance.g_class);
aiclass.fallback = new AppIndicator.Fallback() { aiclass.fallback = new AppIndicator.Fallback() {
@Override @Override
public Pointer callback(final AppIndicator.AppIndicatorInstanceStruct self) { public Pointer callback(final AppIndicator.AppIndicatorInstanceStruct self) {

View File

@ -1,8 +1,21 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray.linux; package dorkbox.util.tray.linux;
import com.sun.jna.Pointer; import java.awt.Dimension;
import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.lang.reflect.InvocationTargetException; import java.lang.reflect.InvocationTargetException;
@ -12,7 +25,10 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import javax.swing.*; import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import com.sun.jna.Pointer;
import dorkbox.util.jna.linux.Gobject; import dorkbox.util.jna.linux.Gobject;
import dorkbox.util.jna.linux.Gtk; import dorkbox.util.jna.linux.Gtk;
@ -67,9 +83,9 @@ public class GtkSystemTray extends SystemTray {
} else { } else {
int iconX = (int) (event.x_root - event.x); int iconX = (int) (event.x_root - event.x);
int iconY = (int) (event.y_root - event.y); int iconY = (int) (event.y_root - event.y);
// System.err.println("x: " + iconX + " y: " + iconY); // System.err.println("x: " + iconX + " y: " + iconY);
// System.err.println("x1: " + event.x_root + " y1: " + event.y_root); // relative to SCREEN // System.err.println("x1: " + event.x_root + " y1: " + event.y_root); // relative to SCREEN
// System.err.println("x2: " + event.x + " y2: " + event.y); // relative to WINDOW // System.err.println("x2: " + event.x + " y2: " + event.y); // relative to WINDOW
Dimension size = GtkSystemTray.this.jmenu.getPreferredSize(); Dimension size = GtkSystemTray.this.jmenu.getPreferredSize();
@ -254,8 +270,7 @@ public class GtkSystemTray extends SystemTray {
* Will update an already existing menu entry (or add a new one, if it doesn't exist) * Will update an already existing menu entry (or add a new one, if it doesn't exist)
*/ */
@Override @Override
public void updateMenuEntry(final String origMenuText, final String newMenuText, public void updateMenuEntry(final String origMenuText, final String newMenuText, final SystemTrayMenuAction newCallback) {
final SystemTrayMenuAction newCallback) {
Runnable doRun = new Runnable() { Runnable doRun = new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -1,3 +1,18 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray.linux; package dorkbox.util.tray.linux;
import com.sun.jna.Pointer; import com.sun.jna.Pointer;

View File

@ -1,7 +1,30 @@
/*
* Copyright 2014 dorkbox, llc
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package dorkbox.util.tray.swing; package dorkbox.util.tray.swing;
import java.awt.AWTException;
import java.awt.*; import java.awt.Dimension;
import java.awt.GraphicsConfiguration;
import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.awt.Image;
import java.awt.Point;
import java.awt.Rectangle;
import java.awt.SystemTray;
import java.awt.TrayIcon;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.awt.event.MouseAdapter; import java.awt.event.MouseAdapter;
@ -11,12 +34,13 @@ import java.util.ArrayList;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import javax.swing.*; import javax.swing.ImageIcon;
import javax.swing.JMenuItem;
import javax.swing.SwingUtilities;
import dorkbox.util.tray.SystemTrayMenuAction; import dorkbox.util.tray.SystemTrayMenuAction;
import dorkbox.util.tray.SystemTrayMenuPopup; import dorkbox.util.tray.SystemTrayMenuPopup;
/** /**
* Class for handling all system tray interaction, via SWING * Class for handling all system tray interaction, via SWING
*/ */
@ -33,8 +57,7 @@ public class SwingSystemTray extends dorkbox.util.tray.SystemTray {
/** /**
* Creates a new system tray handler class. * Creates a new system tray handler class.
*/ */
public SwingSystemTray() { public SwingSystemTray() {}
}
@Override @Override
@ -293,8 +316,7 @@ public class SwingSystemTray extends dorkbox.util.tray.SystemTray {
* Will update an already existing menu entry (or add a new one, if it doesn't exist) * Will update an already existing menu entry (or add a new one, if it doesn't exist)
*/ */
@Override @Override
public void updateMenuEntry(final String origMenuText, final String newMenuText, public void updateMenuEntry(final String origMenuText, final String newMenuText, final SystemTrayMenuAction newCallback) {
final SystemTrayMenuAction newCallback) {
Runnable doRun = new Runnable() { Runnable doRun = new Runnable() {
@Override @Override
public void run() { public void run() {