Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

TopicBar.java 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671
  1. /*
  2. *
  3. * Copyright (c) 2006-2010 Chris Smith, Shane Mc Cormack, Gregory Holmes
  4. *
  5. * Permission is hereby granted, free of charge, to any person obtaining a copy
  6. * of this software and associated documentation files (the "Software"), to deal
  7. * in the Software without restriction, including without limitation the rights
  8. * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  9. * copies of the Software, and to permit persons to whom the Software is
  10. * furnished to do so, subject to the following conditions:
  11. *
  12. * The above copyright notice and this permission notice shall be included in
  13. * all copies or substantial portions of the Software.
  14. *
  15. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  16. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  17. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  18. * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  19. * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  20. * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  21. * SOFTWARE.
  22. */
  23. package com.dmdirc.addons.ui_swing.components;
  24. import com.dmdirc.Channel;
  25. import com.dmdirc.addons.ui_swing.SwingController;
  26. import com.dmdirc.addons.ui_swing.UIUtilities;
  27. import com.dmdirc.addons.ui_swing.actions.NoNewlinesPasteAction;
  28. import com.dmdirc.addons.ui_swing.components.frames.ChannelFrame;
  29. import com.dmdirc.config.IdentityManager;
  30. import com.dmdirc.interfaces.ConfigChangeListener;
  31. import com.dmdirc.parser.interfaces.ChannelInfo;
  32. import com.dmdirc.parser.interfaces.Parser;
  33. import com.dmdirc.parser.interfaces.callbacks.ChannelTopicListener;
  34. import com.dmdirc.ui.IconManager;
  35. import com.dmdirc.ui.messages.ColourManager;
  36. import com.dmdirc.ui.messages.Styliser;
  37. import com.dmdirc.util.URLHandler;
  38. import java.awt.Color;
  39. import java.awt.event.ActionEvent;
  40. import java.awt.event.ActionListener;
  41. import java.awt.event.MouseEvent;
  42. import java.awt.event.MouseListener;
  43. import javax.swing.AbstractAction;
  44. import javax.swing.JButton;
  45. import javax.swing.JComponent;
  46. import javax.swing.JLabel;
  47. import javax.swing.JScrollPane;
  48. import javax.swing.KeyStroke;
  49. import javax.swing.SwingUtilities;
  50. import javax.swing.event.DocumentEvent;
  51. import javax.swing.event.DocumentListener;
  52. import javax.swing.event.HyperlinkEvent;
  53. import javax.swing.event.HyperlinkListener;
  54. import javax.swing.text.AbstractDocument;
  55. import javax.swing.text.BadLocationException;
  56. import javax.swing.text.BoxView;
  57. import javax.swing.text.ComponentView;
  58. import javax.swing.text.DefaultStyledDocument;
  59. import javax.swing.text.Element;
  60. import javax.swing.text.GlyphView;
  61. import javax.swing.text.IconView;
  62. import javax.swing.text.LabelView;
  63. import javax.swing.text.ParagraphView;
  64. import javax.swing.text.SimpleAttributeSet;
  65. import javax.swing.text.StyleConstants;
  66. import javax.swing.text.StyledDocument;
  67. import javax.swing.text.StyledEditorKit;
  68. import javax.swing.text.View;
  69. import javax.swing.text.ViewFactory;
  70. import net.miginfocom.swing.MigLayout;
  71. /**
  72. * Component to show and edit topics for a channel.
  73. */
  74. public class TopicBar extends JComponent implements ActionListener,
  75. ConfigChangeListener, ChannelTopicListener, HyperlinkListener,
  76. MouseListener, DocumentListener {
  77. /**
  78. * A version number for this class. It should be changed whenever the class
  79. * structure is changed (or anything else that would prevent serialized
  80. * objects being unserialized with the new class).
  81. */
  82. private static final long serialVersionUID = 1;
  83. /** Topic text. */
  84. private final TextPaneInputField topicText;
  85. /** Edit button. */
  86. private final JButton topicEdit;
  87. /** Cancel button. */
  88. private final JButton topicCancel;
  89. /** Associated channel. */
  90. private Channel channel;
  91. /** Controller. */
  92. private SwingController controller;
  93. /** Empty Attrib set. */
  94. private SimpleAttributeSet as;
  95. /** Foreground Colour. */
  96. private Color foregroundColour;
  97. /** Background Colour. */
  98. private Color backgroundColour;
  99. /** the maximum length allowed for a topic. */
  100. private int topicLengthMax;
  101. /** Error icon. */
  102. private final JLabel errorIcon;
  103. /**
  104. * Instantiates a new topic bar.
  105. *
  106. * @param channelFrame Parent channel frame
  107. */
  108. public TopicBar(final ChannelFrame channelFrame) {
  109. this.channel = channelFrame.getChannel();
  110. controller = channelFrame.getController();
  111. topicText = new TextPaneInputField();
  112. topicLengthMax = channel.getServer().getParser().getMaxTopicLength();
  113. errorIcon =
  114. new JLabel(IconManager.getIconManager().getIcon("input-error"));
  115. //TODO issue 3251
  116. //if (channelFrame.getConfigManager().getOptionBool(controller.
  117. // getDomain(), "showfulltopic")) {
  118. // topicText.setEditorKit(new StyledEditorKit());
  119. //} else {
  120. topicText.setEditorKit(new WrapEditorKit());
  121. //}
  122. ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
  123. new NewlinesDocumentFilter());
  124. topicText.getActionMap().put("paste-from-clipboard",
  125. new NoNewlinesPasteAction());
  126. topicEdit = new ImageButton("edit", IconManager.getIconManager().
  127. getIcon("edit-inactive"), IconManager.getIconManager().
  128. getIcon("edit"));
  129. topicCancel = new ImageButton("cancel", IconManager.getIconManager().
  130. getIcon("close"), IconManager.getIconManager().
  131. getIcon("close-active"));
  132. final SwingInputHandler handler = new SwingInputHandler(topicText,
  133. channelFrame.getCommandParser(), channelFrame);
  134. handler.setTypes(true, false, true, false);
  135. handler.setTabCompleter(channel.getTabCompleter());
  136. final JScrollPane sp = new JScrollPane(topicText);
  137. sp.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
  138. sp.setVerticalScrollBarPolicy(JScrollPane.VERTICAL_SCROLLBAR_NEVER);
  139. setLayout(new MigLayout("fillx, ins 0, hidemode 3"));
  140. add(sp, "growx, pushx");
  141. add(errorIcon, "");
  142. add(topicCancel, "");
  143. add(topicEdit, "");
  144. channel.getChannelInfo().getParser().getCallbackManager().addCallback(
  145. ChannelTopicListener.class, this, channel.getChannelInfo().
  146. getName());
  147. topicText.addActionListener(this);
  148. topicEdit.addActionListener(this);
  149. topicCancel.addActionListener(this);
  150. topicText.getInputMap().put(KeyStroke.getKeyStroke("ENTER"),
  151. "enterButton");
  152. topicText.getActionMap().put("enterButton", new AbstractAction(
  153. "enterButton") {
  154. private static final long serialVersionUID = 1;
  155. /** {@inheritDoc} */
  156. @Override
  157. public void actionPerformed(ActionEvent e) {
  158. TopicBar.this.actionPerformed(e);
  159. }
  160. });
  161. topicText.getInputMap().put(KeyStroke.getKeyStroke("ESCAPE"),
  162. "escapeButton");
  163. topicText.getActionMap().put("escapeButton", new AbstractAction(
  164. "escapeButton") {
  165. private static final long serialVersionUID = 1;
  166. /** {@inheritDoc} */
  167. @Override
  168. public void actionPerformed(ActionEvent e) {
  169. e.setSource(topicCancel);
  170. TopicBar.this.actionPerformed(e);
  171. }
  172. });
  173. topicText.addHyperlinkListener(this);
  174. topicText.addMouseListener(this);
  175. topicText.getDocument().addDocumentListener(this);
  176. IdentityManager.getGlobalConfig().addChangeListener(
  177. "ui", "backgroundcolour", this);
  178. IdentityManager.getGlobalConfig().addChangeListener(
  179. "ui", "foregroundcolour", this);
  180. IdentityManager.getGlobalConfig().addChangeListener(
  181. "ui", "inputbackgroundcolour", this);
  182. IdentityManager.getGlobalConfig().addChangeListener(
  183. "ui", "inputforegroundcolour", this);
  184. IdentityManager.getGlobalConfig().addChangeListener(
  185. controller.getDomain(), "showfulltopic", this);
  186. IdentityManager.getGlobalConfig().addChangeListener(
  187. controller.getDomain(), "hideEmptyTopicBar", this);
  188. topicText.setFocusable(false);
  189. topicText.setEditable(false);
  190. topicCancel.setVisible(false);
  191. setColours();
  192. }
  193. /** {@inheritDoc} */
  194. @Override
  195. public void onChannelTopic(final Parser tParser, ChannelInfo cChannel,
  196. boolean bIsJoinTopic) {
  197. topicChanged();
  198. }
  199. /**
  200. * Topic has changed, update topic.
  201. */
  202. private void topicChanged() {
  203. if (topicText.isEditable()) {
  204. return;
  205. }
  206. topicText.setText("");
  207. if (channel.getCurrentTopic() != null) {
  208. Styliser.addStyledString((StyledDocument) topicText.getDocument(),
  209. new String[]{Styliser.CODE_HEXCOLOUR + ColourManager.getHex(
  210. foregroundColour) + channel.getCurrentTopic().getTopic(),},
  211. as);
  212. }
  213. if (channel.getConfigManager().getOptionBool(controller.getDomain(),
  214. "hideEmptyTopicBar")) {
  215. setVisible(topicText.getDocument().getLength() != 0);
  216. }
  217. topicText.setCaretPosition(0);
  218. validateTopic();
  219. }
  220. /**
  221. * {@inheritDoc}
  222. *
  223. * @param e Action event
  224. */
  225. @Override
  226. public void actionPerformed(final ActionEvent e) {
  227. if (e.getSource() == topicEdit || e.getSource() == topicText) {
  228. if (topicText.isEditable()) {
  229. channel.setTopic(topicText.getText());
  230. ((ChannelFrame) channel.getFrame()).getInputField().
  231. requestFocusInWindow();
  232. topicChanged();
  233. topicText.setFocusable(false);
  234. topicText.setEditable(false);
  235. topicCancel.setVisible(false);
  236. } else {
  237. topicText.setVisible(false);
  238. topicText.setText("");
  239. if (channel.getCurrentTopic() != null) {
  240. topicText.setText(channel.getCurrentTopic().getTopic());
  241. }
  242. applyAttributes();
  243. topicText.setCaretPosition(0);
  244. topicText.setFocusable(true);
  245. topicText.setEditable(true);
  246. topicText.setVisible(true);
  247. topicText.requestFocusInWindow();
  248. topicCancel.setVisible(true);
  249. }
  250. } else if (e.getSource() == topicCancel) {
  251. topicText.setFocusable(false);
  252. topicText.setEditable(false);
  253. topicCancel.setVisible(false);
  254. ((ChannelFrame) channel.getFrame()).getInputField().
  255. requestFocusInWindow();
  256. topicChanged();
  257. }
  258. }
  259. /** {@inheritDoc} */
  260. @Override
  261. public void hyperlinkUpdate(final HyperlinkEvent e) {
  262. if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
  263. URLHandler.getURLHander().launchApp(e.getURL());
  264. }
  265. }
  266. private void setColours() {
  267. backgroundColour = channel.getConfigManager().getOptionColour(
  268. "ui", "inputbackgroundcolour", "ui", "backgroundcolour");
  269. foregroundColour = channel.getConfigManager().getOptionColour(
  270. "ui", "inputforegroundcolour", "ui", "foregroundcolour");
  271. setBackground(backgroundColour);
  272. setForeground(foregroundColour);
  273. setDisabledTextColour(foregroundColour);
  274. setCaretColor(foregroundColour);
  275. setAttributes();
  276. }
  277. private void setAttributes() {
  278. as = new SimpleAttributeSet();
  279. StyleConstants.setFontFamily(as, topicText.getFont().getFamily());
  280. StyleConstants.setFontSize(as, topicText.getFont().getSize());
  281. StyleConstants.setBackground(as, backgroundColour);
  282. StyleConstants.setForeground(as, foregroundColour);
  283. StyleConstants.setUnderline(as, false);
  284. StyleConstants.setBold(as, false);
  285. StyleConstants.setItalic(as, false);
  286. }
  287. private void applyAttributes() {
  288. setAttributes();
  289. ((DefaultStyledDocument) topicText.getDocument()).setCharacterAttributes(
  290. 0, Integer.MAX_VALUE, as, true);
  291. }
  292. /**
  293. * Sets the caret position in this topic bar.
  294. *
  295. * @param position New position
  296. */
  297. public void setCaretPosition(final int position) {
  298. UIUtilities.invokeLater(new Runnable() {
  299. /** {@inheritDoc} */
  300. @Override
  301. public void run() {
  302. topicText.setCaretPosition(position);
  303. }
  304. });
  305. }
  306. /**
  307. * Sets the caret colour to the specified coloour.
  308. *
  309. * @param optionColour Colour for the caret
  310. */
  311. public void setCaretColor(final Color optionColour) {
  312. UIUtilities.invokeLater(new Runnable() {
  313. /** {@inheritDoc} */
  314. @Override
  315. public void run() {
  316. topicText.setCaretColor(optionColour);
  317. }
  318. });
  319. }
  320. /**
  321. * Sets the foreground colour to the specified coloour.
  322. *
  323. * @param optionColour Colour for the foreground
  324. */
  325. @Override
  326. public void setForeground(final Color optionColour) {
  327. UIUtilities.invokeLater(new Runnable() {
  328. /** {@inheritDoc} */
  329. @Override
  330. public void run() {
  331. topicText.setForeground(optionColour);
  332. }
  333. });
  334. }
  335. /**
  336. * Sets the disabled text colour to the specified coloour.
  337. *
  338. * @param optionColour Colour for the disabled text
  339. */
  340. public void setDisabledTextColour(final Color optionColour) {
  341. UIUtilities.invokeLater(new Runnable() {
  342. /** {@inheritDoc} */
  343. @Override
  344. public void run() {
  345. topicText.setDisabledTextColor(optionColour);
  346. }
  347. });
  348. }
  349. /**
  350. * Sets the background colour to the specified coloour.
  351. *
  352. * @param optionColour Colour for the caret
  353. */
  354. @Override
  355. public void setBackground(final Color optionColour) {
  356. UIUtilities.invokeLater(new Runnable() {
  357. /** {@inheritDoc} */
  358. @Override
  359. public void run() {
  360. topicText.setBackground(optionColour);
  361. }
  362. });
  363. }
  364. /** {@inheritDoc} */
  365. @Override
  366. public void configChanged(String domain, String key) {
  367. //TODO issue 3251
  368. //if ("showfulltopic".equals(key)) {
  369. // if (channel.getConfigManager().getOptionBool(controller.getDomain(),
  370. // "showfulltopic")) {
  371. // topicText.setEditorKit(new StyledEditorKit());
  372. // } else {
  373. // topicText.setEditorKit(new WrapEditorKit());
  374. // }
  375. // ((DefaultStyledDocument) topicText.getDocument()).setDocumentFilter(
  376. // new NewlinesDocumentFilter());
  377. //}
  378. setColours();
  379. if ("hideEmptyTopicBar".equals(key)) {
  380. setVisible(true);
  381. if (channel.getConfigManager().getOptionBool(controller.getDomain(),
  382. "hideEmptyTopicBar")) {
  383. setVisible(topicText.getDocument().getLength() != 0);
  384. }
  385. }
  386. }
  387. /**
  388. * Closes this topic bar.
  389. */
  390. public void close() {
  391. channel.getChannelInfo().getParser().getCallbackManager().delCallback(
  392. ChannelTopicListener.class, this);
  393. }
  394. /**
  395. * Validates the topic text and shows errors as appropriate.
  396. */
  397. public void validateTopic() {
  398. UIUtilities.invokeLater(new Runnable() {
  399. /** {@inheritDoc} */
  400. @Override
  401. public void run() {
  402. if (topicText.isEditable()) {
  403. final int charsLeft = topicLengthMax - topicText.getText().
  404. length();
  405. if (charsLeft < 0) {
  406. errorIcon.setVisible(true);
  407. errorIcon.setToolTipText("Topic too long: " + topicText.
  408. getText().length() + " of " + topicLengthMax);
  409. } else {
  410. errorIcon.setVisible(false);
  411. errorIcon.setToolTipText(null);
  412. }
  413. } else {
  414. errorIcon.setVisible(false);
  415. }
  416. }
  417. });
  418. }
  419. /**
  420. * {@inheritDoc}
  421. *
  422. * @param e Mouse event
  423. */
  424. @Override
  425. public void mouseClicked(MouseEvent e) {
  426. if (e.getClickCount() == 2) {
  427. topicEdit.doClick();
  428. }
  429. }
  430. /**
  431. * {@inheritDoc}
  432. *
  433. * @param e Mouse event
  434. */
  435. @Override
  436. public void mousePressed(final MouseEvent e) {
  437. //Ignore
  438. }
  439. /**
  440. * {@inheritDoc}
  441. *
  442. * @param e Mouse event
  443. */
  444. @Override
  445. public void mouseReleased(final MouseEvent e) {
  446. //Ignore
  447. }
  448. /**
  449. * {@inheritDoc}
  450. *
  451. * @param e Mouse event
  452. */
  453. @Override
  454. public void mouseEntered(final MouseEvent e) {
  455. //Ignore
  456. }
  457. /**
  458. * {@inheritDoc}
  459. *
  460. * @param e Mouse event
  461. */
  462. @Override
  463. public void mouseExited(final MouseEvent e) {
  464. //Ignore
  465. }
  466. /** {@inheritDoc} */
  467. @Override
  468. public void insertUpdate(final DocumentEvent e) {
  469. validateTopic();
  470. if (topicText.isEditable()) {
  471. SwingUtilities.invokeLater(new Runnable() {
  472. @Override
  473. public void run() {
  474. applyAttributes();
  475. }
  476. });
  477. }
  478. }
  479. /** {@inheritDoc} */
  480. @Override
  481. public void removeUpdate(final DocumentEvent e) {
  482. validateTopic();
  483. }
  484. /** {@inheritDoc} */
  485. @Override
  486. public void changedUpdate(final DocumentEvent e) {
  487. validateTopic();
  488. }
  489. }
  490. /**
  491. * @author Stanislav Lapitsky
  492. * @version 1.0
  493. */
  494. class WrapEditorKit extends StyledEditorKit {
  495. private static final long serialVersionUID = 1;
  496. private ViewFactory defaultFactory = new WrapColumnFactory();
  497. /** {@inheritDoc} */
  498. @Override
  499. public ViewFactory getViewFactory() {
  500. return defaultFactory;
  501. }
  502. }
  503. /**
  504. * @author Stanislav Lapitsky
  505. * @version 1.0
  506. */
  507. class WrapColumnFactory implements ViewFactory {
  508. /** {@inheritDoc} */
  509. @Override
  510. public View create(final Element elem) {
  511. String kind = elem.getName();
  512. if (kind != null) {
  513. if (kind.equals(AbstractDocument.ContentElementName)) {
  514. return new WrapLabelView(elem);
  515. } else if (kind.equals(AbstractDocument.ParagraphElementName)) {
  516. return new NoWrapParagraphView(elem);
  517. } else if (kind.equals(AbstractDocument.SectionElementName)) {
  518. return new BoxView(elem, View.Y_AXIS);
  519. } else if (kind.equals(StyleConstants.ComponentElementName)) {
  520. return new ComponentView(elem);
  521. } else if (kind.equals(StyleConstants.IconElementName)) {
  522. return new IconView(elem);
  523. }
  524. }
  525. // default to text display
  526. return new LabelView(elem);
  527. }
  528. }
  529. /**
  530. * @author Stanislav Lapitsky
  531. * @version 1.0
  532. */
  533. class NoWrapParagraphView extends ParagraphView {
  534. /**
  535. * Creates a new no wrap paragraph view.
  536. *
  537. * @param elem Element to view
  538. */
  539. public NoWrapParagraphView(final Element elem) {
  540. super(elem);
  541. }
  542. /** {@inheritDoc} */
  543. @Override
  544. public void layout(final int width, final int height) {
  545. super.layout(Short.MAX_VALUE, height);
  546. }
  547. /** {@inheritDoc} */
  548. @Override
  549. public float getMinimumSpan(final int axis) {
  550. return super.getPreferredSpan(axis);
  551. }
  552. }
  553. /**
  554. * @author Stanislav Lapitsky
  555. * @version 1.0
  556. */
  557. class WrapLabelView extends LabelView {
  558. /**
  559. * Creates a new wrap label view.
  560. *
  561. * @param elem Element to view
  562. */
  563. public WrapLabelView(final Element elem) {
  564. super(elem);
  565. }
  566. /** {@inheritDoc} */
  567. @Override
  568. public int getBreakWeight(final int axis, final float pos, final float len) {
  569. if (axis == View.X_AXIS) {
  570. checkPainter();
  571. int p0 = getStartOffset();
  572. int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
  573. if (p1 == p0) {
  574. // can't even fit a single character
  575. return View.BadBreakWeight;
  576. }
  577. try {
  578. //if the view contains line break char return forced break
  579. if (getDocument().getText(p0, p1 - p0).indexOf("\r") >= 0) {
  580. return View.ForcedBreakWeight;
  581. }
  582. } catch (BadLocationException ex) {
  583. //should never happen
  584. }
  585. }
  586. return super.getBreakWeight(axis, pos, len);
  587. }
  588. /** {@inheritDoc} */
  589. @Override
  590. public View breakView(final int axis, final int p0, final float pos,
  591. final float len) {
  592. if (axis == View.X_AXIS) {
  593. checkPainter();
  594. int p1 = getGlyphPainter().getBoundedPosition(this, p0, pos, len);
  595. try {
  596. //if the view contains line break char break the view
  597. int index = getDocument().getText(p0, p1 - p0).indexOf("\r");
  598. if (index >= 0) {
  599. GlyphView v = (GlyphView) createFragment(p0, p0 + index + 1);
  600. return v;
  601. }
  602. } catch (BadLocationException ex) {
  603. //should never happen
  604. }
  605. }
  606. return super.breakView(axis, p0, pos, len);
  607. }
  608. }