/** * Returns the warning icon for warnings, the error icon for errors, * the info icon for infos and {@code null} otherwise. * * @param severity the severity used to lookup the icon * @return the warning icon for warnings, error icon for errors, * the info icon for infos, {@code null} otherwise * @see #getWarningIcon() * @see #getErrorIcon() * @see #getInfoIcon() * @see #getSmallIcon(Severity) */ public static Icon getIcon(Severity severity) { switch (severity) { case ERROR: return getErrorIcon(); case WARNING: return getWarningIcon(); case INFO: return getInfoIcon(); case OK: return null; default: return null; } }
private void createComponents() { textLabel = new JLabel(); libelleField = new JTextField(); validationResultModel = new DefaultValidationResultModel(); keyTypedResultView = ValidationResultViewFactory.createReportIconAndTextLabel(validationResultModel); }
/** * Creates and returns a list that presents validation messages. * The list content is bound to the given {@link ValidationResultModel} * using a {@link ValidationResultListAdapter}. * * @param model the model that provides the observable validation result * @return a {@code JList} that shows validation messages */ public static JComponent createReportList(ValidationResultModel model) { return createReportList(model, DEFAULT_REPORT_BACKGROUND); }
/** * Returns the small warning icon for warnings, the small error icon for * errors and {@code null} otherwise. * * @param severity the severity used to lookup the icon * @return the small warning icon for warnings, the small error icon for * errors, {@code null} otherwise * @see #getSmallWarningIcon() * @see #getSmallErrorIcon() * @see #getIcon(Severity) */ public static Icon getSmallIcon(Severity severity) { if (severity == Severity.ERROR) { return getSmallErrorIcon(); } else if (severity == Severity.WARNING) { return getSmallWarningIcon(); } else { return null; } }
/** * Returns the warning icon for warnings, the error icon for errors * and {@code null} otherwise. * * @param severity the severity used to lookup the icon * @return the warning icon for warnings, error icon for errors, * {@code null} otherwise * @see #getWarningIcon() * @see #getErrorIcon() * @see #getSmallIcon(Severity) */ public static Icon getIcon(Severity severity) { if (severity == Severity.ERROR) { return getErrorIcon(); } else if (severity == Severity.WARNING) { return getWarningIcon(); } else { return null; } }
/** * Returns the small warning icon for warnings, the small error icon for * errors, the small info icon for infos and {@code null} otherwise. * * @param severity the severity used to lookup the icon * @return the small warning icon for warnings, the small error icon for * errors, the small info icon for infos, {@code null} otherwise * @see #getSmallWarningIcon() * @see #getSmallErrorIcon() * @see #getSmallInfoIcon() * @see #getIcon(Severity) */ public static Icon getSmallIcon(Severity severity) { switch (severity) { case ERROR: return getSmallErrorIcon(); case WARNING: return getSmallWarningIcon(); case INFO: return getSmallInfoIcon(); case OK: return null; default: return null; } }
JLabel label = createReportIconLabel(model); JTextArea area = createReportTextArea(model); area.setOpaque(false);
private JPanel buildInfoAreaPane() { JLabel infoLabel = new JLabel(ValidationResultViewFactory.getInfoIcon()); infoArea = new JTextArea(1, 38); infoArea.setEditable(false); infoArea.setOpaque(false); FormLayout layout = new FormLayout("pref, 2dlu, default", "pref"); //$NON-NLS-1$ //$NON-NLS-2$ PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(infoLabel, cc.xy(1, 1)); builder.add(infoArea, cc.xy(3, 1)); infoAreaPane = builder.getPanel(); infoAreaPane.setVisible(false); return infoAreaPane; }
/** * Creates and returns a text area that is intended to show validation * messages. The area is bound to the given {@link ValidationResultModel}: the text content reflects * the validation result message text and the component is visible * if and only if the model has messages. * * @param model the model that provides the observable validation result * @return a text area intended to show validation messages */ public static JTextArea createReportTextArea(ValidationResultModel model) { return createReportTextArea(model, DEFAULT_REPORT_BACKGROUND); }
private static void updateVisibilityAndIcon(JLabel aLabel, Severity severity) { aLabel.setVisible(severity != Severity.OK); Icon icon = getIcon(severity); if (icon != null) { aLabel.setIcon(icon); } }
/** * Creates and returns a text area wrapped by a scroll pane that is * intended to show validation messages. The component is bound to * the given {@link ValidationResultModel}: the text content reflects * the validation result message text and the component is visible * if and only if the model has messages. * * @param model the model that provides the observable validation result * @return a scrollable text component intended to show validation messages */ public static JComponent createReportTextPane(ValidationResultModel model) { return createReportTextPane(model, DEFAULT_REPORT_BACKGROUND); }
/** * Creates and returns a label with icon and text that indicates * the validation state and displays the first message text * with the highest severity. * * @param model the model that provides the observable validation result * @return a label with text and icon that shows the validation severity * and the first validation message text */ public static JLabel createReportIconAndTextLabel(ValidationResultModel model) { JLabel label = createReportIconLabel(model); LabelTextChangeHandler.updateText(label, model.getResult()); model.addPropertyChangeListener( ValidationResultModel.PROPERTY_RESULT, new LabelTextChangeHandler(label)); return label; }
private static void updateVisibilityAndIcon(JLabel aLabel, Severity severity) { aLabel.setVisible(severity != Severity.OK); if (severity == Severity.ERROR) { aLabel.setIcon(getErrorIcon()); } else if (severity == Severity.WARNING) { aLabel.setIcon(getWarningIcon()); } }
JLabel label = createReportIconLabel(model); JTextArea area = createReportTextArea(model); area.setOpaque(false);
private JPanel buildInfoAreaPane() { JLabel infoLabel = new JLabel(ValidationResultViewFactory.getInfoIcon()); infoArea = new JTextArea(1, 38); infoArea.setEditable(false); infoArea.setOpaque(false); FormLayout layout = new FormLayout("pref, 2dlu, default", "pref"); //$NON-NLS-1$ //$NON-NLS-2$ PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.add(infoLabel, cc.xy(1, 1)); builder.add(infoArea, cc.xy(3, 1)); infoAreaPane = builder.getPanel(); infoAreaPane.setVisible(false); return infoAreaPane; }
/** * Creates and returns a text area that is intended to show validation * messages. The area is bound to the given {@link ValidationResultModel}: the text content reflects * the validation result message text and the component is visible * if and only if the model has messages. * * @param model the model that provides the observable validation result * @return a text area intended to show validation messages */ public static JTextArea createReportTextArea(ValidationResultModel model) { return createReportTextArea(model, DEFAULT_REPORT_BACKGROUND); }
/** * In addition to the superclass behavior, this method * assumes that the value is a ValidationMessage. * It sets the renderer's icon to the one associated with the * ValidationMessage's severity and sets the renderer's text * to the message's formatted text. */ @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { super.getListCellRendererComponent( list, value, index, false, // Ignore the selection state false); // Ignore the cell focus state ValidationMessage message = (ValidationMessage) value; this.setIcon(ValidationResultViewFactory.getIcon(message.severity())); this.setText(message.formattedText()); return this; } }
/** * Creates and returns a text area wrapped by a scroll pane that is * intended to show validation messages. The component is bound to * the given {@link ValidationResultModel}: the text content reflects * the validation result message text and the component is visible * if and only if the model has messages. * * @param model the model that provides the observable validation result * @return a scrollable text component intended to show validation messages */ public static JComponent createReportTextPane(ValidationResultModel model) { return createReportTextPane(model, DEFAULT_REPORT_BACKGROUND); }
/** * Creates and returns a label with icon and text that indicates * the validation state and displays the first message text. * * @param model the model that provides the observable validation result * @return a label with text and icon that shows the validation severity * and the first validation message text */ public static JLabel createReportIconAndTextLabel(ValidationResultModel model) { JLabel label = createReportIconLabel(model); LabelTextChangeHandler.updateText(label, model.getResult()); model.addPropertyChangeListener( ValidationResultModel.PROPERTYNAME_RESULT, new LabelTextChangeHandler(label)); return label; }
private void createComponents() { validationResultModel = new DefaultValidationResultModel(); keyTypedResultView = ValidationResultViewFactory .createReportIconAndTextLabel(validationResultModel); }