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 20 26 public class DiscRack extends JPanel { 27 private static final String appTitle="DiscRack"; 29 private static ImageIcon appIcon; 31 32 36 static { 37 try { 38 String 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 URL url = ResourceManager.getResource("Icon"); 46 if (url != null) appIcon = new ImageIcon(url); 47 48 try { 49 UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName()); 51 } catch (Exception exc) { 52 System.err.println("Error loading L&F: " + exc); 53 } 54 } catch (Throwable t) { 55 System.err.println("uncaught exception: " + t); 56 t.printStackTrace(); 57 } 58 } 59 60 protected JFrame myFrame; 62 63 protected Hashtable commands; 64 protected JMenuBar menubar; 65 protected JToolBar toolbar; 66 69 protected Action[] defaultActions; 70 71 private JScrollPane helperJSP=new JScrollPane(); 72 private JPanel centralPanel=new JPanel(); 73 74 76 public DiscRack() { 77 super(true); 78 79 setBorder(BorderFactory.createEtchedBorder()); 80 setLayout(new BorderLayout()); 81 82 commands = new Hashtable(); 83 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 add(menubar,BorderLayout.NORTH); 94 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(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 139 public void setTitleUser (String user) { 140 if (user==null) { 141 user="no logged user"; 142 } 143 myFrame.setTitle(appTitle+" - "+user); 144 } 145 149 protected final class AppCloser extends WindowAdapter { 150 public void windowClosing(WindowEvent e) { 151 getAction("Exit").actionPerformed(null); 152 } 153 } 154 156 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 169 public Action[] getActions() { 170 return defaultActions; 171 } 172 173 178 public Action getAction(String cmd) { 179 return (Action)commands.get(cmd); 180 } 181 183 185 public JFrame getFrame () { 186 return myFrame; 187 } 188 189 public String 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 [] args) { 199 try { 200 String userDir=System.getProperty("user.dir"); 201 DODS.startup(userDir+File.separator+"discRack.conf"); 202 } catch (Exception ex) { 203 ex.printStackTrace(); 204 System.exit(0); 205 } 206 DiscRack dr=new DiscRack(); 207 } 208 } 209 210 | Popular Tags |