/*
   * (non-Javadoc)
   *
   * @see net.refractions.udig.style.sld.SLDEditorPart#createPartControl(org.eclipse.swt.widgets.Composite)
   */
  protected Control createPartControl(Composite parent) {
    myparent = parent;
    RowLayout layout = new RowLayout();
    myparent.setLayout(layout);
    layout.pack = false;
    layout.wrap = true;
    layout.type = SWT.HORIZONTAL;

    /* Border Opacity */
    Group borderOpacityArea = new Group(myparent, SWT.NONE);
    borderOpacityArea.setLayout(new GridLayout(2, false));
    borderOpacityArea.setText("Raster Opacity"); // $NON-NLS-1$

    opacityScale = new Scale(borderOpacityArea, SWT.HORIZONTAL);
    opacityScale.setMinimum(0);
    opacityScale.setMaximum(100);
    opacityScale.setPageIncrement(10);
    opacityScale.setBounds(0, 0, 10, SWT.DEFAULT);
    opacityScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            opacityText.setText(String.valueOf(opacityScale.getSelection()) + "%"); // $NON-NLS-1$
            opacityText.pack(true);
          }
        });
    opacityScale.addSelectionListener(this);

    opacityText = new Text(borderOpacityArea, SWT.BORDER | SWT.READ_ONLY);
    opacityText.pack(true);

    return parent;
  }
  @Override
  protected Control createControl(Composite parent) {
    // TODO Auto-generated method stub

    Composite composite = new Composite(parent, SWT.NULL);
    GridLayout layout = new GridLayout(1, false);
    layout.marginHeight = layout.marginWidth = layout.horizontalSpacing = 0;
    composite.setLayout(layout);

    scale = new Scale(composite, SWT.HORIZONTAL);
    scale.setSize(200, 30);
    scale.setMinimum(0);
    scale.setMaximum(10);
    scale.addSelectionListener(
        new SelectionListener() {

          @Override
          public void widgetSelected(SelectionEvent e) {
            // TODO Auto-generated method stub
            System.out.println("scale: " + scale.getSelection());
            LevelHighlightingEvent event = new LevelHighlightingEvent();
            event.setHierarchyLevel(scale.getSelection());

            EventPublisher.trigger(event);
          }

          @Override
          public void widgetDefaultSelected(SelectionEvent e) {
            // TODO Auto-generated method stub

          }
        });

    return composite;
  }
  @Override
  public void initialize() {
    super.initialize();

    if (!dynamicEnabled) {
      return;
    }

    Scale scale = getScale();
    scale.addSelectionListener(selectionListener);
  }
  public void testRenderAddSelectionListener() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertEquals(Boolean.TRUE, message.findListenProperty(scale, "selection"));
  }
  public void testRenderSelectionListenerUnchanged() throws Exception {
    Scale scale = new Scale(shell, SWT.NONE);
    Fixture.markInitialized(display);
    Fixture.markInitialized(scale);
    Fixture.preserveWidgets();

    scale.addSelectionListener(new SelectionAdapter() {});
    Fixture.preserveWidgets();
    lca.renderChanges(scale);

    Message message = Fixture.getProtocolMessage();
    assertNull(message.findListenOperation(scale, "selection"));
  }
 private void testSelectionEvent(final Scale scale) {
   final StringBuilder log = new StringBuilder();
   SelectionListener selectionListener =
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent event) {
           assertEquals(scale, event.getSource());
           assertEquals(null, event.item);
           assertEquals(SWT.NONE, event.detail);
           assertEquals(0, event.x);
           assertEquals(0, event.y);
           assertEquals(0, event.width);
           assertEquals(0, event.height);
           assertEquals(true, event.doit);
           log.append("widgetSelected");
         }
       };
   scale.addSelectionListener(selectionListener);
   String scaleId = WidgetUtil.getId(scale);
   Fixture.fakeRequestParam(JSConst.EVENT_WIDGET_SELECTED, scaleId);
   Fixture.readDataAndProcessAction(scale);
   assertEquals("widgetSelected", log.toString());
 }
Example #7
0
 org.eclipse.swt.widgets.Scale makeWidget(
     Composite comp, Dimension major, IFigureConstructionEnv env) {
   int swtConstant = 0;
   switch (major) {
     case X:
       swtConstant = SWT.HORIZONTAL;
       break;
     case Y:
       swtConstant = SWT.VERTICAL;
       break;
   }
   org.eclipse.swt.widgets.Scale result = new org.eclipse.swt.widgets.Scale(comp, swtConstant);
   result.setSelection(selected.getValue());
   result.addSelectionListener(
       new SelectionAdapter() {
         @Override
         public void widgetSelected(SelectionEvent e) {
           doCallback();
         }
       });
   return result;
 }
