mirror of
https://github.com/igniterealtime/Spark.git
synced 2026-08-18 11:10:02 +00:00
cleanup Flashing plugin
This commit is contained in:
@ -15,13 +15,11 @@
|
||||
*/
|
||||
package org.jivesoftware.spark.plugin.flashing;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Window;
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import org.jivesoftware.spark.PluginManager;
|
||||
@ -31,7 +29,6 @@ public class FlashWindow {
|
||||
private final HashMap<Window, Thread> flashings = new HashMap<>();
|
||||
|
||||
static {
|
||||
|
||||
boolean is64bit = System.getProperty("sun.arch.data.model").equals("64");
|
||||
String arch = "";
|
||||
if (is64bit) {
|
||||
@ -54,36 +51,40 @@ public class FlashWindow {
|
||||
* @param intertime The amount of time between different flashes
|
||||
* @param count The number of times to flash the window
|
||||
*/
|
||||
public void flash(final Window window, final int intratime,
|
||||
final int count) {
|
||||
public void flash(Window window, int intratime, int count) {
|
||||
if (!(window instanceof JFrame)) {
|
||||
return;
|
||||
}
|
||||
JFrame jFrame = (JFrame) window;
|
||||
new Thread(() -> {
|
||||
try {
|
||||
if (window instanceof JFrame)
|
||||
{
|
||||
// flash on and off each time
|
||||
for (int i = 0; i < count; i++) {
|
||||
flash(((JFrame) window).getTitle(), true);
|
||||
flash(jFrame.getTitle(), true);
|
||||
Thread.sleep(intratime);
|
||||
}
|
||||
// turn the flash off
|
||||
flash(((JFrame) window).getTitle(), false);
|
||||
}
|
||||
} catch (Exception ex) {
|
||||
// System.out.println(ex.getMessage());
|
||||
flash(jFrame.getTitle(), false);
|
||||
} catch (Exception ignored) {
|
||||
}
|
||||
}).start();
|
||||
}
|
||||
|
||||
public void startFlashing(final Window window) {
|
||||
if (flashings.get(window) == null) {
|
||||
if (flashings.get(window) != null) {
|
||||
return;
|
||||
}
|
||||
if (!(window instanceof JFrame)) {
|
||||
return;
|
||||
}
|
||||
JFrame jFrame = (JFrame) window;
|
||||
Thread t = new Thread(() -> {
|
||||
while (true) {
|
||||
try {
|
||||
Thread.sleep(1500);
|
||||
if (window instanceof JFrame)
|
||||
flash(((JFrame) window).getTitle(), true);
|
||||
flash(jFrame.getTitle(), true);
|
||||
} catch (Exception ex) {
|
||||
flash(((JFrame) window).getTitle(), false);
|
||||
flash(jFrame.getTitle(), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@ -91,37 +92,11 @@ public class FlashWindow {
|
||||
t.start();
|
||||
flashings.put(window, t);
|
||||
}
|
||||
}
|
||||
|
||||
public void stopFlashing(final Window window) {
|
||||
if (flashings.get(window) != null) {
|
||||
flashings.get(window).interrupt();
|
||||
flashings.remove(window);
|
||||
Thread windowFlashingThread = flashings.remove(window);
|
||||
if (windowFlashingThread != null) {
|
||||
windowFlashingThread.interrupt();
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
final JFrame frame = new JFrame();
|
||||
frame.setTitle("Test");
|
||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||
frame.getContentPane().setLayout(new FlowLayout());
|
||||
JButton button = new JButton("Temp Flashing");
|
||||
frame.getContentPane().add(button);
|
||||
final FlashWindow winutil = new FlashWindow();
|
||||
button.addActionListener( evt -> winutil.flash(frame, 750, 5) );
|
||||
|
||||
JButton startButton = new JButton("Start Flashing");
|
||||
frame.getContentPane().add(startButton);
|
||||
startButton.addActionListener( evt -> winutil.startFlashing(frame) );
|
||||
|
||||
JButton stopButton = new JButton("Stop Flashing");
|
||||
frame.getContentPane().add(stopButton);
|
||||
stopButton.addActionListener( evt -> {
|
||||
// winutil.flash(frame,750,1500,5);
|
||||
winutil.stopFlashing(frame);
|
||||
} );
|
||||
frame.pack();
|
||||
frame.setVisible(true);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -21,11 +21,7 @@ import org.jivesoftware.spark.NativeHandler;
|
||||
import org.jivesoftware.spark.SparkManager;
|
||||
|
||||
public class FlashingHandler implements NativeHandler {
|
||||
private final FlashWindow flasher;
|
||||
|
||||
public FlashingHandler() {
|
||||
flasher = new FlashWindow();
|
||||
}
|
||||
private final FlashWindow flasher = new FlashWindow();
|
||||
|
||||
@Override
|
||||
public void flashWindow(Window window) {
|
||||
|
||||
@ -19,6 +19,7 @@ import org.jivesoftware.spark.SparkManager;
|
||||
import org.jivesoftware.spark.plugin.Plugin;
|
||||
|
||||
public class FlashingPlugin implements Plugin {
|
||||
private FlashingHandler nativeHandler;
|
||||
|
||||
@Override
|
||||
public boolean canShutDown() {
|
||||
@ -29,11 +30,14 @@ public class FlashingPlugin implements Plugin {
|
||||
public void initialize() {
|
||||
FlashingPreference preference = new FlashingPreference();
|
||||
SparkManager.getPreferenceManager().addPreference(preference);
|
||||
SparkManager.getNativeManager().addNativeHandler(new FlashingHandler());
|
||||
nativeHandler = new FlashingHandler();
|
||||
SparkManager.getNativeManager().addNativeHandler(nativeHandler);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void shutdown() {
|
||||
SparkManager.getNativeManager().removeNativeHandler(nativeHandler);
|
||||
nativeHandler = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
@ -51,7 +51,6 @@ public class FlashingPreferenceDialog extends JPanel {
|
||||
|
||||
flashingPanel.setBorder(BorderFactory.createTitledBorder(FlashingResources.getString("title.flashing")));
|
||||
|
||||
// Setup MNEMORICS
|
||||
ResourceUtils.resButton(flashingEnabled, FlashingResources.getString("flashing.enable"));
|
||||
ResourceUtils.resLabel(lTyps, flashingType, FlashingResources.getString("flashing.type"));
|
||||
|
||||
@ -73,25 +72,27 @@ public class FlashingPreferenceDialog extends JPanel {
|
||||
}
|
||||
|
||||
public void setFlashingType(String type) {
|
||||
if (FlashingPreferences.TYPE_CONTINUOUS.equals(type)) {
|
||||
switch (type) {
|
||||
case FlashingPreferences.TYPE_CONTINUOUS:
|
||||
flashingType.setSelectedIndex(0);
|
||||
}
|
||||
else if (FlashingPreferences.TYPE_TEMPORARY.equals(type)) {
|
||||
break;
|
||||
case FlashingPreferences.TYPE_TEMPORARY:
|
||||
flashingType.setSelectedIndex(1);
|
||||
}
|
||||
else {
|
||||
break;
|
||||
default:
|
||||
flashingType.setSelectedIndex(0);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
public String getFlashingType() {
|
||||
if (flashingType.getSelectedIndex() == 0) {
|
||||
switch (flashingType.getSelectedIndex()) {
|
||||
case 0:
|
||||
return FlashingPreferences.TYPE_CONTINUOUS;
|
||||
case 1:
|
||||
return FlashingPreferences.TYPE_TEMPORARY;
|
||||
default:
|
||||
return FlashingPreferences.TYPE_CONTINUOUS;
|
||||
}
|
||||
else if (flashingType.getSelectedIndex() == 1) {
|
||||
return FlashingPreferences.TYPE_TEMPORARY;
|
||||
}
|
||||
|
||||
return "continuous";
|
||||
}
|
||||
}
|
||||
|
||||
@ -34,20 +34,17 @@ public class FlashingPreferences {
|
||||
|
||||
public FlashingPreferences() {
|
||||
this.props = new Properties();
|
||||
|
||||
try {
|
||||
props.load(new FileInputStream(getConfigFile()));
|
||||
} catch (IOException e) {
|
||||
// Can't load ConfigFile
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public File getConfigFile() {
|
||||
if (configFile == null)
|
||||
configFile = new File(Spark.getSparkUserHome(),
|
||||
"flashing.properties");
|
||||
|
||||
if (configFile == null) {
|
||||
configFile = new File(Spark.getSparkUserHome(), "flashing.properties");
|
||||
}
|
||||
return configFile;
|
||||
}
|
||||
|
||||
@ -76,11 +73,11 @@ public class FlashingPreferences {
|
||||
}
|
||||
|
||||
private boolean getBoolean(String property, boolean defaultValue) {
|
||||
return Boolean.parseBoolean(props.getProperty(property, Boolean
|
||||
.toString(defaultValue)));
|
||||
String propertyVal = props.getProperty(property);
|
||||
return propertyVal != null ? Boolean.parseBoolean(propertyVal) : defaultValue;
|
||||
}
|
||||
|
||||
private void setBoolean(String property, boolean value) {
|
||||
props.setProperty(property, Boolean.toString(value));
|
||||
props.setProperty(property, String.valueOf(value));
|
||||
}
|
||||
}
|
||||
|
||||
@ -27,7 +27,7 @@ public class FlashingResources {
|
||||
private static ClassLoader cl = FlashingResources.class.getClassLoader();
|
||||
static final ImageIcon LIGHTING_BOLT_IMAGE = getImageIcon("lightning.png");
|
||||
|
||||
public static String getString(String propertyName) {
|
||||
static String getString(String propertyName) {
|
||||
try {
|
||||
return prb.getString(propertyName);
|
||||
} catch (Exception e) {
|
||||
@ -36,7 +36,7 @@ public class FlashingResources {
|
||||
}
|
||||
}
|
||||
|
||||
static ImageIcon getImageIcon(String icon) {
|
||||
private static ImageIcon getImageIcon(String icon) {
|
||||
return new ImageIcon(cl.getResource(icon));
|
||||
}
|
||||
}
|
||||
|
||||
@ -0,0 +1,6 @@
|
||||
title.flashing=Barra de tarefas piscando
|
||||
|
||||
flashing.enable=Ativar flash da barra de tarefas
|
||||
flashing.type=Tipo
|
||||
flashing.type.continuous=Contínuo
|
||||
flashing.type.temporary=Temporário
|
||||
@ -1,6 +1,6 @@
|
||||
title.flashing=Мигание в панели задач
|
||||
|
||||
flashing.enable=&Включить мигание в панели задач
|
||||
flashing.type=&Тип
|
||||
flashing.enable=Включить мигание в панели задач
|
||||
flashing.type=Тип
|
||||
flashing.type.continuous=Непрерывно
|
||||
flashing.type.temporary=Временно
|
||||
|
||||
Reference in New Issue
Block a user