view scripts/java/org/octave/DlgListener.java @ 15733:628011b1bd2f

maint: Remove unnecessary execute permissions from newly added java files. * libinterp/dldfcn/__java__.h, scripts/java/java.m, scripts/java/javafields.m, scripts/java/javamethods.m, scripts/java/javarmpath.m, scripts/java/org/octave/DlgListener.java, scripts/java/org/octave/JDialogBox.java, scripts/java/org/octave/TeXcode.java, scripts/java/org/octave/TeXtranslator.java, scripts/java/org/octave/images/error.png, scripts/java/org/octave/images/information.png, scripts/java/org/octave/images/octave.png, scripts/java/org/octave/images/question.png, scripts/java/org/octave/images/warning.png: Remove unnecessary execute permissions.
author Rik <rik@octave.org>
date Thu, 06 Dec 2012 08:22:32 -0800
parents acf0addfc610
children 6e39fe7992d9
line wrap: on
line source

/*
 ** Copyright (C) 2010 Martin Hepperle
 **
 ** This program is free software; you can redistribute it and/or modify
 ** it under the terms of the GNU General Public License as published by
 ** the Free Software Foundation; either version 2 of the License, or
 ** (at your option) any later version.
 **
 ** This program is distributed in the hope that it will be useful,
 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 ** GNU General Public License for more details.
 **
 ** You should have received a copy of the GNU General Public License
 ** along with this program; If not, see <http://www.gnu.org/licenses/>.
 */

package org.octave;

import java.awt.event.*;
import javax.swing.*;

/**
 * <p>Implements button click actions for dialog box functions</p>
 *
 * <p>Copyright (c) 2010 Martin Hepperle</p>
 *
 * @author Martin Hepperle
 * @version 1.0
 */
public class DlgListener
   extends WindowAdapter implements ActionListener, KeyListener
{
   // the parent frame of the dialog
   JDialogBox m_Parent;

   public DlgListener ( JDialogBox d )
   {
      m_Parent = d;
   }


   //
   // --- extension of the WindowAdapter class ---
   //
   /**
    * Called when the user clicks the close button on the window frame.
    *
    * @param e WindowEvent
    */
   public void windowClosing ( WindowEvent e )
   {
      m_Parent.closeDialog ( JDialogBox.CLOSE_CANCEL );
   }

   public void windowOpened( WindowEvent e )
   {
      m_Parent.setFocus();
   }


   //
   // --- implementation of the ActionListener interface ---
   //
   /**
    * Called when the user clicks a button in the dialog.
    * Closes the dialog when either a button with an
    * action command OK, CANCEL or NO is pressed.
    *
    * @param e ActionEvent
    */
   public void actionPerformed ( ActionEvent e )
   {
      if ( e.getActionCommand ().equals ( "OK" ) )
      {
         m_Parent.closeDialog ( JDialogBox.CLOSE_OK );
      }
      else if ( e.getActionCommand ().equals ( "CANCEL" ) )
      {
         m_Parent.closeDialog ( JDialogBox.CLOSE_CANCEL );
      }
      else if ( e.getActionCommand ().equals ( "NO" ) )
      {
         m_Parent.closeDialog ( JDialogBox.CLOSE_NO );
      }
      else if ( e.getActionCommand ().equals ( "SELALL" ) )
      {
         m_Parent.SelectAll ();
      }
   }


   //
   // --- implementation of the KeyListener interface ---
   //
   /**
    * Closes the dialog when the ENTER or ESCAPE keys are released.
    *
    * @param e KeyEvent
    */
   public void keyTyped ( KeyEvent e )
   {
      if ( e.getKeyCode () == KeyEvent.VK_ESCAPE )
      {
         m_Parent.closeDialog ( JDialogBox.CLOSE_CANCEL );
      }
   }


   /**
    * @param e KeyEvent
    */
   public void keyPressed ( KeyEvent e )
   {
      if ( e.getSource ().getClass ().equals ( JTextArea.class ) )
      {
         JTextArea ta = ( JTextArea ) e.getSource ();
         if ( e.getKeyCode () == KeyEvent.VK_ENTER )
         {
            char c[] = ta.getText ().toCharArray ();
            int nLines = 1;
            for ( int i = 0; i < c.length; i++ )
            {
               if ( c[i] == '\n' )
               {
                  nLines++;
               }
            }

            if ( nLines >= ta.getRows () )
            {
               e.consume ();
            }
         }
         else if ( e.getKeyCode () == KeyEvent.VK_TAB )
         {
            e.consume ();

            if ( ( e.getModifiersEx () & KeyEvent.SHIFT_DOWN_MASK ) ==
                 KeyEvent.SHIFT_DOWN_MASK )
            {
               ta.transferFocusBackward();
            }
            else
            {
               ta.transferFocus ();
            }
         }
      }
   }


   /**
    * @param e KeyEvent
    */
   public void keyReleased ( KeyEvent e )
   {
   }
}