예제 #1
0
  @Override
  public void createPartControl(Composite parent) {
    // TODO read (positioning):
    // http://www.eclipse.org/articles/using-perspectives/PerspectiveArticle.html
    composite = new Composite(parent, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(composite);
    this.mainPanel = new javax.swing.JPanel();
    this.mainPanel.setLayout(new BorderLayout());
    this.viewPanel = new JPanel(new BorderLayout());

    // Control Panel
    this.controlPanel = new JPanel(new FlowLayout());
    // this.controlPanel.add(this.cbCFOnly);
    // this.controlPanel.add(this.exportEPMLBtn);
    this.controlPanel.add(this.refreshBtn);
    // this.cbCFOnly.addActionListener(this);
    // this.exportEPMLBtn.addActionListener(this);
    this.refreshBtn.addActionListener(this);

    // main Panel
    // mainPanel.add(this.controlPanel, BorderLayout.NORTH);
    mainPanel.add(this.viewPanel, BorderLayout.CENTER);
    mainPanel.add(this.errorLabel, BorderLayout.SOUTH);
    frame.add(mainPanel);
  }
예제 #2
0
  public static void main(String[] args) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setText("SWT and Swing DND Example");
    GridLayout layout = new GridLayout(1, false);
    shell.setLayout(layout);

    Text swtText = new Text(shell, SWT.BORDER);
    swtText.setText("SWT Text");
    GridData data = new GridData(GridData.FILL_HORIZONTAL);
    swtText.setLayoutData(data);
    setDragDrop(swtText);

    Composite comp = new Composite(shell, SWT.EMBEDDED);
    java.awt.Frame frame = SWT_AWT.new_Frame(comp);
    JTextField swingText = new JTextField(40);
    swingText.setText("Swing Text");
    swingText.setDragEnabled(true);
    frame.add(swingText);
    data = new GridData(GridData.FILL_HORIZONTAL);
    data.heightHint = swingText.getPreferredSize().height;
    comp.setLayoutData(data);

    shell.setSize(400, 200);
    shell.open();
    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }
    display.dispose();
  }
