Esempio n. 1
0
  protected Composite createWarningComposite(final String text, final int imageType) {

    final Image image = getShell().getDisplay().getSystemImage(imageType);

    final Color backgroundColor = getShell().getBackground();
    final Color foregroundColor = getShell().getForeground();

    final Composite composite = new Composite(getShell(), SWT.NONE);
    final GridLayout gridLayout = new GridLayout(2, false);
    composite.setLayout(gridLayout);
    composite.setBackground(backgroundColor);
    composite.setForeground(foregroundColor);
    Composite imageCanvas = new SWTImageCanvas(composite, SWT.NONE, image);
    imageCanvas.setLayoutData(new GridData(ICONSIZE, ICONSIZE));
    imageCanvas.setBackground(backgroundColor);
    imageCanvas.setForeground(foregroundColor);

    final Label label = new Label(composite, SWT.NONE);
    label.setLayoutData(new GridData(GridData.CENTER, GridData.CENTER, true, true));
    label.setBackground(backgroundColor);
    label.setForeground(foregroundColor);
    label.setText(text);

    return composite;
  }
 @Override
 public void setForegroundColor(final Color foreground) {
   super.setForegroundColor(foreground);
   fContentComposite.setForeground(foreground);
   fTitleText.setForeground(foreground);
   fInfoText.setForeground(foreground);
 }
  /*
   * @see org.eclipse.jface.dialogs.IDialogPage#createControl(org.eclipse.swt.widgets.Composite)
   */
  public void createControl(Composite parent) {

    WidgetFactory factory = getWidgetFactory();

    final int gridDataStyle = GridData.FILL_HORIZONTAL | GridData.GRAB_HORIZONTAL;
    final GridData fieldGridData = new GridData(gridDataStyle);

    Composite container = new Composite(parent, SWT.NULL);
    container.setBackground(parent.getBackground());
    container.setForeground(parent.getForeground());
    container.setLayout(new GridLayout(2, false));
    container.setLayoutData(fieldGridData);

    Label label = null;

    // Format code
    label = new Label(container, SWT.NULL);
    label.setText(Messages.getString("aaa.mdf.metadict.entity.sqlname.label"));
    label.setBackground(container.getBackground());
    mdSQLName = factory.createText(container, null);
    mdSQLName.setLayoutData(fieldGridData);
    mdSQLName.setEditable(false);

    // Format Finantial Function
    label = new Label(container, SWT.NULL);
    label.setText(Messages.getString("aaa.mdf.metadict.entity.name.label"));
    label.setBackground(container.getBackground());
    mdName = factory.createText(container, null);
    mdName.setLayoutData(fieldGridData);
    mdName.setEditable(false);

    initialize();
    setControl(container);
  }
Esempio n. 4
0
 public void setForeground(Color color) {
   super.setForeground(color);
   foreground = color;
   if (text != null) text.setForeground(color);
   if (list != null) list.setForeground(color);
   if (icon != null) icon.setForeground(color);
   if (arrow != null) arrow.setForeground(color);
 }
 static void setColor(Composite composite, String indent, Color color, Color foreGorund) {
   if (composite == null) {
     return;
   }
   try {
     if (!composite.isDisposed()) {
       composite.setRedraw(false);
       if (composite instanceof ToolBar
           || composite instanceof Shell
           || composite instanceof CLabel
           || composite instanceof CTabFolder
           || composite instanceof CoolBar
           || composite instanceof CoolBar
           || composite instanceof CBanner
           || composite instanceof PageBook
           || composite instanceof ViewForm
           || composite instanceof Tree
           || composite instanceof StyledText
           || composite instanceof Table
           || composite.getClass().getName().startsWith("org.eclipse.jface")
           || composite.getClass().getName().startsWith("org.eclipse.ui.internal.layout")
           || composite.getClass().getName().startsWith("org.eclipse.ui.internal.FastViewBar")
           || composite
               .getClass()
               .getName()
               .startsWith("org.eclipse.ui.internal.progress.ProgressRegion")
           || composite.getClass().getName().startsWith("org.eclipse.swt.widgets.Canvas")
           || composite.getClass() == Composite.class) {
         composite.setBackground(color);
         composite.setForeground(foreGorund);
       } else {
         // System.out.println(indent +
         // composite.getClass().getName());
       }
       Control[] controls = composite.getChildren();
       for (Control control : controls) {
         if (!(control instanceof Composite)) {
           // System.out.println(indent + "Control " +
           // control.getClass().getName());
         }
         if (control instanceof Composite) {
           setColor((Composite) control, indent + " ", color, foreGorund);
         } else if (control instanceof Label
             || control instanceof CoolBar
             || control instanceof Sash
             || control instanceof ProgressBar
             || control instanceof Text) {
           control.setBackground(color);
           control.setForeground(foreGorund);
         }
       }
     }
   } finally {
     composite.setRedraw(true);
   }
 }
