package org.hwo.ui.gantt; import java.awt.BorderLayout; import java.awt.FlowLayout; import javax.swing.JButton; import javax.swing.JDialog; import javax.swing.JPanel; import javax.swing.border.EmptyBorder; import java.awt.GridBagLayout; import javax.swing.JScrollPane; import java.awt.GridBagConstraints; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import java.awt.Dialog.ModalExclusionType; import javax.swing.ScrollPaneConstants; import org.hwo.datetime.Date; import org.hwo.datetime.DateTime; import org.hwo.datetime.TimeOfDay; import java.awt.Color; import java.awt.Font; public class JGanttTestDialog extends JDialog { private final JPanel contentPanel = new JPanel(); private JGantt netPlan; /** * Create the dialog. */ public JGanttTestDialog() { setModal(true); setTitle("JGantt Test Dialog"); setModalExclusionType(ModalExclusionType.APPLICATION_EXCLUDE); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); setBounds(100, 100, 975, 481); getContentPane().setLayout(new BorderLayout()); contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5)); getContentPane().add(contentPanel, BorderLayout.CENTER); GridBagLayout gbl_contentPanel = new GridBagLayout(); gbl_contentPanel.columnWidths = new int[]{0, 0}; gbl_contentPanel.rowHeights = new int[]{0, 0}; gbl_contentPanel.columnWeights = new double[]{1.0, Double.MIN_VALUE}; gbl_contentPanel.rowWeights = new double[]{1.0, Double.MIN_VALUE}; contentPanel.setLayout(gbl_contentPanel); { JScrollPane scrollPane = new JScrollPane(); scrollPane.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS); scrollPane.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS); GridBagConstraints gbc_scrollPane = new GridBagConstraints(); gbc_scrollPane.fill = GridBagConstraints.BOTH; gbc_scrollPane.gridx = 0; gbc_scrollPane.gridy = 0; contentPanel.add(scrollPane, gbc_scrollPane); { netPlan = new JGantt(); netPlan.setDays(230); netPlan.setFont(new Font("DejaVu Sans", Font.PLAIN, 16)); netPlan.setBackground(Color.WHITE); scrollPane.setViewportView(netPlan); } } { JPanel buttonPane = new JPanel(); buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT)); getContentPane().add(buttonPane, BorderLayout.SOUTH); { JButton okButton = new JButton("OK"); okButton.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { setVisible(false); } }); okButton.setActionCommand("OK"); buttonPane.add(okButton); getRootPane().setDefaultButton(okButton); } { JButton cancelButton = new JButton("Cancel"); cancelButton.setActionCommand("Cancel"); buttonPane.add(cancelButton); } } this.initialize(); } private void initialize(){ for (int i=0;i<10;i++){ BaseGanttResource res = new BaseGanttResource(String.format("Resource %d",i), "-"); netPlan.addGanttResource(res); } Date d = new Date(); d.addDays(3); Date d2 = new Date(d); d2.addDays(4); BaseGanttObject o = new BaseGanttObject(); o.setStartTime(new DateTime(d, new TimeOfDay())); o.setEndTime(new DateTime(d2, TimeOfDay.beforeMidnight())); o.setShortLabel("Eine Aufgabe"); o.addResource(netPlan.getGanttResources()[0]); o.addResource(netPlan.getGanttResources()[3]); o.addResource(netPlan.getGanttResources()[7]); netPlan.addGanttObject(o); d.addDays(2); d2.addDays(6); o = new BaseGanttObject(); o.setStartTime(new DateTime(d, new TimeOfDay())); o.setEndTime(new DateTime(d2, TimeOfDay.beforeMidnight())); o.setShortLabel("Eine Aufgabe"); o.addResource(netPlan.getGanttResources()[1]); o.addResource(netPlan.getGanttResources()[2]); netPlan.addGanttObject(o); d.addDays(3); d2.addDays(-2); o = new BaseGanttObject(); o.setStartTime(new DateTime(d, new TimeOfDay())); o.setEndTime(new DateTime(d2, TimeOfDay.beforeMidnight())); o.setShortLabel("Eine Aufgabe"); o.addResource(netPlan.getGanttResources()[0]); o.addResource(netPlan.getGanttResources()[7]); netPlan.addGanttObject(o); //netPlan.setSelectedObject(o); } }