UIUtils { public static String getUniqueFrameTitle(final JInternalFrame[] frames, final String titleBase) { if (frames.length == 0) { return titleBase; } String[] titles = new String[frames.length]; for (int i = 0; i < frames.length; i++) { JInternalFrame frame = frames[i]; titles[i] = frame.getTitle(); } if (!ArrayUtils.isMemberOf(titleBase, titles)) { return titleBase; } for (int i = 0; i < frames.length; i++) { final String title = titleBase + " (" + (i + 2) + ")"; if (!ArrayUtils.isMemberOf(title, titles)) { return title; } } return titleBase + " (" + (frames.length + 1) + ")"; } private  UIUtils(); static ImageIcon loadImageIcon(String resourcePath); static ImageIcon loadImageIcon(String resourcePath, Class callerClass); static URL getImageURL(String resourcePath); static URL getImageURL(String resourcePath, Class callerClass); static Dimension getScreenSize(); static int getScreenWidth(); static int getScreenHeight(); static void centerComponent(Component comp); static void centerComponent(Component comp, Component alignComp); static void showPopup(JPopupMenu popup, MouseEvent event); static Window getRootWindow(Component component); static Border createGroupBorder(String title); static Frame getRootFrame(Component component); static JFrame getRootJFrame(Component component); static Cursor setRootFrameWaitCursor(Component component); static Cursor setRootFrameDefaultCursor(Component component); static Cursor setRootFrameCursor(Component component, Cursor newCursor); static JMenu findMenu(JMenuBar menuBar, String name, boolean deepSearch); static int findMenuItemPosition(JPopupMenu popupMenu, String name); static JMenu findSubMenu(JPopupMenu popupMenu, String name); static String getUniqueFrameTitle(final JInternalFrame[] frames, final String titleBase); static JSpinner createSpinner(final Parameter param, final Number spinnerStep, final String formatPattern); static JSpinner createDoubleSpinner(final double value, final double rangeMinimum,
                                               final double rangeMaximum,
                                               final double stepSize, final double bigStepSize,
                                               final String formatPattern); static JSpinner createSpinner(final Number value, final Comparable rangeMinimum, final Comparable rangeMaximum,
                                         final Number stepSize, final Number bigStepSize, final String formatPattern); static final String PROPERTY_SOURCE_PRODUCT; static final String IMAGE_RESOURCE_PATH; static final Color COLOR_DARK_RED; static final Color COLOR_DARK_BLUE; static final Color COLOR_DARK_GREEN; }
@Test public void testGetUniqueFrameTitle() { String title; title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image1"), new JInternalFrame("Image2"), new JInternalFrame("Image3"), }, "Image"); assertEquals("Image", title); title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image"), new JInternalFrame("Data"), new JInternalFrame("Raw"), }, "Image"); assertEquals("Image (2)", title); title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image (3)"), new JInternalFrame("Data"), new JInternalFrame("Raw"), }, "Image"); assertEquals("Image", title); title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image"), new JInternalFrame("Image (2)"), new JInternalFrame("Image (3)"), }, "Image"); assertEquals("Image (4)", title); title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image"), new JInternalFrame("Image (2)"), new JInternalFrame("Image (4)"), }, "Image"); assertEquals("Image (3)", title); title = UIUtils.getUniqueFrameTitle( new JInternalFrame[]{ new JInternalFrame("Image"), new JInternalFrame("Image (1)"), new JInternalFrame("Image (2)"), new JInternalFrame("Image (3)"), }, "Image"); assertEquals("Image (4)", title); }