mirror of
https://github.com/igniterealtime/Spark.git
synced 2025-12-01 12:27:58 +00:00
more work on roar plugin
git-svn-id: http://svn.igniterealtime.org/svn/repos/spark/trunk@12364 b35dd754-fafc-0310-a699-88a17e54d16e
This commit is contained in:
committed by
wolf.posdorfer
parent
2451200c34
commit
a1cfce2fd9
@ -22,6 +22,11 @@ package org.jivesoftware.spark.roar;
|
|||||||
import org.jivesoftware.spark.SparkManager;
|
import org.jivesoftware.spark.SparkManager;
|
||||||
import org.jivesoftware.spark.plugin.Plugin;
|
import org.jivesoftware.spark.plugin.Plugin;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The Main Class of the Roar Plugin
|
||||||
|
* @author wolf.posdorfer
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class Roar implements Plugin {
|
public class Roar implements Plugin {
|
||||||
|
|
||||||
private RoarMessageListener _listener;
|
private RoarMessageListener _listener;
|
||||||
@ -29,7 +34,6 @@ public class Roar implements Plugin {
|
|||||||
@Override
|
@Override
|
||||||
public void initialize() {
|
public void initialize() {
|
||||||
|
|
||||||
|
|
||||||
RoarPreference pref = new RoarPreference();
|
RoarPreference pref = new RoarPreference();
|
||||||
SparkManager.getPreferenceManager().addPreference(pref);
|
SparkManager.getPreferenceManager().addPreference(pref);
|
||||||
|
|
||||||
|
|||||||
@ -19,7 +19,6 @@
|
|||||||
*/
|
*/
|
||||||
package org.jivesoftware.spark.roar;
|
package org.jivesoftware.spark.roar;
|
||||||
|
|
||||||
|
|
||||||
import java.awt.Dimension;
|
import java.awt.Dimension;
|
||||||
import java.awt.Toolkit;
|
import java.awt.Toolkit;
|
||||||
|
|
||||||
@ -33,16 +32,18 @@ import org.jivesoftware.spark.ui.GlobalMessageListener;
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* Message Listener
|
* Message Listener
|
||||||
|
*
|
||||||
* @author wolf.posdorfer
|
* @author wolf.posdorfer
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class RoarMessageListener implements GlobalMessageListener {
|
public class RoarMessageListener implements GlobalMessageListener {
|
||||||
|
|
||||||
|
|
||||||
private int _lastusedXpos;
|
private int _lastusedXpos;
|
||||||
private int _lastusedYpos;
|
private int _lastusedYpos;
|
||||||
private Dimension _screensize;
|
private Dimension _screensize;
|
||||||
|
|
||||||
|
private int _amount;
|
||||||
|
|
||||||
private final int WIDTH = 300;
|
private final int WIDTH = 300;
|
||||||
private final int HEIGHT = 80;
|
private final int HEIGHT = 80;
|
||||||
|
|
||||||
@ -51,42 +52,46 @@ public class RoarMessageListener implements GlobalMessageListener{
|
|||||||
|
|
||||||
_lastusedXpos = _screensize.width - 5;
|
_lastusedXpos = _screensize.width - 5;
|
||||||
_lastusedYpos = 5;
|
_lastusedYpos = 5;
|
||||||
|
_amount = 0;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void messageReceived(ChatRoom room, Message message) {
|
public void messageReceived(ChatRoom room, Message message) {
|
||||||
|
RoarProperties props = new RoarProperties();
|
||||||
|
if (props.getShowingPopups()
|
||||||
|
&& (_amount < props.getMaximumPopups() || props.getMaximumPopups() == 0)) {
|
||||||
|
|
||||||
ImageIcon icon = SparkRes.getImageIcon(SparkRes.SPARK_IMAGE_32x32);
|
ImageIcon icon = SparkRes.getImageIcon(SparkRes.SPARK_IMAGE_32x32);
|
||||||
|
|
||||||
String nickname = StringUtils.parseName(message.getFrom());
|
String nickname = StringUtils.parseName(message.getFrom());
|
||||||
|
|
||||||
RoarPanel.popupWindow(this, icon, nickname, message.getBody(), _lastusedXpos, _lastusedYpos);
|
RoarPanel.popupWindow(this, icon, nickname, message.getBody(),
|
||||||
|
_lastusedXpos, _lastusedYpos, props.getBackgroundColor(),
|
||||||
|
props.getDuration());
|
||||||
|
|
||||||
|
++_amount;
|
||||||
_lastusedYpos += HEIGHT + 5;
|
_lastusedYpos += HEIGHT + 5;
|
||||||
|
|
||||||
|
if (_lastusedYpos >= _screensize.height - 90) {
|
||||||
if(_lastusedYpos>= _screensize.height-90)
|
|
||||||
{
|
|
||||||
_lastusedXpos -= WIDTH + 5;
|
_lastusedXpos -= WIDTH + 5;
|
||||||
_lastusedYpos = 5;
|
_lastusedYpos = 5;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void closingRoarPanel(int x, int y)
|
public void closingRoarPanel(int x, int y) {
|
||||||
{
|
if (_lastusedYpos > (y - 5)) {
|
||||||
if(_lastusedYpos>(y-5))
|
|
||||||
{
|
|
||||||
_lastusedYpos = y - 5;
|
_lastusedYpos = y - 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(_lastusedXpos<(x+5))
|
if (_lastusedXpos < (x + 5)) {
|
||||||
{
|
|
||||||
_lastusedXpos = x + WIDTH + 5;
|
_lastusedXpos = x + WIDTH + 5;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
--_amount;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -24,15 +24,11 @@ import java.awt.Font;
|
|||||||
import java.awt.GridBagConstraints;
|
import java.awt.GridBagConstraints;
|
||||||
import java.awt.GridBagLayout;
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Insets;
|
import java.awt.Insets;
|
||||||
import java.awt.Toolkit;
|
|
||||||
import java.awt.event.MouseAdapter;
|
|
||||||
import java.awt.event.MouseEvent;
|
|
||||||
import java.awt.geom.RoundRectangle2D;
|
import java.awt.geom.RoundRectangle2D;
|
||||||
import java.util.Timer;
|
import java.util.Timer;
|
||||||
import java.util.TimerTask;
|
import java.util.TimerTask;
|
||||||
|
|
||||||
import javax.swing.Icon;
|
import javax.swing.Icon;
|
||||||
import javax.swing.ImageIcon;
|
|
||||||
import javax.swing.JLabel;
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JWindow;
|
import javax.swing.JWindow;
|
||||||
@ -40,66 +36,27 @@ import javax.swing.JWindow;
|
|||||||
import com.sun.awt.AWTUtilities;
|
import com.sun.awt.AWTUtilities;
|
||||||
|
|
||||||
public class RoarPanel {
|
public class RoarPanel {
|
||||||
|
|
||||||
private static ImageIcon xicon = new ImageIcon(
|
|
||||||
"C:\\Dokumente und Einstellungen\\wolf.posdorfer\\Desktop\\eclipse\\spark\\src\\resources\\images\\close_dark.png");
|
|
||||||
private static ImageIcon icon = new ImageIcon(
|
|
||||||
"C:\\Dokumente und Einstellungen\\wolf.posdorfer\\Desktop\\eclipse\\spark\\src\\resources\\images\\spark-32x32.png");
|
|
||||||
private static String _text = "laaaaaaaaaaaaaaaaaaaaaaaaang laaaaaaaaaaaaaaaang\nlaaaaaaaaaaaaaaaang\nlaaaaaaaaaaaaaaaang";
|
|
||||||
|
|
||||||
private static int _width = 300;
|
private static int _width = 300;
|
||||||
private static int _height = 80;
|
private static int _height = 80;
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) throws InterruptedException {
|
|
||||||
|
|
||||||
int x = Toolkit.getDefaultToolkit().getScreenSize().width;
|
|
||||||
|
|
||||||
RoarMessageListener rml = new RoarMessageListener();
|
|
||||||
|
|
||||||
popupWindow(rml, icon, "head1", _text, x, 0);
|
|
||||||
Thread.sleep(500);
|
|
||||||
|
|
||||||
popupWindow(rml, icon, "head2", _text, x, 5 + 80);
|
|
||||||
Thread.sleep(500);
|
|
||||||
|
|
||||||
popupWindow(rml, icon, "head3", _text, x, 5 + 80 + 5 + 80);
|
|
||||||
Thread.sleep(500);
|
|
||||||
|
|
||||||
popupWindow(rml, icon, "head4", _text, x, 5 + 80 + 5 + 80 + 5 + 80);
|
|
||||||
Thread.sleep(500);
|
|
||||||
|
|
||||||
popupWindow(rml, icon, "head5", _text, x, 5 + 80 + 5 + 80 + 5 + 80 + 5
|
|
||||||
+ 80);
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
private static JWindow createWindow(Icon icon, String head, String body,
|
private static JWindow createWindow(Icon icon, String head, String body,
|
||||||
int posx, int posy) {
|
int posx, int posy, Color backgroundcolor, Color headerColor, Color messageColor) {
|
||||||
|
|
||||||
final JWindow window = new JWindow();
|
final JWindow window = new JWindow();
|
||||||
JPanel windowpanel = new JPanel(new GridBagLayout());
|
JPanel windowpanel = new JPanel(new GridBagLayout());
|
||||||
windowpanel.setBackground(Color.BLACK);
|
windowpanel.setBackground(backgroundcolor);
|
||||||
|
|
||||||
AWTUtilities.setWindowShape(window, new RoundRectangle2D.Float(0, 0,
|
AWTUtilities.setWindowShape(window, new RoundRectangle2D.Float(0, 0,
|
||||||
_width, _height, 20, 20));
|
_width, _height, 20, 20));
|
||||||
AWTUtilities.setWindowOpaque(window, true);
|
AWTUtilities.setWindowOpaque(window, true);
|
||||||
|
|
||||||
|
|
||||||
JLabel close = new JLabel(xicon);
|
|
||||||
|
|
||||||
close.addMouseListener(new MouseAdapter() {
|
|
||||||
@Override
|
|
||||||
public void mouseClicked(MouseEvent e) {
|
|
||||||
window.dispose();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
JLabel text = new JLabel("<HTML>" + body + "</HTML>");
|
JLabel text = new JLabel("<HTML>" + body + "</HTML>");
|
||||||
text.setForeground(Color.WHITE);
|
text.setForeground(messageColor);
|
||||||
|
|
||||||
JLabel header = new JLabel(head);
|
JLabel header = new JLabel(head);
|
||||||
header.setForeground(Color.RED);
|
header.setForeground(headerColor);
|
||||||
header.setFont(new Font(header.getFont().getName(), Font.BOLD, header
|
header.setFont(new Font(header.getFont().getName(), Font.BOLD, header
|
||||||
.getFont().getSize() + 2));
|
.getFont().getSize() + 2));
|
||||||
|
|
||||||
@ -120,21 +77,10 @@ public class RoarPanel {
|
|||||||
{
|
{
|
||||||
AWTUtilities.setWindowOpacity(window, 0.9f);
|
AWTUtilities.setWindowOpacity(window, 0.9f);
|
||||||
window.setVisible(true);
|
window.setVisible(true);
|
||||||
//
|
|
||||||
// for(float i=3; i<10;i++)
|
|
||||||
// {
|
|
||||||
// AWTUtilities.setWindowOpacity(window, i/10.f);
|
|
||||||
// try {
|
|
||||||
// Thread.sleep(70);
|
|
||||||
// } catch (InterruptedException e) {
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void popupWindow(final RoarMessageListener owner, Icon icon, String head, String text, int x, int y) {
|
public static void popupWindow(final RoarMessageListener owner, Icon icon, String head, String text, int x, int y, Color backgroundcolor, int duration) {
|
||||||
final JWindow window = createWindow(icon, head, text, x, y);
|
final JWindow window = createWindow(icon, head, text, x, y,backgroundcolor, Color.RED, Color.WHITE);
|
||||||
fadein(window);
|
fadein(window);
|
||||||
|
|
||||||
|
|
||||||
@ -149,7 +95,7 @@ public class RoarPanel {
|
|||||||
};
|
};
|
||||||
|
|
||||||
Timer t = new Timer();
|
Timer t = new Timer();
|
||||||
t.schedule(closeTimer, 3000);
|
t.schedule(closeTimer, duration);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -37,9 +37,12 @@ public class RoarPreference implements Preference {
|
|||||||
|
|
||||||
|
|
||||||
private RoarPreferencePanel _prefPanel;
|
private RoarPreferencePanel _prefPanel;
|
||||||
|
private RoarProperties _props;
|
||||||
|
|
||||||
public RoarPreference() {
|
public RoarPreference() {
|
||||||
|
|
||||||
|
_props = new RoarProperties();
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (EventQueue.isDispatchThread()) {
|
if (EventQueue.isDispatchThread()) {
|
||||||
_prefPanel = new RoarPreferencePanel();
|
_prefPanel = new RoarPreferencePanel();
|
||||||
@ -90,15 +93,19 @@ public class RoarPreference implements Preference {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void load() {
|
public void load() {
|
||||||
|
_prefPanel.setBackgroundColor(_props.getBackgroundColor());
|
||||||
|
_prefPanel.setShowingPopups(_props.getShowingPopups());
|
||||||
|
_prefPanel.setDuration(_props.getDuration());
|
||||||
|
_prefPanel.setAmount(_props.getMaximumPopups());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void commit() {
|
public void commit() {
|
||||||
|
_props.setDuration(_prefPanel.getDuration());
|
||||||
RoarProperties props = new RoarProperties();
|
_props.setShowingPopups(_prefPanel.getShowingPopups());
|
||||||
|
_props.setBackgroundColor(_prefPanel.getBackgroundColor());
|
||||||
props.setBackgroundColor(_prefPanel.getBackgroundColor());
|
_props.setMaximumPopups(_prefPanel.getAmount());
|
||||||
props.save();
|
_props.save();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -114,7 +121,7 @@ public class RoarPreference implements Preference {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object getData() {
|
public Object getData() {
|
||||||
return null;
|
return _props;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@ -21,10 +21,15 @@ package org.jivesoftware.spark.roar;
|
|||||||
|
|
||||||
import java.awt.Color;
|
import java.awt.Color;
|
||||||
import java.awt.Graphics;
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GridBagConstraints;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
import java.awt.Image;
|
import java.awt.Image;
|
||||||
|
import java.awt.Insets;
|
||||||
|
|
||||||
|
import javax.swing.BorderFactory;
|
||||||
import javax.swing.ImageIcon;
|
import javax.swing.ImageIcon;
|
||||||
import javax.swing.JButton;
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.JPanel;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.JTextField;
|
import javax.swing.JTextField;
|
||||||
|
|
||||||
@ -43,38 +48,106 @@ public class RoarPreferencePanel extends JPanel {
|
|||||||
private Image _backgroundimage;
|
private Image _backgroundimage;
|
||||||
|
|
||||||
private JTextField _color;
|
private JTextField _color;
|
||||||
|
private JTextField _duration;
|
||||||
|
private JTextField _amount;
|
||||||
|
private JCheckBox _checkbox;
|
||||||
|
|
||||||
public RoarPreferencePanel() {
|
public RoarPreferencePanel() {
|
||||||
|
|
||||||
|
JPanel contents = new JPanel();
|
||||||
|
contents.setLayout(new GridBagLayout());
|
||||||
|
contents.setBackground(new Color(0,0,0,0));
|
||||||
this.setLayout(new VerticalFlowLayout());
|
this.setLayout(new VerticalFlowLayout());
|
||||||
|
contents.setBorder(BorderFactory.createTitledBorder("Roar Settings"));
|
||||||
|
|
||||||
|
|
||||||
|
add(contents);
|
||||||
|
|
||||||
ClassLoader cl = getClass().getClassLoader();
|
ClassLoader cl = getClass().getClassLoader();
|
||||||
_backgroundimage = new ImageIcon(cl.getResource("background.png"))
|
_backgroundimage = new ImageIcon(cl.getResource("background.png"))
|
||||||
.getImage();
|
.getImage();
|
||||||
|
|
||||||
RoarProperties props = new RoarProperties();
|
_color = new JTextField();
|
||||||
|
_duration = new JTextField();
|
||||||
|
_amount = new JTextField();
|
||||||
|
|
||||||
String farbe = props.getProperty(RoarProperties.BACKGROUNDCOLOR);
|
_checkbox = new JCheckBox("Popups enabled");
|
||||||
|
_checkbox.setBackground(new Color(0,0,0,0));
|
||||||
|
|
||||||
|
Insets in = new Insets(5,5,5,5);
|
||||||
|
|
||||||
|
contents.add(new JLabel("Background color:"), new GridBagConstraints(0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
contents.add(_color, new GridBagConstraints(1, 0, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
|
||||||
|
contents.add(new JLabel("Duration in ms:"), new GridBagConstraints(0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
contents.add(_duration, new GridBagConstraints(1, 1, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
|
||||||
|
contents.add(new JLabel("Maximum Popups on Screen (0=infinity):"), new GridBagConstraints(0, 2, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
contents.add(_amount, new GridBagConstraints(1, 2, 1, 1, 1.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
|
||||||
|
|
||||||
|
contents.add(_checkbox, new GridBagConstraints(0, 3, 1, 1, 0.0, 0.0, GridBagConstraints.NORTHWEST, GridBagConstraints.BOTH, in, 0, 0));
|
||||||
|
|
||||||
_color = new JTextField(farbe);
|
|
||||||
_color.setSize(200, 20);
|
|
||||||
JButton button = new JButton("activate");
|
|
||||||
this.add(button);
|
|
||||||
this.add(_color);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
g.drawImage(_backgroundimage, 0, 0, this.getWidth(), this.getHeight(),
|
|
||||||
this);
|
int imgwi = _backgroundimage.getWidth(null);
|
||||||
|
int imghe = _backgroundimage.getHeight(null);
|
||||||
|
|
||||||
|
int x = this.getSize().width;
|
||||||
|
x = (x/2)-(imgwi/2) < 0 ? 0 : (x/2)-(imgwi/2) ;
|
||||||
|
|
||||||
|
int y = this.getSize().height;
|
||||||
|
y = (y/2) -(imghe/2)< 0 ? 0 : y/2-(imghe/2) ;
|
||||||
|
|
||||||
|
g.drawImage(_backgroundimage, x, y, this);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public Color getBackgroundColor() {
|
public Color getBackgroundColor() {
|
||||||
try {
|
return RoarProperties.convertString(_color.getText());
|
||||||
String[] arr = _color.getText().split(",");
|
}
|
||||||
|
|
||||||
return new Color(Integer.parseInt(arr[0]),
|
public void setBackgroundColor(Color c)
|
||||||
Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
|
{
|
||||||
|
_color.setText(RoarProperties.convertColor(c));
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean getShowingPopups() {
|
||||||
|
return _checkbox.isSelected();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setShowingPopups(boolean pop) {
|
||||||
|
_checkbox.setSelected(pop);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
try {
|
||||||
|
return Integer.parseInt(_duration.getText());
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
return Color.BLACK;
|
return 3000;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDuration(int duration)
|
||||||
|
{
|
||||||
|
_duration.setText(""+duration);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setAmount(int am)
|
||||||
|
{
|
||||||
|
_amount.setText(""+am);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getAmount()
|
||||||
|
{
|
||||||
|
return Integer.parseInt(_amount.getText());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@ -27,12 +27,19 @@ import java.io.IOException;
|
|||||||
import java.util.Properties;
|
import java.util.Properties;
|
||||||
|
|
||||||
import org.jivesoftware.Spark;
|
import org.jivesoftware.Spark;
|
||||||
|
/**
|
||||||
|
* RoarProperties file stuff
|
||||||
|
* @author wolf.posdorfer
|
||||||
|
*
|
||||||
|
*/
|
||||||
public class RoarProperties {
|
public class RoarProperties {
|
||||||
private Properties props;
|
private Properties props;
|
||||||
private File configFile;
|
private File configFile;
|
||||||
|
|
||||||
public static final String BACKGROUNDCOLOR = "backgroundcolor";
|
public static final String BACKGROUNDCOLOR = "backgroundcolor";
|
||||||
|
public static final String DURATION = "duration";
|
||||||
|
public static final String ACTIVE = "active";
|
||||||
|
public static final String AMOUNT = "amount";
|
||||||
|
|
||||||
public RoarProperties() {
|
public RoarProperties() {
|
||||||
this.props = new Properties();
|
this.props = new Properties();
|
||||||
@ -54,18 +61,19 @@ public class RoarProperties {
|
|||||||
|
|
||||||
public void save() {
|
public void save() {
|
||||||
try {
|
try {
|
||||||
props.store(new FileOutputStream(getConfigFile()), "");
|
props.store(new FileOutputStream(getConfigFile()),
|
||||||
|
"Storing ROAR properties");
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
e.printStackTrace();
|
e.printStackTrace();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean showingPopups() {
|
public boolean getShowingPopups() {
|
||||||
return getBoolean("popups", true);
|
return getBoolean(ACTIVE, true);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setShowingPopups(boolean popups) {
|
public void setShowingPopups(boolean popups) {
|
||||||
setBoolean("popups", popups);
|
setBoolean(ACTIVE, popups);
|
||||||
}
|
}
|
||||||
|
|
||||||
public Color getBackgroundColor() {
|
public Color getBackgroundColor() {
|
||||||
@ -76,6 +84,28 @@ public class RoarProperties {
|
|||||||
setColor(BACKGROUNDCOLOR, c);
|
setColor(BACKGROUNDCOLOR, c);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public int getDuration() {
|
||||||
|
|
||||||
|
return getInt(DURATION) == 0 ? 3000 : getInt(DURATION);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setDuration(int dur) {
|
||||||
|
setInt(DURATION, dur);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaximumPopups() {
|
||||||
|
return getInt(AMOUNT);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMaximumPopups(int amount) {
|
||||||
|
setInt(AMOUNT, amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================================================================
|
||||||
|
// ===============================================================================
|
||||||
|
// ===============================================================================
|
||||||
private boolean getBoolean(String property, boolean defaultValue) {
|
private boolean getBoolean(String property, boolean defaultValue) {
|
||||||
return Boolean.parseBoolean(props.getProperty(property,
|
return Boolean.parseBoolean(props.getProperty(property,
|
||||||
Boolean.toString(defaultValue)));
|
Boolean.toString(defaultValue)));
|
||||||
@ -85,29 +115,53 @@ public class RoarProperties {
|
|||||||
props.setProperty(property, Boolean.toString(value));
|
props.setProperty(property, Boolean.toString(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private int getInt(String property) {
|
||||||
|
return Integer.parseInt(props.getProperty(property, "0"));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setInt(String property, int integer) {
|
||||||
|
props.setProperty(property, "" + integer);
|
||||||
|
}
|
||||||
|
|
||||||
private void setColor(String property, Color color) {
|
private void setColor(String property, Color color) {
|
||||||
String c = color.getRed() + "," + color.getGreen() + ","
|
props.setProperty(property, convertColor(color));
|
||||||
+ color.getBlue();
|
|
||||||
props.setProperty(property, c);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Color getColor(String property) {
|
private Color getColor(String property) {
|
||||||
try {
|
return convertString(props.getProperty(property));
|
||||||
String c = props.getProperty(property);
|
|
||||||
|
|
||||||
String[] arr = c.split(",");
|
|
||||||
return new Color(Integer.parseInt(arr[0]),
|
|
||||||
Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
|
|
||||||
} catch (Exception e) {
|
|
||||||
setColor(property,Color.BLACK);
|
|
||||||
save();
|
|
||||||
return Color.BLACK;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public String getProperty(String property)
|
public String getProperty(String property) {
|
||||||
{
|
|
||||||
return props.getProperty(property);
|
return props.getProperty(property);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a {@link String} matching xxx,xxx,xxx to a {@link Color}<br>
|
||||||
|
* where xxx is a number from 0 to 255
|
||||||
|
*
|
||||||
|
* @param s
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static Color convertString(String s) {
|
||||||
|
try {
|
||||||
|
String[] arr = s.split(",");
|
||||||
|
return new Color(Integer.parseInt(arr[0]),
|
||||||
|
Integer.parseInt(arr[1]), Integer.parseInt(arr[2]));
|
||||||
|
} catch (Exception e) {
|
||||||
|
return Color.black;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Converts a {@link Color} to a {@link String} in this format:<br>
|
||||||
|
* <b>xxx,xxx,xxx</b> <br>
|
||||||
|
* where xxx is a number from 0 to 255
|
||||||
|
*
|
||||||
|
* @param color
|
||||||
|
* @return
|
||||||
|
*/
|
||||||
|
public static String convertColor(Color color) {
|
||||||
|
return color.getRed() + "," + color.getGreen() + "," + color.getBlue();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user