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