mirror of
https://github.com/robertvokac/time-calc.git
synced 2025-03-25 07:27:49 +01:00
Code was formatted
This commit is contained in:
parent
7f58f2422a
commit
0b06f31d84
@ -1,3 +1,3 @@
|
|||||||
mvn clean package
|
mvn clean package
|
||||||
mv target/*jar-with-all-dependencies*.jar C:/Users/Robert/Desktop/rv
|
mv target/*jar-with-all-dependencies*.jar C:/Users/Robert/Desktop/rv
|
||||||
rm -r target
|
rm -r target
|
||||||
|
62
pom.xml
62
pom.xml
@ -1,6 +1,6 @@
|
|||||||
<?xml version="1.0" encoding="UTF-8"?>
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
<project xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns="http://maven.apache.org/POM/4.0.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
|
|
||||||
@ -48,35 +48,35 @@
|
|||||||
...
|
...
|
||||||
-->
|
-->
|
||||||
</plugin>
|
</plugin>
|
||||||
<plugin>
|
<plugin>
|
||||||
<artifactId>maven-assembly-plugin</artifactId>
|
<artifactId>maven-assembly-plugin</artifactId>
|
||||||
<configuration>
|
<configuration>
|
||||||
<archive>
|
<archive>
|
||||||
<manifest>
|
<manifest>
|
||||||
<mainClass>rvc.timecalc.Main</mainClass>
|
<mainClass>rvc.timecalc.Main</mainClass>
|
||||||
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
<addDefaultImplementationEntries>true</addDefaultImplementationEntries>
|
||||||
</manifest>
|
</manifest>
|
||||||
<manifestEntries>
|
<manifestEntries>
|
||||||
<Build-Date>${timestamp}</Build-Date>
|
<Build-Date>${timestamp}</Build-Date>
|
||||||
</manifestEntries>
|
</manifestEntries>
|
||||||
</archive>
|
</archive>
|
||||||
<!-- <descriptorRefs>-->
|
<!-- <descriptorRefs>-->
|
||||||
<!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
|
<!-- <descriptorRef>jar-with-dependencies</descriptorRef>-->
|
||||||
<!-- </descriptorRefs>-->
|
<!-- </descriptorRefs>-->
|
||||||
<descriptors>
|
<descriptors>
|
||||||
<descriptor>./src/main/resources/install.xml</descriptor>
|
<descriptor>./src/main/resources/install.xml</descriptor>
|
||||||
</descriptors>
|
</descriptors>
|
||||||
</configuration>
|
</configuration>
|
||||||
<executions>
|
<executions>
|
||||||
<execution>
|
<execution>
|
||||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||||
<goals>
|
<goals>
|
||||||
<goal>single</goal>
|
<goal>single</goal>
|
||||||
</goals>
|
</goals>
|
||||||
</execution>
|
</execution>
|
||||||
</executions>
|
</executions>
|
||||||
</plugin>
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
</project>
|
</project>
|
@ -18,15 +18,11 @@ import java.util.GregorianCalendar;
|
|||||||
//https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
|
//https://kodejava.org/how-do-i-write-a-simple-analog-clock-using-java-2d/
|
||||||
public class AnalogClock extends JPanel {
|
public class AnalogClock extends JPanel {
|
||||||
|
|
||||||
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
private static final Color FOREGROUND_COLOR = new Color(220, 220, 220);
|
||||||
private static final Color BACKGROUND_COLOR = new Color(238,238,238);
|
private static final Color BACKGROUND_COLOR = new Color(238, 238, 238);
|
||||||
|
|
||||||
private boolean highlight = false;
|
private boolean highlight = false;
|
||||||
|
|
||||||
public void setHighlight(boolean highlight) {
|
|
||||||
this.highlight = highlight;
|
|
||||||
}
|
|
||||||
|
|
||||||
public AnalogClock() {
|
public AnalogClock() {
|
||||||
setPreferredSize(new Dimension(400, 300));
|
setPreferredSize(new Dimension(400, 300));
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
@ -60,6 +56,18 @@ public class AnalogClock extends JPanel {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static void main(String[] args) {
|
||||||
|
JFrame frame = new JFrame("Analog Clock");
|
||||||
|
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
||||||
|
frame.add(new AnalogClock());
|
||||||
|
frame.pack();
|
||||||
|
frame.setVisible(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setHighlight(boolean highlight) {
|
||||||
|
this.highlight = highlight;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
super.paintComponent(g);
|
super.paintComponent(g);
|
||||||
@ -77,8 +85,11 @@ public class AnalogClock extends JPanel {
|
|||||||
int hour = time.get(Calendar.HOUR_OF_DAY);
|
int hour = time.get(Calendar.HOUR_OF_DAY);
|
||||||
|
|
||||||
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED);
|
drawHand(g2d, side / 2 - 10, second / 60.0, 0.5f, Color.RED);
|
||||||
drawHand(g2d, side / 2 - 20, minute / 60.0 + second / 60.0 / 60.0, 2.0f, Color.BLUE);
|
drawHand(g2d, side / 2 - 20, minute / 60.0 + second / 60.0 / 60.0, 2.0f,
|
||||||
drawHand(g2d, side / 2 - 40, hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12, 4.0f, Color.BLACK);
|
Color.BLUE);
|
||||||
|
drawHand(g2d, side / 2 - 40,
|
||||||
|
hour / 12.0 + minute / 60.0 / 12 + second / 60 / 60 / 12, 4.0f,
|
||||||
|
Color.BLACK);
|
||||||
|
|
||||||
// Draw clock numbers and circle
|
// Draw clock numbers and circle
|
||||||
drawClockFace(g2d, centerX, centerY, side / 2 - 40);
|
drawClockFace(g2d, centerX, centerY, side / 2 - 40);
|
||||||
@ -86,7 +97,7 @@ public class AnalogClock extends JPanel {
|
|||||||
|
|
||||||
private void drawHand(Graphics2D g2d, int length, double value,
|
private void drawHand(Graphics2D g2d, int length, double value,
|
||||||
float stroke, Color color) {
|
float stroke, Color color) {
|
||||||
length= length - 4;
|
length = length - 4;
|
||||||
double angle = Math.PI * 2 * (value - 0.25);
|
double angle = Math.PI * 2 * (value - 0.25);
|
||||||
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
|
int endX = (int) (getWidth() / 2 + length * Math.cos(angle));
|
||||||
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
|
int endY = (int) (getHeight() / 2 + length * Math.sin(angle));
|
||||||
@ -100,13 +111,13 @@ public class AnalogClock extends JPanel {
|
|||||||
int radius) {
|
int radius) {
|
||||||
g2d.setStroke(new BasicStroke(2.0f));
|
g2d.setStroke(new BasicStroke(2.0f));
|
||||||
g2d.setColor(highlight ? Color.BLACK : FOREGROUND_COLOR);
|
g2d.setColor(highlight ? Color.BLACK : FOREGROUND_COLOR);
|
||||||
// System.out.println("centerX=" + centerX);
|
// System.out.println("centerX=" + centerX);
|
||||||
// System.out.println("centerY=" + centerY);
|
// System.out.println("centerY=" + centerY);
|
||||||
// System.out.println("radius=" + radius);
|
// System.out.println("radius=" + radius);
|
||||||
g2d.drawOval(1, 1, centerX * 2 - 4, centerY * 2 - 4);
|
g2d.drawOval(1, 1, centerX * 2 - 4, centerY * 2 - 4);
|
||||||
g2d.drawOval(2, 2, centerX * 2 - 4, centerY * 2 - 4);
|
g2d.drawOval(2, 2, centerX * 2 - 4, centerY * 2 - 4);
|
||||||
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
|
// g2d.drawOval(3, 3, centerX * 2 - 6, centerY * 2 - 6);
|
||||||
// g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8);
|
// g2d.drawOval(4, 4, centerX * 2 - 8, centerY * 2 - 8);
|
||||||
|
|
||||||
for (int i = 1; i <= 12; i++) {
|
for (int i = 1; i <= 12; i++) {
|
||||||
double angle = Math.PI * 2 * (i / 12.0 - 0.25);
|
double angle = Math.PI * 2 * (i / 12.0 - 0.25);
|
||||||
@ -117,12 +128,4 @@ public class AnalogClock extends JPanel {
|
|||||||
g2d.drawString(Integer.toString(i), dx, dy);
|
g2d.drawString(Integer.toString(i), dx, dy);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) {
|
|
||||||
JFrame frame = new JFrame("Analog Clock");
|
|
||||||
frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
|
|
||||||
frame.add(new AnalogClock());
|
|
||||||
frame.pack();
|
|
||||||
frame.setVisible(true);
|
|
||||||
}
|
|
||||||
}
|
}
|
@ -8,34 +8,35 @@ import javax.swing.JOptionPane;
|
|||||||
*/
|
*/
|
||||||
public class Main {
|
public class Main {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
while(true) {
|
while (true) {
|
||||||
boolean test = false;
|
boolean test = false;
|
||||||
String startTime = test ? "7:00" : (String) JOptionPane.showInputDialog(
|
String startTime =
|
||||||
null,
|
test ? "7:00" : (String) JOptionPane.showInputDialog(
|
||||||
"Start Time:",
|
null,
|
||||||
"Start Time",
|
"Start Time:",
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
"Start Time",
|
||||||
null,
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
null,
|
null,
|
||||||
"7:00"
|
null,
|
||||||
);
|
"7:00"
|
||||||
String overTime = test ? "0:00" : (String) JOptionPane.showInputDialog(
|
);
|
||||||
null,
|
String overTime =
|
||||||
"Overtime:",
|
test ? "0:00" : (String) JOptionPane.showInputDialog(
|
||||||
"Overtime",
|
null,
|
||||||
JOptionPane.PLAIN_MESSAGE,
|
"Overtime:",
|
||||||
null,
|
"Overtime",
|
||||||
null,
|
JOptionPane.PLAIN_MESSAGE,
|
||||||
"0:00"
|
null,
|
||||||
);
|
null,
|
||||||
|
"0:00"
|
||||||
|
);
|
||||||
try {
|
try {
|
||||||
TimeCalcWindow timeCalc =
|
TimeCalcWindow timeCalc =
|
||||||
new TimeCalcWindow(startTime, overTime);
|
new TimeCalcWindow(startTime, overTime);
|
||||||
} catch(Exception e) {
|
} catch (Exception e) {
|
||||||
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(), e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
JOptionPane.showMessageDialog(null, "Error: " + e.getMessage(),
|
||||||
|
e.getMessage(), JOptionPane.ERROR_MESSAGE);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -15,14 +15,8 @@ public class ProgressSquare extends JPanel {
|
|||||||
private int side = 0;
|
private int side = 0;
|
||||||
private int square;
|
private int square;
|
||||||
|
|
||||||
|
|
||||||
private double donePercent = 0;
|
private double donePercent = 0;
|
||||||
|
|
||||||
public void setDonePercent(double donePercent) {
|
|
||||||
this.donePercent = donePercent;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
public ProgressSquare() {
|
public ProgressSquare() {
|
||||||
setPreferredSize(new Dimension(400, 400));
|
setPreferredSize(new Dimension(400, 400));
|
||||||
setBackground(BACKGROUND_COLOR);
|
setBackground(BACKGROUND_COLOR);
|
||||||
@ -30,10 +24,14 @@ public class ProgressSquare extends JPanel {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void setDonePercent(double donePercent) {
|
||||||
|
this.donePercent = donePercent;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void paintComponent(Graphics g) {
|
public void paintComponent(Graphics g) {
|
||||||
|
|
||||||
if(side == 0) {
|
if (side == 0) {
|
||||||
this.side = Math.min(getWidth(), getHeight());
|
this.side = Math.min(getWidth(), getHeight());
|
||||||
this.square = side * side;
|
this.square = side * side;
|
||||||
}
|
}
|
||||||
@ -43,37 +41,37 @@ public class ProgressSquare extends JPanel {
|
|||||||
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
|
||||||
RenderingHints.VALUE_ANTIALIAS_ON);
|
RenderingHints.VALUE_ANTIALIAS_ON);
|
||||||
|
|
||||||
// System.out.println("square=" + square);
|
// System.out.println("square=" + square);
|
||||||
int dotNumber = (int)(donePercent * square);
|
int dotNumber = (int) (donePercent * square);
|
||||||
int y = dotNumber / side;
|
int y = dotNumber / side;
|
||||||
int x = dotNumber - y * side;
|
int x = dotNumber - y * side;
|
||||||
|
|
||||||
// System.out.println("dotNumber=" + dotNumber);
|
// System.out.println("dotNumber=" + dotNumber);
|
||||||
// System.out.println("x=" + x);
|
// System.out.println("x=" + x);
|
||||||
// System.out.println("y=" + y);
|
// System.out.println("y=" + y);
|
||||||
if(y > 1) {
|
if (y > 1) {
|
||||||
g2d.setColor(Color.GRAY);
|
g2d.setColor(Color.GRAY);
|
||||||
g2d.fillRect(side - 4, side - 4, 4, 4);
|
g2d.fillRect(side - 4, side - 4, 4, 4);
|
||||||
g2d.fillRect(1, side - 4, 4, 4);
|
g2d.fillRect(1, side - 4, 4, 4);
|
||||||
|
|
||||||
g2d.setColor(FOREGROUND_COLOR);
|
g2d.setColor(FOREGROUND_COLOR);
|
||||||
g2d.fillRect(1, 1, side, y - 1);
|
g2d.fillRect(1, 1, side, y - 1);
|
||||||
if(x>1) {
|
if (x > 1) {
|
||||||
g2d.drawRect(1, y, x - 1, 1);
|
g2d.drawRect(1, y, x - 1, 1);
|
||||||
}
|
}
|
||||||
g2d.setColor(Color.GRAY);
|
g2d.setColor(Color.GRAY);
|
||||||
g2d.fillRect(side - 4, 1, 4, 4);
|
g2d.fillRect(side - 4, 1, 4, 4);
|
||||||
g2d.fillRect(1, 1, 4, 4);
|
g2d.fillRect(1, 1, 4, 4);
|
||||||
|
|
||||||
g2d.setColor(Color.GRAY);
|
g2d.setColor(Color.GRAY);
|
||||||
g2d.drawLine(1, 1, x, y);
|
g2d.drawLine(1, 1, x, y);
|
||||||
// g2d.drawLine(1+1, 1+1, x+1, y+1);
|
// g2d.drawLine(1+1, 1+1, x+1, y+1);
|
||||||
g2d.drawLine(1, 1+1, x, y+1);
|
g2d.drawLine(1, 1 + 1, x, y + 1);
|
||||||
g2d.drawLine(1, 1+1, x, y+1);
|
g2d.drawLine(1, 1 + 1, x, y + 1);
|
||||||
g2d.setColor(Color.BLUE);
|
g2d.setColor(Color.BLUE);
|
||||||
g2d.drawLine(x-10, y-10, x+10, y+10);
|
g2d.drawLine(x - 10, y - 10, x + 10, y + 10);
|
||||||
g2d.drawLine(x+10, y-10, x-10, y+10);
|
g2d.drawLine(x + 10, y - 10, x - 10, y + 10);
|
||||||
g2d.setColor(FOREGROUND_COLOR);
|
g2d.setColor(FOREGROUND_COLOR);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
File diff suppressed because one or more lines are too long
@ -2,550 +2,275 @@ package rvc.timecalc;
|
|||||||
/**
|
/**
|
||||||
* Java Toaster is a java utility class for your swing applications
|
* Java Toaster is a java utility class for your swing applications
|
||||||
* that show an animate box coming from the bottom of your screen
|
* that show an animate box coming from the bottom of your screen
|
||||||
* with a notification message and/or an associated image
|
* with a notification message and/or an associated image
|
||||||
* (like msn online/offline notifications).
|
* (like msn online/offline notifications).
|
||||||
*
|
* <p>
|
||||||
* Toaster panel in windows system follow the taskbar; So if
|
* Toaster panel in windows system follow the taskbar; So if
|
||||||
* the taskbar is into the bottom the panel coming from the bottom
|
* the taskbar is into the bottom the panel coming from the bottom
|
||||||
* and if the taskbar is on the top then the panel coming from the top.
|
* and if the taskbar is on the top then the panel coming from the top.
|
||||||
*
|
* <p>
|
||||||
* This is a simple example of utilization:
|
* This is a simple example of utilization:
|
||||||
*
|
* <p>
|
||||||
* import com.nitido.utils.toaster.*;
|
* import com.nitido.utils.toaster.*;
|
||||||
* import javax.swing.*;
|
* import javax.swing.*;
|
||||||
*
|
* <p>
|
||||||
* public class ToasterTest
|
* public class ToasterTest
|
||||||
* {
|
* {
|
||||||
*
|
* <p>
|
||||||
* public static void main(String[] args)
|
* public static void main(String[] args)
|
||||||
* {
|
* {
|
||||||
* // Initialize toaster manager...
|
* // Initialize toaster manager...
|
||||||
* Toaster toasterManager = new Toaster();
|
* Toaster toasterManager = new Toaster();
|
||||||
*
|
* <p>
|
||||||
* // Show a simple toaster
|
* // Show a simple toaster
|
||||||
* toasterManager.showToaster( new ImageIcon( "mylogo.gif" ), "A simple toaster with an image" );
|
* toasterManager.showToaster( new ImageIcon( "mylogo.gif" ), "A simple toaster with an image" );
|
||||||
* }
|
* }
|
||||||
* }
|
* }
|
||||||
*/
|
*/
|
||||||
|
|
||||||
import java.awt.*;
|
import javax.swing.BorderFactory;
|
||||||
import java.awt.event.ActionEvent;
|
import javax.swing.Icon;
|
||||||
import java.awt.event.ActionListener;
|
import javax.swing.JButton;
|
||||||
|
import javax.swing.JLabel;
|
||||||
import javax.swing.*;
|
import javax.swing.JPanel;
|
||||||
import javax.swing.border.*;
|
import javax.swing.JTextArea;
|
||||||
|
import javax.swing.JWindow;
|
||||||
|
import javax.swing.border.EtchedBorder;
|
||||||
|
import java.awt.BorderLayout;
|
||||||
|
import java.awt.Color;
|
||||||
|
import java.awt.Font;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GraphicsEnvironment;
|
||||||
|
import java.awt.Image;
|
||||||
|
import java.awt.Insets;
|
||||||
|
import java.awt.Rectangle;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Class to show tosters in multiplatform
|
* Class to show tosters in multiplatform
|
||||||
*
|
*
|
||||||
* @author daniele piras
|
* @author daniele piras
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class Toaster
|
public class Toaster {
|
||||||
{
|
private static final long serialVersionUID = 1L;
|
||||||
// Width of the toster
|
// Set the margin
|
||||||
private int toasterWidth = 300;
|
int margin;
|
||||||
|
// Flag that indicate if use alwaysOnTop or not.
|
||||||
|
// method always on top start only SINCE JDK 5 !
|
||||||
|
boolean useAlwaysOnTop = true;
|
||||||
|
// Width of the toster
|
||||||
|
private int toasterWidth = 300;
|
||||||
|
// Height of the toster
|
||||||
|
private int toasterHeight = 80;
|
||||||
|
// Step for the toaster
|
||||||
|
private int step = 20;
|
||||||
|
// Step time
|
||||||
|
private int stepTime = 20;
|
||||||
|
// Show time
|
||||||
|
private int displayTime = 3000;
|
||||||
|
// Current number of toaster...
|
||||||
|
private int currentNumberOfToaster = 0;
|
||||||
|
// Last opened toaster
|
||||||
|
private int maxToaster = 0;
|
||||||
|
// Max number of toasters for the sceen
|
||||||
|
private int maxToasterInSceen;
|
||||||
|
// Background image
|
||||||
|
private Image backgroundImage;
|
||||||
|
// Font used to display message
|
||||||
|
private Font font;
|
||||||
|
// Color for border
|
||||||
|
private Color borderColor;
|
||||||
|
// Color for toaster
|
||||||
|
private Color toasterColor;
|
||||||
|
// Set message color
|
||||||
|
private Color messageColor;
|
||||||
|
|
||||||
// Height of the toster
|
/**
|
||||||
private int toasterHeight = 80;
|
* Constructor to initialized toaster component...
|
||||||
|
*
|
||||||
// Step for the toaster
|
* @author daniele piras
|
||||||
private int step = 20;
|
*
|
||||||
|
*/
|
||||||
// Step time
|
public Toaster() {
|
||||||
private int stepTime = 20;
|
// Set default font...
|
||||||
|
font = new Font("Arial", Font.BOLD, 12);
|
||||||
// Show time
|
// Border color
|
||||||
private int displayTime = 3000;
|
borderColor = new Color(245, 153, 15);
|
||||||
|
toasterColor = Color.WHITE;
|
||||||
// Current number of toaster...
|
messageColor = Color.BLACK;
|
||||||
private int currentNumberOfToaster = 0;
|
useAlwaysOnTop = true;
|
||||||
|
// Verify AlwaysOnTop Flag...
|
||||||
// Last opened toaster
|
try {
|
||||||
private int maxToaster = 0;
|
JWindow.class
|
||||||
|
.getMethod("setAlwaysOnTop", new Class[] {Boolean.class});
|
||||||
// Max number of toasters for the sceen
|
} catch (Exception e) {
|
||||||
private int maxToasterInSceen;
|
useAlwaysOnTop = false;
|
||||||
|
|
||||||
// Background image
|
|
||||||
private Image backgroundImage;
|
|
||||||
|
|
||||||
// Font used to display message
|
|
||||||
private Font font;
|
|
||||||
|
|
||||||
// Color for border
|
|
||||||
private Color borderColor;
|
|
||||||
|
|
||||||
// Color for toaster
|
|
||||||
private Color toasterColor;
|
|
||||||
|
|
||||||
// Set message color
|
|
||||||
private Color messageColor;
|
|
||||||
|
|
||||||
// Set the margin
|
|
||||||
int margin;
|
|
||||||
|
|
||||||
// Flag that indicate if use alwaysOnTop or not.
|
|
||||||
// method always on top start only SINCE JDK 5 !
|
|
||||||
boolean useAlwaysOnTop = true;
|
|
||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Constructor to initialized toaster component...
|
|
||||||
*
|
|
||||||
* @author daniele piras
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
public Toaster()
|
|
||||||
{
|
|
||||||
// Set default font...
|
|
||||||
font = new Font("Arial", Font.BOLD, 12);
|
|
||||||
// Border color
|
|
||||||
borderColor = new Color(245, 153, 15);
|
|
||||||
toasterColor = Color.WHITE;
|
|
||||||
messageColor = Color.BLACK;
|
|
||||||
useAlwaysOnTop = true;
|
|
||||||
// Verify AlwaysOnTop Flag...
|
|
||||||
try
|
|
||||||
{
|
|
||||||
JWindow.class.getMethod( "setAlwaysOnTop", new Class[] { Boolean.class } );
|
|
||||||
}
|
|
||||||
catch( Exception e )
|
|
||||||
{
|
|
||||||
useAlwaysOnTop = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Class that rappresent a single toaster
|
|
||||||
*
|
|
||||||
* @author daniele piras
|
|
||||||
*
|
|
||||||
*/
|
|
||||||
class SingleToaster extends JWindow
|
|
||||||
{
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
// Label to store Icon
|
|
||||||
private JLabel iconLabel = new JLabel();
|
|
||||||
|
|
||||||
// Text area for the message
|
|
||||||
private JTextArea message = new JTextArea();
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Simple costructor that initialized components...
|
|
||||||
*/
|
|
||||||
public SingleToaster()
|
|
||||||
{
|
|
||||||
initComponents();
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Function to initialized components
|
|
||||||
*/
|
|
||||||
private void initComponents()
|
|
||||||
{
|
|
||||||
|
|
||||||
setSize(toasterWidth, toasterHeight);
|
|
||||||
message.setFont( getToasterMessageFont() );
|
|
||||||
JPanel externalPanel = new JPanel(new BorderLayout(1, 1));
|
|
||||||
externalPanel.setBackground( getBorderColor() );
|
|
||||||
JPanel innerPanel = new JPanel(new BorderLayout( getMargin(), getMargin() ))
|
|
||||||
|
|
||||||
{
|
|
||||||
@Override
|
|
||||||
public void paint(Graphics g) {
|
|
||||||
if ( getBackgroundImage() != null )
|
|
||||||
{
|
|
||||||
g.drawImage(getBackgroundImage(),0,0,null);
|
|
||||||
}
|
|
||||||
super.paint(g);
|
|
||||||
}
|
}
|
||||||
};
|
|
||||||
if ( getBackgroundImage() != null )
|
|
||||||
{
|
|
||||||
innerPanel.setOpaque(false);
|
|
||||||
message.setOpaque(false);
|
|
||||||
iconLabel.setOpaque(false);
|
|
||||||
}
|
|
||||||
innerPanel.setBackground( getToasterColor() );
|
|
||||||
message.setBackground( getToasterColor() );
|
|
||||||
message.setMargin( new Insets( 2,2,2,2 ) );
|
|
||||||
message.setLineWrap( true );
|
|
||||||
message.setWrapStyleWord( true );
|
|
||||||
EtchedBorder etchedBorder = (EtchedBorder) BorderFactory
|
|
||||||
.createEtchedBorder();
|
|
||||||
externalPanel.setBorder(etchedBorder);
|
|
||||||
externalPanel.add(innerPanel);
|
|
||||||
message.setForeground( getMessageColor() );
|
|
||||||
innerPanel.add(iconLabel, BorderLayout.WEST);
|
|
||||||
innerPanel.add(message, BorderLayout.CENTER);
|
|
||||||
getContentPane().add(externalPanel);
|
|
||||||
JButton closeButton=new JButton("Close");
|
|
||||||
closeButton.setBounds(480,10,100, 40);
|
|
||||||
innerPanel.add(closeButton,BorderLayout.BEFORE_FIRST_LINE);
|
|
||||||
closeButton.addActionListener(e -> {setVisible(false); dispose();});
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Start toaster animation...
|
|
||||||
*/
|
|
||||||
public void animate()
|
|
||||||
{
|
|
||||||
( new Animation( this ) ).start();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
/***
|
|
||||||
* Class that manage the animation
|
|
||||||
*/
|
|
||||||
class Animation extends Thread
|
|
||||||
{
|
|
||||||
SingleToaster toaster;
|
|
||||||
|
|
||||||
public Animation( SingleToaster toaster )
|
|
||||||
{
|
|
||||||
this.toaster = toaster;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Animate vertically the toaster. The toaster could be moved from bottom
|
|
||||||
* to upper or to upper to bottom
|
|
||||||
* @param posx
|
|
||||||
* @param fromY
|
|
||||||
* @param toY
|
|
||||||
* @throws InterruptedException
|
|
||||||
*/
|
|
||||||
protected void animateVertically( int posx, int fromY, int toY ) throws InterruptedException
|
|
||||||
{
|
|
||||||
|
|
||||||
toaster.setLocation( posx, fromY );
|
|
||||||
if ( toY < fromY )
|
|
||||||
{
|
|
||||||
for (int i = fromY; i > toY; i -= step)
|
|
||||||
{
|
|
||||||
toaster.setLocation(posx, i);
|
|
||||||
Thread.sleep(stepTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
for (int i = fromY; i < toY; i += step)
|
|
||||||
{
|
|
||||||
toaster.setLocation(posx, i);
|
|
||||||
Thread.sleep(stepTime);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
toaster.setLocation( posx, toY );
|
|
||||||
}
|
|
||||||
|
|
||||||
public void run()
|
|
||||||
{
|
|
||||||
try
|
|
||||||
{
|
|
||||||
boolean animateFromBottom = true;
|
|
||||||
GraphicsEnvironment ge = GraphicsEnvironment
|
|
||||||
.getLocalGraphicsEnvironment();
|
|
||||||
Rectangle screenRect = ge.getMaximumWindowBounds();
|
|
||||||
|
|
||||||
int screenHeight = (int) screenRect.height;
|
|
||||||
|
|
||||||
int startYPosition;
|
|
||||||
int stopYPosition;
|
|
||||||
|
|
||||||
if ( screenRect.y > 0 )
|
|
||||||
{
|
|
||||||
animateFromBottom = false; // Animate from top!
|
|
||||||
}
|
|
||||||
|
|
||||||
maxToasterInSceen = screenHeight / toasterHeight;
|
|
||||||
|
|
||||||
|
|
||||||
int posx = (int) screenRect.width - toasterWidth - 1;
|
|
||||||
|
|
||||||
toaster.setLocation(posx, screenHeight);
|
|
||||||
toaster.setVisible(true);
|
|
||||||
if ( useAlwaysOnTop )
|
|
||||||
{
|
|
||||||
toaster.setAlwaysOnTop(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
if ( animateFromBottom )
|
|
||||||
{
|
|
||||||
startYPosition = screenHeight;
|
|
||||||
stopYPosition = startYPosition - toasterHeight - 1;
|
|
||||||
if ( currentNumberOfToaster > 0 )
|
|
||||||
{
|
|
||||||
stopYPosition = stopYPosition - ( maxToaster % maxToasterInSceen * toasterHeight );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxToaster = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
startYPosition = screenRect.y - toasterHeight;
|
|
||||||
stopYPosition = screenRect.y;
|
|
||||||
|
|
||||||
if ( currentNumberOfToaster > 0 )
|
|
||||||
{
|
|
||||||
stopYPosition = stopYPosition + ( maxToaster % maxToasterInSceen * toasterHeight );
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
maxToaster = 0;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
currentNumberOfToaster++;
|
|
||||||
maxToaster++;
|
|
||||||
|
|
||||||
|
|
||||||
animateVertically( posx, startYPosition, stopYPosition );
|
|
||||||
Thread.sleep(displayTime);
|
|
||||||
animateVertically( posx, stopYPosition, startYPosition );
|
|
||||||
|
|
||||||
currentNumberOfToaster--;
|
|
||||||
toaster.setVisible(false);
|
|
||||||
toaster.dispose();
|
|
||||||
} catch (Exception e)
|
|
||||||
{
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* Show a toaster with the specified message and the associated icon.
|
|
||||||
*/
|
|
||||||
public void showToaster(Icon icon, String msg)
|
|
||||||
{
|
|
||||||
SingleToaster singleToaster = new SingleToaster();
|
|
||||||
if ( icon != null )
|
|
||||||
{
|
|
||||||
singleToaster.iconLabel.setIcon( icon );
|
|
||||||
}
|
}
|
||||||
singleToaster.message.setText( msg );
|
|
||||||
|
|
||||||
singleToaster.toFront( );
|
/**
|
||||||
singleToaster.setAlwaysOnTop(true);
|
* Show a toaster with the specified message and the associated icon.
|
||||||
singleToaster.animate();
|
*/
|
||||||
}
|
public void showToaster(Icon icon, String msg) {
|
||||||
|
SingleToaster singleToaster = new SingleToaster();
|
||||||
|
if (icon != null) {
|
||||||
|
singleToaster.iconLabel.setIcon(icon);
|
||||||
|
}
|
||||||
|
singleToaster.message.setText(msg);
|
||||||
|
|
||||||
/**
|
singleToaster.toFront();
|
||||||
* Show a toaster with the specified message.
|
singleToaster.setAlwaysOnTop(true);
|
||||||
*/
|
singleToaster.animate();
|
||||||
public void showToaster( String msg )
|
}
|
||||||
{
|
|
||||||
showToaster( null, msg );
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the font
|
* Show a toaster with the specified message.
|
||||||
*/
|
*/
|
||||||
public Font getToasterMessageFont()
|
public void showToaster(String msg) {
|
||||||
{
|
showToaster(null, msg);
|
||||||
// TODO Auto-generated method stub
|
}
|
||||||
return font;
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Set the font for the message
|
* @return Returns the font
|
||||||
*/
|
*/
|
||||||
public void setToasterMessageFont( Font f)
|
public Font getToasterMessageFont() {
|
||||||
{
|
// TODO Auto-generated method stub
|
||||||
font = f;
|
return font;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
/**
|
* Set the font for the message
|
||||||
* @return Returns the borderColor.
|
*/
|
||||||
*/
|
public void setToasterMessageFont(Font f) {
|
||||||
public Color getBorderColor()
|
font = f;
|
||||||
{
|
}
|
||||||
return borderColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the borderColor.
|
||||||
|
*/
|
||||||
|
public Color getBorderColor() {
|
||||||
|
return borderColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param borderColor The borderColor to set.
|
||||||
|
*/
|
||||||
|
public void setBorderColor(Color borderColor) {
|
||||||
|
this.borderColor = borderColor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param borderColor The borderColor to set.
|
* @return Returns the displayTime.
|
||||||
*/
|
*/
|
||||||
public void setBorderColor(Color borderColor)
|
public int getDisplayTime() {
|
||||||
{
|
return displayTime;
|
||||||
this.borderColor = borderColor;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param displayTime The displayTime to set.
|
||||||
|
*/
|
||||||
|
public void setDisplayTime(int displayTime) {
|
||||||
|
this.displayTime = displayTime;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the margin.
|
||||||
|
*/
|
||||||
|
public int getMargin() {
|
||||||
|
return margin;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the displayTime.
|
* @param margin The margin to set.
|
||||||
*/
|
*/
|
||||||
public int getDisplayTime()
|
public void setMargin(int margin) {
|
||||||
{
|
this.margin = margin;
|
||||||
return displayTime;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the messageColor.
|
||||||
|
*/
|
||||||
|
public Color getMessageColor() {
|
||||||
|
return messageColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param messageColor The messageColor to set.
|
||||||
|
*/
|
||||||
|
public void setMessageColor(Color messageColor) {
|
||||||
|
this.messageColor = messageColor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param displayTime The displayTime to set.
|
* @return Returns the step.
|
||||||
*/
|
*/
|
||||||
public void setDisplayTime(int displayTime)
|
public int getStep() {
|
||||||
{
|
return step;
|
||||||
this.displayTime = displayTime;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param step The step to set.
|
||||||
|
*/
|
||||||
|
public void setStep(int step) {
|
||||||
|
this.step = step;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the stepTime.
|
||||||
|
*/
|
||||||
|
public int getStepTime() {
|
||||||
|
return stepTime;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the margin.
|
* @param stepTime The stepTime to set.
|
||||||
*/
|
*/
|
||||||
public int getMargin()
|
public void setStepTime(int stepTime) {
|
||||||
{
|
this.stepTime = stepTime;
|
||||||
return margin;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the toasterColor.
|
||||||
|
*/
|
||||||
|
public Color getToasterColor() {
|
||||||
|
return toasterColor;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param toasterColor The toasterColor to set.
|
||||||
|
*/
|
||||||
|
public void setToasterColor(Color toasterColor) {
|
||||||
|
this.toasterColor = toasterColor;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param margin The margin to set.
|
* @return Returns the toasterHeight.
|
||||||
*/
|
*/
|
||||||
public void setMargin(int margin)
|
public int getToasterHeight() {
|
||||||
{
|
return toasterHeight;
|
||||||
this.margin = margin;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param toasterHeight The toasterHeight to set.
|
||||||
|
*/
|
||||||
|
public void setToasterHeight(int toasterHeight) {
|
||||||
|
this.toasterHeight = toasterHeight;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @return Returns the toasterWidth.
|
||||||
|
*/
|
||||||
|
public int getToasterWidth() {
|
||||||
|
return toasterWidth;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return Returns the messageColor.
|
* @param toasterWidth The toasterWidth to set.
|
||||||
*/
|
*/
|
||||||
public Color getMessageColor()
|
public void setToasterWidth(int toasterWidth) {
|
||||||
{
|
this.toasterWidth = toasterWidth;
|
||||||
return messageColor;
|
}
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param messageColor The messageColor to set.
|
|
||||||
*/
|
|
||||||
public void setMessageColor(Color messageColor)
|
|
||||||
{
|
|
||||||
this.messageColor = messageColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the step.
|
|
||||||
*/
|
|
||||||
public int getStep()
|
|
||||||
{
|
|
||||||
return step;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param step The step to set.
|
|
||||||
*/
|
|
||||||
public void setStep(int step)
|
|
||||||
{
|
|
||||||
this.step = step;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the stepTime.
|
|
||||||
*/
|
|
||||||
public int getStepTime()
|
|
||||||
{
|
|
||||||
return stepTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param stepTime The stepTime to set.
|
|
||||||
*/
|
|
||||||
public void setStepTime(int stepTime)
|
|
||||||
{
|
|
||||||
this.stepTime = stepTime;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the toasterColor.
|
|
||||||
*/
|
|
||||||
public Color getToasterColor()
|
|
||||||
{
|
|
||||||
return toasterColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param toasterColor The toasterColor to set.
|
|
||||||
*/
|
|
||||||
public void setToasterColor(Color toasterColor)
|
|
||||||
{
|
|
||||||
this.toasterColor = toasterColor;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the toasterHeight.
|
|
||||||
*/
|
|
||||||
public int getToasterHeight()
|
|
||||||
{
|
|
||||||
return toasterHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param toasterHeight The toasterHeight to set.
|
|
||||||
*/
|
|
||||||
public void setToasterHeight(int toasterHeight)
|
|
||||||
{
|
|
||||||
this.toasterHeight = toasterHeight;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @return Returns the toasterWidth.
|
|
||||||
*/
|
|
||||||
public int getToasterWidth()
|
|
||||||
{
|
|
||||||
return toasterWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
/**
|
|
||||||
* @param toasterWidth The toasterWidth to set.
|
|
||||||
*/
|
|
||||||
public void setToasterWidth(int toasterWidth)
|
|
||||||
{
|
|
||||||
this.toasterWidth = toasterWidth;
|
|
||||||
}
|
|
||||||
|
|
||||||
public Image getBackgroundImage() {
|
public Image getBackgroundImage() {
|
||||||
return backgroundImage;
|
return backgroundImage;
|
||||||
@ -555,7 +280,182 @@ public class Toaster
|
|||||||
this.backgroundImage = backgroundImage;
|
this.backgroundImage = backgroundImage;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class that rappresent a single toaster
|
||||||
|
*
|
||||||
|
* @author daniele piras
|
||||||
|
*
|
||||||
|
*/
|
||||||
|
class SingleToaster extends JWindow {
|
||||||
|
private static final long serialVersionUID = 1L;
|
||||||
|
|
||||||
|
// Label to store Icon
|
||||||
|
private JLabel iconLabel = new JLabel();
|
||||||
|
|
||||||
|
// Text area for the message
|
||||||
|
private JTextArea message = new JTextArea();
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Simple costructor that initialized components...
|
||||||
|
*/
|
||||||
|
public SingleToaster() {
|
||||||
|
initComponents();
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Function to initialized components
|
||||||
|
*/
|
||||||
|
private void initComponents() {
|
||||||
|
|
||||||
|
setSize(toasterWidth, toasterHeight);
|
||||||
|
message.setFont(getToasterMessageFont());
|
||||||
|
JPanel externalPanel = new JPanel(new BorderLayout(1, 1));
|
||||||
|
externalPanel.setBackground(getBorderColor());
|
||||||
|
JPanel innerPanel =
|
||||||
|
new JPanel(new BorderLayout(getMargin(), getMargin())) {
|
||||||
|
@Override
|
||||||
|
public void paint(Graphics g) {
|
||||||
|
if (getBackgroundImage() != null) {
|
||||||
|
g.drawImage(getBackgroundImage(), 0, 0, null);
|
||||||
|
}
|
||||||
|
super.paint(g);
|
||||||
|
}
|
||||||
|
};
|
||||||
|
if (getBackgroundImage() != null) {
|
||||||
|
innerPanel.setOpaque(false);
|
||||||
|
message.setOpaque(false);
|
||||||
|
iconLabel.setOpaque(false);
|
||||||
|
}
|
||||||
|
innerPanel.setBackground(getToasterColor());
|
||||||
|
message.setBackground(getToasterColor());
|
||||||
|
message.setMargin(new Insets(2, 2, 2, 2));
|
||||||
|
message.setLineWrap(true);
|
||||||
|
message.setWrapStyleWord(true);
|
||||||
|
EtchedBorder etchedBorder = (EtchedBorder) BorderFactory
|
||||||
|
.createEtchedBorder();
|
||||||
|
externalPanel.setBorder(etchedBorder);
|
||||||
|
externalPanel.add(innerPanel);
|
||||||
|
message.setForeground(getMessageColor());
|
||||||
|
innerPanel.add(iconLabel, BorderLayout.WEST);
|
||||||
|
innerPanel.add(message, BorderLayout.CENTER);
|
||||||
|
getContentPane().add(externalPanel);
|
||||||
|
JButton closeButton = new JButton("Close");
|
||||||
|
closeButton.setBounds(480, 10, 100, 40);
|
||||||
|
innerPanel.add(closeButton, BorderLayout.BEFORE_FIRST_LINE);
|
||||||
|
closeButton.addActionListener(e -> {
|
||||||
|
setVisible(false);
|
||||||
|
dispose();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Start toaster animation...
|
||||||
|
*/
|
||||||
|
public void animate() {
|
||||||
|
(new Animation(this)).start();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
/***
|
||||||
|
* Class that manage the animation
|
||||||
|
*/
|
||||||
|
class Animation extends Thread {
|
||||||
|
SingleToaster toaster;
|
||||||
|
|
||||||
|
public Animation(SingleToaster toaster) {
|
||||||
|
this.toaster = toaster;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Animate vertically the toaster. The toaster could be moved from bottom
|
||||||
|
* to upper or to upper to bottom
|
||||||
|
* @param posx
|
||||||
|
* @param fromY
|
||||||
|
* @param toY
|
||||||
|
* @throws InterruptedException
|
||||||
|
*/
|
||||||
|
protected void animateVertically(int posx, int fromY, int toY)
|
||||||
|
throws InterruptedException {
|
||||||
|
|
||||||
|
toaster.setLocation(posx, fromY);
|
||||||
|
if (toY < fromY) {
|
||||||
|
for (int i = fromY; i > toY; i -= step) {
|
||||||
|
toaster.setLocation(posx, i);
|
||||||
|
Thread.sleep(stepTime);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
for (int i = fromY; i < toY; i += step) {
|
||||||
|
toaster.setLocation(posx, i);
|
||||||
|
Thread.sleep(stepTime);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
toaster.setLocation(posx, toY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void run() {
|
||||||
|
try {
|
||||||
|
boolean animateFromBottom = true;
|
||||||
|
GraphicsEnvironment ge = GraphicsEnvironment
|
||||||
|
.getLocalGraphicsEnvironment();
|
||||||
|
Rectangle screenRect = ge.getMaximumWindowBounds();
|
||||||
|
|
||||||
|
int screenHeight = (int) screenRect.height;
|
||||||
|
|
||||||
|
int startYPosition;
|
||||||
|
int stopYPosition;
|
||||||
|
|
||||||
|
if (screenRect.y > 0) {
|
||||||
|
animateFromBottom = false; // Animate from top!
|
||||||
|
}
|
||||||
|
|
||||||
|
maxToasterInSceen = screenHeight / toasterHeight;
|
||||||
|
|
||||||
|
int posx = (int) screenRect.width - toasterWidth - 1;
|
||||||
|
|
||||||
|
toaster.setLocation(posx, screenHeight);
|
||||||
|
toaster.setVisible(true);
|
||||||
|
if (useAlwaysOnTop) {
|
||||||
|
toaster.setAlwaysOnTop(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (animateFromBottom) {
|
||||||
|
startYPosition = screenHeight;
|
||||||
|
stopYPosition = startYPosition - toasterHeight - 1;
|
||||||
|
if (currentNumberOfToaster > 0) {
|
||||||
|
stopYPosition =
|
||||||
|
stopYPosition - (maxToaster % maxToasterInSceen
|
||||||
|
* toasterHeight);
|
||||||
|
} else {
|
||||||
|
maxToaster = 0;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
startYPosition = screenRect.y - toasterHeight;
|
||||||
|
stopYPosition = screenRect.y;
|
||||||
|
|
||||||
|
if (currentNumberOfToaster > 0) {
|
||||||
|
stopYPosition =
|
||||||
|
stopYPosition + (maxToaster % maxToasterInSceen
|
||||||
|
* toasterHeight);
|
||||||
|
} else {
|
||||||
|
maxToaster = 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
currentNumberOfToaster++;
|
||||||
|
maxToaster++;
|
||||||
|
|
||||||
|
animateVertically(posx, startYPosition, stopYPosition);
|
||||||
|
Thread.sleep(displayTime);
|
||||||
|
animateVertically(posx, stopYPosition, startYPosition);
|
||||||
|
|
||||||
|
currentNumberOfToaster--;
|
||||||
|
toaster.setVisible(false);
|
||||||
|
toaster.dispose();
|
||||||
|
} catch (Exception e) {
|
||||||
|
e.printStackTrace();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -14,8 +14,8 @@ public class Vtipy {
|
|||||||
*/
|
*/
|
||||||
private static final String[] array = new String[] {
|
private static final String[] array = new String[] {
|
||||||
"\"Když dosáhnete mého věku, 65 let, stanou se tři věci,\" vypráví důchodce Karel. \"Nejprve vás začne opouštět paměť a na ty dvě další si teď nemůžu vzpomenout.\"",
|
"\"Když dosáhnete mého věku, 65 let, stanou se tři věci,\" vypráví důchodce Karel. \"Nejprve vás začne opouštět paměť a na ty dvě další si teď nemůžu vzpomenout.\"",
|
||||||
"Žán, odjíždíme zrovna někam? \"Ne, pane.\" \"Tak to mi právě ukradli auto.\"",
|
"Žán, odjíždíme zrovna někam? \"Ne, pane.\" \"Tak to mi právě ukradli auto.\"",
|
||||||
"Jestli se plaváním hubne, tak co dělají velryby špatně?",
|
"Jestli se plaváním hubne, tak co dělají velryby špatně?",
|
||||||
"\"Tak co, Pepíčku, kde jsi byl o prázdninách?\"\n"
|
"\"Tak co, Pepíčku, kde jsi byl o prázdninách?\"\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "\"S maminkou a jejím novým přítelem u moře.\"\n"
|
+ "\"S maminkou a jejím novým přítelem u moře.\"\n"
|
||||||
@ -84,14 +84,14 @@ public class Vtipy {
|
|||||||
+ "\"Takže ty se opičíš po rodičích, co? To mi tedy řekni, co bys dělal, kdyby tvoje máma byla dementní a tvůj otec homosexuál?\"\n"
|
+ "\"Takže ty se opičíš po rodičích, co? To mi tedy řekni, co bys dělal, kdyby tvoje máma byla dementní a tvůj otec homosexuál?\"\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "A Pepíček odpoví: \"Tak to bych nejspíš fandil Spartě.\"",
|
+ "A Pepíček odpoví: \"Tak to bych nejspíš fandil Spartě.\"",
|
||||||
"Jsou Windows XP vir?\n"
|
"Jsou Windows XP vir?\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "???\n"
|
+ "???\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
+ "Samozřejmě nejsou, nebo\u009D vir se šíří bezplatně, má úsporný kód a něco dělá.",
|
+ "Samozřejmě nejsou, nebo\u009D vir se šíří bezplatně, má úsporný kód a něco dělá.",
|
||||||
"Víte, jaký je rozdíl mezi Windows a listím? . . . . . . . Listí padá jen na podzim.",
|
"Víte, jaký je rozdíl mezi Windows a listím? . . . . . . . Listí padá jen na podzim.",
|
||||||
"Jeden opilec si zkrátil cestu domů přes hřbitov. Tam však spadl do vykopané jámy a usnul. Ráno se prochladlý probudil a nadává: Sakra, to je kosa. A paní, co byla kousek dál položit kytičku, povídá: Tak co ty ses odkopal?",
|
"Jeden opilec si zkrátil cestu domů přes hřbitov. Tam však spadl do vykopané jámy a usnul. Ráno se prochladlý probudil a nadává: Sakra, to je kosa. A paní, co byla kousek dál položit kytičku, povídá: Tak co ty ses odkopal?",
|
||||||
"Co ma spolecneho lahev a blondyna? - Od hrdla vyse jsou obe prazdne.",
|
"Co ma spolecneho lahev a blondyna? - Od hrdla vyse jsou obe prazdne.",
|
||||||
"Vždy, když dávám večer děti spát, přemýšlím, jestli je mám 'Uložit' anebo 'Uložit jako'..",
|
"Vždy, když dávám večer děti spát, přemýšlím, jestli je mám 'Uložit' anebo 'Uložit jako'..",
|
||||||
"Kolik je na světě Somálců?\n"
|
"Kolik je na světě Somálců?\n"
|
||||||
+ "\n"
|
+ "\n"
|
||||||
@ -134,6 +134,6 @@ public class Vtipy {
|
|||||||
t.setToasterColor(Color.GRAY);
|
t.setToasterColor(Color.GRAY);
|
||||||
Font font = new Font("sans", Font.PLAIN, 16);
|
Font font = new Font("sans", Font.PLAIN, 16);
|
||||||
t.setToasterMessageFont(font);
|
t.setToasterMessageFont(font);
|
||||||
t.showToaster(array[((int) (Math.random() * ((double)array.length)))]);
|
t.showToaster(array[((int) (Math.random() * ((double) array.length)))]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
<assembly
|
<assembly
|
||||||
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
|
||||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||||
|
xmlns="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0"
|
||||||
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
xsi:schemaLocation="http://maven.apache.org/plugins/maven-assembly-plugin/assembly/1.1.0 http://maven.apache.org/xsd/assembly-1.1.0.xsd">
|
||||||
<id>jar-with-all-dependencies</id>
|
<id>jar-with-all-dependencies</id>
|
||||||
<formats>
|
<formats>
|
||||||
|
Loading…
x
Reference in New Issue
Block a user