001: package org.enhydra.jawe;
002:
003: import java.awt.Color;
004: import java.awt.Dimension;
005: import java.awt.Toolkit;
006: import java.awt.event.ActionEvent;
007: import java.awt.event.ActionListener;
008: import java.io.File;
009: import java.io.FileInputStream;
010: import java.util.Properties;
011:
012: import javax.swing.Box;
013: import javax.swing.BoxLayout;
014: import javax.swing.JButton;
015: import javax.swing.JDialog;
016: import javax.swing.JFrame;
017: import javax.swing.JPanel;
018: import javax.swing.WindowConstants;
019:
020: /**
021: * The main editor class.
022: *
023: * @author Sasa Bojanic
024: */
025: public class JaWE {
026:
027: static int timeLeft = 10; // in seconds
028:
029: public static void main(String[] args) throws Throwable {
030: System.out.println("Starting JAWE ....");
031: System.out.println("JaWE -> JaWE is being initialized ...");
032:
033: File cfgf = null;
034: System.out.println("JaWE_CONF_HOME="
035: + JaWEConstants.JAWE_CONF_HOME);
036: if (JaWEConstants.JAWE_CONF_HOME != null) {
037: File mainConfig = new File(JaWEConstants.JAWE_CONF_HOME
038: + "/" + "defaultconfig");
039: Properties props = new Properties();
040: if (mainConfig.exists()) {
041: FileInputStream fis = null;
042: try {
043: fis = new FileInputStream(mainConfig);
044: props.load(fis);
045: fis.close();
046: } catch (Exception ex) {
047: System.err
048: .println("Something went wrong while reading configuration from the file "
049: + mainConfig.getAbsolutePath());
050: }
051: }
052: String conf_home = JaWEConstants.JAWE_CONF_HOME
053: + "/"
054: + props
055: .getProperty(JaWEConstants.JAWE_CURRENT_CONFIG_HOME);
056: File cfh = new File(conf_home);
057: if (cfh.exists()) {
058: System.setProperty(
059: JaWEConstants.JAWE_CURRENT_CONFIG_HOME,
060: conf_home);
061: if (Utils
062: .checkFileExistence(JaWEManager.TOGWE_BASIC_PROPERTYFILE_NAME)
063: || Utils
064: .checkResourceExistence(
065: JaWEManager.TOGWE_BASIC_PROPERTYFILE_PATH,
066: JaWEManager.TOGWE_BASIC_PROPERTYFILE_NAME)) {
067: cfgf = new File(conf_home + "/"
068: + JaWEManager.TOGWE_BASIC_PROPERTYFILE_NAME);
069: } else {
070: cfgf = new File(
071: conf_home
072: + "/"
073: + JaWEConstants.JAWE_BASIC_PROPERTYFILE_NAME);
074: }
075: }
076: }
077: if (cfgf != null && cfgf.exists()) {
078: JaWEManager.configure(cfgf);
079: } else {
080: JaWEManager.configure();
081: }
082:
083: // Starting file name
084: String fn = null;
085:
086: // check if there is a file that should be open at the startup
087: if (args != null && args.length > 0) {
088: fn = args[0];
089: }
090:
091: JaWEManager.getInstance().start(fn);
092:
093: if (JaWE.getJaWEVersion() == JaWE.DEMO_VERSION
094: || (JaWE.getJaWEVersion() == JaWE.COMMUNITY_VERSION && !addOnsAvailable())) {
095: JaWEAboutDialog d = new JaWEAboutDialog(JaWEManager
096: .getInstance().getJaWEController().getJaWEFrame());
097:
098: d.pack();
099: Dimension screenSize = Toolkit.getDefaultToolkit()
100: .getScreenSize();
101: Dimension winsize = d.getSize();
102: d.setLocation(screenSize.width / 2 - (winsize.width / 2),
103: screenSize.height / 2 - (winsize.height / 2));
104: d.setLocationRelativeTo(JaWEManager.getInstance()
105: .getJaWEController().getJaWEFrame());
106: d.setTitle(JaWEManager.getInstance().getJaWEController()
107: .getSettings().getLanguageDependentString(
108: "AboutFrameTitle"));
109:
110: d.setVisible(true);
111:
112: if (JaWE.getJaWEVersion() == JaWE.DEMO_VERSION) {
113: timeLeft = 0;
114: }
115: while (timeLeft != 0) {
116: Thread.sleep(1000);
117: timeLeft--;
118: d.setTime(timeLeft);
119: }
120:
121: d.setTime(0);
122:
123: d = null;
124: }
125: }
126:
127: private static class JaWEAboutDialog extends JDialog {
128:
129: JButton okButton;
130:
131: public JaWEAboutDialog(JFrame frame) {
132: super (frame);
133: JPanel main = new JPanel();
134: main.setBackground(Color.WHITE);
135: main.setLayout(new BoxLayout(main, BoxLayout.Y_AXIS));
136: okButton = new JButton(" OK (" + timeLeft + ")");
137: okButton.setAlignmentX(CENTER_ALIGNMENT);
138: okButton.addActionListener(new ActionHandler());
139: okButton.setEnabled(false);
140: main.add(JaWESplash.getSplashPanel());
141: main.add(Box.createVerticalStrut(15));
142: main.add(okButton);
143: getContentPane().add(main);
144:
145: this .getParent().setEnabled(false);
146:
147: this
148: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
149: }
150:
151: public void setTime(int timeLeft) {
152: if (timeLeft != 0)
153: okButton.setText(" OK (" + timeLeft + ")");
154: else {
155: okButton.setText(" OK ");
156: okButton.setEnabled(true);
157: this
158: .setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
159: getParent().setEnabled(true);
160: }
161: }
162:
163: private class ActionHandler implements ActionListener {
164: public void actionPerformed(ActionEvent e) {
165: dispose();
166: }
167: }
168: }
169:
170: public static final int COMMUNITY_VERSION = 0;
171:
172: public static final int DEMO_VERSION = 1;
173:
174: public static final int PROFESSIONAL_VERSION = 2;
175:
176: protected static int VERSION = -1;
177:
178: public static int getJaWEVersion() {
179: if (VERSION == -1) {
180: try {
181: Class
182: .forName("org.enhydra.jawe.base.controller.TogWEDemoController");
183: VERSION = DEMO_VERSION;
184: } catch (Exception ex) {
185: try {
186: Class.forName("org.enhydra.jawe.ProfInfo");
187: VERSION = PROFESSIONAL_VERSION;
188: } catch (Exception ex2) {
189: VERSION = COMMUNITY_VERSION;
190: }
191: }
192: }
193: return VERSION;
194: }
195:
196: protected static boolean addOnsAvailable = false;
197:
198: public static boolean addOnsAvailable() {
199: try {
200: Class.forName("org.enhydra.jawe.AddOnInfo");
201: addOnsAvailable = true;
202: } catch (Exception ex) {
203: }
204: return addOnsAvailable;
205: }
206: }
|