Skip to content

Commit

Permalink
Pequenas refatora�cões de código e atualizacões
Browse files Browse the repository at this point in the history
  • Loading branch information
LucasRodriguesOliveira committed Dec 3, 2019
1 parent 98ad61f commit 4b66312
Show file tree
Hide file tree
Showing 42 changed files with 295 additions and 201 deletions.
19 changes: 9 additions & 10 deletions config.properties
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
#Mon Nov 25 01:07:20 BRST 2019
#Mon Dec 02 21:39:21 BRST 2019
db.scriptSource=filesystem\:C\:\\Users\\"Lucas Oliveira"\\Projetos\\atualizador-java\\atualizacao
update.frequency=1
db.connector=org.sqlite.JDBC
db.scriptSource=filesystem\:D\:\\Renato\\Downloads\\atualizador-java\\atualizador-java-develop\\atualizacao
db.password=
update.frequency=
down.origem=atualizacao
db.dataScriptSource=D\:\\Renato\\Downloads\\atualizador-java\\atualizador-java-develop\\atualizacao\\data.sql
app.version=0.0.0
db.user=
git.url=https\://github.com/renatofritola/QueijosBiopark
db.url=jdbc\:sqlite\:C\:/queijo/bancoqueijos.db
app.version=0.0.0
down.origem=atualizacao
down.destino=C\:\\queijo
zip.file=queijo.zip
down.destino=D\:\\queijo
db.user=
app.name=queijo.jar
db.url=jdbc\:sqlite\:D\:/queijo/bancoqueijos.db
db.password=
125 changes: 54 additions & 71 deletions src/main/java/br/biopark/queijos/atualizador/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Image;
import java.awt.MenuItem;
import java.awt.PopupMenu;
import java.awt.Rectangle;
import java.awt.RenderingHints;
import java.awt.SystemTray;
Expand All @@ -24,11 +26,12 @@
import java.awt.TrayIcon.MessageType;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.net.URL;
import java.util.ArrayList;
import java.util.List;
import java.util.Timer;
import java.util.TimerTask;
import javax.swing.JComponent;
import javax.swing.JRootPane;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicProgressBarUI;

Expand All @@ -45,61 +48,77 @@ public class Main {
private static String novaVersao = "";
private SystemTray tray;
private static TrayIcon trayIcon;
private static Main main;

public TrayIcon getTrayIcon() {
return trayIcon;
}

public static void main(String[] args) {
Main main = new Main();
public void setTrayIcon(TrayIcon trayIcon) {
Main.trayIcon = trayIcon;
}

try {
public static Main getMain() {
return main;
}

UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.put("ProgressBar.background", Color.gray);
UIManager.put("ProgressBar.foreground", Color.orange);
UIManager.put("ProgressBar.selectionBackground", Color.white);
UIManager.put("ProgressBar.selectionForeground", Color.white);
public static void setMain(Main main) {
Main.main = main;
}

public static void main(String[] args) {
main = new Main();

try {
updateUI();
} catch (Exception ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

try {
main.displayTray();
TrayIconController.displayTray();
} catch (AWTException ex) {
Logger.getLogger(Main.class.getName()).log(Level.SEVERE, null, ex);
}

int delay = 5000; // delay de 5 seg.
int interval = 50000;//Integer.parseInt(prop.readPropertie(EPropertie.UPDATE_CHECK_FREQUENCY)) * 3600; // intervalo configurado.
int interval = prop.readPropertie(EPropertie.UPDATE_CHECK_FREQUENCY) != null ? Integer.parseInt(prop.readPropertie(EPropertie.UPDATE_CHECK_FREQUENCY)) * 60000 : 60 * 60000; // intervalo configurado.
Timer timer = new Timer();

//timer.scheduleAtFixedRate(new TimerTask() {
// public void run() {
versaoAtual = prop.readPropertie(EPropertie.APLICATION_VERSION);
GitUtil git = new GitUtil();
versoes = git.buscaVersoes(prop.readPropertie(EPropertie.URL_BASE_GIT));

if (main.checkNewVersion()) {
// main.iniciarAtualizacao();
main.getTrayIcon().displayMessage("Atualizador Queijos", "Uma nova versão foi encontrada. \nClique aqui para atualizar.", MessageType.INFO);
main.getTrayIcon().addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
Versao versao = new Versao(Progress.getInstance(), true, versaoAtual, versoes, trayIcon);
main.getTrayIcon().addActionListener(null);
versao.setLocationRelativeTo(null);
versao.getRootPane().setWindowDecorationStyle(JRootPane.NONE);
versao.getjLabel1().setText("Nova versão "+novaVersao);
versao.setVisible(true);
}
});

timer.scheduleAtFixedRate(new TimerTask() {
public void run() {
checarVersao(false);

}
}, interval, interval);
}

public static void checarVersao(boolean menu) {
if (!TrayIconController.processandoVersao) {
versaoAtual = prop.readPropertie(EPropertie.APLICATION_VERSION);
GitUtil git = new GitUtil();
versoes = git.buscaVersoes(prop.readPropertie(EPropertie.URL_BASE_GIT));

if (main.checkNewVersion()) {

if (menu) {
TrayIconController.showVersionFrame(trayIcon, versaoAtual, versoes, novaVersao);
} else {
TrayIconController.notifyVersion(main.getTrayIcon(), versaoAtual, versoes, novaVersao);
}
}else{
URL url = main.getClass().getResource("/queijo.png");
Image imgQueijo = Toolkit.getDefaultToolkit().getImage(url);
main.getTrayIcon().setImage(imgQueijo);
}
}
//}
// }, delay, interval);
}

private static void updateUI() throws Exception {
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
UIManager.put("ProgressBar.background", Color.gray);
UIManager.put("ProgressBar.foreground", Color.orange);
UIManager.put("ProgressBar.selectionBackground", Color.white);
UIManager.put("ProgressBar.selectionForeground", Color.white);
}

private boolean checkNewVersion() {
Expand All @@ -119,40 +138,4 @@ private boolean checkNewVersion() {

return false;
}

static class MyProgressUI extends BasicProgressBarUI {

Rectangle r = new Rectangle();

@Override
protected void paintIndeterminate(Graphics g, JComponent c) {
Graphics2D g2d = (Graphics2D) g;
g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING,
RenderingHints.VALUE_ANTIALIAS_ON);
r = getBox(r);
g.setColor(progressBar.getForeground());
g.fillRect(r.x, r.y, r.width, r.height);
}
}

public void displayTray() throws AWTException {
//Obtain only one instance of the SystemTray object
tray = SystemTray.getSystemTray();

//If the icon is a file
//Image image = Toolkit.getDefaultToolkit().createImage("icon.png");
//Alternative (if the icon is on the classpath):
Image image = Toolkit.getDefaultToolkit().createImage(getClass().getResource("/queijo.png"));

trayIcon = new TrayIcon(image, "Atualizador Queijos");
//Let the system resize the image if needed
trayIcon.setImageAutoSize(true);

//Set tooltip text for the tray icon
trayIcon.setToolTip("Atualizados Queijos");
tray.add(trayIcon);

trayIcon.displayMessage("Atualizador Queijos", "Atualizador sendo executado em segundo plano.", MessageType.INFO);
}

}
}
Loading

0 comments on commit 4b66312

Please sign in to comment.