Пример #1
0
 @Override
 public void mouseMoved(MouseEvent event) {
   JTextPane textPane = (JTextPane) event.getSource();
   Point point = new Point(event.getX(), event.getY());
   int position = textPane.viewToModel(point);
   DefaultStyledDocument document = (DefaultStyledDocument) textPane.getDocument();
   Element element = document.getCharacterElement(position);
   AttributeSet attributeSet = element.getAttributes();
   String sLink = (String) attributeSet.getAttribute("link");
   if (sLink != null) {
     textPane.setCursor(handCursor);
   } else {
     textPane.setCursor(textCursor);
   }
 }
Пример #2
0
 private ActionListener getAction(final MouseEvent event) {
   Element e = document.getCharacterElement(textPane.viewToModel(event.getPoint()));
   ActionListener action = (ActionListener) e.getAttributes().getAttribute(ACTION_ATTRIBUTE);
   return action;
 }
Пример #3
0
 @Override
 public void mouseClicked(MouseEvent event) {
   if (event.getClickCount() == 2 && event.getSource() instanceof JList) {
     Cursor cursor = hydc3View.getCursor();
     hydc3View.setCursor(new Cursor(Cursor.WAIT_CURSOR));
     String s = hydc3View.getSelected();
     try {
       hydc3View.clearDescriptionTextPane();
       if (s.matches(".[0-9]+ .+")) {
         int index = Integer.parseInt(s.split(" ")[0].substring(1));
         s = s.substring(0, 1);
         hydc3Model.getDescriptionsByCharacterAndIndex(s, index);
       } else if (s.length() == 1) {
         hydc3Model.getDescriptionsByCharacter(s);
       } else {
         hydc3Model.getDescriptionsByWord(s);
       }
       hydc3View.setDescriptionTextPaneTop();
     } catch (Exception e) {
       e.printStackTrace();
     }
     hydc3View.setCursor(cursor);
   } else if (event.getSource() instanceof JTextPane) {
     JTextPane textPane = (JTextPane) event.getSource();
     Point point = new Point(event.getX(), event.getY());
     int position = textPane.viewToModel(point);
     DefaultStyledDocument document = (DefaultStyledDocument) textPane.getDocument();
     Element element = document.getCharacterElement(position);
     AttributeSet attributeSet = element.getAttributes();
     String sLink = (String) attributeSet.getAttribute("link");
     if (sLink != null) {
       Cursor cursor = hydc3View.getCursor();
       hydc3View.setCursor(new Cursor(Cursor.WAIT_CURSOR));
       try {
         if (sLink.matches(".")) {
           hydc3View.clearDescriptionTextPane();
           hydc3Model.getDescriptionsByCharacter(sLink);
           hydc3View.setDescriptionTextPaneTop();
         } else if (sLink.matches(".[0-9]+")) {
           int index = Integer.parseInt(sLink.substring(1));
           hydc3View.clearDescriptionTextPane();
           hydc3Model.getDescriptionsByCharacterAndIndex(sLink.substring(0, 1), index);
           hydc3View.setDescriptionTextPaneTop();
         } else {
           HashMap<String, Integer> wordPositionMap = hydc3View.getWordPositionMap();
           Integer iPosition = wordPositionMap.get(sLink);
           if (iPosition != null) {
             hydc3View.setDescriptionTextPaneCaretPosition(iPosition);
           } else {
             hydc3View.clearDescriptionTextPane();
             hydc3Model.getDescriptionsByWord(sLink);
             hydc3View.setDescriptionTextPaneTop();
           }
         }
       } catch (Exception e) {
         e.printStackTrace();
       }
       hydc3View.setCursor(cursor);
     }
   }
 }
Пример #4
0
 public int getOffsetFromPoint(Point p) {
   return textPane.viewToModel(p);
 }