001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.applications.designstudio.auxilarydialogs;
016:
017: import java.awt.BorderLayout;
018: import java.awt.Color;
019: import java.awt.Component;
020: import java.awt.Dimension;
021: import java.awt.FlowLayout;
022: import java.awt.Graphics;
023: import java.awt.GridBagConstraints;
024: import java.awt.GridBagLayout;
025: import java.awt.Insets;
026: import java.awt.Point;
027: import java.awt.Toolkit;
028: import java.awt.event.ActionEvent;
029: import java.awt.event.ActionListener;
030:
031: import javax.swing.Box;
032: import javax.swing.ImageIcon;
033: import javax.swing.JButton;
034: import javax.swing.JDialog;
035: import javax.swing.JFrame;
036: import javax.swing.JLabel;
037: import javax.swing.JPanel;
038: import javax.swing.border.EmptyBorder;
039:
040: import com.metaboss.applications.designstudio.Application;
041: import com.metaboss.applications.designstudio.components.EtchedLineBorder;
042: import com.metaboss.applications.designstudio.icons.IconsHolder;
043: import com.metaboss.enterprise.bs.BSException;
044: import com.metaboss.enterprise.bs.BSNamingAndDirectoryServiceInvocationException;
045: import com.metaboss.licensing.LicenseService;
046:
047: /* About dialog class */
048:
049: public class AboutDialog extends JDialog {
050: private static boolean sClassInitialised = false;
051: private static Object sClassInitialisationSemaphore = new Object();
052: private static LicenseService sLicenseService = null;
053:
054: private ImageIcon mTextIcon = IconsHolder.loadIcon("MBDS-Text.png");
055: private ImageIcon mBarIcon = IconsHolder
056: .loadIcon("About_MBDS_Bar.gif");
057:
058: private Box mPromptPanel = Box.createVerticalBox();
059: private GridBagLayout mClientGridBagLayout = new GridBagLayout();
060:
061: // Pseudo class initialiser. Main feature that we can throw exception from here (unable to do that from native java class initialiser)
062: protected static void initialiseClassIfNecessary()
063: throws BSException {
064: if (!sClassInitialised) {
065: synchronized (sClassInitialisationSemaphore) {
066: if (!sClassInitialised) {
067: try {
068: javax.naming.Context lCtx = new javax.naming.InitialContext();
069: sLicenseService = (LicenseService) lCtx
070: .lookup(LicenseService.COMPONENT_URL);
071: } catch (javax.naming.NamingException e) {
072: throw new BSNamingAndDirectoryServiceInvocationException(
073: "Unable to initialise CopyrightUtils",
074: e);
075: }
076: sClassInitialised = true;
077: }
078: }
079: }
080: }
081:
082: public AboutDialog(JFrame pFrame) throws Exception {
083: super (Application.mainFrame, "About Metaboss Design Studio",
084: true);
085: // Only initialise static variables once
086: initialiseClassIfNecessary();
087:
088: Dimension lSize = new Dimension(470, 330);
089:
090: Point x = Application.mainFrame.getLocation();
091: Dimension screenSize = Application.mainFrame.getSize();
092: pack();
093:
094: //Dimension frameSize = getPreferredSize();
095: Dimension frameSize = new Dimension(lSize.width, lSize.height);
096: if (x.x <= 0) {
097: x.x = 0;
098: x.y = 0;
099: screenSize = Toolkit.getDefaultToolkit().getScreenSize();
100: }
101: if (frameSize.height > screenSize.height)
102: frameSize.height = screenSize.height;
103: if (frameSize.width > screenSize.width)
104: frameSize.width = screenSize.width;
105: setSize(frameSize);
106: setResizable(false);
107: setLocation(((screenSize.width - frameSize.width) / 2) + x.x,
108: ((screenSize.height - frameSize.height) / 2) + x.y);
109:
110: JPanel lBackPanel = new JPanel();
111: getContentPane().add(lBackPanel);
112: lBackPanel.setLayout(new BorderLayout());
113: lBackPanel.setBorder(new EmptyBorder(2, 2, 2, 2));
114:
115: JLabel lPictureLabel = new JLabel();
116: lPictureLabel.setIcon(mBarIcon);
117: lPictureLabel.setBorder(new EmptyBorder(1, 1, 1, 1) {
118: public void paintBorder(Component c, Graphics g, int x,
119: int y, int width, int height) {
120: Color oldColor = g.getColor();
121: int h = height;
122: int w = width;
123:
124: g.translate(x, y);
125: g.setColor(c.getBackground().darker().darker());
126: g.drawLine(0, 0, 0, h);
127: g.drawLine(0, 0, w, 0);
128:
129: g.setColor(c.getBackground().brighter().brighter());
130: g.drawLine(w - 1, 0, w - 1, h);
131: g.drawLine(0, h - 1, w, h - 1);
132:
133: g.translate(-x, -y);
134: g.setColor(oldColor);
135: }
136: });
137: lBackPanel.add(lPictureLabel, BorderLayout.WEST);
138:
139: JPanel lClient = new JPanel();
140: lClient.setLayout(new BorderLayout());
141: lClient.setBorder(new EmptyBorder(2, 2, 2, 2));
142: lBackPanel.add(lClient, BorderLayout.CENTER);
143:
144: JLabel lSignLabel = new JLabel();
145: lSignLabel.setIcon(mTextIcon);
146: lSignLabel.setHorizontalAlignment(JLabel.CENTER);
147: lClient.add(lSignLabel, BorderLayout.NORTH);
148:
149: JPanel lButtonBar = new JPanel();
150: lClient.add(lButtonBar, BorderLayout.SOUTH);
151: lButtonBar.setLayout(new FlowLayout(FlowLayout.RIGHT));
152:
153: JButton lOKButton = new JButton();
154: lOKButton.setText(" OK ");
155: lOKButton.addActionListener(new OkButtonListener());
156: lButtonBar.add(lOKButton);
157:
158: //mPromptPanel.setLayout(mClientGridBagLayout);
159: JPanel lPromptOuterPanel = new JPanel();
160: lPromptOuterPanel.setLayout(new BorderLayout());
161: lPromptOuterPanel.setBorder(new EmptyBorder(0, 30, 0, 0));
162: lPromptOuterPanel.add(mPromptPanel, BorderLayout.CENTER);
163: lClient.add(lPromptOuterPanel, BorderLayout.CENTER);
164:
165: // Initilaise data values
166: int lItemPos = 1;
167: Color lLabelColor = null;
168: String lRegistrationText = null;
169: if (sLicenseService.isProductCommerciallyLicensed()) {
170: lLabelColor = Color.BLACK;
171: lRegistrationText = "Licensed to "
172: + sLicenseService.getAuthorName();
173: } else {
174: lLabelColor = Color.RED;
175: lRegistrationText = "This copy of "
176: + sLicenseService.getProductName()
177: + " is not commercially licensed.";
178: }
179: // Build the labels
180: mPromptPanel.add(Box.createVerticalGlue());
181: // Version label
182: {
183: JLabel lLabel = new JLabel();
184: lLabel.setText("Version: "
185: + sLicenseService.getProductVersion()
186: + " (Built on "
187: + sLicenseService.getProductBuildDate() + " "
188: + sLicenseService.getProductBuildTime() + ")");
189: addLabelField(lLabel, lItemPos++);
190: }
191: // Website label
192: {
193: JLabel lLabel = new JLabel();
194: lLabel.setText("WebSite: "
195: + sLicenseService.getProductWebSite());
196: addLabelField(lLabel, lItemPos++);
197: }
198: // Copyright lbbel
199: {
200: JLabel lLabel = new JLabel();
201: lLabel.setText(sLicenseService
202: .getManufacturerCopyrightNotice());
203: addLabelField(lLabel, lItemPos++);
204: }
205: mPromptPanel.add(Box.createVerticalGlue());
206:
207: // Registered or not label
208: {
209: JLabel lLabel = new JLabel();
210: lLabel.setText(lRegistrationText);
211: lLabel.setFont(Application.DEFAULT_FONT_BOLD);
212: lLabel.setForeground(lLabelColor);
213: addLabelField(lLabel, lItemPos++);
214: }
215: // License notes
216: {
217: String[] lLicenseNoticeLines = sLicenseService
218: .getManufacturerLicenseNotice();
219: for (int i = 0; i < lLicenseNoticeLines.length; i++) {
220: JLabel lLabel = new JLabel();
221: lLabel.setText(lLicenseNoticeLines[i]);
222: lLabel.setForeground(lLabelColor);
223: addLabelField(lLabel, lItemPos++);
224: }
225: }
226: mPromptPanel.add(Box.createVerticalGlue());
227: lButtonBar.setBorder(new EtchedLineBorder(
228: EtchedLineBorder.TOP_BORDER));
229:
230: // Done !
231: setVisible(true);
232: }
233:
234: private void ok(ActionEvent evt) {
235: setVisible(false);
236: }
237:
238: // add Text field
239: private void addLabelField(JLabel lLabel, int nLine) {
240: mPromptPanel
241: .add(lLabel, new GridBagConstraints(0, nLine, 1, 1,
242: 0.0, 0.0, GridBagConstraints.WEST,
243: GridBagConstraints.NONE,
244: new Insets(4, 20, 4, 0), 0, 0));
245: }
246:
247: /* Events Listeners */
248:
249: class OkButtonListener implements ActionListener {
250: public void actionPerformed(ActionEvent e) {
251: ok(e);
252: }
253: }
254: }
|