]>
git.argeo.org Git - gpl/argeo-slc.git/blob - rcp/org.argeo.eclipse.ui.rcp/src/org/argeo/swt/desktop/MiniDesktopLayer.java
f53e6a3c7e61a88f3a7e10f067a3ea6a296a8dbd
1 package org
.argeo
.swt
.desktop
;
3 import java
.io
.IOException
;
4 import java
.nio
.file
.DirectoryStream
;
5 import java
.nio
.file
.Files
;
6 import java
.nio
.file
.Path
;
8 import org
.eclipse
.swt
.SWT
;
9 import org
.eclipse
.swt
.events
.SelectionAdapter
;
10 import org
.eclipse
.swt
.events
.SelectionEvent
;
11 import org
.eclipse
.swt
.graphics
.Image
;
12 import org
.eclipse
.swt
.graphics
.ImageData
;
13 import org
.eclipse
.swt
.layout
.GridData
;
14 import org
.eclipse
.swt
.layout
.GridLayout
;
15 import org
.eclipse
.swt
.layout
.RowData
;
16 import org
.eclipse
.swt
.layout
.RowLayout
;
17 import org
.eclipse
.swt
.program
.Program
;
18 import org
.eclipse
.swt
.widgets
.Button
;
19 import org
.eclipse
.swt
.widgets
.Composite
;
20 import org
.eclipse
.swt
.widgets
.Display
;
21 import org
.eclipse
.swt
.widgets
.Label
;
23 /** Implementation of an active desktop with icons. */
24 public class MiniDesktopLayer
{
25 public void init(Composite parent
, Path context
) {
26 parent
.setLayout(new RowLayout());
28 DirectoryStream
<Path
> ds
= Files
.newDirectoryStream(context
);
29 ds
.forEach((path
) -> createIcon(parent
, path
));
30 } catch (IOException e
) {
35 protected void createIcon(Composite parent
, Path path
) {
36 String fileName
= path
.getFileName().toString();
37 String ext
= fileName
.substring(fileName
.lastIndexOf('.') + 1);
38 Program program
= Program
.findProgram(ext
);
39 if (program
== null) {
40 createDefaultIcon(parent
, path
);
44 Display display
= parent
.getDisplay();
45 ImageData iconData
= program
.getImageData();
48 if (iconData
== null) {
51 iconImage
= new Image(display
, iconData
);
54 Composite icon
= new Composite(parent
, SWT
.BORDER
);
55 icon
.setLayoutData(new RowData(48, 72));
56 icon
.setLayout(new GridLayout());
58 Button iconB
= new Button(icon
, SWT
.FLAT
);
59 iconB
.setImage(iconImage
);
60 // iconB.setLayoutData(new GridData(iconData.width, iconData.height));
61 iconB
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false));
62 iconB
.addSelectionListener(new SelectionAdapter() {
65 public void widgetSelected(SelectionEvent e
) {
66 program
.execute(path
.toString());
71 Label iconL
= new Label(icon
, SWT
.WRAP
);
72 iconL
.setText(path
.getFileName().toString());
73 iconL
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, false, false));
76 protected void createDefaultIcon(Composite parent
, Path path
) {
77 Composite icon
= new Composite(parent
, SWT
.NONE
);
78 icon
.setLayout(new GridLayout());
79 Label iconL
= new Label(icon
, SWT
.NONE
);
80 iconL
.setText(path
.getFileName().toString());
81 iconL
.setLayoutData(new GridData(SWT
.CENTER
, SWT
.CENTER
, true, true));