~ubuntu-branches/ubuntu/natty/java-gnome/natty

« back to all changes in this revision

Viewing changes to src/bindings/org/gnome/gtk/Action.java

  • Committer: Bazaar Package Importer
  • Author(s): Guillaume Mazoyer
  • Date: 2011-02-18 17:46:52 UTC
  • mfrom: (1.1.7 upstream)
  • Revision ID: james.westby@ubuntu.com-20110218174652-mk7ajkt790es0jwr
Tags: 4.0.19-0ubuntu1
* New upstream release. (LP: #596252) (Forwarded: Debian: 588943)
* debian/control
  - Update dependencies version according to the upstream configure file.
  - Update Standards-Version to 3.9.1.
  - Sync JNI and JAR packages.
* debian/copyright
  - Update copyright to 2011.
* debian/patches/01_take_screenshots.diff
  - Fix patch to make doc screenshots works.
* debian/patches/02_javadoc_workaround.patch
  - Fix javadoc generation.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
2
 * java-gnome, a UI library for writing GTK and GNOME programs from Java!
3
3
 *
4
 
 * Copyright © 2007-2010 Operational Dynamics Consulting, Pty Ltd
 
4
 * Copyright © 2007-2011 Operational Dynamics Consulting, Pty Ltd
5
5
 * Copyright © 2007      Vreixo Formoso
6
6
 *
7
7
 * The code in this file, and the program it is a part of, is made available
33
33
 */
34
34
package org.gnome.gtk;
35
35
 
 
36
import org.freedesktop.icons.Helper;
 
37
import org.freedesktop.icons.Icon;
 
38
import org.gnome.gdk.Keyval;
 
39
import org.gnome.gdk.ModifierType;
36
40
import org.gnome.glib.Object;
37
41
 
38
42
/**
113
117
     * FIXME describe the implications of different choices for name.
114
118
     */
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())));
 
121
        connect(handler);
 
122
    }
 
123
 
 
124
    /**
 
125
     * Create a new Action, and connect a handler to its
 
126
     * <code>Action.Activate</code> signal.
 
127
     * 
 
128
     * @param name
 
129
     *            A unique name for the Action.
 
130
     * @param label
 
131
     *            The text that will be displayed in the proxy Widgets. You
 
132
     *            usually will want to localize it to the user language.
 
133
     * @param tooltip
 
134
     *            A Tooltip or little help message for the Action. Also
 
135
     *            localized.
 
136
     * @param icon
 
137
     *            The Icon to display in proxy Widgets.
 
138
     * @param handler
 
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.
 
142
     * @since 4.0.19
 
143
     */
 
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);
118
148
    }
119
149
 
139
169
     * @since 4.0.4
140
170
     */
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())));
 
173
    }
 
174
 
 
175
    /**
 
176
     * Create a new Action.
 
177
     * 
 
178
     * @param name
 
179
     *            A unique name for the Action.
 
180
     * @param label
 
181
     *            The text that will be displayed in the proxy Widgets. You
 
182
     *            usually will want to localize it to the user language.
 
183
     * @param tooltip
 
184
     *            A Tooltip or little help message for the Action. Also
 
185
     *            localized.
 
186
     * @param icon
 
187
     *            The Icon to display in proxy Widgets.
 
188
     * @since 4.0.19
 
189
     */
 
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));
143
193
    }
144
194
 
145
195
    /**
149
199
     * @since 4.0.7
150
200
     */
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())));
153
203
    }
154
204
 
155
205
    /**
450
500
     * nifty.setTooltip(&quot;This will result in amazingly nifty things happening&quot;);
451
501
     * nifty.connect(new Action.Activate() {
452
502
     *     public void onActivate(Action source) {
453
 
     *     // do something cool
 
503
     *         // do something cool
454
504
     *     }
455
505
     * });
456
506
     * 
471
521
     * <code>nifty</code>'s <code>Action.Activate</code> signal being called.
472
522
     * 
473
523
     * @since 4.0.6
 
524
     * @deprecated
474
525
     */
475
526
    public void connectProxy(Widget proxy) {
476
 
        GtkAction.connectProxy(this, proxy);
 
527
        Activatable activatable;
 
528
 
 
529
        assert false : "Use the Activatable's setRelatedAction() instead";
 
530
 
 
531
        activatable = (Activatable) proxy;
 
532
        activatable.setRelatedAction(this);
 
533
    }
 
534
 
 
535
    /**
 
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) &lt;init&gt;(Stock)}.
 
540
     */
 
541
    /*
 
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.
 
546
     */
 
547
    void setAccelerator(AcceleratorGroup group) {
 
548
        GtkAction.setAccelGroup(this, group);
 
549
    }
 
550
 
 
551
    /**
 
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()}.
 
556
     * 
 
557
     * @since 4.0.16
 
558
     */
 
559
    /*
 
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.
 
564
     */
 
565
    public void setAccelerator(AcceleratorGroup group, Keyval keyval, ModifierType modifier) {
 
566
        String path;
 
567
        boolean exists, result;
 
568
 
 
569
        GtkAction.setAccelGroup(this, group);
 
570
 
 
571
        path = GtkAction.getAccelPath(this);
 
572
 
 
573
        if (path == null) {
 
574
            exists = false;
 
575
            path = group.generateRandomPath();
 
576
            GtkAction.setAccelPath(this, path);
 
577
            GtkAction.connectAccelerator(this);
 
578
        } else {
 
579
            exists = GtkAccelMap.lookupEntry(path, null);
 
580
        }
 
581
 
 
582
        if (exists) {
 
583
            result = GtkAccelMap.changeEntry(path, keyval, modifier, true);
 
584
 
 
585
            if (!result) {
 
586
                throw new IllegalStateException("Can't change exising accelerator");
 
587
            }
 
588
        } else {
 
589
            GtkAccelMap.addEntry(path, keyval, modifier);
 
590
        }
477
591
    }
478
592
}