2
2
* java-gnome, a UI library for writing GTK and GNOME programs from Java!
4
* Copyright © 2007-2010 Operational Dynamics Consulting, Pty Ltd
4
* Copyright © 2007-2011 Operational Dynamics Consulting, Pty Ltd
5
5
* Copyright © 2007 Vreixo Formoso
7
7
* The code in this file, and the program it is a part of, is made available
113
117
* FIXME describe the implications of different choices for name.
115
119
public Action(String name, String label, String tooltip, Stock stock, Action.Activate handler) {
116
super(GtkAction.createAction(name, label, tooltip, stock.getStockId()));
120
super(GtkAction.createAction(name, label, tooltip, (stock == null ? null : stock.getStockId())));
125
* Create a new Action, and connect a handler to its
126
* <code>Action.Activate</code> signal.
129
* A unique name for the Action.
131
* The text that will be displayed in the proxy Widgets. You
132
* usually will want to localize it to the user language.
134
* A Tooltip or little help message for the Action. Also
137
* The Icon to display in proxy Widgets.
139
* A handler to connect to the <code>Action.Activate</code>
140
* signal. Typically this will be used to actually start the
141
* operation related to this Action.
144
public Action(String name, String label, String tooltip, Icon icon, Action.Activate handler) {
145
super(GtkAction.createAction(name, label, tooltip, null));
146
GtkAction.setIconName(this, Helper.getName(icon));
117
147
connect(handler);
141
171
public Action(String name, String label, String tooltip, Stock stock) {
142
super(GtkAction.createAction(name, label, tooltip, stock.getStockId()));
172
super(GtkAction.createAction(name, label, tooltip, (stock == null ? null : stock.getStockId())));
176
* Create a new Action.
179
* A unique name for the Action.
181
* The text that will be displayed in the proxy Widgets. You
182
* usually will want to localize it to the user language.
184
* A Tooltip or little help message for the Action. Also
187
* The Icon to display in proxy Widgets.
190
public Action(String name, String label, String tooltip, Icon icon) {
191
super(GtkAction.createAction(name, label, tooltip, null));
192
GtkAction.setIconName(this, Helper.getName(icon));
151
201
public Action(String name, Stock stock) {
152
super(GtkAction.createAction(name, null, null, stock.getStockId()));
202
super(GtkAction.createAction(name, null, null, (stock == null ? null : stock.getStockId())));
471
521
* <code>nifty</code>'s <code>Action.Activate</code> signal being called.
475
526
public void connectProxy(Widget proxy) {
476
GtkAction.connectProxy(this, proxy);
527
Activatable activatable;
529
assert false : "Use the Activatable's setRelatedAction() instead";
531
activatable = (Activatable) proxy;
532
activatable.setRelatedAction(this);
536
* Specify a key binding to trigger this Action, as actually specified by
537
* the Stock item being used. This assumes, of course that you
538
* instantiated this Action using one of the Stock constructors, ie
539
* {@link #Action(String, Stock) <init>(Stock)}.
542
* TODO this appears to be parallel to ImageMenuItem's setAccelerator(),
543
* but testing couldn't show it to actually have any effect. It would be
544
* nice if we could figure it out, but for now the convenience in the
545
* other setAccelerator() takes care of things.
547
void setAccelerator(AcceleratorGroup group) {
548
GtkAction.setAccelGroup(this, group);
552
* Specify a key binding to trigger this Action. You need to use the same
553
* group object as was (or will be) passed to Window's
554
* {@link Window#addAcceleratorGroup(AcceleratorGroup)
555
* addAcceleratorGroup()}.
560
* This call also sets the AcceleratorGroup for this Action as a
561
* convenience allowing us to avoid having to make an otherwise
562
* unnecessary additional public API call and makes this parallel with
563
* MenuItem and ImageMenuItem.
565
public void setAccelerator(AcceleratorGroup group, Keyval keyval, ModifierType modifier) {
567
boolean exists, result;
569
GtkAction.setAccelGroup(this, group);
571
path = GtkAction.getAccelPath(this);
575
path = group.generateRandomPath();
576
GtkAction.setAccelPath(this, path);
577
GtkAction.connectAccelerator(this);
579
exists = GtkAccelMap.lookupEntry(path, null);
583
result = GtkAccelMap.changeEntry(path, keyval, modifier, true);
586
throw new IllegalStateException("Can't change exising accelerator");
589
GtkAccelMap.addEntry(path, keyval, modifier);