001: package org.enhydra.shark.swingclient.actions;
002:
003: import java.awt.BorderLayout;
004: import java.awt.Color;
005: import java.awt.Component;
006: import java.awt.Dimension;
007: import java.awt.Toolkit;
008: import java.awt.event.ActionEvent;
009: import java.awt.event.ActionListener;
010: import java.awt.event.WindowAdapter;
011: import java.awt.event.WindowEvent;
012: import java.io.BufferedReader;
013: import java.io.InputStreamReader;
014: import java.net.URL;
015: import java.net.URLConnection;
016:
017: import javax.swing.BorderFactory;
018: import javax.swing.Box;
019: import javax.swing.BoxLayout;
020: import javax.swing.JButton;
021: import javax.swing.JDialog;
022: import javax.swing.JEditorPane;
023: import javax.swing.JFrame;
024: import javax.swing.JPanel;
025: import javax.swing.JScrollPane;
026: import javax.swing.JTabbedPane;
027: import javax.swing.JTextArea;
028: import javax.swing.JToolBar;
029: import javax.swing.SwingConstants;
030: import javax.swing.WindowConstants;
031:
032: import org.enhydra.shark.swingclient.AdminHyperactive;
033: import org.enhydra.shark.swingclient.AdminSplash;
034: import org.enhydra.shark.swingclient.ResourceManager;
035: import org.enhydra.shark.swingclient.SharkClient;
036:
037: public class AdminAboutDialog extends JDialog {
038: private int timeLeft = 10; // in seconds
039:
040: protected JButton okButton;
041:
042: private JPanel licencePnl;
043:
044: private JTabbedPane tabContainer;
045:
046: private JToolBar buttonToolbar;
047:
048: private ActionListener actionHandler = new ActionHandler();
049:
050: private SharkClient sc;
051:
052: private boolean isClosed = false;
053:
054: public AdminAboutDialog(SharkClient sc, String title) {
055: super (SharkClient.getFrame(), title, true);
056: this .sc = sc;
057: createUI();
058: setResizable(false);
059: pack();
060: Dimension screenSize = Toolkit.getDefaultToolkit()
061: .getScreenSize();
062: Dimension winsize = this .getSize();
063: setLocation(screenSize.width / 2 - (winsize.width / 2),
064: screenSize.height / 2 - (winsize.height / 2));
065: setLocationRelativeTo(SharkClient.getFrame());
066: }
067:
068: public AdminAboutDialog(SharkClient sc, JDialog parent) {
069: super (parent);
070: init(sc);
071: }
072:
073: public AdminAboutDialog(SharkClient sc, JFrame parent) {
074: super (parent);
075: init(sc);
076: }
077:
078: public void init(SharkClient scl) {
079: this .sc = scl;
080: JPanel main = new JPanel();
081: main.setBackground(Color.WHITE);
082: main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
083: okButton = new JButton(" OK (" + timeLeft + ")");
084: okButton.setAlignmentX(CENTER_ALIGNMENT);
085: okButton.addActionListener(new ActionHandler());
086: okButton.setEnabled(false);
087: main.add(AdminSplash.getSplashPanel(sc));
088: main.add(Box.createVerticalStrut(15));
089: main.add(okButton);
090: getContentPane().add(main);
091:
092: setResizable(false);
093:
094: this .getParent().setEnabled(false);
095:
096: this
097: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
098: this .addWindowListener(new WindowAdapter() {
099: public void windowClosing(WindowEvent e) {
100: close();
101: }
102: });
103:
104: }
105:
106: public void setTime(int timeLeft) {
107: this .timeLeft = timeLeft;
108: if (timeLeft != 0)
109: okButton.setText(" OK (" + timeLeft + ")");
110: else {
111: okButton.setText(" OK ");
112: okButton.setEnabled(true);
113: }
114: }
115:
116: public int getTimeLeft() {
117: return timeLeft;
118: }
119:
120: public boolean isClosed() {
121: return isClosed;
122: }
123:
124: public void show() {
125: super .show();
126: isClosed = false;
127: }
128:
129: private void createUI() {
130: createButtonPane();
131: if (sc.showLicenseInfo()) {
132: createTabbedPane();
133: getContentPane().add(tabContainer, BorderLayout.CENTER);
134: } else {
135: getContentPane().add(AdminSplash.getSplashPanel(sc),
136: BorderLayout.CENTER);
137: }
138: getContentPane().add(buttonToolbar, BorderLayout.SOUTH);
139: getRootPane().setDefaultButton(okButton);
140: }
141:
142: private void createButtonPane() {
143: okButton = new JButton(" OK ");
144: okButton.addActionListener(actionHandler);
145: buttonToolbar = new JToolBar(SwingConstants.HORIZONTAL);
146: buttonToolbar.setBorder(BorderFactory.createEmptyBorder(5, 10,
147: 5, 10));
148: buttonToolbar.setFloatable(false);
149: buttonToolbar.add(Box.createHorizontalGlue());
150: buttonToolbar.add(okButton);
151: buttonToolbar.add(Box.createHorizontalGlue());
152: }
153:
154: private void createTabbedPane() {
155: createLicencePane();
156: tabContainer = new JTabbedPane();
157: tabContainer.addTab(ResourceManager
158: .getLanguageDependentString("GeneralKey"), AdminSplash
159: .getSplashPanel(sc));
160: tabContainer.addTab(ResourceManager
161: .getLanguageDependentString("LicenseKey"), licencePnl);
162: }
163:
164: private void createLicencePane() {
165: licencePnl = new JPanel(new BorderLayout());
166:
167: JScrollPane licenceS = new JScrollPane();
168: licenceS.setPreferredSize(new Dimension(400, 300));
169: JTextArea licenceText = new JTextArea();
170:
171: licenceS.setAlignmentX(Component.LEFT_ALIGNMENT);
172: licenceS.setAlignmentY(Component.TOP_ALIGNMENT);
173:
174: licenceText = new JTextArea();
175:
176: licenceText.setTabSize(4);
177: licenceText.getCaret().setDot(0);
178: licenceText.setLineWrap(true);
179: licenceText.setWrapStyleWord(true);
180:
181: licenceText.setEnabled(true);
182: licenceText.setEditable(false);
183:
184: licenceS.setViewportView(licenceText);
185:
186: String textL = "";
187: try {
188: URL u = null;
189: if (SharkClient.getAdminVersion() == SharkClient.COMMUNITY_VERSION) {
190: u = ResourceManager.class.getClassLoader().getResource(
191: "LicenseAdminCommunity.txt");
192: } else if (SharkClient.getAdminVersion() == SharkClient.DEMO_VERSION) {
193: u = ResourceManager.class.getClassLoader().getResource(
194: "LicenseAdminDemo.txt");
195: } else {
196: u = ResourceManager.class.getClassLoader().getResource(
197: "LicenseAdminProfessional.txt");
198: }
199: URLConnection ucon = u.openConnection();
200:
201: BufferedReader br = new BufferedReader(
202: new InputStreamReader(ucon.getInputStream()));
203:
204: String temp;
205: while ((temp = br.readLine()) != null) {
206: textL += temp + "\n";
207: }
208: } catch (Exception e) {
209: }
210:
211: licenceText.append(textL);
212: licenceText.getCaret().setDot(0);
213:
214: AdminHyperactive ha = new AdminHyperactive();
215: JEditorPane text = new JEditorPane();
216: text.setAlignmentX(LEFT_ALIGNMENT);
217: text.setAlignmentY(TOP_ALIGNMENT);
218: text.addHyperlinkListener(ha);
219: text.setContentType("text/html");
220: text.setOpaque(false);
221: String t = sc.getAdditionalLicenseText();
222: text.setText(t);
223: text.setEditable(false);
224:
225: licencePnl.add(licenceS, BorderLayout.CENTER);
226: licencePnl.add(text, BorderLayout.SOUTH);
227: }
228:
229: private class ActionHandler implements ActionListener {
230: public void actionPerformed(ActionEvent e) {
231: if (e.getSource() == okButton) {
232: close();
233: }
234: }
235: }
236:
237: protected void close() {
238: if (okButton.isEnabled()) {
239: dispose();
240: isClosed = true;
241: }
242: }
243:
244: }
|