예제 #3
0
  public static void view(DrawModel d) {
    final Display display = new Display();
    final Shell shell = new Shell(display);
    shell.setLayout(new FillLayout());

    Composite composite = new Composite(shell, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    Frame baseFrame = SWT_AWT.new_Frame(composite);

    baseFrame.setBounds(0, 0, 800, 600);

    Java3DViewer viewer = new Java3DViewer(baseFrame, d);
    baseFrame.add(viewer);

    shell.open();

    d.setFaceColor(Color.GREEN);
    d.circle(0.9);
    //		viewer.draw(d);

    while (!shell.isDisposed()) {
      if (!display.readAndDispatch()) display.sleep();
    }

    baseFrame.dispose();
    shell.dispose();
    composite.dispose();
    display.dispose();
    System.exit(0);
  }
예제 #4
0
  /**
   * Creates a new SWT {@link Composite} with this <code>ViewAppState</code> embedded within it.
   * This method gets an {@link VizEmbeddedView} from the {@link MasterApplication}, connects with
   * that view, and embeds that view in the <code>Composite</code>.
   *
   * @param parent The parent <code>Composite</code>.
   * @return The <code>Composite</code> that has an embedded jME view managed by this <code>
   *     ViewAppState</code>. This <code>Composite</code>'s layout should be set by the caller.
   *     <b>This <code>Composite</code> should be disposed when it is no longer required</b>.
   */
  public Composite createComposite(Composite parent) {

    // Set the default return value and check the parameter.
    Composite composite = null;
    if (parent != null && embeddedView == null) {

      // Get an EmbeddedView that uses the app for rendering.
      embeddedView = app.getEmbeddedView();

      // Create the embedded Composite. When it is disposed, the
      // associated EmbeddedView should be released.
      composite =
          new Composite(parent, SWT.EMBEDDED) {
            @Override
            public void dispose() {
              // Dispose of resources tied with this specific view.
              disposeView(embeddedView);
              super.dispose();
            }
          };
      // Create the AWT frame inside the SWT.EMBEDDED Composite.
      Frame embeddedFrame = SWT_AWT.new_Frame(composite);
      // Add the AwtPanel to the embedded AWT Frame. The panel needs to
      // fill the Frame.
      embeddedFrame.setLayout(new BorderLayout());
      // Attach the EmbeddedView to the embedded Frame.
      embeddedView.addToEmbeddedFrame(embeddedFrame);
      embeddedFrame.pack();
      embeddedFrame.setVisible(true);

      // Wait for a maximum of 5 seconds if the view has not been
      // initialized yet. The ViewAppState must be initialized!!!
      int limit = 5000;
      int count = 0;
      while (!isInitialized() && count < limit) {
        try {
          Thread.sleep(50);
          count += 50;
        } catch (InterruptedException e) {
          logger.error(getClass().getName() + " Exception!", e);
        }
      }

      // Register with the EmbeddedView.
      embeddedView.registerViewClient(this);

      // Make sure the controls are enabled.
      enableControls();
    }

    return composite;
  }
  /**
   * This method generates the dependency graph and sets an {@link EditorPart} to show the graph's
   * window.
   */
  @Override
  public void createPartControl(final Composite parent) {
    initGeneratorAndHandler(parent);
    editorComposite = new Composite(parent, SWT.NO_BACKGROUND | SWT.EMBEDDED);
    window = SWT_AWT.new_Frame(editorComposite);
    windowSize = new Dimension(parent.getSize().x, parent.getSize().y);

    parent.addListener(
        SWT.Resize,
        new Listener() {
          @Override
          public void handleEvent(org.eclipse.swt.widgets.Event event) {
            Point tmpSize = parent.getSize();
            windowSize = new Dimension(tmpSize.x, tmpSize.y);
            if (handler != null) {
              handler.changeWindowSize(windowSize);
            }
            if (window != null && drawArea != null) {
              drawArea.setPreferredSize(windowSize);
              window.setPreferredSize(windowSize);
              window.repaint();
            }
          }
        });

    project = ((IFileEditorInput) getEditorInput()).getFile().getProject();
    setPartName(getPartName() + " - " + project.getName());

    // get a reference to the satellite viewer
    satView =
        (SatelliteView)
            PlatformUI.getWorkbench()
                .getActiveWorkbenchWindow()
                .getActivePage()
                .findView(SatelliteView.ID);
    if (satView != null) {
      satView.setEditor(this);
    } else {
      try {
        satView =
            (SatelliteView)
                PlatformUI.getWorkbench()
                    .getActiveWorkbenchWindow()
                    .getActivePage()
                    .showView(SatelliteView.ID);
        satView.setEditor(this);
      } catch (PartInitException e) {
        errorHandler.reportException("Error while opening the view", e);
      }
    }
    initWindow();
  }
  @Override
  public void createPartControl(Composite parent) {
    ListenerStore.addListener(this);
    plate = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    frame = SWT_AWT.new_Frame(plate);
    frame.setLayout(new java.awt.GridLayout(1, 1));
    // panel = new JPanel();

    tabbedPane = new JTabbedPane();
    tabbedPane.setTabPlacement(JTabbedPane.LEFT);

    frame.add(tabbedPane);
  }
예제 #7
0
  @Override
  public void createPartControl(Composite parent) {
    laf = new SynthLookAndFeel();

    try {
      laf.load(SynthResources.class.getResourceAsStream("laf.xml"), SynthResources.class);
      UIManager.setLookAndFeel(laf);
    } catch (ParseException e) {
      e.printStackTrace();
    } catch (UnsupportedLookAndFeelException e) {
      e.printStackTrace();
    }

    Composite composite = new Composite(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    frame = SWT_AWT.new_Frame(composite);
    frame.setLayout(new FlowLayout());

    JLabel label = new JLabel("Label");
    JButton button = new JButton("Change");

    button.addActionListener(
        new ActionListener() {
          public void actionPerformed(java.awt.event.ActionEvent arg0) {
            lafIndex++;

            if (lafIndex == 2) {
              lafIndex = 0;
            }

            reloadLookAndFeel();
          }
        });

    frame.add(label);
    frame.add(button);
  }
예제 #8
0
  public void createPartControl(Composite parent) {
    listener =
        new WorkbenchWindowListener(
            new WorkbenchPageListener(
                new PartListener(new DropTemplateWorkflowModelEditorAction())));
    listener.register();

    FillLayout parentLayout = new FillLayout();
    parent.setLayout(parentLayout);
    SashForm sashForm = new SashForm(parent, SWT.HORIZONTAL);

    Tree tree = new Tree(sashForm, SWT.BORDER);
    tree.setLinesVisible(false);
    tree.setLayoutData(FormBuilder.createDefaultMultiLineWidgetGridData());
    Composite composite = FormBuilder.createComposite(sashForm, 1);
    Composite swingComposite = new Composite(composite, SWT.EMBEDDED);
    swingComposite.setLayoutData(FormBuilder.createDefaultMultiLineWidgetGridData());
    java.awt.Frame locationFrame = SWT_AWT.new_Frame(swingComposite);
    textPane = new JTextPane();
    JScrollPane scrollPane = new JScrollPane(textPane);
    locationFrame.add(scrollPane);
    textPane.setContentType("text/html"); // $NON-NLS-1$
    StyleSheet css = ((HTMLEditorKit) textPane.getEditorKit()).getStyleSheet();
    URL url = this.getClass().getResource("/html/carnot.css"); // $NON-NLS-1$
    css.importStyleSheet(url);
    textPane.setEditable(false);
    sashForm.setWeights(new int[] {1, 2});
    final TreeViewer viewer = new TreeViewer(tree);
    viewer.setContentProvider(new PatternsContentProvider());
    viewer.setLabelProvider(new PatternsLabelProvider());
    viewer.addSelectionChangedListener(
        new ISelectionChangedListener() {

          public void selectionChanged(SelectionChangedEvent event) {
            TreeSelection selection = (TreeSelection) event.getSelection();
            Object object = selection.getFirstElement();
            if (object instanceof ITemplate) {
              ITemplate template = (ITemplate) object;
              textPane.setEditorKit(new ExtendedHTMLEditorKit(template));
              textPane.setText(template.getDescription());
            } else {
              if (object instanceof ITemplateFactory) {
                ITemplateFactory templateFactory = (ITemplateFactory) object;
                textPane.setText(templateFactory.getDescription());
              }
            }
          }
        });

    viewer.addDragSupport(
        DND.DROP_COPY,
        new Transfer[] {LocalSelectionTransfer.getTransfer()},
        new DragSourceAdapter() {
          public void dragStart(DragSourceEvent event) {
            ISelection selection = viewer.getSelection();
            LocalSelectionTransfer.getTransfer().setSelection(selection);
            LocalSelectionTransfer.getTransfer().setSelectionSetTime(event.time & 0xFFFFFFFFL);
            event.doit = DropTemplateWorkflowModelEditorAction.isValidDndSelection(selection);
          }

          public void dragSetData(DragSourceEvent event) {
            event.data = LocalSelectionTransfer.getTransfer().getSelection();
          }

          public void dragFinished(DragSourceEvent event) {
            LocalSelectionTransfer.getTransfer().setSelection(null);
            LocalSelectionTransfer.getTransfer().setSelectionSetTime(0);
          }
        });

    // Add actions to the local tool bar
    IToolBarManager tbm = getViewSite().getActionBars().getToolBarManager();
    Action refreshAction =
        new Action(Diagram_Messages.LB_VersionRepository_Refresh) {
          public void run() {
            viewer.setInput(
                "org.eclipse.stardust.modeling.templates.templateProvider"); //$NON-NLS-1$
          }
        };
    tbm.add(refreshAction);

    refreshAction.run();
  }
예제 #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);
    }
  }
