Run/Debug Configuration: layout optimization

This commit is contained in:
Vassiliy Kudryashov
2012-09-12 20:45:32 +04:00
parent b32925117a
commit 37fdf46277
5 changed files with 97 additions and 32 deletions
@@ -272,4 +272,50 @@ public class IconUtil {
private static String getToolbarDecoratorIconsFolder() {
return "/toolbarDecorator/" + (SystemInfo.isMac ? "mac/" : "");
}
/**
* Result icons look like original but have equal (maximum) size
*/
public static Icon[] getEqualSizedIcons(@NotNull Icon... icons) {
Icon[] result = new Icon[icons.length];
int width = 0;
int height = 0;
for (Icon icon : icons) {
width = Math.max(width, icon.getIconWidth());
height = Math.max(height, icon.getIconHeight());
}
for (int i = 0; i < icons.length; i++) {
result[i] = new IconSizeWrapper(icons[i], width, height);
}
return result;
}
private static class IconSizeWrapper implements Icon {
private final Icon myIcon;
private final int myWidth;
private final int myHeight;
private IconSizeWrapper(Icon icon, int width, int height) {
myIcon = icon;
myWidth = width;
myHeight = height;
}
@Override
public void paintIcon(Component c, Graphics g, int x, int y) {
x += (myWidth - myIcon.getIconWidth()) / 2;
y += (myHeight - myIcon.getIconHeight()) / 2;
myIcon.paintIcon(c, g, x, y);
}
@Override
public int getIconWidth() {
return myWidth;
}
@Override
public int getIconHeight() {
return myHeight;
}
}
}
@@ -269,6 +269,6 @@ public abstract class RunConfigurationBase extends UserDataHolderBase implements
@Override
public String toString() {
return getType() + ": " + getName();
return getType().getDisplayName() + ": " + getName();
}
}
@@ -21,6 +21,7 @@ import com.intellij.execution.ExecutionBundle;
import com.intellij.execution.RunnerAndConfigurationSettings;
import com.intellij.execution.configurations.RunConfiguration;
import com.intellij.execution.configurations.UnknownRunConfiguration;
import com.intellij.ide.util.PropertiesComponent;
import com.intellij.openapi.actionSystem.AnAction;
import com.intellij.openapi.actionSystem.AnActionEvent;
import com.intellij.openapi.actionSystem.DefaultActionGroup;
@@ -35,9 +36,12 @@ import com.intellij.openapi.util.SystemInfo;
import com.intellij.ui.*;
import com.intellij.ui.components.JBList;
import com.intellij.util.containers.hash.HashSet;
import org.jetbrains.annotations.NonNls;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListDataEvent;
import javax.swing.event.ListDataListener;
import java.awt.*;
@@ -50,6 +54,8 @@ import java.util.List;
* @author Vassiliy Kudryashov
*/
class BeforeRunStepsPanel extends DropDownPanel {
@NonNls private static final String EXPAND_PROPERTY_KEY = "ExpandBeforeRunStepsPanel";
private final JCheckBox myShowSettingsBeforeRunCheckBox;
private final JBList myList;
private final CollectionListModel<BeforeRunTask> myModel;
@@ -143,6 +149,13 @@ class BeforeRunStepsPanel extends DropDownPanel {
wrapper.add(myShowSettingsBeforeRunCheckBox, BorderLayout.NORTH);
wrapper.add(myPanel, BorderLayout.CENTER);
setContent(wrapper);
setExpanded(PropertiesComponent.getInstance().getBoolean(EXPAND_PROPERTY_KEY, false));
addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
PropertiesComponent.getInstance().setValue(EXPAND_PROPERTY_KEY, String.valueOf(isExpanded()));
}
});
}
@Nullable
@@ -160,11 +173,13 @@ class BeforeRunStepsPanel extends DropDownPanel {
myRunConfiguration = settings.getConfiguration();
originalTasks.clear();
originalTasks.addAll(RunManagerImpl.getInstanceImpl(myRunConfiguration.getProject()).getBeforeRunTasks(myRunConfiguration));
RunManagerImpl runManager = RunManagerImpl.getInstanceImpl(myRunConfiguration.getProject());
originalTasks.addAll(runManager.getBeforeRunTasks(myRunConfiguration));
myModel.replaceAll(originalTasks);
myShowSettingsBeforeRunCheckBox.setSelected(settings.isEditBeforeRun());
myShowSettingsBeforeRunCheckBox.setEnabled(!(isUnknown()));
myPanel.setVisible(checkBeforeRunTasksAbility(false));
updateText();
}
private void updateText() {
@@ -19,32 +19,36 @@ import com.intellij.icons.AllIcons;
import com.intellij.openapi.actionSystem.ActionButtonComponent;
import com.intellij.openapi.actionSystem.ex.ActionButtonLook;
import com.intellij.util.IconUtil;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
/**
* User: Vassiliy.Kudryashov
*/
public class DropDownPanel extends JPanel {
private static final Icon DOWN = AllIcons.General.ComboArrow;
private static final Icon UP = IconUtil.flip(AllIcons.General.ComboArrow, false);
private static final Icon[] WRAPPERS = IconUtil.getEqualSizedIcons(AllIcons.General.ComboArrowRight, AllIcons.General.ComboArrow);
private static final Icon DOWN = WRAPPERS[0];
private static final Icon UP = WRAPPERS[1];
private final JLabel myLabel;
private final ButtonLabel myLabel;
private @Nullable JComponent myContent;
private boolean myExpanded = true;
private final List<ChangeListener> myListeners = new CopyOnWriteArrayList<ChangeListener>();
public DropDownPanel() {
this(null, null, true);
this(null, null);
}
public DropDownPanel(@Nullable String title, @Nullable JComponent content, boolean withSeparatorLine) {
public DropDownPanel(@Nullable String title, @Nullable JComponent content) {
super(new BorderLayout());
myLabel = new ButtonLabel(withSeparatorLine);
myLabel = new ButtonLabel();
add(myLabel, BorderLayout.NORTH);
setTitle(title);
setContent(content);
@@ -71,7 +75,7 @@ public class DropDownPanel extends JPanel {
if (myExpanded == expanded) {
return;
}
myLabel.setIcon(expanded ? UP : DOWN);
myLabel.getLabel().setIcon(expanded ? UP : DOWN);
if (myContent != null) {
if (expanded) {
add(myContent, BorderLayout.CENTER);
@@ -83,42 +87,42 @@ public class DropDownPanel extends JPanel {
myExpanded = expanded;
revalidate();
repaint();
ChangeEvent changeEvent = new ChangeEvent(this);
for (ChangeListener listener : myListeners) {
listener.stateChanged(changeEvent);
}
}
public boolean isExpanded() {
return myExpanded;
}
private class ButtonLabel extends JLabel implements ActionButtonComponent {
public void addChangeListener(ChangeListener listener) {
if (listener != null) {
myListeners.add(listener);
}
}
public void removeChangeListener(ChangeListener listener) {
if (listener != null) {
myListeners.remove(listener);
}
}
private class ButtonLabel extends TitledSeparator implements ActionButtonComponent {
private boolean myMouseDown;
private boolean myRollover;
private final boolean myLine;
private ButtonLabel(boolean withSeparatorLine) {
myLine = withSeparatorLine;
setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
setIconTextGap(2);
private ButtonLabel() {
setBorder(BorderFactory.createEmptyBorder(4, 0, 4, 0));
myLabel.setIconTextGap(2);
enableEvents(AWTEvent.MOUSE_EVENT_MASK);
}
@Override
public void paintComponent(Graphics g) {
super.paintComponent(g);
ActionButtonLook.IDEA_LOOK.paintBackground(g, this);
ActionButtonLook.IDEA_LOOK.paintBorder(g, this);
super.paintComponent(g);
if (myLine) {
g.setColor(GroupedElementsRenderer.POPUP_SEPARATOR_FOREGROUND);
Icon icon = getIcon();
final FontMetrics fm = getFontMetrics(getFont());
String text = getText();
Border border = getBorder();
Insets insets = border != null ? border.getBorderInsets(this) : new Insets(0, 0, 0, 0);
int width = (icon != null ? icon.getIconWidth() : 0)
+ (text != null ? getIconTextGap() + fm.stringWidth(text) : 0)
+ insets.left;
final int lineY = (UIUtil.isUnderNativeMacLookAndFeel() ? 1 : 3) + fm.getHeight() / 2;
g.drawLine(width + 3, lineY, getWidth() - 3 - insets.right, lineY);
}
}
@Override
@@ -278,7 +278,7 @@ show.swing.inspector=&Enable capturing form snapshots
show.swing.inspector.disabled=&Enable capturing form snapshots (requires JRE 5.0 or higher)
before.run.property.make=Make
run.configuration.store.place.option=&Share
run.configuration.singleton=Single instance allowed
run.configuration.singleton=Single instance only
run.configuration.default.type.description=configuration
#GeneralCommandLine