Programalama > JAVA - JSP

Etiketler: dialog, örneği

Ort. 0
Puan ver:

import java.awt.*;
import javax.swing.*;
import javax.swing.event.*;
import com.marinilli.b1.ac.pres.*;
import com.marinilli.b1.ac.pres.ui.memory.*;
import com.marinilli.b1.ac.util.*;

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

/**
 *
 *
 * @author Toygar Dündaralp
 * tdundaralp@gmail.com
 *
 *
 */
public class ConfigurationDialog extends JDialog
                                  implements ActionListener {
  JPanel panel1 = new JPanel();
  JSplitPane jSplitPane = new JSplitPane();
  MenuList list;
  OkCancelPane okCancelPane = new OkCancelPane(true);


  public ConfigurationDialog(String title, Configurable[] cv) {
    this(ServiceManager.getMainFrame(), title, cv);
  }

  private ConfigurationDialog(Frame frame,
                            String title,
                            Configurable[] cv) {
    super(frame, title , true);
    if (cv.length > 1) {
      list = new MenuList(new Layout(cv));
      list.setPreferredSize(new Dimension(112,122));
    }
    // UI init
    initGUI();
    pack();
    if (frame!=null)
      Utilities.center(this, frame);
    setVisible(true);
  }

  void initGUI() {
    okCancelPane.addActionListener(this);
    panel1.setLayout(new BorderLayout());
    getContentPane().add(panel1);
    panel1.add(jSplitPane, BorderLayout.CENTER);
    panel1.add(okCancelPane, BorderLayout.SOUTH);
    JScrollPane jsp = new JScrollPane(list);
    jSplitPane.add(jsp, JSplitPane.LEFT);
    jSplitPane.setDividerSize(6);
    setViewSizes();
  }

  private void setViewSizes() {
    int wm = 0;
    int hm = 0;
    for (int i = 0; i < list.getModel().getSize(); i++) {
      int w =list.getView(i).getComponent().getWidth();
      int h =list.getView(i).getComponent().getHeight();
      if (w>wm)
        wm=w;
      if (h>hm)
        hm=h;
    }
    Dimension max = new Dimension(wm, hm);
    for (int i = 0; i < list.getModel().getSize(); i++) {
      ((JComponent)list.getView(i).getComponent()).setPreferredSize(max);
      ((JComponent)list.getView(i).getComponent()).setMinimumSize(max);
      ((JComponent)list.getView(i).getComponent()).setMaximumSize(max);
    }
  }

  /**
   * The menuList appears on the left hand side of the ConfigurationDialog.
   */
  public class MenuList extends JList implements ListSelectionListener{

    public MenuList(Layout l) {
      super(l);
      addListSelectionListener(this);
      setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
      setCellRenderer(l);
      setSelectedIndex(0);

    }

    public View getView(int index) {
      return ((Layout)getModel()).getView(index);
    }

    public void valueChanged(ListSelectionEvent lse) {
      if (!lse.getValueIsAdjusting()) {
        Component c = getView(getSelectedIndex()).getComponent();
        jSplitPane.setRightComponent(c);
      }
    }

  }// - MenuList class


  /**
   * defines the menuList items layout
   * (order, look and correspondent Viewable object).
   */
  public class Layout extends DefaultListModel
                              implements ListCellRenderer {
    private Component[] categories;

    public Layout(Configurable[] cv) {
      super();
      categories = new Component[cv.length];
      for (int i = 0; i < cv.length; i++) {
        addElement(cv[i].getConfigurationView(true));
        categories[i] = cv[i].getCategory();
      }
    }

    public View getView(int index) {
      return (View) getElementAt(index);
    }

    public Component getCategory(int index) {
      return (Component) categories[index];
    }

    public Component getListCellRendererComponent(
        JList list,
        Object value,
        int index,
        boolean isSelected,
        boolean cellHasFocus) {

      Component c = getCategory(index);
      if (isSelected) {
        c.setEnabled(true);
        c.setForeground(Color.darkGray);
      }  else if (c instanceof JLabel)
        // just some special effect
        ((JLabel)c).setEnabled(false);
      return c;
    }

  }/// - Layout class




  public void actionPerformed(ActionEvent e) {
    String command = e.getActionCommand();
    if (command==CommonActions.CANCEL) {
      dispose();
    } else if (command==CommonActions.OK) {
      // for every View commits its values into the Viewable model
      for (int i = 0; i < list.getModel().getSize(); i++) {
        list.getView(i).doCommit();
      }
      dispose();
    }
  }//-actionPerformed()

}//- main class


toygar dündaralp
bahcivan ibrahim sitesi orman sk.


Yorumlar                 Yorum Yaz
Bu hazır kod'a ilk yorumu siz yapın!
KATEGORİLER
ASP - 240
ASP.NET - 24
C# - 75
C++ - 174
CGI - 8
DELPHI - 247
FLASH - 49
HTML - 536
PASCAL - 246
PERL - 11
PHP - 160
WML - 9
XML - 2
Copyright © 2002 - 2024 Hazır Kod - Tüm Hakları Saklıdır.
Siteden yararlanırken gizlilik ilkelerini okumanızı tavsiye ederiz.
hazirkod.com bir İSOBİL projesidir.