use of javax.swing.event.ListSelectionListener in project pcgen by PCGen.
the class ExperienceAdjusterView method initComponents.
/** This method is called from within the constructor to
* initialize the form.
* WARNING: Do NOT modify this code. The content of this method is
* always regenerated by the Form Editor.
*/
private void initComponents() {
java.awt.GridBagConstraints gridBagConstraints;
jPanel5 = new javax.swing.JPanel();
panelChar = new javax.swing.JPanel();
characterList = new javax.swing.JList();
spCharLabel = new javax.swing.JLabel();
jPanel1 = new javax.swing.JPanel();
jLabel4 = new javax.swing.JLabel();
enemyList = new javax.swing.JList();
jPanel6 = new javax.swing.JPanel();
jPanel7 = new javax.swing.JPanel();
jLabel7 = new javax.swing.JLabel();
experienceToAdd = new javax.swing.JTextField(6);
addExperienceToCharButton = new javax.swing.JButton();
jPanel8 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
experienceFromCombat = new javax.swing.JLabel();
experienceMultNameLabel = new javax.swing.JLabel();
experienceMultSlider = new javax.swing.JSlider();
addExperienceToPartyButton = new javax.swing.JButton();
experienceMultLabel = new javax.swing.JLabel();
adjustCRButton = new javax.swing.JButton();
addEnemyButton = new javax.swing.JButton();
removeEnemyButton = new javax.swing.JButton();
scrollPaneChar = new JScrollPane(characterList);
scrollPaneEnemy = new JScrollPane(enemyList);
setLayout(new GridLayout(0, 1));
//$NON-NLS-1$
jPanel5.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_xp_char")));
jPanel5.setLayout(new java.awt.GridLayout(1, 0));
panelChar.setLayout(new java.awt.BorderLayout());
//$NON-NLS-1$
spCharLabel.setText(LanguageBundle.getString("in_plugin_xp_nameLvlXp"));
panelChar.add(spCharLabel, BorderLayout.NORTH);
panelChar.add(scrollPaneChar, java.awt.BorderLayout.CENTER);
jPanel5.add(panelChar);
jPanel1.setLayout(new java.awt.BorderLayout());
//$NON-NLS-1$
jLabel4.setText(LanguageBundle.getString("in_plugin_xp_nameCr"));
jPanel1.add(jLabel4, java.awt.BorderLayout.NORTH);
jPanel1.add(scrollPaneEnemy, java.awt.BorderLayout.CENTER);
add(jPanel5);
jPanel6.setLayout(new java.awt.GridLayout(1, 0));
//$NON-NLS-1$
jPanel6.setBorder(new TitledBorder(LanguageBundle.getString("in_plugin_xp_enemies")));
jPanel6.add(jPanel1);
jPanel7.setLayout(new java.awt.GridBagLayout());
// the button is after to allow the use of Tab after entering a value then pressing the button
//$NON-NLS-1$
jLabel7.setText(LanguageBundle.getString("in_plugin_xp_xpTo"));
//$NON-NLS-1$
addExperienceToCharButton.setText(LanguageBundle.getString("in_plugin_xp_selectedChar"));
addExperienceToCharButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
//$NON-NLS-1$
jPanel7.add(new JLabel(LanguageBundle.getString("in_plugin_xp_add")), gridBagConstraints);
jPanel7.add(experienceToAdd, gridBagConstraints);
jPanel7.add(jLabel7, gridBagConstraints);
jPanel7.add(addExperienceToCharButton, gridBagConstraints);
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
// add an empty horizontal glue like panel
jPanel7.add(new JPanel(), gridBagConstraints);
// Updates the button if there is a selected character
characterList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
addExperienceToCharButton.setEnabled(!characterList.isSelectionEmpty());
}
}
});
jPanel7.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, 0));
jPanel5.add(jPanel7);
jPanel8.setLayout(new java.awt.GridBagLayout());
//$NON-NLS-1$
jLabel5.setText(LanguageBundle.getString("in_plugin_xp_xpFromCombat"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridwidth = 2;
jPanel8.add(jLabel5, gridBagConstraints);
experienceFromCombat.setText(Integer.toString(0));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceFromCombat, gridBagConstraints);
//$NON-NLS-1$
experienceMultNameLabel.setText(LanguageBundle.getString("in_plugin_xp_normal"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 1;
gridBagConstraints.weightx = 1.0;
gridBagConstraints.fill = GridBagConstraints.HORIZONTAL;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceMultNameLabel, gridBagConstraints);
experienceMultSlider.setMaximum(10);
experienceMultSlider.setMinimum(-5);
experienceMultSlider.setValue(0);
// TODO the false value (the slider's) should not be visible, only the real one should
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 1;
gridBagConstraints.gridheight = 2;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
jPanel8.add(experienceMultSlider, gridBagConstraints);
experienceMultSlider.addChangeListener(new ChangeListener() {
@Override
public void stateChanged(ChangeEvent e) {
double realValue = getSliderRealValue();
if (CoreUtility.doublesEqual(realValue, 0.5)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_half"));
} else if (realValue <= 0.7) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_easier"));
} else if ((realValue > 0.7) && (realValue < 1.5)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_normal"));
} else if (realValue >= 1.5) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_harder"));
}
if (CoreUtility.doublesEqual(realValue, 2)) {
getExperienceMultNameLabel().setText(//$NON-NLS-1$
LanguageBundle.getString("in_plugin_xp_twice"));
}
getExperienceMultLabel().setText(LanguageBundle.getPrettyMultiplier(realValue));
model.setMultiplier(realValue);
}
});
//$NON-NLS-1$
addExperienceToPartyButton.setText(LanguageBundle.getString("in_plugin_xp_addXpToParty"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 3;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(addExperienceToPartyButton, gridBagConstraints);
experienceMultLabel.setText(LanguageBundle.getPrettyMultiplier(1.0d));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 2;
gridBagConstraints.gridy = 2;
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(experienceMultLabel, gridBagConstraints);
//$NON-NLS-1$
adjustCRButton.setText(LanguageBundle.getString("in_plugin_xp_adjustCr"));
adjustCRButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 5;
gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(adjustCRButton, gridBagConstraints);
//$NON-NLS-1$
addEnemyButton.setText(LanguageBundle.getString("in_plugin_xp_addEnemy"));
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 0;
gridBagConstraints.gridy = 6;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(addEnemyButton, gridBagConstraints);
//$NON-NLS-1$
removeEnemyButton.setText(LanguageBundle.getString("in_plugin_xp_removeEnemy"));
removeEnemyButton.setEnabled(false);
gridBagConstraints = new java.awt.GridBagConstraints();
gridBagConstraints.gridx = 1;
gridBagConstraints.gridy = 5;
gridBagConstraints.gridwidth = 2;
gridBagConstraints.insets = new java.awt.Insets(12, BORDER_SIZE, 0, 0);
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
jPanel8.add(removeEnemyButton, gridBagConstraints);
// Update buttons on selection change
enemyList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
if (!e.getValueIsAdjusting()) {
adjustCRButton.setEnabled(!enemyList.isSelectionEmpty());
removeEnemyButton.setEnabled(!enemyList.isSelectionEmpty());
}
}
});
jPanel8.setBorder(BorderFactory.createEmptyBorder(0, BORDER_SIZE, 0, 0));
jPanel6.add(jPanel8);
add(jPanel6);
}
use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.
the class MethodOrClosureScopeChooser method create.
/**
* @param callback is invoked if any scope was chosen. The first arg is this scope and the second arg is a psielement to search for (super method of chosen method or
* variable if the scope is a closure)
*/
public static JBPopup create(List<? extends GrParametersOwner> scopes, final Editor editor, final JBPopupOwner popupRef, final PairFunction<GrParametersOwner, PsiElement, Object> callback) {
final JPanel panel = new JPanel(new BorderLayout());
final JCheckBox superMethod = new JCheckBox(USE_SUPER_METHOD_OF, true);
superMethod.setMnemonic('U');
panel.add(superMethod, BorderLayout.SOUTH);
final JBList list = new JBList(scopes.toArray());
list.setVisibleRowCount(5);
list.setCellRenderer(new DefaultListCellRenderer() {
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
final String text;
if (value instanceof PsiMethod) {
final PsiMethod method = (PsiMethod) value;
text = PsiFormatUtil.formatMethod(method, PsiSubstitutor.EMPTY, PsiFormatUtilBase.SHOW_CONTAINING_CLASS | PsiFormatUtilBase.SHOW_NAME | PsiFormatUtilBase.SHOW_PARAMETERS, PsiFormatUtilBase.SHOW_TYPE);
final int flags = Iconable.ICON_FLAG_VISIBILITY;
final Icon icon = method.getIcon(flags);
if (icon != null)
setIcon(icon);
} else {
LOG.assertTrue(value instanceof GrClosableBlock);
setIcon(JetgroovyIcons.Groovy.Groovy_16x16);
text = "{...}";
}
setText(text);
return this;
}
});
list.getSelectionModel().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
list.setSelectedIndex(0);
final List<RangeHighlighter> highlighters = new ArrayList<>();
final TextAttributes attributes = EditorColorsManager.getInstance().getGlobalScheme().getAttributes(EditorColors.SEARCH_RESULT_ATTRIBUTES);
list.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(final ListSelectionEvent e) {
final GrParametersOwner selectedMethod = (GrParametersOwner) list.getSelectedValue();
if (selectedMethod == null)
return;
dropHighlighters(highlighters);
updateView(selectedMethod, editor, attributes, highlighters, superMethod);
}
});
updateView(scopes.get(0), editor, attributes, highlighters, superMethod);
final JScrollPane scrollPane = ScrollPaneFactory.createScrollPane(list);
scrollPane.setBorder(null);
panel.add(scrollPane, BorderLayout.CENTER);
final List<Pair<ActionListener, KeyStroke>> keyboardActions = Collections.singletonList(Pair.<ActionListener, KeyStroke>create(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
final GrParametersOwner ToSearchIn = (GrParametersOwner) list.getSelectedValue();
final JBPopup popup = popupRef.get();
if (popup != null && popup.isVisible()) {
popup.cancel();
}
final PsiElement toSearchFor;
if (ToSearchIn instanceof GrMethod) {
final GrMethod method = (GrMethod) ToSearchIn;
toSearchFor = superMethod.isEnabled() && superMethod.isSelected() ? method.findDeepestSuperMethod() : method;
} else {
toSearchFor = superMethod.isEnabled() && superMethod.isSelected() ? ToSearchIn.getParent() : null;
}
IdeFocusManager.findInstance().doWhenFocusSettlesDown(() -> callback.fun(ToSearchIn, toSearchFor), ModalityState.current());
}
}, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0)));
return JBPopupFactory.getInstance().createComponentPopupBuilder(panel, list).setTitle("Introduce parameter to").setMovable(false).setResizable(false).setRequestFocus(true).setKeyboardActions(keyboardActions).addListener(new JBPopupAdapter() {
@Override
public void onClosed(LightweightWindowEvent event) {
dropHighlighters(highlighters);
}
}).createPopup();
}
use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.
the class CreateResourceBundleDialogComponent method createUIComponents.
@SuppressWarnings("unchecked")
private void createUIComponents() {
final JBList projectExistLocalesList = new JBList();
final MyExistLocalesListModel existLocalesListModel = new MyExistLocalesListModel();
projectExistLocalesList.setModel(existLocalesListModel);
projectExistLocalesList.setCellRenderer(getLocaleRenderer());
myProjectExistLocalesPanel = ToolbarDecorator.createDecorator(projectExistLocalesList).disableRemoveAction().disableUpDownActions().createPanel();
myProjectExistLocalesPanel.setBorder(IdeBorderFactory.createTitledBorder("Project locales", false));
final JBList localesToAddList = new JBList();
final List<Locale> locales;
final List<Locale> restrictedLocales;
if (myResourceBundle == null) {
locales = Collections.singletonList(PropertiesUtil.DEFAULT_LOCALE);
restrictedLocales = Collections.emptyList();
} else {
locales = Collections.emptyList();
restrictedLocales = ContainerUtil.map(myResourceBundle.getPropertiesFiles(), PropertiesFile::getLocale);
}
myLocalesModel = new CollectionListModel<Locale>(locales) {
@Override
public void add(@NotNull List<? extends Locale> elements) {
final List<Locale> currentItems = getItems();
elements = ContainerUtil.filter(elements, locale -> !restrictedLocales.contains(locale) && !currentItems.contains(locale));
super.add(elements);
}
};
localesToAddList.setModel(myLocalesModel);
localesToAddList.setCellRenderer(getLocaleRenderer());
localesToAddList.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
projectExistLocalesList.clearSelection();
}
});
projectExistLocalesList.addFocusListener(new FocusAdapter() {
@Override
public void focusGained(FocusEvent e) {
localesToAddList.clearSelection();
}
});
myNewBundleLocalesPanel = ToolbarDecorator.createDecorator(localesToAddList).setAddAction(new AnActionButtonRunnable() {
@Override
public void run(AnActionButton button) {
final String rawAddedLocales = Messages.showInputDialog(myProject, PropertiesBundle.message("create.resource.bundle.dialog.add.locales.validator.message"), PropertiesBundle.message("create.resource.bundle.dialog.add.locales.validator.title"), null, null, new InputValidatorEx() {
@Nullable
@Override
public String getErrorText(String inputString) {
return checkInput(inputString) ? null : "Invalid locales";
}
@Override
public boolean checkInput(String inputString) {
return extractLocalesFromString(inputString) != null;
}
@Override
public boolean canClose(String inputString) {
return checkInput(inputString);
}
});
if (rawAddedLocales != null) {
final List<Locale> locales = extractLocalesFromString(rawAddedLocales);
LOG.assertTrue(locales != null);
myLocalesModel.add(locales);
}
}
}).setAddActionName("Add locales by suffix").disableUpDownActions().createPanel();
myNewBundleLocalesPanel.setBorder(IdeBorderFactory.createTitledBorder("Locales to add", false));
myAddLocaleFromExistButton = new JButton(AllIcons.Actions.Forward);
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (clickCount == 1) {
myLocalesModel.add(ContainerUtil.map(projectExistLocalesList.getSelectedValues(), o -> (Locale) o));
return true;
}
return false;
}
}.installOn(myAddLocaleFromExistButton);
projectExistLocalesList.addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
final List<Locale> currentItems = myLocalesModel.getItems();
for (Object o : projectExistLocalesList.getSelectedValues()) {
Locale l = (Locale) o;
if (!restrictedLocales.contains(l) && !currentItems.contains(l)) {
myAddLocaleFromExistButton.setEnabled(true);
return;
}
}
myAddLocaleFromExistButton.setEnabled(false);
}
});
myAddLocaleFromExistButton.setEnabled(false);
myAddAllButton = new JButton("Add All");
new ClickListener() {
@Override
public boolean onClick(@NotNull MouseEvent event, int clickCount) {
if (clickCount == 1) {
myLocalesModel.add(existLocalesListModel.getLocales());
}
return false;
}
}.installOn(myAddAllButton);
}
use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.
the class PythonSdkDetailsDialog method addListeners.
private void addListeners() {
myListener = new SdkModel.Listener() {
@Override
public void sdkAdded(Sdk sdk) {
}
@Override
public void beforeSdkRemove(Sdk sdk) {
}
@Override
public void sdkChanged(Sdk sdk, String previousName) {
refreshSdkList();
}
@Override
public void sdkHomeSelected(Sdk sdk, String newSdkHome) {
}
};
myProjectSdksModel.addListener(myListener);
mySdkList.addListSelectionListener(new ListSelectionListener() {
public void valueChanged(ListSelectionEvent event) {
updateOkButton();
}
});
}
use of javax.swing.event.ListSelectionListener in project intellij-community by JetBrains.
the class AbstractTableView method setToolbarActions.
public final void setToolbarActions(final AnAction... actions) {
final DefaultActionGroup actionGroup = new DefaultActionGroup();
for (final AnAction action : actions) {
actionGroup.add(action);
}
if (getHelpId() != null) {
actionGroup.add(Separator.getInstance());
actionGroup.add(new ContextHelpAction(getHelpId()));
}
final ActionManager actionManager = ActionManager.getInstance();
final ToolbarPosition position = getToolbarPosition();
final ActionToolbar myActionToolbar = actionManager.createActionToolbar(ActionPlaces.PROJECT_VIEW_TOOLBAR, actionGroup, position == ToolbarPosition.TOP || position == ToolbarPosition.BOTTOM);
myActionToolbar.setTargetComponent(myInnerPanel);
final JComponent toolbarComponent = myActionToolbar.getComponent();
final MatteBorder matteBorder = BorderFactory.createMatteBorder(0, 0, position == ToolbarPosition.TOP ? 1 : 0, 0, JBColor.DARK_GRAY);
toolbarComponent.setBorder(BorderFactory.createCompoundBorder(matteBorder, toolbarComponent.getBorder()));
getTable().getSelectionModel().addListSelectionListener(new ListSelectionListener() {
@Override
public void valueChanged(ListSelectionEvent e) {
myActionToolbar.updateActionsImmediately();
}
});
add(toolbarComponent, position.getPosition());
}
Aggregations