Esempio n. 6
0
 /**
  * Creates a fresh Basic Text widget
  *
  * @param parent
  * @param style
  */
 public BasicText(Composite parent, int style) {
   super(parent, style);
   super.setForeground(getForeground());
   this.style = style;
   if ((style & SWT.READ_ONLY) != 0) {
     setEditable(false);
   }
   setupClient();
   createRemoteObject();
   installListeners();
 }
  private void createStatusBar(Composite parent) {
    statusComposite = new Composite(parent, SWT.BORDER);
    statusComposite.setLayout(new GridLayout(2, false));
    statusComposite.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, true, false));
    statusComposite.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    statusComposite.setForeground(Displays.getSystemColor(SWT.COLOR_INFO_FOREGROUND));

    Label imageLabel = new Label(statusComposite, SWT.NONE);
    imageLabel.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    imageLabel.setImage(
        PlatformUI.getWorkbench().getSharedImages().getImage(ISharedImages.IMG_OBJS_WARN_TSK));
    imageLabel.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    imageLabel.setForeground(Displays.getSystemColor(SWT.COLOR_INFO_FOREGROUND));

    statusLabel = new Label(statusComposite, SWT.NONE);
    statusLabel.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    statusLabel.setText("");
    statusLabel.setBackground(Displays.getSystemColor(SWT.COLOR_INFO_BACKGROUND));
    statusLabel.setForeground(Displays.getSystemColor(SWT.COLOR_RED));
  }
Esempio n. 8
0
    private void initComponents() {
      Composite root = NorthEdge.this.getEdgeRoot();
      GridLayout gl = new GridLayout(2, false);
      // gl.horizontalSpacing = 0;
      gl.verticalSpacing = 0;
      gl.marginHeight = 0;
      gl.marginWidth = 0;
      root.setLayout(gl);
      _avatar = new Label(root, SWT.NONE);
      _avatar.setImage(null);
      _avatar.setLayoutData(new GridData(64, SWT.DEFAULT)); // the frame pegs the height at 64
      _info = new Label(root, SWT.SINGLE);
      _info.setLayoutData(new GridData(GridData.BEGINNING, GridData.CENTER, true, true));

      Color black = ColorUtil.getColor("black");
      Color white = ColorUtil.getColor("white");
      _avatar.setBackground(white);
      _info.setBackground(white);
      _info.setForeground(black);
      root.setBackground(white);
      root.setForeground(black);
      _themeRegistry.register(NorthEdge.this);
    }
