Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

Frame.java 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678
  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.swing.components;
  23. import com.dmdirc.util.BrowserLauncher;
  24. import com.dmdirc.FrameContainer;
  25. import com.dmdirc.Main;
  26. import com.dmdirc.util.StringTranscoder;
  27. import com.dmdirc.commandparser.ChannelCommand;
  28. import com.dmdirc.commandparser.Command;
  29. import com.dmdirc.commandparser.CommandManager;
  30. import com.dmdirc.commandparser.ServerCommand;
  31. import com.dmdirc.config.ConfigChangeListener;
  32. import com.dmdirc.config.ConfigManager;
  33. import com.dmdirc.logger.ErrorLevel;
  34. import com.dmdirc.logger.Logger;
  35. import com.dmdirc.ui.interfaces.Window;
  36. import com.dmdirc.ui.messages.Formatter;
  37. import com.dmdirc.ui.messages.IRCTextAttribute;
  38. import com.dmdirc.ui.swing.MainFrame;
  39. import com.dmdirc.ui.swing.actions.SearchAction;
  40. import com.dmdirc.ui.swing.textpane.TextPane;
  41. import com.dmdirc.ui.swing.textpane.TextPaneListener;
  42. import java.awt.Color;
  43. import java.awt.Dimension;
  44. import java.awt.Point;
  45. import java.awt.Toolkit;
  46. import java.awt.datatransfer.StringSelection;
  47. import java.awt.event.ActionEvent;
  48. import java.awt.event.ActionListener;
  49. import java.awt.event.InputEvent;
  50. import java.awt.event.KeyEvent;
  51. import java.awt.event.KeyListener;
  52. import java.awt.event.MouseEvent;
  53. import java.awt.event.MouseListener;
  54. import java.beans.PropertyChangeEvent;
  55. import java.beans.PropertyChangeListener;
  56. import java.beans.PropertyVetoException;
  57. import java.lang.reflect.Constructor;
  58. import java.lang.reflect.InvocationTargetException;
  59. import java.nio.charset.Charset;
  60. import java.nio.charset.IllegalCharsetNameException;
  61. import java.nio.charset.UnsupportedCharsetException;
  62. import java.text.AttributedCharacterIterator;
  63. import java.util.ArrayList;
  64. import java.util.Date;
  65. import java.util.HashMap;
  66. import java.util.List;
  67. import java.util.Locale;
  68. import java.util.Map;
  69. import javax.swing.BorderFactory;
  70. import javax.swing.JComponent;
  71. import javax.swing.JInternalFrame;
  72. import javax.swing.JMenuItem;
  73. import javax.swing.JPopupMenu;
  74. import javax.swing.KeyStroke;
  75. import javax.swing.SwingUtilities;
  76. import javax.swing.UIManager;
  77. import javax.swing.WindowConstants;
  78. import javax.swing.event.InternalFrameEvent;
  79. import javax.swing.event.InternalFrameListener;
  80. import javax.swing.plaf.basic.BasicInternalFrameUI;
  81. import javax.swing.plaf.synth.SynthLookAndFeel;
  82. /**
  83. * Implements a generic (internal) frame.
  84. */
  85. public abstract class Frame extends JInternalFrame implements Window,
  86. PropertyChangeListener, InternalFrameListener,
  87. MouseListener, ActionListener, KeyListener, TextPaneListener,
  88. ConfigChangeListener {
  89. /**
  90. * A version number for this class. It should be changed whenever the class
  91. * structure is changed (or anything else that would prevent serialized
  92. * objects being unserialized with the new class).
  93. */
  94. private static final long serialVersionUID = 5;
  95. /** The channel object that owns this frame. */
  96. private final FrameContainer parent;
  97. /** Frame output pane. */
  98. private TextPane textPane;
  99. /** Popupmenu for this frame. */
  100. private JPopupMenu popup;
  101. /** popup menu item. */
  102. private JMenuItem copyMI;
  103. /** hyperlink menu item. */
  104. private JMenuItem hyperlinkCopyMI;
  105. /** hyperlink menu item. */
  106. private JMenuItem hyperlinkOpenMI;
  107. /** search bar. */
  108. private SearchBar searchBar;
  109. /** String transcoder. */
  110. private StringTranscoder transcoder;
  111. /** Command map. */
  112. protected final Map<String, Command> commands;
  113. /** nicklist popup menu. */
  114. protected JPopupMenu nicklistPopup;
  115. /** Frame buffer size. */
  116. private int frameBufferSize;
  117. /**
  118. * Creates a new instance of Frame.
  119. *
  120. * @param owner FrameContainer owning this frame.
  121. */
  122. public Frame(final FrameContainer owner) {
  123. super();
  124. final ConfigManager config = owner.getConfigManager();
  125. final Boolean pref = config.getOptionBool("ui", "maximisewindows");
  126. frameBufferSize = config.getOptionInt("ui", "frameBufferSize",
  127. Integer.MAX_VALUE);
  128. parent = owner;
  129. commands = new HashMap<String, Command>();
  130. setFrameIcon(Main.getUI().getMainWindow().getIcon());
  131. try {
  132. transcoder = new StringTranscoder(Charset.forName(
  133. config.getOption("channel", "encoding", "UTF-8")));
  134. } catch (UnsupportedCharsetException ex) {
  135. transcoder = new StringTranscoder(Charset.forName("UTF-8"));
  136. } catch (IllegalCharsetNameException ex) {
  137. transcoder = new StringTranscoder(Charset.forName("UTF-8"));
  138. } catch (IllegalArgumentException ex) {
  139. transcoder = new StringTranscoder(Charset.forName("UTF-8"));
  140. }
  141. initComponents();
  142. setMaximizable(true);
  143. setClosable(true);
  144. setResizable(true);
  145. setIconifiable(true);
  146. setPreferredSize(new Dimension(((MainFrame) Main.getUI().getMainWindow()).getWidth() / 2,
  147. ((MainFrame) Main.getUI().getMainWindow()).getHeight() / 3));
  148. setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
  149. addPropertyChangeListener("maximum", this);
  150. addPropertyChangeListener("UI", this);
  151. addInternalFrameListener(this);
  152. getTextPane().setBackground(config.getOptionColour("ui", "backgroundcolour", Color.WHITE));
  153. getTextPane().setForeground(config.getOptionColour("ui", "foregroundcolour", Color.BLACK));
  154. config.addChangeListener("ui", "foregroundcolour", this);
  155. config.addChangeListener("ui", "backgroundcolour", this);
  156. if (pref || Main.getUI().getMainWindow().getMaximised()) {
  157. hideTitlebar();
  158. }
  159. Main.getUI().getMainWindow().addChild(this);
  160. }
  161. /** {@inheritDoc} */
  162. public void open() {
  163. setVisible(true);
  164. }
  165. /** {@inheritDoc} */
  166. public final void addLine(final String line, final boolean timestamp) {
  167. final String encodedLine = transcoder.decode(line);
  168. SwingUtilities.invokeLater(new Runnable() {
  169. public void run() {
  170. for (String myLine : encodedLine.split("\n")) {
  171. if (timestamp) {
  172. getTextPane().addStyledString(new String[]{
  173. Formatter.formatMessage("timestamp", new Date()),
  174. myLine, });
  175. } else {
  176. getTextPane().addStyledString(myLine);
  177. }
  178. if (frameBufferSize > 0) {
  179. textPane.trim(frameBufferSize);
  180. }
  181. }
  182. }
  183. });
  184. }
  185. /** {@inheritDoc} */
  186. public final void addLine(final String messageType, final Object... args) {
  187. if (!messageType.isEmpty()) {
  188. addLine(Formatter.formatMessage(messageType, args), true);
  189. }
  190. }
  191. /** {@inheritDoc} */
  192. public final void addLine(final StringBuffer messageType, final Object... args) {
  193. if (messageType != null) {
  194. addLine(messageType.toString(), args);
  195. }
  196. }
  197. /** {@inheritDoc} */
  198. public final void clear() {
  199. getTextPane().clear();
  200. }
  201. /**
  202. * Initialises the components for this frame.
  203. */
  204. private void initComponents() {
  205. setTextPane(new TextPane());
  206. getTextPane().addMouseListener(this);
  207. getTextPane().addKeyListener(this);
  208. getTextPane().addTextPaneListener(this);
  209. popup = new JPopupMenu();
  210. copyMI = new JMenuItem("Copy");
  211. copyMI.addActionListener(this);
  212. hyperlinkCopyMI = new JMenuItem("Copy URL");
  213. hyperlinkCopyMI.addActionListener(this);
  214. hyperlinkCopyMI.setVisible(false);
  215. hyperlinkOpenMI = new JMenuItem("Open URL");
  216. hyperlinkOpenMI.addActionListener(this);
  217. hyperlinkOpenMI.setVisible(false);
  218. popup.add(hyperlinkOpenMI);
  219. popup.add(hyperlinkCopyMI);
  220. popup.add(copyMI);
  221. popup.setOpaque(true);
  222. popup.setLightWeightPopupEnabled(true);
  223. nicklistPopup = new JPopupMenu();
  224. popuplateNicklistPopup();
  225. searchBar = new SearchBar(this);
  226. searchBar.setVisible(false);
  227. getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
  228. put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), "searchAction");
  229. getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).
  230. put(KeyStroke.getKeyStroke(KeyEvent.VK_F,
  231. InputEvent.CTRL_DOWN_MASK), "searchAction");
  232. getActionMap().put("searchAction", new SearchAction(searchBar));
  233. }
  234. /**
  235. * Removes and reinserts the border of an internal frame on maximising.
  236. * {@inheritDoc}
  237. */
  238. public final void propertyChange(final PropertyChangeEvent event) {
  239. if ("maximum".equals(event.getPropertyName())) {
  240. if (event.getNewValue().equals(Boolean.TRUE)) {
  241. hideTitlebar();
  242. Main.getUI().getMainWindow().setMaximised(true);
  243. } else {
  244. showTitlebar();
  245. Main.getUI().getMainWindow().setMaximised(false);
  246. Main.getUI().getMainWindow().setActiveFrame(this);
  247. }
  248. } else if ("UI".equals(event.getPropertyName()) && isMaximum()) {
  249. hideTitlebar();
  250. }
  251. }
  252. /** Hides the titlebar for this frame. */
  253. private void hideTitlebar() {
  254. setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
  255. ((BasicInternalFrameUI) getUI()).setNorthPane(null);
  256. }
  257. /** Shows the titlebar for this frame. */
  258. private void showTitlebar() {
  259. final Class< ? > c;
  260. Object temp = null;
  261. Constructor< ? > constructor;
  262. final String componentUI = (String) UIManager.get("InternalFrameUI");
  263. if ("javax.swing.plaf.synth.SynthLookAndFeel".equals(componentUI)) {
  264. temp = SynthLookAndFeel.createUI(this);
  265. } else {
  266. try {
  267. c = getClass().getClassLoader().loadClass(componentUI);
  268. constructor = c.getConstructor(new Class[] {javax.swing.JInternalFrame.class});
  269. temp = constructor.newInstance(new Object[] {this});
  270. } catch (ClassNotFoundException ex) {
  271. Logger.appError(ErrorLevel.MEDIUM, "Unable to readd titlebar", ex);
  272. } catch (NoSuchMethodException ex) {
  273. Logger.appError(ErrorLevel.MEDIUM, "Unable to readd titlebar", ex);
  274. } catch (InstantiationException ex) {
  275. Logger.appError(ErrorLevel.MEDIUM, "Unable to readd titlebar", ex);
  276. } catch (IllegalAccessException ex) {
  277. Logger.appError(ErrorLevel.MEDIUM, "Unable to readd titlebar", ex);
  278. } catch (InvocationTargetException ex) {
  279. Logger.appError(ErrorLevel.MEDIUM, "Unable to readd titlebar", ex);
  280. }
  281. }
  282. setBorder(UIManager.getBorder("InternalFrame.border"));
  283. if (temp == null) {
  284. temp = new BasicInternalFrameUI(this);
  285. }
  286. this.setUI((BasicInternalFrameUI) temp);
  287. }
  288. /**
  289. * Not needed for this class. {@inheritDoc}
  290. */
  291. public void internalFrameOpened(final InternalFrameEvent event) {
  292. parent.windowOpened();
  293. }
  294. /**
  295. * Not needed for this class. {@inheritDoc}
  296. */
  297. public void internalFrameClosing(final InternalFrameEvent event) {
  298. parent.windowClosing();
  299. }
  300. /**
  301. * Not needed for this class. {@inheritDoc}
  302. */
  303. public void internalFrameClosed(final InternalFrameEvent event) {
  304. parent.windowClosed();
  305. }
  306. /**
  307. * Makes the internal frame invisible. {@inheritDoc}
  308. */
  309. public void internalFrameIconified(final InternalFrameEvent event) {
  310. event.getInternalFrame().setVisible(false);
  311. }
  312. /**
  313. * Not needed for this class. {@inheritDoc}
  314. */
  315. public void internalFrameDeiconified(final InternalFrameEvent event) {
  316. //Ignore.
  317. }
  318. /**
  319. * Activates the input field on frame focus. {@inheritDoc}
  320. */
  321. public void internalFrameActivated(final InternalFrameEvent event) {
  322. parent.windowActivated();
  323. }
  324. /**
  325. * Not needed for this class. {@inheritDoc}
  326. */
  327. public void internalFrameDeactivated(final InternalFrameEvent event) {
  328. parent.windowDeactivated();
  329. }
  330. /** {@inheritDoc} */
  331. public FrameContainer getContainer() {
  332. return parent;
  333. }
  334. /** {@inheritDoc} */
  335. public ConfigManager getConfigManager() {
  336. return getContainer().getConfigManager();
  337. }
  338. /**
  339. * Returns the text pane for this frame.
  340. *
  341. * @return Text pane for this frame
  342. */
  343. public final TextPane getTextPane() {
  344. return textPane;
  345. }
  346. /**
  347. * Returns the transcoder for this frame.
  348. *
  349. * @return String transcoder for this frame
  350. */
  351. public StringTranscoder getTranscoder() {
  352. return transcoder;
  353. }
  354. /** {@inheritDoc} */
  355. @Override
  356. public final String getName() {
  357. if (parent == null) {
  358. return "";
  359. }
  360. return parent.toString();
  361. }
  362. /**
  363. * Sets the frames text pane.
  364. *
  365. * @param newTextPane new text pane to use
  366. */
  367. protected final void setTextPane(final TextPane newTextPane) {
  368. this.textPane = newTextPane;
  369. }
  370. /**
  371. * Checks for url's, channels and nicknames. {@inheritDoc}
  372. */
  373. public void mouseClicked(final MouseEvent mouseEvent) {
  374. if (mouseEvent.getSource() == getTextPane()) {
  375. processMouseEvent(mouseEvent);
  376. }
  377. }
  378. /**
  379. * Not needed for this class. {@inheritDoc}
  380. */
  381. public void mousePressed(final MouseEvent mouseEvent) {
  382. processMouseEvent(mouseEvent);
  383. }
  384. /**
  385. * Not needed for this class. {@inheritDoc}
  386. */
  387. public void mouseReleased(final MouseEvent mouseEvent) {
  388. if (getConfigManager().getOptionBool("ui", "quickCopy")
  389. && mouseEvent.getSource() == getTextPane()) {
  390. getTextPane().copy();
  391. getTextPane().clearSelection();
  392. }
  393. processMouseEvent(mouseEvent);
  394. }
  395. /**
  396. * Not needed for this class. {@inheritDoc}
  397. */
  398. public void mouseEntered(final MouseEvent mouseEvent) {
  399. //Ignore.
  400. }
  401. /**
  402. * Not needed for this class. {@inheritDoc}
  403. */
  404. public void mouseExited(final MouseEvent mouseEvent) {
  405. //Ignore.
  406. }
  407. /**
  408. * Processes every mouse button event to check for a popup trigger.
  409. *
  410. * @param e mouse event
  411. */
  412. @Override
  413. public void processMouseEvent(final MouseEvent e) {
  414. if (e.isPopupTrigger() && e.getSource() == getTextPane()) {
  415. final Point point = getTextPane().getMousePosition();
  416. if (point != null) {
  417. hyperlinkOpenMI.setActionCommand("");
  418. hyperlinkOpenMI.setVisible(false);
  419. hyperlinkCopyMI.setVisible(false);
  420. final int[] info = textPane.getClickPosition(point);
  421. if (info[0] != -1) {
  422. final AttributedCharacterIterator iterator = textPane.getLine(info[0]).getIterator();
  423. iterator.setIndex(info[2]);
  424. final Object linkattr = iterator.getAttributes().get(IRCTextAttribute.HYPERLINK);
  425. if (linkattr instanceof String) {
  426. hyperlinkCopyMI.setVisible(true);
  427. hyperlinkOpenMI.setVisible(true);
  428. hyperlinkOpenMI.setActionCommand((String) linkattr);
  429. }
  430. }
  431. final int[] selection = textPane.getSelectedRange();
  432. if ((selection[0] == selection[2] && selection[1] == selection[3])) {
  433. copyMI.setEnabled(false);
  434. } else {
  435. copyMI.setEnabled(true);
  436. }
  437. getPopup().show(this, (int) point.getX(), (int) point.getY());
  438. }
  439. }
  440. super.processMouseEvent(e);
  441. }
  442. /** {@inheritDoc} */
  443. public void actionPerformed(final ActionEvent actionEvent) {
  444. if (actionEvent.getSource() == copyMI) {
  445. getTextPane().copy();
  446. } else if (actionEvent.getSource() == hyperlinkCopyMI) {
  447. Toolkit.getDefaultToolkit().getSystemClipboard().setContents(
  448. new StringSelection(hyperlinkOpenMI.getActionCommand()), null);
  449. } else if (actionEvent.getSource() == hyperlinkOpenMI) {
  450. BrowserLauncher.openURL(hyperlinkOpenMI.getActionCommand());
  451. }
  452. }
  453. /**
  454. * returns the popup menu for this frame.
  455. *
  456. * @return JPopupMenu for this frame
  457. */
  458. public final JPopupMenu getPopup() {
  459. return popup;
  460. }
  461. /** {@inheritDoc} */
  462. public void keyTyped(final KeyEvent event) {
  463. //Ignore.
  464. }
  465. /** {@inheritDoc} */
  466. public void keyPressed(final KeyEvent event) {
  467. if ((event.getModifiers() & KeyEvent.CTRL_MASK) == 0) {
  468. if (event.getKeyCode() == KeyEvent.VK_PAGE_UP) {
  469. getTextPane().pageUp();
  470. } else if (event.getKeyCode() == KeyEvent.VK_PAGE_DOWN) {
  471. getTextPane().pageDown();
  472. }
  473. } else {
  474. if (event.getKeyCode() == KeyEvent.VK_HOME) {
  475. getTextPane().setScrollBarPosition(0);
  476. } else if (event.getKeyCode() == KeyEvent.VK_END) {
  477. getTextPane().setScrollBarPosition(textPane.getNumLines());
  478. }
  479. }
  480. if (!getConfigManager().getOptionBool("ui", "quickCopy")
  481. && (event.getModifiers() & KeyEvent.CTRL_MASK) != 0
  482. && event.getKeyCode() == KeyEvent.VK_C) {
  483. getTextPane().copy();
  484. }
  485. }
  486. /** {@inheritDoc} */
  487. public void keyReleased(final KeyEvent event) {
  488. //Ignore.
  489. }
  490. /** {@inheritDoc} */
  491. public void hyperlinkClicked(final String url, final MouseEvent e) {
  492. if (e.isPopupTrigger()) {
  493. //Show hyperlink popup
  494. } else {
  495. Main.getUI().getStatusBar().setMessage("Opening: " + url);
  496. BrowserLauncher.openURL(url);
  497. }
  498. }
  499. /** {@inheritDoc} */
  500. public void channelClicked(final String channel, final MouseEvent e) {
  501. if (e.isPopupTrigger()) {
  502. //Show channel popup
  503. } else {
  504. if (parent.getServer().getParser().getChannelInfo(channel) == null) {
  505. parent.getServer().getParser().joinChannel(channel);
  506. } else {
  507. parent.getServer().getChannel(channel).activateFrame();
  508. }
  509. }
  510. }
  511. /** {@inheritDoc} */
  512. public void nickNameClicked(final String nickname, final MouseEvent e) {
  513. if (e.isPopupTrigger()) {
  514. final Point point = getMousePosition();
  515. popuplateNicklistPopup();
  516. nicklistPopup.show(this, (int) point.getX(), (int) point.getY());
  517. }
  518. }
  519. /**
  520. * Gets the search bar.
  521. *
  522. * @return the frames search bar
  523. */
  524. public final SearchBar getSearchBar() {
  525. return searchBar;
  526. }
  527. /** Closes this frame. */
  528. public void close() {
  529. try {
  530. setClosed(true);
  531. } catch (PropertyVetoException ex) {
  532. Logger.userError(ErrorLevel.LOW, "Unable to close frame");
  533. }
  534. }
  535. /** Minimises the frame. */
  536. public void minimise() {
  537. try {
  538. setIcon(true);
  539. } catch (PropertyVetoException ex) {
  540. Logger.userError(ErrorLevel.LOW, "Unable to minimise frame");
  541. }
  542. }
  543. /** Popuplates the nicklist popup. */
  544. protected final void popuplateNicklistPopup() {
  545. nicklistPopup.removeAll();
  546. commands.clear();
  547. final List<Command> commandList = CommandManager.getNicklistCommands();
  548. final List<Command> serverCommands = new ArrayList<Command>();
  549. final List<Command> channelCommands = new ArrayList<Command>();
  550. for (Command command : commandList) {
  551. if (command instanceof ServerCommand) {
  552. serverCommands.add(command);
  553. } else if (command instanceof ChannelCommand) {
  554. channelCommands.add(command);
  555. }
  556. }
  557. for (Command command : serverCommands) {
  558. commands.put(command.getName(), command);
  559. final JMenuItem mi = new JMenuItem(command.getName().substring(0, 1).
  560. toUpperCase(Locale.getDefault()) + command.getName().substring(1));
  561. mi.setActionCommand(command.getName());
  562. mi.addActionListener(this);
  563. nicklistPopup.add(mi);
  564. }
  565. nicklistPopup.addSeparator();
  566. for (Command command : channelCommands) {
  567. commands.put(command.getName(), command);
  568. final JMenuItem mi = new JMenuItem(command.getName().substring(0, 1).
  569. toUpperCase(Locale.getDefault()) + command.getName().substring(1));
  570. mi.setActionCommand(command.getName());
  571. mi.addActionListener(this);
  572. nicklistPopup.add(mi);
  573. }
  574. }
  575. /** {@inheritDoc} */
  576. public void configChanged(final String domain, final String key,
  577. final String oldValue, final String newValue) {
  578. if (getConfigManager() == null) {
  579. return;
  580. }
  581. if ("ui".equals(domain)) {
  582. if ("foregroundcolour".equals(key)) {
  583. getTextPane().setForeground(getConfigManager().
  584. getOptionColour("ui", "foregroundcolour", Color.BLACK));
  585. } else if ("backgroundcolour".equals(key)) {
  586. getTextPane().setBackground(getConfigManager().
  587. getOptionColour("ui", "backgroundcolour", Color.WHITE));
  588. } else if ("frameBufferSize".equals(key)) {
  589. frameBufferSize = getContainer().getConfigManager().
  590. getOptionInt("ui", "frameBufferSize", Integer.MAX_VALUE);
  591. }
  592. }
  593. }
  594. }