Git Product home page Git Product logo

Comments (8)

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Problem re-created.  I'm investigating it now...

Original comment by [email protected] on 12 Aug 2008 at 6:44

  • Changed state: Accepted

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Problem is that in SyntaxActions, at about line 340 (labeled 7 here):
1    public static void addAction(JTextComponent control, String stroke,
2            TextAction action) {
3        KeyStroke ks = KeyStroke.getKeyStroke(stroke);
4        if (ks == null) {
5            throw new IllegalArgumentException("invalid keystroke: " + stroke);
6        }
7        control.getKeymap().addActionForKeyStroke(ks, action);
8    }

The same keymap is used by all EditorPanes.  Probably the default one.  Need a 
way to
add bindings to a specific keymap just for that pane.  I'll research the Keymap
hierarchy classes later when I have a chance.  

Could be tricky, but a very good bug catch!

Original comment by [email protected] on 12 Aug 2008 at 7:05

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Looked at Swing keymaps, and so far no idea how to resolve this.  Most keymap 
methods
are static methods of the TextComponent.  So how can I add a key binding to 
just one
component?  Any ideas anybody?

Original comment by [email protected] on 15 Aug 2008 at 8:15

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Thanks @javlopez for finding this tricky issue!

Think we should create a custom Keymap and do setKeymap() on JTextComponent. 
When we
do a getKeymap(), this custom object will be returned to us. I don't know if we 
can
clone() the existing Keymap and set it again:

// init code
Keymap commonKeymap = control.getKeymap();
Keymap customKeymap = (Keymap)((Colonable)commonKeymap).clone();
control.setKeymap(customKeymap);

// Later
control.getKeymap().addActionForKeyStroke(ks, action);

Original comment by subwiz on 16 Aug 2008 at 7:29

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
I am getting class cast exception when trying to cast to Cloneable! So above 
approach
does not hold good!

Original comment by subwiz on 16 Aug 2008 at 8:06

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
<quote>
JTextComponent defines getKeymap() and setKeymap() methods you can use to query 
and
set the current keymap of a text component. There are no public implementations 
of
the Keymap  interface, so you cannot instantiate one directly. Instead, create 
a new
Keymap by calling the static JTextComponent.addKeymap() method. This method 
allows
you to specify a name and parent for the new Keymap. Both arguments are 
optional,
however, so you may pass in null.
</quote>

From: http://www.unix.com.ua/orelly/java-ent/jfc/ch03_08.htm

And see this for creating private keymap which is used only by our component:

http://books.google.com/books?id=E0HGXKrxcS8C&pg=PA89&lpg=PA89&dq=swing+Keymap+c
ommon+to+all+component&source=web&ots=jeZVgHPlH5&sig=wArw85z8_ZV_q9FZKvCsQt9FHEA
&hl=en&sa=X&oi=book_result&resnum=3&ct=result

So basically, it is:

// init
Keymap jsyntaxpaneKeyMap = JTextComponent.addKeymap(null,
JTextComponent.getKeymap(JTextComponent.DEFAULT_KEYMAP);

// immdtly after creating TextComponent:
control.setKeymap(jsyntaxpaneKeyMap);

// Now, this should work:
control.getKeymap().addActionForKeyStroke(ks, action);

Original comment by subwiz on 16 Aug 2008 at 8:22

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Rev. 30 has a fix. Let me know if it works!

Original comment by subwiz on 16 Aug 2008 at 8:58

  • Changed state: Fixed

from jsyntaxpane.

GoogleCodeExporter avatar GoogleCodeExporter commented on August 30, 2024
Another regression issue was fixed in rev.31.

Original comment by subwiz on 16 Aug 2008 at 9:35

from jsyntaxpane.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.