| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
package org.homeunix.thecave.buddi.view; |
| 5 | |
|
| 6 | |
import java.awt.BorderLayout; |
| 7 | |
import java.awt.Dimension; |
| 8 | |
import java.awt.FlowLayout; |
| 9 | |
import java.awt.event.ActionEvent; |
| 10 | |
import java.awt.event.ActionListener; |
| 11 | |
import java.awt.event.MouseAdapter; |
| 12 | |
import java.awt.event.MouseEvent; |
| 13 | |
import java.util.logging.Level; |
| 14 | |
import java.util.logging.Logger; |
| 15 | |
|
| 16 | |
import javax.swing.BorderFactory; |
| 17 | |
import javax.swing.ImageIcon; |
| 18 | |
import javax.swing.JButton; |
| 19 | |
import javax.swing.JLabel; |
| 20 | |
import javax.swing.JPanel; |
| 21 | |
|
| 22 | |
import org.homeunix.thecave.buddi.Buddi; |
| 23 | |
import org.homeunix.thecave.buddi.Const; |
| 24 | |
import org.homeunix.thecave.buddi.i18n.BuddiKeys; |
| 25 | |
import org.homeunix.thecave.buddi.i18n.keys.ButtonKeys; |
| 26 | |
import org.homeunix.thecave.buddi.model.prefs.PrefsModel; |
| 27 | |
import org.homeunix.thecave.buddi.plugin.api.util.TextFormatter; |
| 28 | |
import org.homeunix.thecave.buddi.view.menu.bars.BuddiMenuBar; |
| 29 | |
|
| 30 | |
import ca.digitalcave.moss.common.ClassLoaderFunctions; |
| 31 | |
import ca.digitalcave.moss.common.OperatingSystemUtil; |
| 32 | |
import ca.digitalcave.moss.swing.MossFrame; |
| 33 | |
import edu.stanford.ejalbert.BrowserLauncher; |
| 34 | |
|
| 35 | |
public class AboutFrame extends MossFrame implements ActionListener { |
| 36 | |
public static final long serialVersionUID = 0; |
| 37 | |
|
| 38 | |
private final JButton okButton; |
| 39 | |
private final JButton donateButton; |
| 40 | |
private final JLabel text; |
| 41 | |
|
| 42 | |
public AboutFrame() { |
| 43 | 423 | super("AboutFrame"); |
| 44 | 423 | this.setIconImage(ClassLoaderFunctions.getImageFromClasspath("img/BuddiFrameIcon.gif")); |
| 45 | |
|
| 46 | 423 | okButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_OK)); |
| 47 | 423 | donateButton = new JButton(TextFormatter.getTranslation(ButtonKeys.BUTTON_DONATE)); |
| 48 | |
|
| 49 | 423 | Dimension buttonSize = new Dimension(Math.max(100, donateButton.getPreferredSize().width), donateButton.getPreferredSize().height); |
| 50 | |
|
| 51 | 423 | okButton.setPreferredSize(buttonSize); |
| 52 | 423 | donateButton.setPreferredSize(buttonSize); |
| 53 | |
|
| 54 | 423 | JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
| 55 | 423 | buttonPanel.add(donateButton); |
| 56 | 423 | buttonPanel.add(okButton); |
| 57 | |
|
| 58 | 423 | StringBuffer sbTitle = new StringBuffer(); |
| 59 | 423 | sbTitle.append( |
| 60 | |
"<html><center><h1>") |
| 61 | |
.append(TextFormatter.getTranslation(BuddiKeys.BUDDI)) |
| 62 | |
.append("</h1></center></html>"); |
| 63 | |
|
| 64 | 423 | StringBuffer sbVersion = new StringBuffer(); |
| 65 | 423 | sbVersion.append( |
| 66 | |
"<html><center><h5>") |
| 67 | |
.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_VERSION)) |
| 68 | |
.append(" ") |
| 69 | |
.append(Buddi.getVersion()) |
| 70 | |
.append("</h5></center></html"); |
| 71 | |
|
| 72 | 423 | JLabel version = new JLabel(sbVersion.toString()); |
| 73 | |
|
| 74 | 423 | JPanel bottomPanel = new JPanel(new BorderLayout()); |
| 75 | 423 | bottomPanel.add(buttonPanel, BorderLayout.SOUTH); |
| 76 | 423 | bottomPanel.add(version, BorderLayout.NORTH); |
| 77 | |
|
| 78 | 423 | JLabel title = new JLabel(sbTitle.toString()); |
| 79 | 423 | JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.CENTER)); |
| 80 | 423 | titlePanel.add(title); |
| 81 | |
|
| 82 | 423 | ClassLoader cl = Thread.currentThread().getContextClassLoader(); |
| 83 | 423 | if (null == cl) { |
| 84 | 0 | cl = MossFrame.class.getClassLoader(); |
| 85 | |
} |
| 86 | |
|
| 87 | |
|
| 88 | 423 | title.setIcon(new ImageIcon(ClassLoaderFunctions.getImageFromClasspath("img/BuddiAboutLogo.png"))); |
| 89 | 423 | title.setVerticalTextPosition(JLabel.BOTTOM); |
| 90 | 423 | title.setHorizontalAlignment(JLabel.CENTER); |
| 91 | 423 | title.setHorizontalTextPosition(JLabel.CENTER); |
| 92 | |
|
| 93 | 423 | StringBuffer sbText = new StringBuffer(); |
| 94 | 423 | sbText.append( |
| 95 | |
"<html><center>") |
| 96 | |
.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_TEXT)) |
| 97 | |
.append("<br><br>") |
| 98 | |
.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_COPYRIGHT)) |
| 99 | |
.append("<br><") |
| 100 | |
.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_EMAIL)) |
| 101 | |
.append("><br><a href='") |
| 102 | |
.append(TextFormatter.getTranslation(Const.PROJECT_URL)) |
| 103 | |
.append("'>") |
| 104 | |
.append(TextFormatter.getTranslation(Const.PROJECT_URL)) |
| 105 | |
.append("</a><br><br>"); |
| 106 | 423 | if (!TextFormatter.getTranslation(BuddiKeys.ABOUT_TRANSLATION).equals(BuddiKeys.ABOUT_TRANSLATION.toString())){ |
| 107 | 0 | sbText.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_TRANSLATION)) |
| 108 | |
.append("<br><br>"); |
| 109 | |
} |
| 110 | 423 | sbText.append(TextFormatter.getTranslation(BuddiKeys.ABOUT_GPL)) |
| 111 | |
.append("</center></html>"); |
| 112 | |
|
| 113 | 423 | text = new JLabel(sbText.toString()); |
| 114 | |
|
| 115 | 423 | JPanel inlayPanel = new JPanel(new BorderLayout()); |
| 116 | 423 | inlayPanel.add(text, BorderLayout.CENTER); |
| 117 | 423 | inlayPanel.add(bottomPanel, BorderLayout.SOUTH); |
| 118 | |
|
| 119 | 423 | if (OperatingSystemUtil.isMac()){ |
| 120 | 0 | inlayPanel.setBorder(BorderFactory.createTitledBorder("")); |
| 121 | |
} |
| 122 | |
|
| 123 | 423 | this.setLayout(new BorderLayout()); |
| 124 | 423 | this.getRootPane().setDefaultButton(okButton); |
| 125 | 423 | this.setTitle(TextFormatter.getTranslation(BuddiKeys.ABOUT_BUDDI)); |
| 126 | 423 | this.add(titlePanel, BorderLayout.NORTH); |
| 127 | 423 | this.add(inlayPanel, BorderLayout.CENTER); |
| 128 | 423 | } |
| 129 | |
|
| 130 | |
public void init() { |
| 131 | 410 | super.init(); |
| 132 | |
|
| 133 | 410 | this.setJMenuBar(new BuddiMenuBar(this)); |
| 134 | |
|
| 135 | 410 | okButton.addActionListener(this); |
| 136 | 410 | donateButton.addActionListener(this); |
| 137 | |
|
| 138 | 410 | text.addMouseListener(new MouseAdapter(){ |
| 139 | |
@Override |
| 140 | |
public void mouseClicked(MouseEvent e) { |
| 141 | |
try{ |
| 142 | 0 | BrowserLauncher bl = new BrowserLauncher(null); |
| 143 | 0 | bl.openURLinBrowser(Const.PROJECT_URL); |
| 144 | |
} |
| 145 | 0 | catch (Exception ex){ |
| 146 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Unknown Exception", ex); |
| 147 | 0 | } |
| 148 | 0 | super.mouseClicked(e); |
| 149 | 0 | } |
| 150 | |
}); |
| 151 | 410 | } |
| 152 | |
|
| 153 | |
public void actionPerformed(ActionEvent e) { |
| 154 | 44 | if (e.getSource().equals(okButton)){ |
| 155 | 20 | AboutFrame.this.closeWindow(); |
| 156 | |
} |
| 157 | 24 | else if (e.getSource().equals(donateButton)){ |
| 158 | |
try{ |
| 159 | 24 | BrowserLauncher bl = new BrowserLauncher(null); |
| 160 | 24 | bl.openURLinBrowser(Const.DONATE_URL); |
| 161 | |
} |
| 162 | 0 | catch (Exception ex){ |
| 163 | 0 | Logger.getLogger(this.getClass().getName()).log(Level.WARNING, "Unknown Exception", ex); |
| 164 | 24 | } |
| 165 | |
} |
| 166 | 44 | } |
| 167 | |
|
| 168 | |
@Override |
| 169 | |
public void closeWindowWithoutPrompting() { |
| 170 | 31 | PrefsModel.getInstance().putWindowLocation(BuddiKeys.ABOUT_BUDDI.toString(), this.getLocation()); |
| 171 | 31 | PrefsModel.getInstance().save(); |
| 172 | |
|
| 173 | 31 | super.closeWindowWithoutPrompting(); |
| 174 | 31 | } |
| 175 | |
} |