@Override public synchronized void addItem(final StringMenuItem<T> menuItem) { if (menuItem == null) { log.fatal("Item may not be null"); throw new IllegalArgumentException("Item may not be null"); } if (!EventQueue.isDispatchThread()) { log.fatal("Must be called on the EventQueue dispatch thread"); throw new IllegalStateException( "Must be called on the EventQueue dispatch thread"); } if (!itemStringToJMenuItem.containsKey(menuItem)) { log.trace("Adding item to menu"); addItemInternal(menuItem); } }
/** * @see nu.zoom.swing.desktop.component.stringmenu.StringMenu#addItem(java.lang.String) */ public synchronized void addItem(final StringMenuItem<T> menuItem) { if (menuItem == null) { log.fatal("Item may not be null"); throw new IllegalArgumentException("Item may not be null"); } if (!EventQueue.isDispatchThread()) { log.fatal("Must be called on the EventQueue dispatch thread"); throw new IllegalStateException( "Must be called on the EventQueue dispatch thread"); } if (!itemStringToJMenuItem.containsKey(menuItem)) { log.trace("Adding item to menu"); addItemInternal(menuItem); } }
@SuppressWarnings("unchecked") private synchronized void restoreMenu() { try { log.trace("Trying to deserialize key list from preferences"); byte[] data = preferences.getBytes(preferencesKey); if (data != null) { ObjectInputStream ins = new ObjectInputStream( new ByteArrayInputStream(data)); // Generates unchecked warnings but we know ArrayList<StringMenuItem<T>> restoredKeys = (ArrayList<StringMenuItem<T>>) ins .readObject(); for (final StringMenuItem<T> item : restoredKeys) { addItemInternal(item); } } } catch (InvalidDataTypeException e) { log.warn(e); } catch (BackendException e) { log.warn(e); } catch (IOException e) { log.warn(e); } catch (ClassNotFoundException e) { log.warn(e); } }
@SuppressWarnings("unchecked") private synchronized void restoreMenu() { try { log.trace("Trying to deserialize key list from preferences"); byte[] data = preferences.getBytes(preferencesKey); if (data != null) { ObjectInputStream ins = new ObjectInputStream( new ByteArrayInputStream(data)); // Generates unchecked warnings but we know ArrayList<StringMenuItem<T>> restoredKeys = (ArrayList<StringMenuItem<T>>) ins .readObject(); createJMenu(); for (final StringMenuItem<T> item : restoredKeys) { addItemInternal(item); } } } catch (InvalidDataTypeException e) { log.warn(e); } catch (BackendException e) { log.warn(e); } catch (IOException e) { log.warn(e); } catch (ClassNotFoundException e) { log.warn(e); } }