1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168
|
public String iconsPath = "C:/Documents and Settings/darty/Bureau/Icons2"; //path to folder containing icons
public String iconFolder1 = iconsPath+"/Action";
public String iconFolder2 = iconsPath+"/Annotation";
public String iconFolder3 = iconsPath+"/Moyen Fixe";
public String iconFolder4 = iconsPath+"/Moyen Mobile";
public Composite c1, c2, c3, c4, cconf;
public CTabFolder tabfolder;
public Action actionOpenFolder, actionOpenConfig;
public Composite createTable(CTabFolder folder, UIIconGroup oIconGroup) {
ScrolledComposite scroller = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.H_SCROLL);
final Composite composite = new Composite(scroller, SWT.NONE);
composite.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
Vector vtItems = oIconGroup.getItems();
int count = vtItems.size();
GridLayout gridLayout = new GridLayout();
gridLayout.numColumns = count;
gridLayout.makeColumnsEqualWidth = false;
gridLayout.verticalSpacing = 0;
composite.setLayout(gridLayout);
for (int i=0; i<count; i++) {
final UIIconItem oItem = (UIIconItem)vtItems.elementAt(i);
final Label label1 = new Label(composite, SWT.LEFT);
label1.setImage(oItem.getImage());
label1.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
label1.setToolTipText(oItem.getName());
final DragSource dragSource = new DragSource(label1, DND.DROP_COPY);
Transfer[] formats = new Transfer[] { TextTransfer.getInstance()};
dragSource.setTransfer(formats);
dragSource.addDragListener(new DragSourceListener() {
public void dragStart(DragSourceEvent event) {
event.doit = true;
}
public void dragSetData(DragSourceEvent event) {
if (TextTransfer.getInstance().isSupportedType(event.dataType)) {
String sData = oItem.getImageString();
sData = "Citise"+sData;
event.data = sData;
}
}
public void dragFinished(DragSourceEvent event) {}
});
label1.addDisposeListener(new DisposeListener() {
public void widgetDisposed(DisposeEvent e) {
dragSource.dispose();
}
});
}
scroller.setContent(composite);
scroller.setExpandHorizontal(true);
scroller.setExpandVertical(true);
scroller.setMinSize(composite.computeSize(SWT.DEFAULT, SWT.DEFAULT));
return scroller;
}
public UIIconGroup createIconGroup(String iconFolder) {
UIIconGroup ig = new UIIconGroup();
Vector<UIIconItem> iconList=new Vector<UIIconItem>();
File folder = new File(iconFolder);
String[] children = folder.list();
if (children != null) {
for (int i=0; i<children.length; i++) {
if (!children[i].equals("Thumbs.db")) {
String filename = iconFolder+"/"+children[i];
UIIconItem item= new UIIconItem();
Image icon= new Image(Display.getCurrent(),filename);
item.setImageString(filename);
item.setName(children[i]);
item.setImage(icon);
iconList.addElement(item);
}
}
}
ig.setItems(iconList);
String[] path = iconFolder.split("/");
ig.setFolderName(path[path.length-1]);
return ig;
}
public Composite createConfig(CTabFolder folder) {
ScrolledComposite scrollerConf = new ScrolledComposite(folder, SWT.V_SCROLL | SWT.H_SCROLL);
final Composite compositeConf = new Composite(scrollerConf, SWT.NONE);
compositeConf.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_WHITE));
GridLayout gridLayoutConf = new GridLayout();
gridLayoutConf.numColumns = 3;
gridLayoutConf.makeColumnsEqualWidth = false;
gridLayoutConf.verticalSpacing = 0;
compositeConf.setLayout(gridLayoutConf);
Label labelConfig = new Label(compositeConf, SWT.LEFT);
labelConfig.setText("Configuration");
labelConfig.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
scrollerConf.setContent(compositeConf);
return compositeConf;
}
@Override
public void createPartControl(Composite parent) {
//ACTIONS
makeActions();
contributeToActionBars();
//NOUVEAU TABLEAU D'ONGLETS
tabfolder = new CTabFolder(parent, SWT.BORDER);
// Set up a gradient background for the selected tab
Display display = parent.getDisplay();
tabfolder.setSelectionBackground(new Color[] {
display.getSystemColor(SWT.COLOR_RED),
display.getSystemColor(SWT.COLOR_YELLOW),
display.getSystemColor(SWT.COLOR_DARK_BLUE)}, new int[] { 50,
100});
File f = new File(iconsPath);
if (f.exists() && f.isDirectory()) {
UIIconGroup myIconGroup1 = createIconGroup(iconFolder1);
UIIconGroup myIconGroup2 = createIconGroup(iconFolder2);
UIIconGroup myIconGroup3 = createIconGroup(iconFolder3);
UIIconGroup myIconGroup4 = createIconGroup(iconFolder4);
//ONGLET 1
CTabItem onglet1 = new CTabItem(tabfolder, SWT.NONE);
//onglet1.setText(myIconGroup1.getFolderName());
onglet1.setText(" "+myIconGroup1.getFolderName()+" ");
c1=createTable(tabfolder, myIconGroup1);
onglet1.setControl( c1 );
//ONGLET 2
CTabItem onglet2 = new CTabItem(tabfolder, SWT.NONE);
onglet2.setText(" "+myIconGroup2.getFolderName()+" ");
c2=createTable(tabfolder, myIconGroup2);
onglet2.setControl( c2 );
//ONGLET 3
CTabItem onglet3 = new CTabItem(tabfolder, SWT.NONE);
onglet3.setText(" "+myIconGroup3.getFolderName()+" ");
c3 = createTable(tabfolder, myIconGroup3);
onglet3.setControl( c3 );
//ONGLET 4
CTabItem onglet4 = new CTabItem(tabfolder, SWT.NONE);
onglet4.setText(" "+myIconGroup4.getFolderName()+" ");
c4 = createTable(tabfolder, myIconGroup4);
onglet4.setControl( c4 );
} else {
CTabItem ongletConfig = new CTabItem(tabfolder, SWT.NONE);
ongletConfig.setText("Configuration");
cconf = createConfig(tabfolder);
ongletConfig.setControl(cconf);
}
} |
Partager