Example #8
0
 private void createScalingControls(Composite client) {
   final Scale scale = new Scale(client, SWT.NONE);
   scale.setMinimum(1);
   scale.setMaximum(100);
   scale.setSelection(50);
   scale.setPageIncrement(5);
   scale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           int selection = scale.getSelection();
           if (selection > 50) {
             selection = selection - 50;
             scaleFactor.setText(String.valueOf(1.0d * selection));
           } else if (selection == 50) {
             scaleFactor.setText(String.valueOf(1.0d));
           } else {
             selection = 50 - selection;
             scaleFactor.setText(String.valueOf(1.0d / selection));
           }
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().span(3, 0).applyTo(scale);
   Label label = kit.createLabel(client, "scale factor: ");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(label);
   scaleFactor = kit.createText(client, "1.0");
   GridDataFactory.fillDefaults().grab(true, false).applyTo(scaleFactor);
   final Button setScale = kit.createButton(client, "apply", SWT.PUSH);
   setScale.addSelectionListener(
       new SelectionAdapter() {
         public void widgetSelected(SelectionEvent e) {
           applyScaleFactor();
         }
       });
   GridDataFactory.fillDefaults().applyTo(setScale);
 }
  @Override
  public void createPartControl(Composite parent) {
    plotViewName = getViewSite().getRegisteredName();
    plotServer.addIObserver(this);
    setPartName(plotViewName);
    this.parent = parent;
    parent.setLayout(new GridLayout(1, true));

    locationRow = new Composite(parent, SWT.NONE);
    locationRow.setLayout(new GridLayout(4, false));
    {
      btnHistoryBack = new Button(locationRow, SWT.LEFT);
      btnHistoryBack.setEnabled(false);
      btnHistoryBack.setToolTipText("Go back in history");
      btnHistoryBack.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_left.png").createImage());
      btnHistoryBack.addSelectionListener(this);
      btnHistoryForw = new Button(locationRow, SWT.LEFT);
      btnHistoryForw.setEnabled(false);
      btnHistoryForw.setToolTipText("Go forward in history");
      btnHistoryForw.addSelectionListener(this);
      btnHistoryForw.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/arrow_right.png").createImage());
      lblLocation = new Label(locationRow, SWT.LEFT);
      lblLocation.setText("Location:");

      cmbDirectoryLocation = new Combo(locationRow, SWT.SINGLE | SWT.LEFT | SWT.BORDER);
      cmbDirectoryLocation.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
      cmbDirectoryLocation.addSelectionListener(this);
    }
    locationRow.setLayoutData(new GridData(SWT.FILL, SWT.NONE, false, false));

    canvas = new Canvas(parent, SWT.DOUBLE_BUFFERED | SWT.V_SCROLL | SWT.H_SCROLL);
    canvas.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));

    compHUD = new Group(parent, SWT.NONE);
    compHUD.setLayout(new GridLayout(6, false));
    compHUD.setText("Image Playback");
    {
      btnRewind = new Button(compHUD, SWT.PUSH);
      btnRewind.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_start.png").createImage());
      btnRewind.addSelectionListener(this);
      btnRewind.setToolTipText("Rewind");
      btnPlay = new Button(compHUD, SWT.TOGGLE);
      imgPlay = AnalysisRCPActivator.getImageDescriptor("icons/control_play.png").createImage();
      imgStill = AnalysisRCPActivator.getImageDescriptor("icons/control_pause.png").createImage();
      btnPlay.setImage(imgPlay);
      btnPlay.addSelectionListener(this);
      btnPlay.setToolTipText("Play/Pause");
      btnStop = new Button(compHUD, SWT.PUSH);
      btnStop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_stop.png").createImage());
      btnStop.addSelectionListener(this);
      btnStop.setToolTipText("Stop playback");
      btnForward = new Button(compHUD, SWT.PUSH);
      btnForward.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_end.png").createImage());
      btnForward.addSelectionListener(this);
      btnForward.setToolTipText("Forward");
      btnPlayLoop = new Button(compHUD, SWT.TOGGLE);
      btnPlayLoop.setImage(
          AnalysisRCPActivator.getImageDescriptor("icons/control_repeat.png").createImage());
      btnPlayLoop.setToolTipText("Playback loop (On/off)");
      btnPlayLoop.addSelectionListener(this);
      sldProgress = new Scale(compHUD, SWT.HORIZONTAL);
      sldProgress.setPageIncrement(1);
      sldProgress.addSelectionListener(this);
      sldProgress.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true));
    }
    compHUD.setLayoutData(new GridData(SWT.FILL, SWT.NONE, true, false));

    imageGrid = new PlotServerSWTImageGrid(canvas, plotViewName);
    imageGrid.setThumbnailSize(getPreferenceImageSize());
    retainStateFromServer();

    if (dirPath != null && dirPath.length() > 0) {
      dirPath.trim();
      updateDirectory.setUser(true);
      updateDirectory.setPriority(Job.DECORATE);
      updateDirectory.schedule(1000);
      cmbDirectoryLocation.setText(dirPath);
      currentDir = dirPath;
    }
    playback =
        new ImagePlayBack(
            parent,
            getPreferencePlaybackView(),
            getViewSite().getPage(),
            sldProgress,
            getPreferenceTimeDelay(),
            getPreferencePlaybackRate());

    isDisposed = false;

    // listen to preference changes to update the Live plot play back view and colour map
    AnalysisRCPActivator.getDefault()
        .getPreferenceStore()
        .addPropertyChangeListener(
            new IPropertyChangeListener() {
              @Override
              public void propertyChange(PropertyChangeEvent event) {
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_PLAYBACKVIEW)) {
                  playback.setPlotView(getPreferencePlaybackView());
                }
                if (event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_COLOURMAP)
                    || event.getProperty().equals(PreferenceConstants.IMAGEEXPLORER_IMAGESIZE)) {
                  List<GridImageEntry> images = imageGrid.getListOfEntries();
                  imageGrid.setThumbnailSize(getPreferenceImageSize());
                  String colourScheme = getPreferenceColourMapChoice();
                  for (GridImageEntry entry : images) {
                    IDataset data = entry.getData();
                    SWTGridEntry gridEntry =
                        new SWTGridEntry(
                            entry.getFilename(),
                            data,
                            canvas,
                            colourScheme,
                            getPreferenceAutoContrastLo(),
                            getPreferenceAutoContrastHi());
                    imageGrid.addEntry(gridEntry, entry.getGridColumnPos(), entry.getGridRowPos());
                  }
                  // Check the colour menu accordingly
                  IAction currentColour = colorMenu.findAction(colourScheme);
                  if (currentColour != null) currentColour.setChecked(true);
                }
              }
            });
  }
