List of usage examples for org.eclipse.jface.resource JFaceResources getDefaultFont
public static Font getDefaultFont()
From source file:com.ibm.xsp.extlib.designer.bluemix.manifest.editor.AbstractManifestEditorPage.java
License:Open Source License
public AbstractManifestEditorPage(Composite parent, FormToolkit toolkit, ManifestMultiPageEditor mpe) { super(parent, SWT.NONE); _mpe = mpe;/* www . ja va2 s.c om*/ _toolkit = toolkit; _errorImage = getDisplay().getSystemImage(SWT.ICON_ERROR); _errorFont = JFaceResources.getDefaultFont(); _titleFont = JFaceResources.getHeaderFont(); initialize(); }
From source file:com.joeysoft.kc868.ui.BorderStyler.java
License:Open Source License
/** * shell// w ww . ja v a2 s. com * * @param shell * @return * */ public Composite decorateShell(Shell s) { shell = s; shell.setData(STYLER, this); // layout GridLayout layout = new GridLayout(3, false); layout.marginHeight = layout.marginWidth = layout.verticalSpacing = layout.horizontalSpacing = 0; shell.setLayout(layout); Composite leftTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) leftTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE)); GridData gd = new GridData(); gd.widthHint = gd.heightHint = 5; leftTop.setLayoutData(gd); leftTop.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, i, bound.width, i); e.gc.drawLine(i, i, i, bound.height); i++; } } }); if (resizable) { leftTop.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = downX - loc.x; int dy = downY - loc.y; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.y -= dy; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } top = new Label(shell, SWT.LEFT); if (resizable) top.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 5; top.setLayoutData(gd); top.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(0, i, bound.width, i); i++; } } }); if (resizable) { top.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downY = control.toDisplay(e.x, e.y).y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newY = control.toDisplay(e.x, e.y).y; int dy = downY - newY; if (dy == 0) return; Rectangle bound = shell.getBounds(); bound.y -= dy; bound.height += dy; setShellBound(bound); } }); } Composite rightTop = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) rightTop.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; rightTop.setLayoutData(gd); rightTop.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(bound.width - i - 1, i, 0, i); e.gc.drawLine(bound.width - i - 1, i, bound.width - i - 1, bound.height); i++; } } }); if (resizable) { rightTop.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = loc.x - downX; int dy = downY - loc.y; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.y -= dy; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } left = new Label(shell, SWT.LEFT); gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 5; gd.verticalSpan = 2; left.setLayoutData(gd); if (resizable) left.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE)); left.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, 0, i, bound.height); i++; } } }); if (resizable) { left.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downX = control.toDisplay(e.x, e.y).x; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newX = control.toDisplay(e.x, e.y).x; int dx = downX - newX; if (dx == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.width += dx; setShellBound(bound); } }); } topDown = new Composite(shell, SWT.LEFT); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 23; topDown.setLayoutData(gd); topDown.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); e.gc.setForeground(Colors.MAINSHELL_TITLE_TOP); e.gc.setBackground(Colors.MAINSHELL_TITLE_BOTTOM); e.gc.fillGradientRectangle(0, 0, bound.width, bound.height, true); e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_TOP); e.gc.drawLine(2, 19, bound.width - 2, 19); e.gc.setForeground(Colors.MAINSHELL_TITLE_SEPARATOR_BOTTOM); e.gc.drawLine(2, 20, bound.width - 2, 20); Image image = shell.getImage(); Rectangle imgBound = (image == null) ? new Rectangle(0, 0, 16, 16) : image.getBounds(); if (image != null) { e.gc.drawImage(image, 2, (18 - imgBound.height) >> 1); } String text = shell.getText(); if (text != null) { String name = JFaceResources.getDefaultFont().getFontData()[0].getName(); e.gc.setForeground(Colors.WHITE); e.gc.setFont(JFaceResources.getFontRegistry().getBold(name)); Point extent = e.gc.textExtent(text); e.gc.drawString(text, imgBound.width + 7, (18 - extent.y) >> 1, true); } } }); topDown.setLayout(new FormLayout()); topDown.addMouseListener(new MouseListener() { public void mouseDown(MouseEvent e) { downX = e.x; downY = e.y; isMove = true; fireMouseDownEvent(e); } public void mouseUp(MouseEvent e) { isMove = false; fireMouseUpEvent(e); } public void mouseDoubleClick(MouseEvent e) { if (maximizeWhenDoubleClick && showMaxButton) doMaximize(); } }); topDown.addMouseMoveListener(new MouseMoveListener() { public void mouseMove(MouseEvent e) { if (isMove) { Point loc = shell.getLocation(); int x = loc.x + e.x - downX; int y = loc.y + e.y - downY; shell.setLocation(x, y); } } }); Label referenceLabel = null; // if (showButton) { Label lblClose = new Label(topDown, SWT.CENTER); lblClose.setImage(icons.getImage(IconHolder.bmpCloseNormal)); FormData fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(100, -2); fd.left = new FormAttachment(100, -19); lblClose.setLayoutData(fd); lblClose.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpCloseHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpCloseNormal)); } }); lblClose.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpCloseDown)); } @Override public void mouseUp(MouseEvent e) { if (checkMinimizeWhenClose && main != null) { shell.close(); } else shell.close(); } }); referenceLabel = lblClose; } // if (showMaxButton) { lblMax = new Label(topDown, SWT.CENTER); lblMax.setImage(icons.getImage(IconHolder.bmpMaxNormal)); FormData fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT); fd.left = new FormAttachment(referenceLabel, -17, SWT.LEFT); lblMax.setLayoutData(fd); lblMax.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? icons.getImage(IconHolder.bmpRestoreHover) : icons.getImage(IconHolder.bmpMaxHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? icons.getImage(IconHolder.bmpRestoreNormal) : icons.getImage(IconHolder.bmpMaxNormal)); } }); lblMax.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(shell.getMaximized() ? icons.getImage(IconHolder.bmpRestoreDown) : icons.getImage(IconHolder.bmpMaxDown)); } @Override public void mouseUp(MouseEvent e) { doMaximize(); } }); referenceLabel = lblMax; } if (showButton) { // ? Label lblMin = new Label(topDown, SWT.CENTER); lblMin.setImage(icons.getImage(IconHolder.bmpMinNormal)); FormData fd = new FormData(); fd.top = new FormAttachment(0, 0); fd.bottom = new FormAttachment(0, 16); fd.right = new FormAttachment(referenceLabel, 0, SWT.LEFT); fd.left = new FormAttachment(referenceLabel, -16, SWT.LEFT); lblMin.setLayoutData(fd); lblMin.addMouseTrackListener(new MouseTrackAdapter() { @Override public void mouseEnter(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpMinHover)); } @Override public void mouseExit(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpMinNormal)); } }); lblMin.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpMinDown)); } @Override public void mouseUp(MouseEvent e) { Label lbl = (Label) e.getSource(); lbl.setImage(icons.getImage(IconHolder.bmpMinHover)); shell.setMinimized(true); if (hideWhenMinimize) shell.setVisible(false); } }); } right = new Label(shell, SWT.LEFT); gd = new GridData(GridData.FILL_VERTICAL); gd.widthHint = 5; gd.verticalSpan = 2; right.setLayoutData(gd); if (resizable) right.setCursor(display.getSystemCursor(SWT.CURSOR_SIZEWE)); right.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 4; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, 0, i, bound.height); i--; } } }); if (resizable) { right.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downX = control.toDisplay(e.x, e.y).x; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newX = control.toDisplay(e.x, e.y).x; int dx = newX - downX; if (dx == 0) return; Point size = shell.getSize(); size.x += dx; setShellSize(size); } }); } center = new Composite(shell, SWT.NONE); center.setLayoutData(new GridData(GridData.FILL_BOTH)); //layout = new GridLayout(); //layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = layout.verticalSpacing = 0; //center.setLayout(layout); Composite leftBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) leftBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENESW)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; leftBottom.setLayoutData(gd); leftBottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(i, bound.height - i - 1, i, 0); e.gc.drawLine(i, bound.height - i - 1, bound.width, bound.height - i - 1); i++; } } }); if (resizable) { leftBottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = downX - loc.x; int dy = loc.y - downY; if (dx == 0 && dy == 0) return; Rectangle bound = shell.getBounds(); bound.x -= dx; bound.width += dx; bound.height += dy; setShellBound(bound); } }); } bottom = new Label(shell, SWT.LEFT); if (resizable) bottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENS)); gd = new GridData(GridData.FILL_HORIZONTAL); gd.heightHint = 5; bottom.setLayoutData(gd); bottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(0, 5 - i - 1, bound.width, 5 - i - 1); i++; } } }); if (resizable) { bottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); downY = control.toDisplay(e.x, e.y).y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); int newY = control.toDisplay(e.x, e.y).y; int dy = newY - downY; if (dy == 0) return; Point size = shell.getSize(); size.y += dy; setShellSize(size); } }); } Composite rightBottom = new Composite(shell, SWT.NONE | SWT.NO_BACKGROUND); if (resizable) rightBottom.setCursor(display.getSystemCursor(SWT.CURSOR_SIZENWSE)); gd = new GridData(); gd.widthHint = gd.heightHint = 5; rightBottom.setLayoutData(gd); rightBottom.addPaintListener(new PaintListener() { public void paintControl(PaintEvent e) { Rectangle bound = ((Control) e.getSource()).getBounds(); int i = 0; for (Color c : Colors.MAINSHELL_BORDERS) { e.gc.setForeground(c); e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, bound.width - i - 1, 0); e.gc.drawLine(bound.width - i - 1, bound.height - i - 1, 0, bound.height - i - 1); i++; } } }); if (resizable) { rightBottom.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); downX = loc.x; downY = loc.y; } @Override public void mouseUp(MouseEvent e) { Control control = (Control) e.getSource(); Point loc = control.toDisplay(e.x, e.y); int dx = loc.x - downX; int dy = loc.y - downY; if (dx == 0 && dy == 0) return; Point size = shell.getSize(); size.x += dx; size.y += dy; setShellSize(size); } }); } return center; }
From source file:com.mobilesorcery.sdk.ui.UIUtils.java
License:Open Source License
/** * <p>Creates a new {@link Font} based on a prototype font.</p> * <p>Clients must dispose of the new font.</p> * @param original/* w w w . j a va 2 s. c om*/ * @param style The style(ie <code>SWT.BOLD</code>) to apply to * the new font, or <code>SWT.DEFAULT</code> if the current style should be kept * @param relativeHeight * @return */ public static Font modifyFont(Font original, int style, int relativeHeight) { if (original == null) { original = JFaceResources.getDefaultFont(); } FontData[] fd = original.getFontData(); fd = modifyFont(fd, style, relativeHeight); return new Font(original.getDevice(), fd); }
From source file:com.mobilesorcery.sdk.ui.UIUtils.java
License:Open Source License
/** * <p>Modifies an array of {@link FontData} based on a new style and relative height.</p> * @param original/* ww w . j a va2 s.co m*/ * @param style The style(ie <code>SWT.BOLD</code>) to apply to * the new font, or <code>SWT.DEFAULT</code> if the current style should be kept * @param relativeHeight * @return The modified array, always the same as the input value unless the input value is <code>null</code> * in which case a new array is created. */ public static FontData[] modifyFont(FontData[] fd, int style, int relativeHeight) { if (fd == null) { fd = JFaceResources.getDefaultFont().getFontData(); } for (int i = 0; i < fd.length; i++) { if (style != SWT.DEFAULT) { fd[i].setStyle(style); } fd[i].setHeight(fd[i].getHeight() + relativeHeight); } return fd; }
From source file:com.nokia.tools.s60.ide.actions.ThemeModelDropDownAction.java
License:Open Source License
public ImageDescriptor getCustomImageDescriptor(String id, String text) { FontData fd = JFaceResources.getDefaultFont().getFontData()[0]; Font bigFont = new Font(Display.getDefault(), fd.getName(), 9, SWT.BOLD); Font smallFont = new Font(Display.getDefault(), fd.getName(), 5, SWT.NORMAL); Font normalFont = new Font(Display.getDefault(), fd.getName(), 7, SWT.NORMAL); ImageDescriptor desc = S60WorkspacePlugin.getImageDescriptor("icons/platform/platform_base.png"); Image bannerImage = null;/*from w w w . j a v a 2s . c o m*/ GC imageGC = null; int logoSpace; Color color1 = new Color(Display.getDefault(), 128, 132, 135); Color color2 = new Color(Display.getDefault(), 183, 83, 176); Color color3 = new Color(Display.getDefault(), 143, 0, 96); try { bannerImage = desc.createImage(); int imageWidth = bannerImage.getBounds().width; imageGC = new GC(bannerImage); if (id.contains("60")) { logoSpace = FigureUtilities.getTextWidth("S60", bigFont) + 2; imageGC.setForeground(color1); imageGC.setFont(bigFont); imageGC.drawString("S60", 1, 1, true); } else { logoSpace = 0; } imageGC.setForeground(ColorConstants.black); imageGC.setFont(normalFont); text = filtrateText(text); int freeSpace = imageWidth - logoSpace - 2; int textWidth = FigureUtilities.getTextWidth(text, normalFont); if (textWidth > freeSpace) { text = ScreenUtil.toShorterWithDots(text, freeSpace, normalFont); textWidth = FigureUtilities.getTextWidth(text, normalFont); } int x = (int) (((freeSpace) - textWidth) / 2) + logoSpace; imageGC.drawString(text, x, 3, true); ImageData data = bannerImage.getImageData(); data.transparentPixel = new java.awt.Color(192, 192, 192).getRGB(); return ImageDescriptor.createFromImageData(data); } finally { if (imageGC != null) { imageGC.dispose(); } if (bannerImage != null) { bannerImage.dispose(); } if (bigFont != null) { bigFont.dispose(); } if (normalFont != null) { normalFont.dispose(); } if (smallFont != null) { smallFont.dispose(); } if (color1 != null) { color1.dispose(); } if (color2 != null) { color2.dispose(); } if (color3 != null) { color3.dispose(); } } }
From source file:com.nokia.tools.s60.views.ResourceViewPage.java
License:Open Source License
public void createCompositeArea(Composite parent) { inputs = createInput2(null);/*from w w w. j a v a 2 s. c o m*/ table = new Table(parent, SWT.FULL_SELECTION | SWT.HIDE_SELECTION | SWT.H_SCROLL); GridData gd = new GridData(GridData.FILL_BOTH); table.setLayoutData(gd); table.setBackground(ColorConstants.menuBackground); // table.setBackground(ColorConstants.orange); table.setLinesVisible(false); table.setHeaderVisible(false); addDragDropSupport(table); // 1st column final TableColumn column0 = new TableColumn(table, SWT.CENTER, 0); column0.setWidth(COLUMN0_WIDTH); // 2nd column final TableColumn column = new TableColumn(table, SWT.CENTER, 1); column.setWidth(COLUMN1_WIDTH); // 3rd column final TableColumn column2 = new TableColumn(table, SWT.CENTER, 2); column2.setWidth(COLUMN2_WIDTH); // 4th column final TableColumn column3 = new TableColumn(table, SWT.CENTER, 3); fillTable(); Listener paintListener = new Listener() { Boolean itemIsSelected; public void handleEvent(Event event) { GC gc = event.gc; TableItem item = (TableItem) event.item; Color foreground = gc.getForeground(); Color background = gc.getBackground(); gc.setForeground(FG_TEXT_COLOR); itemIsSelected = false; // gc.setBackground(BG_COLOR); switch (event.type) { case SWT.MeasureItem: { if (item.getData() instanceof ResourceTableMasterGroup) { event.height = ROW_HEIGHT; } if (event.index == 3) { int clientWidth = table.getClientArea().width; event.width = 2 * clientWidth; column3.setWidth(table.getBounds().width - event.x); } if (table.getItemCount() > 0 && table.getItem(table.getItemCount() - 1) != item) { // strange logic here, if breaks on the last item, the // last line is not drawn break; } } case SWT.PaintItem: { if (item.getData() instanceof ResourceTableInput) { gc.setBackground(item.getBackground()); } if (item.getData() instanceof ResourceColorBoxesLine) { gc.setBackground(item.getBackground()); drawColorBoxesLine(gc, event, (ResourceColorBoxesLine) item.getData()); return; } if (event.index == 0) { // gc.setBackground(item.getBackground()); if (item.getData() == selectedCategory && (item.getData() instanceof ColorResourceTableCategory || (item.getData() instanceof ResourceTableCategory))) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else if (item.getData() == selectedItem || item.getData() == selectedGroup) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else { gc.setBackground(item.getBackground()); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } drawCheckIcon(gc, event, item.getData()); } if (event.index == 2) { gc.setBackground(item.getBackground()); if (item.getData() == selectedCategory && (item.getData() instanceof ColorResourceTableCategory || (item.getData() instanceof ResourceTableCategory))) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else if (item.getData() == selectedItem || item.getData() == selectedGroup) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else { gc.setBackground(item.getBackground()); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } if (item.getData() instanceof ColorTableItem) { drawColorItemBox(gc, event, (ColorTableItem) item.getData()); } } if (event.index == 3) { gc.setBackground(item.getBackground()); if (item.getData() == selectedCategory && (item.getData() instanceof ColorResourceTableCategory || (item.getData() instanceof ResourceTableCategory))) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else if (item.getData() == selectedItem || item.getData() == selectedGroup) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else { gc.setBackground(item.getBackground()); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } drawPin(gc, event, item.getData()); } if (event.index == 1) { // if(table.getSelection()!=null&&table.getSelection().length>0&& // table.getSelection()[0]==item){ // return; // } if (item.getData() == selectedCategory && (item.getData() instanceof ColorResourceTableCategory || (item.getData() instanceof ResourceTableCategory))) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else if (item.getData() == selectedItem || item.getData() == selectedGroup) { itemIsSelected = true; gc.setBackground(BG_SELECTED_COLOR); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } else { gc.setBackground(item.getBackground()); gc.fillRectangle(event.x, event.y, table.getBounds().width, event.height); } drawMainText(gc, event, item.getData()); drawIconToResourceTableCategory(gc, event, item.getData()); } gc.setForeground(FG_LINE_COLOR); gc.drawLine(event.x, event.y, event.x + table.getBounds().width, event.y); gc.drawLine(event.x, event.y + event.height, event.x + table.getBounds().width, event.y + event.height); } } gc.setForeground(background); gc.setBackground(foreground); } /** * * * @param gc * @param event * @param objData */ private void drawIconToResourceTableCategory(GC gc, Event event, Object objData) { if (objData instanceof ResourceTableCategory) { ResourceTableCategory cat = (ResourceTableCategory) objData; int offset = COLUMN0_WIDTH; offset += TOP_TREE_ELEMENT_SHIFT; if (cat.isVisible()) { if (cat.getImageData() != null) { ImageData imageData = cat.getImageData(); int y = event.y + (event.height - imageData.height) / 2; Image img = new Image(null, imageData); gc.drawImage(img, event.x + offset - COLUMN0_WIDTH, y); img.dispose(); } } } } private void drawMainText(GC gc, Event event, Object objData) { int offset = COLUMN0_WIDTH; String text = ""; Font oldFont = gc.getFont(); Font tempFont = null; ImageData data = null; if (objData instanceof ResourceTableCategory) { ResourceTableCategory cat = (ResourceTableCategory) objData; text = cat.getName(); offset += TREE_SUBELEMENT_SHIFT + TOP_TREE_ELEMENT_SHIFT; if (cat.isVisible()) { if (cat.getItems() != null && cat.getItems().size() > 0) { if (((ResourceTableCategory) objData).isExtracted()) { data = getTreeExpandedDescriptor().getImageData(); } else { data = getTreeCollapsedDescriptor().getImageData(); } } } else { return; } } if (objData instanceof ResourceTableMasterGroup) { text = ((ResourceTableMasterGroup) objData).getMasterGroupName(); offset += TOP_TREE_ELEMENT_SHIFT; if (((ResourceTableMasterGroup) objData).isExtracted()) { data = getTreeExpandedDescriptor().getImageData(); } else { data = getTreeCollapsedDescriptor().getImageData(); } FontData fd = JFaceResources.getDefaultFont().getFontData()[0]; tempFont = new Font(Display.getDefault(), fd.getName(), fd.getHeight(), SWT.BOLD); gc.setFont(tempFont); } if (objData instanceof ResourceTableItem) { ResourceTableItem item = (ResourceTableItem) objData; if (item.isVisible()) { text = ((ResourceTableItem) objData).getName(); offset += TOP_TREE_ELEMENT_SHIFT + 2 * TREE_SUBELEMENT_SHIFT; int positionInParentCategory = item.getParent().getItems().indexOf(item); if (positionInParentCategory != item.getParent().getItems().size() - 1) { gc.setLineDash(new int[] { 1, 1 }); gc.drawLine(event.x + offset + 3 - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y, event.x + 3 + offset - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y + event.height); gc.drawLine(event.x + offset + 3 - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y + event.height / 2, event.x + offset - 3, event.y + event.height / 2); gc.setLineStyle(SWT.LINE_SOLID); } else { gc.setLineDash(new int[] { 1, 1 }); gc.drawLine(event.x + offset + 3 - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y, event.x + 3 + offset - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y + event.height / 2); gc.drawLine(event.x + offset + 3 - 2 * TREE_SUBELEMENT_SHIFT + 8, event.y + event.height / 2, event.x + offset - 3, event.y + event.height / 2); gc.setLineStyle(SWT.LINE_SOLID); } } else { return; } } if (objData instanceof ColorResourceTableCategory) { ColorResourceTableCategory colorCat = (ColorResourceTableCategory) objData; int positionInParentCategory = colorCat.getParent().getCategories().indexOf(colorCat); if (positionInParentCategory != colorCat.getParent().getCategories().size() - 1) { gc.setLineDash(new int[] { 1, 1 }); gc.drawLine(event.x + offset - COLUMN0_WIDTH, event.y, event.x + offset - COLUMN0_WIDTH, event.y + event.height); gc.drawLine(event.x + offset - COLUMN0_WIDTH, event.y + event.height / 2, event.x + offset - 3, event.y + event.height / 2); gc.setLineStyle(SWT.LINE_SOLID); } else { gc.setLineDash(new int[] { 1, 1 }); gc.drawLine(event.x + offset - COLUMN0_WIDTH, event.y, event.x + offset - COLUMN0_WIDTH, event.y + event.height / 2); gc.drawLine(event.x + offset - COLUMN0_WIDTH, event.y + event.height / 2, event.x + offset - 3, event.y + event.height / 2); gc.setLineStyle(SWT.LINE_SOLID); } } gc.setForeground(ColorConstants.gray); gc.drawLine(event.x, event.y, event.x + column.getWidth(), event.y); gc.drawLine(event.x, event.y + event.height, event.x + column.getWidth(), event.y + event.height); gc.setForeground(itemIsSelected ? FG_SELECTED_TEXT_COLOR : FG_TEXT_COLOR); if (data != null) { int y = event.y + (event.height - data.height) / 2; Image img = new Image(null, data); gc.drawImage(img, event.x + offset - COLUMN0_WIDTH, y); img.dispose(); } final Point extent = event.gc.stringExtent(text); int y = event.y + (event.height - extent.y) / 2; gc.drawText(text, event.x + offset, y, true); gc.setFont(oldFont); if (tempFont != null && !tempFont.isDisposed()) { tempFont.dispose(); } } private void drawPin(GC gc, Event event, Object data) { ImageData imgData = null; if (data instanceof ResourceTableCategory) { if (((ResourceTableCategory) data == selectedCategory)) { imgData = getPinIconDescriptor().getImageData(); } } if (imgData != null) { // gc.setBackground(bgSelectedColor); gc.fillRectangle(event.x, event.y, COLUMN3_WIDTH, event.height); // pin removed // int y = event.y + (event.height - imgData.height) / 2; // Image img = new Image(null, imgData); // gc.drawImage(img, event.x, y); // img.dispose(); } gc.setForeground(FG_LINE_COLOR); gc.drawLine(event.x, event.y, event.x + event.width, event.y); gc.drawLine(event.x, event.y + event.height, event.x + event.width, event.y + event.height); } // drawing method private void drawColorItemBox(GC gc, Event event, ColorTableItem item) { int y = event.y + (event.height - COLOR_BOX_SIZE_OUTER) / 2; Color backgroundColor = gc.getBackground(); RGB rgb = item.getRGB(); if (rgb != null && item.isLinked()) { gc.setAntialias(SWT.ON); Color color = new Color(null, rgb); gc.setBackground(FG_TEXT_COLOR); gc.fillOval(event.x + 1, y, COLOR_BOX_SIZE_OUTER, COLOR_BOX_SIZE_OUTER); gc.setBackground(ColorConstants.white); gc.fillOval(event.x + 2, y + 1, COLOR_BOX_SIZE_MIDDLE, COLOR_BOX_SIZE_MIDDLE); gc.setBackground(color); gc.fillOval(event.x + 3, y + 2, COLOR_BOX_SIZE_INNER, COLOR_BOX_SIZE_INNER); color.dispose(); } else if (rgb != null && !item.isLinked()) { Color color = new Color(null, rgb); gc.setBackground(FG_TEXT_COLOR); gc.fillRoundRectangle(event.x + 1, y, COLOR_BOX_SIZE_OUTER, COLOR_BOX_SIZE_OUTER, COLOR_BOX_ROUND_ANGLE, COLOR_BOX_ROUND_ANGLE); gc.setBackground(ColorConstants.white); gc.fillRectangle(event.x + 2, y + 1, COLOR_BOX_SIZE_MIDDLE, COLOR_BOX_SIZE_MIDDLE); gc.setBackground(color); gc.fillRectangle(event.x + 3, y + 2, COLOR_BOX_SIZE_INNER, COLOR_BOX_SIZE_INNER); color.dispose(); } else { gc.setBackground(ColorConstants.lightGray); gc.fillRoundRectangle(event.x + 1, y, COLOR_BOX_SIZE_OUTER, COLOR_BOX_SIZE_OUTER, COLOR_BOX_ROUND_ANGLE, COLOR_BOX_ROUND_ANGLE); gc.setBackground(ColorConstants.lightGray); gc.fillRectangle(event.x + 2, y + 1, COLOR_BOX_SIZE_MIDDLE, COLOR_BOX_SIZE_MIDDLE); gc.setBackground(ColorConstants.lightGray); gc.fillRectangle(event.x + 3, y + 2, COLOR_BOX_SIZE_INNER, COLOR_BOX_SIZE_INNER); } gc.setBackground(backgroundColor); } // drawing method private void drawCheckIcon(GC gc, Event event, Object item) { ImageData data = null; if (item instanceof ResourceTableCategory) { if (((ResourceTableCategory) item).isVisible()) { if (((ResourceTableCategory) item).isSkinned()) { data = getCheckDescriptor().getImageData(); } else if (((ResourceTableCategory) item).isHalfSkinned()) { data = getHalfCheckDescriptor().getImageData(); } else { // data = getNotCheckDescriptor().getImageData(); } } else { return; } } if (item instanceof ResourceTableMasterGroup) { if (((ResourceTableMasterGroup) item).isSkinned()) { data = getCheckDescriptor().getImageData(); } else if (((ResourceTableMasterGroup) item).isHalfSkinned()) { data = getHalfCheckDescriptor().getImageData(); } else { if (((ResourceTableMasterGroup) item).getAssociatedContentData() != null) { if (((ResourceTableMasterGroup) item).getAssociatedContentData().getImageDescriptor(16, 16) != null) { data = ((ResourceTableMasterGroup) item).getAssociatedContentData() .getImageDescriptor(16, 16).getImageData(); } } else { // data = getNotCheckDescriptor().getImageData(); } } } if (item instanceof ResourceTableItem) { if (((ResourceTableItem) item).isVisible()) { if (((ResourceTableItem) item).isSkinned()) { data = getCheckDescriptor().getImageData(); } else if (((ResourceTableItem) item).isHalfSkinned()) { data = getHalfCheckDescriptor().getImageData(); } else { // data = getNotCheckDescriptor().getImageData(); } } else { return; } } gc.fillRectangle(0, event.y, column0.getWidth(), event.height); if (data != null) { int y = event.y + (event.height - data.height) / 2; Image img = new Image(null, data); if (item instanceof ResourceTableMasterGroup) gc.drawImage(img, event.x, y); else gc.drawImage(img, event.x + 3, y); img.dispose(); } gc.setForeground(FG_LINE_COLOR); gc.drawLine(event.x - 4, event.y, column0.getWidth(), event.y); gc.drawLine(event.x - 4, event.y + event.height, column0.getWidth(), event.y + event.height); } // drawing method private void drawColorBoxesLine(GC gc, Event event, ResourceColorBoxesLine line) { String string = line.getName(); final Point extent = event.gc.stringExtent(string); int column1Offset = 0; if (event.index == 2) { // this helps to simulate column span column1Offset = COLUMN1_WIDTH; } int y = event.y + (event.height - extent.y) / 2; if ((event.index == 1) || event.index == 2) { int offset = TREE_SUBELEMENT_SHIFT + TOP_TREE_ELEMENT_SHIFT - column1Offset; int i = 0; List<RGB> rgbList = line.getRGBList(); for (RGB rgb : rgbList) { // for linked colors draw oval if (line.getLinkedRGBList() != null && line.getLinkedRGBList().contains(rgb)) { gc.setAntialias(SWT.ON); Color color = new Color(null, rgb); gc.setBackground(FG_TEXT_COLOR); gc.fillOval(event.x + 1 + i * COLOR_CELL_OFFSET + offset, y + 1, COLOR_BOX_SIZE_OUTER, COLOR_BOX_SIZE_OUTER); gc.setBackground(ColorConstants.white); gc.fillOval(event.x + 2 + i * COLOR_CELL_OFFSET + offset, y + 2, COLOR_BOX_SIZE_MIDDLE, COLOR_BOX_SIZE_MIDDLE); gc.setBackground(color); gc.fillOval(event.x + 3 + i * COLOR_CELL_OFFSET + offset, y + 3, COLOR_BOX_SIZE_INNER, COLOR_BOX_SIZE_INNER); color.dispose(); } else { // for not linked colors draw rounded // rectangles Color color = new Color(null, rgb); gc.setBackground(FG_TEXT_COLOR); gc.fillRoundRectangle(event.x + 1 + i * COLOR_CELL_OFFSET + offset, y + 1, COLOR_BOX_SIZE_OUTER, COLOR_BOX_SIZE_OUTER, COLOR_BOX_ROUND_ANGLE, COLOR_BOX_ROUND_ANGLE); gc.setBackground(ColorConstants.white); gc.fillRectangle(event.x + 2 + i * COLOR_CELL_OFFSET + offset, y + 2, COLOR_BOX_SIZE_MIDDLE, COLOR_BOX_SIZE_MIDDLE); gc.setBackground(color); gc.fillRectangle(event.x + 3 + i * COLOR_CELL_OFFSET + offset, y + 3, COLOR_BOX_SIZE_INNER, COLOR_BOX_SIZE_INNER); color.dispose(); } i++; } gc.setBackground(table.getBackground()); } } }; table.addMouseListener(new MouseAdapter() { @Override public void mouseDown(MouseEvent event) { Table table = (Table) event.widget; TableItem item = table.getItem(new Point(event.x, event.y)); if (item == null) { clearSelection(); // select root if (table.getItem(0).getData() instanceof ResourceTableMasterGroup) { ResourceTableMasterGroup rtmg = (ResourceTableMasterGroup) table.getItem(0).getData(); if (rtmg != null && rtmg.getAssociatedContentData() != null && rtmg.getAssociatedContentData().getParent() != null) { setSelectionWithoutUpdatingListeners( new StructuredSelection(rtmg.getAssociatedContentData().getParent())); } } return; } if (event.button == SWT.MouseDown) { // right click serves // for context menu if (item.getData() instanceof ResourceTableCategory) { ResourceTableCategory cat = (ResourceTableCategory) item.getData(); // only set selection for the context menu setSelectionWithoutUpdatingListeners( new StructuredSelection(cat.getAssociatedContentData())); return; } else if (item.getData() instanceof ResourceTableItem) { ResourceTableItem selectedItem = (ResourceTableItem) item.getData(); // only set selection for the context menu setSelectionWithoutUpdatingListeners( new StructuredSelection(selectedItem.getAssociatedContentData())); return; } else if (item.getData() instanceof ResourceTableMasterGroup) { ResourceTableMasterGroup mg = (ResourceTableMasterGroup) item.getData(); setSelectionWithoutUpdatingListeners( new StructuredSelection(mg.getAssociatedContentData())); return; } else { setSelection(null); return; } } if (!item.isDisposed() && item.getData() instanceof ResourceTableCategory) { if (event.x > COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + 15 && event.x < (COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + 30)) { // category is selected, call execute category selection ResourceTableCategory cat = (ResourceTableCategory) item.getData(); if (!(cat instanceof ColorResourceTableCategory)) { if (cat.isExtracted()) { cat.setExtracted(false); } else { if (selectedCategory != null) selectedCategory.setExtracted(false); cat.setExtracted(true); clearSelection(); selectedCategory = cat; } } else { clearSelection(); selectedCategory = cat; } refreshKeepingIndex(); } else if (event.x > COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + 30 && event.x < (COLUMN0_WIDTH + COLUMN1_WIDTH)) { ResourceTableCategory cat = (ResourceTableCategory) item.getData(); if (!(cat instanceof ColorResourceTableCategory)) { if (cat.getAssociatedContentData() != null) { clearSelection(); selectedCategory = cat; if (cat.getAssociatedContentData().getAllChildren().length > 0) { if (cat.getAssociatedContentData().getChildren()[0] != null) { StructuredSelection selection = new StructuredSelection( cat.getAssociatedContentData().getChildren()[0]); setSelection(selection); IResourceViewerSelectionHelper2 helper = getResourceSelectionHelper( cat.getAssociatedContentData().getChildren()[0]); helper.executeSelect(sourceEditor, cat, SELECT_ITEM, null); } } else { StructuredSelection selection = new StructuredSelection( cat.getAssociatedContentData()); setSelection(selection); } } else setSelection(null); refreshKeepingIndex(); } else { clearSelection(); StructuredSelection selection = new StructuredSelection( cat.getAssociatedContentData().getChildren()[0]); clearSelection(); selectedCategory = cat; setSelection(selection); refreshKeepingIndex(); } } } else if (!item.isDisposed() && item.getData() instanceof ResourceTableItem) { if (event.x > COLUMN0_WIDTH && event.x < (COLUMN0_WIDTH + COLUMN1_WIDTH)) { // item is selected, call execute item selection ResourceTableItem resItem = (ResourceTableItem) item.getData(); // IResourceViewerSelectionHelper2 helper = // getResourceSelectionHelper(resItem // .getAssociatedContentData()); clearSelection(); selectedItem = resItem; // helper // .executeSelect(sourceEditor, resItem, // SELECT_ITEM); if (resItem.getAssociatedContentData().getAllChildren().length > 0) { StructuredSelection selection = new StructuredSelection( resItem.getAssociatedContentData().getChildren()[0]); setSelection(selection); } else setSelection(null); refreshKeepingIndex(); } } else if (!item.isDisposed() && item.getData() instanceof ResourceTableMasterGroup) { if (event.x > COLUMN0_WIDTH && event.x < (COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + 15)) { // group is expanded/collapsed, // tree to show/hide child elements ResourceTableMasterGroup grp = (ResourceTableMasterGroup) item.getData(); if (grp.isExtracted()) { grp.setExtracted(false); } else { grp.setExtracted(true); // collapse other expanded group for (ResourceTableMasterGroup group : inputs.get(0).getGroups()) { if (group != grp) { group.setExtracted(false); } } } // IResourceViewerSelectionHelper2 helper = // getResourceSelectionHelper(grp // .getAssociatedContentData()); // helper.executeSelect(sourceEditor, grp, // SELECT_ITEM); // if(grp.getAssociatedContentData()!=null&&grp.getAssociatedContentData().getChildren()[0]!=null){ // StructuredSelection selection= new // StructuredSelection(grp.getAssociatedContentData().getChildren()[0]); // setSelection(selection); // } // refreshKeepingIndex(); } else if (event.x > (COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + 15) && event.x < (COLUMN0_WIDTH + COLUMN1_WIDTH)) { // group is expanded/collapsed, // tree to show/hide child elements ResourceTableMasterGroup grp = (ResourceTableMasterGroup) item.getData(); if (grp.getAssociatedContentData() != null) { StructuredSelection selection = null; clearSelection(); selectedGroup = grp; if (grp.getAssociatedContentData().getAllChildren().length > 0) { if (grp.getAssociatedContentData().getChildren()[0] != null) { selection = new StructuredSelection( grp.getAssociatedContentData().getChildren()[0]); } } else { selection = new StructuredSelection(grp.getAssociatedContentData()); } setSelection(selection); } else setSelection(null); refreshKeepingIndex(); } } else if (!item.isDisposed() && item.getData() instanceof ResourceColorBoxesLine) { // item with color boxes int positionOffset = COLUMN0_WIDTH + TOP_TREE_ELEMENT_SHIFT + TREE_SUBELEMENT_SHIFT; int offset = (event.x - positionOffset) % COLOR_CELL_OFFSET; int position = (event.x - positionOffset) / COLOR_CELL_OFFSET; ResourceColorBoxesLine sep = (ResourceColorBoxesLine) item.getData(); if (position >= 0 && position < sep.getRGBList().size() && offset < COLOR_BOX_SIZE_OUTER - 1 && offset >= 0) { sep.setSelectedRGB(sep.getRGBList().get(position)); IResourceViewerSelectionHelper2 helper = getResourceSelectionHelper( sep.getParent().getAssociatedContentData()); CssColorDialog dialog = new CssColorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); dialog.setRGBString(ColorUtil.asHashString(sep.getSelectedRGB())); if (dialog.open() == CssColorDialog.CANCEL) { return; } RGB newRGB = dialog.getRGB(); helper.executeSelect(sourceEditor, sep, CHANGE_COLOR, newRGB); sep.setSelectedRGB(null); table.redraw(); } } if (!item.isDisposed() && item.getData() instanceof ColorTableItem) { if (event.x > (COLUMN0_WIDTH + COLUMN1_WIDTH) && event.x < (COLUMN0_WIDTH + COLUMN1_WIDTH + COLUMN3_WIDTH)) { // color box next to category was selected ColorTableItem colorItem = (ColorTableItem) item.getData(); if (colorItem instanceof ColorResourceTableCategory) { ColorResourceTableCategory colorCat = (ColorResourceTableCategory) colorItem; IContentData data = colorCat.getAssociatedContentData(); if (colorCat != null && colorCat.getRGB() != null) { String hashColor = ColorUtil.asHashString(colorCat.getRGB()); CssColorDialog dialog = new CssColorDialog( PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell()); dialog.setRGBString(hashColor); if (dialog.open() == CssColorDialog.CANCEL) { return; } RGB newRGB = dialog.getRGB(); IResourceViewerSelectionHelper2 helper = getResourceSelectionHelper(data); helper.executeSelect(sourceEditor, colorCat, CHANGE_COLOR, newRGB); } } table.redraw(); } } } }); table.addListener(SWT.MeasureItem, paintListener); table.addListener(SWT.PaintItem, paintListener); table.addControlListener(new ControlListener() { /* * (non-Javadoc) * * @see org.eclipse.swt.events.ControlListener#controlMoved(org.eclipse.swt.events.ControlEvent) */ public void controlMoved(ControlEvent e) { update3rdColumn(e); } /* * (non-Javadoc) * * @see org.eclipse.swt.events.ControlListener#controlResized(org.eclipse.swt.events.ControlEvent) */ public void controlResized(ControlEvent e) { update3rdColumn(e); } private void update3rdColumn(ControlEvent e) { if (e.widget == table && table.getItemCount() > 0) { TableItem the3rdOne = table.getItem(0); if (the3rdOne != null) { Rectangle rect = the3rdOne.getBounds(3); if (null != rect) column3.setWidth(table.getBounds().width - rect.x); } } } }); /* add copy element(s) action */ MenuManager mmgr = new MenuManager(); mmgr.setRemoveAllWhenShown(true); for (IResourceSection2 section : resourceSections) { IMenuListener listener = section.createResourceViewerMenuListener(this, getCommandStack()); if (listener != null) { mmgr.addMenuListener(listener); } } Menu menu = mmgr.createContextMenu(table); table.setMenu(menu); table.setToolTipText(""); // Fix for a dummy tool tip coming in the resource view and occupying the space over the editor as well. }
From source file:com.nokia.tools.s60ct.resources.Activator.java
License:Open Source License
public static Font getItalicFont() { if (italicFont == null) { Font defaultFont = JFaceResources.getDefaultFont(); FontData italicData = defaultFont.getFontData()[0]; italicData.setStyle(SWT.ITALIC); italicFont = new Font(Display.getDefault(), italicData); }//from w w w.jav a2 s . c o m // // // // italicFont = new Font(Display.getDefault(), "Arial", 8, SWT.ITALIC); // } return italicFont; }
From source file:com.nokia.tools.screen.ui.views.ResourceViewer.java
License:Open Source License
/** * Initializes the resouce viewer with a particular theme. * /*from w w w .j ava 2 s. c o m*/ */ public ResourceViewer(IContentAdapter adapter, final ResourcePage page) { this.setEditPartFactory(new PaletteEditPartFactory() { /* * (non-Javadoc) * * @see org.eclipse.gef.ui.palette.PaletteEditPartFactory#createEditPart(org.eclipse.gef.EditPart, * java.lang.Object) */ @Override public EditPart createEditPart(EditPart parentEditPart, Object model) { if (model instanceof PaletteText) { return new TextEditPart(((PaletteText) model)); } final EditPart part = super.createEditPart(parentEditPart, model); return part; } }); resourceSections = createResourceSections(); reset(adapter); /* add copy element(s) action */ MenuManager mmgr = new MenuManager(); mmgr.setRemoveAllWhenShown(true); for (IResourceSection section : resourceSections) { IMenuListener listener = section.createResourceViewerMenuListener(this, page.getCommandStack()); if (listener != null) { mmgr.addMenuListener(listener); } } setContextMenu(mmgr); FontData fd = JFaceResources.getDefaultFont().getFontData()[0]; boldFont = new Font(Display.getDefault(), fd.getName(), fd.getHeight(), SWT.BOLD); plainFont = new Font(Display.getDefault(), fd.getName(), fd.getHeight(), SWT.NORMAL); addResourceToDispose(boldFont); addResourceToDispose(plainFont); }
From source file:com.nokia.tools.theme.s60.ui.dialogs.MakeKeysDialog.java
License:Open Source License
protected Control createDialogArea(Composite parent) { PlatformUI.getWorkbench().getHelpSystem().setHelp(parent.getParent(), MakeKeysDialog.MAKE_KEYS_DIALOG_CONTEXT); Composite area = (Composite) super.createDialogArea(parent); Composite container = new Composite(area, SWT.NONE); container.setLayoutData(new GridData(GridData.FILL_BOTH)); setTitle(WizardMessages.Make_Keys_Banner_Title); setMessage(WizardMessages.Make_Keys_Banner_Message); GridLayout layout = new GridLayout(); container.setLayout(layout);/* ww w . j a v a2s .c om*/ layout.marginHeight = 13; layout.marginWidth = 13; layout.verticalSpacing = 7; FontData fd = JFaceResources.getDefaultFont().getFontData()[0]; infoFont = new Font(Display.getDefault(), fd.getName(), 7, SWT.ITALIC); Composite topContainer = new Composite(container, SWT.NULL); layout = new GridLayout(); topContainer.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); topContainer.setLayoutData(gd); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 7; layout.horizontalSpacing = 10; Group grpInformation = new Group(topContainer, SWT.NONE); grpInformation.setText(WizardMessages.Make_Keys_Group_Information_Title); gd = new GridData(GridData.FILL_HORIZONTAL); grpInformation.setLayoutData(gd); layout = new GridLayout(); layout.numColumns = 3; layout.marginWidth = 9; layout.marginTop = 5; layout.marginBottom = 2; layout.verticalSpacing = 7; grpInformation.setLayout(layout); Label lblName = new Label(grpInformation, SWT.NONE); lblName.setText(WizardMessages.Make_Keys_lblName_Text); txtName = new Text(grpInformation, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtName.setLayoutData(gd); txtName.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strName = txtName.getText(); dialogChanged(); } }); txtName.setTextLimit(INFORMATION_TEXT_LIMIT); txtName.addListener(SWT.Modify, this); Label lblNameExample = new Label(grpInformation, SWT.NONE); lblNameExample.setText(WizardMessages.Make_Keys_lblExampleName_Text); lblNameExample.setFont(infoFont); Label lblUnit = new Label(grpInformation, SWT.NONE); lblUnit.setText(WizardMessages.Make_Keys_lblUnit_Text); txtUnit = new Text(grpInformation, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtUnit.setLayoutData(gd); txtUnit.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strUnit = txtUnit.getText(); dialogChanged(); } }); txtUnit.setTextLimit(INFORMATION_TEXT_LIMIT); txtUnit.addListener(SWT.Modify, this); Label lblUnitExample = new Label(grpInformation, SWT.NONE); lblUnitExample.setText(WizardMessages.Make_Keys_lblExampleUnit_Text); lblUnitExample.setFont(infoFont); Label lblOrganization = new Label(grpInformation, SWT.NONE); lblOrganization.setText(WizardMessages.Make_Keys_lblOrganization_Text); txtOrganization = new Text(grpInformation, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtOrganization.setLayoutData(gd); txtOrganization.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strOrganization = txtOrganization.getText(); dialogChanged(); } }); txtOrganization.setTextLimit(INFORMATION_TEXT_LIMIT); txtOrganization.addListener(SWT.Modify, this); Label lblOrganizationExample = new Label(grpInformation, SWT.NONE); lblOrganizationExample.setText(WizardMessages.Make_Keys_lblExampleOrganization_Text); lblOrganizationExample.setFont(infoFont); Label lblCountry = new Label(grpInformation, SWT.NONE); lblCountry.setText(WizardMessages.Make_Keys_lblCountry_Text); txtCountry = new Text(grpInformation, SWT.BORDER); gd = new GridData(); gd.widthHint = 20; txtCountry.setLayoutData(gd); txtCountry.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strCountry = txtCountry.getText(); dialogChanged(); } }); txtCountry.setTextLimit(2); txtCountry.addListener(SWT.Modify, this); Label lblCountryExample = new Label(grpInformation, SWT.NONE); lblCountryExample.setText(WizardMessages.Make_Keys_lblExampleCountry_Text); lblCountryExample.setFont(infoFont); Label lblEmail = new Label(grpInformation, SWT.NONE); lblEmail.setText(WizardMessages.Make_Keys_lblEmail_Text); txtEmail = new Text(grpInformation, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtEmail.setLayoutData(gd); txtEmail.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strEmail = txtEmail.getText(); dialogChanged(); } }); txtEmail.setTextLimit(INFORMATION_TEXT_LIMIT); txtEmail.addListener(SWT.Modify, this); Label lblEmailExample = new Label(grpInformation, SWT.NONE); lblEmailExample.setText(WizardMessages.Make_Keys_lblExampleEmail_Text); lblEmailExample.setFont(infoFont); Group grpParameters = new Group(topContainer, SWT.NONE); grpParameters.setText(WizardMessages.Make_Keys_Group_Parameters_Title); gd = new GridData(GridData.FILL_VERTICAL); grpParameters.setLayoutData(gd); layout = new GridLayout(); layout.marginHeight = 9; layout.marginWidth = 9; layout.verticalSpacing = 7; grpParameters.setLayout(layout); Composite lengthContainer = new Composite(grpParameters, SWT.NONE); layout = new GridLayout(); lengthContainer.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); gd.verticalAlignment = SWT.BOTTOM; lengthContainer.setLayoutData(gd); layout.numColumns = 3; layout.marginHeight = 0; layout.marginWidth = 0; Label lblLength = new Label(lengthContainer, SWT.NONE); lblLength.setText(WizardMessages.Make_Keys_lblKeyLength_Text); spnKeyLength = new Spinner(lengthContainer, SWT.BORDER); gd = new GridData(); gd.widthHint = 25; spnKeyLength.setLayoutData(gd); spnKeyLength.setMaximum(SymbianUtil.MAX_KEY_LENGTH); spnKeyLength.setMinimum(SymbianUtil.MIN_KEY_LENGTH); spnKeyLength.setPageIncrement(KEY_PAGE_INCREMENT); spnKeyLength.setIncrement(KEY_INCREMENT); spnKeyLength.setSelection(keyLength); spnKeyLength.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { keyLength = spnKeyLength.getSelection(); dialogChanged(); } }); spnKeyLength.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (keyLength % KEY_INCREMENT != 0) { int valueBefore = (Math.round(keyLength / KEY_INCREMENT)) * KEY_INCREMENT; int valueNext = valueBefore + KEY_INCREMENT; if (keyLength - valueBefore < valueNext - keyLength) spnKeyLength.setSelection(valueBefore); else spnKeyLength.setSelection(valueNext); } } }); spnKeyLength.addListener(SWT.Modify, this); Label lblBits = new Label(lengthContainer, SWT.NONE); lblBits.setText(WizardMessages.Make_Keys_lblKeyBits_Text); gd = new GridData(GridData.FILL_HORIZONTAL); lblBits.setLayoutData(gd); Composite infoContainer = new Composite(grpParameters, SWT.NONE); layout = new GridLayout(); infoContainer.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); infoContainer.setLayoutData(gd); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; Label lblInfoImage = new Label(infoContainer, SWT.NONE); gd = new GridData(SWT.RIGHT, SWT.TOP, false, false); lblInfoImage.setLayoutData(gd); labelImage = ISharedImageDescriptor.ICON16_INFO.createImage(); lblInfoImage.setImage(labelImage); Label lblInfoText = new Label(infoContainer, SWT.WRAP); gd = new GridData(GridData.FILL_HORIZONTAL); gd.widthHint = 20; gd.heightHint = 67; lblInfoText.setLayoutData(gd); lblInfoText.setText(WizardMessages.Make_Keys_lblInfoText_Text); Composite validityContainer = new Composite(grpParameters, SWT.NONE); layout = new GridLayout(); validityContainer.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); gd.verticalAlignment = SWT.BOTTOM; validityContainer.setLayoutData(gd); layout.numColumns = 3; layout.marginHeight = 0; layout.marginWidth = 0; Label lblValid = new Label(validityContainer, SWT.NONE); lblValid.setText(WizardMessages.Make_Keys_lblValidText_Text); spnValidityTime = new Spinner(validityContainer, SWT.BORDER); gd = new GridData(); gd.widthHint = 15; spnValidityTime.setLayoutData(gd); spnValidityTime.setMaximum(VALID_MAX); spnValidityTime.setMinimum(VALID_MIN); spnValidityTime.setPageIncrement(VALID_PAGE_INCREMENT); spnValidityTime.setIncrement(VALID_INCREMENT); spnValidityTime.setSelection(VALID_DEFAULT); spnValidityTime.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { validityTime = spnValidityTime.getSelection(); if (validityTime == 1) lblYears.setText(WizardMessages.Make_Keys_lblYearText_Text); else lblYears.setText(WizardMessages.Make_Keys_lblYearsText_Text); dialogChanged(); } }); spnValidityTime.addSelectionListener(new SelectionListener() { public void widgetDefaultSelected(SelectionEvent e) { } public void widgetSelected(SelectionEvent e) { if (validityTime > VALID_MAX) spnValidityTime.setSelection(VALID_MAX); if (validityTime < VALID_MIN) spnValidityTime.setSelection(VALID_MIN); } }); spnValidityTime.addListener(SWT.Modify, this); lblYears = new Label(validityContainer, SWT.NONE); lblYears.setText(WizardMessages.Make_Keys_lblYearsText_Text); gd = new GridData(GridData.FILL_HORIZONTAL); lblYears.setLayoutData(gd); Group grpDestination = new Group(container, SWT.NONE); grpDestination.setText(WizardMessages.Make_Keys_Group_Destination_Title); gd = new GridData(GridData.FILL_HORIZONTAL); gd.widthHint = 459; grpDestination.setLayoutData(gd); layout = new GridLayout(); layout.numColumns = 5; layout.marginHeight = 9; layout.marginWidth = 9; layout.verticalSpacing = 7; grpDestination.setLayout(layout); Label lblKeyDestination = new Label(grpDestination, SWT.NONE); lblKeyDestination.setText(WizardMessages.Make_Keys_lblKeyDestination_Text); txtKeyDestination = new Text(grpDestination, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 3; txtKeyDestination.setLayoutData(gd); txtKeyDestination.setText(DEFAULT_FOLDER + File.separator + DEFAULT_KEY_FILE_NAME + ".key"); txtKeyDestination.addListener(SWT.Modify, this); txtKeyDestination.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strKeyDestination = txtKeyDestination.getText(); dialogChanged(); } }); strKeyDestination = txtKeyDestination.getText(); class OpenKeyDestination implements SelectionListener { public void widgetSelected(SelectionEvent event) { FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); fileDialog.setText(WizardMessages.Make_Keys_KeyFileDialog_Title); fileDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); fileDialog.setFilterExtensions(KEY_FILTER_EXT); if (strKeyDestination != "") fileDialog.setFileName(strKeyDestination); if (fileDialog.open() != null) { String separator = ""; int length = fileDialog.getFilterPath().trim().length(); if (length > 0 && fileDialog.getFilterPath().charAt(length - 1) != File.separatorChar) separator = File.separator; strKeyDestination = new Path(fileDialog.getFilterPath() + separator + fileDialog.getFileName()) .toOSString(); txtKeyDestination.setText(strKeyDestination); } updateStates(); txtKeyDestination.setFocus(); } public void widgetDefaultSelected(SelectionEvent event) { } } btnKeyBrowse = new Button(grpDestination, SWT.NONE); initializeDialogUnits(btnKeyBrowse); setButtonLayoutData(btnKeyBrowse); btnKeyBrowse.setText(WizardMessages.Make_Keys_btnKeyBrowse_Text); btnKeyBrowse.addSelectionListener(new OpenKeyDestination()); Label lblCerDestination = new Label(grpDestination, SWT.NONE); lblCerDestination.setText(WizardMessages.Make_Keys_lblCerDestination_Text); txtCerDestination = new Text(grpDestination, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); gd.horizontalSpan = 3; txtCerDestination.setLayoutData(gd); txtCerDestination.setText(DEFAULT_FOLDER + File.separator + DEFAULT_CERTIFICATE_FILE_NAME + ".cer"); txtCerDestination.addListener(SWT.Modify, this); txtCerDestination.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strCerDestination = txtCerDestination.getText(); dialogChanged(); } }); strCerDestination = txtCerDestination.getText(); class OpenCerDestination implements SelectionListener { public void widgetSelected(SelectionEvent event) { FileDialog fileDialog = new FileDialog(getShell(), SWT.SAVE); fileDialog.setText(WizardMessages.Make_Keys_CerFileDialog_Title); fileDialog.setFilterPath(ResourcesPlugin.getWorkspace().getRoot().getLocation().toOSString()); fileDialog.setFilterExtensions(CERTIFICATE_FILTER_EXT); if (strCerDestination != "") fileDialog.setFileName(strCerDestination); if (fileDialog.open() != null) { String separator = ""; int length = fileDialog.getFilterPath().trim().length(); if (length > 0 && fileDialog.getFilterPath().charAt(length - 1) != File.separatorChar) separator = File.separator; strCerDestination = new Path(fileDialog.getFilterPath() + separator + fileDialog.getFileName()) .toOSString(); txtCerDestination.setText(strCerDestination); } txtCerDestination.setFocus(); updateStates(); } public void widgetDefaultSelected(SelectionEvent event) { } } btnCerBrowse = new Button(grpDestination, SWT.NONE); initializeDialogUnits(btnCerBrowse); setButtonLayoutData(btnCerBrowse); btnCerBrowse.setText(WizardMessages.Make_Keys_btnCerBrowse_Text); btnCerBrowse.addSelectionListener(new OpenCerDestination()); Label lblPassword = new Label(grpDestination, SWT.NONE); lblPassword.setText(WizardMessages.Make_Keys_lblPassword_Text); txtPassword = new Text(grpDestination, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtPassword.setLayoutData(gd); txtPassword.setEchoChar('*'); txtPassword.addListener(SWT.Modify, this); txtPassword.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strPassword = txtPassword.getText(); if (txtPassword.getText().trim().length() < 4) txtConfirmPassword.setText(""); dialogChanged(); } }); warningContainer = new Composite(grpDestination, SWT.NULL); layout = new GridLayout(); warningContainer.setLayout(layout); gd = new GridData(GridData.FILL_VERTICAL); gd.horizontalSpan = 2; gd.verticalSpan = 2; warningContainer.setLayoutData(gd); layout.numColumns = 2; layout.marginHeight = 0; layout.marginWidth = 0; if (new File(DEFAULT_FOLDER + File.separator + DEFAULT_KEY_FILE_NAME + ".key").exists()) warningContainer.setVisible(true); else warningContainer.setVisible(false); Label lblInfo2Image = new Label(warningContainer, SWT.NONE); gd = new GridData(SWT.RIGHT, SWT.TOP, false, false); lblInfo2Image.setLayoutData(gd); labelImage2 = ISharedImageDescriptor.ICON16_WARNING.createImage(); lblInfo2Image.setImage(labelImage2); Label lblInfo2Text = new Label(warningContainer, SWT.WRAP); gd = new GridData(GridData.FILL_BOTH); gd.widthHint = 110; lblInfo2Text.setLayoutData(gd); lblInfo2Text.setText(WizardMessages.Make_Keys_lblInfo2Text_Text); // Dummy label to fill a column new Label(grpDestination, SWT.NONE); lblConfirmPassword = new Label(grpDestination, SWT.NONE); lblConfirmPassword.setText(WizardMessages.Make_Keys_lblConfirmPassword_Text); lblConfirmPassword.setEnabled(false); txtConfirmPassword = new Text(grpDestination, SWT.BORDER); gd = new GridData(GridData.FILL_HORIZONTAL); txtConfirmPassword.setLayoutData(gd); txtConfirmPassword.setEchoChar('*'); txtConfirmPassword.setEnabled(false); txtConfirmPassword.addListener(SWT.Modify, this); txtConfirmPassword.addModifyListener(new ModifyListener() { public void modifyText(ModifyEvent e) { strConfirmPassword = txtConfirmPassword.getText(); dialogChanged(); } }); Composite container3 = new Composite(area, SWT.NONE); container3.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); layout = new GridLayout(); container3.setLayout(layout); layout.marginHeight = 0; layout.marginWidth = 0; layout.verticalSpacing = 0; final Label separator2 = new Label(container3, SWT.SEPARATOR | SWT.HORIZONTAL); separator2.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); shell = this.getShell(); return area; }
From source file:com.nokia.tools.variant.editor.editors.composites.SearchComposite.java
License:Open Source License
public static Font getBoldFont() { if (boldFont == null) { FontData fd = JFaceResources.getDefaultFont().getFontData()[0]; boldFont = new Font(Display.getDefault(), fd.getName(), 8, SWT.BOLD); }//w ww .j a va 2 s. c o m return boldFont; }