예제 #10
0
 public void createPartControl(Composite parent) {
   Composite composite = new Composite(parent, SWT.EMBEDDED);
   f = SWT_AWT.new_Frame(composite);
   JPanel jp = JungViewData.getPanel();
   f.add(jp);
 }
  /**
   * Create contents of the wizard.
   *
   * @param parent
   */
  public void createControl(Composite parent) {
    Composite container = new Composite(parent, SWT.NULL);

    setControl(container);
    container.setLayout(new GridLayout(3, false));

    Label label = new Label(container, SWT.NONE);
    label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    label.setText("代码保存路径");

    txtSavePath = new Text(container, SWT.BORDER);
    txtSavePath.setEditable(false);
    txtSavePath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    // 选择源码保存路径
    Button button = new Button(container, SWT.NONE);
    button.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent e) {
            // 选择路径
            ContainerSelectionDialog dialog =
                new ContainerSelectionDialog(
                    getShell(), ResourcesPlugin.getWorkspace().getRoot(), false, "请选择生成的源文件的存放目录");
            if (dialog.open() == ContainerSelectionDialog.OK) {
              Object[] result = dialog.getResult();
              if (result.length == 1) {
                txtSavePath.setText(((Path) result[0]).makeAbsolute().toString());
                validInput();
              }
            }
          }
        });
    button.setText("浏览...");

    Label label_1 = new Label(container, SWT.NONE);
    label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false, 1, 1));
    label_1.setText("模板文件路径");

    txtTempPath = new Text(container, SWT.BORDER);
    txtTempPath.setEditable(false);
    txtTempPath.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true, false, 1, 1));

    // 选择模板文件
    Button button_1 = new Button(container, SWT.NONE);
    button_1.addMouseListener(
        new MouseAdapter() {
          @Override
          public void mouseDown(MouseEvent e) {
            // 选择模板文件
            FileDialog fileDialog = new FileDialog(getShell());
            fileDialog.setFilterExtensions(new String[] {"*.xml", "*.*"});
            String filenameString = fileDialog.open();
            if (filenameString != null && filenameString.length() > 0) {
              txtTempPath.setText(filenameString);
            }
            // 加载模板配置文件内容
            loadTemplate(filenameString);
            validInput();
          }
        });
    button_1.setText("浏览...");

    Label label_2 = new Label(container, SWT.NONE);
    label_2.setText("模板明细列表");

    Composite composite = new Composite(container, SWT.EMBEDDED);
    composite.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 1, 1));

    Frame frame = SWT_AWT.new_Frame(composite);

    Panel panel = new Panel();
    frame.add(panel);
    panel.setLayout(new BorderLayout(0, 0));

    JRootPane rootPane = new JRootPane();
    panel.add(rootPane);

    JScrollPane scrollPane = new JScrollPane();
    rootPane.getContentPane().add(scrollPane, BorderLayout.CENTER);

    table = new JTable();
    table.setFillsViewportHeight(true);
    table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    table.setModel(tableModel);
    table.setRowHeight(25);
    scrollPane.setViewportView(table);
    new Label(container, SWT.NONE);

    // 是否生成 列表头设置
    final int isattributeIndex = 0; // 是否生成
    final JTableCheckBoxHeader isgenallcheck = new JTableCheckBoxHeader("是否生成");
    table.getColumnModel().getColumn(isattributeIndex).setHeaderRenderer(isgenallcheck);
    table.getColumnModel().getColumn(isattributeIndex).setPreferredWidth(50);
    table
        .getTableHeader()
        .addMouseListener(
            new java.awt.event.MouseAdapter() {
              public void mouseClicked(java.awt.event.MouseEvent e) {
                if (table.getColumnModel().getColumnIndexAtX(e.getX())
                    == isattributeIndex) { // 如果点击的是第0列,即checkbox这一列
                  @SuppressWarnings("unused")
                  JCheckBox Checkbox = (JCheckBox) isgenallcheck;
                  boolean b = !isgenallcheck.isSelected();
                  isgenallcheck.setSelected(b);
                  table.getTableHeader().repaint();
                  for (int i = 0; i < table.getRowCount(); i++) {
                    table.getModel().setValueAt(b, i, isattributeIndex); // 把这一列都设成和表头一样
                  }
                }
              }
            });

    // 加原来的配置
    ConfigUtil configUtil = new ConfigUtil();
    this.setTxtSavePath(configUtil.getSavePath());
    this.setTxtTempPath(configUtil.getTempPath());
    // 加载模板配置文件内容
    loadTemplate(this.getTxtTempPath());
    setPageComplete(false);
    validInput();
  }
