⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 rotatecontrolpanel.java

📁 JPowerGraph is a Java library for creating directed graphs for SWT. It supports graph movement, sele
💻 JAVA
字号:
package net.sourceforge.jpowergraph.viewcontrols;

import net.sourceforge.jpowergraph.lens.Lens;
import net.sourceforge.jpowergraph.lens.LensListener;
import net.sourceforge.jpowergraph.lens.RotateLens;

import org.eclipse.swt.SWT;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;

/**
 * @author Mick Kerrigan
 *
 * Created on 05-Aug-2005
 * Committed by $Author: morcen $
 *
 * $Source: /cvsroot/jpowergraph/swt/src/net/sourceforge/jpowergraph/viewcontrols/RotateControlPanel.java,v $,
 * @version $Revision: 1.2 $ $Date: 2005/08/10 09:19:56 $
 */
public class RotateControlPanel extends Composite {
    
    public static final Integer[] DEFAULT_ROTATE_ANGLES = new Integer[]{0, 90, 180, 270};

    private Combo rotateFactor;
    private RotateLens rotateLens;
    
    /**
     * 
     */
    public RotateControlPanel(Composite theParent, RotateLens theRotateLens) {
        this(theParent, theRotateLens, DEFAULT_ROTATE_ANGLES, 0);
    }
    
    public RotateControlPanel(Composite theParent, RotateLens theRotateLens, Integer[] rotateAngles, Integer rotateValue) {
        super(theParent, SWT.NONE);
        rotateLens = theRotateLens;
        
        GridLayout gridLayout = new GridLayout();
        gridLayout.numColumns = 2;
        gridLayout.marginWidth = 2;
        gridLayout.marginHeight = 0;
        this.setLayout(gridLayout);
        
        Label l = new Label(this, SWT.NONE);
        l.setText("Rotate: ");
        
        rotateFactor = new Combo(this, SWT.DROP_DOWN | SWT.READ_ONLY);
        for (int i = 0; i < rotateAngles.length; i++){
            rotateFactor.add(getComboTextFromInt(rotateAngles[i]));
        }
        rotateFactor.setEnabled(rotateLens != null);
        rotateFactor.setText(getComboTextFromInt(rotateValue));
        setSelectedItemFromLens();
        this.addActionListeners();
    }

    private void addActionListeners() {
        if (rotateLens != null && rotateFactor != null){
            rotateFactor.addSelectionListener(new SelectionAdapter(){
                public void widgetSelected(SelectionEvent e){
                    int i = 360 - getIntFromComboText(rotateFactor.getText());
                    if (rotateLens.getRotationAngle() != i){
                        rotateLens.setRotationAngle(i);
                    }
                }
            });
        }
        
        if (rotateLens != null){
            rotateLens.addLensListener(new LensListener() {
                public void lensUpdated(Lens lens) {
                    setSelectedItemFromLens();
                }
            });
        }
    }
    
    public String getComboTextFromInt(int i){
        return i + "

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -