protected void onSave() { try { int channelInt = Integer.parseInt(channelName.getText()); if (channelInt < 0 || channelInt > 256) { throw new Exception(); } String key = getKey(String.valueOf(channelInt)); raptorPreferenceStore.setValue(key, colorSelector.getColorValue()); boolean channelsHasSelection = false; for (int i = 0; i < channels.getItemCount(); i++) { if (channels.getItem(i).equals(String.valueOf(channelInt))) { channelsHasSelection = true; break; } } if (!channelsHasSelection) { channels.add(String.valueOf(channelInt)); } } catch (Throwable t) { MessageDialog.openInformation( Raptor.getInstance().getWindow().getShell(), local.getString("alert"), local.getString("chatConColP3")); } }
private void editPressed() { setPresentsDefaultValue(false); String value = list.getItem(list.getSelectionIndex()); value = promptForText(local.getString("entNewVal"), value); if (value != null && isTextValid(value)) { list.setItem(list.getSelectionIndex(), value); selectionChanged(); } else { showErrorMessage(local.getString("invalid") + value); } }
/** Notifies that the Add button has been pressed. */ private void addPressed() { setPresentsDefaultValue(false); String value = promptForText(local.getString("entNewVal")); if (value != null && isTextValid(value)) { int index = list.getSelectionIndex(); if (index >= 0) { list.add(value, index + 1); } else { list.add(value, 0); } selectionChanged(); } else { showErrorMessage(local.getString("invalid") + value); } }
/** * Creates the Add, Remove, Up, and Down button in the given button box. * * @param box the box for the buttons */ private void createButtons(Composite box) { addButton = createPushButton(box, "ListEditor.add", null); // $NON-NLS-1$ editButton = createPushButton(box, null, local.getString("edit")); removeButton = createPushButton(box, "ListEditor.remove", null); // $NON-NLS-1$ upButton = createPushButton(box, "ListEditor.up", null); // $NON-NLS-1$ downButton = createPushButton(box, "ListEditor.down", null); // $NON-NLS-1$ }
/** * Prompts a user for the answer to a question. The user enters text. The text the user entered is * returned. * * @answer the initial text to place in the users answer. */ public String promptForText(final String question, String answer) { InputDialog dialog = new InputDialog(getShell(), L10n.getInstance().getString("entText"), question, true); if (answer != null) { dialog.setInput(answer); } return dialog.open(); }
public ClassicLayout() { super(null, L10n.getInstance().getString("consBottom")); addCrossConnectorSetting(PreferenceKeys.BUG_BUTTONS_QUADRANT, Quadrant.IX.toString()); addCrossConnectorSetting(PreferenceKeys.MAIN_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.CHANNEL_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.PERSON_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.REGEX_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.PARTNER_TELL_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.GAME_CHAT_TAB_QUADRANT, Quadrant.VI.toString()); addCrossConnectorSetting(PreferenceKeys.GAMES_TAB_QUADRANT, Quadrant.VIII.toString()); addCrossConnectorSetting(PreferenceKeys.GAME_BOT_QUADRANT, Quadrant.VIII.toString()); addCrossConnectorSetting(PreferenceKeys.BUG_WHO_QUADRANT, Quadrant.VIII.toString()); addCrossConnectorSetting(PreferenceKeys.SEEK_TABLE_QUADRANT, Quadrant.VIII.toString()); preferenceAdjustments.put(PreferenceKeys.APP_PGN_RESULTS_QUADRANT, Quadrant.II.toString()); preferenceAdjustments.put(PreferenceKeys.APP_BROWSER_QUADRANT, Quadrant.II.toString()); preferenceAdjustments.put( PreferenceKeys.APP_CHESS_BOARD_QUADRANTS, RaptorStringUtils.toDelimitedString( new String[] { Quadrant.II.toString(), Quadrant.III.toString(), Quadrant.IV.toString(), Quadrant.V.toString() }, ",")); preferenceAdjustments.put( PreferenceKeys.APP_QUAD9_QUAD12345678_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {10, 90})); preferenceAdjustments.put( PreferenceKeys.APP_QUAD1_QUAD2345678_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {50, 50})); preferenceAdjustments.put( PreferenceKeys.APP_QUAD2345_QUAD678_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {70, 30})); preferenceAdjustments.put( PreferenceKeys.APP_QUAD2_QUAD3_QUAD4_QUAD5_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {25, 25, 25, 25})); preferenceAdjustments.put( PreferenceKeys.APP_QUAD67_QUAD8_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {70, 30})); preferenceAdjustments.put( PreferenceKeys.APP_QUAD6_QUAD7_SASH_WEIGHTS, RaptorStringUtils.toString(new int[] {50, 50})); }
@Override protected void createFieldEditors() { addField( new ComboFieldEditor( PreferenceKeys.BOARD_USER_MOVE_INPUT_MODE, local.getString("chesBBehP10"), USER_MOVE_INPUT_MODE_ARRAY, getFieldEditorParent())); addField( new ComboFieldEditor( PreferenceKeys.BOARD_CLOCK_SHOW_MILLIS_WHEN_LESS_THAN, local.getString("chesBBehP11"), SHOW_TENTHS_OPTIONS, getFieldEditorParent())); addField( new ComboFieldEditor( PreferenceKeys.BOARD_CLOCK_SHOW_SECONDS_WHEN_LESS_THAN, local.getString("chesBBehP12"), SHOW_SECONDS_OPTIONS, getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_TRAVERSE_WITH_MOUSE_WHEEL, local.getString("chesBBehP13"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ALLOW_MOUSE_WHEEL_NAVIGATION_WHEEL_PLAYING, local.getString("chesBBehP14"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ANNOUNCE_CHECK_WHEN_I_CHECK_OPPONENT, local.getString("chesBBehP15"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ANNOUNCE_CHECK_WHEN_OPPONENT_CHECKS_ME, local.getString("chesBBehP16"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IGNORE_OBSERVED_GAMES_IF_PLAYING, local.getString("chesBBehP17"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_TAKEOVER_INACTIVE_GAMES, local.getString("chesBBehP18"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_USING_CROSSHAIRS_CURSOR, local.getString("chesBBehP19"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_ABORT_REQUEST_SOUND, local.getString("chesBBehP20"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_CHALLENGE_SOUND, local.getString("chesBBehP21"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_DRAW_OFFER_SOUND, local.getString("chesBBehP22"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_MOVE_SOUND_WHEN_OBSERVING, local.getString("chesBBehP23"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_PLAYING_10_SECOND_COUNTDOWN_SOUNDS, local.getString("chesBBehP24"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PREMOVE_ENABLED, local.getString("chesBBehP25"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_QUEUED_PREMOVE_ENABLED, local.getString("chesBBehP26"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_SHOW_COORDINATES, local.getString("chesBBehP27"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_SHOWING_PIECE_JAIL, local.getString("chesBBehP28"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SHOW_PLAYING_GAME_STATS_ON_GAME_END, local.getString("chesBBehP29"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_RESULTS, local.getString("chesBBehP30"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_MOVES_I_MAKE, local.getString("chesBBehP31"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_MOVES_OPP_MAKES, local.getString("chesBBehP32"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_WHEN_OBSERVING, local.getString("chesBBehP33"), getFieldEditorParent())); }
public ChessBoardBehaviorPage() { // Use the "flat" layout super(GRID); setTitle(local.getString("behavior")); setPreferenceStore(Raptor.getInstance().getPreferences()); }
public class ChessBoardBehaviorPage extends FieldEditorPreferencePage { protected static L10n local = L10n.getInstance(); public static final String[][] USER_MOVE_INPUT_MODE_ARRAY = { {local.getString("dragNDrop"), UserMoveInputMode.DragAndDrop.toString()}, {local.getString("clClMove"), UserMoveInputMode.ClickClickMove.toString()} }; public static final String[][] SHOW_SECONDS_OPTIONS = { {local.getString("always"), "" + Integer.MAX_VALUE}, {local.getString("chesBBehP1"), "" + (60 * 60 * 1000 + 1)}, {local.getString("chesBBehP2"), "" + (30 * 60 * 1000 + 1)}, {local.getString("chesBBehP3"), "" + (15 * 60 * 1000 + 1)}, {local.getString("chesBBehP4"), "" + (10 * 60 * 1000 + 1)} }; public static final String[][] SHOW_TENTHS_OPTIONS = { {local.getString("never"), "" + Integer.MIN_VALUE}, {local.getString("chesBBehP5"), "" + (10 * 1000 + 1)}, {local.getString("chesBBehP6"), "" + (60 * 1000 + 1)}, {local.getString("chesBBehP7"), "" + (3 * 60 * 1000 + 1)}, {local.getString("chesBBehP8"), "" + (5 * 60 * 1000 + 1)}, {local.getString("chesBBehP9"), "" + (10 * 60 * 1000 + 1)}, {local.getString("always"), "" + Integer.MAX_VALUE} }; public ChessBoardBehaviorPage() { // Use the "flat" layout super(GRID); setTitle(local.getString("behavior")); setPreferenceStore(Raptor.getInstance().getPreferences()); } @Override protected void createFieldEditors() { addField( new ComboFieldEditor( PreferenceKeys.BOARD_USER_MOVE_INPUT_MODE, local.getString("chesBBehP10"), USER_MOVE_INPUT_MODE_ARRAY, getFieldEditorParent())); addField( new ComboFieldEditor( PreferenceKeys.BOARD_CLOCK_SHOW_MILLIS_WHEN_LESS_THAN, local.getString("chesBBehP11"), SHOW_TENTHS_OPTIONS, getFieldEditorParent())); addField( new ComboFieldEditor( PreferenceKeys.BOARD_CLOCK_SHOW_SECONDS_WHEN_LESS_THAN, local.getString("chesBBehP12"), SHOW_SECONDS_OPTIONS, getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_TRAVERSE_WITH_MOUSE_WHEEL, local.getString("chesBBehP13"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ALLOW_MOUSE_WHEEL_NAVIGATION_WHEEL_PLAYING, local.getString("chesBBehP14"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ANNOUNCE_CHECK_WHEN_I_CHECK_OPPONENT, local.getString("chesBBehP15"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_ANNOUNCE_CHECK_WHEN_OPPONENT_CHECKS_ME, local.getString("chesBBehP16"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IGNORE_OBSERVED_GAMES_IF_PLAYING, local.getString("chesBBehP17"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_TAKEOVER_INACTIVE_GAMES, local.getString("chesBBehP18"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_USING_CROSSHAIRS_CURSOR, local.getString("chesBBehP19"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_ABORT_REQUEST_SOUND, local.getString("chesBBehP20"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_CHALLENGE_SOUND, local.getString("chesBBehP21"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_DRAW_OFFER_SOUND, local.getString("chesBBehP22"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PLAY_MOVE_SOUND_WHEN_OBSERVING, local.getString("chesBBehP23"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_PLAYING_10_SECOND_COUNTDOWN_SOUNDS, local.getString("chesBBehP24"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_PREMOVE_ENABLED, local.getString("chesBBehP25"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_QUEUED_PREMOVE_ENABLED, local.getString("chesBBehP26"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_SHOW_COORDINATES, local.getString("chesBBehP27"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_IS_SHOWING_PIECE_JAIL, local.getString("chesBBehP28"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SHOW_PLAYING_GAME_STATS_ON_GAME_END, local.getString("chesBBehP29"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_RESULTS, local.getString("chesBBehP30"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_MOVES_I_MAKE, local.getString("chesBBehP31"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_MOVES_OPP_MAKES, local.getString("chesBBehP32"), getFieldEditorParent())); addField( new BooleanFieldEditor( PreferenceKeys.BOARD_SPEAK_WHEN_OBSERVING, local.getString("chesBBehP33"), getFieldEditorParent())); } }
public ScriptsPage() { super(FLAT); setTitle(L10n.getInstance().getString("scripts")); setPreferenceStore(Raptor.getInstance().getPreferences()); }
/** * A clone of the SWT list editor. This version has a height hint you can set. Useful to keep lists * from growing far to large. */ public abstract class ListEditor extends FieldEditor { /** The list widget; <code>null</code> if none (before creation or after disposal). */ private List list; /** * The button box containing the Add, Remove, Up, and Down buttons; <code>null</code> if none * (before creation or after disposal). */ private Composite buttonBox; /** The Add button. */ private Button addButton; /** The Remove button. */ private Button removeButton; /** The Up button. */ private Button upButton; /** The edit button. */ private Button editButton; /** The Down button. */ private Button downButton; /** The selection listener. */ private SelectionListener selectionListener; private int heightHint = SWT.DEFAULT; protected static L10n local = L10n.getInstance(); /** Creates a new list field editor */ protected ListEditor() {} /** * Creates a list field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param parent the parent of the field editor's control */ protected ListEditor(String name, String labelText, Composite parent) { init(name, labelText); createControl(parent); } /** * Creates a list field editor. * * @param name the name of the preference this field editor works on * @param labelText the label text of the field editor * @param parent the parent of the field editor's control */ protected ListEditor(String name, String labelText, Composite parent, int heightHint) { this.heightHint = heightHint; init(name, labelText); createControl(parent); } /** Creates a selection listener. */ public void createSelectionListener() { selectionListener = new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent event) { Widget widget = event.widget; if (widget == addButton) { addPressed(); } else if (widget == editButton) { editPressed(); } else if (widget == removeButton) { removePressed(); } else if (widget == upButton) { upPressed(); } else if (widget == downButton) { downPressed(); } else if (widget == list) { selectionChanged(); } } }; } /** * Returns this field editor's button box containing the Add, Remove, Up, and Down button. * * @param parent the parent control * @return the button box */ public Composite getButtonBoxControl(Composite parent) { if (buttonBox == null) { buttonBox = new Composite(parent, SWT.NULL); GridLayout layout = new GridLayout(); layout.marginWidth = 0; buttonBox.setLayout(layout); createButtons(buttonBox); buttonBox.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent event) { addButton = null; removeButton = null; editButton = null; upButton = null; downButton = null; buttonBox = null; } }); } else { checkParent(buttonBox, parent); } selectionChanged(); return buttonBox; } public int getHeightHint() { return heightHint; } /** * Returns this field editor's list control. * * @param parent the parent control * @return the list control */ public List getListControl(Composite parent) { if (list == null) { list = new List(parent, SWT.BORDER | SWT.SINGLE | SWT.V_SCROLL | SWT.H_SCROLL); list.setFont(parent.getFont()); list.addSelectionListener(getSelectionListener()); list.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent event) { list = null; } }); } else { checkParent(list, parent); } return list; } /* * (non-) Method declared on FieldEditor. */ @Override public int getNumberOfControls() { return 2; } /** * Prompts a user for the answer to a question. The user enters text. The text the user entered is * returned. */ public String promptForText(final String question) { InputDialog dialog = new InputDialog(getShell(), L10n.getInstance().getString("entText"), question, true); return dialog.open(); } /** * Prompts a user for the answer to a question. The user enters text. The text the user entered is * returned. * * @answer the initial text to place in the users answer. */ public String promptForText(final String question, String answer) { InputDialog dialog = new InputDialog(getShell(), L10n.getInstance().getString("entText"), question, true); if (answer != null) { dialog.setInput(answer); } return dialog.open(); } /** * Returns true if the text is valid, false otherwise. * * @param text The text to check. * @return True if valid, false otherwise. */ public boolean isTextValid(String text) { return true; } /* * @see FieldEditor.setEnabled(boolean,Composite). */ @Override public void setEnabled(boolean enabled, Composite parent) { super.setEnabled(enabled, parent); getListControl(parent).setEnabled(enabled); addButton.setEnabled(enabled); editButton.setEnabled(enabled); removeButton.setEnabled(enabled); upButton.setEnabled(enabled); downButton.setEnabled(enabled); } /* * (non-) Method declared on FieldEditor. */ @Override public void setFocus() { if (list != null) { list.setFocus(); } } public void setHeightHint(int heightHint) { this.heightHint = heightHint; } /* * (non-) Method declared on FieldEditor. */ @Override protected void adjustForNumColumns(int numColumns) { Control control = getLabelControl(); ((GridData) control.getLayoutData()).horizontalSpan = numColumns; ((GridData) list.getLayoutData()).horizontalSpan = numColumns - 1; } /** * Combines the given list of items into a single string. This method is the converse of <code> * parseString</code>. * * <p>Subclasses must implement this method. * * @param items the list of items * @return the combined string * @see #parseString */ protected abstract String createList(String[] items); /* * (non-) Method declared on FieldEditor. */ @Override protected void doFillIntoGrid(Composite parent, int numColumns) { Control control = getLabelControl(parent); GridData gd = new GridData(); gd.horizontalSpan = numColumns; control.setLayoutData(gd); list = getListControl(parent); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = heightHint; gd.verticalAlignment = GridData.FILL; gd.horizontalSpan = numColumns - 1; gd.grabExcessHorizontalSpace = true; list.setLayoutData(gd); buttonBox = getButtonBoxControl(parent); gd = new GridData(); gd.verticalAlignment = GridData.BEGINNING; buttonBox.setLayoutData(gd); } /* * (non-) Method declared on FieldEditor. */ @Override protected void doLoad() { if (list != null) { String s = getPreferenceStore().getString(getPreferenceName()); String[] array = parseString(s); for (int i = 0; i < array.length; i++) { list.add(array[i]); } } } /* * (non-) Method declared on FieldEditor. */ @Override protected void doLoadDefault() { if (list != null) { list.removeAll(); String s = getPreferenceStore().getDefaultString(getPreferenceName()); String[] array = parseString(s); for (int i = 0; i < array.length; i++) { list.add(array[i]); } } } /* * (non-) Method declared on FieldEditor. */ @Override protected void doStore() { String s = createList(list.getItems()); if (s != null) { getPreferenceStore().setValue(getPreferenceName(), s); } } /** * Creates and returns a new item for the list. * * <p>Subclasses must implement this method. * * @return a new item */ protected abstract String getNewInputObject(); /** * Returns this field editor's shell. * * <p>This method is internal to the framework; subclassers should not call this method. * * @return the shell */ protected Shell getShell() { if (addButton == null) { return null; } return addButton.getShell(); } /** * Splits the given string into a list of strings. This method is the converse of <code>createList * </code>. * * <p>Subclasses must implement this method. * * @param stringList the string * @return an array of <code>String</code> * @see #createList */ protected abstract String[] parseString(String stringList); /** Notifies that the Add button has been pressed. */ private void addPressed() { setPresentsDefaultValue(false); String value = promptForText(local.getString("entNewVal")); if (value != null && isTextValid(value)) { int index = list.getSelectionIndex(); if (index >= 0) { list.add(value, index + 1); } else { list.add(value, 0); } selectionChanged(); } else { showErrorMessage(local.getString("invalid") + value); } } /** * Creates the Add, Remove, Up, and Down button in the given button box. * * @param box the box for the buttons */ private void createButtons(Composite box) { addButton = createPushButton(box, "ListEditor.add", null); // $NON-NLS-1$ editButton = createPushButton(box, null, local.getString("edit")); removeButton = createPushButton(box, "ListEditor.remove", null); // $NON-NLS-1$ upButton = createPushButton(box, "ListEditor.up", null); // $NON-NLS-1$ downButton = createPushButton(box, "ListEditor.down", null); // $NON-NLS-1$ } /** * Helper method to create a push button. * * @param parent the parent control * @param key the resource name used to supply the button's label text * @return Button */ private Button createPushButton(Composite parent, String key, String keyOverride) { Button button = new Button(parent, SWT.PUSH); button.setText(key != null ? JFaceResources.getString(key) : keyOverride); button.setFont(parent.getFont()); GridData data = new GridData(GridData.FILL_HORIZONTAL); int widthHint = convertHorizontalDLUsToPixels(button, IDialogConstants.BUTTON_WIDTH); data.widthHint = Math.max(widthHint, button.computeSize(SWT.DEFAULT, SWT.DEFAULT, true).x); button.setLayoutData(data); button.addSelectionListener(getSelectionListener()); return button; } /** Notifies that the Down button has been pressed. */ private void downPressed() { swap(false); } private void editPressed() { setPresentsDefaultValue(false); String value = list.getItem(list.getSelectionIndex()); value = promptForText(local.getString("entNewVal"), value); if (value != null && isTextValid(value)) { list.setItem(list.getSelectionIndex(), value); selectionChanged(); } else { showErrorMessage(local.getString("invalid") + value); } } /** * Returns this field editor's selection listener. The listener is created if nessessary. * * @return the selection listener */ private SelectionListener getSelectionListener() { if (selectionListener == null) { createSelectionListener(); } return selectionListener; } /** Notifies that the Remove button has been pressed. */ private void removePressed() { setPresentsDefaultValue(false); int index = list.getSelectionIndex(); if (index >= 0) { list.remove(index); selectionChanged(); } } /** Notifies that the list selection has changed. */ private void selectionChanged() { int index = list.getSelectionIndex(); int size = list.getItemCount(); removeButton.setEnabled(index >= 0); editButton.setEnabled(index >= 0); upButton.setEnabled(size > 1 && index > 0); downButton.setEnabled(size > 1 && index >= 0 && index < size - 1); } /** * Moves the currently selected item up or down. * * @param up <code>true</code> if the item should move up, and <code>false</code> if it should * move down */ private void swap(boolean up) { setPresentsDefaultValue(false); int index = list.getSelectionIndex(); int target = up ? index - 1 : index + 1; if (index >= 0) { String[] selection = list.getSelection(); Assert.isTrue(selection.length == 1); list.remove(index); list.add(selection[0], target); list.setSelection(target); } selectionChanged(); } /** Notifies that the Up button has been pressed. */ private void upPressed() { swap(true); } }
/** * Prompts a user for the answer to a question. The user enters text. The text the user entered is * returned. */ public String promptForText(final String question) { InputDialog dialog = new InputDialog(getShell(), L10n.getInstance().getString("entText"), question, true); return dialog.open(); }
@Override protected Control createContents(Composite parent) { parent = new Composite(parent, SWT.NONE); parent.setLayout(new GridLayout(3, false)); Label label = new Label(parent, SWT.NONE); label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); label.setText( WordUtils.wrap(local.getString("chatConColP1"), 70) + WordUtils.wrap(local.getString("chatConColP2"), 70)); Label channelNamesLabel = new Label(parent, SWT.NONE); channelNamesLabel.setText(local.getString("channels")); channelNamesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); channels = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); channels.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); channels.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String selectedChannelName = channels.getItem(channels.getSelectionIndex()); channelName.setText(selectedChannelName); String key = getKey(selectedChannelName); colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB()); } }); Label channelNameLabel = new Label(parent, SWT.NONE); channelNameLabel.setText(local.getString("chanName")); channelNameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); channelName = new Text(parent, SWT.SINGLE | SWT.BORDER); channelName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); colorSelector = new ColorSelector(parent); colorSelector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); saveButton = new Button(parent, SWT.PUSH); saveButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); saveButton.setText(local.getString("svAddChCol")); saveButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { onSave(); } }); // deleteButton = new Button(parent, SWT.PUSH); // deleteButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, // false, 2, 1)); // deleteButton.setText("Delete Channel Color"); // deleteButton.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e) { // try { // int channelInt = Integer.parseInt(channelName.getText()); // String key = getKey("" + channelInt); // channels.remove("" + channelInt); // raptorPreferenceStore.putValue(key, null); // } catch (NumberFormatException nfe) { // MessageDialog // .openInformation(Raptor.getInstance() // .getRaptorWindow().getShell(), "Alert", // "Channel name must be an integer greater than -1 and less than 256."); // } // } // }); updateChannelsCombo(); if (channels.getItemCount() > 0) { channels.select(0); String selectedChannelName = channels.getItem(channels.getSelectionIndex()); channelName.setText(selectedChannelName); String key = getKey(selectedChannelName); colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB()); } return parent; }
public ChatConsoleChannelColorsPage() { // Use the "flat" layout super(); setPreferenceStore(raptorPreferenceStore = Raptor.getInstance().getPreferences()); setTitle(local.getString("chanCol")); }
public class ChatConsoleChannelColorsPage extends PreferencePage { Text channelName; Combo channels; ColorSelector colorSelector; RaptorPreferenceStore raptorPreferenceStore; Button saveButton; protected static L10n local = L10n.getInstance(); public ChatConsoleChannelColorsPage() { // Use the "flat" layout super(); setPreferenceStore(raptorPreferenceStore = Raptor.getInstance().getPreferences()); setTitle(local.getString("chanCol")); } public String getKey(String channel) { return PreferenceKeys.CHAT_CHAT_EVENT_TYPE_COLOR_APPEND_TO + ChatType.CHANNEL_TELL + "-" + channel + "-color"; } public void updateChannelsCombo() { for (int i = 0; i < 255; i++) { String key = getKey(String.valueOf(i)); if (raptorPreferenceStore.contains(key)) { boolean contains = false; for (int j = 0; j < channels.getItemCount(); j++) { if (channels.getItem(j).equals(String.valueOf(i))) { contains = true; break; } } if (!contains) { channels.add(String.valueOf(i)); } } } } @Override protected Control createContents(Composite parent) { parent = new Composite(parent, SWT.NONE); parent.setLayout(new GridLayout(3, false)); Label label = new Label(parent, SWT.NONE); label.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); label.setText( WordUtils.wrap(local.getString("chatConColP1"), 70) + WordUtils.wrap(local.getString("chatConColP2"), 70)); Label channelNamesLabel = new Label(parent, SWT.NONE); channelNamesLabel.setText(local.getString("channels")); channelNamesLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); channels = new Combo(parent, SWT.DROP_DOWN | SWT.READ_ONLY); channels.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 2, 1)); channels.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { String selectedChannelName = channels.getItem(channels.getSelectionIndex()); channelName.setText(selectedChannelName); String key = getKey(selectedChannelName); colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB()); } }); Label channelNameLabel = new Label(parent, SWT.NONE); channelNameLabel.setText(local.getString("chanName")); channelNameLabel.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 1)); channelName = new Text(parent, SWT.SINGLE | SWT.BORDER); channelName.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1)); colorSelector = new ColorSelector(parent); colorSelector.getButton().setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 1, 1)); saveButton = new Button(parent, SWT.PUSH); saveButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, false, 3, 1)); saveButton.setText(local.getString("svAddChCol")); saveButton.addSelectionListener( new SelectionAdapter() { @Override public void widgetSelected(SelectionEvent e) { onSave(); } }); // deleteButton = new Button(parent, SWT.PUSH); // deleteButton.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, false, // false, 2, 1)); // deleteButton.setText("Delete Channel Color"); // deleteButton.addSelectionListener(new SelectionAdapter() { // @Override // public void widgetSelected(SelectionEvent e) { // try { // int channelInt = Integer.parseInt(channelName.getText()); // String key = getKey("" + channelInt); // channels.remove("" + channelInt); // raptorPreferenceStore.putValue(key, null); // } catch (NumberFormatException nfe) { // MessageDialog // .openInformation(Raptor.getInstance() // .getRaptorWindow().getShell(), "Alert", // "Channel name must be an integer greater than -1 and less than 256."); // } // } // }); updateChannelsCombo(); if (channels.getItemCount() > 0) { channels.select(0); String selectedChannelName = channels.getItem(channels.getSelectionIndex()); channelName.setText(selectedChannelName); String key = getKey(selectedChannelName); colorSelector.setColorValue(raptorPreferenceStore.getColor(key).getRGB()); } return parent; } protected void onSave() { try { int channelInt = Integer.parseInt(channelName.getText()); if (channelInt < 0 || channelInt > 256) { throw new Exception(); } String key = getKey(String.valueOf(channelInt)); raptorPreferenceStore.setValue(key, colorSelector.getColorValue()); boolean channelsHasSelection = false; for (int i = 0; i < channels.getItemCount(); i++) { if (channels.getItem(i).equals(String.valueOf(channelInt))) { channelsHasSelection = true; break; } } if (!channelsHasSelection) { channels.add(String.valueOf(channelInt)); } } catch (Throwable t) { MessageDialog.openInformation( Raptor.getInstance().getWindow().getShell(), local.getString("alert"), local.getString("chatConColP3")); } } @Override protected void performApply() { onSave(); super.performApply(); } }