예제 #12
0
  /** Create a new PagePanel, with a default size of 800 by 600 pixels. */
  @SuppressWarnings("serial")
  public PDFPageViewerAWT(Composite parent, PDFEditor editor) {
    // super(parent, SWT.NO_BACKGROUND|SWT.NO_REDRAW_RESIZE);
    super(parent, SWT.EMBEDDED | SWT.NO_BACKGROUND);
    this.editor = editor;
    this.setLayout(new FillLayout());
    // Seems to fix a deadlock in SWT_AWT.new_Frame
    while (Display.getDefault().readAndDispatch() == true) ;
    frame = SWT_AWT.new_Frame(this);
    final PDFEditor ed = editor;

    EventQueue.invokeLater(
        new Runnable() {

          @Override
          public void run() {
            canvas =
                new Canvas() {

                  @Override
                  public void update(Graphics g) {
                    paint(g);
                  };

                  @Override
                  public void paint(Graphics g) {
                    Dimension sz = getSize();
                    if (currentImage == null) {
                      g.setColor(getBackground());
                      g.fillRect(0, 0, sz.width, sz.height);
                      g.setColor(Color.BLACK);
                      g.drawString("No page selected", sz.width / 2 - 30, sz.height / 2);

                    } else {
                      // draw the image

                      g.drawImage(currentImage, 0, 0, null);

                      List<PDFAnnotation> anno =
                          currentPage.getAnnots(PDFAnnotation.LINK_ANNOTATION);
                      g.setColor(Color.RED);
                      for (PDFAnnotation a : anno) {
                        Rectangle2D r = convertPDF2ImageCoord(a.getRect());
                        g.drawRect(
                            (int) Math.round(r.getX()),
                            (int) Math.round(r.getY()),
                            (int) Math.round(r.getWidth()),
                            (int) Math.round(r.getHeight()));
                      }

                      // Draw highlight frame
                      if (highlight != null) {
                        g.setColor(Color.BLUE);
                        g.drawRect(
                            (int) Math.round(highlight.getX()),
                            (int) Math.round(highlight.getY()),
                            (int) Math.round(highlight.getWidth()),
                            (int) Math.round(highlight.getHeight()));
                      }
                    }
                  }
                };
            // canvas.setIgnoreRepaint(true);
            canvas.enableInputMethods(false);
            // Beware: This seem to be necessary to enable MouseWheel scrolling
            // on some systems. A riddle though.
            canvas.addMouseWheelListener(
                new MouseWheelListener() {

                  @Override
                  public void mouseWheelMoved(MouseWheelEvent e) {
                    // System.out.println("Scroll");
                  }
                });
            canvas.addMouseListener(
                new MouseAdapter() {

                  @Override
                  public void mouseClicked(final MouseEvent e) {
                    if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 1) {
                      List<PDFAnnotation> annos =
                          getPage().getAnnots(PDFAnnotation.LINK_ANNOTATION);
                      for (PDFAnnotation a : annos) {
                        LinkAnnotation aa = (LinkAnnotation) a;
                        Rectangle2D r = convertPDF2ImageCoord(aa.getRect());
                        if (r.contains(e.getX(), e.getY())) {
                          if (aa.getAction() instanceof GoToAction) {
                            final GoToAction action = (GoToAction) aa.getAction();

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

                                      @Override
                                      public void run() {
                                        ed.gotoAction(action.getDestination());
                                      }
                                    });
                            return;
                          }
                        }
                      }
                    }
                    if (e.getButton() == MouseEvent.BUTTON1 && e.getClickCount() == 2) {
                      final Rectangle2D r =
                          convertImage2PDFCoord(new java.awt.Rectangle(e.getX(), e.getY(), 1, 1));

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

                                @Override
                                public void run() {
                                  ed.reverseSearch(r.getX(), currentPage.getHeight() - r.getY());
                                }
                              });
                    }
                  }
                });
            frame.add(canvas);
            frame.enableInputMethods(false);
            frame.setFocusable(false);
            frame.setIgnoreRepaint(true);
          }
        });

    // setSize(800, 600);
    zoomFactor = 1.f;
  }