ABC

Ads

 
 

Share on Google+Share on Google+

Shadab Ahmad Khan
ABC
0 Answer(s)      5 years ago
Posted in : HTML

package threeDAssignment;

import java.awt.GridBagConstraints; import java.awt.GridBagLayout; import java.awt.Insets; import java.awt.Point; import java.awt.event.ActionEvent; import java.awt.event.ActionListener;

import javax.swing.Box; import javax.swing.DefaultComboBoxModel; import javax.swing.JButton; import javax.swing.JComboBox; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel;

@SuppressWarnings("serial") public class LayerOptionDialog extends JDialog implements ActionListener {

public LayerOptionDialog(JFrame owner, String title) {
    super(owner,title);

    setSize(350, 150);

    setLocation(new Point(0, owner.getHeight()-155));

    setResizable(false);

    grid=((DisplayUI)owner).getGrid();

    canvas=((DisplayUI)owner).getCanvas();

    createDialog();

    addListeners();
}

private void addListeners() {
    cmbDirection.addActionListener(this);
    cmbLayer.addActionListener(this);

    btnBack.addActionListener(this);
    btnForward.addActionListener(this);
    btnFastBack.addActionListener(this);
    btnFastForward.addActionListener(this);
    btnStop.addActionListener(this);

    btnReset.addActionListener(this);
    btnClose.addActionListener(this);
}

@Override
public void actionPerformed(ActionEvent e) {
    Object source=e.getSource();

    if(source.equals(cmbDirection))
    {
        if(cmbDirection.getSelectedIndex()>0){
            DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
            cmbLayerModel.removeAllElements();

            if(cmbDirection.getSelectedIndex()==1){
                int NX=grid.getNX();
                for(int i=1; i<=NX; i++){
                    cmbLayerModel.addElement(i);
                }
            }else if(cmbDirection.getSelectedIndex()==2){
                int NY=grid.getNY();
                for(int i=1; i<=NY; i++){
                    cmbLayerModel.addElement(i);
                }
            }
            else if(cmbDirection.getSelectedIndex()==3){
                int NZ=grid.getNZ();
                for(int i=1; i<=NZ; i++){
                    cmbLayerModel.addElement(i);
                }
            }

            cmbLayer.repaint();
        }else{
            DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
            cmbLayerModel.removeAllElements();
            cmbLayer.repaint();
        }
    }
    else if(source.equals(cmbLayer)){
        showGridLayer(0);

    }

    else if(source.equals(btnForward)){
        showGridLayer(1);
    }
    else if(source.equals(btnBack)){
        showGridLayer(-1);
    }
    else if (source.equals(btnFastForward)) {
        isStop=false;
        if (cmbDirection.getSelectedIndex() > 0) {
                Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        while (Integer.parseInt(cmbLayer.getSelectedItem().toString()) < ((cmbDirection.getSelectedIndex()==1)?grid.getNX():((cmbDirection.getSelectedIndex()==2)?grid.getNY():grid.getNZ()))) {
                            if(isStop)
                                return;
                            showGridLayer(1);
                            if(Integer.parseInt(cmbLayer.getSelectedItem().toString()) == ((cmbDirection.getSelectedIndex()==1)?grid.getNX():((cmbDirection.getSelectedIndex()==2)?grid.getNY():grid.getNZ()))){
                                return;
                            }
                            try {
                                Thread.sleep(300);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                });
                t.start();
        }
    }
    else if (source.equals(btnFastBack)) {
        isStop=false;
        if (cmbDirection.getSelectedIndex() > 0) {
            Thread t = new Thread(new Runnable() {

                    @Override
                    public void run() {
                        while (Integer.parseInt(cmbLayer.getSelectedItem().toString()) > 0) {
                            if(isStop)
                                return;
                            showGridLayer(-1);
                            if(Integer.parseInt(cmbLayer.getSelectedItem().toString())==1)
                                return;
                            try {
                                Thread.sleep(300);
                            } catch (InterruptedException e1) {
                                e1.printStackTrace();
                            }
                        }
                    }
                });
                t.start();
        }
    }
    else if(source.equals(btnReset)){
        cmbDirection.setSelectedIndex(0);
        DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
        cmbLayerModel.removeAllElements();
        cmbLayer.repaint();
        canvas.showLayer(0);
    }
    else if(source.equals(btnClose)){
        this.dispose();
    }
    else if(source.equals(btnStop)){

// t.interrupt(); isStop=true; } }

private void showGridLayer(int i) {
    if(cmbDirection.getSelectedIndex()>0){
        DefaultComboBoxModel cmbLayerModel=(DefaultComboBoxModel)cmbLayer.getModel();
        if(cmbLayerModel.getSize()>0){
            int layer=Integer.parseInt(cmbLayer.getSelectedItem().toString());
            if(cmbDirection.getSelectedIndex()==1){

                if((layer+i)<=grid.getNX() && (layer+i)>0){
                    canvas.showLayer(layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }

            }else if(cmbDirection.getSelectedIndex()==2){

                if((layer+i)<=grid.getNY() && (layer+i)>0){
                    canvas.showLayer(grid.getNX()+layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }
            }else if(cmbDirection.getSelectedIndex()==3){

                if((layer+i)<=grid.getNZ() && (layer+i)>0){
                    canvas.showLayer(grid.getNX()+grid.getNY()+layer+i);
                    cmbLayer.setSelectedItem(layer+i);
                }
            }
        }
    }else{
        canvas.showLayer(0);
    }
}

private void createDialog() {
    setLayout(new GridBagLayout());
    GridBagConstraints gbc=new GridBagConstraints();

    Insets ins=new Insets(10, 2, 10, 2);

    gbc.anchor=GridBagConstraints.FIRST_LINE_START;
    gbc.fill=GridBagConstraints.BOTH;
    gbc.insets=ins;

    gbc.gridx=0;
    gbc.gridy=0;
    add(new JLabel("Direction :"),gbc);

    cmbDirection=new JComboBox(new Object[]{"Select","X-Direction","Y-Directiion","Z-Direction"});
    gbc.gridx=1;
    gbc.gridwidth=2;
    add(cmbDirection,gbc);

    gbc.gridx=2;
    gbc.gridwidth=1;
    add(Box.createHorizontalStrut(10),gbc);

    gbc.gridx=3;
    add(new JLabel("   Layer :"),gbc);

    cmbLayer=new JComboBox();
    gbc.gridx=4;
    add(cmbLayer,gbc);

    btnFastBack=new JButton("<<<");
    gbc.gridx=0;
    gbc.gridy=1;
    add(btnFastBack,gbc);

    btnBack=new JButton("<<");
    gbc.gridx=1;
    add(btnBack,gbc);

    btnStop=new JButton("...");
    gbc.gridx=2;
    add(btnStop,gbc);

    btnForward=new JButton(">>");
    gbc.gridx=3;
    add(btnForward,gbc);

    btnFastForward=new JButton(">>>");
    gbc.gridx=4;
    add(btnFastForward,gbc);

    gbc.gridx=0;
    gbc.gridy=2;
    gbc.gridwidth=2;
    add(Box.createHorizontalStrut(50),gbc);

    btnReset=new JButton("Reset");
    gbc.gridx=1;
    gbc.gridwidth=1;
    add(btnReset,gbc);

    gbc.gridx=2;
    add(Box.createHorizontalStrut(50),gbc);

    btnClose=new JButton("Close");
    gbc.gridx=3;
    add(btnClose,gbc);
}

private Grid grid;
private ThreeDCanvas canvas;

private JComboBox cmbLayer;
private JComboBox cmbDirection;

private JButton btnBack;
private JButton btnForward;
private JButton btnFastBack;
private JButton btnFastForward;
private JButton btnStop;
private JButton btnReset;
private JButton btnClose;

private boolean isStop=false;

}

Ads
View Answers
Ads









Related Tutorials/Questions & Answers:
ABC
ABC
Advertisements
Version of com.rklaehn>abc-collection_2.11 dependency
List of Version of com.rklaehn>abc-collection_2.11 dependency
Version of com.rklaehn>abc-collection_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-collection_sjs0.6_2.11 dependency
Version of com.rklaehn>abc-extras_2.11 dependency
List of Version of com.rklaehn>abc-extras_2.11 dependency
Version of com.rklaehn>abc-extras_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-extras_sjs0.6_2.11 dependency
Version of com.rklaehn>abc-laws_2.11 dependency
List of Version of com.rklaehn>abc-laws_2.11 dependency
Version of com.rklaehn>abc-laws_sjs0.6_2.11 dependency
List of Version of com.rklaehn>abc-laws_sjs0.6_2.11 dependency
Version of com.rklaehn>abc-collection_2.12 dependency
List of Version of com.rklaehn>abc-collection_2.12 dependency
Version of com.rklaehn>abc-collection_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-collection_sjs0.6_2.12 dependency
Version of com.rklaehn>abc-extras_2.12 dependency
List of Version of com.rklaehn>abc-extras_2.12 dependency
Version of com.rklaehn>abc-extras_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-extras_sjs0.6_2.12 dependency
Version of com.rklaehn>abc-laws_2.12 dependency
List of Version of com.rklaehn>abc-laws_2.12 dependency
Version of com.rklaehn>abc-laws_sjs0.6_2.12 dependency
List of Version of com.rklaehn>abc-laws_sjs0.6_2.12 dependency
Maven Dependency abc-collection_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.2.1 in your project
Maven Dependency abc-collection_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.3.0 in your project
Maven Dependency abc-collection_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.11 version0.2.0 in your project
Maven Dependency abc-collection_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_2.12 version0.4.0 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.2.1 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.2.0 in your project
Maven Dependency abc-collection_sjs0.6_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.11 version0.3.0 in your project
Maven Dependency abc-collection_sjs0.6_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-collection_sjs0.6_2.12 version0.4.0 in your project
Maven Dependency abc-extras_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.2.1 in your project
Maven Dependency abc-extras_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.2.0 in your project
Maven Dependency abc-extras_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.11 version0.3.0 in your project
Maven Dependency abc-extras_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_2.12 version0.4.0 in your project
Maven Dependency abc-extras_sjs0.6_2.11 >> 0.3.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.11 version0.3.0 in your project
Maven Dependency abc-extras_sjs0.6_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.11 version0.2.0 in your project
Maven Dependency abc-extras_sjs0.6_2.11 >> 0.2.1
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.11 version0.2.1 in your project
Maven Dependency abc-extras_sjs0.6_2.12 >> 0.4.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-extras_sjs0.6_2.12 version0.4.0 in your project
Maven Dependency abc-laws_2.11 >> 0.2.0
You should include the dependency code given in this page to add Maven Dependency of com.rklaehn >> abc-laws_2.11 version0.2.0 in your project