KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > compiere > grid > VOnlyCurrentDays


1 /******************************************************************************
2  * The contents of this file are subject to the Compiere License Version 1.1
3  * ("License"); You may not use this file except in compliance with the License
4  * You may obtain a copy of the License at http://www.compiere.org/license.html
5  * Software distributed under the License is distributed on an "AS IS" basis,
6  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
7  * the specific language governing rights and limitations under the License.
8  * The Original Code is Compiere ERP & CRM Business Solution
9  * The Initial Developer of the Original Code is Jorg Janke and ComPiere, Inc.
10  * Portions created by Jorg Janke are Copyright (C) 1999-2002 Jorg Janke, parts
11  * created by ComPiere are Copyright (C) ComPiere, Inc.; All Rights Reserved.
12  * Contributor(s): ______________________________________.
13  *****************************************************************************/

14 package org.compiere.grid;
15
16 import java.awt.*;
17 import javax.swing.*;
18 import java.awt.event.*;
19
20 import org.compiere.util.*;
21 import org.compiere.apps.*;
22 import org.compiere.swing.*;
23
24 /**
25  * Queries how many days back cistory is displayed as current
26  *
27  * @author Jorg Janke
28  * @version $Id: VOnlyCurrentDays.java,v 1.2 2002/09/15 01:05:40 jjanke Exp $
29  */

30 public class VOnlyCurrentDays extends JDialog implements ActionListener
31 {
32     /**
33      * Constructor
34      * @param parent parent frame
35      * @param buttonLocation lower left corner of the button
36      */

37     public VOnlyCurrentDays(Frame parent, Point buttonLocation)
38     {
39         // How long back in History?
40
super (parent, Msg.getMsg(Env.getCtx(), "VOnlyCurrentDays", true), true);
41         try
42         {
43             jbInit();
44         }
45         catch(Exception JavaDoc e)
46         {
47             Log.error("VOnlyCurrentDays", e);
48         }
49         this.pack();
50         buttonLocation.x -= (int)getPreferredSize().getWidth()/2;
51         this.setLocation(buttonLocation);
52         this.setVisible(true);
53     } // VOnlyCurrentDays
54

55     private CPanel mainPanel = new CPanel();
56     private CButton bShowAll = new CButton();
57     private CButton bShowMonth = new CButton();
58     private CButton bShowWeek = new CButton();
59     private CButton bShowDay = new CButton();
60     private CButton bShowYear = new CButton();
61
62     /** Days */
63     private int m_days = 1;
64     /** Margin */
65     private static Insets s_margin = new Insets (2, 2, 2, 2);
66
67     /**
68      * Static Initializer
69      * @throws Exception
70      */

71     private void jbInit() throws Exception JavaDoc
72     {
73         this.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
74         bShowAll.setText(Msg.getMsg(Env.getCtx(), "All"));
75         bShowAll.addActionListener(this);
76         bShowAll.setMargin(s_margin);
77         bShowYear.setText(Msg.getMsg(Env.getCtx(), "Year"));
78         bShowYear.addActionListener(this);
79         bShowYear.setMargin(s_margin);
80         bShowMonth.setText(Msg.getMsg(Env.getCtx(), "Month"));
81         bShowMonth.addActionListener(this);
82         bShowMonth.setMargin(s_margin);
83         bShowWeek.setText(Msg.getMsg(Env.getCtx(), "Week"));
84         bShowWeek.addActionListener(this);
85         bShowWeek.setMargin(s_margin);
86         bShowDay.setText(Msg.getMsg(Env.getCtx(), "Day"));
87         bShowDay.addActionListener(this);
88         bShowDay.setMargin(s_margin);
89         bShowDay.setDefaultCapable(true);
90         //
91
mainPanel.add(bShowDay, null);
92         mainPanel.add(bShowWeek, null);
93         mainPanel.add(bShowMonth, null);
94         mainPanel.add(bShowYear, null);
95         mainPanel.add(bShowAll, null);
96         //
97
mainPanel.setToolTipText(Msg.getMsg(Env.getCtx(), "VOnlyCurrentDays", false));
98         this.getContentPane().add(mainPanel, BorderLayout.CENTER);
99         this.getRootPane().setDefaultButton(bShowDay);
100     } // jbInit
101

102     /**
103      * Action Listener
104      * @param e evant
105      */

106     public void actionPerformed(ActionEvent e)
107     {
108         if (e.getSource() == bShowDay)
109             m_days = 1;
110         else if (e.getSource() == bShowWeek)
111             m_days = 7;
112         else if (e.getSource() == bShowMonth)
113             m_days = 31;
114         else if (e.getSource() == bShowYear)
115             m_days = 356;
116         else
117             m_days = -1;
118         dispose();
119     } // actionPerformed
120

121     /**
122      * Get selected number of days
123      * @return days or -1 for all
124      */

125     public int getCurrentDays()
126     {
127         return m_days;
128     } // getCurrentDays
129

130 } // VOnlyCurrentDays
Popular Tags