001: /*
002: * VersionCheckDialog.java
003: *
004: * This file is part of SQL Workbench/J, http://www.sql-workbench.net
005: *
006: * Copyright 2002-2008, Thomas Kellerer
007: * No part of this code maybe reused without the permission of the author
008: *
009: * To contact the author please send an email to: support@sql-workbench.net
010: *
011: */
012: package workbench.gui.tools;
013:
014: import java.awt.Color;
015: import java.awt.Cursor;
016: import java.awt.Font;
017: import java.awt.event.ActionEvent;
018: import java.awt.event.ActionListener;
019: import java.awt.event.MouseEvent;
020: import java.awt.event.MouseListener;
021: import javax.swing.JDialog;
022:
023: import workbench.resource.ResourceMgr;
024: import workbench.util.BrowserLauncher;
025: import workbench.util.UpdateVersion;
026: import workbench.util.VersionNumber;
027: import workbench.util.WbVersionReader;
028:
029: /**
030: * A Dialog to display available versions from the SQL Workbench/J homepage.
031: *
032: * @author support@sql-workbench.net
033: */
034: public class VersionCheckDialog extends JDialog implements
035: ActionListener, MouseListener {
036: private WbVersionReader versionReader;
037:
038: /** Creates new form VersionCheckDialog */
039: public VersionCheckDialog(java.awt.Frame parent) {
040: super (parent, true);
041: initComponents();
042: setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
043: this .closeButton.addActionListener(this );
044: Font f = this .headingLabel.getFont().deriveFont(Font.BOLD);
045: this .headingLabel.setFont(f);
046: this .headingLabel.setText(ResourceMgr
047: .getString("LblReadingVersion"));
048: this .headingLabel.addMouseListener(this );
049: this .headingLabel.setCursor(Cursor
050: .getPredefinedCursor(Cursor.HAND_CURSOR));
051: this .stableVersion.setText(" "
052: + ResourceMgr.getString("LblNotAvailable"));
053: this .devVersion.setText(" "
054: + ResourceMgr.getString("LblNotAvailable"));
055: }
056:
057: private void startRetrieveVersions() {
058: readVersion();
059: }
060:
061: public void setVisible(boolean flag) {
062: if (flag == true)
063: startRetrieveVersions();
064: super .setVisible(flag);
065: }
066:
067: protected void readVersion() {
068: this .versionReader = new WbVersionReader(this );
069: this .versionReader.startCheckThread();
070: }
071:
072: private void checkDisplay() {
073: UpdateVersion version = this .versionReader.getAvailableUpdate();
074:
075: String msg = ResourceMgr.getString("LblVersionUpToDate");
076: if (!this .versionReader.success()) {
077: msg = ResourceMgr.getString("LblVersionReadError");
078: } else if (version == UpdateVersion.stable) {
079: this .stableVersion.setBackground(Color.YELLOW);
080: msg = ResourceMgr.getString("LblVersionNewStableAvailable");
081: } else if (version == UpdateVersion.devBuild) {
082: this .devVersion.setBackground(Color.YELLOW);
083: msg = ResourceMgr.getString("LblVersionNewDevAvailable");
084: }
085: this .statusLabel.setText(msg);
086: }
087:
088: /** This method is called from within the constructor to
089: * initialize the form.
090: * WARNING: Do NOT modify this code. The content of this method is
091: * always regenerated by the Form Editor.
092: */
093: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
094: private void initComponents() {
095: java.awt.GridBagConstraints gridBagConstraints;
096:
097: yourVersionLabel = new javax.swing.JLabel();
098: yourVersion = new javax.swing.JLabel();
099: closeButton = new javax.swing.JButton();
100: stableVersionLabel = new javax.swing.JLabel();
101: stableVersion = new javax.swing.JLabel();
102: devVersionLabel = new javax.swing.JLabel();
103: devVersion = new javax.swing.JLabel();
104: statusLabel = new javax.swing.JLabel();
105: headingLabel = new javax.swing.JLabel();
106: jSeparator2 = new javax.swing.JSeparator();
107:
108: getContentPane().setLayout(new java.awt.GridBagLayout());
109:
110: setTitle(ResourceMgr.getString("TxtWindowTitleVersionCheck"));
111: setResizable(false);
112: addWindowListener(new java.awt.event.WindowAdapter() {
113: public void windowClosing(java.awt.event.WindowEvent evt) {
114: closeDialog(evt);
115: }
116: });
117:
118: yourVersionLabel.setText(ResourceMgr
119: .getString("LblYourVersion"));
120: gridBagConstraints = new java.awt.GridBagConstraints();
121: gridBagConstraints.gridx = 0;
122: gridBagConstraints.gridy = 2;
123: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
124: gridBagConstraints.insets = new java.awt.Insets(5, 5, 5, 0);
125: getContentPane().add(yourVersionLabel, gridBagConstraints);
126:
127: yourVersion.setBackground(java.awt.Color.white);
128: yourVersion.setText(" " + ResourceMgr.getBuildInfo());
129: yourVersion.setOpaque(true);
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 1;
132: gridBagConstraints.gridy = 2;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
134: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135: gridBagConstraints.weightx = 1.0;
136: gridBagConstraints.insets = new java.awt.Insets(5, 10, 5, 5);
137: getContentPane().add(yourVersion, gridBagConstraints);
138:
139: closeButton.setText(ResourceMgr.getString("LblClose"));
140: gridBagConstraints = new java.awt.GridBagConstraints();
141: gridBagConstraints.gridx = 1;
142: gridBagConstraints.gridy = 6;
143: gridBagConstraints.anchor = java.awt.GridBagConstraints.SOUTHEAST;
144: gridBagConstraints.weighty = 1.0;
145: gridBagConstraints.insets = new java.awt.Insets(10, 0, 5, 5);
146: getContentPane().add(closeButton, gridBagConstraints);
147:
148: stableVersionLabel.setText(ResourceMgr
149: .getString("LblStableVersion"));
150: gridBagConstraints = new java.awt.GridBagConstraints();
151: gridBagConstraints.gridx = 0;
152: gridBagConstraints.gridy = 3;
153: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
154: gridBagConstraints.insets = new java.awt.Insets(0, 5, 5, 0);
155: getContentPane().add(stableVersionLabel, gridBagConstraints);
156:
157: stableVersion.setBackground(java.awt.Color.white);
158: stableVersion.setOpaque(true);
159: gridBagConstraints = new java.awt.GridBagConstraints();
160: gridBagConstraints.gridx = 1;
161: gridBagConstraints.gridy = 3;
162: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
163: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
164: gridBagConstraints.insets = new java.awt.Insets(0, 10, 5, 5);
165: getContentPane().add(stableVersion, gridBagConstraints);
166:
167: devVersionLabel.setText(ResourceMgr.getString("LblDevVersion"));
168: gridBagConstraints = new java.awt.GridBagConstraints();
169: gridBagConstraints.gridx = 0;
170: gridBagConstraints.gridy = 4;
171: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
172: gridBagConstraints.insets = new java.awt.Insets(0, 5, 0, 0);
173: getContentPane().add(devVersionLabel, gridBagConstraints);
174:
175: devVersion.setBackground(java.awt.Color.white);
176: devVersion.setOpaque(true);
177: gridBagConstraints = new java.awt.GridBagConstraints();
178: gridBagConstraints.gridx = 1;
179: gridBagConstraints.gridy = 4;
180: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
181: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
182: gridBagConstraints.insets = new java.awt.Insets(0, 10, 0, 5);
183: getContentPane().add(devVersion, gridBagConstraints);
184:
185: statusLabel
186: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
187: statusLabel.setBorder(new javax.swing.border.EtchedBorder());
188: statusLabel.setMaximumSize(new java.awt.Dimension(32768, 28));
189: statusLabel.setMinimumSize(new java.awt.Dimension(100, 28));
190: statusLabel.setPreferredSize(new java.awt.Dimension(200, 28));
191: gridBagConstraints = new java.awt.GridBagConstraints();
192: gridBagConstraints.gridx = 0;
193: gridBagConstraints.gridy = 5;
194: gridBagConstraints.gridwidth = 2;
195: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196: gridBagConstraints.insets = new java.awt.Insets(9, 3, 0, 3);
197: getContentPane().add(statusLabel, gridBagConstraints);
198:
199: headingLabel.setBackground(new java.awt.Color(255, 255, 255));
200: headingLabel
201: .setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
202: headingLabel
203: .setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
204: headingLabel.setMaximumSize(new java.awt.Dimension(32768, 25));
205: headingLabel.setMinimumSize(new java.awt.Dimension(150, 25));
206: headingLabel.setOpaque(true);
207: headingLabel.setPreferredSize(new java.awt.Dimension(200, 25));
208: gridBagConstraints = new java.awt.GridBagConstraints();
209: gridBagConstraints.gridx = 0;
210: gridBagConstraints.gridy = 0;
211: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
212: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
213: gridBagConstraints.insets = new java.awt.Insets(8, 2, 5, 2);
214: getContentPane().add(headingLabel, gridBagConstraints);
215:
216: gridBagConstraints = new java.awt.GridBagConstraints();
217: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
218: gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
219: gridBagConstraints.insets = new java.awt.Insets(0, 0, 4, 0);
220: getContentPane().add(jSeparator2, gridBagConstraints);
221:
222: setSize(new java.awt.Dimension(386, 212));
223: }
224:
225: // </editor-fold>//GEN-END:initComponents
226:
227: /** Closes the dialog */
228: private void closeDialog(java.awt.event.WindowEvent evt)//GEN-FIRST:event_closeDialog
229: {
230: setVisible(false);
231: dispose();
232: }//GEN-LAST:event_closeDialog
233:
234: public void actionPerformed(ActionEvent e) {
235: if (e.getSource() == this .versionReader) {
236: if (this .versionReader.success()) {
237: this .stableVersion
238: .setText(" "
239: + ResourceMgr.getString("TxtBuild")
240: + " "
241: + this .versionReader
242: .getStableBuildNumber()
243: + " ("
244: + this .versionReader
245: .getStableBuildDate() + ")");
246: String date = this .versionReader.getDevBuildDate();
247: VersionNumber nr = this .versionReader
248: .getDevBuildNumber();
249: if (date != null && nr.isValid()) {
250: this .devVersion.setText(" "
251: + ResourceMgr.getString("TxtBuild") + " "
252: + nr + " (" + date + ")");
253: }
254: } else {
255: this .stableVersion.setText(" "
256: + ResourceMgr.getString("LblNotAvailable"));
257: this .devVersion.setText(" "
258: + ResourceMgr.getString("LblNotAvailable"));
259: }
260: this .headingLabel.setText(ResourceMgr
261: .getString("LblVersionsAvailable"));
262: this .headingLabel.setCursor(Cursor
263: .getPredefinedCursor(Cursor.HAND_CURSOR));
264:
265: checkDisplay();
266: } else if (e.getSource() == this .closeButton) {
267: setVisible(false);
268: dispose();
269: }
270: }
271:
272: public void mouseClicked(java.awt.event.MouseEvent e) {
273: if (e.getSource() == this .headingLabel
274: && e.getButton() == MouseEvent.BUTTON1
275: && e.getClickCount() == 1) {
276: try {
277: BrowserLauncher.openURL("http://www.sql-workbench.net");
278: } catch (Exception ex) {
279: ex.printStackTrace();
280: }
281: }
282: }
283:
284: public void mouseEntered(java.awt.event.MouseEvent e) {
285: }
286:
287: public void mouseExited(java.awt.event.MouseEvent e) {
288: }
289:
290: public void mousePressed(java.awt.event.MouseEvent e) {
291: }
292:
293: public void mouseReleased(java.awt.event.MouseEvent e) {
294: }
295:
296: // Variables declaration - do not modify//GEN-BEGIN:variables
297: private javax.swing.JButton closeButton;
298: private javax.swing.JLabel devVersion;
299: private javax.swing.JLabel devVersionLabel;
300: private javax.swing.JLabel headingLabel;
301: private javax.swing.JSeparator jSeparator2;
302: private javax.swing.JLabel stableVersion;
303: private javax.swing.JLabel stableVersionLabel;
304: private javax.swing.JLabel statusLabel;
305: private javax.swing.JLabel yourVersion;
306: private javax.swing.JLabel yourVersionLabel;
307: // End of variables declaration//GEN-END:variables
308:
309: }
|