001: package org.enhydra.jawe.base.controller.actions;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Component;
005: import java.awt.Dimension;
006: import java.awt.Frame;
007: import java.awt.Toolkit;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.KeyEvent;
011: import java.io.BufferedReader;
012: import java.io.InputStreamReader;
013: import java.net.URL;
014: import java.net.URLConnection;
015:
016: import javax.swing.BorderFactory;
017: import javax.swing.Box;
018: import javax.swing.JButton;
019: import javax.swing.JComponent;
020: import javax.swing.JDialog;
021: import javax.swing.JEditorPane;
022: import javax.swing.JPanel;
023: import javax.swing.JRootPane;
024: import javax.swing.JScrollPane;
025: import javax.swing.JTabbedPane;
026: import javax.swing.JTextArea;
027: import javax.swing.JToolBar;
028: import javax.swing.KeyStroke;
029: import javax.swing.SwingConstants;
030:
031: import org.enhydra.jawe.ActionBase;
032: import org.enhydra.jawe.Hyperactive;
033: import org.enhydra.jawe.JaWEComponent;
034: import org.enhydra.jawe.JaWEManager;
035: import org.enhydra.jawe.JaWESplash;
036: import org.enhydra.jawe.ResourceManager;
037: import org.enhydra.jawe.base.controller.JaWEController;
038:
039: public class HelpAbout extends ActionBase {
040:
041: private JDialog aboutDlg;
042:
043: public HelpAbout(JaWEComponent jawecomponent) {
044: super (jawecomponent);
045: }
046:
047: public void enableDisableAction() {
048: }
049:
050: public void actionPerformed(ActionEvent e) {
051: JaWEController jcon = (JaWEController) jawecomponent;
052:
053: if (aboutDlg == null) {
054: String title = jcon.getSettings()
055: .getLanguageDependentString("AboutFrameTitle");
056: aboutDlg = new JaWEAboutDialog(jcon.getJaWEFrame(), title);
057: aboutDlg.setVisible(true);
058: } else {
059: aboutDlg.setVisible(true);
060: }
061: }
062:
063: public class JaWEAboutDialog extends JDialog {
064: protected JButton okButton;
065: private JPanel licencePnl;
066: private JTabbedPane tabContainer;
067: private JToolBar buttonToolbar;
068:
069: private ActionListener actionHandler = new ActionHandler();
070:
071: public void showAbout(Frame owner, String title) {
072: JaWEAboutDialog about = new JaWEAboutDialog(owner, title);
073: about.setVisible(true);
074: about = null;
075: }
076:
077: protected JaWEAboutDialog(Frame owner, String title) {
078: super (owner, title, true);
079: createUI();
080: setResizable(false);
081: pack();
082: Dimension screenSize = Toolkit.getDefaultToolkit()
083: .getScreenSize();
084: Dimension winsize = this .getSize();
085: setLocation(screenSize.width / 2 - (winsize.width / 2),
086: screenSize.height / 2 - (winsize.height / 2));
087: setLocationRelativeTo(owner);
088: }
089:
090: private void createUI() {
091: createButtonPane();
092: if (JaWEManager.showLicenseInfo()) {
093: createTabbedPane();
094: getContentPane().add(tabContainer, BorderLayout.CENTER);
095: } else {
096: getContentPane().add(JaWESplash.getSplashPanel(),
097: BorderLayout.CENTER);
098: }
099: getContentPane().add(buttonToolbar, BorderLayout.SOUTH);
100: getRootPane().setDefaultButton(okButton);
101: }
102:
103: private void createButtonPane() {
104: okButton = new JButton(" OK ");
105: okButton.addActionListener(actionHandler);
106: buttonToolbar = new JToolBar(SwingConstants.HORIZONTAL);
107: buttonToolbar.setBorder(BorderFactory.createEmptyBorder(5,
108: 10, 5, 10));
109: buttonToolbar.setFloatable(false);
110: buttonToolbar.add(Box.createHorizontalGlue());
111: buttonToolbar.add(okButton);
112: buttonToolbar.add(Box.createHorizontalGlue());
113: }
114:
115: private void createTabbedPane() {
116: createLicencePane();
117: tabContainer = new JTabbedPane();
118: tabContainer.addTab(ResourceManager
119: .getLanguageDependentString("GeneralKey"),
120: JaWESplash.getSplashPanel());
121: tabContainer.addTab(ResourceManager
122: .getLanguageDependentString("LicenseKey"),
123: licencePnl);
124: }
125:
126: private void createLicencePane() {
127: licencePnl = new JPanel(new BorderLayout());
128:
129: JScrollPane licenceS = new JScrollPane();
130: licenceS.setPreferredSize(new Dimension(400, 300));
131:
132: licenceS.setAlignmentX(Component.LEFT_ALIGNMENT);
133: licenceS.setAlignmentY(Component.TOP_ALIGNMENT);
134:
135: JTextArea licenceText = new JTextArea();
136:
137: licenceText.setTabSize(4);
138: licenceText.getCaret().setDot(0);
139: // Font f = licenceText.getFont();
140: // f.
141: // licenceText.setfont
142: licenceText.setLineWrap(true);
143: licenceText.setWrapStyleWord(true);
144:
145: licenceText.setEnabled(true);
146: licenceText.setEditable(false);
147:
148: licenceS.setViewportView(licenceText);
149:
150: String textL = "";
151: try {
152: URL u = ResourceManager.class.getClassLoader()
153: .getResource("License.txt");
154: URLConnection ucon = u.openConnection();
155:
156: BufferedReader br = new BufferedReader(
157: new InputStreamReader(ucon.getInputStream()));
158:
159: String temp;
160: while ((temp = br.readLine()) != null) {
161: textL += temp + "\n";
162: }
163: } catch (Exception e) {
164: }
165:
166: licenceText.append(textL);
167: licenceText.getCaret().setDot(0);
168:
169: Hyperactive ha = new Hyperactive();
170: JEditorPane text = new JEditorPane();
171: text.setAlignmentX(LEFT_ALIGNMENT);
172: text.setAlignmentY(TOP_ALIGNMENT);
173: text.addHyperlinkListener(ha);
174: text.setContentType("text/html");
175: text.setOpaque(false);
176: String t = JaWEManager.getAdditionalLicenseText();
177: text.setText(t);
178: text.setEditable(false);
179:
180: licencePnl.add(licenceS, BorderLayout.CENTER);
181: licencePnl.add(text, BorderLayout.SOUTH);
182: }
183:
184: // Close on escape
185: protected JRootPane createRootPane() {
186: KeyStroke stroke = KeyStroke.getKeyStroke(
187: KeyEvent.VK_ESCAPE, 0);
188: JRootPane _rootPane = new JRootPane();
189: _rootPane.registerKeyboardAction(new ActionListener() {
190: public void actionPerformed(ActionEvent actionEvent) {
191: setVisible(false);
192: }
193: }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);
194: return _rootPane;
195: }
196:
197: private class ActionHandler implements ActionListener {
198: public void actionPerformed(ActionEvent e) {
199: if (e.getSource() == okButton) {
200: dispose();
201: }
202: }
203: }
204: }
205: }
|