use of com.biglybt.core.devices.DeviceTemplate in project BiglyBT by BiglySoftware.
the class DeviceDriveManager method addDevice.
protected DeviceMediaRendererManual addDevice(String target_name, String target_classification, File root, File target_directory, boolean generic) {
DeviceMediaRenderer existingDevice = getDeviceMediaRendererByClassification(target_classification);
if (existingDevice instanceof DeviceMediaRendererManual) {
mapDevice((DeviceMediaRendererManual) existingDevice, root, target_directory);
existingDevice.setGenericUSB(generic);
return (DeviceMediaRendererManual) existingDevice;
}
DeviceTemplate[] templates = manager.getDeviceTemplates(Device.DT_MEDIA_RENDERER);
DeviceMediaRendererManual renderer = null;
for (DeviceTemplate template : templates) {
if (template.getClassification().equalsIgnoreCase(target_classification)) {
try {
renderer = (DeviceMediaRendererManual) template.createInstance(target_name);
break;
} catch (Throwable e) {
log("Failed to add device", e);
}
}
}
if (renderer == null) {
try {
renderer = (DeviceMediaRendererManual) manager.createDevice(Device.DT_MEDIA_RENDERER, null, target_classification, target_name, true);
} catch (Throwable e) {
log("Failed to add device", e);
}
}
if (renderer != null) {
try {
renderer.setAutoCopyToFolder(true);
// This will cause a change event
renderer.setGenericUSB(generic);
mapDevice(renderer, root, target_directory);
return renderer;
} catch (Throwable e) {
log("Failed to add device", e);
}
}
return renderer;
}
use of com.biglybt.core.devices.DeviceTemplate in project BiglyBT by BiglySoftware.
the class DeviceTemplateChooser method createDeviceTemplateList2.
private void createDeviceTemplateList2(SWTSkinObjectContainer soList) {
DeviceTemplate[] devices = mf.getDeviceTemplates();
if (devices.length == 0) {
noDevices();
return;
}
Arrays.sort(devices, new Comparator<DeviceTemplate>() {
@Override
public int compare(DeviceTemplate o1, DeviceTemplate o2) {
return o1.getName().compareToIgnoreCase(o2.getName());
}
});
Composite parent = soList.getComposite();
if (parent.getChildren().length > 0) {
Utils.disposeComposite(parent, false);
}
SWTSkin skin = skinnedDialog.getSkin();
RowLayout layout = new RowLayout(SWT.HORIZONTAL);
layout.spacing = 0;
layout.marginLeft = layout.marginRight = 0;
layout.wrap = true;
layout.justify = true;
layout.fill = true;
parent.setLayout(layout);
Listener clickListener = new Listener() {
boolean down = false;
@Override
public void handleEvent(Event event) {
if (event.type == SWT.MouseDown) {
down = true;
} else if (event.type == SWT.MouseUp && down) {
Widget widget = (event.widget instanceof Label) ? ((Label) event.widget).getParent() : event.widget;
selectedDeviceTemplate = (DeviceTemplate) widget.getData("obj");
if (selectedDeviceTemplate == null) {
Debug.out("selectedDeviceTemplate is null!");
}
skinnedDialog.close();
down = false;
}
}
};
for (DeviceTemplate deviceTemplate : devices) {
if (deviceTemplate.isAuto()) {
continue;
}
// deviceTemplate.getIconURL();
String iconURL = null;
TranscodeChooser.addImageBox(parent, clickListener, null, deviceTemplate, iconURL, deviceTemplate.getName());
}
SWTSkinObjectText soTitle = (SWTSkinObjectText) skin.getSkinObject("title");
if (soTitle != null) {
soTitle.setTextID("devices.choose.device.title");
}
SWTSkinObjectText soSubTitle = (SWTSkinObjectText) skin.getSkinObject("subtitle");
if (soSubTitle != null) {
soSubTitle.setTextID("label.clickone");
}
Shell shell = skinnedDialog.getShell();
Point computeSize = shell.computeSize(shell.getSize().x, SWT.DEFAULT, true);
shell.setSize(computeSize);
UIFunctionsSWT uiFunctionsSWT = UIFunctionsManagerSWT.getUIFunctionsSWT();
if (uiFunctionsSWT != null) {
Shell mainShell = uiFunctionsSWT.getMainShell();
Utils.centerWindowRelativeTo(shell, mainShell);
}
}
Aggregations