KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > discRack > DiscRack


1 package discRack;
2
3 import com.lutris.appserver.server.sql.*;
4 import com.lutris.util.*;
5 import org.enhydra.dods.*;
6
7 import discRack.actions.*;
8 import discRack.presentation.*;
9 import discRack.presentation.delements.*;
10
11 import javax.swing.*;
12 import java.util.*;
13 import java.awt.*;
14 import java.awt.event.*;
15 import java.net.*;
16 import java.io.*;
17 //import org.apache.log4j.Logger;
18
//import org.apache.log4j.xml.DOMConfigurator;
19

20 /**
21  * The main class of DiscRack application.
22  *
23  * @author Sasa Bojanic
24  * @version 1.0
25  */

26 public class DiscRack extends JPanel {
27    // Application Title and other stuff. From resource file.
28
private static final String JavaDoc appTitle="DiscRack";
29    // Application Icon. From resource file.
30
private static ImageIcon appIcon;
31
32    /**
33     * Checks if java version is >= 1.4, sets application title and icon, as
34     * well as logo icon.
35     */

36    static {
37       try {
38          String JavaDoc vers = System.getProperty("java.version");
39          if (vers.compareTo("1.") < 0) {
40             System.out.println("!!!WARNING: JaWE must be run with a " +
41                   "1.4 or higher version VM!!!");
42          }
43
44          // Icon
45
URL url = ResourceManager.getResource("Icon");
46          if (url != null) appIcon = new ImageIcon(url);
47
48          try {
49             //UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
50
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
51          } catch (Exception JavaDoc exc) {
52             System.err.println("Error loading L&F: " + exc);
53          }
54       } catch (Throwable JavaDoc t) {
55          System.err.println("uncaught exception: " + t);
56          t.printStackTrace();
57       }
58    }
59
60    // The frame of application
61
protected JFrame myFrame;
62
63    protected Hashtable commands;
64    protected JMenuBar menubar;
65    protected JToolBar toolbar;
66    /**
67     * Actions defined by the WorkflowAdmin class
68     */

69    protected Action[] defaultActions;
70
71    private JScrollPane helperJSP=new JScrollPane();
72    private JPanel centralPanel=new JPanel();
73
74    //************************** CONSTRUCTOR ***********************
75
/** Creates instance of main application class. */
76    public DiscRack() {
77       super(true);
78
79       setBorder(BorderFactory.createEtchedBorder());
80       setLayout(new BorderLayout());
81
82       commands = new Hashtable();
83       // Actions defined by the ProcessEditor class
84
createActions();
85       Action[] actions = getActions();
86       for (int i = 0; i < actions.length; i++) {
87          Action a = actions[i];
88          commands.put(a.getValue(Action.NAME), a);
89       }
90
91       menubar = BarFactory.createMenubar("menubar",commands);
92       // adding menubar to the main panel
93
add(menubar,BorderLayout.NORTH);
94       // adding center component
95
JPanel helperPanel=new JPanel();
96       helperPanel.setLayout(new BorderLayout());
97
98       toolbar=(JToolBar)BarFactory.createToolbar("toolbar",commands);
99       helperPanel.add(toolbar,BorderLayout.NORTH);
100       helperJSP.setViewportView(centralPanel);
101       helperPanel.add(helperJSP,BorderLayout.CENTER);
102       //add(centralPanel,BorderLayout.CENTER);
103
add(helperPanel,BorderLayout.CENTER);
104
105       myFrame = new JFrame();
106       myFrame.setBackground(Color.lightGray);
107       myFrame.getContentPane().setLayout(new BorderLayout());
108       myFrame.getContentPane().add(this,BorderLayout.CENTER);
109       myFrame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
110       myFrame.addWindowListener(new AppCloser());
111       myFrame.pack();
112       Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
113       int xSize=950,ySize=600;
114       int xMinus, yMinus;
115       if (screenSize.width>xSize) {
116          xMinus=screenSize.width-xSize;
117       } else {
118          xMinus=0;
119       }
120       if (screenSize.height>ySize) {
121          yMinus=screenSize.height-ySize;
122       } else {
123          yMinus=0;
124       }
125
126       myFrame.setBounds(xMinus/2, yMinus/2, screenSize.width - xMinus,
127             screenSize.height - yMinus);
128
129       if (appIcon != null) myFrame.setIconImage(appIcon.getImage());
130       setTitleUser(null);
131
132       getAction("Logout").setEnabled(false);
133       myFrame.show();
134       getAction("Login").actionPerformed(null);
135
136    }
137    //************************* END OF WORKLISTHANDLER CONSTRUCTOR *****************
138

139    public void setTitleUser (String JavaDoc user) {
140       if (user==null) {
141          user="no logged user";
142       }
143       myFrame.setTitle(appTitle+" - "+user);
144    }
145    //************** APPCLOSER CLASS FOR CLOSING APPLICATION WINDOW ***************
146
/**
147     * To shutdown when run as an application.
148     */

149    protected final class AppCloser extends WindowAdapter {
150       public void windowClosing(WindowEvent e) {
151          getAction("Exit").actionPerformed(null);
152       }
153    }
154    //**** END OF CREATING APPLICATION CLOSER COMPONENT FOR APPLICATION WINDOW ****
155

156    // ************************* GETTING ACTION STUFF *****************************
157
protected void createActions () {
158       defaultActions=new Action[] {
159          new discRack.actions.Exit(this),
160          new discRack.actions.Login(this),
161          new discRack.actions.Logout(this),
162          new discRack.actions.Register(this),
163       };
164    }
165
166    /**
167     * Fetch the list of actions supported by this app.
168     */

169    public Action[] getActions() {
170       return defaultActions;
171    }
172
173    /**
174     * Method to get action corresponding to the given string.
175     * @param cmd String representation of editor's action.
176     * @return action specified by the string cmd.
177     **/

178    public Action getAction(String JavaDoc cmd) {
179       return (Action)commands.get(cmd);
180    }
181    // ********************* END OF GETTING ACTION STUFF **************************
182

183    //*********************** END OF EXIT ACTION CLASS *************************
184

185    public JFrame getFrame () {
186       return myFrame;
187    }
188
189    public String JavaDoc getAppTitle () {
190       return appTitle;
191    }
192
193    public void setCentralPanel (JPanel p) {
194       centralPanel=p;
195       helperJSP.setViewportView(centralPanel);
196    }
197
198    public static void main (String JavaDoc[] args) {
199       try {
200          String JavaDoc userDir=System.getProperty("user.dir");
201          DODS.startup(userDir+File.separator+"discRack.conf");
202       } catch (Exception JavaDoc ex) {
203          ex.printStackTrace();
204          System.exit(0);
205       }
206       DiscRack dr=new DiscRack();
207    }
208 }
209
210
Popular Tags