correct enabling/disabling in TitledSeparator/IdeaTitledBorder/HideableTitledPanel. TitledSeparatorWithMnemonic removed - use TitledSeparator instead.

This commit is contained in:
Evgeny
2012-09-14 07:29:53 +04:00
parent 69d8f45fcd
commit 576eb066dd
13 changed files with 75 additions and 111 deletions
@@ -44,7 +44,6 @@ import java.awt.*;
class CopyClassDialog extends DialogWrapper{
@NonNls private static final String RECENTS_KEY = "CopyClassDialog.RECENTS_KEY";
private final JLabel myInformationLabel = new JLabel();
private final JLabel myNameLabel = new JLabel();
private EditorTextField myNameField;
private final JLabel myPackageLabel = new JLabel();
private ReferenceEditorComboWithBrowseButton myTfPackage;
@@ -97,9 +96,7 @@ class CopyClassDialog extends DialogWrapper{
}
protected JComponent createNorthPanel() {
myNameLabel.setText(RefactoringBundle.message("copy.files.new.name.label"));
myNameField = new EditorTextField("");
myNameLabel.setLabelFor(myNameField);
String qualifiedName = getQualifiedName();
myTfPackage = new PackageNameReferenceEditorCombo(qualifiedName, myProject, RECENTS_KEY, RefactoringBundle.message("choose.destination.package"));
@@ -119,7 +116,7 @@ class CopyClassDialog extends DialogWrapper{
return FormBuilder.createFormBuilder()
.addComponent(myInformationLabel)
.addLabeledComponent(myNameLabel, myNameField, UIUtil.LARGE_VGAP)
.addLabeledComponent(RefactoringBundle.message("copy.files.new.name.label"), myNameField, UIUtil.LARGE_VGAP)
.addLabeledComponent(myPackageLabel, myTfPackage)
.addLabeledComponent(label, myDestinationCB)
.getPanel();
@@ -153,7 +150,7 @@ class CopyClassDialog extends DialogWrapper{
final PsiNameHelper nameHelper = JavaPsiFacade.getInstance(manager.getProject()).getNameHelper();
if (packageName.length() > 0 && !nameHelper.isQualifiedName(packageName)) {
errorString[0] = RefactoringBundle.message("invalid.target.package.name.specified");
} else if ("".equals(className)) {
} else if (className != null && className.isEmpty()) {
errorString[0] = RefactoringBundle.message("no.class.name.specified");
} else {
if (!nameHelper.isIdentifier(className)) {
@@ -25,7 +25,7 @@ import com.intellij.refactoring.RefactoringBundle;
import com.intellij.refactoring.move.MoveInstanceMembersUtil;
import com.intellij.ui.EditorTextField;
import com.intellij.ui.ScrollPaneFactory;
import com.intellij.ui.TitledSeparatorWithMnemonic;
import com.intellij.ui.TitledSeparator;
import com.intellij.util.containers.HashMap;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.NonNls;
@@ -62,7 +62,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
protected JComponent createCenterPanel() {
JPanel mainPanel = new JPanel(new GridBagLayout());
final TitledSeparatorWithMnemonic separator = new TitledSeparatorWithMnemonic();
final TitledSeparator separator = new TitledSeparator();
mainPanel.add(separator, new GridBagConstraints(0, GridBagConstraints.RELATIVE, 2, 1, 1.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0,0,0,0), 0,0));
myList = createTargetVariableChooser();
@@ -116,7 +116,7 @@ public class MoveInstanceMethodDialog extends MoveInstanceMethodDialogBase {
JPanel panel = new JPanel(new VerticalFlowLayout(VerticalFlowLayout.TOP, 0, 0, true, true));
for (PsiClass aClass : myThisClassesMap.keySet()) {
final String text = RefactoringBundle.message("move.method.this.parameter.label", aClass.getName());
panel.add(new TitledSeparatorWithMnemonic(text, null));
panel.add(new TitledSeparator(text, null));
String suggestedName = MoveInstanceMethodHandler.suggestParameterNameForThisClass(aClass);
final EditorTextField field = new EditorTextField(suggestedName, getProject(), StdFileTypes.JAVA);
@@ -71,7 +71,7 @@
</component>
</children>
</scrollpane>
<component id="1a9fa" class="com.intellij.ui.TitledSeparatorWithMnemonic" binding="myPsiTreeSeparator">
<component id="1a9fa" class="com.intellij.ui.TitledSeparator" binding="myPsiTreeSeparator">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -106,7 +106,7 @@
</constraints>
<properties/>
</component>
<component id="287f6" class="com.intellij.ui.TitledSeparatorWithMnemonic" binding="myRefsSeparator">
<component id="287f6" class="com.intellij.ui.TitledSeparator" binding="myRefsSeparator">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -137,7 +137,7 @@
</component>
</children>
</scrollpane>
<component id="62949" class="com.intellij.ui.TitledSeparatorWithMnemonic" binding="myBlockTreeSeparator">
<component id="62949" class="com.intellij.ui.TitledSeparator" binding="myBlockTreeSeparator">
<constraints>
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -261,7 +261,7 @@
</component>
</children>
</grid>
<component id="bd033" class="com.intellij.ui.TitledSeparatorWithMnemonic" binding="myTextSeparator">
<component id="9944b" class="com.intellij.ui.TitledSeparator" binding="myTextSeparator">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -128,10 +128,10 @@ public class PsiViewerDialog extends DialogWrapper implements DataProvider, Disp
private JPanel myBlockStructurePanel;
private JSplitPane myBlockRefSplitPane;
private JCheckBox myShowBlocksCheckBox;
private TitledSeparatorWithMnemonic myTextSeparator;
private TitledSeparatorWithMnemonic myPsiTreeSeparator;
private TitledSeparatorWithMnemonic myRefsSeparator;
private TitledSeparatorWithMnemonic myBlockTreeSeparator;
private TitledSeparator myTextSeparator;
private TitledSeparator myPsiTreeSeparator;
private TitledSeparator myRefsSeparator;
private TitledSeparator myBlockTreeSeparator;
@Nullable
private BlockTreeBuilder myBlockTreeBuilder;
private RangeHighlighter myHighlighter;
@@ -752,7 +752,6 @@ public class SingleInspectionProfilePanel extends JPanel {
}
myOptionsPanel.removeAll();
myOptionsPanel.add(SeparatorFactory.createSeparator("Options", null), BorderLayout.NORTH);
final NamedScope scope = node.getScope();
if (scope != null || node.isInspectionNode()) {
@@ -781,14 +780,14 @@ public class SingleInspectionProfilePanel extends JPanel {
final JPanel withSeverity = new JPanel(new GridBagLayout());
withSeverity.add(new JLabel(InspectionsBundle.message("inspection.severity")),
new GridBagConstraints(0, 0, 1, 1, 0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, IdeBorderFactory.TITLED_BORDER_INDENT, 10, 10), 0, 0));
GridBagConstraints.NONE, new Insets(0, 0, 10, 10), 0, 0));
withSeverity.add(chooser, new GridBagConstraints(1, 0, 1, 1, 1.0, 0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(0, 0, 10, 0), 0, 0));
final JComponent comp = descriptor.getState().getAdditionalConfigPanel();
withSeverity.add(comp != null ? comp : new JPanel(),
new GridBagConstraints(0, 1, 2, 1, 1.0, 1.0, GridBagConstraints.NORTHWEST,
GridBagConstraints.BOTH, new Insets(0, IdeBorderFactory.TITLED_BORDER_INDENT, 0, 0), 0, 0));
GridBagConstraints.BOTH, new Insets(0, 0, 0, 0), 0, 0));
myOptionsPanel.add(withSeverity, BorderLayout.CENTER);
}
@@ -893,6 +892,8 @@ public class SingleInspectionProfilePanel extends JPanel {
myRightSplitter.setProportion(myProperties.getFloat(HORIZONTAL_DIVIDER_PROPORTION, 0.5f));
myOptionsPanel = new JPanel(new BorderLayout());
myOptionsPanel.setBorder(IdeBorderFactory.createTitledBorder("Options", false,
new Insets(0, 0, 0, 0)));
initOptionsAndDescriptionPanel();
myRightSplitter.setSecondComponent(myOptionsPanel);
myRightSplitter.setHonorComponentsMinimumSize(true);
@@ -29,17 +29,17 @@ public class SeparatorFactory {
}
@Deprecated
public static JComponent createSeparator(String textWithMnemonic, @Nullable JComponent labelFor, boolean boldFont, boolean smallFont) {
return new TitledSeparatorWithMnemonic(textWithMnemonic, labelFor);
public static JComponent createSeparator(String text, @Nullable JComponent labelFor, boolean boldFont, boolean smallFont) {
return new TitledSeparator(text, labelFor);
}
public static JComponent createSeparator(String textWithMnemonic, @Nullable JComponent labelFor) {
return new TitledSeparatorWithMnemonic(textWithMnemonic, labelFor);
public static JComponent createSeparator(String text, @Nullable JComponent labelFor) {
return new TitledSeparator(text, labelFor);
}
@Deprecated
public static JComponent createSeparatorWithBoldTitle(String textWithMnemonic, @Nullable JComponent labelFor) {
TitledSeparatorWithMnemonic separator = new TitledSeparatorWithMnemonic(textWithMnemonic, labelFor);
public static JComponent createSeparatorWithBoldTitle(String text, @Nullable JComponent labelFor) {
TitledSeparator separator = new TitledSeparator(text, labelFor);
separator.setTitleFont(separator.getTitleFont().deriveFont(Font.BOLD));
return separator;
}
@@ -16,7 +16,9 @@
package com.intellij.ui;
import com.intellij.ui.components.JBLabel;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
@@ -30,42 +32,44 @@ public class TitledSeparator extends JPanel {
public static int SEPARATOR_LEFT_INSET = 6;
public static int SEPARATOR_RIGHT_INSET = 3;
protected final JLabel myLabel = new JLabel();
protected final JBLabel myLabel = new JBLabel() {
@Override
public Font getFont() {
return UIUtil.getTitledBorderFont();
}
};
protected final JSeparator mySeparator = new JSeparator(SwingConstants.HORIZONTAL);
private String originalText;
public TitledSeparator() {
this("");
}
public TitledSeparator(String text) {
this(text, null);
}
public TitledSeparator(String text, @Nullable JComponent labelFor) {
super();
setLayout(new GridBagLayout());
add(myLabel, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 3, 0, 0), 0, 0));
add(myLabel, new GridBagConstraints(0, 0, 1, 1, 0, 1, GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(0, 0, 0, 0), 0, 0));
add(mySeparator,
new GridBagConstraints(1, 0, GridBagConstraints.REMAINDER, 1, 1, 1, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL,
new Insets(2, SEPARATOR_LEFT_INSET, 0, SEPARATOR_RIGHT_INSET), 0, 0));
setBorder(IdeBorderFactory.createEmptyBorder(TOP_INSET, 0, BOTTOM_INSET, 0));
setText(text);
updateUI();
}
@Override
public void updateUI() {
super.updateUI();
if (myLabel != null) {
myLabel.setFont(UIUtil.getTitledBorderFont());
}
setLabelFor(labelFor);
}
public String getText() {
return myLabel.getText();
return originalText;
}
public void setText(String text) {
myLabel.setText(text);
originalText = text;
myLabel.setText(UIUtil.replaceMnemonicAmpersand(originalText));
}
public void setTitleFont(Font font) {
myLabel.setFont(font);
}
@@ -81,4 +85,20 @@ public class TitledSeparator extends JPanel {
public JSeparator getSeparator() {
return mySeparator;
}
public Component getLabelFor() {
return myLabel.getLabelFor();
}
public void setLabelFor(Component labelFor) {
myLabel.setLabelFor(labelFor);
}
@Override
public void setEnabled(boolean enabled) {
super.setEnabled(enabled);
myLabel.setEnabled(enabled);
mySeparator.setEnabled(enabled);
}
}
@@ -1,58 +0,0 @@
/*
* Copyright 2000-2011 JetBrains s.r.o.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package com.intellij.ui;
import com.intellij.util.ui.UIUtil;
import org.jetbrains.annotations.Nullable;
import javax.swing.*;
import java.awt.*;
/**
* @author evgeny zakrevsky
*/
public class TitledSeparatorWithMnemonic extends TitledSeparator {
private String originalText;
public TitledSeparatorWithMnemonic() {
this("", null);
}
public TitledSeparatorWithMnemonic(String textWithMnemonic, @Nullable JComponent labelFor) {
super(textWithMnemonic);
setText(textWithMnemonic);
setLabelFor(labelFor);
}
public String getText() {
return originalText;
}
public void setText(String text) {
originalText = text;
myLabel.setText(UIUtil.replaceMnemonicAmpersand(originalText));
}
public Component getLabelFor() {
return myLabel.getLabelFor();
}
public void setLabelFor(Component labelFor) {
myLabel.setLabelFor(labelFor);
}
}
@@ -1,6 +1,7 @@
package com.intellij.ui;
import com.intellij.icons.AllIcons;
import com.intellij.openapi.util.IconLoader;
import com.intellij.util.ui.UIUtil;
import javax.swing.*;
@@ -15,7 +16,7 @@ import java.awt.event.MouseEvent;
*/
public class HideableTitledPanel extends JPanel {
private TitledSeparatorWithMnemonic myTitledSeparator;
private TitledSeparator myTitledSeparator;
private boolean myOn;
private final JComponent myContent;
private Dimension myPreviousContentSize;
@@ -24,7 +25,7 @@ public class HideableTitledPanel extends JPanel {
super(new BorderLayout());
myContent = content;
add(myContent, BorderLayout.CENTER);
myTitledSeparator = new TitledSeparatorWithMnemonic("", null);
myTitledSeparator = new TitledSeparator(title, null);
add(myTitledSeparator, BorderLayout.NORTH);
myTitledSeparator.getLabel().setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));
myTitledSeparator.getLabel().addMouseListener(new MouseAdapter() {
@@ -40,7 +41,6 @@ public class HideableTitledPanel extends JPanel {
});
setOn(on);
setTitle(title);
}
public void setOn(boolean on) {
@@ -64,6 +64,7 @@ public class HideableTitledPanel extends JPanel {
protected void on() {
myOn = true;
myTitledSeparator.getLabel().setIcon(AllIcons.General.ComboArrowDown);
myTitledSeparator.getLabel().setDisabledIcon(IconLoader.getTransparentIcon(AllIcons.General.ComboArrowDown, 0.5f));
myTitledSeparator.getLabel().setIconTextGap(5);
myContent.setVisible(true);
adjustWindow();
@@ -74,7 +75,9 @@ public class HideableTitledPanel extends JPanel {
protected void off() {
myOn = false;
myTitledSeparator.getLabel().setIcon(AllIcons.General.ComboArrowRight);
myTitledSeparator.getLabel().setIconTextGap(5 + AllIcons.General.ComboArrowDown.getIconWidth() - AllIcons.General.ComboArrowRight.getIconWidth());
myTitledSeparator.getLabel().setDisabledIcon(IconLoader.getTransparentIcon(AllIcons.General.ComboArrowRight, 0.5f));
myTitledSeparator.getLabel()
.setIconTextGap(5 + AllIcons.General.ComboArrowDown.getIconWidth() - AllIcons.General.ComboArrowRight.getIconWidth());
myContent.setVisible(false);
myPreviousContentSize = myContent.getSize();
adjustWindow();
@@ -109,7 +112,7 @@ public class HideableTitledPanel extends JPanel {
@Override
public void setEnabled(boolean enabled) {
myTitledSeparator.myLabel.setForeground(enabled ? UIUtil.getActiveTextColor() : UIUtil.getInactiveTextColor());
myTitledSeparator.setEnabled(enabled);
myContent.setEnabled(enabled);
}
@@ -118,7 +121,7 @@ public class HideableTitledPanel extends JPanel {
super.addNotify();
final int mnemonicIndex = UIUtil.getDisplayMnemonicIndex(getTitle());
if (mnemonicIndex != -1) {
getActionMap().put("tt", new AbstractAction() {
getActionMap().put("Collapse/Expand on mnemonic", new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
if (myOn) {
@@ -130,7 +133,8 @@ public class HideableTitledPanel extends JPanel {
}
});
final Character mnemonicCharacter = UIUtil.removeMnemonic(getTitle()).toUpperCase().charAt(mnemonicIndex);
getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(mnemonicCharacter, InputEvent.ALT_MASK, false), "tt");
getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(mnemonicCharacter, InputEvent.ALT_MASK, false), "Collapse/Expand on mnemonic");
}
}
}
@@ -78,7 +78,7 @@ hg4idea.init.error.description=Couldn''t create a Mercurial repository in {0}
hg4idea.move.progress=Moving files in the VCS...
hg4idea.push.dialog.title=Push
hg4idea.push.branch=&Branch
hg4idea.push.branch=&Branch\:
hg4idea.push.force=&Force push
hg4idea.remove.single.title=Remove file from Mercurial
@@ -23,7 +23,7 @@
</vspacer>
<component id="e003e" class="javax.swing.JTextField" binding="repositoryTxt">
<constraints>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="1" use-parent-layout="false"/>
<grid row="2" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="6" anchor="8" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
<properties/>
</component>
@@ -45,7 +45,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="8" fill="0" indent="0" use-parent-layout="false"/>
</constraints>
<properties>
<text value="&amp;Revision"/>
<text value="&amp;Revision:"/>
</properties>
</component>
<component id="8b024" class="javax.swing.JTextField" binding="revisionTxt">
@@ -93,7 +93,7 @@
<grid row="0" column="0" row-span="1" col-span="1" vsize-policy="3" hsize-policy="7" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
</nested-form>
<component id="76372" class="com.intellij.ui.TitledSeparatorWithMnemonic">
<component id="78cf" class="com.intellij.ui.TitledSeparator">
<constraints>
<grid row="1" column="0" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
</constraints>
@@ -7,7 +7,7 @@
</constraints>
<properties/>
<clientProperties>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithIndent"/>
<BorderFactoryClass class="java.lang.String" value="com.intellij.ui.IdeBorderFactory$PlainSmallWithoutIndent"/>
</clientProperties>
<border type="none" title="Select repository"/>
<children>
@@ -179,7 +179,7 @@
<text value=" "/>
</properties>
</component>
<component id="b34c" class="com.intellij.ui.TitledSeparatorWithMnemonic">
<component id="b34c" class="com.intellij.ui.TitledSeparator">
<constraints>
<grid row="2" column="2" row-span="1" col-span="1" vsize-policy="0" hsize-policy="3" anchor="0" fill="1" indent="0" use-parent-layout="false"/>
<gridbag weightx="0.0" weighty="0.0"/>