Esempio n. 9
0
  private void initGUI() {
    try {

      this.setOrientation(SWT.VERTICAL);

      this.setBackground(MainGui.cHART_DARKER);
      Color innerBgColor = MainGui.cHART_LIGHT;

      this.addDisposeListener(
          new DisposeListener() {

            public void widgetDisposed(DisposeEvent evt) {
              rootShellClosed(evt);
            }
          });

      this.addListener(
          SWT.Hide,
          new Listener() {

            @Override
            public void handleEvent(Event event) {
              ChartsComposite.this.shutDownDisplay();
            }
          });

      {
        try {
          // Set cross-platform Java L&F (also called "Metal")
          UIManager.setLookAndFeel(UIManager.getCrossPlatformLookAndFeelClassName());
        } catch (UnsupportedLookAndFeelException e) {
          LOGGER.error(e);
        } catch (ClassNotFoundException e) {
          LOGGER.error(e);
        } catch (InstantiationException e) {
          LOGGER.error(e);
        } catch (IllegalAccessException e) {
          LOGGER.error(e);
        }

        mainChartComposite = new Composite(this, SWT.EMBEDDED | SWT.NO_BACKGROUND);
        final Frame chartFrame = SWT_AWT.new_Frame(mainChartComposite);
        final Panel rootHeavyPanel = new Panel();
        rootHeavyPanel.setLayout(new BorderLayout());
        chartFrame.add(rootHeavyPanel);

        mainChartWraper =
            new ChartMain(ChartsComposite.DEFAULT_START_DATE, JFreeChartTimePeriod.DAY);
        mainChartPanel =
            new ChartPanel(
                mainChartWraper.initChart(stripedCloseFunction), true, true, true, false, true) {
              private static final long serialVersionUID = 1L;

              @Override
              public void restoreAutoBounds() {
                // Do nothing (disable mouse left drag zoom)
              }
            };
        mainChartPanel.setMouseZoomable(false, false);
        mainChartPanel.setMinimumDrawWidth(0);
        mainChartPanel.setMinimumDrawHeight(0);
        mainChartPanel.setMaximumDrawWidth(Display.getCurrent().getClientArea().width);
        mainChartPanel.setMaximumDrawHeight(Display.getCurrent().getClientArea().height);

        mainChartPanel.getPopupMenu().addSeparator();
        JMenuItem deleteVLines = new JMenuItem("Remove vertical lines");
        deleteVLines.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                chartDisplayStrategy.removeVLines();
              }
            });
        mainChartPanel.getPopupMenu().add(deleteVLines);
        JMenuItem deleteHLines = new JMenuItem("Remove horizontal lines");
        deleteHLines.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                chartDisplayStrategy.removeHLines();
              }
            });
        mainChartPanel.getPopupMenu().add(deleteHLines);

        mainChartPanel.getPopupMenu().addSeparator();
        JMenuItem lookAndFeelInfoItem = new JMenuItem("Look and feel Info");
        lookAndFeelInfoItem.addActionListener(
            new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                LOGGER.info(UIManager.getLookAndFeel());
              }
            });
        mainChartPanel.getPopupMenu().add(lookAndFeelInfoItem);

        mainChartPanel.addMouseListener(
            new ClickListener() {

              @Override
              public void singleClick(final MouseEvent event) {

                Display.getDefault()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            Boolean isSlidingArea =
                                getMainChartWraper()
                                    .isSlidingArea(
                                        mainChartComposite.getSize().y, event.getPoint().y);
                            if (isSlidingArea) return;

                            int button = event.getButton();
                            if (button == MouseEvent.BUTTON1) {
                              Point2D clickPoint =
                                  mainChartPanel.translateScreenToJava2D(event.getPoint());
                              Rectangle2D plotArea = mainChartPanel.getScreenDataArea();

                              if (plotArea.getMaxY() > clickPoint.getY()
                                  && clickPoint.getY() > plotArea.getY()
                                  && plotArea.getMaxX() > clickPoint.getX()
                                  && clickPoint.getX() > plotArea.getX()) {
                                chartDisplayStrategy.addVLineAt(clickPoint, plotArea);
                              }
                            }
                          }
                        });
              }

              @Override
              public void doubleClick(final MouseEvent event) {

                Display.getDefault()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            Boolean isSlidingArea =
                                getMainChartWraper()
                                    .isSlidingArea(
                                        mainChartComposite.getSize().y, event.getPoint().y);
                            if (isSlidingArea) return;

                            int button = event.getButton();
                            if (button == MouseEvent.BUTTON1) {
                              Point2D clickPoint = getPointCoordinates(event.getPoint());
                              Rectangle2D plotArea = mainChartPanel.getScreenDataArea();

                              if (plotArea.getMaxY() > clickPoint.getY()
                                  && clickPoint.getY() > plotArea.getY()
                                  && plotArea.getMaxX() > clickPoint.getX()
                                  && clickPoint.getX() > plotArea.getX()) {
                                chartDisplayStrategy.removeVLineAt(clickPoint, plotArea);
                                chartDisplayStrategy.removeHLineAt(clickPoint, plotArea);
                              }
                            }
                          }
                        });
              }
            });

        // Slider
        chartPanelFocusGain = false;
        mainChartPanel.addMouseListener(
            new MouseAdapter() {

              @Override
              public void mouseEntered(MouseEvent e) {
                chartPanelFocusGain = true;
              }

              @Override
              public void mouseExited(MouseEvent e) {
                chartPanelFocusGain = false;
              }

              @Override
              public void mousePressed(final MouseEvent e) {
                panelClickPosition = e.getPoint();
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            Boolean isSlidingArea =
                                getMainChartWraper()
                                    .isSlidingArea(mainChartComposite.getSize().y, e.getPoint().y);
                            if (isSlidingArea) {
                              isInPanelChartSlider = true;
                            } else {
                              isInPanelChartSlider = false;
                            }
                          }
                        });
              }

              @Override
              public void mouseReleased(final MouseEvent e) {
                Display.getDefault()
                    .asyncExec(
                        new Runnable() {

                          @Override
                          public void run() {
                            if (isInPanelChartSlider != null
                                && isInPanelChartSlider
                                && panelClickPosition != null) {
                              int indicChartSlideIncrement =
                                  (int)
                                      ((((double) panelClickPosition.y - e.getPoint().y)
                                              / (double) mainChartComposite.getSize().y)
                                          * 100);
                              chartDisplayStrategy.slideChart(indicChartSlideIncrement);
                            }
                            isInPanelChartSlider = false;
                          }
                        });
              }
            });

        // focus bizz (useful?)
        mainChartPanel.addMouseMotionListener(
            new MouseMotionListener() {

              @Override
              public void mouseMoved(final MouseEvent e) {

                // Sliding
                if (!closeRequested) {
                  Display.getDefault()
                      .asyncExec(
                          new Runnable() {

                            @Override
                            public void run() {

                              if (!closeRequested) {
                                try {
                                  Cursor cursor = ChartsComposite.this.getCursor();
                                  if (cursor == null
                                      || (!cursor.equals(CursorFactory.getCursor(SWT.CURSOR_WAIT))
                                          && !cursor.equals(
                                              CursorFactory.getCursor(SWT.CURSOR_APPSTARTING)))) {
                                    Boolean isSlidingArea =
                                        getMainChartWraper()
                                            .isSlidingArea(
                                                mainChartComposite.getSize().y, e.getPoint().y);
                                    if (isSlidingArea) {
                                      ChartsComposite.this.setCursor(
                                          CursorFactory.getCursor(SWT.CURSOR_SIZENS));
                                    } else {
                                      ChartsComposite.this.setCursor(
                                          CursorFactory.getCursor(SWT.CURSOR_ARROW));
                                    }
                                  }

                                } catch (Throwable e) {
                                  try {
                                    ChartsComposite.this.setCursor(
                                        CursorFactory.getCursor(SWT.CURSOR_ARROW));
                                  } catch (Throwable e1) {
                                    LOGGER.warn(e1, e1);
                                  }
                                  LOGGER.warn(e, e);
                                }
                              }
                            }
                          });
                }

                // Gain focus mgt
                if (!closeRequested) {
                  Display.getDefault()
                      .asyncExec(
                          new Runnable() {
                            public void run() {
                              try {
                                if (!closeRequested) {
                                  if (!mainChartComposite.isDisposed()
                                      && !mainChartComposite.isFocusControl()) {
                                    int cpt = 0;
                                    while (chartPanelFocusGain && cpt < 200) {
                                      Thread.sleep(10);
                                      cpt++;
                                    }
                                    if (chartPanelFocusGain && !mainChartComposite.isDisposed()) {
                                      mainChartComposite.forceFocus();
                                    }
                                  }
                                }
                              } catch (Throwable e) {
                                LOGGER.warn(e, e);
                              }
                            }
                          });
                }
              }

              @Override
              public void mouseDragged(MouseEvent e) {
                // Nothing
              }
            });

        mainChartComposite.addKeyListener(
            new org.eclipse.swt.events.KeyListener() {

              @Override
              public void keyReleased(org.eclipse.swt.events.KeyEvent e) {
                if (((e.stateMask & SWT.CTRL) == SWT.CTRL)
                    && ((e.stateMask & SWT.ALT) == SWT.ALT)
                    && (e.keyCode == 'p')) {
                  try {
                    chartDisplayStrategy.exportBarChartPng();
                  } catch (InvalidParameterException exception) {
                    chartDisplayStrategy.showPopupDialog(exception.getMessage(), "Ok", null, null);
                  }
                }
                if (e.keyCode == SWT.ARROW_UP) {
                  chartDisplayStrategy.slideChart(+1);
                }
                if (e.keyCode == SWT.ARROW_DOWN) {
                  chartDisplayStrategy.slideChart(-1);
                }
              }

              @Override
              public void keyPressed(org.eclipse.swt.events.KeyEvent e) {
                //
              }
            });

        mainChartComposite.addMouseTrackListener(
            new MouseTrackListener() {

              @Override
              public void mouseHover(org.eclipse.swt.events.MouseEvent e) {}

              @Override
              public void mouseExit(org.eclipse.swt.events.MouseEvent e) {}

              @Override
              public void mouseEnter(org.eclipse.swt.events.MouseEvent e) {
                mainChartPanel.requestFocusInWindow();
              }
            });

        rootHeavyPanel.add(mainChartPanel);
        chartFrame.pack();
        chartFrame.setVisible(true);
      }
      {
        chartBoutonsGroup = new Group(this, SWT.NONE);
        chartBoutonsGroup.setBackground(innerBgColor);
        GridLayout portfolioBoutonsGroupLayout = new GridLayout();
        portfolioBoutonsGroupLayout.numColumns = 1;
        portfolioBoutonsGroupLayout.verticalSpacing = 0;
        portfolioBoutonsGroupLayout.marginHeight = 0;
        chartBoutonsGroup.setLayout(portfolioBoutonsGroupLayout);
        GridData portfolioInfosGroupData = new GridData(GridData.FILL_HORIZONTAL);
        chartBoutonsGroup.setLayoutData(portfolioInfosGroupData);

        chartBoutonsGroup.setText("Portfolios charting : ");
        chartBoutonsGroup.setFont(MainGui.DEFAULTFONT);
        chartBoutonsGroup.setBackground(innerBgColor);

        {
          popusGroup = new Group(chartBoutonsGroup, SWT.NONE);
          GridData popusGroupData = new GridData(SWT.FILL, SWT.FILL, true, false);
          popusGroup.setLayoutData(popusGroupData);
          popusGroup.setBackground(innerBgColor);
          RowLayout popusGroupL = new RowLayout(SWT.HORIZONTAL);
          popusGroupL.justify = true;
          popusGroupL.fill = true;
          popusGroupL.wrap = false;
          popusGroupL.marginHeight = 0;
          popusGroup.setLayout(popusGroupL);
        }

        // Sliding
        {
          slidingGroup = new Group(chartBoutonsGroup, SWT.NONE);
          GridData slidingGroupData = new GridData(SWT.FILL, SWT.FILL, true, false);
          slidingGroup.setLayoutData(slidingGroupData);
          slidingGroup.setBackground(innerBgColor);
          GridLayout slidingGroupL = new GridLayout();
          slidingGroupL.numColumns = 5;
          slidingGroupL.marginHeight = 0;
          slidingGroupL.verticalSpacing = 0;
          slidingGroup.setLayout(slidingGroupL);
          /// start
          {
            startDateLabel = new Label(slidingGroup, SWT.NONE);
            GridData startOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, false);
            startOneYearBackData.horizontalSpan = 2;
            startDateLabel.setLayoutData(startOneYearBackData);
            startDateLabel.setText(
                DateFormat.getDateInstance(DateFormat.MEDIUM).format(slidingStartDate) + "");
            startDateLabel.setBackground(innerBgColor);
            startDateLabel.setFont(MainGui.DEFAULTFONT);
          }
          /// sliding sliders
          Composite slidingSliderGroup = new Composite(slidingGroup, SWT.NONE);
          slidingSliderGroup.setSize(1000, SWT.DEFAULT);
          GridData slidersGridData = new GridData(SWT.FILL, SWT.FILL, true, true);
          slidersGridData.verticalSpan = 2;
          slidingSliderGroup.setLayoutData(slidersGridData);
          slidingSliderGroup.setBackground(innerBgColor);
          slidingSliderGroup.setForeground(innerBgColor);
          FillLayout slidingSliderGroupL = new FillLayout(SWT.VERTICAL);
          slidingSliderGroup.setLayout(slidingSliderGroupL);
          {
            sliderStartDate = new Slider(slidingSliderGroup, SWT.HORIZONTAL);
            sliderStartDate.setThumb(1);
            sliderStartDate.setMaximum(100);
            sliderStartDate.addListener(
                SWT.MouseExit,
                new Listener() {

                  public void handleEvent(Event arg0) {
                    sliderChangesApply();
                  }
                });
          }
          {
            sliderEndDate = new Slider(slidingSliderGroup, SWT.HORIZONTAL);
            sliderEndDate.setThumb(1);
            sliderEndDate.setMinimum(0);
            sliderEndDate.setSelection(100);
            sliderEndDate.addListener(
                SWT.MouseExit,
                new Listener() {

                  public void handleEvent(Event arg0) {
                    sliderChangesApply();
                  }
                });
          }
          // end
          {
            endDateLabel = new Label(slidingGroup, SWT.NONE);
            GridData endOneYearBackData = new GridData(SWT.END, SWT.FILL, false, false);
            endOneYearBackData.horizontalSpan = 2;
            endDateLabel.setLayoutData(endOneYearBackData);
            endDateLabel.setText(
                DateFormat.getDateInstance(DateFormat.MEDIUM).format(slidingEndDate));
            endDateLabel.setBackground(innerBgColor);
            endDateLabel.setFont(MainGui.DEFAULTFONT);
          }

          // but start
          {
            Button startOneYearBack = new Button(slidingGroup, SWT.ARROW | SWT.LEFT);
            GridData startOneYearBackData = new GridData(SWT.END, SWT.FILL, false, true);
            startOneYearBack.setLayoutData(startOneYearBackData);
            startOneYearBack.setToolTipText("Move start date one year backward.");
            startOneYearBack.addSelectionListener(
                new SelectionListener() {

                  @Override
                  public void widgetSelected(SelectionEvent e) {
                    handle();
                  }

                  private void handle() {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(slidingStartDate);
                    calendar.add(Calendar.YEAR, -1);
                    firstStartDate = calendar.getTime();
                    sliderStartDate.setSelection(0);
                    startSliderUpdateConditional(
                        sliderStartDate, startDateLabel, sliderEndDate, endDateLabel);
                  }

                  @Override
                  public void widgetDefaultSelected(SelectionEvent e) {
                    handle();
                  }
                });
            startOneYearBack.addListener(
                SWT.MouseExit,
                new Listener() {

                  @Override
                  public void handleEvent(Event event) {
                    sliderChangesApply();
                  }
                });
          }

          {
            Button startOneYearForward = new Button(slidingGroup, SWT.ARROW | SWT.RIGHT);
            GridData startOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, true);
            startOneYearForward.setLayoutData(startOneYearBackData);
            startOneYearForward.setToolTipText("Move start date one year forward.");
            startOneYearForward.addSelectionListener(
                new SelectionListener() {

                  @Override
                  public void widgetSelected(SelectionEvent e) {
                    handle();
                  }

                  private void handle() {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(slidingStartDate);
                    calendar.add(Calendar.YEAR, +1);
                    if (calendar.getTime().before(slidingEndDate)) {
                      firstStartDate = calendar.getTime();
                      sliderStartDate.setSelection(0);
                      startSliderUpdateConditional(
                          sliderStartDate, startDateLabel, sliderEndDate, endDateLabel);
                    } else {
                      chartDisplayStrategy.showPopupDialog(
                          "To move the start date further forward, you will need to move the end date first.",
                          "Ok",
                          null,
                          null);
                    }
                  }

                  @Override
                  public void widgetDefaultSelected(SelectionEvent e) {
                    handle();
                  }
                });
            startOneYearForward.addListener(
                SWT.MouseExit,
                new Listener() {

                  @Override
                  public void handleEvent(Event event) {
                    sliderChangesApply();
                  }
                });
          }
          /// but end

          {
            Button endOneYearBack = new Button(slidingGroup, SWT.ARROW | SWT.LEFT);
            GridData endOneYearBackData = new GridData(SWT.END, SWT.FILL, false, true);
            endOneYearBack.setLayoutData(endOneYearBackData);
            endOneYearBack.setToolTipText("Move end date one year backward.");
            endOneYearBack.addSelectionListener(
                new SelectionListener() {

                  @Override
                  public void widgetSelected(SelectionEvent e) {
                    handle();
                  }

                  private void handle() {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(slidingEndDate);
                    calendar.add(Calendar.YEAR, -1);
                    if (calendar.getTime().after(slidingStartDate)) {
                      lastEndDate = calendar.getTime();
                      sliderEndDate.setSelection(100);
                      endSliderUpdateConditional(
                          sliderEndDate, endDateLabel, sliderStartDate, startDateLabel);
                    } else {
                      chartDisplayStrategy.showPopupDialog(
                          "To move the end date further backward, you will need to move the start date first.",
                          "Ok",
                          null,
                          null);
                    }
                  }

                  @Override
                  public void widgetDefaultSelected(SelectionEvent e) {
                    handle();
                  }
                });
            endOneYearBack.addListener(
                SWT.MouseExit,
                new Listener() {

                  @Override
                  public void handleEvent(Event event) {
                    sliderChangesApply();
                  }
                });
          }
          {
            Button endOneYearForward = new Button(slidingGroup, SWT.ARROW | SWT.RIGHT);
            GridData endOneYearBackData = new GridData(SWT.BEGINNING, SWT.FILL, false, true);
            endOneYearForward.setLayoutData(endOneYearBackData);
            endOneYearForward.setToolTipText("Move end date one year forward.");
            endOneYearForward.addSelectionListener(
                new SelectionListener() {

                  @Override
                  public void widgetSelected(SelectionEvent e) {
                    handle();
                  }

                  private void handle() {
                    Calendar calendar = Calendar.getInstance();
                    calendar.setTime(slidingEndDate);
                    calendar.add(Calendar.YEAR, +1);
                    Date newDate = EventSignalConfig.getNewDate();
                    if (calendar.getTime().after(newDate)) {
                      calendar.setTime(newDate);
                    }
                    lastEndDate = calendar.getTime();
                    sliderEndDate.setSelection(100);
                    endSliderUpdateConditional(
                        sliderEndDate, endDateLabel, sliderStartDate, startDateLabel);
                  }

                  @Override
                  public void widgetDefaultSelected(SelectionEvent e) {
                    handle();
                  }
                });
            endOneYearForward.addListener(
                SWT.MouseExit,
                new Listener() {

                  @Override
                  public void handleEvent(Event event) {
                    sliderChangesApply();
                  }
                });
          }

          sliderStartDate.addListener(
              SWT.Selection,
              new Listener() {
                public void handleEvent(Event event) {
                  startSliderUpdateConditional(
                      sliderStartDate, startDateLabel, sliderEndDate, endDateLabel);
                }
              });

          sliderEndDate.addListener(
              SWT.Selection,
              new Listener() {

                public void handleEvent(Event event) {
                  endSliderUpdateConditional(
                      sliderEndDate, endDateLabel, sliderStartDate, startDateLabel);
                }
              });

          slidingGroup.layout();
        }
      }

      this.layout();
      this.pack();

    } catch (Exception e) {
      LOGGER.error("", e);
    }
  }
