1 /* |
|
2 * CDDL HEADER START |
|
3 * |
|
4 * The contents of this file are subject to the terms of the |
|
5 * Common Development and Distribution License (the "License"). |
|
6 * You may not use this file except in compliance with the License. |
|
7 * |
|
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE |
|
9 * or http://www.opensolaris.org/os/licensing. |
|
10 * See the License for the specific language governing permissions |
|
11 * and limitations under the License. |
|
12 * |
|
13 * When distributing Covered Code, include this CDDL HEADER in each |
|
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. |
|
15 * If applicable, add the following below this CDDL HEADER, with the |
|
16 * fields enclosed by brackets "[]" replaced with your own identifying |
|
17 * information: Portions Copyright [yyyy] [name of copyright owner] |
|
18 * |
|
19 * CDDL HEADER END |
|
20 */ |
|
21 |
|
22 /* |
|
23 * Copyright (c) 2009, 2012, Oracle and/or its affiliates. All rights reserved. |
|
24 */ |
|
25 |
|
26 package com.oracle.solaris.vp.panel.swing.action; |
|
27 |
|
28 import java.util.Collection; |
|
29 import javax.swing.*; |
|
30 import com.oracle.solaris.vp.panel.common.ClientContext; |
|
31 import com.oracle.solaris.vp.panel.common.action.*; |
|
32 import com.oracle.solaris.vp.panel.swing.control.SwingControl; |
|
33 import com.oracle.solaris.vp.util.misc.*; |
|
34 import com.oracle.solaris.vp.util.swing.*; |
|
35 |
|
36 public abstract class SwingStructuredAction<P, I, O> |
|
37 extends DefaultStructuredAction<P, I, O> { |
|
38 |
|
39 // |
|
40 // Static data |
|
41 // |
|
42 |
|
43 public static final int SMALL_ICON_HEIGHT = 16; |
|
44 |
|
45 // |
|
46 // Instance data |
|
47 // |
|
48 |
|
49 private Collection<? extends Icon> icons; |
|
50 private HasComponent hasComponent; |
|
51 |
|
52 // |
|
53 // Constructors |
|
54 // |
|
55 |
|
56 public SwingStructuredAction(String text, P pInput, |
|
57 Collection<? extends Icon> icons, ClientContext context, |
|
58 HasComponent hasComponent) { |
|
59 |
|
60 super(text, pInput, context); |
|
61 |
|
62 setIcons(icons); |
|
63 this.hasComponent = hasComponent; |
|
64 } |
|
65 |
|
66 public SwingStructuredAction(String text, P pInput, |
|
67 Collection<? extends Icon> icons, SwingControl control) { |
|
68 |
|
69 this(text, pInput, icons, control.getClientContext(), control); |
|
70 } |
|
71 |
|
72 // |
|
73 // DefaultStructuredAction methods |
|
74 // |
|
75 |
|
76 @Override |
|
77 protected void showError(ActionFailedException e) { |
|
78 GUIUtil.showError(hasComponent.getComponent(), null, |
|
79 ThrowableUtil.getTrueMessage(e)); |
|
80 } |
|
81 |
|
82 // |
|
83 // SwingStructuredAction methods |
|
84 // |
|
85 |
|
86 public HasComponent getHasComponent() { |
|
87 return hasComponent; |
|
88 } |
|
89 |
|
90 public Collection<? extends Icon> getIcons() { |
|
91 return icons; |
|
92 } |
|
93 |
|
94 public void setIcons(Collection<? extends Icon> icons) { |
|
95 this.icons = icons; |
|
96 Icon icon = null; |
|
97 |
|
98 if (icons != null) { |
|
99 icon = IconUtil.getClosestIcon(icons, SMALL_ICON_HEIGHT); |
|
100 if (icon != null) { |
|
101 icon = IconUtil.ensureIconHeight(icon, SMALL_ICON_HEIGHT); |
|
102 } |
|
103 } |
|
104 |
|
105 putValue(Action.SMALL_ICON, icon); |
|
106 } |
|
107 } |
|