Modified google code format
This commit is contained in:
parent
f48754838a
commit
462e15a291
|
@ -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;
|
||||
|
||||
public interface FailureCallback {
|
||||
|
||||
public void createTrayFailed();
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.IOException;
|
||||
|
@ -18,6 +30,9 @@ import java.security.SecureRandom;
|
|||
import java.util.concurrent.ExecutorService;
|
||||
import java.util.concurrent.Executors;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import dorkbox.util.NamedThreadFactory;
|
||||
import dorkbox.util.OS;
|
||||
import dorkbox.util.jna.linux.GtkSupport;
|
||||
|
@ -37,12 +52,12 @@ public abstract class SystemTray {
|
|||
protected static final Logger logger = LoggerFactory.getLogger(SystemTray.class);
|
||||
|
||||
/**
|
||||
* Size of the icon *
|
||||
* Size of the icon
|
||||
*/
|
||||
public static int ICON_SIZE = 22;
|
||||
|
||||
/**
|
||||
* Location of the icon *
|
||||
* Location of the icon
|
||||
*/
|
||||
public static String ICON_PATH = "";
|
||||
|
||||
|
@ -82,9 +97,7 @@ public abstract class SystemTray {
|
|||
}
|
||||
}
|
||||
|
||||
protected final ExecutorService
|
||||
callbackExecutor =
|
||||
Executors.newSingleThreadExecutor(new NamedThreadFactory("SysTrayExecutor", false));
|
||||
protected final ExecutorService callbackExecutor = Executors.newSingleThreadExecutor(new NamedThreadFactory("SysTrayExecutor", false));
|
||||
|
||||
protected volatile FailureCallback failureCallback;
|
||||
protected volatile boolean active = false;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
public interface SystemTrayMenuAction {
|
||||
|
||||
void onClick(SystemTray systemTray);
|
||||
}
|
||||
|
|
|
@ -1,15 +1,17 @@
|
|||
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.MouseEvent;
|
||||
|
||||
import javax.swing.*;
|
||||
import javax.swing.JPopupMenu;
|
||||
import javax.swing.SwingUtilities;
|
||||
|
||||
import dorkbox.util.DelayTimer;
|
||||
|
||||
public class SystemTrayMenuPopup extends JPopupMenu {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
private DelayTimer timer;
|
||||
|
@ -28,8 +30,9 @@ public class SystemTrayMenuPopup extends JPopupMenu {
|
|||
Point locationOnScreen = getLocationOnScreen();
|
||||
Dimension size = getSize();
|
||||
|
||||
if (location.x >= locationOnScreen.x && location.x < locationOnScreen.x + size.width &&
|
||||
location.y >= locationOnScreen.y && location.y < locationOnScreen.y + size.height) {
|
||||
if (location.x >= locationOnScreen.x && location.x < locationOnScreen.x + size.width
|
||||
&& location.y >= locationOnScreen.y && location.y < locationOnScreen.y + size.height) {
|
||||
|
||||
SystemTrayMenuPopup.this.timer.delay(SystemTrayMenuPopup.this.timer.getDelay());
|
||||
} else {
|
||||
setVisible(false);
|
||||
|
|
|
@ -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;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import dorkbox.util.jna.linux.AppIndicator;
|
||||
import dorkbox.util.jna.linux.Gobject;
|
||||
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.SystemTrayMenuAction;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public class AppIndicatorTray extends SystemTray {
|
||||
|
||||
private static final AppIndicator libappindicator = AppIndicator.INSTANCE;
|
||||
private static final Gobject libgobject = Gobject.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);
|
||||
|
||||
|
||||
public AppIndicatorTray() {
|
||||
}
|
||||
public AppIndicatorTray() {}
|
||||
|
||||
@Override
|
||||
public void createTray(String iconName) {
|
||||
this.appIndicator =
|
||||
libappindicator
|
||||
.app_indicator_new(this.appName, "indicator-messages-new", AppIndicator.CATEGORY_APPLICATION_STATUS);
|
||||
libappindicator.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
|
||||
hack the app indicator class itself. Not an issue unless we need other
|
||||
appindicators.
|
||||
/*
|
||||
* 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 appindicators.
|
||||
*/
|
||||
AppIndicator.AppIndicatorClassStruct
|
||||
aiclass =
|
||||
AppIndicator.AppIndicatorClassStruct aiclass =
|
||||
new AppIndicator.AppIndicatorClassStruct(this.appIndicator.parent.g_type_instance.g_class);
|
||||
|
||||
|
||||
aiclass.fallback = new AppIndicator.Fallback() {
|
||||
@Override
|
||||
public Pointer callback(final AppIndicator.AppIndicatorInstanceStruct self) {
|
||||
|
|
|
@ -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;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
@ -12,7 +25,10 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
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.Gtk;
|
||||
|
@ -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)
|
||||
*/
|
||||
@Override
|
||||
public void updateMenuEntry(final String origMenuText, final String newMenuText,
|
||||
final SystemTrayMenuAction newCallback) {
|
||||
public void updateMenuEntry(final String origMenuText, final String newMenuText, final SystemTrayMenuAction newCallback) {
|
||||
Runnable doRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
|
@ -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;
|
||||
|
||||
import com.sun.jna.Pointer;
|
||||
|
|
|
@ -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;
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.AWTException;
|
||||
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.ActionListener;
|
||||
import java.awt.event.MouseAdapter;
|
||||
|
@ -11,12 +34,13 @@ import java.util.ArrayList;
|
|||
import java.util.HashMap;
|
||||
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.SystemTrayMenuPopup;
|
||||
|
||||
|
||||
/**
|
||||
* 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.
|
||||
*/
|
||||
public SwingSystemTray() {
|
||||
}
|
||||
public SwingSystemTray() {}
|
||||
|
||||
|
||||
@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)
|
||||
*/
|
||||
@Override
|
||||
public void updateMenuEntry(final String origMenuText, final String newMenuText,
|
||||
final SystemTrayMenuAction newCallback) {
|
||||
public void updateMenuEntry(final String origMenuText, final String newMenuText, final SystemTrayMenuAction newCallback) {
|
||||
Runnable doRun = new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
|
Loading…
Reference in New Issue