Search in sources :

Example 1 with Slider

use of org.eclipse.swt.widgets.Slider in project translationstudio8 by heartsome.

the class XLFEditor method createEditorPart.

/**
	 * 创建编辑器组件。
	 */
private void createEditorPart(Composite parent) {
    bottomComposite = new Composite(parent, SWT.BORDER);
    GridLayout glBottomCmp = new GridLayout(2, false);
    glBottomCmp.marginHeight = HEIGHT_SPACE;
    glBottomCmp.marginWidth = WIDTH_SPACE;
    glBottomCmp.horizontalSpacing = 0;
    glBottomCmp.verticalSpacing = 0;
    bottomComposite.setLayout(glBottomCmp);
    bottomComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    // 左上方,第一行,第一列,即表头容器
    colHeaderComposite = new Composite(bottomComposite, SWT.NONE);
    colHeaderComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
    createTableHeader(colHeaderComposite);
    // 右方,第二列,占两行。
    editorVBar = new Slider(bottomComposite, SWT.V_SCROLL | SWT.BORDER);
    GridData gdVBar = new GridData(GridData.FILL_VERTICAL);
    // 合并两行,使之占满整个自定义表格位置。
    gdVBar.verticalSpan = 2;
    editorVBar.setLayoutData(gdVBar);
    // 左下方,第二行,第一列,编辑器容器
    oScrolledComposite = new ScrolledComposite(bottomComposite, SWT.H_SCROLL);
    GridLayout glScrolledComposite = new GridLayout(1, false);
    glScrolledComposite.horizontalSpacing = 0;
    glScrolledComposite.verticalSpacing = 0;
    glScrolledComposite.marginHeight = 0;
    glScrolledComposite.marginWidth = 0;
    oScrolledComposite.setLayout(glScrolledComposite);
    oScrolledComposite.setExpandHorizontal(true);
    oScrolledComposite.setExpandVertical(true);
    oScrolledComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    editorContentComposite = new Composite(oScrolledComposite, SWT.NONE);
    GridLayout glEditorContentComposite = new GridLayout(1, true);
    glEditorContentComposite.horizontalSpacing = 0;
    glEditorContentComposite.verticalSpacing = 0;
    glEditorContentComposite.marginHeight = 0;
    glEditorContentComposite.marginWidth = 0;
    editorContentComposite.setLayout(glEditorContentComposite);
    editorContentComposite.setLayoutData(new GridData(GridData.FILL_BOTH));
    oScrolledComposite.setContent(editorContentComposite);
    // TODO 需换成真实数据
    // 初始化编辑器中表格行组件。
    txtComposites = new Composite[ROWSOFPAGE];
    tgtComposites = new Composite[ROWSOFPAGE];
    statusComposites = new Composite[ROWSOFPAGE];
    lblRowIndexs = new Label[ROWSOFPAGE];
    for (int i = 0; i < ROWSOFPAGE; i++) {
        Composite rowComposite = new Composite(editorContentComposite, SWT.NONE);
        GridLayout glRowCmp = new GridLayout(2, false);
        glRowCmp.marginHeight = 0;
        glRowCmp.marginWidth = 0;
        glRowCmp.horizontalSpacing = 0;
        glRowCmp.verticalSpacing = 0;
        rowComposite.setLayout(glRowCmp);
        rowComposite.setLayoutData(new GridData(GridData.FILL_HORIZONTAL));
        lblRowIndexs[i] = new Label(rowComposite, SWT.BORDER);
        lblRowIndexs[i].setAlignment(SWT.CENTER);
        lblRowIndexs[i].setText(String.valueOf(i + 1));
        GridData gdIndex = new GridData(GridData.FILL_VERTICAL);
        gdIndex.widthHint = COLUMN_INDEX_WIDTH;
        lblRowIndexs[i].setLayoutData(gdIndex);
        txtComposites[i] = new Composite(rowComposite, SWT.NONE);
        StyledText stSrc = new StyledText(txtComposites[i], SWT.MULTI | SWT.WRAP | SWT.READ_ONLY | SWT.BORDER);
        stSrc.setCursor(cursorArrow);
        stSrc.setData(DATAKEY_INDEX, i);
        stSrc.setText("This is a test." + (i + 1));
        GridData gdStSrc = new GridData(GridData.FILL_BOTH);
        gdStSrc.minimumHeight = MINIMUM_ROW_HEIGHT;
        gdStSrc.grabExcessVerticalSpace = true;
        stSrc.setLayoutData(gdStSrc);
        stSrc.addModifyListener(textModifyListener);
        stSrc.addMouseListener(mouseListener);
        stSrc.addKeyListener(keyListener);
        stSrc.addMouseTrackListener(mouseTrackListener);
        stSrc.setCaretOffset(-1);
        tgtComposites[i] = new Composite(txtComposites[i], SWT.NONE);
        statusComposites[i] = new Composite(tgtComposites[i], SWT.NONE);
        Label lblApprovedStatus = new Label(statusComposites[i], SWT.NONE);
        lblApprovedStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_RED));
        lblApprovedStatus.setToolTipText("翻译单元审批状态:已批准");
        lblApprovedStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
        Label lblTranslatableStatus = new Label(statusComposites[i], SWT.NONE);
        lblTranslatableStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_BLUE));
        lblTranslatableStatus.setToolTipText("翻译单元可译状态:可译");
        lblTranslatableStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
        Label lblTranslationStatus = new Label(statusComposites[i], SWT.NONE);
        lblTranslationStatus.setBackground(Display.getCurrent().getSystemColor(SWT.COLOR_CYAN));
        lblTranslationStatus.setToolTipText("目标文本段状态:已翻译");
        lblTranslationStatus.setLayoutData(new GridData(STATUS_FLAG_WIDTH, STATUS_FLAG_HEIGHT));
        StyledText stTgt = new StyledText(tgtComposites[i], SWT.MULTI | SWT.WRAP | SWT.BORDER);
        stTgt.setCursor(cursorArrow);
        stTgt.setData(DATAKEY_INDEX, i);
        GridData gdStTgt = new GridData(GridData.FILL_BOTH);
        gdStTgt.minimumHeight = MINIMUM_ROW_HEIGHT;
        gdStTgt.grabExcessVerticalSpace = true;
        stTgt.setLayoutData(gdStTgt);
        stTgt.addModifyListener(textModifyListener);
        stTgt.addMouseListener(mouseListener);
        stTgt.addKeyListener(keyListener);
        stTgt.addMouseTrackListener(mouseTrackListener);
        stTgt.setCaretOffset(-1);
    }
    // 模拟的编辑器数据模型
    final List<SimpleModel> models = getModel(1000);
    editorVBar.setIncrement(1);
    editorVBar.setPageIncrement(ROWSOFPAGE);
    editorVBar.setMaximum(models.size());
    editorVBar.setMinimum(1);
    editorVBar.setThumb(ROWSOFPAGE);
    editorVBar.addSelectionListener(new SelectionAdapter() {

        @Override
        public void widgetSelected(SelectionEvent e) {
            int y = editorVBar.getSelection();
            System.out.println("current y value:" + y);
            System.out.println("thumb value:" + editorVBar.getThumb());
            refreshContent(models, editorVBar.getSelection());
        }
    });
    // 初始化界面 UI 的显示内容
    // refreshContent(models, 1);
    // 设置编辑器组件布局
    setEditorLayout();
}
Also used : StyledText(org.eclipse.swt.custom.StyledText) Composite(org.eclipse.swt.widgets.Composite) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite) Slider(org.eclipse.swt.widgets.Slider) SelectionAdapter(org.eclipse.swt.events.SelectionAdapter) Label(org.eclipse.swt.widgets.Label) Point(org.eclipse.swt.graphics.Point) GridLayout(org.eclipse.swt.layout.GridLayout) GridData(org.eclipse.swt.layout.GridData) SelectionEvent(org.eclipse.swt.events.SelectionEvent) ScrolledComposite(org.eclipse.swt.custom.ScrolledComposite)

Aggregations

ScrolledComposite (org.eclipse.swt.custom.ScrolledComposite)1 StyledText (org.eclipse.swt.custom.StyledText)1 SelectionAdapter (org.eclipse.swt.events.SelectionAdapter)1 SelectionEvent (org.eclipse.swt.events.SelectionEvent)1 Point (org.eclipse.swt.graphics.Point)1 GridData (org.eclipse.swt.layout.GridData)1 GridLayout (org.eclipse.swt.layout.GridLayout)1 Composite (org.eclipse.swt.widgets.Composite)1 Label (org.eclipse.swt.widgets.Label)1 Slider (org.eclipse.swt.widgets.Slider)1