Viewing Issue Advanced Details

ID 0003739 Category [DMDirc] *Unsorted Severity minor
Reproducibility always Date Submitted 2010-02-05 19:20 Last Update 2010-03-06 21:32
Reporter Dataforce Assigned To Greboid View Status public
Priority normal Status closed Resolution fixed
Platform Fixed in Version Target Version 0.6.3
Product Version Product Build
Summary 0003739: Topic bar URLs don't appear to work
Description Topic bar URLs don't appear to work
Needs unit test no
Upstream Bug URL

Relationships

Notes

(0009749)
Greboid (administrator)
2010-02-05 19:21

Good observation
(0009750)
Dataforce (administrator)
2010-02-05 19:25

Surely this is fixable..
(0009751)
Greboid (administrator)
2010-02-05 19:26

Feel free to take ownership of it and do so if you think its possible
(0009753)
Version Control (developer)
2010-02-05 23:15

A patchset (1) related to this change has been added to gerrit by Gregory Holmes

I'm almost tempted to class this as a bug, but equally i'm not...  Add support
for hyperlink events in WrapEditorKit so the topic bar URLs are exposed and
clickable.

Fixes issue 3739: Topic bar URLs don't appear to work

Change-Id: I8c5412e5e5d6b87b14e0b841ce50be2b204a747e
authorGregory Holmes <greg@dmdirc.com>2010-02-05 23:13:59 (GMT)
committer Shane Mc Cormack <shane@dmdirc.com>2010-02-06 08:36:26 (GMT)
commitd6903ca08c677449392532d66e3fc75720b3f4c6 (patch) (side-by-side diff)
I'm almost tempted to class this as a bug, but equally i'm not... Add support for hyperlink events in WrapEditorKit so the topic bar URLs are exposed and clickable.
Fixes issue 3739: Topic bar URLs don't appear to work Change-Id: I8c5412e5e5d6b87b14e0b841ce50be2b204a747e Reviewed-on: http://gerrit.dmdirc.com/851 Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com> Reviewed-by: Shane Mc Cormack <shane@dmdirc.com>
-rw-r--r--src/com/dmdirc/addons/ui_swing/components/TopicBar.java2
-rw-r--r--src/com/dmdirc/addons/ui_swing/components/text/WrapEditorKit.java148
2 files changed, 147 insertions, 3 deletions
Click to Expand/Collapse
diff src/com/dmdirc/addons/ui_swing/components/TopicBar.java
@@ -265,7 +265,7 @@ public class TopicBar extends JComponent implements ActionListener,
@Override
public void hyperlinkUpdate(final HyperlinkEvent e) {
if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
- URLHandler.getURLHander().launchApp(e.getURL());
+ URLHandler.getURLHander().launchApp(e.getDescription());
}
}
Click to Expand/Collapse
diff src/com/dmdirc/addons/ui_swing/components/text/WrapEditorKit.java
@@ -1,25 +1,169 @@
/*
* @author Stanislav Lapitsky
* @version 1.0
+ *
+ * Extended for Hyperlink events
*/
package com.dmdirc.addons.ui_swing.components.text;
+import com.dmdirc.ui.messages.IRCTextAttribute;
+
+import java.awt.Cursor;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+
+import javax.swing.JEditorPane;
+import javax.swing.SwingUtilities;
+import javax.swing.event.HyperlinkEvent;
+import javax.swing.text.Element;
+import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
import javax.swing.text.ViewFactory;
/**
* @author Stanislav Lapitsky
* @version 1.0
+ *
+ * Extended for Hyperlink events
*/
-public class WrapEditorKit extends StyledEditorKit {
+public class WrapEditorKit extends StyledEditorKit implements MouseListener,
+ MouseMotionListener {
private static final long serialVersionUID = 1;
+ /** Wrap column factory. */
private ViewFactory defaultFactory = new WrapColumnFactory();
+ /** Hand cursor. */
+ private static final Cursor HAND_CURSOR = new Cursor(Cursor.HAND_CURSOR);
+ /** Associated Component. */
+ private JEditorPane editorPane;
+
+ /** {@inheritDoc} */
+ @Override
+ public void install(final JEditorPane c) {
+ super.install(c);
+ editorPane = c;
+ c.addMouseListener(this);
+ c.addMouseMotionListener(this);
+ }
+
+ /** {@inheritDoc} */
+ @Override
+ public void deinstall(final JEditorPane c) {
+ c.removeMouseListener(this);
+ c.removeMouseMotionListener(this);
+ editorPane = null;
+ super.deinstall(c);
+ }
/** {@inheritDoc} */
@Override
public ViewFactory getViewFactory() {
return defaultFactory;
}
-} \ No newline at end of file
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseMoved(final MouseEvent e) {
+ if (editorPane == null) {
+ return;
+ }
+ if (!editorPane.isEditable()) {
+ Object target = characterElementAt(e).getAttributes().getAttribute(
+ IRCTextAttribute.HYPERLINK);
+ if (target != null) {
+ editorPane.setCursor(HAND_CURSOR);
+ return;
+ }
+ }
+ editorPane.setCursor(Cursor.getDefaultCursor());
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseReleased(final MouseEvent e) {
+ if (!SwingUtilities.isLeftMouseButton(e) || editorPane == null) {
+ return;
+ }
+ if (!editorPane.isEditable()) {
+ Object target = characterElementAt(e).getAttributes().getAttribute(
+ IRCTextAttribute.HYPERLINK);
+ if (target != null) {
+ editorPane.fireHyperlinkUpdate(new HyperlinkEvent(editorPane,
+ HyperlinkEvent.EventType.ACTIVATED, null,
+ (String) target));
+ }
+ }
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseClicked(final MouseEvent e) {
+ //Ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mousePressed(final MouseEvent e) {
+ //Ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseEntered(final MouseEvent e) {
+ //Ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseExited(final MouseEvent e) {
+ //Ignore
+ }
+
+ /**
+ * {@inheritDoc}
+ *
+ * @param e Mouse Event
+ */
+ @Override
+ public void mouseDragged(final MouseEvent e) {
+ //Ignore
+ }
+
+ /**
+ * Returns the character element for the positition of the mouse event.
+ *
+ * @param e Mouse event to get position from
+ *
+ * @return Character element at mouse event
+ */
+ private Element characterElementAt(final MouseEvent e) {
+ return ((StyledDocument) editorPane.getDocument()).getCharacterElement(
+ editorPane.getUI().viewToModel(editorPane, e.getPoint()));
+ }
+}

Issue History

Date Modified Username Field Change
2010-02-05 19:20 Dataforce New Issue
2010-02-05 19:20 Dataforce Status new => assigned
2010-02-05 19:20 Dataforce Assigned To => Greboid
2010-02-05 19:21 Greboid Needs unit test => no
2010-02-05 19:21 Greboid Note Added: 0009749
2010-02-05 19:21 Greboid Status assigned => closed
2010-02-05 19:21 Greboid Resolution open => not fixable
2010-02-05 19:25 Dataforce Note Added: 0009750
2010-02-05 19:25 Dataforce Status closed => acknowledged
2010-02-05 19:26 Greboid Assigned To Greboid =>
2010-02-05 19:26 Greboid Note Added: 0009751
2010-02-05 23:15 Version Control Checkin
2010-02-05 23:15 Version Control Note Added: 0009753
2010-02-05 23:15 Version Control Status acknowledged => fix pending
2010-02-05 23:15 Greboid Status fix pending => assigned
2010-02-05 23:15 Greboid Assigned To => Greboid
2010-02-05 23:16 Greboid Status assigned => fix pending
2010-02-05 23:16 Greboid Resolution not fixable => open
2010-02-06 08:37 Greboid Checkin
2010-02-06 08:37 Greboid Note Added: 0009755
2010-02-06 08:37 Greboid Status fix pending => resolved
2010-02-06 08:37 Greboid Resolution open => fixed
2010-03-06 21:32 Greboid Status resolved => closed