📄 titleareadialog.java
字号:
* @deprecated */ protected Composite getTitleArea() { return getShell(); } /** * Returns the title image label. * * @return the title image label */ protected Label getTitleImageLabel() { return titleImageLabel; } /** * Display the given error message. The currently displayed message is saved * and will be redisplayed when the error message is set to * <code>null</code>. * * @param newErrorMessage * the newErrorMessage to display or <code>null</code> */ public void setErrorMessage(String newErrorMessage) { // Any change? if (errorMessage == null ? newErrorMessage == null : errorMessage .equals(newErrorMessage)) { return; } errorMessage = newErrorMessage; //Clear or set error message. if (errorMessage == null) { if(messageArea != null && !showingWarning){ setMessageAreaVisible(false); } if (showingError) { // we were previously showing an error showingError = false; } // show the message // avoid calling setMessage in case it is overridden to call // setErrorMessage, // which would result in a recursive infinite loop if (message == null) { // setMessage does this conversion.... message = ""; //$NON-NLS-1$ } updateMessage(message); messageImageLabel.setImage(messageImage); setImageLabelVisible(messageImage != null); if(showingWarning) setWarningMessage(warningMessage); } else { if (!showingError) { // we were not previously showing an error showingError = true; } if(showingWarning) setWarningMessage(null); if(messageArea == null){ // create a message area to display the error messageArea = new ImageAndMessageArea(titleArea, SWT.WRAP); messageArea.setBackground(messageLabel.getBackground()); animator = Policy.getAnimatorFactory().createAnimator(messageArea); } // show the error messageArea.setToolTipText(errorMessage); messageArea.setText(errorMessage); messageArea.setImage(JFaceResources.getImage(DLG_IMG_TITLE_ERROR)); setMessageAreaVisible(true); } int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing); } /** * Sets whether the message area should appear or dissapear * * @param visible * <code>true</code> if the message area should be * displayed, and <code>false</code> otherwise. */ private void setMessageAreaVisible(boolean visible) { messageArea.moveAbove(null); // assumes that bottom of the message area should match // the bottom of te parent composite. int bottom = titleArea.getBounds().y + titleArea.getBounds().height; // Only set bounds if the message area is CLOSED (i.e. not visible) // and out of place. The bounds are dependent on whether a message // image is being shown. Rectangle msgLabelBounds = messageLabel.getBounds(); if(!messageArea.isVisible() && messageArea.getBounds().y != bottom) { messageArea.setBounds( (messageImageLabel == null) ? msgLabelBounds.x: messageImageLabel.getBounds().x, bottom, (messageImageLabel == null) ? msgLabelBounds.width: msgLabelBounds.width + messageImageLabel.getBounds().width, messageArea.computeSize(SWT.DEFAULT,SWT.DEFAULT).y); } animator.setVisible(visible); setMessageLayoutData(); } /** * Set the layoutData for the messageArea. */ private void setMessageLayoutData() { if(messageArea == null) return; FormData messageAreaData = new FormData(); messageAreaData.right = new FormAttachment(titleImageLabel); messageAreaData.left = new FormAttachment(leftFillerLabel); messageAreaData.bottom = new FormAttachment(100,0); messageArea.setLayoutData(messageAreaData); } /** * Re-layout the labels for the new message. */ private void layoutForNewMessage() { int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing); //Do not layout before the dialog area has been created //to avoid incomplete calculations. if (dialogArea != null) { workArea.getParent().layout(true); // force re-layout of controls on titleArea since the // above call will not perform this operation if the // titleArea has resized. titleArea.layout(true); } } /** * Set the message text. If the message line currently displays an error, * the message is saved and will be redisplayed when the error message is * set to <code>null</code>. * <p> * Shortcut for <code>setMessage(newMessage, IMessageProvider.NONE)</code> * </p> * This method should be called after the dialog has been opened as it * updates the message label immediately. * * @param newMessage * the message, or <code>null</code> to clear the message */ public void setMessage(String newMessage) { setMessage(newMessage, IMessageProvider.NONE); } /** * Sets the message for this dialog with an indication of what type of * message it is. * <p> * The valid message types are one of <code>NONE</code>, * <code>INFORMATION</code>,<code>WARNING</code>, or * <code>ERROR</code>. * </p> * <p> * Note that for backward compatibility, a message of type * <code>ERROR</code> is different than an error message (set using * <code>setErrorMessage</code>). An error message overrides the current * message until the error message is cleared. This method replaces the * current message and does not affect the error message. * </p> * * @param newMessage * the message, or <code>null</code> to clear the message * @param newType * the message type * @since 2.0 */ public void setMessage(String newMessage, int newType) { Image newImage = null; if (newMessage != null) { switch (newType) { case IMessageProvider.NONE: break; case IMessageProvider.INFORMATION: newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_INFO); break; case IMessageProvider.WARNING: newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING); break; case IMessageProvider.ERROR: newImage = JFaceResources.getImage(DLG_IMG_MESSAGE_ERROR); break; } } if(newType == IMessageProvider.WARNING) setWarningMessage(newMessage); else { setWarningMessage(null); showMessage(newMessage, newImage); } } /** * Show the new message and image. * @param newMessage * @param newImage */ private void showMessage(String newMessage, Image newImage) { // Any change? if (message.equals(newMessage) && messageImage == newImage) { return; } message = newMessage; if (message == null) { message = "";//$NON-NLS-1$ } // Message string to be shown - if there is an image then add in // a space to the message for layout purposes String shownMessage = message; messageImage = newImage; if (!showingError) { // we are not showing an error updateMessage(shownMessage); messageImageLabel.setImage(messageImage); setImageLabelVisible(messageImage != null); layoutForNewMessage(); } } /** * Update the contents of the messageLabel. * * @param newMessage * the message to use */ private void updateMessage(String newMessage) { messageLabel.setText(newMessage); } /** * Sets the title to be shown in the title area of this dialog. * * @param newTitle * the title show */ public void setTitle(String newTitle) { if (titleLabel == null) { return; } String title = newTitle; if (title == null) { title = "";//$NON-NLS-1$ } titleLabel.setText(title); } /** * Sets the title bar color for this dialog. * * @param color * the title bar color */ public void setTitleAreaColor(RGB color) { titleAreaRGB = color; } /** * Sets the title image to be shown in the title area of this dialog. * * @param newTitleImage * the title image to be shown */ public void setTitleImage(Image newTitleImage) { titleImage = newTitleImage; // Check that the title area has been created. // See https://bugs.eclipse.org/bugs/show_bug.cgi?id=82064 if (titleImageLabel != null && !titleImageLabel.isDisposed()) { titleImageLabel.setImage(newTitleImage); titleImageLabel.setVisible(newTitleImage != null); if (newTitleImage != null) { resetWorkAreaAttachments(titleArea); } } } /** * Make the label used for displaying error images visible depending on * boolean. * @param visible If <code>true</code> make the image visible, if * not then make it not visible. */ private void setImageLabelVisible(boolean visible) { messageImageLabel.setVisible(visible); leftFillerLabel.setVisible(visible); } /** * Reset the attachment of the workArea to now attach to top as the top * control. * * @param top */ private void resetWorkAreaAttachments(Control top) { FormData childData = new FormData(); childData.top = new FormAttachment(top); childData.right = new FormAttachment(100, 0); childData.left = new FormAttachment(0, 0); childData.bottom = new FormAttachment(100, 0); workArea.setLayoutData(childData); } private void setWarningMessage(String newMessage) { // Any change? if (warningMessage == null ? newMessage == null : warningMessage .equals(newMessage)) { return; } warningMessage = newMessage; //Clear or set warning message. if (warningMessage == null) { if(messageArea != null && !showingError) setMessageAreaVisible(false); if (showingWarning) showingWarning = false; } else { if (!showingWarning) showingWarning = true; warningMessage = newMessage; if(messageArea == null){ // create a message area to display the error messageArea = new ImageAndMessageArea(titleArea, SWT.WRAP); messageArea.setBackground(messageLabel.getBackground()); animator = Policy.getAnimatorFactory().createAnimator(messageArea); } // show the error messageArea.setToolTipText(warningMessage); messageArea.setText(warningMessage); messageArea.setImage(JFaceResources.getImage(DLG_IMG_MESSAGE_WARNING)); setMessageAreaVisible(true); } int verticalSpacing = convertVerticalDLUsToPixels(IDialogConstants.VERTICAL_SPACING); int horizontalSpacing = convertHorizontalDLUsToPixels(IDialogConstants.HORIZONTAL_SPACING); setLayoutsForNormalMessage(verticalSpacing, horizontalSpacing); } }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -