~ubuntu-branches/debian/stretch/insubstantial/stretch

« back to all changes in this revision

Viewing changes to flamingo/src/main/java/org/pushingpixels/flamingo/api/common/AbstractCommandButton.java

  • Committer: Package Import Robot
  • Author(s): Felix Natter
  • Date: 2016-01-18 20:58:45 UTC
  • Revision ID: package-import@ubuntu.com-20160118205845-crbmrkda61qsi5qa
Tags: upstream-7.3+dfsg2
ImportĀ upstreamĀ versionĀ 7.3+dfsg2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright (c) 2005-2010 Flamingo Kirill Grouchnikov. All Rights Reserved.
 
3
 *
 
4
 * Redistribution and use in source and binary forms, with or without 
 
5
 * modification, are permitted provided that the following conditions are met:
 
6
 * 
 
7
 *  o Redistributions of source code must retain the above copyright notice, 
 
8
 *    this list of conditions and the following disclaimer. 
 
9
 *     
 
10
 *  o Redistributions in binary form must reproduce the above copyright notice, 
 
11
 *    this list of conditions and the following disclaimer in the documentation 
 
12
 *    and/or other materials provided with the distribution. 
 
13
 *     
 
14
 *  o Neither the name of Flamingo Kirill Grouchnikov nor the names of 
 
15
 *    its contributors may be used to endorse or promote products derived 
 
16
 *    from this software without specific prior written permission. 
 
17
 *     
 
18
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 
 
19
 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, 
 
20
 * THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
 
21
 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 
 
22
 * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
 
23
 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 
 
24
 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; 
 
25
 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, 
 
26
 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE 
 
27
 * OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, 
 
28
 * EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 
 
29
 */
 
30
package org.pushingpixels.flamingo.api.common;
 
31
 
 
32
import java.awt.Dimension;
 
33
import java.awt.Rectangle;
 
34
import java.awt.event.*;
 
35
 
 
36
import javax.accessibility.AccessibleContext;
 
37
import javax.swing.ButtonModel;
 
38
import javax.swing.SwingConstants;
 
39
import javax.swing.event.*;
 
40
 
 
41
import org.pushingpixels.flamingo.api.common.icon.ResizableIcon;
 
42
import org.pushingpixels.flamingo.api.common.model.ActionButtonModel;
 
43
import org.pushingpixels.flamingo.internal.ui.common.CommandButtonUI;
 
44
 
 
45
/**
 
46
 * Base class for command buttons.
 
47
 * 
 
48
 * @author Kirill Grouchnikov
 
49
 */
 
50
public abstract class AbstractCommandButton extends
 
51
                RichToolTipManager.JTrackableComponent {
 
52
        /**
 
53
         * Associated icon.
 
54
         * 
 
55
         * @see #setIcon(ResizableIcon)
 
56
         * @see #getIcon()
 
57
         */
 
58
        protected ResizableIcon icon;
 
59
 
 
60
        /**
 
61
         * Associated disabled icon.
 
62
         * 
 
63
         * @see #setDisabledIcon(ResizableIcon)
 
64
         * @see #getDisabledIcon()
 
65
         */
 
66
        protected ResizableIcon disabledIcon;
 
67
 
 
68
        /**
 
69
         * The button text.
 
70
         * 
 
71
         * @see #setText(String)
 
72
         * @see #getText()
 
73
         */
 
74
        private String text;
 
75
 
 
76
        /**
 
77
         * The button action model.
 
78
         * 
 
79
         * @see #getActionModel()
 
80
         * @see #setActionModel(ActionButtonModel)
 
81
         */
 
82
        protected ActionButtonModel actionModel;
 
83
 
 
84
        /**
 
85
         * Additional text. This is shown for {@link CommandButtonDisplayState#TILE}
 
86
         * .
 
87
         * 
 
88
         * @see #setExtraText(String)
 
89
         * @see #getExtraText()
 
90
         */
 
91
        protected String extraText;
 
92
 
 
93
        /**
 
94
         * Current display state of <code>this</code> button.
 
95
         * 
 
96
         * @see #setDisplayState(CommandButtonDisplayState)
 
97
         * @see #getDisplayState()
 
98
         */
 
99
        protected CommandButtonDisplayState displayState;
 
100
 
 
101
        /**
 
102
         * The dimension of the icon of the associated command button in the
 
103
         * {@link CommandButtonDisplayState#FIT_TO_ICON} state.
 
104
         * 
 
105
         * @see #getCustomDimension()
 
106
         * @see #updateCustomDimension(int)
 
107
         */
 
108
        protected int customDimension;
 
109
 
 
110
        /**
 
111
         * Indication whether this button is flat.
 
112
         * 
 
113
         * @see #setFlat(boolean)
 
114
         * @see #isFlat()
 
115
         */
 
116
        protected boolean isFlat;
 
117
 
 
118
        /**
 
119
         * Horizontal alignment of the content.
 
120
         * 
 
121
         * @see #setHorizontalAlignment(int)
 
122
         * @see #getHorizontalAlignment()
 
123
         */
 
124
        private int horizontalAlignment;
 
125
 
 
126
        /**
 
127
         * Scale factor for horizontal gaps.
 
128
         * 
 
129
         * @see #setHGapScaleFactor(double)
 
130
         * @see #getHGapScaleFactor()
 
131
         */
 
132
        private double hgapScaleFactor;
 
133
 
 
134
        /**
 
135
         * Scale factor for vertical gaps.
 
136
         * 
 
137
         * @see #setVGapScaleFactor(double)
 
138
         * @see #getVGapScaleFactor()
 
139
         */
 
140
        private double vgapScaleFactor;
 
141
 
 
142
        /**
 
143
         * Rich tooltip for the action area.
 
144
         * 
 
145
         * @see #setActionRichTooltip(RichTooltip)
 
146
         * @see #getRichTooltip(MouseEvent)
 
147
         */
 
148
        private RichTooltip actionRichTooltip;
 
149
 
 
150
        /**
 
151
         * Location order kind for buttons placed in command button strips or for
 
152
         * buttons that need the visuals of segmented strips.
 
153
         * 
 
154
         * @see #setLocationOrderKind(CommandButtonLocationOrderKind)
 
155
         * @see #getLocationOrderKind()
 
156
         */
 
157
        private CommandButtonLocationOrderKind locationOrderKind;
 
158
 
 
159
        /**
 
160
         * Action handler for the button.
 
161
         */
 
162
        protected ActionHandler actionHandler;
 
163
 
 
164
        /**
 
165
         * Key tip for the action area.
 
166
         * 
 
167
         * @see #setActionKeyTip(String)
 
168
         * @see #getActionKeyTip()
 
169
         */
 
170
        protected String actionKeyTip;
 
171
 
 
172
        /**
 
173
         * Enumerates the available values for the location order kind. This is used
 
174
         * for buttons placed in command button strips or for buttons that need the
 
175
         * visuals of segmented strips.
 
176
         * 
 
177
         * @author Kirill Grouchnikov
 
178
         */
 
179
        public static enum CommandButtonLocationOrderKind {
 
180
                /**
 
181
                 * Indicates that this button is the only button in the strip.
 
182
                 */
 
183
                ONLY,
 
184
 
 
185
                /**
 
186
                 * Indicates that this button is the first button in the strip.
 
187
                 */
 
188
                FIRST,
 
189
 
 
190
                /**
 
191
                 * Indicates that this button is in the middle of the strip.
 
192
                 */
 
193
                MIDDLE,
 
194
 
 
195
                /**
 
196
                 * Indicates that this button is the last button in the strip.
 
197
                 */
 
198
                LAST
 
199
        }
 
200
 
 
201
        /**
 
202
         * Creates a new command button.
 
203
         * 
 
204
         * @param text
 
205
         *            Button title. May contain any number of words.
 
206
         * @param icon
 
207
         *            Button icon.
 
208
         */
 
209
        public AbstractCommandButton(String text, ResizableIcon icon) {
 
210
                this.icon = icon;
 
211
                this.customDimension = -1;
 
212
                this.displayState = CommandButtonDisplayState.FIT_TO_ICON;
 
213
                this.horizontalAlignment = SwingConstants.CENTER;
 
214
                this.actionHandler = new ActionHandler();
 
215
                this.isFlat = true;
 
216
                this.hgapScaleFactor = 1.0;
 
217
                this.vgapScaleFactor = 1.0;
 
218
                this.setText(text);
 
219
                this.setOpaque(false);
 
220
        }
 
221
 
 
222
        /**
 
223
         * Sets the new UI delegate.
 
224
         * 
 
225
         * @param ui
 
226
         *            New UI delegate.
 
227
         */
 
228
        public void setUI(CommandButtonUI ui) {
 
229
                super.setUI(ui);
 
230
        }
 
231
 
 
232
        /**
 
233
         * Returns the UI delegate for this button.
 
234
         * 
 
235
         * @return The UI delegate for this button.
 
236
         */
 
237
        public CommandButtonUI getUI() {
 
238
                return (CommandButtonUI) ui;
 
239
        }
 
240
 
 
241
        /**
 
242
         * Sets new display state for <code>this</code> button. Fires a
 
243
         * <code>displayState</code> property change event.
 
244
         * 
 
245
         * @param state
 
246
         *            New display state.
 
247
         * @see #getDisplayState()
 
248
         */
 
249
        public void setDisplayState(CommandButtonDisplayState state) {
 
250
                CommandButtonDisplayState old = this.displayState;
 
251
                this.displayState = state;
 
252
 
 
253
                this.firePropertyChange("displayState", old, this.displayState);
 
254
        }
 
255
 
 
256
        /**
 
257
         * Returns the associated icon.
 
258
         * 
 
259
         * @return The associated icon.
 
260
         * @see #getDisabledIcon()
 
261
         * @see #setIcon(ResizableIcon)
 
262
         */
 
263
        public ResizableIcon getIcon() {
 
264
                return icon;
 
265
        }
 
266
 
 
267
        /**
 
268
         * Sets new icon for this button. Fires an <code>icon</code> property change
 
269
         * event.
 
270
         * 
 
271
         * @param defaultIcon
 
272
         *            New default icon for this button.
 
273
         * @see #setDisabledIcon(ResizableIcon)
 
274
         * @see #getIcon()
 
275
         */
 
276
        public void setIcon(ResizableIcon defaultIcon) {
 
277
                ResizableIcon oldValue = this.icon;
 
278
                this.icon = defaultIcon;
 
279
 
 
280
                firePropertyChange("icon", oldValue, defaultIcon);
 
281
                if (defaultIcon != oldValue) {
 
282
                        if (defaultIcon == null || oldValue == null
 
283
                                        || defaultIcon.getIconWidth() != oldValue.getIconWidth()
 
284
                                        || defaultIcon.getIconHeight() != oldValue.getIconHeight()) {
 
285
                                revalidate();
 
286
                        }
 
287
                        repaint();
 
288
                }
 
289
        }
 
290
 
 
291
        /**
 
292
         * Sets the disabled icon for this button.
 
293
         * 
 
294
         * @param disabledIcon
 
295
         *            Disabled icon for this button.
 
296
         * @see #setIcon(ResizableIcon)
 
297
         * @see #getDisabledIcon()
 
298
         */
 
299
        public void setDisabledIcon(ResizableIcon disabledIcon) {
 
300
                this.disabledIcon = disabledIcon;
 
301
        }
 
302
 
 
303
        /**
 
304
         * Returns the associated disabled icon.
 
305
         * 
 
306
         * @return The associated disabled icon.
 
307
         * @see #setDisabledIcon(ResizableIcon)
 
308
         * @see #getIcon()
 
309
         */
 
310
        public ResizableIcon getDisabledIcon() {
 
311
                return disabledIcon;
 
312
        }
 
313
 
 
314
        /**
 
315
         * Return the current display state of <code>this</code> button.
 
316
         * 
 
317
         * @return The current display state of <code>this</code> button.
 
318
         * @see #setDisplayState(CommandButtonDisplayState)
 
319
         */
 
320
        public CommandButtonDisplayState getDisplayState() {
 
321
                return displayState;
 
322
        }
 
323
 
 
324
        /**
 
325
         * Returns the extra text of this button.
 
326
         * 
 
327
         * @return Extra text of this button.
 
328
         * @see #setExtraText(String)
 
329
         */
 
330
        public String getExtraText() {
 
331
                return this.extraText;
 
332
        }
 
333
 
 
334
        /**
 
335
         * Sets the extra text for this button. Fires an <code>extraText</code>
 
336
         * property change event.
 
337
         * 
 
338
         * @param extraText
 
339
         *            Extra text for this button.
 
340
         * @see #getExtraText()
 
341
         */
 
342
        public void setExtraText(String extraText) {
 
343
                String oldValue = this.extraText;
 
344
                this.extraText = extraText;
 
345
                firePropertyChange("extraText", oldValue, extraText);
 
346
 
 
347
                if (accessibleContext != null) {
 
348
                        accessibleContext.firePropertyChange(
 
349
                                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
 
350
                                        oldValue, extraText);
 
351
                }
 
352
                if (extraText == null || oldValue == null
 
353
                                || !extraText.equals(oldValue)) {
 
354
                        revalidate();
 
355
                        repaint();
 
356
                }
 
357
        }
 
358
 
 
359
        /**
 
360
         * Returns the text of this button.
 
361
         * 
 
362
         * @return The text of this button.
 
363
         * @see #setText(String)
 
364
         */
 
365
        public String getText() {
 
366
                return this.text;
 
367
        }
 
368
 
 
369
        /**
 
370
         * Sets the new text for this button. Fires a <code>text</code> property
 
371
         * change event.
 
372
         * 
 
373
         * @param text
 
374
         *            The new text for this button.
 
375
         * @see #getText()
 
376
         */
 
377
        public void setText(String text) {
 
378
                String oldValue = this.text;
 
379
                this.text = text;
 
380
                firePropertyChange("text", oldValue, text);
 
381
 
 
382
                if (accessibleContext != null) {
 
383
                        accessibleContext.firePropertyChange(
 
384
                                        AccessibleContext.ACCESSIBLE_VISIBLE_DATA_PROPERTY,
 
385
                                        oldValue, text);
 
386
                }
 
387
                if (text == null || oldValue == null || !text.equals(oldValue)) {
 
388
                        revalidate();
 
389
                        repaint();
 
390
                }
 
391
        }
 
392
 
 
393
        /**
 
394
         * Updates the dimension of the icon of the associated command button in the
 
395
         * {@link CommandButtonDisplayState#FIT_TO_ICON} state. Fires a
 
396
         * <code>customDimension</code> property change event.
 
397
         * 
 
398
         * @param dimension
 
399
         *            New dimension of the icon of the associated command button in
 
400
         *            the {@link CommandButtonDisplayState#FIT_TO_ICON} state.
 
401
         * @see #getCustomDimension()
 
402
         */
 
403
        public void updateCustomDimension(int dimension) {
 
404
                if (this.customDimension != dimension) {
 
405
                        int old = this.customDimension;
 
406
                        this.customDimension = dimension;
 
407
                        this.firePropertyChange("customDimension", old,
 
408
                                        this.customDimension);
 
409
                }
 
410
        }
 
411
 
 
412
        /**
 
413
         * Returns the dimension of the icon of the associated command button in the
 
414
         * {@link CommandButtonDisplayState#FIT_TO_ICON} state.
 
415
         * 
 
416
         * @return The dimension of the icon of the associated command button in the
 
417
         *         {@link CommandButtonDisplayState#FIT_TO_ICON} state.
 
418
         * @see #updateCustomDimension(int)
 
419
         */
 
420
        public int getCustomDimension() {
 
421
                return this.customDimension;
 
422
        }
 
423
 
 
424
        /**
 
425
         * Returns indication whether this button has flat appearance.
 
426
         * 
 
427
         * @return <code>true</code> if this button has flat appearance,
 
428
         *         <code>false</code> otherwise.
 
429
         * @see #setFlat(boolean)
 
430
         */
 
431
        public boolean isFlat() {
 
432
                return this.isFlat;
 
433
        }
 
434
 
 
435
        /**
 
436
         * Sets the flat appearance of this button. Fires a <code>flat</code>
 
437
         * property change event.
 
438
         * 
 
439
         * @param isFlat
 
440
         *            If <code>true</code>, this button will have flat appearance,
 
441
         *            otherwise this button will not have flat appearance.
 
442
         * @see #isFlat()
 
443
         */
 
444
        public void setFlat(boolean isFlat) {
 
445
                boolean old = this.isFlat;
 
446
                this.isFlat = isFlat;
 
447
                if (old != this.isFlat) {
 
448
                        this.firePropertyChange("flat", old, this.isFlat);
 
449
                }
 
450
 
 
451
                if (old != isFlat) {
 
452
                        repaint();
 
453
                }
 
454
        }
 
455
 
 
456
        /**
 
457
         * Returns the action model for this button.
 
458
         * 
 
459
         * @return The action model for this button.
 
460
         * @see #setActionModel(ActionButtonModel)
 
461
         */
 
462
        public ActionButtonModel getActionModel() {
 
463
                return this.actionModel;
 
464
        }
 
465
 
 
466
        /**
 
467
         * Sets the new action model for this button. Fires an
 
468
         * <code>actionModel</code> property change event.
 
469
         * 
 
470
         * @param newModel
 
471
         *            The new action model for this button.
 
472
         * @see #getActionModel()
 
473
         */
 
474
        public void setActionModel(ActionButtonModel newModel) {
 
475
                ButtonModel oldModel = getActionModel();
 
476
 
 
477
                if (oldModel != null) {
 
478
                        oldModel.removeChangeListener(this.actionHandler);
 
479
                        oldModel.removeActionListener(this.actionHandler);
 
480
                }
 
481
 
 
482
                actionModel = newModel;
 
483
 
 
484
                if (newModel != null) {
 
485
                        newModel.addChangeListener(this.actionHandler);
 
486
                        newModel.addActionListener(this.actionHandler);
 
487
                }
 
488
 
 
489
                firePropertyChange("actionModel", oldModel, newModel);
 
490
                if (newModel != oldModel) {
 
491
                        revalidate();
 
492
                        repaint();
 
493
                }
 
494
        }
 
495
 
 
496
        /**
 
497
         * Adds the specified action listener to this button.
 
498
         * 
 
499
         * @param l
 
500
         *            Action listener to add.
 
501
         * @see #removeActionListener(ActionListener)
 
502
         */
 
503
        public void addActionListener(ActionListener l) {
 
504
                this.listenerList.add(ActionListener.class, l);
 
505
        }
 
506
 
 
507
        /**
 
508
         * Removes the specified action listener from this button.
 
509
         * 
 
510
         * @param l
 
511
         *            Action listener to remove.
 
512
         * @see #addActionListener(ActionListener)
 
513
         */
 
514
        public void removeActionListener(ActionListener l) {
 
515
                this.listenerList.remove(ActionListener.class, l);
 
516
        }
 
517
 
 
518
        /**
 
519
         * Adds the specified change listener to this button.
 
520
         * 
 
521
         * @param l
 
522
         *            Change listener to add.
 
523
         * @see #removeChangeListener(ChangeListener)
 
524
         */
 
525
        public void addChangeListener(ChangeListener l) {
 
526
                this.listenerList.add(ChangeListener.class, l);
 
527
        }
 
528
 
 
529
        /**
 
530
         * Removes the specified change listener from this button.
 
531
         * 
 
532
         * @param l
 
533
         *            Change listener to remove.
 
534
         * @see #addChangeListener(ChangeListener)
 
535
         */
 
536
        public void removeChangeListener(ChangeListener l) {
 
537
                this.listenerList.remove(ChangeListener.class, l);
 
538
        }
 
539
 
 
540
        /*
 
541
         * (non-Javadoc)
 
542
         * 
 
543
         * @see javax.swing.JComponent#setEnabled(boolean)
 
544
         */
 
545
        @Override
 
546
        public void setEnabled(boolean b) {
 
547
                if (!b && actionModel.isRollover()) {
 
548
                        actionModel.setRollover(false);
 
549
                }
 
550
                super.setEnabled(b);
 
551
                actionModel.setEnabled(b);
 
552
        }
 
553
 
 
554
        /**
 
555
         * Default action handler for this button.
 
556
         * 
 
557
         * @author Kirill Grouchnikov
 
558
         */
 
559
        class ActionHandler implements ActionListener, ChangeListener {
 
560
                @Override
 
561
        public void stateChanged(ChangeEvent e) {
 
562
                        fireStateChanged();
 
563
                        repaint();
 
564
                }
 
565
 
 
566
                @Override
 
567
        public void actionPerformed(ActionEvent event) {
 
568
                        fireActionPerformed(event);
 
569
                }
 
570
        }
 
571
 
 
572
        /**
 
573
         * Notifies all listeners that have registered interest for notification on
 
574
         * this event type. The event instance is lazily created.
 
575
         * 
 
576
         * @see EventListenerList
 
577
         */
 
578
        protected void fireStateChanged() {
 
579
                // Guaranteed to return a non-null array
 
580
                Object[] listeners = listenerList.getListenerList();
 
581
                // Process the listeners last to first, notifying
 
582
                // those that are interested in this event
 
583
                ChangeEvent ce = new ChangeEvent(this);
 
584
                for (int i = listeners.length - 2; i >= 0; i -= 2) {
 
585
                        if (listeners[i] == ChangeListener.class) {
 
586
                                // Lazily create the event:
 
587
                                ((ChangeListener) listeners[i + 1]).stateChanged(ce);
 
588
                        }
 
589
                }
 
590
        }
 
591
 
 
592
        /**
 
593
         * Notifies all listeners that have registered interest for notification on
 
594
         * this event type. The event instance is lazily created using the
 
595
         * <code>event</code> parameter.
 
596
         * 
 
597
         * @param event
 
598
         *            the <code>ActionEvent</code> object
 
599
         * @see EventListenerList
 
600
         */
 
601
        protected void fireActionPerformed(ActionEvent event) {
 
602
                // Guaranteed to return a non-null array
 
603
                Object[] listeners = listenerList.getListenerList();
 
604
                ActionEvent e = null;
 
605
                // Process the listeners last to first, notifying
 
606
                // those that are interested in this event
 
607
                for (int i = listeners.length - 2; i >= 0; i -= 2) {
 
608
                        if (listeners[i] == ActionListener.class) {
 
609
                                // Lazily create the event:
 
610
                                if (e == null) {
 
611
                                        String actionCommand = event.getActionCommand();
 
612
                                        e = new ActionEvent(this, ActionEvent.ACTION_PERFORMED,
 
613
                                                        actionCommand, event.getWhen(), event
 
614
                                                                        .getModifiers());
 
615
                                }
 
616
                                ((ActionListener) listeners[i + 1]).actionPerformed(e);
 
617
                        }
 
618
                }
 
619
        }
 
620
 
 
621
        /**
 
622
         * Sets new horizontal alignment for the content of this button. Fires a
 
623
         * <code>horizontalAlignment</code> property change event.
 
624
         * 
 
625
         * @param alignment
 
626
         *            New horizontal alignment for the content of this button.
 
627
         * @see #getHorizontalAlignment()
 
628
         */
 
629
        public void setHorizontalAlignment(int alignment) {
 
630
                if (alignment == this.horizontalAlignment)
 
631
                        return;
 
632
                int oldValue = this.horizontalAlignment;
 
633
                this.horizontalAlignment = alignment;
 
634
                firePropertyChange("horizontalAlignment", oldValue,
 
635
                                this.horizontalAlignment);
 
636
                repaint();
 
637
        }
 
638
 
 
639
        /**
 
640
         * Returns the horizontal alignment for the content of this button.
 
641
         * 
 
642
         * @return The horizontal alignment for the content of this button.
 
643
         * @see #setHorizontalAlignment(int)
 
644
         */
 
645
        public int getHorizontalAlignment() {
 
646
                return this.horizontalAlignment;
 
647
        }
 
648
 
 
649
        /**
 
650
         * Sets new horizontal gap scale factor for the content of this button.
 
651
         * Fires an <code>hgapScaleFactor</code> property change event.
 
652
         * 
 
653
         * @param hgapScaleFactor
 
654
         *            New horizontal gap scale factor for the content of this
 
655
         *            button.
 
656
         * @see #getHGapScaleFactor()
 
657
         * @see #setVGapScaleFactor(double)
 
658
         * @see #setGapScaleFactor(double)
 
659
         */
 
660
        public void setHGapScaleFactor(double hgapScaleFactor) {
 
661
                if (hgapScaleFactor == this.hgapScaleFactor)
 
662
                        return;
 
663
                double oldValue = this.hgapScaleFactor;
 
664
                this.hgapScaleFactor = hgapScaleFactor;
 
665
                firePropertyChange("hgapScaleFactor", oldValue, this.hgapScaleFactor);
 
666
                if (this.hgapScaleFactor != oldValue) {
 
667
                        revalidate();
 
668
                        repaint();
 
669
                }
 
670
        }
 
671
 
 
672
        /**
 
673
         * Sets new vertical gap scale factor for the content of this button. Fires
 
674
         * a <code>vgapScaleFactor</code> property change event.
 
675
         * 
 
676
         * @param vgapScaleFactor
 
677
         *            New vertical gap scale factor for the content of this button.
 
678
         * @see #getVGapScaleFactor()
 
679
         * @see #setHGapScaleFactor(double)
 
680
         * @see #setGapScaleFactor(double)
 
681
         */
 
682
        public void setVGapScaleFactor(double vgapScaleFactor) {
 
683
                if (vgapScaleFactor == this.vgapScaleFactor)
 
684
                        return;
 
685
                double oldValue = this.vgapScaleFactor;
 
686
                this.vgapScaleFactor = vgapScaleFactor;
 
687
                firePropertyChange("vgapScaleFactor", oldValue, this.vgapScaleFactor);
 
688
                if (this.vgapScaleFactor != oldValue) {
 
689
                        revalidate();
 
690
                        repaint();
 
691
                }
 
692
        }
 
693
 
 
694
        /**
 
695
         * Sets new gap scale factor for the content of this button.
 
696
         * 
 
697
         * @param gapScaleFactor
 
698
         *            New gap scale factor for the content of this button.
 
699
         * @see #getHGapScaleFactor()
 
700
         * @see #getVGapScaleFactor()
 
701
         */
 
702
        public void setGapScaleFactor(double gapScaleFactor) {
 
703
                setHGapScaleFactor(gapScaleFactor);
 
704
                setVGapScaleFactor(gapScaleFactor);
 
705
        }
 
706
 
 
707
        /**
 
708
         * Returns the horizontal gap scale factor for the content of this button.
 
709
         * 
 
710
         * @return The horizontal gap scale factor for the content of this button.
 
711
         * @see #setHGapScaleFactor(double)
 
712
         * @see #setGapScaleFactor(double)
 
713
         * @see #getVGapScaleFactor()
 
714
         */
 
715
        public double getHGapScaleFactor() {
 
716
                return this.hgapScaleFactor;
 
717
        }
 
718
 
 
719
        /**
 
720
         * Returns the vertical gap scale factor for the content of this button.
 
721
         * 
 
722
         * @return The vertical gap scale factor for the content of this button.
 
723
         * @see #setVGapScaleFactor(double)
 
724
         * @see #setGapScaleFactor(double)
 
725
         * @see #getHGapScaleFactor()
 
726
         */
 
727
        public double getVGapScaleFactor() {
 
728
                return this.vgapScaleFactor;
 
729
        }
 
730
 
 
731
        /**
 
732
         * Programmatically perform an action "click". This does the same thing as
 
733
         * if the user had pressed and released the action area of the button.
 
734
         */
 
735
        public void doActionClick() {
 
736
                Dimension size = getSize();
 
737
                ButtonModel actionModel = this.getActionModel();
 
738
                actionModel.setArmed(true);
 
739
                actionModel.setPressed(true);
 
740
                paintImmediately(new Rectangle(0, 0, size.width, size.height));
 
741
                try {
 
742
                        Thread.sleep(100);
 
743
                } catch (InterruptedException ie) {
 
744
                }
 
745
                actionModel.setPressed(false);
 
746
                actionModel.setArmed(false);
 
747
        }
 
748
 
 
749
        boolean hasRichTooltips() {
 
750
                return (this.actionRichTooltip != null);
 
751
        }
 
752
 
 
753
        /**
 
754
         * Sets the rich tooltip for the action area of this button.
 
755
         * 
 
756
         * @param richTooltip
 
757
         *            Rich tooltip for the action area of this button.
 
758
         * @see #getRichTooltip(MouseEvent)
 
759
         */
 
760
        public void setActionRichTooltip(RichTooltip richTooltip) {
 
761
                this.actionRichTooltip = richTooltip;
 
762
                RichToolTipManager richToolTipManager = RichToolTipManager
 
763
                                .sharedInstance();
 
764
                if (this.hasRichTooltips()) {
 
765
                        richToolTipManager.registerComponent(this);
 
766
                } else {
 
767
                        richToolTipManager.unregisterComponent(this);
 
768
                }
 
769
        }
 
770
 
 
771
        /*
 
772
         * (non-Javadoc)
 
773
         * 
 
774
         * @seeorg.jvnet.flamingo.common.RichToolTipManager.JTrackableComponent#
 
775
         * getRichTooltip(java.awt.event.MouseEvent)
 
776
         */
 
777
        @Override
 
778
        public RichTooltip getRichTooltip(MouseEvent mouseEvent) {
 
779
                return this.actionRichTooltip;
 
780
        }
 
781
 
 
782
        /*
 
783
         * (non-Javadoc)
 
784
         * 
 
785
         * @see javax.swing.JComponent#setToolTipText(java.lang.String)
 
786
         */
 
787
        @Override
 
788
        public void setToolTipText(String text) {
 
789
                throw new UnsupportedOperationException("Use rich tooltip APIs");
 
790
        }
 
791
 
 
792
        /**
 
793
         * Returns the location order kind for buttons placed in command button
 
794
         * strips or for buttons that need the visuals of segmented strips.
 
795
         * 
 
796
         * @return The location order kind for buttons placed in command button
 
797
         *         strips or for buttons that need the visuals of segmented strips.
 
798
         * @see #setLocationOrderKind(CommandButtonLocationOrderKind)
 
799
         */
 
800
        public CommandButtonLocationOrderKind getLocationOrderKind() {
 
801
                return this.locationOrderKind;
 
802
        }
 
803
 
 
804
        /**
 
805
         * Sets the location order kind for buttons placed in command button strips
 
806
         * or for buttons that need the visuals of segmented strips. Fires a
 
807
         * <code>locationOrderKind</code> property change event.
 
808
         * 
 
809
         * @param locationOrderKind
 
810
         *            The location order kind for buttons placed in command button
 
811
         *            strips or for buttons that need the visuals of segmented
 
812
         *            strips.
 
813
         * @see #getLocationOrderKind()
 
814
         */
 
815
        public void setLocationOrderKind(
 
816
                        CommandButtonLocationOrderKind locationOrderKind) {
 
817
                CommandButtonLocationOrderKind old = this.locationOrderKind;
 
818
                if (old != locationOrderKind) {
 
819
                        this.locationOrderKind = locationOrderKind;
 
820
                        this.firePropertyChange("locationOrderKind", old,
 
821
                                        this.locationOrderKind);
 
822
                }
 
823
        }
 
824
 
 
825
        /**
 
826
         * Returns the key tip for the action area of this button.
 
827
         * 
 
828
         * @return The key tip for the action area of this button.
 
829
         * @see #setActionKeyTip(String)
 
830
         */
 
831
        public String getActionKeyTip() {
 
832
                return this.actionKeyTip;
 
833
        }
 
834
 
 
835
        /**
 
836
         * Sets the key tip for the action area of this button. Fires an
 
837
         * <code>actionKeyTip</code> property change event.
 
838
         * 
 
839
         * @param actionKeyTip
 
840
         *            The key tip for the action area of this button.
 
841
         * @see #getActionKeyTip()
 
842
         */
 
843
        public void setActionKeyTip(String actionKeyTip) {
 
844
                String old = this.actionKeyTip;
 
845
                this.actionKeyTip = actionKeyTip;
 
846
                this.firePropertyChange("actionKeyTip", old, this.actionKeyTip);
 
847
        }
 
848
}