/** * Adds the component of a specific <tt>PluginComponent</tt> to the associated <tt>Container</tt>. * * @param c the <tt>PluginComponent</tt> which is to have its component added to the * <tt>Container</tt> associated with this <tt>PluginContainer</tt> */ private synchronized void addPluginComponent(PluginComponent c) { /* * Try to respect positionIndex of PluginComponent to some extent: * PluginComponents with positionIndex equal to 0 go at the beginning, * these with positionIndex equal to -1 follow them and then go these * with positionIndex greater than 0. */ int cIndex = c.getPositionIndex(); int index = -1; int i = 0; for (PluginComponent pluginComponent : pluginComponents) { if (pluginComponent.equals(c)) return; if (-1 == index) { int pluginComponentIndex = pluginComponent.getPositionIndex(); if ((0 == cIndex) || (-1 == cIndex)) { if ((0 != pluginComponentIndex) && (cIndex != pluginComponentIndex)) index = i; } else if (cIndex < pluginComponentIndex) index = i; } i++; } int pluginComponentCount = pluginComponents.size(); if (-1 == index) index = pluginComponents.size(); /* * The container may have added Components of its own apart from the * ones this PluginContainer has added to it. Since the common case for * the additional Components is to have them appear at the beginning, * adjust the index so it gets correct in the common case. */ int containerComponentCount = getComponentCount(container); addComponentToContainer( (Component) c.getComponent(), container, (containerComponentCount > pluginComponentCount) ? (index + (containerComponentCount - pluginComponentCount)) : index); pluginComponents.add(index, c); container.revalidate(); container.repaint(); }
/** * Creates preview for the device(video) in the video container. * * @param device the device * @param videoContainer the container * @throws IOException a problem accessing the device. * @throws MediaException a problem getting preview. */ private static void createPreview(MediaDevice device, final JComponent videoContainer) throws IOException, MediaException { videoContainer.removeAll(); videoContainer.revalidate(); videoContainer.repaint(); if (device == null) return; Component c = (Component) GuiActivator.getMediaService() .getVideoPreviewComponent( device, videoContainer.getSize().width, videoContainer.getSize().height); videoContainer.add(c); }
/** * Creates preview for the (video) device in the video container. * * @param device the device * @param videoContainer the video container * @throws IOException a problem accessing the device * @throws MediaException a problem getting preview */ private static void createVideoPreview(CaptureDeviceInfo device, JComponent videoContainer) throws IOException, MediaException { videoContainer.removeAll(); videoContainer.revalidate(); videoContainer.repaint(); if (device == null) return; for (MediaDevice mediaDevice : mediaService.getDevices(MediaType.VIDEO, MediaUseCase.ANY)) { if (((MediaDeviceImpl) mediaDevice).getCaptureDeviceInfo().equals(device)) { Dimension videoContainerSize = videoContainer.getPreferredSize(); Component preview = (Component) mediaService.getVideoPreviewComponent( mediaDevice, videoContainerSize.width, videoContainerSize.height); if (preview != null) videoContainer.add(preview); break; } } }