/** @param form2 */ private Composite getPageHeader(Composite parent) { final Composite header = new Composite(parent, SWT.FILL); final FormLayout layout = new FormLayout(); layout.marginHeight = 5; layout.marginWidth = 5; header.setLayout(layout); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(header); header.setBackground(parent.getBackground()); final Label titleImage = new Label(header, SWT.FILL); final ImageDescriptor imageDescriptor = ImageDescriptor.createFromURL( Activator.getDefault().getBundle().getResource("icons/view.png")); // $NON-NLS-1$ titleImage.setImage(new Image(parent.getDisplay(), imageDescriptor.getImageData())); final FormData titleImageData = new FormData(); final int imageOffset = -titleImage.computeSize(SWT.DEFAULT, SWT.DEFAULT).y / 2; titleImageData.top = new FormAttachment(50, imageOffset); titleImageData.left = new FormAttachment(0, 10); titleImage.setLayoutData(titleImageData); final Label title = new Label(header, SWT.WRAP); title.setText("View Editor"); // $NON-NLS-1$ titleFont = new Font(title.getDisplay(), getDefaultFontName(title), 12, SWT.BOLD); title.setFont(titleFont); title.setForeground(getTitleColor(parent)); final FormData titleData = new FormData(); title.setLayoutData(titleData); titleData.left = new FormAttachment(titleImage, 5, SWT.DEFAULT); return header; }
private void refresh() { if (theValue != null) { theLabel .getDisplay() .syncExec( new Runnable() { public void run() { theLabel.setText(theValue.getValue()); } }); } }
protected void applyFonts(final Composite composite) { Dialog.applyDialogFont(composite); if (info != null) { final Font font = info.getFont(); final FontData[] fontDatas = font.getFontData(); for (int i = 0; i < fontDatas.length; i++) { fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); } infoFont = new Font(info.getDisplay(), fontDatas); info.setFont(infoFont); } }
public void setLabel(final String text) { if (text == null || label == null || label.isDisposed()) { return; } label .getDisplay() .syncExec( new Runnable() { public void run() { label.setText(text); } }); }
/** * Creates the composite holding the details. * * @param parent the parent * @return the right panel/detail composite */ protected ScrolledComposite createRightPanelContent(Composite parent) { rightPanel = new ScrolledComposite(parent, SWT.V_SCROLL | SWT.H_SCROLL); rightPanel.setShowFocusedControl(true); rightPanel.setExpandVertical(true); rightPanel.setExpandHorizontal(true); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(rightPanel); rightPanel.setLayout(GridLayoutFactory.fillDefaults().create()); rightPanel.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_WHITE)); container = new Composite(rightPanel, SWT.FILL); container.setLayout(GridLayoutFactory.fillDefaults().create()); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, true).applyTo(container); container.setBackground(rightPanel.getBackground()); /* The header */ final Composite header = new Composite(container, SWT.FILL); final GridLayout headerLayout = GridLayoutFactory.fillDefaults().create(); headerLayout.marginWidth = 5; header.setLayout(headerLayout); GridDataFactory.fillDefaults().align(SWT.FILL, SWT.FILL).grab(true, false).applyTo(header); header.setBackground(rightPanel.getBackground()); final Label label = new Label(header, SWT.WRAP); label.setText("Details"); // $NON-NLS-1$ detailsFont = new Font(label.getDisplay(), getDefaultFontName(label), 10, SWT.BOLD); label.setFont(detailsFont); label.setForeground(getTitleColor(parent)); label.setBackground(header.getBackground()); rightPanelContainerComposite = new Composite(container, SWT.FILL); rightPanelContainerComposite.setLayout(GridLayoutFactory.fillDefaults().create()); GridDataFactory.fillDefaults() .align(SWT.FILL, SWT.FILL) .grab(true, true) .applyTo(rightPanelContainerComposite); rightPanelContainerComposite.setBackground(rightPanel.getBackground()); rightPanel.setContent(container); rightPanel.layout(); container.layout(); final Point point = container.computeSize(SWT.DEFAULT, SWT.DEFAULT); rightPanel.setMinSize(point); return rightPanel; }
/** * Updates the change font button and the previewer to reflect the newly selected font. * * @param font The FontData[] to update with. */ private void updateFont(FontData font[]) { FontData[] bestFont = JFaceResources.getFontRegistry().filterData(font, valueControl.getDisplay()); // if we have nothing valid do as best we can if (bestFont == null) { bestFont = getDefaultFontData(); } // Now cache this value in the receiver this.chosenFont = bestFont; if (valueControl != null) { valueControl.setText(StringConverter.asString(chosenFont[0])); } if (previewer != null) { previewer.setFont(bestFont); } }
private void addTitle(Composite parent, String text) { Label label = new Label(parent, SWT.LEFT); label.setLayoutData(new GridData(SWT.FILL, SWT.TOP, true, true, 2, 1)); label.setText(text); FontData[] fontDatas = label.getFont().getFontData(); if (fontDatas.length > 0) { int fHeight = (fontDatas[0].getHeight() + 2); int fStyle = (fontDatas[0].getStyle() | SWT.BOLD); final Font font = new Font(label.getDisplay(), fontDatas[0].getName(), fHeight, fStyle); label.setFont(font); label.addDisposeListener( new DisposeListener() { public void widgetDisposed(DisposeEvent arg0) { font.dispose(); } }); } }
@Override public void createPartControl(Composite parent) { if (!isEditable()) { super.createPartControl(parent); return; } Layout defaultLayout = parent.getLayout(); GridLayout layout = new GridLayout(); layout.marginWidth = 0; layout.marginHeight = 0; layout.verticalSpacing = 0; layout.horizontalSpacing = 0; parent.setLayout(layout); GridData gd = new GridData(GridData.FILL_HORIZONTAL); Composite toolbar = new Composite(parent, SWT.NONE); gd = new GridData(GridData.FILL_HORIZONTAL); toolbar.setLayoutData(gd); _xqueryContextPart = new XQueryContextPart(this); _xqueryContextPart.createToolbarControl(toolbar); GridData separatorGd = new GridData(GridData.FILL_HORIZONTAL); separatorGd.heightHint = 1; Label separator = new Label(parent, SWT.NONE); separator.setLayoutData(separatorGd); separator.setBackground(separator.getDisplay().getSystemColor(SWT.COLOR_WIDGET_LIGHT_SHADOW)); Composite editorContainer = new Composite(parent, SWT.NONE); editorContainer.setLayout(defaultLayout); gd = new GridData(GridData.FILL_BOTH); editorContainer.setLayoutData(gd); super.createPartControl(editorContainer); setGlobalActionHandlers(); activateContext(); }
/** * @see * com.aptana.ide.editors.unified.ContributedBrowser#createControl(org.eclipse.swt.widgets.Composite) */ public void createControl(Composite parent) { browser = createSWTBrowser(parent); browser.setLayoutData(new GridData(GridData.FILL, GridData.FILL, true, true)); errors = new Composite(parent, SWT.NONE); GridLayout eLayout = new GridLayout(2, false); eLayout.marginHeight = 1; eLayout.marginWidth = 1; eLayout.horizontalSpacing = 2; errors.setLayout(eLayout); errors.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false)); hand = new Cursor(errors.getDisplay(), SWT.CURSOR_HAND); errorIcon = new Label(errors, SWT.LEFT); errorIcon.setCursor(hand); MouseAdapter showConsole = new MouseAdapter() { public void mouseDown(MouseEvent e) { ConsolePlugin.getDefault() .getConsoleManager() .showConsoleView(FirefoxConsole.getConsole()); } }; errorIcon.setLayoutData(new GridData(SWT.END, SWT.FILL, true, true)); errorIcon.addMouseListener(showConsole); errorLabel = new Label(errors, SWT.LEFT); errorLabel.setCursor(hand); errorLabel.addMouseListener(showConsole); errorLabel.setForeground(errorLabel.getDisplay().getSystemColor(SWT.COLOR_DARK_RED)); errorLabel.setLayoutData(new GridData(SWT.END, SWT.CENTER, false, true)); nsIConsoleService service = (nsIConsoleService) Mozilla.getInstance() .getServiceManager() .getServiceByContractID( "@mozilla.org/consoleservice;1", nsIConsoleService.NS_ICONSOLESERVICE_IID); // $NON-NLS-1$ service.registerListener(errorListener); // Hook console FirefoxConsole.getConsole(); }
/** * Get the size hints for the receiver. These are used for layout data. * * @return Point - the preferred x and y coordinates */ public Point getSizeHints() { Display display = canvas.getDisplay(); GC gc = new GC(canvas); FontMetrics fm = gc.getFontMetrics(); int charWidth = fm.getAverageCharWidth(); int charHeight = fm.getHeight(); gc.dispose(); int maxWidth = display.getBounds().width / 2; int maxHeight = display.getBounds().height / 6; int fontWidth = charWidth * maxCharacterWidth; int fontHeight = charHeight * numShowItems; if (maxWidth < fontWidth) { fontWidth = maxWidth; } if (maxHeight < fontHeight) { fontHeight = maxHeight; } return new Point(fontWidth, fontHeight); }
/** * Get the system default font data. * * @return FontData[] */ private FontData[] getDefaultFontData() { return valueControl.getDisplay().getSystemFont().getFontData(); }
public Composite configSectionCreate(final Composite parent) { ImageLoader imageLoader = ImageLoader.getInstance(); Image imgOpenFolder = imageLoader.getImage("openFolderButton"); GridData gridData; GridLayout layout; final Composite cBR = new Composite(parent, SWT.NULL); gridData = new GridData(GridData.VERTICAL_ALIGN_FILL | GridData.HORIZONTAL_ALIGN_FILL); cBR.setLayoutData(gridData); layout = new GridLayout(); layout.numColumns = 1; cBR.setLayout(layout); Label info_label = new Label(cBR, SWT.WRAP); Messages.setLanguageText(info_label, "ConfigView.section.br.overview"); gridData = Utils.getWrappableLabelGridData(1, GridData.HORIZONTAL_ALIGN_FILL); info_label.setLayoutData(gridData); // wiki link final Label linkLabel = new Label(cBR, SWT.NULL); linkLabel.setText(MessageText.getString("ConfigView.label.please.visit.here")); linkLabel.setData("http://wiki.vuze.com/w/Backup_And_Restore"); linkLabel.setCursor(linkLabel.getDisplay().getSystemCursor(SWT.CURSOR_HAND)); linkLabel.setForeground(Colors.blue); gridData = Utils.getWrappableLabelGridData(1, 0); linkLabel.setLayoutData(gridData); linkLabel.addMouseListener( new MouseAdapter() { public void mouseDoubleClick(MouseEvent arg0) { Utils.launch((String) ((Label) arg0.widget).getData()); } public void mouseDown(MouseEvent arg0) { Utils.launch((String) ((Label) arg0.widget).getData()); } }); ClipboardCopy.addCopyToClipMenu(linkLabel); final BackupManager backup_manager = BackupManagerFactory.getManager(AzureusCoreFactory.getSingleton()); // backup Group gBackup = new Group(cBR, SWT.NULL); Messages.setLanguageText(gBackup, "br.backup"); layout = new GridLayout(2, false); gBackup.setLayout(layout); gBackup.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // info Label last_backup_label = new Label(gBackup, SWT.NULL); Messages.setLanguageText(last_backup_label, "br.backup.last.time"); final Label last_backup_time = new Label(gBackup, SWT.NULL); Label last_backup_error_label = new Label(gBackup, SWT.NULL); Messages.setLanguageText(last_backup_error_label, "br.backup.last.error"); final Label last_backup_error = new Label(gBackup, SWT.NULL); final Runnable stats_updater = new Runnable() { public void run() { long backup_time = backup_manager.getLastBackupTime(); last_backup_time.setText(backup_time == 0 ? "" : String.valueOf(new Date(backup_time))); last_backup_error.setText(backup_manager.getLastBackupError()); }; }; stats_updater.run(); // manual button Label backup_manual_label = new Label(gBackup, SWT.NULL); Messages.setLanguageText(backup_manual_label, "br.backup.manual.info"); Button backup_button = new Button(gBackup, SWT.PUSH); Messages.setLanguageText(backup_button, "br.backup"); backup_button.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default"); DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL); if (def_dir != null) { dialog.setFilterPath(def_dir); } dialog.setMessage(MessageText.getString("br.backup.folder.info")); dialog.setText(MessageText.getString("br.backup.folder.title")); String path = dialog.open(); if (path != null) { COConfigurationManager.setParameter("br.backup.folder.default", path); runBackup(backup_manager, path, stats_updater); } } }); final BooleanParameter auto_backup_enable = new BooleanParameter(gBackup, "br.backup.auto.enable", "br.backup.auto.enable"); gridData = new GridData(); gridData.horizontalSpan = 2; auto_backup_enable.setLayoutData(gridData); Composite gDefaultDir = new Composite(gBackup, SWT.NONE); layout = new GridLayout(); layout.numColumns = 3; layout.marginHeight = 2; gDefaultDir.setLayout(layout); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 2; gDefaultDir.setLayoutData(gridData); Label lblDefaultDir = new Label(gDefaultDir, SWT.NONE); Messages.setLanguageText(lblDefaultDir, "ConfigView.section.file.defaultdir.ask"); lblDefaultDir.setLayoutData(new GridData()); gridData = new GridData(GridData.FILL_HORIZONTAL); final StringParameter pathParameter = new StringParameter(gDefaultDir, "br.backup.auto.dir", ""); pathParameter.setLayoutData(gridData); if (pathParameter.getValue().length() == 0) { String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default"); pathParameter.setValue(def_dir); } Button browse = new Button(gDefaultDir, SWT.PUSH); browse.setImage(imgOpenFolder); imgOpenFolder.setBackground(browse.getBackground()); browse.setToolTipText(MessageText.getString("ConfigView.button.browse")); browse.addListener( SWT.Selection, new Listener() { /* (non-Javadoc) * @see org.eclipse.swt.widgets.Listener#handleEvent(org.eclipse.swt.widgets.Event) */ public void handleEvent(Event event) { DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL); dialog.setFilterPath(pathParameter.getValue()); dialog.setMessage(MessageText.getString("br.backup.auto.dir.select")); dialog.setText(MessageText.getString("ConfigView.section.file.defaultdir.ask")); String path = dialog.open(); if (path != null) { pathParameter.setValue(path); COConfigurationManager.setParameter("br.backup.folder.default", path); } } }); Label lbl_backup_days = new Label(gDefaultDir, SWT.NULL); Messages.setLanguageText(lbl_backup_days, "br.backup.auto.everydays"); IntParameter backup_everydays = new IntParameter(gDefaultDir, "br.backup.auto.everydays", 1, Integer.MAX_VALUE); gridData = new GridData(); gridData.horizontalSpan = 2; backup_everydays.setLayoutData(gridData); Label lbl_backup_retain = new Label(gDefaultDir, SWT.NULL); Messages.setLanguageText(lbl_backup_retain, "br.backup.auto.retain"); IntParameter backup_retain = new IntParameter(gDefaultDir, "br.backup.auto.retain", 1, Integer.MAX_VALUE); gridData = new GridData(); gridData.horizontalSpan = 2; backup_retain.setLayoutData(gridData); BooleanParameter chkNotify = new BooleanParameter(gDefaultDir, "br.backup.notify", "br.backup.notify"); gridData = new GridData(GridData.FILL_HORIZONTAL); gridData.horizontalSpan = 3; chkNotify.setLayoutData(gridData); Label backup_auto_label = new Label(gDefaultDir, SWT.NULL); Messages.setLanguageText(backup_auto_label, "br.backup.auto.now"); Button backup_auto_button = new Button(gDefaultDir, SWT.PUSH); Messages.setLanguageText(backup_auto_button, "br.test"); backup_auto_button.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { runBackup(backup_manager, null, stats_updater); } }); auto_backup_enable.setAdditionalActionPerformer( new ChangeSelectionActionPerformer(gDefaultDir)); // restore Group gRestore = new Group(cBR, SWT.NULL); Messages.setLanguageText(gRestore, "br.restore"); layout = new GridLayout(2, false); gRestore.setLayout(layout); gRestore.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); Label restore_label = new Label(gRestore, SWT.NULL); Messages.setLanguageText(restore_label, "br.restore.info"); Button restore_button = new Button(gRestore, SWT.PUSH); Messages.setLanguageText(restore_button, "br.restore"); restore_button.addListener( SWT.Selection, new Listener() { public void handleEvent(Event event) { String def_dir = COConfigurationManager.getStringParameter("br.backup.folder.default"); DirectoryDialog dialog = new DirectoryDialog(parent.getShell(), SWT.APPLICATION_MODAL); if (def_dir != null) { dialog.setFilterPath(def_dir); } dialog.setMessage(MessageText.getString("br.restore.folder.info")); dialog.setText(MessageText.getString("br.restore.folder.title")); final String path = dialog.open(); if (path != null) { MessageBoxShell mb = new MessageBoxShell( SWT.ICON_WARNING | SWT.OK | SWT.CANCEL, MessageText.getString("br.restore.warning.title"), MessageText.getString("br.restore.warning.info")); mb.setDefaultButtonUsingStyle(SWT.CANCEL); mb.setParent(parent.getShell()); mb.open( new UserPrompterResultListener() { public void prompterClosed(int returnVal) { if (returnVal != SWT.OK) { return; } final TextViewerWindow viewer = new TextViewerWindow( MessageText.getString("br.backup.progress"), null, "", true, true); viewer.setEditable(false); viewer.setOKEnabled(false); backup_manager.restore( new File(path), new BackupManager.BackupListener() { public boolean reportProgress(String str) { return (append(str, false)); } public void reportComplete() { append("Restore Complete!", true); Utils.execSWTThread( new AERunnable() { public void runSupport() { MessageBoxShell mb = new MessageBoxShell( SWT.ICON_INFORMATION | SWT.OK, MessageText.getString( "ConfigView.section.security.restart.title"), MessageText.getString( "ConfigView.section.security.restart.msg")); mb.setParent(parent.getShell()); mb.open( new UserPrompterResultListener() { public void prompterClosed(int returnVal) { UIFunctionsSWT uiFunctions = UIFunctionsManagerSWT.getUIFunctionsSWT(); if (uiFunctions != null) { uiFunctions.dispose(true, false); } } }); } }); } public void reportError(Throwable error) { append( "Restore Failed: " + Debug.getNestedExceptionMessage(error), true); } private boolean append(final String str, final boolean complete) { if (viewer.isDisposed()) { return (false); } Utils.execSWTThread( new AERunnable() { public void runSupport() { if (str.endsWith("...")) { viewer.append(str); } else { viewer.append(str + "\r\n"); } if (complete) { viewer.setOKEnabled(true); } } }); return (true); } }); viewer.goModal(); } }); } } }); return (cBR); }
/** * Creates a source viewer information control with the given shell as parent. The given shell * styles are applied to the created shell. The given styles are applied to the created styled * text widget. The text widget will be initialized with the given font. The status field will * contain the given text or be hidden. * * @param parent the parent shell * @param isResizable <code>true</code> if resizable * @param symbolicFontName the symbolic font name * @param statusFieldText the text to be used in the optional status field or <code>null</code> if * the status field should be hidden */ public SourceViewerInformationControl( Shell parent, boolean isResizable, String symbolicFontName, String statusFieldText) { GridLayout layout; GridData gd; int shellStyle = SWT.TOOL | SWT.ON_TOP | (isResizable ? SWT.RESIZE : 0); int textStyle = isResizable ? SWT.V_SCROLL | SWT.H_SCROLL : SWT.NONE; fShell = new Shell(parent, SWT.NO_FOCUS | SWT.ON_TOP | shellStyle); Display display = fShell.getDisplay(); Composite composite = fShell; layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); gd = new GridData(GridData.FILL_HORIZONTAL); composite.setLayoutData(gd); if (statusFieldText != null) { composite = new Composite(composite, SWT.NONE); layout = new GridLayout(1, false); layout.marginHeight = 0; layout.marginWidth = 0; composite.setLayout(layout); gd = new GridData(GridData.FILL_BOTH); composite.setLayoutData(gd); composite.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND)); composite.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } // Source viewer fViewer = new SourceViewer(composite, null, textStyle); fViewer.configure(new SourceViewerConfiguration()); fViewer.setEditable(false); fText = fViewer.getTextWidget(); gd = new GridData(GridData.BEGINNING | GridData.FILL_BOTH); fText.setLayoutData(gd); fText.setForeground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_FOREGROUND)); fText.setBackground(parent.getDisplay().getSystemColor(SWT.COLOR_INFO_BACKGROUND)); fSymbolicFontName = symbolicFontName; fTextFont = JFaceResources.getFont(symbolicFontName); fText.setFont(fTextFont); fText.addKeyListener( new KeyListener() { public void keyPressed(KeyEvent e) { if (e.character == 0x1B) // ESC fShell.dispose(); } public void keyReleased(KeyEvent e) {} }); // Status field if (statusFieldText != null) { // Horizontal separator line fSeparator = new Label(composite, SWT.SEPARATOR | SWT.HORIZONTAL | SWT.LINE_DOT); fSeparator.setLayoutData(new GridData(GridData.FILL_HORIZONTAL)); // Status field label fStatusField = new Label(composite, SWT.RIGHT); fStatusField.setText(statusFieldText); Font font = fStatusField.getFont(); FontData[] fontDatas = font.getFontData(); for (int i = 0; i < fontDatas.length; i++) fontDatas[i].setHeight(fontDatas[i].getHeight() * 9 / 10); fStatusTextFont = new Font(fStatusField.getDisplay(), fontDatas); fStatusField.setFont(fStatusTextFont); GridData gd2 = new GridData( GridData.FILL_VERTICAL | GridData.FILL_HORIZONTAL | GridData.HORIZONTAL_ALIGN_BEGINNING | GridData.VERTICAL_ALIGN_BEGINNING); fStatusField.setLayoutData(gd2); fStatusTextForegroundColor = new Color( fStatusField.getDisplay(), blend( display.getSystemColor(SWT.COLOR_INFO_BACKGROUND).getRGB(), display.getSystemColor(SWT.COLOR_INFO_FOREGROUND).getRGB(), 0.56f)); fStatusField.setForeground(fStatusTextForegroundColor); fStatusField.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND)); } addDisposeListener(this); }