if ("ancestor" == e.getPropertyName()) { JOptionPane op = (JOptionPane)e.getSource(); boolean isComingUp; // if the old value is null, then the JOptionPane is being // created since it didn't previously have an ancestor. if (e.getOldValue() == null) { isComingUp = true; } else { isComingUp = false; } // figure out what to do based on the message type switch (op.getMessageType()) { case JOptionPane.PLAIN_MESSAGE: if (isComingUp) { BasicLookAndFeel.playSound(optionPane, "OptionPane.informationSound"); } break; // all other message types handled as well }
@Override protected boolean matchesSafely(JOptionPane item) { return item.getMessageType() == messageTypeCode; }
@RunsInEDT static int messageTypeOf(final @Nonnull JOptionPane optionPane) { Integer result = execute(() -> optionPane.getMessageType()); return checkNotNull(result); }
/** * Displays an option pane as a sheet on its parent window. * * @param pane The option pane. * @param parentComponent The parent of the option pane. * @param listener The listener for SheetEvents. */ public static void showSheet(JOptionPane pane, Component parentComponent, SheetListener listener) { final JSheet sheet = createSheet(pane, parentComponent, styleFromMessageType(pane.getMessageType())); sheet.addSheetListener(listener); sheet.show(); }
/** * Returns the {@code String} representation of the given {@code Component}, which should be a {@code JOptionPane}. * * @param c the given {@code Component}. * @return the {@code String} representation of the given {@code JOptionPane}. */ @RunsInCurrentThread @Override @Nonnull protected String doFormat(@Nonnull Component c) { JOptionPane optionPane = (JOptionPane) c; String format = "%s[message=%s, messageType=%s, optionType=%s, enabled=%b, visible=%b, showing=%b]"; return String.format(format, getRealClassName(c), quote(optionPane.getMessage()), MESSAGE_TYPES.get(optionPane.getMessageType()), OPTION_TYPES.get(optionPane.getOptionType()), optionPane.isEnabled(), optionPane.isVisible(), optionPane.isShowing()); }
@Override protected void addIcon(Container top) { Icon sideIcon = (optionPane == null ? null : optionPane.getIcon()); if (sideIcon == null && optionPane != null) sideIcon = super.getIconForType(optionPane.getMessageType()); if (sideIcon != null) { if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) { sideIcon = SubstanceCoreUtilities.getThemedIcon(null, sideIcon); } this.substanceIconLabel = new OptionPaneLabel(); this.iconGlowTracker = new IconGlowTracker(substanceIconLabel); this.substanceIconLabel.setIcon(new GlowingIcon(sideIcon, this.iconGlowTracker)); this.substanceIconLabel.setName("OptionPane.iconLabel"); this.substanceIconLabel.setVerticalAlignment(SwingConstants.TOP); top.add(this.substanceIconLabel, BorderLayout.BEFORE_LINE_BEGINS); } }
@Override protected void addIcon(Container top) { Icon sideIcon = (optionPane == null ? null : optionPane.getIcon()); if (sideIcon == null && optionPane != null) sideIcon = super.getIconForType(optionPane.getMessageType()); if (sideIcon != null) { if (!SubstanceLookAndFeel.isToUseConstantThemesOnDialogs()) { sideIcon = SubstanceCoreUtilities.getThemedIcon(null, sideIcon); } this.substanceIconLabel = new OptionPaneLabel(); this.iconGlowTracker = new IconGlowTracker(substanceIconLabel); this.substanceIconLabel.setIcon(new GlowingIcon(sideIcon, this.iconGlowTracker)); this.substanceIconLabel.setName("OptionPane.iconLabel"); this.substanceIconLabel.setVerticalAlignment(SwingConstants.TOP); top.add(this.substanceIconLabel, BorderLayout.BEFORE_LINE_BEGINS); } }