|
What this is
Other links
The source code
/*
* Java14.java - Java 2 version 1.4 API calls
* :tabSize=8:indentSize=8:noTabs=false:
* :folding=explicit:collapseFolds=1:
*
* Copyright (C) 2001, 2004 Slava Pestov
*
* 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 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, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package org.gjt.sp.jedit;
//{{{ Imports
import javax.swing.event.*;
import javax.swing.*;
import java.awt.datatransfer.*;
import java.awt.dnd.*;
import java.awt.event.*;
import java.awt.*;
import java.io.File;
import java.util.Iterator;
import java.util.List;
import org.gjt.sp.jedit.gui.*;
import org.gjt.sp.jedit.msg.*;
import org.gjt.sp.jedit.textarea.*;
import org.gjt.sp.util.Log;
//}}}
/**
* This file must be compiled with a JDK 1.4 or higher javac. If you are using
* an older Java version and wish to compile from source, you can safely leave
* this file out.
* @since jEdit 4.0pre4
* @author Slava Pestov
* @version $Id: Java14.java,v 1.36 2004/07/12 19:25:07 spestov Exp $
*/
public class Java14
{
//{{{ init() method
public static void init()
{
JFrame.setDefaultLookAndFeelDecorated(
jEdit.getBooleanProperty("decorate.frames"));
JDialog.setDefaultLookAndFeelDecorated(
jEdit.getBooleanProperty("decorate.dialogs"));
KeyboardFocusManager.setCurrentKeyboardFocusManager(
new MyFocusManager());
EditBus.addToBus(new EBComponent()
{
public void handleMessage(EBMessage msg)
{
if(msg instanceof ViewUpdate)
{
ViewUpdate vu = (ViewUpdate)msg;
if(vu.getWhat() == ViewUpdate.CREATED)
{
vu.getView().setFocusTraversalPolicy(
new MyFocusTraversalPolicy());
}
}
else if(msg instanceof EditPaneUpdate)
{
EditPaneUpdate eu = (EditPaneUpdate)msg;
if(eu.getWhat() == EditPaneUpdate.CREATED)
{
initTextArea(eu.getEditPane()
.getTextArea());
}
}
}
});
Clipboard selection = Toolkit.getDefaultToolkit().getSystemSelection();
if(selection != null)
{
Log.log(Log.DEBUG,Java14.class,"Setting % register"
+ " to system selection");
Registers.setRegister('%',new Registers.ClipboardRegister(selection));
}
} //}}}
//{{{ dragAndDropCallback() method
/**
* Called by the text area via reflection to initiate a text drag and
* drop operation using the JDK 1.4 API.
* @since jEdit 4.2pre5
*/
public static void dragAndDropCallback(JEditTextArea textArea,
InputEvent evt, boolean copy)
{
Log.log(Log.DEBUG,Java14.class,"Drag and drop callback");
TransferHandler handler = textArea.getTransferHandler();
handler.exportAsDrag(textArea,evt,
copy ? TransferHandler.COPY
: TransferHandler.MOVE);
} //}}}
//{{{ initTextArea() method
static void initTextArea(JEditTextArea textArea)
{
textArea.addMouseWheelListener(new MouseWheelHandler());
// drag and drop support
// I'd just move the code to
// JEditTextArea but it
// depends on JDK 1.4 APIs
textArea.setTransferHandler(new TextAreaTransferHandler());
try
{
textArea.getDropTarget().addDropTargetListener(
new DropHandler(textArea));
textArea.setDragAndDropCallback(
Java14.class.getMethod("dragAndDropCallback",
new Class[] { JEditTextArea.class,
InputEvent.class, boolean.class }));
}
catch(Exception e)
{
Log.log(Log.ERROR,Java14.class,e);
}
} //}}}
//{{{ initBufferSwitcher() method
public static void initBufferSwitcher(final EditPane pane,
BufferSwitcher switcher)
{
switcher.addPopupMenuListener(new PopupMenuListener()
{
public void popupMenuWillBecomeVisible(
PopupMenuEvent e) {}
public void popupMenuWillBecomeInvisible(
PopupMenuEvent e)
{
pane.getTextArea().requestFocus();
}
public void popupMenuCanceled(PopupMenuEvent e)
{
pane.getTextArea().requestFocus();
}
});
} //}}}
//{{{ MyFocusManager class
static class MyFocusManager extends DefaultKeyboardFocusManager
{
MyFocusManager()
{
setDefaultFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
}
public boolean postProcessKeyEvent(KeyEvent evt)
{
if(!evt.isConsumed())
{
Component comp = (Component)evt.getSource();
if(!comp.isShowing())
return true;
for(;;)
{
if(comp instanceof View)
{
((View)comp).processKeyEvent(evt,
View.VIEW);
return true;
}
else if(comp == null || comp instanceof Window
|| comp instanceof JEditTextArea)
{
break;
}
else
comp = comp.getParent();
}
}
return super.postProcessKeyEvent(evt);
}
} //}}}
//{{{ MyFocusTraversalPolicy class
static class MyFocusTraversalPolicy extends LayoutFocusTraversalPolicy
{
public Component getDefaultComponent(Container focusCycleRoot)
{
return GUIUtilities.getView(focusCycleRoot).getTextArea();
}
} //}}}
//{{{ MouseWheelHandler class
static class MouseWheelHandler implements MouseWheelListener
{
public void mouseWheelMoved(MouseWheelEvent e)
{
JEditTextArea textArea = (JEditTextArea)e.getSource();
/****************************************************
* move caret depending on pressed control-keys:
* - Alt: move cursor, do not select
* - Alt+(shift or control): move cursor, select
* - shift: scroll page
* - control: scroll single line
* -
|
| ... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2024 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.