summaryrefslogtreecommitdiffstats
path: root/dozentenmodul/src/main/java/org/openslx/dozmod/gui/activity/UpdatePanel.java
blob: 41b53302e0733b8458f9d07c6a3ebdd2ab53797a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
package org.openslx.dozmod.gui.activity;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.Box;
import javax.swing.BoxLayout;
import javax.swing.JButton;
import javax.swing.JPanel;
import javax.swing.SwingUtilities;

import org.openslx.dozmod.gui.Gui;
import org.openslx.dozmod.gui.control.QLabel;
import org.openslx.dozmod.gui.window.CheckUpdateWindow;
import org.openslx.dozmod.util.DesktopEnvironment;
import org.openslx.dozmod.util.DesktopEnvironment.Link;

public class UpdatePanel extends ActivityPanel implements ActionListener {

	private static final long serialVersionUID = 1L;

	protected JPanel header;
	protected QLabel lblInfo;
	protected final JButton btnLink;
	protected final JButton btnDetails;
	protected final JButton btnClose;

	@Override
	public boolean wantConfirmQuit() {
		return false;
	}

	public UpdatePanel(final String newVersion) {
		this(newVersion, true);
	}
	
	public UpdatePanel(final String newVersion, boolean allowClose) {
		super();
		setLayout(new BoxLayout(this, BoxLayout.PAGE_AXIS));
		// Header: Neue Version verfügbar: <newVersion> [Button]
		header = new JPanel();
		header.setLayout(new BoxLayout(header, BoxLayout.LINE_AXIS));
		lblInfo = new QLabel("Neue Version verfügbar: " + newVersion, Gui.getScaledIconResource("/img/upload-icon.png", "!", 32, this), QLabel.LEFT);
		header.add(lblInfo);
		header.add(Box.createHorizontalGlue());
		btnLink = new JButton("Im Browser öffnen", Gui.getScaledIconResource("/img/download-icon.png", "!", 24, this));
		btnDetails = new JButton("Changelog", Gui.getScaledIconResource("/img/info-icon.png", "?", 24, this));
		btnClose = new JButton("Schließen", Gui.getScaledIconResource("/img/delete-icon.png", "X", 24, this));
		btnLink.addActionListener(this);
		btnClose.addActionListener(this);
		header.add(btnLink);
		header.add(btnDetails);
		header.add(btnClose);
		add(header);
		
		btnDetails.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent e) {
				CheckUpdateWindow.open(SwingUtilities.getWindowAncestor(UpdatePanel.this));
			}
		});
		btnClose.setEnabled(allowClose);
	}

	@Override
	public void actionPerformed(ActionEvent e) {
		if (e.getSource() == btnLink) {
			DesktopEnvironment.openWebpage(Link.DOZMOD);
			close();
		}
		if (e.getSource() == btnClose) {
			close();
		}
	}
}