⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 actioncontributionitem.java

📁 jfa2ce 源码帮助开发人员更好的理解运用
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
                }                if (imageChanged) {                    // only substitute a missing image if it has no text                    updateImages(!showText);                }                if (tooltipTextChanged || textChanged) {                    String toolTip = action.getToolTipText();					if ((toolTip == null) || (toolTip.length() == 0)) {						toolTip = text;					}                    // if the text is showing, then only set the tooltip if					// different                    if (!showText || toolTip != null && !toolTip.equals(text)) {                        ti.setToolTipText(toolTip);                    } else {                        ti.setToolTipText(null);                    }                }                if (enableStateChanged) {                    boolean shouldBeEnabled = action.isEnabled()                            && isEnabledAllowed();                    if (ti.getEnabled() != shouldBeEnabled) {						ti.setEnabled(shouldBeEnabled);					}                }                if (checkChanged) {                    boolean bv = action.isChecked();                    if (ti.getSelection() != bv) {						ti.setSelection(bv);					}                }                return;            }            if (widget instanceof MenuItem) {                MenuItem mi = (MenuItem) widget;                if (textChanged) {                    int accelerator = 0;					String acceleratorText = null;					IAction updatedAction = getAction();					String text = null;					accelerator = updatedAction.getAccelerator();					ExternalActionManager.ICallback callback = ExternalActionManager							.getInstance().getCallback();					// Block accelerators that are already in use.					if ((accelerator != 0) && (callback != null)                            && (callback.isAcceleratorInUse(accelerator))) {                        accelerator = 0;					}					/*					 * Process accelerators on GTK in a special way to avoid Bug					 * 42009. We will override the native input method by					 * allowing these reserved accelerators to be placed on the					 * menu. We will only do this for "Ctrl+Shift+[0-9A-FU]".					 */					final String commandId = updatedAction							.getActionDefinitionId();					if (("gtk".equals(SWT.getPlatform())) && (callback instanceof IBindingManagerCallback) //$NON-NLS-1$							&& (commandId != null)) {						final IBindingManagerCallback bindingManagerCallback = (IBindingManagerCallback) callback;						final IKeyLookup lookup = KeyLookupFactory.getDefault();						final TriggerSequence[] triggerSequences = bindingManagerCallback								.getActiveBindingsFor(commandId);						for (int i = 0; i < triggerSequences.length; i++) {							final TriggerSequence triggerSequence = triggerSequences[i];							final Trigger[] triggers = triggerSequence									.getTriggers();							if (triggers.length == 1) {								final Trigger trigger = triggers[0];								if (trigger instanceof KeyStroke) {									final KeyStroke currentKeyStroke = (KeyStroke) trigger;									final int currentNaturalKey = currentKeyStroke											.getNaturalKey();									if ((currentKeyStroke.getModifierKeys() == (lookup											.getCtrl() | lookup.getShift()))											&& ((currentNaturalKey >= '0' && currentNaturalKey <= '9')													|| (currentNaturalKey >= 'A' && currentNaturalKey <= 'F') || (currentNaturalKey == 'U'))) {										accelerator = currentKeyStroke												.getModifierKeys()												| currentNaturalKey;										acceleratorText = triggerSequence												.format();										break;									}								}							}						}					}                    if (accelerator == 0) {                        if ((callback != null) && (commandId != null)) {                            acceleratorText = callback                                    .getAcceleratorText(commandId);                        }                    } else {                        acceleratorText = Action                                .convertAccelerator(accelerator);                    }                    IContributionManagerOverrides overrides = null;                    if (getParent() != null) {						overrides = getParent().getOverrides();					}                    if (overrides != null) {						text = getParent().getOverrides().getText(this);					}                    mi.setAccelerator(accelerator);                    if (text == null) {						text = updatedAction.getText();					}                    if (text == null) {						text = ""; //$NON-NLS-1$					} else {						text = Action.removeAcceleratorText(text);					}                    if (acceleratorText == null) {						mi.setText(text);					} else {						mi.setText(text + '\t' + acceleratorText);					}                }                if (imageChanged) {					updateImages(false);				}                if (enableStateChanged) {                    boolean shouldBeEnabled = action.isEnabled()                            && isEnabledAllowed();                    if (mi.getEnabled() != shouldBeEnabled) {						mi.setEnabled(shouldBeEnabled);					}                }                if (checkChanged) {                    boolean bv = action.isChecked();                    if (mi.getSelection() != bv) {						mi.setSelection(bv);					}                }                return;            }            if (widget instanceof Button) {                Button button = (Button) widget;                if (imageChanged && updateImages(false)) {					textChanged = false; // don't update text if it has an image				}                if (textChanged) {                    String text = action.getText();                    if (text == null) {						text = ""; //$NON-NLS-1$					} else {						text = Action.removeAcceleratorText(text);					}                    button.setText(text);                }                if (tooltipTextChanged) {					button.setToolTipText(action.getToolTipText());				}                if (enableStateChanged) {                    boolean shouldBeEnabled = action.isEnabled()                            && isEnabledAllowed();                    if (button.getEnabled() != shouldBeEnabled) {						button.setEnabled(shouldBeEnabled);					}                }                if (checkChanged) {                    boolean bv = action.isChecked();                    if (button.getSelection() != bv) {						button.setSelection(bv);					}                }                return;            }        }    }    /**     * Updates the images for this action.     *     * @param forceImage <code>true</code> if some form of image is compulsory,     *  and <code>false</code> if it is acceptable for this item to have no image     * @return <code>true</code> if there are images for this action, <code>false</code> if not     */    private boolean updateImages(boolean forceImage) {        ResourceManager parentResourceManager = JFaceResources.getResources();                if (widget instanceof ToolItem) {            if (USE_COLOR_ICONS) {                ImageDescriptor image = action.getHoverImageDescriptor();                if (image == null) {                    image = action.getImageDescriptor();                }                ImageDescriptor disabledImage = action                        .getDisabledImageDescriptor();                // Make sure there is a valid image.                if (image == null && forceImage) {                    image = ImageDescriptor.getMissingImageDescriptor();                }                        LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);                                // performance: more efficient in SWT to set disabled and hot image before regular image                ((ToolItem) widget).setDisabledImage(disabledImage == null ? null : localManager.createImageWithDefault(disabledImage));                ((ToolItem) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));                disposeOldImages();                imageManager = localManager;                                return image != null;            }            ImageDescriptor image = action.getImageDescriptor();            ImageDescriptor hoverImage = action                    .getHoverImageDescriptor();            ImageDescriptor disabledImage = action                    .getDisabledImageDescriptor();            // If there is no regular image, but there is a hover image,            // convert the hover image to gray and use it as the regular image.            if (image == null && hoverImage != null) {                image = ImageDescriptor.createWithFlags(action.getHoverImageDescriptor(), SWT.IMAGE_GRAY);             } else {                // If there is no hover image, use the regular image as the hover image,                // and convert the regular image to gray                if (hoverImage == null && image != null) {                    hoverImage = image;                    image = ImageDescriptor.createWithFlags(action.getImageDescriptor(), SWT.IMAGE_GRAY);                }            }            // Make sure there is a valid image.            if (hoverImage == null && image == null && forceImage) {                image = ImageDescriptor.getMissingImageDescriptor();            }            // Create a local resource manager to remember the images we've allocated for this tool item            LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);                        // performance: more efficient in SWT to set disabled and hot image before regular image            ((ToolItem) widget).setDisabledImage(disabledImage == null? null : localManager.createImageWithDefault(disabledImage));            ((ToolItem) widget).setHotImage(hoverImage == null? null : localManager.createImageWithDefault(hoverImage));            ((ToolItem) widget).setImage(image == null? null : localManager.createImageWithDefault(image));            // Now that we're no longer referencing the old images, clear them out.            disposeOldImages();            imageManager = localManager;                        return image != null;        } else if (widget instanceof Item || widget instanceof Button) {                        // Use hover image if there is one, otherwise use regular image.            ImageDescriptor image = action.getHoverImageDescriptor();            if (image == null) {                image = action.getImageDescriptor();            }            // Make sure there is a valid image.            if (image == null && forceImage) {                image = ImageDescriptor.getMissingImageDescriptor();            }                        // Create a local resource manager to remember the images we've allocated for this widget            LocalResourceManager localManager = new LocalResourceManager(parentResourceManager);                        if (widget instanceof Item) {                ((Item) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));            } else if (widget instanceof Button) {                ((Button) widget).setImage(image == null ? null : localManager.createImageWithDefault(image));            }                        // Now that we're no longer referencing the old images, clear them out.            disposeOldImages();            imageManager = localManager;                        return image != null;        }        return false;    }    /**     * Dispose any images allocated for this contribution item     */    private void disposeOldImages() {        if (imageManager != null) {            imageManager.dispose();            imageManager = null;        }    }    /**     * Shorten the given text <code>t</code> so that its length doesn't     * exceed the given width. The default implementation replaces characters     * in the center of the original string with an ellipsis ("..."). Override     * if you need a different strategy.     */    protected String shortenText(String textValue, ToolItem item) {        if (textValue == null) {			return null;		}        GC gc = new GC(item.getParent());        int maxWidth = item.getImage().getBounds().width * 4;        if (gc.textExtent(textValue).x < maxWidth) {            gc.dispose();            return textValue;        }        for (int i = textValue.length(); i > 0; i--) {            String test = textValue.substring(0, i);            test = test + ellipsis;            if (gc.textExtent(test).x < maxWidth) {                gc.dispose();                return test;            }        }        gc.dispose();        //If for some reason we fall through abort        return textValue;    }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -