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.

SwingController.java 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868
  1. /*
  2. * Copyright (c) 2006-2010 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.addons.ui_swing;
  23. import com.dmdirc.addons.ui_swing.dialogs.DialogKeyListener;
  24. import com.dmdirc.addons.ui_swing.components.frames.ServerFrame;
  25. import com.dmdirc.addons.ui_swing.components.frames.CustomFrame;
  26. import com.dmdirc.addons.ui_swing.components.frames.QueryFrame;
  27. import com.dmdirc.addons.ui_swing.components.frames.CustomInputFrame;
  28. import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
  29. import com.dmdirc.Channel;
  30. import com.dmdirc.FrameContainer;
  31. import com.dmdirc.Main;
  32. import com.dmdirc.config.prefs.PreferencesInterface;
  33. import com.dmdirc.config.prefs.PreferencesManager;
  34. import com.dmdirc.ui.IconManager;
  35. import com.dmdirc.Query;
  36. import com.dmdirc.Server;
  37. import com.dmdirc.WritableFrameContainer;
  38. import com.dmdirc.commandparser.parsers.CommandParser;
  39. import com.dmdirc.config.IdentityManager;
  40. import com.dmdirc.logger.ErrorLevel;
  41. import com.dmdirc.logger.Logger;
  42. import com.dmdirc.ui.core.dialogs.sslcertificate.SSLCertificateDialogModel;
  43. import com.dmdirc.ui.interfaces.ChannelWindow;
  44. import com.dmdirc.ui.interfaces.InputWindow;
  45. import com.dmdirc.ui.interfaces.QueryWindow;
  46. import com.dmdirc.ui.interfaces.ServerWindow;
  47. import com.dmdirc.ui.interfaces.StatusBar;
  48. import com.dmdirc.ui.interfaces.UIController;
  49. import com.dmdirc.ui.interfaces.Window;
  50. import com.dmdirc.addons.ui_swing.components.pluginpanel.PluginPanel;
  51. import com.dmdirc.addons.ui_swing.components.statusbar.FeedbackNag;
  52. import com.dmdirc.addons.ui_swing.components.statusbar.SwingStatusBar;
  53. import com.dmdirc.addons.ui_swing.components.themepanel.ThemePanel;
  54. import com.dmdirc.addons.ui_swing.dialogs.updater.SwingUpdaterDialog;
  55. import com.dmdirc.addons.ui_swing.dialogs.url.URLDialog;
  56. import com.dmdirc.addons.ui_swing.dialogs.channelsetting.ChannelSettingsDialog;
  57. import com.dmdirc.addons.ui_swing.dialogs.error.ErrorListDialog;
  58. import com.dmdirc.addons.ui_swing.dialogs.prefs.SwingPreferencesDialog;
  59. import com.dmdirc.addons.ui_swing.dialogs.prefs.URLConfigPanel;
  60. import com.dmdirc.addons.ui_swing.dialogs.prefs.UpdateConfigPanel;
  61. import com.dmdirc.addons.ui_swing.wizard.firstrun.SwingFirstRunWizard;
  62. import com.dmdirc.addons.ui_swing.dialogs.serversetting.ServerSettingsDialog;
  63. import com.dmdirc.addons.ui_swing.dialogs.sslcertificate.SSLCertificateDialog;
  64. import com.dmdirc.addons.ui_swing.wizard.WizardListener;
  65. import com.dmdirc.config.Identity;
  66. import com.dmdirc.config.prefs.PreferencesCategory;
  67. import com.dmdirc.config.prefs.PreferencesSetting;
  68. import com.dmdirc.config.prefs.PreferencesType;
  69. import com.dmdirc.config.prefs.validator.NumericalValidator;
  70. import com.dmdirc.plugins.Plugin;
  71. import com.dmdirc.updater.Update;
  72. import com.dmdirc.util.ReturnableThread;
  73. import java.awt.Font;
  74. import java.awt.GraphicsEnvironment;
  75. import java.awt.KeyboardFocusManager;
  76. import java.awt.Toolkit;
  77. import java.net.URI;
  78. import java.util.ArrayList;
  79. import java.util.HashMap;
  80. import java.util.List;
  81. import java.util.Map;
  82. import java.util.concurrent.Semaphore;
  83. import java.util.concurrent.atomic.AtomicBoolean;
  84. import javax.swing.JOptionPane;
  85. import javax.swing.SwingUtilities;
  86. import javax.swing.UIManager;
  87. import javax.swing.UIManager.LookAndFeelInfo;
  88. import javax.swing.UnsupportedLookAndFeelException;
  89. import net.miginfocom.layout.PlatformDefaults;
  90. /**
  91. * Controls the main swing UI.
  92. */
  93. public final class SwingController extends Plugin implements UIController {
  94. /** Logger to use. */
  95. private static final java.util.logging.Logger LOGGER =
  96. java.util.logging.Logger.getLogger(SwingController.class.getName());
  97. /** Singleton instance of MainFrame. */
  98. private MainFrame me;
  99. /** Status bar. */
  100. private SwingStatusBar statusBar;
  101. /** Top level window list. */
  102. private final List<java.awt.Window> windows;
  103. /** Waiting on mainframe creation. */
  104. private AtomicBoolean mainFrameCreated = new AtomicBoolean(false);
  105. /** Error dialog. */
  106. private ErrorListDialog errorDialog;
  107. /** Instantiates a new SwingController. */
  108. public SwingController() {
  109. setAntiAlias();
  110. windows = new ArrayList<java.awt.Window>();
  111. }
  112. /**
  113. * Make swing not use Anti Aliasing if the user doesn't want it.
  114. */
  115. public void setAntiAlias() {
  116. // For this to work it *HAS* to be before anything else UI related.
  117. final boolean aaSetting = IdentityManager.getGlobalConfig().
  118. getOptionBool("ui", "antialias");
  119. System.setProperty("awt.useSystemAAFontSettings",
  120. Boolean.toString(aaSetting));
  121. System.setProperty("swing.aatext", Boolean.toString(aaSetting));
  122. }
  123. /**
  124. * Does the main frame exist?
  125. *
  126. * @return true iif mainframe exists
  127. */
  128. protected boolean hasMainFrame() {
  129. return mainFrameCreated.get();
  130. }
  131. /** {@inheritDoc} */
  132. @Override
  133. public MainFrame getMainWindow() {
  134. return getMainFrame();
  135. }
  136. /**
  137. * Retrieves the main window used by this UI.
  138. *
  139. * @return This UI's main window
  140. */
  141. public MainFrame getMainFrame() {
  142. return me;
  143. }
  144. /** {@inheritDoc} */
  145. @Override
  146. public StatusBar getStatusBar() {
  147. return getSwingStatusBar();
  148. }
  149. /**
  150. * Retrieves the Swing Status Bar used by this UI.
  151. *
  152. * @return This UI's status bar
  153. */
  154. public SwingStatusBar getSwingStatusBar() {
  155. return statusBar;
  156. }
  157. /** {@inheritDoc} */
  158. @Override
  159. public ChannelWindow getChannel(final Channel channel) {
  160. return UIUtilities.invokeAndWait(new ReturnableThread<ChannelFrame>() {
  161. /** {@inheritDoc} */
  162. @Override
  163. public void run() {
  164. setObject(new ChannelFrame(channel, SwingController.this));
  165. }
  166. });
  167. }
  168. /** {@inheritDoc} */
  169. @Override
  170. public ServerWindow getServer(final Server server) {
  171. return UIUtilities.invokeAndWait(new ReturnableThread<ServerFrame>() {
  172. /** {@inheritDoc} */
  173. @Override
  174. public void run() {
  175. setObject(new ServerFrame(server, SwingController.this));
  176. }
  177. });
  178. }
  179. /** {@inheritDoc} */
  180. @Override
  181. public QueryWindow getQuery(final Query query) {
  182. return UIUtilities.invokeAndWait(new ReturnableThread<QueryFrame>() {
  183. /** {@inheritDoc} */
  184. @Override
  185. public void run() {
  186. setObject(new QueryFrame(query, SwingController.this));
  187. }
  188. });
  189. }
  190. /** {@inheritDoc} */
  191. @Override
  192. public Window getWindow(final FrameContainer owner) {
  193. return UIUtilities.invokeAndWait(new ReturnableThread<CustomFrame>() {
  194. /** {@inheritDoc} */
  195. @Override
  196. public void run() {
  197. setObject(new CustomFrame(owner, SwingController.this));
  198. }
  199. });
  200. }
  201. /** {@inheritDoc} */
  202. @Override
  203. public InputWindow getInputWindow(final WritableFrameContainer owner,
  204. final CommandParser commandParser) {
  205. LOGGER.finest("getInputWindow()");
  206. return UIUtilities.invokeAndWait(new ReturnableThread<CustomInputFrame>() {
  207. /** {@inheritDoc} */
  208. @Override
  209. public void run() {
  210. LOGGER.finest("getInputWindow(): run");
  211. setObject(new CustomInputFrame(owner, commandParser,
  212. SwingController.this));
  213. LOGGER.finest("getInputWindow(): object set: " + getObject());
  214. }
  215. });
  216. }
  217. /** {@inheritDoc} */
  218. @Override
  219. public SwingUpdaterDialog getUpdaterDialog(final List<Update> updates) {
  220. return UIUtilities.invokeAndWait(new ReturnableThread<SwingUpdaterDialog>() {
  221. /** {@inheritDoc} */
  222. @Override
  223. public void run() {
  224. setObject(SwingUpdaterDialog.getSwingUpdaterDialog(updates, me));
  225. }
  226. });
  227. }
  228. /** {@inheritDoc} */
  229. @Override
  230. public void showFirstRunWizard() {
  231. showFirstRunWizard(true);
  232. }
  233. /** {@inheritDoc} */
  234. @Override
  235. public void showMigrationWizard() {
  236. showFirstRunWizard(false);
  237. }
  238. /**
  239. * Shows a first run wizard, or a migration wizard.
  240. *
  241. * @param firstRun First run?
  242. */
  243. private synchronized void showFirstRunWizard(final boolean firstRun) {
  244. final Semaphore semaphore = new Semaphore(0);
  245. UIUtilities.invokeLater(new Runnable() {
  246. /** {@inheritDoc} */
  247. @Override
  248. public void run() {
  249. final WizardListener listener = new WizardListener() {
  250. /** {@inheritDoc} */
  251. @Override
  252. public void wizardFinished() {
  253. semaphore.release();
  254. }
  255. /** {@inheritDoc} */
  256. @Override
  257. public void wizardCancelled() {
  258. semaphore.release();
  259. }
  260. };
  261. final SwingFirstRunWizard wizard =
  262. new SwingFirstRunWizard(firstRun);
  263. wizard.getWizardDialog().addWizardListener(listener);
  264. wizard.display();
  265. }
  266. });
  267. semaphore.acquireUninterruptibly();
  268. }
  269. /** {@inheritDoc} */
  270. @Override
  271. public void showChannelSettingsDialog(final Channel channel) {
  272. UIUtilities.invokeLater(new Runnable() {
  273. /** {@inheritDoc} */
  274. @Override
  275. public void run() {
  276. ChannelSettingsDialog.showChannelSettingsDialog(channel, me);
  277. }
  278. });
  279. }
  280. /** {@inheritDoc} */
  281. @Override
  282. public void showServerSettingsDialog(final Server server) {
  283. UIUtilities.invokeLater(new Runnable() {
  284. /** {@inheritDoc} */
  285. @Override
  286. public void run() {
  287. ServerSettingsDialog.showServerSettingsDialog(server, me);
  288. }
  289. });
  290. }
  291. /**
  292. * Updates the look and feel to the current config setting.
  293. */
  294. void updateLookAndFeel() {
  295. try {
  296. UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
  297. getGlobalConfig().getOption("ui", "lookandfeel")));
  298. final int state = UIUtilities.invokeAndWait(new ReturnableThread<Integer>() {
  299. /** {@inheritDoc} */
  300. @Override
  301. public void run() {
  302. setObject(me.getExtendedState());
  303. }
  304. });
  305. UIUtilities.invokeLater(new Runnable() {
  306. /** {@inheritDoc} */
  307. @Override
  308. public void run() {
  309. SwingUtilities.updateComponentTreeUI(errorDialog);
  310. }
  311. });
  312. for (final java.awt.Window window : getTopLevelWindows()) {
  313. UIUtilities.invokeLater(new Runnable() {
  314. /** {@inheritDoc} */
  315. @Override
  316. public void run() {
  317. SwingUtilities.updateComponentTreeUI(window);
  318. if (window != me) {
  319. window.pack();
  320. }
  321. }
  322. });
  323. }
  324. UIUtilities.invokeLater(new Runnable() {
  325. /** {@inheritDoc} */
  326. @Override
  327. public void run() {
  328. me.setExtendedState(state);
  329. }
  330. });
  331. } catch (ClassNotFoundException ex) {
  332. Logger.userError(ErrorLevel.LOW,
  333. "Unable to change Look and Feel: " +
  334. ex.getMessage());
  335. } catch (InstantiationException ex) {
  336. Logger.userError(ErrorLevel.LOW,
  337. "Unable to change Look and Feel: " +
  338. ex.getMessage());
  339. } catch (IllegalAccessException ex) {
  340. Logger.userError(ErrorLevel.LOW,
  341. "Unable to change Look and Feel: " +
  342. ex.getMessage());
  343. } catch (UnsupportedLookAndFeelException ex) {
  344. Logger.userError(ErrorLevel.LOW,
  345. "Unable to change Look and Feel: " +
  346. ex.getMessage());
  347. }
  348. }
  349. /** {@inheritDoc} */
  350. @Override
  351. public void initUISettings() {
  352. // This will do nothing on non OS X Systems
  353. if (Apple.isApple()) {
  354. final Apple apple = Apple.getApple();
  355. apple.setUISettings();
  356. apple.setListener();
  357. }
  358. final Font defaultFont = new Font(Font.DIALOG, Font.TRUETYPE_FONT,
  359. 12);
  360. if (UIManager.getFont("TextField.font") == null) {
  361. UIManager.put("TextField.font", defaultFont);
  362. }
  363. if (UIManager.getFont("TextPane.font") == null) {
  364. UIManager.put("TextPane.font", defaultFont);
  365. }
  366. UIManager.put("Tree.collapsedIcon",
  367. IconManager.getIconManager().getIcon("nothing"));
  368. UIManager.put("Tree.expandedIcon",
  369. IconManager.getIconManager().getIcon("nothing"));
  370. try {
  371. UIUtilities.initUISettings();
  372. UIManager.setLookAndFeel(UIUtilities.getLookAndFeel(IdentityManager.
  373. getGlobalConfig().getOption("ui", "lookandfeel")));
  374. } catch (UnsupportedOperationException ex) {
  375. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  376. } catch (UnsupportedLookAndFeelException ex) {
  377. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  378. } catch (IllegalAccessException ex) {
  379. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  380. } catch (InstantiationException ex) {
  381. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  382. } catch (ClassNotFoundException ex) {
  383. Logger.userError(ErrorLevel.LOW, "Unable to set UI Settings");
  384. }
  385. if ("Metal".equals(UIManager.getLookAndFeel().getName())) {
  386. PlatformDefaults.setPlatform(PlatformDefaults.WINDOWS_XP);
  387. }
  388. }
  389. /** {@inheritDoc} */
  390. @Override
  391. @Deprecated
  392. public Window getActiveWindow() {
  393. return me.getActiveFrame();
  394. }
  395. /** {@inheritDoc} */
  396. @Override
  397. public Server getActiveServer() {
  398. if (!mainFrameCreated.get()) {
  399. return null;
  400. }
  401. if (getActiveWindow() == null) {
  402. return null;
  403. } else {
  404. return getActiveWindow().getContainer().getServer();
  405. }
  406. }
  407. /** {@inheritDoc} */
  408. @Override
  409. public void showURLDialog(final URI url) {
  410. UIUtilities.invokeLater(new Runnable() {
  411. /** {@inheritDoc} */
  412. @Override
  413. public void run() {
  414. URLDialog.showURLDialog(url, me);
  415. }
  416. });
  417. }
  418. /** {@inheritDoc} */
  419. @Override
  420. public void showSSLCertificateDialog(final SSLCertificateDialogModel model) {
  421. UIUtilities.invokeLater(new Runnable() {
  422. /** {@inheritDoc} */
  423. @Override
  424. public void run() {
  425. new SSLCertificateDialog(me, model).display();
  426. }
  427. });
  428. }
  429. /** {@inheritDoc} */
  430. @Override
  431. public void showFeedbackNag() {
  432. UIUtilities.invokeLater(new Runnable() {
  433. /** {@inheritDoc} */
  434. @Override
  435. public void run() {
  436. new FeedbackNag(SwingController.this);
  437. }
  438. });
  439. }
  440. /** {@inheritDoc} */
  441. @Override
  442. public void showMessageDialog(final String title, final String message) {
  443. UIUtilities.invokeLater(new Runnable() {
  444. /** {@inheritDoc} */
  445. @Override
  446. public void run() {
  447. JOptionPane.showMessageDialog(null, message, title,
  448. JOptionPane.PLAIN_MESSAGE);
  449. }
  450. });
  451. }
  452. /**
  453. * Shows the error dialog.
  454. */
  455. public void showErrorDialog() {
  456. errorDialog.display();
  457. }
  458. /** {@inheritDoc} */
  459. @Override
  460. public String getUserInput(final String prompt) {
  461. return JOptionPane.showInputDialog(prompt);
  462. }
  463. /** {@inheritDoc} */
  464. @Override
  465. public PreferencesInterface getPluginPrefsPanel() {
  466. return UIUtilities.invokeAndWait(new ReturnableThread<PluginPanel>() {
  467. /** {@inheritDoc} */
  468. @Override
  469. public void run() {
  470. setObject(new PluginPanel(me, SwingController.this));
  471. }
  472. });
  473. }
  474. /** {@inheritDoc} */
  475. @Override
  476. public PreferencesInterface getUpdatesPrefsPanel() {
  477. return UIUtilities.invokeAndWait(new ReturnableThread<PreferencesInterface>() {
  478. /** {@inheritDoc} */
  479. @Override
  480. public void run() {
  481. setObject(new UpdateConfigPanel(SwingController.this));
  482. }
  483. });
  484. }
  485. /** {@inheritDoc} */
  486. @Override
  487. public PreferencesInterface getUrlHandlersPrefsPanel() {
  488. return UIUtilities.invokeAndWait(new ReturnableThread<PreferencesInterface>() {
  489. /** {@inheritDoc} */
  490. @Override
  491. public void run() {
  492. setObject(new URLConfigPanel(me));
  493. }
  494. });
  495. }
  496. /** {@inheritDoc} */
  497. @Override
  498. public PreferencesInterface getThemesPrefsPanel() {
  499. return UIUtilities.invokeAndWait(new ReturnableThread<PreferencesInterface>() {
  500. /** {@inheritDoc} */
  501. @Override
  502. public void run() {
  503. setObject(new ThemePanel());
  504. }
  505. });
  506. }
  507. /**
  508. * Returns the current look and feel.
  509. *
  510. * @return Current look and feel
  511. */
  512. public static String getLookAndFeel() {
  513. return UIManager.getLookAndFeel().getName();
  514. }
  515. /** {@inheritDoc} */
  516. @Override
  517. public void onLoad() {
  518. if (GraphicsEnvironment.isHeadless()) {
  519. throw new IllegalStateException(
  520. "Swing UI can't be run in a headless environment");
  521. }
  522. Toolkit.getDefaultToolkit().getSystemEventQueue().
  523. push(new DMDircEventQueue(this));
  524. KeyboardFocusManager.getCurrentKeyboardFocusManager().
  525. addKeyEventDispatcher(new DialogKeyListener());
  526. UIUtilities.invokeAndWait(new Runnable() {
  527. /** {@inheritDoc} */
  528. @Override
  529. public void run() {
  530. initUISettings();
  531. me = new MainFrame(SwingController.this);
  532. mainFrameCreated.set(true);
  533. statusBar = me.getStatusBar();
  534. errorDialog = new ErrorListDialog(me);
  535. }
  536. });
  537. if (!mainFrameCreated.get()) {
  538. throw new IllegalStateException(
  539. "Main frame not created. Unable to continue.");
  540. }
  541. if (System.getProperty("java.vm.name", "unknown").contains("OpenJDK")) {
  542. JOptionPane.showMessageDialog(null, "OpenJDK has known graphical " +
  543. "issues and as such is unsupported by DMDirc. Please " +
  544. "consider using the official JRE.", "Unsupported JRE",
  545. JOptionPane.WARNING_MESSAGE);
  546. }
  547. Main.setUI(this);
  548. }
  549. /** {@inheritDoc} */
  550. @Override
  551. public void onUnload() {
  552. // Do nothing
  553. }
  554. /** {@inheritDoc} */
  555. @Override
  556. public void domainUpdated() {
  557. final Identity defaults = IdentityManager.getAddonIdentity();
  558. defaults.setOption("ui", "textPaneFontName",
  559. UIManager.getFont("TextPane.font").getFamily());
  560. defaults.setOption("ui", "textPaneFontSize",
  561. UIManager.getFont("TextPane.font").getSize());
  562. }
  563. /**
  564. * Returns the preferences dialog instance creating if required.
  565. *
  566. * @return Swing prefs dialog
  567. */
  568. public SwingPreferencesDialog getPrefsDialog() {
  569. return SwingPreferencesDialog.getSwingPreferencesDialog(me);
  570. }
  571. /** {@inheritDoc} */
  572. @Override
  573. public void showConfig(final PreferencesManager manager) {
  574. manager.getCategory("GUI").addSubCategory(createGeneralCategory());
  575. }
  576. /**
  577. * Creates the "Advanced" category.
  578. */
  579. private PreferencesCategory createGeneralCategory() {
  580. final PreferencesCategory general = new PreferencesCategory("Swing UI",
  581. "These config options apply only to the swing UI.",
  582. "category-gui");
  583. final Map<String, String> lafs = new HashMap<String, String>();
  584. final Map<String, String> framemanagers = new HashMap<String, String>();
  585. final Map<String, String> fmpositions = new HashMap<String, String>();
  586. framemanagers.put(
  587. "com.dmdirc.addons.ui_swing.framemanager.tree.TreeFrameManager",
  588. "Treeview");
  589. framemanagers.put(
  590. "com.dmdirc.addons.ui_swing.framemanager.buttonbar.ButtonBar",
  591. "Button bar");
  592. fmpositions.put("top", "Top");
  593. fmpositions.put("bottom", "Bottom");
  594. fmpositions.put("left", "Left");
  595. fmpositions.put("right", "Right");
  596. final LookAndFeelInfo[] plaf = UIManager.getInstalledLookAndFeels();
  597. lafs.put("Native", "Native");
  598. for (LookAndFeelInfo laf : plaf) {
  599. lafs.put(laf.getName(), laf.getName());
  600. }
  601. general.addSetting(new PreferencesSetting("ui", "lookandfeel",
  602. "Look and feel", "The Java look and feel to use", lafs));
  603. general.addSetting(new PreferencesSetting("ui", "framemanager",
  604. "Window manager", "Which window manager should be used?",
  605. framemanagers).setRestartNeeded());
  606. general.addSetting(new PreferencesSetting("ui", "framemanagerPosition",
  607. "Window manager position", "Where should the window " +
  608. "manager be positioned?", fmpositions).setRestartNeeded());
  609. general.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  610. "ui", "stylelinks", "Style links", "Style links in text areas"));
  611. general.addSetting(new PreferencesSetting(PreferencesType.FONT,
  612. "ui", "textPaneFontName", "Textpane font",
  613. "Font for the textpane"));
  614. general.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  615. "ui", "textPaneFontSize", "Textpane font size",
  616. "Font size for the textpane"));
  617. general.addSubCategory(createNicklistCategory());
  618. general.addSubCategory(createTreeViewCategory());
  619. general.addSubCategory(createAdvancedCategory());
  620. return general;
  621. }
  622. /**
  623. * Creates the "Advanced" category.
  624. */
  625. private PreferencesCategory createAdvancedCategory() {
  626. final PreferencesCategory advanced = new PreferencesCategory("Advanced",
  627. "");
  628. final Map<String, String> options = new HashMap<String, String>();
  629. options.put("alwaysShow", "Always show");
  630. options.put("neverShow", "Never show");
  631. options.put("showWhenMaximised", "Show only when windows maximised");
  632. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER,
  633. new NumericalValidator(10, -1), "ui", "frameBufferSize",
  634. "Window buffer size", "The maximum number of lines in a window" +
  635. " buffer"));
  636. advanced.addSetting(new PreferencesSetting("ui", "mdiBarVisibility",
  637. "MDI Bar Visibility", "Controls the visibility of the MDI bar",
  638. options));
  639. advanced.addSetting(
  640. new PreferencesSetting(PreferencesType.BOOLEAN, "ui",
  641. "useOneTouchExpandable", "Use one touch expandable split panes?",
  642. "Use one touch expandable arrows for collapsing/expanding the split panes"));
  643. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER, getDomain(),
  644. "windowMenuItems", "Window menu item count",
  645. "Number of items to show in the window menu"));
  646. advanced.addSetting(new PreferencesSetting(PreferencesType.INTEGER, getDomain(),
  647. "windowMenuScrollInterval", "Window menu scroll interval",
  648. "Number of milliseconds to pause when autoscrolling in the window menu"));
  649. advanced.addSetting(
  650. new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(),
  651. "showtopicbar", "Show topic bar",
  652. "Shows a graphical topic bar in channels."));
  653. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(),
  654. "shownicklist", "Show nicklist?", "Do you want the nicklist visible"));
  655. //TODO issue 3251
  656. //advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN, getDomain(),
  657. // "showfulltopic", "Show full topic in topic bar?",
  658. // "Do you want to show the full topic in the topic bar or just" +
  659. // "first line?"));
  660. advanced.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  661. getDomain(), "hideEmptyTopicBar", "Hide empty topic bar?",
  662. "Do you want to hide the topic bar when there is no topic"));
  663. return advanced;
  664. }
  665. /**
  666. * Creates the "Treeview" category.
  667. */
  668. private PreferencesCategory createTreeViewCategory() {
  669. final PreferencesCategory treeview = new PreferencesCategory("Treeview",
  670. "", "treeview");
  671. treeview.addSetting(new PreferencesSetting(
  672. PreferencesType.OPTIONALCOLOUR,
  673. "treeview", "backgroundcolour", "Treeview background colour",
  674. "Background colour to use for the treeview"));
  675. treeview.addSetting(new PreferencesSetting(
  676. PreferencesType.OPTIONALCOLOUR,
  677. "treeview", "foregroundcolour", "Treeview foreground colour",
  678. "Foreground colour to use for the treeview"));
  679. treeview.addSetting(new PreferencesSetting(
  680. PreferencesType.OPTIONALCOLOUR,
  681. "ui", "treeviewRolloverColour", "Treeview rollover colour",
  682. "Background colour to use when the mouse cursor is over a node"));
  683. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  684. "treeview", "sortwindows", "Sort windows",
  685. "Sort windows belonging to servers in the treeview?"));
  686. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  687. "treeview", "sortservers", "Sort servers",
  688. "Sort servers in the treeview?"));
  689. treeview.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  690. "ui", "treeviewActiveBold", "Active node bold",
  691. "Make the active node bold?"));
  692. treeview.addSetting(new PreferencesSetting(
  693. PreferencesType.OPTIONALCOLOUR,
  694. "ui", "treeviewActiveBackground", "Active node background",
  695. "Background colour to use for active treeview node"));
  696. treeview.addSetting(new PreferencesSetting(
  697. PreferencesType.OPTIONALCOLOUR,
  698. "ui", "treeviewActiveForeground", "Active node foreground",
  699. "Foreground colour to use for active treeview node"));
  700. return treeview;
  701. }
  702. /**
  703. * Creates the "Nicklist" category.
  704. */
  705. private PreferencesCategory createNicklistCategory() {
  706. final PreferencesCategory nicklist = new PreferencesCategory("Nicklist",
  707. "", "nicklist");
  708. nicklist.addSetting(new PreferencesSetting(
  709. PreferencesType.OPTIONALCOLOUR,
  710. "ui", "nicklistbackgroundcolour", "Nicklist background colour",
  711. "Background colour to use for the nicklist"));
  712. nicklist.addSetting(new PreferencesSetting(
  713. PreferencesType.OPTIONALCOLOUR,
  714. "ui", "nicklistforegroundcolour", "Nicklist foreground colour",
  715. "Foreground colour to use for the nicklist"));
  716. nicklist.addSetting(new PreferencesSetting(
  717. PreferencesType.OPTIONALCOLOUR,
  718. "ui", "nickListAltBackgroundColour",
  719. "Alternate background colour",
  720. "Background colour to use for every other nicklist entry"));
  721. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  722. "nicklist", "sortByMode", "Sort nicklist by user mode",
  723. "Sort nicknames by the modes that they have?"));
  724. nicklist.addSetting(new PreferencesSetting(PreferencesType.BOOLEAN,
  725. "nicklist", "sortByCase", "Sort nicklist by case",
  726. "Sort nicknames in a case-sensitive manner?"));
  727. return nicklist;
  728. }
  729. /**
  730. * Adds a top level window to the window list.
  731. *
  732. * @param source New window
  733. */
  734. protected void addTopLevelWindow(final java.awt.Window source) {
  735. synchronized (windows) {
  736. windows.add(source);
  737. }
  738. }
  739. /**
  740. * Deletes a top level window to the window list.
  741. *
  742. * @param source Old window
  743. */
  744. protected void delTopLevelWindow(final java.awt.Window source) {
  745. synchronized (windows) {
  746. windows.remove(source);
  747. }
  748. }
  749. /**
  750. * Returns a list of top level windows.
  751. *
  752. * @return Top level window list
  753. */
  754. public List<java.awt.Window> getTopLevelWindows() {
  755. synchronized (windows) {
  756. return windows;
  757. }
  758. }
  759. }