You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761
  1. /*
  2. * Copyright (c) 2006-2007 Chris Smith, Shane Mc Cormack, Gregory Holmes
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a copy
  5. * of this software and associated documentation files (the "Software"), to deal
  6. * in the Software without restriction, including without limitation the rights
  7. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. * copies of the Software, and to permit persons to whom the Software is
  9. * furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  17. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  18. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  19. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  20. * SOFTWARE.
  21. */
  22. package com.dmdirc.ui;
  23. import com.dmdirc.ui.interfaces.InputWindow;
  24. import com.dmdirc.Config;
  25. import com.dmdirc.FrameContainer;
  26. import com.dmdirc.Main;
  27. import com.dmdirc.ServerManager;
  28. import com.dmdirc.actions.ActionManager;
  29. import com.dmdirc.actions.CoreActionType;
  30. import com.dmdirc.logger.ErrorLevel;
  31. import com.dmdirc.logger.Logger;
  32. import com.dmdirc.ui.components.Frame;
  33. import com.dmdirc.ui.components.StatusBar;
  34. import com.dmdirc.ui.dialogs.AboutDialog;
  35. import com.dmdirc.ui.dialogs.ActionsManagerDialog;
  36. import com.dmdirc.ui.dialogs.NewServerDialog;
  37. import com.dmdirc.ui.dialogs.PluginDialog;
  38. import com.dmdirc.ui.dialogs.PreferencesDialog;
  39. import com.dmdirc.ui.dialogs.ProfileEditorDialog;
  40. import com.dmdirc.ui.dialogs.firstrunwizard.FirstRunWizard;
  41. import com.dmdirc.ui.framemanager.FrameManager;
  42. import com.dmdirc.ui.framemanager.MainFrameManager;
  43. import com.dmdirc.ui.framemanager.windowmenu.WindowMenuFrameManager;
  44. import static com.dmdirc.ui.UIUtilities.SMALL_BORDER;
  45. import java.awt.BorderLayout;
  46. import java.awt.Color;
  47. import java.awt.Dimension;
  48. import java.awt.Font;
  49. import java.awt.GraphicsConfiguration;
  50. import java.awt.GraphicsDevice;
  51. import java.awt.Insets;
  52. import java.awt.MouseInfo;
  53. import java.awt.PointerInfo;
  54. import java.awt.Rectangle;
  55. import java.awt.event.ActionEvent;
  56. import java.awt.event.ActionListener;
  57. import java.awt.event.WindowEvent;
  58. import java.awt.event.WindowListener;
  59. import java.beans.PropertyVetoException;
  60. import java.net.URL;
  61. import java.util.HashMap;
  62. import java.util.Map;
  63. import javax.swing.BorderFactory;
  64. import javax.swing.ImageIcon;
  65. import javax.swing.JDesktopPane;
  66. import javax.swing.JFrame;
  67. import javax.swing.JInternalFrame;
  68. import javax.swing.JMenu;
  69. import javax.swing.JMenuBar;
  70. import javax.swing.JMenuItem;
  71. import javax.swing.JPanel;
  72. import javax.swing.JSeparator;
  73. import javax.swing.JSplitPane;
  74. import javax.swing.UIManager;
  75. import javax.swing.UIManager.LookAndFeelInfo;
  76. import javax.swing.UnsupportedLookAndFeelException;
  77. import javax.swing.WindowConstants;
  78. import javax.swing.border.EtchedBorder;
  79. import javax.swing.plaf.FontUIResource;
  80. /**
  81. * The main application frame.
  82. */
  83. public final class MainFrame extends JFrame implements WindowListener,
  84. ActionListener {
  85. /**
  86. * A version number for this class. It should be changed whenever the class
  87. * structure is changed (or anything else that would prevent serialized
  88. * objects being unserialized with the new class).
  89. */
  90. private static final long serialVersionUID = 5;
  91. /**
  92. * The number of pixels each new internal frame is offset by.
  93. */
  94. private static final int FRAME_OPENING_OFFSET = 30;
  95. /**
  96. * Singleton instance of MainFrame.
  97. */
  98. private static MainFrame me;
  99. /**
  100. * Whether the internal frames are maximised or not.
  101. */
  102. private boolean maximised;
  103. /**
  104. * The current number of pixels to displace new frames in the X direction.
  105. */
  106. private int xOffset;
  107. /**
  108. * The current number of pixels to displace new frames in the Y direction.
  109. */
  110. private int yOffset;
  111. /**
  112. * The main application icon.
  113. */
  114. private final ImageIcon imageIcon;
  115. /**
  116. * The frame manager that's being used.
  117. */
  118. private final MainFrameManager mainFrameManager;
  119. /**
  120. * The window menu frame manager that's being used.
  121. */
  122. private final WindowMenuFrameManager windowListFrameManager;
  123. /** Dekstop pane. */
  124. private JDesktopPane desktopPane;
  125. /** Plugin menu item. */
  126. private JMenu pluginsMenu;
  127. /** Windows menu item. */
  128. private JMenu windowsMenu;
  129. /** Main panel. */
  130. private JPanel frameManagerPanel;
  131. /** Add server menu item. */
  132. private JMenuItem miAddServer;
  133. /** Preferences menu item. */
  134. private JMenuItem miPreferences;
  135. /** Toggle state menu item. */
  136. private JMenuItem toggleStateMenuItem;
  137. /** status bar. */
  138. private StatusBar statusBar;
  139. /**
  140. * Creates new form MainFrame.
  141. */
  142. private MainFrame() {
  143. super();
  144. windowListFrameManager = new WindowMenuFrameManager();
  145. initComponents();
  146. setTitle(getTitlePrefix());
  147. // Load an icon
  148. final ClassLoader cldr = this.getClass().getClassLoader();
  149. final URL imageURL = cldr.getResource("com/dmdirc/res/icon.png");
  150. imageIcon = new ImageIcon(imageURL);
  151. setIconImage(imageIcon.getImage());
  152. mainFrameManager = new MainFrameManager();
  153. mainFrameManager.setParent(frameManagerPanel);
  154. // Get the Location of the mouse pointer
  155. final PointerInfo myPointerInfo = MouseInfo.getPointerInfo();
  156. // Get the Device (screen) the mouse pointer is on
  157. final GraphicsDevice myDevice = myPointerInfo.getDevice();
  158. // Get the configuration for the device
  159. final GraphicsConfiguration myGraphicsConfig = myDevice.getDefaultConfiguration();
  160. // Get the bounds of the device
  161. final Rectangle gcBounds = myGraphicsConfig.getBounds();
  162. // Calculate the center of the screen
  163. // gcBounds.x and gcBounds.y give the co ordinates where the screen
  164. // starts. gcBounds.width and gcBounds.height return the size in pixels
  165. // of the screen.
  166. final int xPos = gcBounds.x + ((gcBounds.width - getWidth()) / 2);
  167. final int yPos = gcBounds.y + ((gcBounds.height - getHeight()) / 2);
  168. // Set the location of the window
  169. setLocation(xPos, yPos);
  170. setVisible(true);
  171. miAddServer.addActionListener(new ActionListener() {
  172. public void actionPerformed(final ActionEvent actionEvent) {
  173. NewServerDialog.showNewServerDialog();
  174. }
  175. });
  176. miPreferences.addActionListener(new ActionListener() {
  177. public void actionPerformed(final ActionEvent actionEvent) {
  178. PreferencesDialog.showPreferencesDialog();
  179. }
  180. });
  181. toggleStateMenuItem.addActionListener(new ActionListener() {
  182. public void actionPerformed(final ActionEvent actionEvent) {
  183. try {
  184. getActiveFrame().setMaximum(!getActiveFrame().isMaximum());
  185. } catch (PropertyVetoException ex) {
  186. Logger.error(ErrorLevel.WARNING, "Unable to maximise window", ex);
  187. }
  188. }
  189. });
  190. addWindowListener(this);
  191. checkWindowState();
  192. }
  193. /**
  194. * Returns the singleton instance of MainFrame.
  195. * @return MainFrame instance
  196. */
  197. public static synchronized MainFrame getMainFrame() {
  198. if (me == null) {
  199. me = new MainFrame();
  200. if (!Config.hasOption("general", "firstRun")
  201. || Config.getOptionBool("general", "firstRun")) {
  202. Config.setOption("general", "firstRun", "false");
  203. new FirstRunWizard().display();
  204. }
  205. }
  206. return me;
  207. }
  208. /**
  209. * Indicates whether the main frame has been initialised or not.
  210. * @return True iff the main frame exists
  211. */
  212. public static boolean hasMainFrame() {
  213. return me != null;
  214. }
  215. /**
  216. * Adds the specified InternalFrame as a child of the main frame.
  217. * @param frame the frame to be added
  218. */
  219. public void addChild(final JInternalFrame frame) {
  220. // Add the frame
  221. desktopPane.add(frame);
  222. // Make sure it'll fit with our offsets
  223. if (frame.getWidth() + xOffset > desktopPane.getWidth()) {
  224. xOffset = 0;
  225. }
  226. if (frame.getHeight() + yOffset > desktopPane.getHeight()) {
  227. yOffset = 0;
  228. }
  229. // Position the frame
  230. frame.setLocation(xOffset, yOffset);
  231. frame.moveToFront();
  232. // Increase the offsets
  233. xOffset += FRAME_OPENING_OFFSET;
  234. yOffset += FRAME_OPENING_OFFSET;
  235. }
  236. /**
  237. * Removes the specified InternalFrame from our desktop pane.
  238. * @param frame The frame to be removed
  239. */
  240. public void delChild(final JInternalFrame frame) {
  241. desktopPane.remove(frame);
  242. if (desktopPane.getAllFrames().length == 0) {
  243. setTitle(getTitlePrefix());
  244. }
  245. }
  246. /**
  247. * Sets the active internal frame to the one specified.
  248. * @param frame The frame to be activated
  249. */
  250. public void setActiveFrame(final JInternalFrame frame) {
  251. try {
  252. frame.setVisible(true);
  253. frame.setIcon(false);
  254. frame.moveToFront();
  255. frame.setSelected(true);
  256. } catch (PropertyVetoException ex) {
  257. Logger.error(ErrorLevel.ERROR, "Unable to set active window", ex);
  258. }
  259. if (maximised) {
  260. setTitle(getTitlePrefix() + " - " + frame.getTitle());
  261. }
  262. ActionManager.processEvent(CoreActionType.CLIENT_FRAME_CHANGED, null, ((InputWindow) frame).getContainer());
  263. }
  264. /**
  265. * Retrieves the frame manager that's currently in use.
  266. * @return The current frame manager
  267. */
  268. public FrameManager getFrameManager() {
  269. return mainFrameManager;
  270. }
  271. /**
  272. * Retrieves the application icon.
  273. * @return The application icon
  274. */
  275. public ImageIcon getIcon() {
  276. return imageIcon;
  277. }
  278. /**
  279. * Returns the JInternalFrame that is currently active.
  280. * @return The active JInternalFrame
  281. */
  282. public JInternalFrame getActiveFrame() {
  283. return desktopPane.getSelectedFrame();
  284. }
  285. /**
  286. * Adds a JMenuItem to the plugin menu.
  287. * @param menuItem The menu item to be added.
  288. */
  289. public void addPluginMenu(final JMenuItem menuItem) {
  290. if (pluginsMenu.getComponents().length == 1) {
  291. final JSeparator seperator = new JSeparator();
  292. pluginsMenu.add(seperator);
  293. }
  294. pluginsMenu.add(menuItem);
  295. }
  296. /**
  297. * Removes a JMenuItem from the plugin menu.
  298. * @param menuItem The menu item to be removed.
  299. */
  300. public void removePluginMenu(final JMenuItem menuItem) {
  301. pluginsMenu.remove(menuItem);
  302. if (pluginsMenu.getComponents().length == 2) {
  303. pluginsMenu.remove(2);
  304. }
  305. }
  306. /**
  307. * Sets whether or not the internal frame state is currently maximised.
  308. * @param max whether the frame is maxomised
  309. */
  310. public void setMaximised(final boolean max) {
  311. maximised = max;
  312. if (max) {
  313. if (getActiveFrame() != null) {
  314. setTitle(getTitlePrefix() + " - " + getActiveFrame().getTitle());
  315. }
  316. } else {
  317. setTitle(getTitlePrefix());
  318. for (JInternalFrame frame : desktopPane.getAllFrames()) {
  319. try {
  320. frame.setMaximum(false);
  321. } catch (PropertyVetoException ex) {
  322. Logger.error(ErrorLevel.ERROR, "Unable to maximise window", ex);
  323. }
  324. }
  325. }
  326. checkWindowState();
  327. }
  328. /**
  329. * Returns a prefix for use in the titlebar. Includes the version number
  330. * if the config option is set.
  331. * @return Titlebar prefix
  332. */
  333. public String getTitlePrefix() {
  334. if (Config.getOptionBool("ui", "showversion")) {
  335. return "DMDirc " + Main.VERSION;
  336. } else {
  337. return "DMDirc";
  338. }
  339. }
  340. /**
  341. * Gets whether or not the internal frame state is currently maximised.
  342. * @return True iff frames should be maximised, false otherwise
  343. */
  344. public boolean getMaximised() {
  345. return maximised;
  346. }
  347. /**
  348. * Checks the current state of the internal frames, and configures the
  349. * window menu to behave appropriately.
  350. */
  351. private void checkWindowState() {
  352. if (getActiveFrame() == null) {
  353. toggleStateMenuItem.setEnabled(false);
  354. return;
  355. }
  356. toggleStateMenuItem.setEnabled(true);
  357. if (maximised) {
  358. toggleStateMenuItem.setText("Restore");
  359. toggleStateMenuItem.setMnemonic('r');
  360. toggleStateMenuItem.invalidate();
  361. } else {
  362. toggleStateMenuItem.setText("Maximise");
  363. toggleStateMenuItem.setMnemonic('m');
  364. toggleStateMenuItem.invalidate();
  365. }
  366. }
  367. /**
  368. * Returns the status bar instance.
  369. *
  370. * @return StatusBar instance
  371. */
  372. public StatusBar getStatusBar() {
  373. return statusBar;
  374. }
  375. /** {@inheritDoc}. */
  376. public void windowOpened(final WindowEvent windowEvent) {
  377. //ignore
  378. }
  379. /**
  380. * Called when the window is closing. Saves the config and has all servers
  381. * disconnect with the default close method
  382. * @param windowEvent The event associated with this callback
  383. */
  384. public void windowClosing(final WindowEvent windowEvent) {
  385. ServerManager.getServerManager().closeAll(Config.getOption("general", "closemessage"));
  386. Config.save();
  387. }
  388. /** {@inheritDoc}. */
  389. public void windowClosed(final WindowEvent windowEvent) {
  390. //ignore
  391. }
  392. /** {@inheritDoc}. */
  393. public void windowIconified(final WindowEvent windowEvent) {
  394. //ignore
  395. }
  396. /** {@inheritDoc}. */
  397. public void windowDeiconified(final WindowEvent windowEvent) {
  398. //ignore
  399. }
  400. /** {@inheritDoc}. */
  401. public void windowActivated(final WindowEvent windowEvent) {
  402. //ignore
  403. }
  404. /** {@inheritDoc}. */
  405. public void windowDeactivated(final WindowEvent windowEvent) {
  406. //ignore
  407. }
  408. /**
  409. * Initialises the components for this frame.
  410. */
  411. private void initComponents() {
  412. JSplitPane mainSplitPane;
  413. frameManagerPanel = new JPanel();
  414. desktopPane = new JDesktopPane();
  415. desktopPane.setBackground(new Color(238, 238, 238));
  416. mainSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
  417. statusBar = new StatusBar();
  418. mainSplitPane.setBorder(null);
  419. initMenuBar();
  420. setPreferredSize(new Dimension(800, 600));
  421. getContentPane().setLayout(new BorderLayout(SMALL_BORDER, SMALL_BORDER));
  422. getContentPane().add(mainSplitPane, BorderLayout.CENTER);
  423. getContentPane().add(statusBar, BorderLayout.SOUTH);
  424. mainSplitPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0,
  425. SMALL_BORDER));
  426. mainSplitPane.setDividerSize(SMALL_BORDER);
  427. mainSplitPane.setOneTouchExpandable(false);
  428. mainSplitPane.setLeftComponent(frameManagerPanel);
  429. mainSplitPane.setRightComponent(desktopPane);
  430. frameManagerPanel.setMinimumSize(new Dimension(150, Integer.MAX_VALUE));
  431. desktopPane.setMaximumSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE));
  432. desktopPane.setMinimumSize(new Dimension(300, Integer.MAX_VALUE));
  433. mainSplitPane.setResizeWeight(0);
  434. mainSplitPane.setContinuousLayout(true);
  435. setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
  436. setTitle("DMDirc");
  437. frameManagerPanel.setBorder(
  438. BorderFactory.createEmptyBorder(0, SMALL_BORDER, 0, 0));
  439. desktopPane.setBorder(
  440. BorderFactory.createEtchedBorder(EtchedBorder.LOWERED));
  441. pack();
  442. }
  443. /** Initialises the menu bar. */
  444. private void initMenuBar() {
  445. final JMenuBar menuBar = new JMenuBar();
  446. JMenuItem menuItem;
  447. final JMenu fileMenu = new JMenu();
  448. miAddServer = new JMenuItem();
  449. miPreferences = new JMenuItem();
  450. final JMenu settingsMenu = new JMenu();
  451. final JMenu helpMenu = new JMenu();
  452. toggleStateMenuItem = new JMenuItem();
  453. settingsMenu.setText("Settings");
  454. settingsMenu.setMnemonic('s');
  455. fileMenu.setMnemonic('f');
  456. fileMenu.setText("File");
  457. miAddServer.setText("New Server...");
  458. miAddServer.setMnemonic('n');
  459. fileMenu.add(miAddServer);
  460. miPreferences.setText("Preferences");
  461. miPreferences.setMnemonic('p');
  462. settingsMenu.add(miPreferences);
  463. menuItem = new JMenuItem();
  464. menuItem.setMnemonic('m');
  465. menuItem.setText("Profile Manager");
  466. menuItem.setActionCommand("Profile");
  467. menuItem.addActionListener(this);
  468. settingsMenu.add(menuItem);
  469. menuItem = new JMenuItem();
  470. menuItem.setMnemonic('a');
  471. menuItem.setText("Actions Manager");
  472. menuItem.setActionCommand("Actions");
  473. menuItem.addActionListener(this);
  474. settingsMenu.add(menuItem);
  475. menuItem = new JMenuItem();
  476. menuItem.setMnemonic('x');
  477. menuItem.setText("Exit");
  478. menuItem.setActionCommand("Exit");
  479. menuItem.addActionListener(this);
  480. fileMenu.add(menuItem);
  481. populateWindowMenu(new HashMap<FrameContainer, JMenuItem>());
  482. helpMenu.setMnemonic('h');
  483. helpMenu.setText("Help");
  484. menuItem = new JMenuItem();
  485. menuItem.setMnemonic('a');
  486. menuItem.setText("About");
  487. menuItem.setActionCommand("About");
  488. menuItem.addActionListener(this);
  489. helpMenu.add(menuItem);
  490. pluginsMenu = new JMenu("Plugins");
  491. pluginsMenu.setMnemonic('p');
  492. settingsMenu.add(pluginsMenu);
  493. menuItem = new JMenuItem();
  494. menuItem.setMnemonic('m');
  495. menuItem.setText("Manage plugins");
  496. menuItem.setActionCommand("ManagePlugins");
  497. menuItem.addActionListener(this);
  498. pluginsMenu.add(menuItem);
  499. menuBar.add(fileMenu);
  500. menuBar.add(settingsMenu);
  501. menuBar.add(windowsMenu);
  502. menuBar.add(helpMenu);
  503. setJMenuBar(menuBar);
  504. }
  505. /**
  506. * Initialises the window menu.
  507. *
  508. * @param windows Map of windows
  509. */
  510. public void populateWindowMenu(final Map<FrameContainer, JMenuItem> windows) {
  511. if (windowsMenu == null) {
  512. windowsMenu = new JMenu();
  513. } else {
  514. windowsMenu.removeAll();
  515. }
  516. JMenuItem menuItem;
  517. windowsMenu.setMnemonic('w');
  518. windowsMenu.setText("Window");
  519. toggleStateMenuItem.setMnemonic('m');
  520. toggleStateMenuItem.setText("Maximise");
  521. windowsMenu.add(toggleStateMenuItem);
  522. menuItem = new JMenuItem();
  523. menuItem.setMnemonic('n');
  524. menuItem.setText("Minimise");
  525. menuItem.setActionCommand("Minimise");
  526. menuItem.addActionListener(this);
  527. windowsMenu.add(menuItem);
  528. menuItem = new JMenuItem();
  529. menuItem.setMnemonic('c');
  530. menuItem.setText("Close");
  531. menuItem.setActionCommand("Close");
  532. menuItem.addActionListener(this);
  533. windowsMenu.add(menuItem);
  534. menuItem = new JMenuItem();
  535. menuItem.setMnemonic('a');
  536. menuItem.setText("Close all");
  537. menuItem.setActionCommand("CloseAll");
  538. menuItem.addActionListener(this);
  539. windowsMenu.add(menuItem);
  540. windowsMenu.addSeparator();
  541. int i = 0;
  542. for (JMenuItem mi : windows.values()) {
  543. if (i > 34) {
  544. break;
  545. }
  546. windowsMenu.add(mi);
  547. i++;
  548. }
  549. }
  550. /**
  551. * {@inheritDoc}.
  552. */
  553. public void actionPerformed(final ActionEvent e) {
  554. if (e.getActionCommand().equals("About")) {
  555. AboutDialog.showAboutDialog();
  556. } else if (e.getActionCommand().equals("Profile")) {
  557. ProfileEditorDialog.showActionsManagerDialog();
  558. } else if (e.getActionCommand().equals("Exit")) {
  559. Main.quit();
  560. } else if (e.getActionCommand().equals("ManagePlugins")) {
  561. PluginDialog.showPluginDialog();
  562. } else if (e.getActionCommand().equals("Actions")) {
  563. ActionsManagerDialog.showActionsManagerDialog();
  564. } else if (e.getActionCommand().equals("Minimise")) {
  565. ((Frame) MainFrame.getMainFrame().getActiveFrame()).minimise();
  566. } else if (e.getActionCommand().equals("Close")) {
  567. ((Frame) MainFrame.getMainFrame().getActiveFrame()).close();
  568. } else if (e.getActionCommand().equals("CloseAll")) {
  569. ServerManager.getServerManager().closeAll();
  570. }
  571. }
  572. /** Initialises UI Settings. */
  573. public static void initUISettings() {
  574. final String lnfName = getLookAndFeel(Config.getOption("ui", "lookandfeel"));
  575. if (Config.hasOption("ui", "antialias")) {
  576. final String aaSetting = Config.getOption("ui", "antialias");
  577. System.setProperty("awt.useSystemAAFontSettings", aaSetting);
  578. System.setProperty("swing.aatext", aaSetting);
  579. }
  580. try {
  581. UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
  582. final FontUIResource font = new FontUIResource("Dialog", Font.PLAIN , 12);
  583. UIManager.put("Label.font", font);
  584. UIManager.put("TextField.font", font);
  585. UIManager.put("PasswordField.font", font);
  586. UIManager.put("Button.font", font);
  587. UIManager.put("RadioButton.font", font);
  588. UIManager.put("CheckBox.font", font);
  589. UIManager.put("ComboBox.font", font);
  590. UIManager.put("Menu.font", font);
  591. UIManager.put("List.font", font);
  592. UIManager.put("MenuItem.font", font);
  593. UIManager.put("Panel.font", font);
  594. UIManager.put("TitledBorder.font", font);
  595. UIManager.put("TabbedPane.font", font);
  596. UIManager.put("Tree.font", font);
  597. UIManager.put("InternalFrame.titleFont", font);
  598. UIManager.put("EditorPane.font", font);
  599. UIManager.put("swing.boldMetal", false);
  600. UIManager.put("InternalFrame.useTaskBar", false);
  601. UIManager.put("SplitPaneDivider.border", BorderFactory.createEmptyBorder());
  602. UIManager.put("TabbedPane.contentBorderInsets", new Insets(1, 1, 1, 1));
  603. UIManager.put("Tree.scrollsOnExpand", true);
  604. UIManager.put("Tree.scrollsHorizontallyAndVertically", true);
  605. UIManager.put("Tree.dropCellBackground", Color.WHITE);
  606. UIManager.put("Tree.selectionBackground", Color.WHITE);
  607. UIManager.put("Tree.textBackground", Color.WHITE);
  608. UIManager.put("Tree.selectionBorderColor", Color.WHITE);
  609. UIManager.put("Tree.drawsFocusBorder", false);
  610. UIManager.put("Tree.drawHorizontalLines", true);
  611. UIManager.put("Tree.drawVerticalLines", true);
  612. UIManager.put("Tree.background", Color.WHITE);
  613. if (Config.hasOption("ui", "lookandfeel") && lnfName.length() != 0) {
  614. UIManager.setLookAndFeel(lnfName);
  615. }
  616. } catch (InstantiationException ex) {
  617. Logger.error(ErrorLevel.ERROR, "Unable to set look and feel: " + lnfName, ex);
  618. } catch (ClassNotFoundException ex) {
  619. Logger.error(ErrorLevel.ERROR, "Look and feel not available: " + lnfName, ex);
  620. } catch (UnsupportedLookAndFeelException ex) {
  621. Logger.error(ErrorLevel.ERROR, "Look and feel not available: " + lnfName, ex);
  622. } catch (IllegalAccessException ex) {
  623. Logger.error(ErrorLevel.ERROR, "Unable to set look and feel: " + lnfName, ex);
  624. }
  625. }
  626. /**
  627. * Returns the class name of the look and feel from its display name.
  628. *
  629. * @param displayName Look and feel display name
  630. *
  631. * @return Look and feel class name or a zero length string
  632. */
  633. private static String getLookAndFeel(final String displayName) {
  634. final StringBuilder classNameBuilder = new StringBuilder();
  635. if (displayName != null && !"".equals(displayName)) {
  636. for (LookAndFeelInfo laf : UIManager.getInstalledLookAndFeels()) {
  637. if (laf.getName().equals(displayName)) {
  638. classNameBuilder.setLength(0);
  639. classNameBuilder.append(laf.getClassName());
  640. break;
  641. }
  642. }
  643. }
  644. return classNameBuilder.toString();
  645. }
  646. }