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