// ReverseSelection.java
// Cyno's Editor Plug-In

// Cynosure.X International
// 10-30-1997

// Copyright (C) 1997, 1998 by Chieh Cheng.
// All Rights Reserved.

// This plug-in reverses the selected text.

package plug_ins;

import cynosurex.awt.*;

public class ReverseSelection
{
  // This variable specifies the string to be displayed
  // by Cyno's Editor.
  // This variable is required for all plug-ins.

  public final static String description = "Reverse Selection";

  // This constructor is the constructor
  // to be executed by Cyno's Editor.
  // This constructor is required for all plug-ins.

  public ReverseSelection (ShareData shared)
  {
    EnhancedTextArea eta = shared.getTextArea ();
    int start = eta.getSelectionStart ();
    int end = eta.getSelectionEnd ();

    if (start != end)
    {
      String str = eta.getSelectedText ();
      StringBuffer buffer = new StringBuffer (str.length ());

      for (int i = str.length () - 1; i >= 0; i--)
      {
        buffer.append (str.charAt (i));
      }

      eta.replaceRange (buffer.toString (), start, end);
      eta.select (start, end);
    }
  }
}
