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

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