/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package de.netsysit.view;
import de.netsysit.controller.ActionFactory;
import de.netsysit.controller.ActionFactory.ActionKey;
import de.netsysit.controller.PolicyController;
import de.netsysit.model.PersonalTreeNode;
import de.netsysit.policymanager.PolicyUtilities;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.dnd.DragGestureEvent;
import java.util.ResourceBundle;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.JTextField;
import javax.swing.JTree;
import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.tree.DefaultTreeModel;
/**
*
* @author Ducksoul
*/
public class PolicyView extends JPanel {
private static ResourceBundle rb = PolicyUtilities.getResourceBundle();
//
private JList policyAPoliciesLst = new JList();
private JList policyCPoliciesLst = new JList();
private JList policyIPoliciesLst = new JList();
private JScrollPane policyAPoliciesScroll = new JScrollPane(policyAPoliciesLst);
private JScrollPane policyCPoliciesScroll = new JScrollPane(policyCPoliciesLst);
private JScrollPane policyIPoliciesScroll = new JScrollPane(policyIPoliciesLst);
private JPanel policyLeftPnl = new JPanel();
private JPanel policyRightPnl = new JPanel();
private JPanel policyRightTopPnl = new JPanel();
private JPanel policyRightBottomPnl = new JPanel();
private JPanel policyHelpPnl = new JPanel();
private JTree policyTree = new JTree(new DefaultTreeModel(new PersonalTreeNode("root", false)));
private JScrollPane policyTreeScroll = new JScrollPane(policyTree);
private JScrollPane policyTableScroll = new JScrollPane(policyHelpPnl);
private JSplitPane policyVerticalSplit = new JSplitPane(JSplitPane.VERTICAL_SPLIT, policyTreeScroll, policyTableScroll);
private JLabel policyNameLbl = new JLabel(rb.getString("name"));
private JLabel policyFallBackLbl = new JLabel(rb.getString("fallback"));
private JLabel policyActionLbl = new JLabel(rb.getString("action"));
private JLabel policyUseTokenLbl = new JLabel(rb.getString("usetoken"));
private JTextField policyNameTxt = new JTextField();
private JLabel policyFallBackLbl2 = new JLabel();
private JButton policyFallBackBtn = new JButton(ActionFactory.get(ActionKey.POLICY_CHOOSEFB));
private JPanel policyFallBackPnl = new JPanel();
private JPanel policyAlgorithmPnl = new JPanel();
private JComboBox policyAlgorithmCombo = new JComboBox();
private JComboBox policyModeCombo = new JComboBox();
private JCheckBox policyUseTokenCheck = new JCheckBox();
public PolicyView() {
// glassPane = new de.netsysit.view.DragImageGlassPane(this, false);
// dragsource = new java.awt.dnd.DragSource();
// DragImageGlassPane gl
//// dragsource.createDefaultDragGestureRecognizer(policyCPoliciesLst, java.awt.dnd.DnDConstants.ACTION_MOVE, this);
// glassPane.setOpaque(false);
PolicyController pc = new PolicyController(this);
init();
}
public JList getPolicyAPoliciesLst() {
return policyAPoliciesLst;
}
public JComboBox getPolicyAlgorithmCombo() {
return policyAlgorithmCombo;
}
public JList getPolicyCPoliciesLst() {
return policyCPoliciesLst;
}
public JLabel getPolicyFallBackLbl2() {
return policyFallBackLbl2;
}
public JList getPolicyIPoliciesLst() {
return policyIPoliciesLst;
}
public JComboBox getPolicyModeCombo() {
return policyModeCombo;
}
public JTextField getPolicyNameTxt() {
return policyNameTxt;
}
public JTree getPolicyTree() {
return policyTree;
}
public JCheckBox getPolicyUseTokenCheck() {
return policyUseTokenCheck;
}
public JLabel getPolicyActionLbl() {
return policyActionLbl;
}
public JLabel getPolicyFallBackLbl() {
return policyFallBackLbl;
}
public JLabel getPolicyNameLbl() {
return policyNameLbl;
}
public JLabel getPolicyUseTokenLbl() {
return policyUseTokenLbl;
}
public JScrollPane getPolicyTreeScroll() {
return policyTreeScroll;
}
private void init() {
policyLeftPnl.setLayout(new GridLayout(3, 1));
policyLeftPnl.setBorder(BorderFactory.createMatteBorder(0, 0, 0, 1, Color.gray));
policyLeftPnl.add(policyAPoliciesScroll);
policyAPoliciesLst.setBorder(BorderFactory.createTitledBorder(rb.getString("alevel")));
policyLeftPnl.add(policyCPoliciesScroll);
policyCPoliciesLst.setBorder(BorderFactory.createTitledBorder(rb.getString("clevel")));
policyLeftPnl.add(policyIPoliciesScroll);
policyIPoliciesLst.setBorder(BorderFactory.createTitledBorder(rb.getString("ilevel")));
policyAPoliciesScroll.setBorder(null);
policyCPoliciesScroll.setBorder(null);
policyIPoliciesScroll.setBorder(null);
policyRightPnl.setLayout(new BorderLayout());
policyRightPnl.add(policyRightTopPnl, BorderLayout.NORTH);
policyRightPnl.add(policyRightBottomPnl, BorderLayout.CENTER);
policyRightTopPnl.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.gray));
policyRightBottomPnl.setLayout(new GridLayout());
policyRightBottomPnl.add(policyVerticalSplit);
policyTreeScroll.setBorder(BorderFactory.createTitledBorder(rb.getString("fbrelations")));
policyTree.setRootVisible(false);
policyTree.setCellRenderer(new PersonalTreeCellRenderer());
//eigentliche GUI erzeugen
GridBagLayout gbl = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
policyRightTopPnl.setLayout(gbl);
policyAlgorithmPnl.setLayout(new BorderLayout());
policyAlgorithmPnl.add(policyAlgorithmCombo, BorderLayout.WEST);
policyAlgorithmPnl.add(policyModeCombo, BorderLayout.CENTER);
policyFallBackPnl.setLayout(new BorderLayout());
policyFallBackPnl.add(policyFallBackLbl2, BorderLayout.CENTER);
policyFallBackPnl.add(policyFallBackBtn, BorderLayout.EAST);
policyFallBackLbl2.setHorizontalAlignment(SwingConstants.LEFT);
policyFallBackLbl2.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
ActionFactory.get(ActionKey.POLICY_CHOOSEFB).setEnabled(false);
PolicyUtilities.createLine(policyRightTopPnl, gbl, policyNameLbl, policyNameTxt, 0, 15, 2);
PolicyUtilities.createLine(policyRightTopPnl, gbl, policyFallBackLbl, policyFallBackPnl, 1);
PolicyUtilities.createLine(policyRightTopPnl, gbl, policyActionLbl, policyAlgorithmPnl, 2);
PolicyUtilities.createLine(policyRightTopPnl, gbl, policyUseTokenLbl, policyUseTokenCheck, 3);
policyAPoliciesScroll.setMinimumSize(new Dimension(175, 1));
policyAPoliciesScroll.setPreferredSize(new Dimension(175, 1));
policyCPoliciesScroll.setMinimumSize(new Dimension(175, 1));
policyCPoliciesScroll.setPreferredSize(new Dimension(175, 1));
policyIPoliciesScroll.setMinimumSize(new Dimension(175, 1));
policyIPoliciesScroll.setPreferredSize(new Dimension(175, 1));
policyNameTxt.setMinimumSize(new Dimension(200, 21));
policyNameTxt.setPreferredSize(new Dimension(200, 21));
policyFallBackLbl2.setMinimumSize(new Dimension(1, 40));
policyFallBackBtn.setMinimumSize(new Dimension(1, 40));
policyAlgorithmCombo.setMinimumSize(new Dimension(75, 21));
policyAlgorithmCombo.setPreferredSize(new Dimension(75, 21));
policyModeCombo.setMinimumSize(new Dimension(125, 21));
policyModeCombo.setPreferredSize(new Dimension(125, 21));
policyTreeScroll.setMinimumSize(new Dimension(150, 150));
policyTreeScroll.setPreferredSize(new Dimension(250, 250));
policyNameTxt.setEnabled(false);
policyAlgorithmCombo.setEnabled(false);
policyModeCombo.setEnabled(false);
policyUseTokenCheck.setEnabled(false);
setLayout(new BorderLayout());
add(policyLeftPnl, BorderLayout.WEST);
add(policyRightPnl, BorderLayout.CENTER);
}
private class RowHeaderRenderer extends JLabel implements ListCellRenderer {
RowHeaderRenderer() {
setOpaque(true);
setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.UIManager.getBorder("TableHeader.cellBorder"), javax.swing.BorderFactory.createEmptyBorder(0, 5, 0, 5)));
// setFont(getFont().deriveFont(4.0f));
{
setHorizontalAlignment(CENTER);
}
// setBorder(javax.swing.BorderFactory.createBevelBorder(javax.swing.border.BevelBorder.RAISED));
}
@Override
public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
this.setText(value.toString());
return this;
}
}
}