Example #1
0
 public org.eclipse.swt.widgets.Shell open(org.eclipse.swt.widgets.Display display) {
   createShell(display);
   createMenuBar();
   createStyledText();
   shell.setSize(500, 400);
   shell.open();
   return shell;
 }
Example #2
0
 private void setHoverLocation(
     org.eclipse.swt.widgets.Shell shell, org.eclipse.swt.graphics.Point position) {
   org.eclipse.swt.graphics.Rectangle displayBounds = shell.getDisplay().getBounds();
   org.eclipse.swt.graphics.Rectangle shellBounds = shell.getBounds();
   shellBounds.x = Math.max(Math.min(position.x, displayBounds.width - shellBounds.width), 0);
   shellBounds.y =
       Math.max(Math.min(position.y + 16, displayBounds.height - shellBounds.height), 0);
   shell.setBounds(shellBounds);
 }
Example #3
0
 public static void main(java.lang.String[] args) {
   org.eclipse.swt.widgets.Display display = new org.eclipse.swt.widgets.Display();
   org.eclipse.swt.widgets.Shell shell =
       (new org.eclipse.swt.examples.hoverhelp.HoverHelp()).open(display);
   while (shell != null && !shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }
Example #4
0
 public static void main(java.lang.String[] args) {
   org.eclipse.swt.widgets.Display display = new org.eclipse.swt.widgets.Display();
   org.eclipse.swt.examples.javaviewer.JavaViewer example =
       new org.eclipse.swt.examples.javaviewer.JavaViewer();
   org.eclipse.swt.widgets.Shell shell = example.open(display);
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   display.dispose();
 }
Example #5
0
 private static void setShellSize(
     org.eclipse.swt.widgets.Display display, org.eclipse.swt.widgets.Shell shell) {
   org.eclipse.swt.graphics.Rectangle bounds = display.getBounds();
   org.eclipse.swt.graphics.Point size = shell.computeSize(SWT.DEFAULT, SWT.DEFAULT);
   if (size.x > bounds.width) {
     size.x = bounds.width * 9 / 10;
   }
   if (size.y > bounds.height) {
     size.y = bounds.height * 9 / 10;
   }
   shell.setSize(size);
 }
Example #6
0
 void createShell(org.eclipse.swt.widgets.Display display) {
   shell = new org.eclipse.swt.widgets.Shell(display);
   shell.setText(resources.getString("Window_title"));
   org.eclipse.swt.layout.GridLayout layout = new org.eclipse.swt.layout.GridLayout();
   layout.numColumns = 1;
   shell.setLayout(layout);
   shell.addShellListener(
       new org.eclipse.swt.events.ShellAdapter() {
         public void shellClosed(org.eclipse.swt.events.ShellEvent e) {
           lineStyler.disposeColors();
           text.removeLineStyleListener(lineStyler);
         }
       });
 }
Example #7
0
 void createMenuBar() {
   org.eclipse.swt.widgets.Menu bar = new org.eclipse.swt.widgets.Menu(shell, SWT.BAR);
   shell.setMenuBar(bar);
   org.eclipse.swt.widgets.MenuItem fileItem =
       new org.eclipse.swt.widgets.MenuItem(bar, SWT.CASCADE);
   fileItem.setText(resources.getString("File_menuitem"));
   fileItem.setMenu(createFileMenu());
 }
Example #8
0
 public org.eclipse.swt.widgets.Shell open(org.eclipse.swt.widgets.Display display) {
   java.lang.Class clazz = org.eclipse.swt.examples.hoverhelp.HoverHelp.class;
   try {
     if (images == null) {
       images = new org.eclipse.swt.graphics.Image[imageLocations.length];
       for (int i = 0; i < imageLocations.length; ++i) {
         java.io.InputStream stream = clazz.getResourceAsStream(imageLocations[i]);
         org.eclipse.swt.graphics.ImageData source =
             new org.eclipse.swt.graphics.ImageData(stream);
         org.eclipse.swt.graphics.ImageData mask = source.getTransparencyMask();
         images[i] = new org.eclipse.swt.graphics.Image(display, source, mask);
         try {
           stream.close();
         } catch (java.io.IOException e) {
           e.printStackTrace();
         }
       }
     }
   } catch (java.lang.Exception ex) {
     System.err.println(
         getResourceString(
             "error.CouldNotLoadResources", new java.lang.Object[] {ex.getMessage()}));
     return null;
   }
   org.eclipse.swt.widgets.Shell shell = new org.eclipse.swt.widgets.Shell();
   createPartControl(shell);
   shell.addDisposeListener(
       new org.eclipse.swt.events.DisposeListener() {
         public void widgetDisposed(org.eclipse.swt.events.DisposeEvent e) {
           if (images != null) {
             for (int i = 0; i < images.length; i++) {
               final org.eclipse.swt.graphics.Image image = images[i];
               if (image != null) {
                 image.dispose();
               }
             }
             images = null;
           }
         }
       });
   shell.pack();
   shell.open();
   return shell;
 }
Example #9
0
 public static void main(java.lang.String[] args) {
   org.eclipse.swt.widgets.Display display = new org.eclipse.swt.widgets.Display();
   org.eclipse.swt.widgets.Shell shell = new org.eclipse.swt.widgets.Shell(display);
   shell.setLayout(new org.eclipse.swt.layout.FillLayout());
   shell.setText(getResourceString("window.title"));
   java.io.InputStream stream =
       (org.eclipse.swt.examples.browserexample.BrowserExample.class)
           .getResourceAsStream(iconLocation);
   org.eclipse.swt.graphics.Image icon = new org.eclipse.swt.graphics.Image(display, stream);
   shell.setImage(icon);
   try {
     stream.close();
   } catch (java.io.IOException e) {
     e.printStackTrace();
   }
   org.eclipse.swt.examples.browserexample.BrowserExample app =
       new org.eclipse.swt.examples.browserexample.BrowserExample(shell, true);
   app.setShellDecoration(icon, true);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   icon.dispose();
   app.dispose();
   display.dispose();
 }
Example #10
0
 public ToolTipHandler(org.eclipse.swt.widgets.Shell parent) {
   final org.eclipse.swt.widgets.Display display = parent.getDisplay();
   this.parentShell = parent;
   tipShell = new org.eclipse.swt.widgets.Shell(parent, SWT.ON_TOP | SWT.TOOL);
   org.eclipse.swt.layout.GridLayout gridLayout = new org.eclipse.swt.layout.GridLayout();
   gridLayout.numColumns = 2;
   gridLayout.marginWidth = 2;
   gridLayout.marginHeight = 2;
   tipShell.setLayout(gridLayout);
   tipShell.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelImage = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE);
   tipLabelImage.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
   tipLabelImage.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelImage.setLayoutData(
       new org.eclipse.swt.layout.GridData(
           GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER));
   tipLabelText = new org.eclipse.swt.widgets.Label(tipShell, SWT.NONE);
   tipLabelText.setForeground(display.getSystemColor(SWT.COLOR_INFO_FOREGROUND));
   tipLabelText.setBackground(display.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
   tipLabelText.setLayoutData(
       new org.eclipse.swt.layout.GridData(
           (-(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_CENTER))));
 }
Example #11
0
 public static void main(java.lang.String[] args) {
   org.eclipse.swt.widgets.Display display = new org.eclipse.swt.widgets.Display();
   org.eclipse.swt.widgets.Shell shell = new org.eclipse.swt.widgets.Shell(display);
   shell.setText(getResourceString("window.title"));
   shell.setLayout(new org.eclipse.swt.layout.GridLayout());
   org.eclipse.swt.examples.paint.PaintExample instance =
       new org.eclipse.swt.examples.paint.PaintExample(shell);
   instance.createToolBar(shell);
   org.eclipse.swt.widgets.Composite composite =
       new org.eclipse.swt.widgets.Composite(shell, SWT.NONE);
   composite.setLayout(new org.eclipse.swt.layout.FillLayout());
   composite.setLayoutData(new org.eclipse.swt.layout.GridData(SWT.FILL, SWT.FILL, true, true));
   instance.createGUI(composite);
   instance.setDefaults();
   setShellSize(display, shell);
   shell.open();
   while (!shell.isDisposed()) {
     if (!display.readAndDispatch()) {
       display.sleep();
     }
   }
   instance.dispose();
 }
Example #12
0
 org.eclipse.swt.widgets.Menu createFileMenu() {
   org.eclipse.swt.widgets.Menu bar = shell.getMenuBar();
   org.eclipse.swt.widgets.Menu menu = new org.eclipse.swt.widgets.Menu(bar);
   org.eclipse.swt.widgets.MenuItem item;
   item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
   item.setText(resources.getString("Open_menuitem"));
   item.setAccelerator(SWT.MOD1 + 'O');
   item.addSelectionListener(
       new org.eclipse.swt.events.SelectionAdapter() {
         public void widgetSelected(org.eclipse.swt.events.SelectionEvent event) {
           openFile();
         }
       });
   item = new org.eclipse.swt.widgets.MenuItem(menu, SWT.PUSH);
   item.setText(resources.getString("Exit_menuitem"));
   item.addSelectionListener(
       new org.eclipse.swt.events.SelectionAdapter() {
         public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
           menuFileExit();
         }
       });
   return menu;
 }
