001: package jtaDiscRack;
002:
003: import org.enhydra.dods.*;
004:
005: import javax.swing.*;
006: import java.util.*;
007: import java.awt.*;
008: import java.awt.event.*;
009: import java.net.*;
010: import java.io.*;
011:
012: /**
013: * The main class of DiscRack application.
014: *
015: * @author Sasa Bojanic
016: * @version 1.0
017: */
018: public class JtaDiscRack extends JPanel {
019: // Application Title and other stuff. From resource file.
020: private static final String appTitle = "JtaDiscRack";
021: // Application Icon. From resource file.
022: private static ImageIcon appIcon;
023:
024: /**
025: * Checks if java version is >= 1.4, sets application title and icon, as
026: * well as logo icon.
027: */
028: static {
029: try {
030: String vers = System.getProperty("java.version");
031: if (vers.compareTo("1.") < 0) {
032: System.out
033: .println("!!!WARNING: Application must be run with a "
034: + "1.4 or higher version VM!!!");
035: }
036:
037: // Icon
038: URL url = ResourceManager.getResource("Icon");
039: if (url != null)
040: appIcon = new ImageIcon(url);
041:
042: try {
043: //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
044: UIManager.setLookAndFeel(UIManager
045: .getSystemLookAndFeelClassName());
046: } catch (Exception exc) {
047: System.err.println("Error loading L&F: " + exc);
048: }
049: } catch (Throwable t) {
050: System.err.println("uncaught exception: " + t);
051: t.printStackTrace();
052: }
053: }
054:
055: // The frame of application
056: protected JFrame myFrame;
057:
058: protected Hashtable commands;
059: protected JMenuBar menubar;
060: protected JToolBar toolbar;
061: /**
062: * Actions defined by the WorkflowAdmin class
063: */
064: protected Action[] defaultActions;
065:
066: private JScrollPane helperJSP = new JScrollPane();
067: private JPanel centralPanel = new JPanel();
068:
069: //************************** CONSTRUCTOR ***********************
070: /** Creates instance of main application class. */
071: public JtaDiscRack() {
072: super (true);
073:
074: setBorder(BorderFactory.createEtchedBorder());
075: setLayout(new BorderLayout());
076:
077: commands = new Hashtable();
078: // Actions defined by the ProcessEditor class
079: createActions();
080: Action[] actions = getActions();
081: for (int i = 0; i < actions.length; i++) {
082: Action a = actions[i];
083: commands.put(a.getValue(Action.NAME), a);
084: }
085:
086: menubar = BarFactory.createMenubar("menubar", commands);
087: // adding menubar to the main panel
088: add(menubar, BorderLayout.NORTH);
089: // adding center component
090: JPanel helperPanel = new JPanel();
091: helperPanel.setLayout(new BorderLayout());
092:
093: toolbar = (JToolBar) BarFactory.createToolbar("toolbar",
094: commands);
095: helperPanel.add(toolbar, BorderLayout.NORTH);
096: helperJSP.setViewportView(centralPanel);
097: helperPanel.add(helperJSP, BorderLayout.CENTER);
098: //add(centralPanel,BorderLayout.CENTER);
099: add(helperPanel, BorderLayout.CENTER);
100:
101: myFrame = new JFrame();
102: myFrame.setBackground(Color.lightGray);
103: myFrame.getContentPane().setLayout(new BorderLayout());
104: myFrame.getContentPane().add(this , BorderLayout.CENTER);
105: myFrame
106: .setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
107: myFrame.addWindowListener(new AppCloser());
108: myFrame.pack();
109: Dimension screenSize = Toolkit.getDefaultToolkit()
110: .getScreenSize();
111: int xSize = 950, ySize = 600;
112: int xMinus, yMinus;
113: if (screenSize.width > xSize) {
114: xMinus = screenSize.width - xSize;
115: } else {
116: xMinus = 0;
117: }
118: if (screenSize.height > ySize) {
119: yMinus = screenSize.height - ySize;
120: } else {
121: yMinus = 0;
122: }
123:
124: myFrame.setBounds(xMinus / 2, yMinus / 2, screenSize.width
125: - xMinus, screenSize.height - yMinus);
126:
127: if (appIcon != null)
128: myFrame.setIconImage(appIcon.getImage());
129: setTitleUser(null);
130:
131: getAction("Logout").setEnabled(false);
132: myFrame.show();
133: getAction("Login").actionPerformed(null);
134:
135: }
136:
137: //************************* END OF WORKLISTHANDLER CONSTRUCTOR *****************
138:
139: public void setTitleUser(String user) {
140: if (user == null) {
141: user = "no logged user";
142: }
143: myFrame.setTitle(appTitle + " - " + user);
144: }
145:
146: //************** APPCLOSER CLASS FOR CLOSING APPLICATION WINDOW ***************
147: /**
148: * To shutdown when run as an application.
149: */
150: protected final class AppCloser extends WindowAdapter {
151: public void windowClosing(WindowEvent e) {
152: getAction("Exit").actionPerformed(null);
153: }
154: }
155:
156: //**** END OF CREATING APPLICATION CLOSER COMPONENT FOR APPLICATION WINDOW ****
157:
158: // ************************* GETTING ACTION STUFF *****************************
159: protected void createActions() {
160: defaultActions = new Action[] {
161: new jtaDiscRack.actions.Exit(this ),
162: new jtaDiscRack.actions.Login(this ),
163: new jtaDiscRack.actions.Logout(this ),
164: new jtaDiscRack.actions.Register(this ), };
165: }
166:
167: /**
168: * Fetch the list of actions supported by this app.
169: */
170: public Action[] getActions() {
171: return defaultActions;
172: }
173:
174: /**
175: * Method to get action corresponding to the given string.
176: * @param cmd String representation of editor's action.
177: * @return action specified by the string cmd.
178: **/
179: public Action getAction(String cmd) {
180: return (Action) commands.get(cmd);
181: }
182:
183: // ********************* END OF GETTING ACTION STUFF **************************
184:
185: //*********************** END OF EXIT ACTION CLASS *************************
186:
187: public JFrame getFrame() {
188: return myFrame;
189: }
190:
191: public String getAppTitle() {
192: return appTitle;
193: }
194:
195: public void setCentralPanel(JPanel p) {
196: centralPanel = p;
197: helperJSP.setViewportView(centralPanel);
198: }
199:
200: public static void main(String[] args) {
201: try {
202: /*
203: * Initialize Application configuration file path
204: */
205: String conFilePath = null;
206: String userDir = System.getProperty("user.dir");
207: conFilePath = userDir + File.separator + "conf"
208: + File.separator + "jtaDiscRack.conf";
209:
210: if (args.length > 0) {
211: String tempPath = args[0];
212: File tempConfFile = new File(tempPath);
213: if (tempConfFile.exists()) {
214: conFilePath = tempConfFile.getCanonicalPath();
215: }
216: }
217:
218: /*
219: * Initialize JNDI, JOTM and Datasource JNDI context instance
220: */
221: org.enhydra.dods.jts.LocalContextFactory
222: .setup("jtaDiscRackDB");
223:
224: /*
225: * Initialize and configure DODS instalce
226: */
227: DODS.startup(conFilePath);
228:
229: /*
230: * Start application
231: */
232: JtaDiscRack jdr = new JtaDiscRack();
233: } catch (Exception ex) {
234: ex.printStackTrace();
235: System.exit(0);
236: }
237: }
238: }
|