İPUCU

Java Object Oriented Programming temeline dayanan, çok işlevli, step by step işleyen dilin dökümanlarının paylaşım alanı.

Seçenekler

JAVA - JSP / Uı Dialog Örneği

"Squ4LL - ait Kullanıcı Resmi (Avatar)
Yardımsever
Üyelik tarihi:
07/2009
Mesajlar:
13.304
Konular:
772
Teşekkür (Etti):
101
Teşekkür (Aldı):
2213
Ticaret:
(0) %
02-10-2017 01:25
#1
JAVA - JSP / Uı Dialog Örneği
JAVA - JSP / Uı Dialog Örneği

Kod:
 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 isim yaz
* @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); 
  } 
 
  **** 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 **** 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 **** valueChanged(ListSelectionEvent lse) { 
      if (!lse.getValueIsAdjusting()) { 
        Component c = getView(getSelectedIndex()).getComponent(); 
        jSplitPane.setRightComponent©; 
      } 
    } 
 
  }// - 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 **** 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 

Bookmarks


« Önceki Konu | Sonraki Konu »
Seçenekler

Yetkileriniz
Sizin Yeni Konu Acma Yetkiniz var yok
You may not post replies
Sizin eklenti yükleme yetkiniz yok
You may not edit your posts

BB code is Açık
Smileler Açık
[IMG] Kodları Açık
HTML-Kodları Kapalı
Trackbacks are Kapalı
Pingbacks are Kapalı
Refbacks are Kapalı