Move the SwingActionLink class

This commit is contained in:
Sergey Malenkov
2014-10-03 17:53:11 +04:00
parent 1ff91f6ca1
commit cba40c31d9
2 changed files with 16 additions and 11 deletions
@@ -13,9 +13,8 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.openapi.options.newEditor;
package com.intellij.ui.components.labels;
import com.intellij.ui.components.labels.LinkLabel;
import org.jetbrains.annotations.NotNull;
import javax.swing.Action;
@@ -28,20 +27,19 @@ import static java.beans.EventHandler.create;
/**
* @author Sergey.Malenkov
*/
final class ActionLink extends LinkLabel {
public class SwingActionLink extends LinkLabel<Action> implements LinkListener<Action> {
private final ActionEvent myEvent = new ActionEvent(this, ActionEvent.ACTION_PERFORMED, Action.ACTION_COMMAND_KEY);
private final Action myAction;
ActionLink(@NotNull Action action) {
super("<html><body><strong>" + action.getValue(Action.NAME), (Icon)action.getValue(Action.SMALL_ICON));
public SwingActionLink(@NotNull Action action) {
super((String)action.getValue(Action.NAME), (Icon)action.getValue(Action.SMALL_ICON));
setToolTipText((String)action.getValue(Action.SHORT_DESCRIPTION));
setVisible(action.isEnabled());
myAction = action;
setListener(this, action);
action.addPropertyChangeListener(create(PropertyChangeListener.class, this, "visible", "source.enabled"));
}
@Override
public void doClick() {
myAction.actionPerformed(myEvent);
public void linkSelected(LinkLabel link, Action action) {
action.actionPerformed(myEvent);
}
}
@@ -19,6 +19,7 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.options.OptionsBundle;
import com.intellij.openapi.project.Project;
import com.intellij.ui.JBColor;
import com.intellij.ui.components.labels.SwingActionLink;
import javax.swing.Action;
import javax.swing.BorderFactory;
@@ -27,23 +28,29 @@ import javax.swing.JLabel;
import javax.swing.JPanel;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Font;
/**
* @author Sergey.Malenkov
*/
final class Banner extends JPanel {
private final JPanel myLeftPanel = new JPanel();
private final JPanel myLeftPanel = new JPanel(null);
private final JLabel myProjectIcon = new JLabel();
Banner(Action action) {
super(new BorderLayout(10, 0));
SwingActionLink link = new SwingActionLink(action);
myLeftPanel.setLayout(new BoxLayout(myLeftPanel, BoxLayout.X_AXIS));
myProjectIcon.setIcon(AllIcons.General.ProjectConfigurableBanner);
myProjectIcon.setForeground(JBColor.GRAY);
myProjectIcon.setVisible(false);
add(BorderLayout.WEST, myLeftPanel);
add(BorderLayout.CENTER, myProjectIcon);
add(BorderLayout.EAST, new ActionLink(action));
add(BorderLayout.EAST, link);
Font font = link.getFont();
if (font != null) {
link.setFont(font.deriveFont(Font.BOLD));
}
}
void setText(String... text) {