Example #10
0
  /** Creates the GUI. */
  public void createGUI(Composite parent) {
    GridLayout gridLayout;
    GridData gridData;

    /** * Create principal GUI layout elements ** */
    Composite displayArea = new Composite(parent, SWT.NONE);
    gridLayout = new GridLayout();
    gridLayout.numColumns = 1;
    displayArea.setLayout(gridLayout);

    // Creating these elements here avoids the need to instantiate the GUI elements
    // in strict layout order. The natural layout ordering is an artifact of using
    // SWT layouts, but unfortunately it is not the same order as that required to
    // instantiate all of the non-GUI application elements to satisfy referential
    // dependencies. It is possible to reorder the initialization to some extent, but
    // this can be very tedious.

    // paint canvas
    final Canvas paintCanvas =
        new Canvas(
            displayArea,
            SWT.BORDER | SWT.V_SCROLL | SWT.H_SCROLL | SWT.NO_REDRAW_RESIZE | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    paintCanvas.setLayoutData(gridData);
    paintCanvas.setBackground(paintColorWhite);

    // color selector frame
    final Composite colorFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    colorFrame.setLayoutData(gridData);

    // tool settings frame
    final Composite toolSettingsFrame = new Composite(displayArea, SWT.NONE);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    toolSettingsFrame.setLayoutData(gridData);

    // status text
    final Text statusText = new Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    gridData = new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    statusText.setLayoutData(gridData);

    /** * Create the remaining application elements inside the principal GUI layout elements ** */
    // paintSurface
    paintSurface = new PaintSurface(paintCanvas, statusText, paintColorWhite);

    // finish initializing the tool data
    PaintExample.tools[PaintExample.Pencil_tool].data = new PencilTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Airbrush_tool].data =
        new AirbrushTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Line_tool].data = new LineTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.PolyLine_tool].data =
        new PolyLineTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Rectangle_tool].data =
        new RectangleTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.RoundedRectangle_tool].data =
        new RoundedRectangleTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Ellipse_tool].data =
        new EllipseTool(toolSettings, paintSurface);
    PaintExample.tools[PaintExample.Text_tool].data = new TextTool(toolSettings, paintSurface);

    // colorFrame
    gridLayout = new GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    colorFrame.setLayout(gridLayout);

    // activeForegroundColorCanvas, activeBackgroundColorCanvas
    activeForegroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeForegroundColorCanvas.setLayoutData(gridData);

    activeBackgroundColorCanvas = new Canvas(colorFrame, SWT.BORDER);
    gridData = new GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeBackgroundColorCanvas.setLayoutData(gridData);

    // paletteCanvas
    final Canvas paletteCanvas = new Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
    gridData = new GridData(GridData.FILL_HORIZONTAL);
    gridData.heightHint = 24;
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addListener(
        SWT.MouseDown,
        new Listener() {
          public void handleEvent(Event e) {
            Rectangle bounds = paletteCanvas.getClientArea();
            Color color = getColorAt(bounds, e.x, e.y);

            if (e.button == 1) setForegroundColor(color);
            else setBackgroundColor(color);
          }

          private Color getColorAt(Rectangle bounds, int x, int y) {
            if (bounds.height <= 1 && bounds.width <= 1) return paintColorWhite;
            final int row = (y - bounds.y) * PaintExample.numPaletteRows / bounds.height;
            final int col = (x - bounds.x) * PaintExample.numPaletteCols / bounds.width;
            return paintColors[
                Math.min(
                    Math.max(row * PaintExample.numPaletteCols + col, 0), paintColors.length - 1)];
          }
        });
    Listener refreshListener =
        new Listener() {
          public void handleEvent(Event e) {
            if (e.gc == null) return;
            Rectangle bounds = paletteCanvas.getClientArea();
            for (int row = 0; row < PaintExample.numPaletteRows; ++row)
              for (int col = 0; col < PaintExample.numPaletteCols; ++col) {
                final int x = bounds.width * col / PaintExample.numPaletteCols;
                final int y = bounds.height * row / PaintExample.numPaletteRows;
                final int width =
                    Math.max(bounds.width * (col + 1) / PaintExample.numPaletteCols - x, 1);
                final int height =
                    Math.max(bounds.height * (row + 1) / PaintExample.numPaletteRows - y, 1);
                e.gc.setBackground(paintColors[row * PaintExample.numPaletteCols + col]);
                e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height);
              }
          }
        };
    paletteCanvas.addListener(SWT.Resize, refreshListener);
    paletteCanvas.addListener(SWT.Paint, refreshListener);
    // paletteCanvas.redraw();

    // toolSettingsFrame
    gridLayout = new GridLayout();
    gridLayout.numColumns = 4;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolSettingsFrame.setLayout(gridLayout);

    Label label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(PaintExample.getResourceString("settings.AirbrushRadius.text"));

    final Scale airbrushRadiusScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushRadiusScale.setMinimum(5);
    airbrushRadiusScale.setMaximum(50);
    airbrushRadiusScale.setSelection(toolSettings.airbrushRadius);
    airbrushRadiusScale.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushRadiusScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushRadius = airbrushRadiusScale.getSelection();
            updateToolSettings();
          }
        });

    label = new Label(toolSettingsFrame, SWT.NONE);
    label.setText(PaintExample.getResourceString("settings.AirbrushIntensity.text"));

    final Scale airbrushIntensityScale = new Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushIntensityScale.setMinimum(1);
    airbrushIntensityScale.setMaximum(100);
    airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity);
    airbrushIntensityScale.setLayoutData(
        new GridData(GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushIntensityScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();
            updateToolSettings();
          }
        });
  }
  /** {@inheritDoc} */
  public Composite createControls(Composite parent, FormToolkit toolkit) {
    Section section = toolkit.createSection(parent, Section.TITLE_BAR);
    section.setText("Sampling Rate");
    section.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    Composite composite = toolkit.createComposite(section);
    section.setClient(composite);

    GridLayout layout = new GridLayout(4, false);
    layout.marginLeft = 10;
    layout.horizontalSpacing = 10;
    composite.setLayout(layout);
    GridData gridData = new GridData(SWT.MAX, SWT.DEFAULT);
    gridData.grabExcessHorizontalSpace = true;
    composite.setLayoutData(gridData);

    final Label sliderLabel = toolkit.createLabel(composite, "no sensitivity selected", SWT.LEFT);
    GridData data = new GridData(SWT.FILL, SWT.FILL, false, false);
    data.widthHint = sliderLabel.computeSize(SWT.DEFAULT, SWT.DEFAULT).x;
    sliderLabel.setLayoutData(data);

    slider = new Scale(composite, SWT.HORIZONTAL);
    toolkit.adapt(slider, true, true);
    slider.setMinimum(0);
    slider.setMaximum(Sensitivity.values().length - 1);
    slider.setIncrement(1);
    slider.setSize(200, 10);
    slider.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false));
    slider.addSelectionListener(
        new SelectionAdapter() {
          /** {@inheritDoc} */
          @Override
          public void widgetSelected(SelectionEvent event) {
            Sensitivity sensitivity = Sensitivity.fromOrd(slider.getSelection());

            switch (sensitivity) {
              case NO_SENSITIVITY:
                sliderLabel.setText("no sensitivity selected");
                break;
              case VERY_FINE:
                sliderLabel.setText("very fine");
                break;
              case FINE:
                sliderLabel.setText("fine");
                break;
              case MEDIUM:
                sliderLabel.setText("medium");
                break;
              case COARSE:
                sliderLabel.setText("coarse");
                break;
              case VERY_COARSE:
                sliderLabel.setText("very coarse");
                break;
              default:
                break;
            }
          }
        });
    slider.setSelection(DEFAULT_SENSITIVITY.ordinal());
    slider.notifyListeners(SWT.Selection, null);

    Label modeLabel = toolkit.createLabel(composite, "Sampling Rate Mode: ", SWT.LEFT);
    modeLabel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));

    timeframeModeButton = toolkit.createButton(composite, "Timeframe dividing", SWT.RADIO);
    timeframeModeButton.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
    timeframeModeButton.setSelection(true);

    return composite;
  }
