import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.GraphicsEnvironment;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Insets;
import java.awt.Toolkit;
import java.util.Hashtable;
import javax.swing.Box;
import javax.swing.ButtonGroup;
import javax.swing.DefaultListModel;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JComponent;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollPane;
import javax.swing.JSlider;
import javax.swing.JTable;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import javax.swing.ListSelectionModel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.table.DefaultTableModel;
public class TestLayoutView {
private static final long serialVersionUID = 9139718415334230659L;
private JComboBox gvcComboBox;
private JList gvcRuleList;
private JList exceptionList;
private JPanel mainPanel;
private JButton addRuleButton;
private JButton deleteRuleButton;
private JButton updateRuleButton;
private JButton cancelRuleButton;
private JButton addAllVisibleAsExceptionButton;
private JButton addExceptionButton;
private JButton deleteExceptionButton;
private JButton testWhereClauseButton;
private JTextField gvcPriorityField;
private JTextField gvcDescriptionField;
private JTextArea gvcWhereClauseField;
private JSlider gvcPrioritySlider;
protected JTable paginatedTable;
private JFrame frame;
private final static String BROWSE_DATA_HEADLINE_TEXT =
"Browse working data set";
private Insets screenInsets;
private Dimension maxFrameDimension;
private Dimension physicalDimension;
public void fillTestData() {
final DefaultTableModel tableModel = (DefaultTableModel)this.paginatedTable.getModel();
Object[] row = {0, "data", "buikbuikbuik", "Bitch Death Teenage Mucousi Monster From Hell",
"lips", "um", "lorum", "anvil", "löffelsteel","Kernspaltaxt","Heizol","hacken",
"Unsinn","Unsinn","Unsinn","Unsinn","Unsinn","Unsinn"};
for (int i=1; i<row.length; ) {
tableModel.addColumn("col "+(++i));
}
for (int i=0; i<50; i++) {
row[0] = ((Integer)row[0])+1;
tableModel.addRow(row);
}
DefaultListModel listModel = (DefaultListModel)gvcRuleList.getModel();
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement(11111);
listModel.addElement("Es könnte noch weitere Antworten auf das Thema geben, jedoch erhalten Sie keine zusätzlichen Benachrichtigungen, bis Sie das Forum wieder");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel = (DefaultListModel)exceptionList.getModel();
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("hello");
listModel.addElement("world");
listModel.addElement("1world");
listModel.addElement("2hello");
listModel.addElement("3world");
listModel.addElement("4hello");
listModel.addElement("5world");
listModel.addElement("6hello");
listModel.addElement("77777777777777world");
}
private JPanel getCombinedEditPanel() {
this.gvcRuleList = new JList();
this.gvcRuleList.setModel(new DefaultListModel());
this.gvcRuleList.setVisibleRowCount(12);
this.gvcRuleList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.addRuleButton = new JButton ("Add");
this.deleteRuleButton = new JButton ("Remove");
this.exceptionList = new JList();
this.exceptionList.setVisibleRowCount(12);
this.exceptionList.setModel(new DefaultListModel());
this.exceptionList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
this.addAllVisibleAsExceptionButton = new JButton ("Add all visible as exception");
this.addExceptionButton = new JButton ("Add");
this.deleteExceptionButton = new JButton ("Remove");
final JPanel combinedEditPanel = new JPanel(new BorderLayout());
JPanel panel2 = new JPanel (new BorderLayout());
final GridBagConstraints constraint = new GridBagConstraints();
panel2.add(this.getPaginationControlPanel(), BorderLayout.WEST);
panel2.add(this.getSearchPanel(), BorderLayout.EAST);
combinedEditPanel.add(panel2, BorderLayout.NORTH);
panel2 = new JPanel (new GridBagLayout());
constraint.gridx = 0;
constraint.fill = GridBagConstraints.BOTH;
constraint.insets.left = constraint.insets.right = 5;
constraint.gridy = 0;
panel2.add(new JLabel("GVC rules"));
constraint.gridx++;
panel2.add(new JLabel("Edit rule"));
constraint.gridx++;
panel2.add(new JLabel("GVC rule exceptions"));
constraint.gridx = 0;
constraint.fill = GridBagConstraints.BOTH;
constraint.weightx = 0.5;
constraint.gridy ++;
final JScrollPane gvcRuleListScrollPane = new JScrollPane(
this.gvcRuleList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
panel2.add(gvcRuleListScrollPane, constraint);
constraint.gridx++;
constraint.fill = GridBagConstraints.BOTH;
constraint.weightx = 1.;
panel2.add(this.getGVCRuleEditPanel(),constraint);
constraint.gridx++;
constraint.weightx = 0.;
final JScrollPane exceptionListScrollPane = new JScrollPane(
this.exceptionList,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);
panel2.add(exceptionListScrollPane, constraint);
JPanel buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(this.addRuleButton);
buttonPanel.add(this.deleteRuleButton);
constraint.gridx = 0;
constraint.gridy ++;
panel2.add(buttonPanel,constraint);
buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(this.cancelRuleButton);
buttonPanel.add(this.updateRuleButton);
constraint.gridx++;
panel2.add(buttonPanel,constraint);
buttonPanel = new JPanel(new FlowLayout());
buttonPanel.add(this.addExceptionButton);
buttonPanel.add(this.deleteExceptionButton);
constraint.gridx++;
panel2.add(buttonPanel,constraint);
combinedEditPanel.add(panel2, BorderLayout.CENTER);
return combinedEditPanel;
}
private JPanel getGVCRuleEditPanel() {
final JPanel ruleEditPanel = new JPanel(new GridBagLayout());
final GridBagConstraints constraint = new GridBagConstraints();
this.updateRuleButton = new JButton("Save/Update");
this.cancelRuleButton = new JButton("Cancel creation");
this.testWhereClauseButton = new JButton("Test");
this.gvcWhereClauseField = new JTextArea(2,30);
this.gvcWhereClauseField.setLineWrap(true);
this.gvcWhereClauseField.setWrapStyleWord(true);
this.gvcComboBox = new JComboBox();
this.gvcPrioritySlider = new JSlider(0,999,999);
Hashtable<Integer, JComponent> sliderLabels = new Hashtable<Integer, JComponent>();
sliderLabels.put(0, new JLabel("min"));
sliderLabels.put(500, new JLabel("medium"));
sliderLabels.put(999, new JLabel("max"));
this.gvcPrioritySlider.setLabelTable(sliderLabels);
this.gvcPrioritySlider.setMajorTickSpacing(100);
this.gvcPrioritySlider.setPaintTicks(true);
this.gvcPrioritySlider.setPaintLabels(true);
this.gvcPriorityField = new JTextField(3);
this.gvcWhereClauseField.setBorder(this.gvcPriorityField.getBorder());
this.gvcDescriptionField = new JTextField(30);
constraint.gridx = 0;
constraint.gridy = 0;
ruleEditPanel.add(new JLabel("code",SwingConstants.LEFT),constraint);
constraint.gridy++;
final JPanel wherePanel = new JPanel(new GridLayout(2,1));
wherePanel.add(new JLabel("where clause",SwingConstants.LEFT));
wherePanel.add(this.testWhereClauseButton);
ruleEditPanel.add(wherePanel,constraint);
constraint.gridy++;
ruleEditPanel.add(new JLabel("priority",SwingConstants.LEFT),constraint);
constraint.gridy++;
ruleEditPanel.add(new JLabel("description",SwingConstants.LEFT),constraint);
constraint.gridx = 1;
constraint.gridy = 0;
ruleEditPanel.add(this.gvcComboBox,constraint);
constraint.gridy++;
ruleEditPanel.add(new JScrollPane(this.gvcWhereClauseField),constraint);
constraint.gridy++;
JPanel priorityPanel = new JPanel(new FlowLayout(FlowLayout.LEFT,30,0));
priorityPanel.add(this.gvcPriorityField);
priorityPanel.add(this.gvcPrioritySlider);
ruleEditPanel.add(priorityPanel,constraint);
constraint.gridy++;
ruleEditPanel.add(this.gvcDescriptionField,constraint);
return ruleEditPanel;
}
private JPanel getPageInputPanel() {
final JPanel panel = new JPanel(new GridBagLayout());
final JLabel totalPagesTextField = new JLabel();
final JTextField selectedPageTextField = new JTextField(5);
final GridBagConstraints constraint = new GridBagConstraints();
constraint.gridwidth = 3;
constraint.gridx = 0;
constraint.gridy = 0;
panel.add(new JLabel("Page"),constraint);
constraint.gridwidth = 1;
constraint.gridy++;
panel.add(selectedPageTextField,constraint);
constraint.gridx++;
panel.add(new JLabel(" / "),constraint);
constraint.gridx++;
panel.add(totalPagesTextField,constraint);
return panel;
}
private JPanel getPaginationControlPanel() {
final JPanel paginateControlPanel;
final JButton nextPageButton;
final JButton prevPageButton;
final JButton firstPageButton;
final JButton lastPageButton;
firstPageButton = new JButton("<<");
prevPageButton = new JButton("<");
nextPageButton = new JButton(">");
lastPageButton = new JButton(">>");
paginateControlPanel = new JPanel(new FlowLayout(FlowLayout.CENTER,5,0));
paginateControlPanel.add(firstPageButton);
paginateControlPanel.add(prevPageButton);
paginateControlPanel.add(getPageInputPanel());
paginateControlPanel.add(nextPageButton);
paginateControlPanel.add(lastPageButton);
return paginateControlPanel;
}
private JPanel getSearchPanel() {
final JPanel panel = new JPanel (new FlowLayout());
final JTextField textField = new JTextField(25);
final JButton searchButton = new JButton("Search");
panel.add(textField);
panel.add(searchButton);
return panel;
}
private JPanel getBrowsePanel() {
final JPanel browsePanel = new JPanel(new BorderLayout());
final ButtonGroup browseButtonGroup;
final JRadioButton showAllRadioButton;
final JRadioButton showSingleConnectedRadioButton;
final JRadioButton showMultiConnectedRadioButton;
final JRadioButton showUnconnectedRadioButton;
final JLabel browseInfoLabel;
showAllRadioButton = new JRadioButton("all");
showSingleConnectedRadioButton = new JRadioButton("single connected");
showSingleConnectedRadioButton.setBackground( new Color(128,255,128));
showMultiConnectedRadioButton = new JRadioButton("multi connected ");
showMultiConnectedRadioButton.setBackground( new Color(255,128,128));
showUnconnectedRadioButton = new JRadioButton("free ");
showUnconnectedRadioButton.setBackground( new Color(255,255,128));
browseButtonGroup = new ButtonGroup();
browseButtonGroup.add(showAllRadioButton);
browseButtonGroup.add(showSingleConnectedRadioButton);
browseButtonGroup.add(showMultiConnectedRadioButton);
browseButtonGroup.add(showUnconnectedRadioButton);
showAllRadioButton.setSelected(true);
browseInfoLabel = new JLabel(BROWSE_DATA_HEADLINE_TEXT);
Box innerboxLeft = Box.createVerticalBox();
innerboxLeft.add(showAllRadioButton);
innerboxLeft.add(showSingleConnectedRadioButton);
Box innerboxRight = Box.createVerticalBox();
innerboxRight.add(showMultiConnectedRadioButton);
innerboxRight.add(showUnconnectedRadioButton);
Box outerBox = Box.createHorizontalBox();
outerBox.add(innerboxLeft);
outerBox.add(innerboxRight);
browsePanel.add(browseInfoLabel,BorderLayout.WEST);
browsePanel.add(outerBox,BorderLayout.EAST);
return browsePanel;
}
private void initScreenSizeProps() {
this.physicalDimension = Toolkit.getDefaultToolkit().getScreenSize();
this.screenInsets = Toolkit.getDefaultToolkit().getScreenInsets(
GraphicsEnvironment.getLocalGraphicsEnvironment()
.getDefaultScreenDevice().getDefaultConfiguration());
this.maxFrameDimension = new Dimension(
this.physicalDimension.width - screenInsets.left - screenInsets.right,
this.physicalDimension.height - screenInsets.top - screenInsets.bottom);
final JFrame testFrame = new JFrame();
testFrame.setSize(this.maxFrameDimension);
testFrame.setVisible(true);
testFrame.validate();
testFrame.dispose();
}
private void setViewSizeAndPosition () {
this.frame = new JFrame();
Dimension newFrameSize = new Dimension (
this.maxFrameDimension.width,
this.maxFrameDimension.height
);
this.frame.setSize(newFrameSize);
this.frame.setLocation(
(this.maxFrameDimension.width - newFrameSize.width) / 2 + this.screenInsets.left,
(this.maxFrameDimension.height - newFrameSize.height) / 2 + this.screenInsets.top
);
this.frame.setResizable(false);
this.frame.setContentPane(this.mainPanel);
}
public void setVisible() {
this.initScreenSizeProps();
this.paginatedTable = new JTable();
this.paginatedTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
this.mainPanel = new JPanel(null);
this.mainPanel.setLayout( new BorderLayout());
this.mainPanel.add(this.getBrowsePanel(),BorderLayout.NORTH);
final JScrollPane paginatedTableScrollPane = new JScrollPane(
this.paginatedTable,
JScrollPane.VERTICAL_SCROLLBAR_ALWAYS,
JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
this.mainPanel.add(paginatedTableScrollPane,BorderLayout.CENTER);
this.mainPanel.add(getCombinedEditPanel(),BorderLayout.SOUTH);
this.setViewSizeAndPosition();
this.frame.setVisible(true);
}
public static void main(String[] args) {
final TestLayoutView view = new TestLayoutView();
SwingUtilities.invokeLater(new Runnable (){
public void run() {
view.setVisible();
view.fillTestData();
}});
}
}