Example #13
0
  void show(
      boolean owned,
      org.eclipse.swt.graphics.Point location,
      org.eclipse.swt.graphics.Point size,
      boolean addressBar,
      boolean menuBar,
      boolean statusBar,
      boolean toolBar) {
    final org.eclipse.swt.widgets.Shell shell = browser.getShell();
    if (owned) {
      if (location != null) {
        shell.setLocation(location);
      }
      if (size != null) {
        shell.setSize(shell.computeSize(size.x, size.y));
      }
    }
    org.eclipse.swt.layout.FormData data = null;
    if (toolBar) {
      toolbar = new org.eclipse.swt.widgets.ToolBar(parent, SWT.NONE);
      data = new org.eclipse.swt.layout.FormData();
      data.top = new org.eclipse.swt.layout.FormAttachment(0, 5);
      toolbar.setLayoutData(data);
      itemBack = new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemBack.setText(getResourceString("Back"));
      itemForward = new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemForward.setText(getResourceString("Forward"));
      final org.eclipse.swt.widgets.ToolItem itemStop =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemStop.setText(getResourceString("Stop"));
      final org.eclipse.swt.widgets.ToolItem itemRefresh =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemRefresh.setText(getResourceString("Refresh"));
      final org.eclipse.swt.widgets.ToolItem itemGo =
          new org.eclipse.swt.widgets.ToolItem(toolbar, SWT.PUSH);
      itemGo.setText(getResourceString("Go"));
      itemBack.setEnabled(browser.isBackEnabled());
      itemForward.setEnabled(!browser.isForwardEnabled());
      org.eclipse.swt.widgets.Listener listener =
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event event) {
              org.eclipse.swt.widgets.ToolItem item =
                  (org.eclipse.swt.widgets.ToolItem) event.widget;
              if (item == itemBack) {
                browser.back();
              } else {
                if (item == itemForward) {
                  browser.forward();
                } else {
                  if (item == itemStop) {
                    browser.stop();
                  } else {
                    if (item == itemRefresh) {
                      browser.refresh();
                    } else {
                      if (item == itemGo) {
                        browser.setUrl(locationBar.getText());
                      }
                    }
                  }
                }
              }
            }
          };
      itemBack.addListener(SWT.Selection, listener);
      itemForward.addListener(SWT.Selection, listener);
      itemStop.addListener(SWT.Selection, listener);
      itemRefresh.addListener(SWT.Selection, listener);
      itemGo.addListener(SWT.Selection, listener);
      canvas = new org.eclipse.swt.widgets.Canvas(parent, SWT.NO_BACKGROUND);
      data = new org.eclipse.swt.layout.FormData();
      data.width = 24;
      data.height = 24;
      data.top = new org.eclipse.swt.layout.FormAttachment(0, 5);
      data.right = new org.eclipse.swt.layout.FormAttachment(100, -5);
      canvas.setLayoutData(data);
      final org.eclipse.swt.graphics.Rectangle rect = images[0].getBounds();
      canvas.addListener(
          SWT.Paint,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              org.eclipse.swt.graphics.Point pt =
                  ((org.eclipse.swt.widgets.Canvas) e.widget).getSize();
              e.gc.drawImage(images[index], 0, 0, rect.width, rect.height, 0, 0, pt.x, pt.y);
            }
          });
      canvas.addListener(
          SWT.MouseDown,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              browser.setUrl(getResourceString("Startup"));
            }
          });
      final org.eclipse.swt.widgets.Display display = parent.getDisplay();
      display.asyncExec(
          new java.lang.Runnable() {
            public void run() {
              if (canvas.isDisposed()) {
                return;
              }
              if (busy) {
                index++;
                if (index == images.length) {
                  index = 0;
                }
                canvas.redraw();
              }
              display.timerExec(150, this);
            }
          });
    }
    if (addressBar) {
      locationBar = new org.eclipse.swt.widgets.Text(parent, SWT.BORDER);
      data = new org.eclipse.swt.layout.FormData();
      if (toolbar != null) {
        data.top = new org.eclipse.swt.layout.FormAttachment(toolbar, 0, SWT.TOP);
        data.left = new org.eclipse.swt.layout.FormAttachment(toolbar, 5, SWT.RIGHT);
        data.right = new org.eclipse.swt.layout.FormAttachment(canvas, -5, SWT.DEFAULT);
      } else {
        data.top = new org.eclipse.swt.layout.FormAttachment(0, 0);
        data.left = new org.eclipse.swt.layout.FormAttachment(0, 0);
        data.right = new org.eclipse.swt.layout.FormAttachment(100, 0);
      }
      locationBar.setLayoutData(data);
      locationBar.addListener(
          SWT.DefaultSelection,
          new org.eclipse.swt.widgets.Listener() {
            public void handleEvent(org.eclipse.swt.widgets.Event e) {
              browser.setUrl(locationBar.getText());
            }
          });
    }
    if (statusBar) {
      status = new org.eclipse.swt.widgets.Label(parent, SWT.NONE);
      progressBar = new org.eclipse.swt.widgets.ProgressBar(parent, SWT.NONE);
      data = new org.eclipse.swt.layout.FormData();
      data.left = new org.eclipse.swt.layout.FormAttachment(0, 5);
      data.right = new org.eclipse.swt.layout.FormAttachment(progressBar, 0, SWT.DEFAULT);
      data.bottom = new org.eclipse.swt.layout.FormAttachment(100, -5);
      status.setLayoutData(data);
      data = new org.eclipse.swt.layout.FormData();
      data.right = new org.eclipse.swt.layout.FormAttachment(100, -5);
      data.bottom = new org.eclipse.swt.layout.FormAttachment(100, -5);
      progressBar.setLayoutData(data);
      browser.addStatusTextListener(
          new org.eclipse.swt.browser.StatusTextListener() {
            public void changed(org.eclipse.swt.browser.StatusTextEvent event) {
              status.setText(event.text);
            }
          });
    }
    parent.setLayout(new org.eclipse.swt.layout.FormLayout());
    org.eclipse.swt.widgets.Control aboveBrowser =
        toolBar
            ? (org.eclipse.swt.widgets.Control) canvas
            : addressBar ? (org.eclipse.swt.widgets.Control) locationBar : null;
    data = new org.eclipse.swt.layout.FormData();
    data.left = new org.eclipse.swt.layout.FormAttachment(0, 0);
    data.top =
        aboveBrowser != null
            ? new org.eclipse.swt.layout.FormAttachment(aboveBrowser, 5, SWT.DEFAULT)
            : new org.eclipse.swt.layout.FormAttachment(0, 0);
    data.right = new org.eclipse.swt.layout.FormAttachment(100, 0);
    data.bottom =
        status != null
            ? new org.eclipse.swt.layout.FormAttachment(status, -5, SWT.DEFAULT)
            : new org.eclipse.swt.layout.FormAttachment(100, 0);
    browser.setLayoutData(data);
    if (statusBar || toolBar) {
      browser.addProgressListener(
          new org.eclipse.swt.browser.ProgressListener() {
            public void changed(org.eclipse.swt.browser.ProgressEvent event) {
              if (event.total == 0) {
                return;
              }
              int ratio = event.current * 100 / event.total;
              if (progressBar != null) {
                progressBar.setSelection(ratio);
              }
              busy = event.current != event.total;
              if (!busy) {
                index = 0;
                if (canvas != null) {
                  canvas.redraw();
                }
              }
            }

            public void completed(org.eclipse.swt.browser.ProgressEvent event) {
              if (progressBar != null) {
                progressBar.setSelection(0);
              }
              busy = false;
              index = 0;
              if (canvas != null) {
                itemBack.setEnabled(browser.isBackEnabled());
                itemForward.setEnabled(browser.isForwardEnabled());
                canvas.redraw();
              }
            }
          });
    }
    if (addressBar || statusBar || toolBar) {
      browser.addLocationListener(
          new org.eclipse.swt.browser.LocationListener() {
            public void changed(org.eclipse.swt.browser.LocationEvent event) {
              busy = true;
              if (event.top && locationBar != null) {
                locationBar.setText(event.location);
              }
            }

            public void changing(org.eclipse.swt.browser.LocationEvent event) {}
          });
    }
    if (title) {
      browser.addTitleListener(
          new org.eclipse.swt.browser.TitleListener() {
            public void changed(org.eclipse.swt.browser.TitleEvent event) {
              shell.setText(event.title + " - " + getResourceString("window.title"));
            }
          });
    }
    parent.layout(true);
    if (owned) {
      shell.open();
    }
  }
Example #14
0
 void menuFileExit() {
   shell.close();
 }