Example #12
0
  /** Create contents of the window. */
  protected void createContents() {
    splitImageShell = new Shell();
    splitImageShell.setSize(500, 500);
    splitImageShell.setText("Image Mosaic");

    Log.print("Opening the split image GUI.");

    Group splitImageGroup = new Group(splitImageShell, SWT.NONE);
    splitImageGroup.setText("Split Main Image");
    splitImageGroup.setBounds(10, 10, 464, 400);

    numYCompSpinner = new Spinner(splitImageGroup, SWT.BORDER);
    numYCompScale = new Scale(splitImageGroup, SWT.VERTICAL);
    numXCompScale = new Scale(splitImageGroup, SWT.NONE);
    numXCompSpinner = new Spinner(splitImageGroup, SWT.BORDER);
    mainImageLabel = new Label(splitImageGroup, SWT.NONE);

    numYCompSpinner.setBounds(10, 20, 47, 22);
    numYCompSpinner.setMaximum(150);
    numYCompSpinner.setMinimum(1);
    numYCompSpinner.setSelection(1);
    numYCompSpinner.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            numYCompScale.setSelection(numYCompSpinner.getSelection());
            dispImage =
                outlineSplitImage(
                    image, numXCompSpinner.getSelection(), numYCompScale.getSelection());
            final Image swtMainImage =
                new Image(Display.getDefault(), ImageManipulator.convertAWTImageToSWT(dispImage));
            mainImageLabel.setImage(swtMainImage);
          }
        });

    numYCompScale.setBounds(10, 48, 42, 300);
    numYCompScale.setMaximum(150);
    numYCompScale.setMinimum(1);
    numYCompScale.setSelection(1);
    numYCompScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            numYCompSpinner.setSelection(numYCompScale.getSelection());
            dispImage =
                outlineSplitImage(
                    image, numXCompSpinner.getSelection(), numYCompSpinner.getSelection());
            final Image swtMainImage =
                new Image(Display.getDefault(), ImageManipulator.convertAWTImageToSWT(dispImage));
            mainImageLabel.setImage(swtMainImage);
          }
        });

    numXCompScale.setMaximum(150);
    numXCompScale.setMinimum(1);
    numXCompScale.setSelection(1);
    numXCompScale.setBounds(41, 348, 360, 42);
    numXCompScale.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            numXCompSpinner.setSelection(numXCompScale.getSelection());
            dispImage =
                outlineSplitImage(
                    image, numXCompSpinner.getSelection(), numYCompSpinner.getSelection());
            final Image swtMainImage =
                new Image(Display.getDefault(), ImageManipulator.convertAWTImageToSWT(dispImage));
            mainImageLabel.setImage(swtMainImage);
          }
        });

    numXCompSpinner.setMaximum(150);
    numXCompSpinner.setMinimum(1);
    numXCompSpinner.setSelection(1);
    numXCompSpinner.setBounds(407, 357, 47, 22);
    numXCompSpinner.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            numXCompScale.setSelection(numXCompSpinner.getSelection());
            dispImage =
                outlineSplitImage(
                    image, numXCompScale.getSelection(), numYCompSpinner.getSelection());
            final Image swtMainImage =
                new Image(Display.getDefault(), ImageManipulator.convertAWTImageToSWT(dispImage));
            mainImageLabel.setImage(swtMainImage);
          }
        });

    int mainImageLabelWidth = 391;
    int mainImageLabelHeight = 328;
    mainImageLabel.setBounds(63, 20, mainImageLabelWidth, mainImageLabelHeight);
    this.image = ImageManipulator.fitImage(this.image, mainImageLabelWidth, mainImageLabelHeight);
    dispImage =
        outlineSplitImage(
            this.image, numXCompSpinner.getSelection(), numYCompSpinner.getSelection());
    final Image swtMainImage =
        new Image(Display.getDefault(), ImageManipulator.convertAWTImageToSWT(dispImage));
    mainImageLabel.setImage(swtMainImage);

    Button cancelButton = new Button(splitImageShell, SWT.NONE);
    cancelButton.setBounds(399, 427, 75, 25);
    cancelButton.setText("Cancel");
    cancelButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            Log.print("Cancelled splitting image. Closing split image GUI.");
            splitImageShell.dispose();
          }
        });

    Button okayButton = new Button(splitImageShell, SWT.NONE);
    okayButton.setBounds(318, 427, 75, 25);
    okayButton.setText("Okay");
    okayButton.addSelectionListener(
        new SelectionAdapter() {
          public void widgetSelected(SelectionEvent e) {
            numXSubcomponents = numXCompSpinner.getSelection();
            numYSubcomponents = numYCompSpinner.getSelection();

            Log.print("Image split has been confirmed.");

            splitImageShell.dispose();
          }
        });
  }
  public RoomDataComposite(Composite parent, RoomController control) {
    super(parent, SWT.NONE);
    setLayout(new GridLayout(3, false));

    this.roomC = control;
    container = Manager.getCurrentShip();
    final ShipController shipC = container.getShipController();

    label = new Label(this, SWT.NONE);
    label.setAlignment(SWT.CENTER);
    label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));
    label.setText("Room");

    Label separator = new Label(this, SWT.SEPARATOR | SWT.HORIZONTAL);
    separator.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 3, 1));

    Label lblSystem = new Label(this, SWT.NONE);
    lblSystem.setText("System: ");

    btnSystem = new Button(this, SWT.NONE);
    GridData gd_btnSystem = new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1);
    gd_btnSystem.widthHint = 100;
    btnSystem.setLayoutData(gd_btnSystem);
    btnSystem.setText("");

    btnAvailable = new Button(this, SWT.CHECK);
    btnAvailable.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1));
    btnAvailable.setText("Available At Start");

    lblSysLevel = new Label(this, SWT.NONE);
    lblSysLevel.setText("Starting Level:");

    scaleSysLevel = new Scale(this, SWT.NONE);
    scaleSysLevel.setMaximum(2);
    scaleSysLevel.setMinimum(1);
    scaleSysLevel.setPageIncrement(1);
    scaleSysLevel.setIncrement(1);
    scaleSysLevel.setSelection(1);
    scaleSysLevel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));

    txtSysLevel = new Text(this, SWT.BORDER | SWT.READ_ONLY);
    txtSysLevel.setText("");
    txtSysLevel.setTextLimit(3);
    GridData gd_txtSysLevel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
    gd_txtSysLevel.widthHint = 20;
    txtSysLevel.setLayoutData(gd_txtSysLevel);

    scaleSysLevel.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Systems sys = container.getActiveSystem(roomC.getGameObject());
            SystemController system = container.getSystemController(sys);
            system.setLevel(scaleSysLevel.getSelection());
            txtSysLevel.setText("" + scaleSysLevel.getSelection());
          }
        });

    if (!Manager.getCurrentShip().getShipController().isPlayerShip()) {
      lblMaxLevel = new Label(this, SWT.NONE);
      lblMaxLevel.setText("Max Level:");

      scaleMaxLevel = new Scale(this, SWT.NONE);
      scaleMaxLevel.setMaximum(2);
      scaleMaxLevel.setMinimum(1);
      scaleMaxLevel.setPageIncrement(1);
      scaleMaxLevel.setIncrement(1);
      scaleMaxLevel.setSelection(1);
      scaleMaxLevel.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));

      txtMaxLevel = new Text(this, SWT.BORDER | SWT.READ_ONLY);
      txtMaxLevel.setText("");
      txtMaxLevel.setTextLimit(3);
      GridData gd_txtMaxLevel = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1);
      gd_txtMaxLevel.widthHint = 20;
      txtMaxLevel.setLayoutData(gd_txtMaxLevel);

      scaleMaxLevel.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              system.setLevelMax(scaleMaxLevel.getSelection());
              txtMaxLevel.setText("" + scaleMaxLevel.getSelection());
              if (!shipC.isPlayerShip()) {
                scaleSysLevel.setMaximum(scaleMaxLevel.getSelection());
                scaleSysLevel.notifyListeners(SWT.Selection, null);
                scaleSysLevel.setEnabled(scaleMaxLevel.getSelection() > 1);
                scaleSysLevel.setSelection(
                    Math.min(scaleSysLevel.getSelection(), scaleSysLevel.getMaximum()));
              }
            }
          });
    } else {
      imagesComposite = new Composite(this, SWT.NONE);
      GridLayout gl_imagesComposite = new GridLayout(4, false);
      gl_imagesComposite.marginHeight = 0;
      gl_imagesComposite.marginWidth = 0;
      imagesComposite.setLayout(gl_imagesComposite);
      imagesComposite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, false, 3, 1));

      // Interior widgets
      Label lblInterior = new Label(imagesComposite, SWT.NONE);
      lblInterior.setText("Interior image:");

      btnInteriorView = new Button(imagesComposite, SWT.NONE);
      btnInteriorView.setEnabled(false);
      btnInteriorView.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 1, 1));
      btnInteriorView.setText("View");

      btnInteriorBrowse = new Button(imagesComposite, SWT.NONE);
      btnInteriorBrowse.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      btnInteriorBrowse.setText("Browse");

      btnInteriorClear = new Button(imagesComposite, SWT.NONE);
      btnInteriorClear.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      btnInteriorClear.setText("Reset");

      txtInterior = new Text(imagesComposite, SWT.BORDER | SWT.READ_ONLY);
      txtInterior.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 4, 1));

      // Glow widgets
      lblGlow = new Label(imagesComposite, SWT.NONE);
      lblGlow.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
      lblGlow.setText("Manning glow:");

      btnGlow = new Button(imagesComposite, SWT.NONE);
      GridData gd_btnGlow = new GridData(SWT.RIGHT, SWT.CENTER, false, false, 3, 1);
      gd_btnGlow.widthHint = 120;
      btnGlow.setLayoutData(gd_btnGlow);
      btnGlow.setText("None");

      SelectionAdapter imageViewListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              File file = new File(system.getInteriorPath());

              if (file != null && file.exists()) {
                if (Desktop.isDesktopSupported()) {
                  Desktop desktop = Desktop.getDesktop();
                  if (desktop != null) {
                    try {
                      desktop.open(file.getParentFile());
                    } catch (IOException ex) {
                    }
                  }
                } else {
                  Superluminal.log.error(
                      "Unable to open file location - AWT Desktop not supported.");
                }
              }
            }
          };
      btnInteriorView.addSelectionListener(imageViewListener);

      SelectionAdapter imageBrowseListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);
              FileDialog dialog = new FileDialog(EditorWindow.getInstance().getShell());
              dialog.setFilterExtensions(new String[] {"*.png"});
              String path = dialog.open();

              // path == null only when user cancels
              if (path != null) {
                system.setInteriorPath("file:" + path);
                updateData();
              }
            }
          };
      btnInteriorBrowse.addSelectionListener(imageBrowseListener);

      SelectionAdapter imageClearListener =
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemController system = container.getSystemController(sys);

              system.setInteriorPath(null);
              updateData();
            }
          };
      btnInteriorClear.addSelectionListener(imageClearListener);

      btnGlow.addSelectionListener(
          new SelectionAdapter() {
            @Override
            public void widgetSelected(SelectionEvent e) {
              Systems sys = container.getActiveSystem(roomC.getGameObject());
              SystemObject systemObject = container.getSystemController(sys).getGameObject();

              GlowSelectionDialog dialog =
                  new GlowSelectionDialog(EditorWindow.getInstance().getShell());
              GlowSet glowSet = dialog.open(systemObject);

              if (glowSet != null) {
                btnGlow.setText(glowSet.getIdentifier());
                systemObject.setGlowSet(glowSet);
              }
            }
          });
    }

    btnSystem.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Point p = btnSystem.getLocation();
            SystemsMenu sysMenu = SystemsMenu.getInstance();
            sysMenu.setLocation(toDisplay(p.x, p.y + btnSystem.getSize().y));
            sysMenu.open();
          }
        });

    btnAvailable.addSelectionListener(
        new SelectionAdapter() {
          @Override
          public void widgetSelected(SelectionEvent e) {
            Systems sys = container.getActiveSystem(roomC.getGameObject());
            SystemController system = container.getSystemController(sys);
            system.setAvailableAtStart(btnAvailable.getSelection());
            roomC.redraw();
          }
        });

    updateData();

    pack();
  }
