/[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.38 by rabbit78, Fri Sep 30 19:54:18 2005 UTC revision 1.39 by abalkiss, Tue Oct 4 15:10:54 2005 UTC
# Line 321  public abstract class JTextComponent ext Line 321  public abstract class JTextComponent ext
321      {      {
322        Caret c = caret;        Caret c = caret;
323        if (c != null)        if (c != null)
324          c.setVisible(!c.isVisible());          c.setVisible(!c.isVisible());
325      }      }
326    
327      /**      /**
# Line 332  public abstract class JTextComponent ext Line 332  public abstract class JTextComponent ext
332        stop();        stop();
333        Caret c = caret;        Caret c = caret;
334        if (c != null)        if (c != null)
335          {          {
336            setDelay(c.getBlinkRate());            setDelay(c.getBlinkRate());
337            if (editable)            if (editable)
338              start();              start();
339            else            else
340              c.setVisible(false);              c.setVisible(false);
341          }          }
342      }      }
343    }    }
344    
# Line 628  public abstract class JTextComponent ext Line 628  public abstract class JTextComponent ext
628        int end = textComponent.getSelectionEnd();        int end = textComponent.getSelectionEnd();
629    
630        if (start == end)        if (start == end)
631          return;          return;
632    
633        try        try
634          {          {
635            // Copy text to clipboard.            // Copy text to clipboard.
636            String data = textComponent.getDocument().getText(start, end);            String data = textComponent.getDocument().getText(start, end);
637            StringSelection selection = new StringSelection(data);            StringSelection selection = new StringSelection(data);
638            clipboard.setContents(selection, null);            clipboard.setContents(selection, null);
639    
640            // Delete selected text on cut action.            // Delete selected text on cut action.
641            if (action == MOVE)            if (action == MOVE)
642              doc.remove(start, end - start);              doc.remove(start, end - start);
643          }          }
644        catch (BadLocationException e)        catch (BadLocationException e)
645          {          {
646            // Ignore this and do nothing.            // Ignore this and do nothing.
647          }          }
648      }      }
649            
650      public int getSourceActions()      public int getSourceActions()
# Line 658  public abstract class JTextComponent ext Line 658  public abstract class JTextComponent ext
658        DataFlavor[] flavors = transferable.getTransferDataFlavors();        DataFlavor[] flavors = transferable.getTransferDataFlavors();
659    
660        if (flavors == null)        if (flavors == null)
661          return false;          return false;
662    
663        for (int i = 0; i < flavors.length; ++i)        for (int i = 0; i < flavors.length; ++i)
664          if (flavors[i].equals(DataFlavor.stringFlavor))          if (flavors[i].equals(DataFlavor.stringFlavor))
665             flavor = flavors[i];            flavor = flavors[i];
666                
667        if (flavor == null)        if (flavor == null)
668          return false;          return false;
669    
670        try        try
671          {          {
672            JTextComponent textComponent = (JTextComponent) component;            JTextComponent textComponent = (JTextComponent) component;
673            String data = (String) transferable.getTransferData(flavor);            String data = (String) transferable.getTransferData(flavor);
674            textComponent.replaceSelection(data);            textComponent.replaceSelection(data);
675            return true;            return true;
676          }          }
677        catch (IOException e)        catch (IOException e)
678          {          {
679            // Ignored.            // Ignored.
680          }          }
681        catch (UnsupportedFlavorException e)        catch (UnsupportedFlavorException e)
682          {          {
683            // Ignored.            // Ignored.
684          }          }
685    
686        return false;        return false;
687      }      }
# Line 1018  public abstract class JTextComponent ext Line 1018  public abstract class JTextComponent ext
1018    {    {
1019      try      try
1020        {        {
1021          doc.remove(0, doc.getLength());          doc.remove(0, doc.getLength());
1022          doc.insertString(0, text, null);          doc.insertString(0, text, null);
1023        }        }
1024      catch (BadLocationException e)      catch (BadLocationException e)
1025        {        {
1026          // This can never happen.          // This can never happen.
1027        }        }
1028    }    }
1029    
# Line 1041  public abstract class JTextComponent ext Line 1041  public abstract class JTextComponent ext
1041    
1042      try      try
1043        {        {
1044          return doc.getText(0, doc.getLength());          return doc.getText(0, doc.getLength());
1045        }        }
1046      catch (BadLocationException e)      catch (BadLocationException e)
1047        {        {
1048          // This should never happen.          // This should never happen.
1049          return "";          return "";
1050        }        }
1051    }    }
1052    
# Line 1077  public abstract class JTextComponent ext Line 1077  public abstract class JTextComponent ext
1077    {    {
1078      try      try
1079        {        {
1080          return doc.getText(getSelectionStart(), getSelectionEnd());          return doc.getText(getSelectionStart(), getSelectionEnd());
1081        }        }
1082      catch (BadLocationException e)      catch (BadLocationException e)
1083        {        {
1084          // This should never happen.          // This should never happen.
1085          return null;          return null;
1086        }        }
1087    }    }
1088    
# Line 1421  public abstract class JTextComponent ext Line 1421  public abstract class JTextComponent ext
1421      // If content is empty delete selection.      // If content is empty delete selection.
1422      if (content == null)      if (content == null)
1423        {        {
1424          caret.setDot(dot);          caret.setDot(dot);
1425          return;          return;
1426        }        }
1427    
1428      try      try
1429        {        {
1430          int start = getSelectionStart();          int start = getSelectionStart();
1431          int end = getSelectionEnd();          int end = getSelectionEnd();
           
         // Remove selected text.  
         if (dot != mark)  
           doc.remove(start, end - start);  
1432    
1433          // Insert new text.          // Remove selected text.
1434          doc.insertString(start, content, null);          if (dot != mark)
1435              doc.remove(start, end - start);
1436    
1437          // Set dot to new position.          // Insert new text.
1438          setCaretPosition(start + content.length());          doc.insertString(start, content, null);
1439    
1440            // Set dot to new position.
1441            setCaretPosition(start + content.length());
1442        }        }
1443      catch (BadLocationException e)      catch (BadLocationException e)
1444        {        {
1445          // This should never happen.          // This should never happen.
1446        }        }
1447    }    }
1448    
# Line 1576  public abstract class JTextComponent ext Line 1576  public abstract class JTextComponent ext
1576      // Install default TransferHandler if none set.      // Install default TransferHandler if none set.
1577      if (getTransferHandler() == null)      if (getTransferHandler() == null)
1578        {        {
1579          if (defaultTransferHandler == null)          if (defaultTransferHandler == null)
1580            defaultTransferHandler = new DefaultTransferHandler();            defaultTransferHandler = new DefaultTransferHandler();
1581            
1582          setTransferHandler(defaultTransferHandler);          setTransferHandler(defaultTransferHandler);
1583        }        }
1584    
1585      // Perform action.      // Perform action.
1586      ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,      ActionEvent event = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
1587                                          action.getValue(Action.NAME).toString());                                          action.getValue(Action.NAME).toString());
1588      action.actionPerformed(event);      action.actionPerformed(event);
1589    }    }
1590    

Legend:
Removed from v.1.38  
changed lines
  Added in v.1.39

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