Esempio n. 10
0
  @SuppressWarnings("unchecked")
  private BalloonWindow(Display display, Shell parent, final int style) {
    this.style = style;
    int shellStyle = style & (SWT.ON_TOP | SWT.TOOL);
    this.shell =
        (display != null)
            ? new Shell(display, SWT.NO_TRIM | shellStyle)
            : new Shell(parent, SWT.NO_TRIM | shellStyle);
    this.contents = new Composite(shell, SWT.NONE);

    final Color c = new Color(shell.getDisplay(), 255, 255, 225);
    shell.setBackground(c);
    shell.setForeground(shell.getDisplay().getSystemColor(SWT.COLOR_BLACK));
    contents.setBackground(shell.getBackground());
    contents.setForeground(shell.getForeground());

    selectionControls.add(shell);
    selectionControls.add(contents);

    final Listener globalListener =
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            Widget w = event.widget;
            for (int i = selectionControls.size() - 1; i >= 0; i--) {
              if (selectionControls.get(i) == w) {
                if ((style & SWT.CLOSE) != 0) {
                  for (int j = selectionListeners.size() - 1; j >= 0; j--)
                    ((Listener) selectionListeners.get(j)).handleEvent(event);
                } else {
                  shell.close();
                }
                event.doit = false;
              }
            }
          }
        };

    shell.addListener(
        SWT.Show,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (!addedGlobalListener) {
              shell.getDisplay().addFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = true;
            }
          }
        });

    shell.addListener(
        SWT.Hide,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (addedGlobalListener) {
              shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = false;
            }
          }
        });

    shell.addListener(
        SWT.Dispose,
        new Listener() {
          @Override
          public void handleEvent(Event event) {
            if (addedGlobalListener) {
              shell.getDisplay().removeFilter(SWT.MouseDown, globalListener);
              addedGlobalListener = false;
            }
            c.dispose();
          }
        });
  }
  /**
   * 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);
  }
Esempio n. 12
0
  private void createErrorControl(Composite parent) {
    Color bgColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_BACKGROUND);
    Color fgColor = parent.getDisplay().getSystemColor(SWT.COLOR_LIST_FOREGROUND);

    parent.setBackground(bgColor);
    parent.setForeground(fgColor);

    GridLayout layout = new GridLayout();

    layout.numColumns = 3;

    int spacing = 8;
    int margins = 8;
    layout.marginBottom = margins;
    layout.marginTop = margins;
    layout.marginLeft = margins;
    layout.marginRight = margins;
    layout.horizontalSpacing = spacing;
    layout.verticalSpacing = spacing;
    parent.setLayout(layout);

    Label imageLabel = new Label(parent, SWT.NONE);
    imageLabel.setBackground(bgColor);
    Image image = getImage();
    if (image != null) {
      image.setBackground(bgColor);
      imageLabel.setImage(image);
      imageLabel.setLayoutData(
          new GridData(GridData.HORIZONTAL_ALIGN_CENTER | GridData.VERTICAL_ALIGN_BEGINNING));
    }

    Text text = new Text(parent, SWT.MULTI | SWT.READ_ONLY | SWT.WRAP);
    text.setBackground(bgColor);
    text.setForeground(fgColor);

    // text.setForeground(JFaceColors.getErrorText(text.getDisplay()));
    text.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false));
    text.setText(Messages.getString("ReportDocumentEditor.errorMessage")); // $NON-NLS-1$

    detailsButton = new Button(parent, SWT.PUSH);
    detailsButton.addSelectionListener(
        new SelectionAdapter() {

          public void widgetSelected(SelectionEvent e) {
            showDetails(!showingDetails);
          }
        });

    detailsButton.setLayoutData(new GridData(SWT.BEGINNING, SWT.CENTER, false, false));
    detailsButton.setVisible(e != null);

    updateDetailsText();

    detailsArea = new Composite(parent, SWT.NONE);
    detailsArea.setBackground(bgColor);
    detailsArea.setForeground(fgColor);
    GridData data = new GridData(GridData.FILL_BOTH);
    data.horizontalSpan = 3;
    data.verticalSpan = 1;
    detailsArea.setLayoutData(data);
    detailsArea.setLayout(new FillLayout());
    parent.layout(true);
  }
  private Composite fillInWorkArea(Composite workArea) {
    if (workArea.isDisposed()) System.err.println("fillInWorkArea:  workArea is disposed!!!");
    GridLayout workLayout = new GridLayout();
    workLayout.marginHeight = 0;
    workLayout.marginWidth = 0;
    workLayout.verticalSpacing = 0;
    workLayout.horizontalSpacing = 0;
    workArea.setLayout(workLayout);
    workArea.setLayoutData(new GridData(GridData.FILL_BOTH));

    // page group
    Color background = JFaceColors.getBannerBackground(parent.getDisplay());
    Color foreground = JFaceColors.getBannerForeground(parent.getDisplay());
    Composite top = (Composite) super.createDialogArea(workArea);

    // override any layout inherited from createDialogArea
    GridLayout layout = new GridLayout();
    layout.marginHeight = 0;
    layout.marginWidth = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    top.setLayout(layout);
    top.setLayoutData(new GridData(GridData.FILL_BOTH));
    top.setBackground(background);
    top.setForeground(foreground);

    // the image & text
    Composite topContainer = new Composite(top, SWT.NONE);
    topContainer.setBackground(background);
    topContainer.setForeground(foreground);

    layout = new GridLayout();
    layout.numColumns = (1);
    layout.marginWidth = 0;
    layout.marginHeight = 0;
    layout.verticalSpacing = 0;
    layout.horizontalSpacing = 0;
    topContainer.setLayout(layout);
    GridData data = new GridData();
    data.horizontalAlignment = GridData.FILL;
    data.grabExcessHorizontalSpace = true;
    topContainer.setLayoutData(data);

    String levelString = null;
    if (field.getPreferencesLevel() == null) {
      levelString = "Details as currently applicable";
      if (preferencesService.getProject() != null) {
        levelString += " (including project preferences):  ";
      } else {
        levelString += " (not including any project preferences):  ";
      }
    } else if (field.getPreferencesLevel().equals(IPreferencesService.INSTANCE_LEVEL))
      levelString = PreferenceDialogConstants.INSTANCE_LEVEL_STRING;
    else if (field.getPreferencesLevel().equals(IPreferencesService.CONFIGURATION_LEVEL))
      levelString = PreferenceDialogConstants.CONFIGURATION_LEVEL_STRING;
    else if (field.getPreferencesLevel().equals(IPreferencesService.DEFAULT_LEVEL))
      levelString = PreferenceDialogConstants.DEFAULT_LEVEL_STRING;
    else if (field.getPreferencesLevel().equals(IPreferencesService.PROJECT_LEVEL))
      levelString = PreferenceDialogConstants.PROJECT_LEVEL_STRING;
    else levelString = PreferenceDialogConstants.UNKNOWN_LEVEL_STRING + field.getPreferencesLevel();

    Label label = null;

    label = new Label(topContainer, SWT.LEAD);
    label.setText(levelString);
    label.setBackground(PreferencesUtilities.colorWhite);

    label = new Label(topContainer, SWT.LEAD);
    label.setText("\tCurrent value:  '" + field.getStringValue() + "'");
    label.setBackground(PreferencesUtilities.colorWhite);

    label = new Label(topContainer, SWT.LEAD);
    String level = PreferenceDialogConstants.getLevelName(field.getLevelFromWhichLoaded());
    label.setText("\tLevel at which set:  " + level);
    label.setBackground(PreferencesUtilities.colorWhite);

    label = new Label(topContainer, SWT.LEAD);
    //	        if (field.isEmptyStringAllowed()) {
    //		        label.setText(PreferenceDialogConstants.EMPTY_OK	);
    //	        } else {
    //		        label.setText(PreferenceDialogConstants.EMPTY_NOT_OK);
    //	        }
    label.setBackground(PreferencesUtilities.colorWhite);

    if ((field.getPreferencesLevel() != null)
        && field.getPreferencesLevel().equals(field.getLevelFromWhichLoaded())) {
      label = new Label(topContainer, SWT.LEAD);
      if (field.isRemovable()) {
        label.setText(PreferenceDialogConstants.IS_REMOVABLE);
      } else {
        label.setText(PreferenceDialogConstants.NOT_REMOVABLE);
      }
    }
    label.setBackground(PreferencesUtilities.colorWhite);

    label = new Label(top, SWT.LEAD);
    label.setText("~~~");
    label.setVisible(false);

    this.workArea = workArea;
    return workArea;
  }