Example #14
0
  public void createGUI(org.eclipse.swt.widgets.Composite parent) {
    org.eclipse.swt.layout.GridLayout gridLayout;
    org.eclipse.swt.layout.GridData gridData;
    org.eclipse.swt.widgets.Composite displayArea =
        new org.eclipse.swt.widgets.Composite(parent, SWT.NONE);
    gridLayout = new org.eclipse.swt.layout.GridLayout();
    gridLayout.numColumns = 1;
    displayArea.setLayout(gridLayout);
    final org.eclipse.swt.widgets.Canvas paintCanvas =
        new org.eclipse.swt.widgets.Canvas(
            displayArea,
            (-(SWT.BORDER | SWT.V_SCROLL))
                | SWT.H_SCROLL
                | SWT.NO_REDRAW_RESIZE
                | SWT.NO_BACKGROUND);
    gridData =
        new org.eclipse.swt.layout.GridData(GridData.FILL_HORIZONTAL | GridData.FILL_VERTICAL);
    paintCanvas.setLayoutData(gridData);
    paintCanvas.setBackground(paintColorWhite);
    final org.eclipse.swt.widgets.Composite colorFrame =
        new org.eclipse.swt.widgets.Composite(displayArea, SWT.NONE);
    gridData =
        new org.eclipse.swt.layout.GridData(
            GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    colorFrame.setLayoutData(gridData);
    final org.eclipse.swt.widgets.Composite toolSettingsFrame =
        new org.eclipse.swt.widgets.Composite(displayArea, SWT.NONE);
    gridData =
        new org.eclipse.swt.layout.GridData(
            GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    toolSettingsFrame.setLayoutData(gridData);
    final org.eclipse.swt.widgets.Text statusText =
        new org.eclipse.swt.widgets.Text(displayArea, SWT.BORDER | SWT.SINGLE | SWT.READ_ONLY);
    gridData =
        new org.eclipse.swt.layout.GridData(
            GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL);
    statusText.setLayoutData(gridData);
    paintSurface =
        new org.eclipse.swt.examples.paint.PaintSurface(paintCanvas, statusText, paintColorWhite);
    tools[Pencil_tool].data =
        new org.eclipse.swt.examples.paint.PencilTool(toolSettings, paintSurface);
    tools[Airbrush_tool].data =
        new org.eclipse.swt.examples.paint.AirbrushTool(toolSettings, paintSurface);
    tools[Line_tool].data = new org.eclipse.swt.examples.paint.LineTool(toolSettings, paintSurface);
    tools[PolyLine_tool].data =
        new org.eclipse.swt.examples.paint.PolyLineTool(toolSettings, paintSurface);
    tools[Rectangle_tool].data =
        new org.eclipse.swt.examples.paint.RectangleTool(toolSettings, paintSurface);
    tools[RoundedRectangle_tool].data =
        new org.eclipse.swt.examples.paint.RoundedRectangleTool(toolSettings, paintSurface);
    tools[Ellipse_tool].data =
        new org.eclipse.swt.examples.paint.EllipseTool(toolSettings, paintSurface);
    tools[Text_tool].data = new org.eclipse.swt.examples.paint.TextTool(toolSettings, paintSurface);
    gridLayout = new org.eclipse.swt.layout.GridLayout();
    gridLayout.numColumns = 3;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    colorFrame.setLayout(gridLayout);
    activeForegroundColorCanvas = new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER);
    gridData = new org.eclipse.swt.layout.GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeForegroundColorCanvas.setLayoutData(gridData);
    activeBackgroundColorCanvas = new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER);
    gridData = new org.eclipse.swt.layout.GridData(GridData.HORIZONTAL_ALIGN_FILL);
    gridData.heightHint = 24;
    gridData.widthHint = 24;
    activeBackgroundColorCanvas.setLayoutData(gridData);
    final org.eclipse.swt.widgets.Canvas paletteCanvas =
        new org.eclipse.swt.widgets.Canvas(colorFrame, SWT.BORDER | SWT.NO_BACKGROUND);
    gridData = new org.eclipse.swt.layout.GridData(GridData.FILL_HORIZONTAL);
    gridData.heightHint = 24;
    paletteCanvas.setLayoutData(gridData);
    paletteCanvas.addListener(
        SWT.MouseDown,
        new org.eclipse.swt.widgets.Listener() {
          public void handleEvent(org.eclipse.swt.widgets.Event e) {
            org.eclipse.swt.graphics.Rectangle bounds = paletteCanvas.getClientArea();
            org.eclipse.swt.graphics.Color color = getColorAt(bounds, e.x, e.y);
            if (e.button == 1) {
              setForegroundColor(color);
            } else {
              setBackgroundColor(color);
            }
          }

          private org.eclipse.swt.graphics.Color getColorAt(
              org.eclipse.swt.graphics.Rectangle bounds, int x, int y) {
            if (bounds.height <= 1 && bounds.width <= 1) {
              return paintColorWhite;
            }
            final int row = (y - bounds.y) * numPaletteRows / bounds.height;
            final int col = (x - bounds.x) * numPaletteCols / bounds.width;
            return paintColors[
                Math.min(Math.max(row * numPaletteCols + col, 0), paintColors.length - 1)];
          }
        });
    org.eclipse.swt.widgets.Listener refreshListener =
        new org.eclipse.swt.widgets.Listener() {
          public void handleEvent(org.eclipse.swt.widgets.Event e) {
            if (e.gc == null) {
              return;
            }
            org.eclipse.swt.graphics.Rectangle bounds = paletteCanvas.getClientArea();
            for (int row = 0; row < numPaletteRows; ++row) {
              for (int col = 0; col < numPaletteCols; ++col) {
                final int x = bounds.width * col / numPaletteCols;
                final int y = bounds.height * row / numPaletteRows;
                final int width = Math.max(bounds.width * (col + 1) / numPaletteCols - x, 1);
                final int height = Math.max(bounds.height * (row + 1) / numPaletteRows - y, 1);
                e.gc.setBackground(paintColors[row * numPaletteCols + col]);
                e.gc.fillRectangle(bounds.x + x, bounds.y + y, width, height);
              }
            }
          }
        };
    paletteCanvas.addListener(SWT.Resize, refreshListener);
    paletteCanvas.addListener(SWT.Paint, refreshListener);
    gridLayout = new org.eclipse.swt.layout.GridLayout();
    gridLayout.numColumns = 4;
    gridLayout.marginHeight = 0;
    gridLayout.marginWidth = 0;
    toolSettingsFrame.setLayout(gridLayout);
    org.eclipse.swt.widgets.Label label =
        new org.eclipse.swt.widgets.Label(toolSettingsFrame, SWT.NONE);
    label.setText(getResourceString("settings.AirbrushRadius.text"));
    final org.eclipse.swt.widgets.Scale airbrushRadiusScale =
        new org.eclipse.swt.widgets.Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushRadiusScale.setMinimum(5);
    airbrushRadiusScale.setMaximum(50);
    airbrushRadiusScale.setSelection(toolSettings.airbrushRadius);
    airbrushRadiusScale.setLayoutData(
        new org.eclipse.swt.layout.GridData(
            GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushRadiusScale.addSelectionListener(
        new org.eclipse.swt.events.SelectionAdapter() {
          public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            toolSettings.airbrushRadius = airbrushRadiusScale.getSelection();
            updateToolSettings();
          }
        });
    label = new org.eclipse.swt.widgets.Label(toolSettingsFrame, SWT.NONE);
    label.setText(getResourceString("settings.AirbrushIntensity.text"));
    final org.eclipse.swt.widgets.Scale airbrushIntensityScale =
        new org.eclipse.swt.widgets.Scale(toolSettingsFrame, SWT.HORIZONTAL);
    airbrushIntensityScale.setMinimum(1);
    airbrushIntensityScale.setMaximum(100);
    airbrushIntensityScale.setSelection(toolSettings.airbrushIntensity);
    airbrushIntensityScale.setLayoutData(
        new org.eclipse.swt.layout.GridData(
            GridData.FILL_HORIZONTAL | GridData.VERTICAL_ALIGN_FILL));
    airbrushIntensityScale.addSelectionListener(
        new org.eclipse.swt.events.SelectionAdapter() {
          public void widgetSelected(org.eclipse.swt.events.SelectionEvent e) {
            toolSettings.airbrushIntensity = airbrushIntensityScale.getSelection();
            updateToolSettings();
          }
        });
  }