/[classpath]/classpath/javax/swing/text/JTextComponent.java
ViewVC logotype

Diff of /classpath/javax/swing/text/JTextComponent.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.13.2.12 by gnu_andrew, Tue Sep 20 18:46:35 2005 UTC revision 1.13.2.13 by gnu_andrew, Wed Nov 2 00:44:03 2005 UTC
# Line 53  import java.awt.event.ActionEvent; Line 53  import java.awt.event.ActionEvent;
53  import java.awt.event.ActionListener;  import java.awt.event.ActionListener;
54  import java.awt.event.InputMethodListener;  import java.awt.event.InputMethodListener;
55  import java.awt.event.KeyEvent;  import java.awt.event.KeyEvent;
56    import java.awt.event.MouseEvent;
57  import java.io.IOException;  import java.io.IOException;
58  import java.io.Reader;  import java.io.Reader;
59  import java.io.Writer;  import java.io.Writer;
# Line 89  public abstract class JTextComponent ext Line 90  public abstract class JTextComponent ext
90    /**    /**
91     * AccessibleJTextComponent     * AccessibleJTextComponent
92     */     */
93      // FIXME: This inner class is a complete stub and needs to be implemented.
94    public class AccessibleJTextComponent extends AccessibleJComponent    public class AccessibleJTextComponent extends AccessibleJComponent
95      implements AccessibleText, CaretListener, DocumentListener      implements AccessibleText, CaretListener, DocumentListener
96    {    {
# Line 99  public abstract class JTextComponent ext Line 101  public abstract class JTextComponent ext
101       */       */
102      public AccessibleJTextComponent()      public AccessibleJTextComponent()
103      {      {
104          // Nothing to do here.
105      }      }
106    
107      /**      /**
# Line 321  public abstract class JTextComponent ext Line 324  public abstract class JTextComponent ext
324      {      {
325        Caret c = caret;        Caret c = caret;
326        if (c != null)        if (c != null)
327          c.setVisible(!c.isVisible());          c.setVisible(!c.isVisible());
328      }      }
329    
330      /**      /**
# Line 332  public abstract class JTextComponent ext Line 335  public abstract class JTextComponent ext
335        stop();        stop();
336        Caret c = caret;        Caret c = caret;
337        if (c != null)        if (c != null)
338          {          {
339            setDelay(c.getBlinkRate());            setDelay(c.getBlinkRate());
340            if (editable)            if (editable)
341              start();              start();
342            else            else
343              c.setVisible(false);              c.setVisible(false);
344          }          }
345      }      }
346    }    }
347    
# Line 628  public abstract class JTextComponent ext Line 631  public abstract class JTextComponent ext
631        int end = textComponent.getSelectionEnd();        int end = textComponent.getSelectionEnd();
632    
633        if (start == end)        if (start == end)
634          return;          return;
635    
636        try        try
637          {          {
638            // Copy text to clipboard.            // Copy text to clipboard.
639            String data = textComponent.getDocument().getText(start, end);            String data = textComponent.getDocument().getText(start, end);
640            StringSelection selection = new StringSelection(data);            StringSelection selection = new StringSelection(data);
641            clipboard.setContents(selection, null);            clipboard.setContents(selection, null);
642    
643            // Delete selected text on cut action.            // Delete selected text on cut action.
644            if (action == MOVE)            if (action == MOVE)
645              doc.remove(start, end - start);              doc.remove(start, end - start);
646          }          }
647        catch (BadLocationException e)        catch (BadLocationException e)
648          {          {
649            // Ignore this and do nothing.            // Ignore this and do nothing.
650          }          }
651      }      }
652            
653      public int getSourceActions()      public int getSourceActions()
# Line 658  public abstract class JTextComponent ext Line 661  public abstract class JTextComponent ext
661        DataFlavor[] flavors = transferable.getTransferDataFlavors();        DataFlavor[] flavors = transferable.getTransferDataFlavors();
662    
663        if (flavors == null)        if (flavors == null)
664          return false;          return false;
665    
666        for (int i = 0; i < flavors.length; ++i)        for (int i = 0; i < flavors.length; ++i)
667          if (flavors[i].equals(DataFlavor.stringFlavor))          if (flavors[i].equals(DataFlavor.stringFlavor))
668             flavor = flavors[i];            flavor = flavors[i];
669                
670        if (flavor == null)        if (flavor == null)
671          return false;          return false;
672    
673        try        try
674          {          {
675            JTextComponent textComponent = (JTextComponent) component;            JTextComponent textComponent = (JTextComponent) component;
676            String data = (String) transferable.getTransferData(flavor);            String data = (String) transferable.getTransferData(flavor);
677            textComponent.replaceSelection(data);            textComponent.replaceSelection(data);
678            return true;            return true;
679          }          }
680        catch (IOException e)        catch (IOException e)
681          {          {
682            // Ignored.            // Ignored.
683          }          }
684        catch (UnsupportedFlavorException e)        catch (UnsupportedFlavorException e)
685          {          {
686            // Ignored.            // Ignored.
687          }          }
688    
689        return false;        return false;
690      }      }
# Line 1018  public abstract class JTextComponent ext Line 1021  public abstract class JTextComponent ext
1021    {    {
1022      try      try
1023        {        {
1024          doc.remove(0, doc.getLength());          if (doc instanceof AbstractDocument)
1025          doc.insertString(0, text, null);            ((AbstractDocument) doc).replace(0, doc.getLength(), text, null);
1026            else
1027              {
1028                doc.remove(0, doc.getLength());
1029                doc.insertString(0, text, null);
1030              }
1031        }        }
1032      catch (BadLocationException e)      catch (BadLocationException e)
1033        {        {
1034          // This can never happen.          // This can never happen.
1035        }        }
1036    }    }
1037    
# Line 1041  public abstract class JTextComponent ext Line 1049  public abstract class JTextComponent ext
1049    
1050      try      try
1051        {        {
1052          return doc.getText(0, doc.getLength());          return doc.getText(0, doc.getLength());
1053        }        }
1054      catch (BadLocationException e)      catch (BadLocationException e)
1055        {        {
1056          // This should never happen.          // This should never happen.
1057          return "";          return "";
1058        }        }
1059    }    }
1060    
# Line 1077  public abstract class JTextComponent ext Line 1085  public abstract class JTextComponent ext
1085    {    {
1086      try      try
1087        {        {
1088          return doc.getText(getSelectionStart(), getSelectionEnd());          return doc.getText(getSelectionStart(), getSelectionEnd());
1089        }        }
1090      catch (BadLocationException e)      catch (BadLocationException e)
1091        {        {
1092          // This should never happen.          // This should never happen.
1093          return null;          return null;
1094        }        }
1095    }    }
1096    
# Line 1420  public abstract class JTextComponent ext Line 1428  public abstract class JTextComponent ext
1428      // If content is empty delete selection.      // If content is empty delete selection.
1429      if (content == null)      if (content == null)
1430        {        {
1431          caret.setDot(dot);          caret.setDot(dot);
1432          return;          return;
1433        }        }
1434    
1435      try      try
1436        {        {
1437          int start = getSelectionStart();          int start = getSelectionStart();
1438          int end = getSelectionEnd();          int end = getSelectionEnd();
           
         // Remove selected text.  
         if (dot != mark)  
           doc.remove(start, end - start);  
1439    
1440          // Insert new text.          // Remove selected text.
1441          doc.insertString(start, content, null);          if (dot != mark)
1442              doc.remove(start, end - start);
1443    
1444          // Set dot to new position.          // Insert new text.
1445          setCaretPosition(start + content.length());          doc.insertString(start, content, null);
1446    
1447            // Set dot to new position.
1448            setCaretPosition(start + content.length());
1449        }        }
1450      catch (BadLocationException e)      catch (BadLocationException e)
1451        {        {
1452          // This should never happen.          // This should never happen.
1453        }        }
1454    }    }
1455    
# Line 1575  public abstract class JTextComponent ext Line 1583  public abstract class JTextComponent ext
1583      // Install default TransferHandler if none set.      // Install default TransferHandler if none set.
1584      if (getTransferHandler() == null)      if (getTransferHandler() == null)
1585        {        {
1586          if (defaultTransferHandler == null)          if (defaultTransferHandler == null)
1587            defaultTransferHandler = new DefaultTransferHandler();            defaultTransferHandler = new DefaultTransferHandler();
1588            
1589          setTransferHandler(defaultTransferHandler);          setTransferHandler(defaultTransferHandler);
1590        }        }
1591    
1592      // Perform action.      // Perform action.
1593      ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,      ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
1594                                          action.getValue(Action.NAME).toString());                                          action.getValue(Action.NAME).toString());
1595      action.actionPerformed(event);      action.actionPerformed(event);
1596    }    }
1597    
# Line 1667  public abstract class JTextComponent ext Line 1675  public abstract class JTextComponent ext
1675               throws IOException               throws IOException
1676    {    {
1677      output.write(getText());      output.write(getText());
1678    }      }
1679    
1680      /**
1681       * Returns the tooltip text for this text component for the given mouse
1682       * event. This forwards the call to
1683       * {@link TextUI#getToolTipText(JTextComponent, Point)}.
1684       *
1685       * @param ev the mouse event
1686       *
1687       * @return the tooltip text for this text component for the given mouse
1688       *         event
1689       */
1690      public String getToolTipText(MouseEvent ev)
1691      {
1692        return getUI().getToolTipText(this, ev.getPoint());
1693      }
1694  }  }

Legend:
Removed from v.1.13.2.12  
changed lines
  Added in v.1.13.2.13

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26