001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.client.gui.access;
019:
020: import java.awt.FlowLayout;
021: import java.awt.Font;
022: import java.awt.HeadlessException;
023: import java.awt.LayoutManager;
024: import java.awt.event.ActionEvent;
025: import java.awt.event.ActionListener;
026: import java.util.Date;
027:
028: import javax.swing.Box;
029: import javax.swing.BoxLayout;
030: import javax.swing.ButtonGroup;
031: import javax.swing.JButton;
032: import javax.swing.JDialog;
033: import javax.swing.JFrame;
034: import javax.swing.JPanel;
035: import javax.swing.JRadioButton;
036: import javax.swing.JTextArea;
037:
038: import de.finix.contelligent.client.i18n.Resources;
039: import de.finix.contelligent.client.security.ComponentAccess;
040: import de.finix.contelligent.client.util.DateChooser;
041: import de.finix.contelligent.client.util.TableLayout;
042:
043: public class TimeDialog extends JDialog implements ActionListener {
044:
045: private Font headerFont = Font.decode("Arial-BOLD-12");
046:
047: private boolean result = false;
048:
049: private JRadioButton startOff;
050:
051: private JRadioButton startOn;
052:
053: private JRadioButton endOff;
054:
055: private JRadioButton endOn;
056:
057: private DateChooser startChooser;
058:
059: private DateChooser endChooser;
060:
061: private ComponentAccess access;
062:
063: public TimeDialog(ComponentAccess accessParam, JFrame owner)
064: throws HeadlessException {
065: super (owner, true); // Proper modal behaviour on Windows needs the owner
066: // to be set here
067:
068: access = accessParam;
069:
070: this .setTitle(Resources.getLocalString("acl_time_header"));
071: this .setSize(450, 405);
072: setLocationRelativeTo(owner); // Do this after setting the size or the
073: // position will be off
074:
075: LayoutManager tableLayout = new TableLayout(new String[][] {
076: { "10", "PREFERRED", "5", "PREFERRED", "FILL" },
077: { "15", "PREFERRED=acl", "10", "PREFERRED=headers",
078: "10", "PREFERRED=option1", "5",
079: "PREFERRED=option2", "5", "PREFERRED=details",
080: "15", "PREFERRED=buttons", "15", "FILL" } });
081: getContentPane().setLayout(tableLayout);
082:
083: StringBuffer aclText = new StringBuffer(Resources
084: .getLocalString("acl_time_description"));
085: aclText.append(" [");
086: aclText.append(access.getPrincipal().getGroupId());
087: aclText.append(":");
088: aclText.append(access.getPrincipal().getId());
089: aclText.append(" - ");
090: aclText.append(access.getPermissionDisplayName());
091: aclText.append(" - ");
092: aclText.append(access.getVisibleModeDisplayName());
093: aclText.append("]");
094: getContentPane().add(
095: buildText(aclText.toString(), headerFont, true),
096: "1, acl, 3, 1");
097:
098: getContentPane().add(
099: buildText("acl_time_starttime", headerFont),
100: "1, headers");
101: ButtonGroup startButtons = new ButtonGroup();
102: startOff = new JRadioButton(Resources
103: .getLocalString("acl_time_startoff"));
104: startOn = new JRadioButton(Resources
105: .getLocalString("acl_time_starton"));
106: startButtons.add(startOff);
107: startButtons.add(startOn);
108: getContentPane().add(startOff, "1, option1");
109: getContentPane().add(startOn, "1, option2");
110: startChooser = new DateChooser();
111: startChooser.select(new Date(access.getValidFrom()));
112: getContentPane().add(startChooser, "1, details");
113: if (access.getValidFrom() == -1) {
114: startOff.setSelected(true);
115: startChooser.setEnabled(false);
116: } else {
117: startOn.setSelected(true);
118: }
119: startOff.addActionListener(this );
120: startOn.addActionListener(this );
121:
122: getContentPane().add(buildText("acl_time_endtime", headerFont),
123: "3, headers");
124: ButtonGroup endButtons = new ButtonGroup();
125: endOff = new JRadioButton(Resources
126: .getLocalString("acl_time_endoff"));
127: endOn = new JRadioButton(Resources
128: .getLocalString("acl_time_endon"));
129: endButtons.add(endOff);
130: endButtons.add(endOn);
131: getContentPane().add(endOff, "3, option1");
132: getContentPane().add(endOn, "3, option2");
133: endChooser = new DateChooser();
134: endChooser.select(new Date(access.getValidTo()));
135: getContentPane().add(endChooser, "3, details");
136: if (access.getValidTo() == -1) {
137: endOff.setSelected(true);
138: endChooser.setEnabled(false);
139: } else {
140: endOn.setSelected(true);
141: }
142: endOff.addActionListener(this );
143: endOn.addActionListener(this );
144:
145: JButton okButton = new JButton(Resources.getLocalString("ok"));
146: okButton.addActionListener(new ActionListener() {
147: public void actionPerformed(ActionEvent arg0) {
148: if (startOn.isSelected()) {
149: access.setValidFrom(startChooser.getDate()
150: .getTime());
151: } else {
152: access.setValidFrom(-1);
153: }
154: if (endOn.isSelected()) {
155: access.setValidTo(endChooser.getDate().getTime());
156: } else {
157: access.setValidTo(-1);
158: }
159: result = true;
160: TimeDialog.this .setVisible(false);
161: }
162: });
163: JButton cancelButton = new JButton(Resources
164: .getLocalString("cancel"));
165: cancelButton.addActionListener(new ActionListener() {
166: public void actionPerformed(ActionEvent arg0) {
167: result = false;
168: TimeDialog.this .setVisible(false);
169: }
170: });
171: JPanel buttonPanel = new JPanel();
172: buttonPanel.setOpaque(false);
173: buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT));
174: buttonPanel.add(okButton);
175: buttonPanel.add(cancelButton);
176: getContentPane().add(buttonPanel, "1, buttons, 3, 1");
177: }
178:
179: private JPanel buildText(String text, Font font) {
180: return buildText(text, font, false);
181: }
182:
183: private JPanel buildText(String text, Font font,
184: boolean preLocalized) {
185: JPanel textPanel = new JPanel();
186: textPanel.setOpaque(false);
187: textPanel.setLayout(new BoxLayout(textPanel, BoxLayout.X_AXIS));
188: if (!preLocalized) {
189: text = Resources.getLocalString(text);
190: }
191: JTextArea label = new JTextArea(text);
192: label.setOpaque(false);
193: label.setLineWrap(true);
194: label.setWrapStyleWord(true);
195: label.setEditable(false);
196: label.setFocusable(false);
197: label.setFont(font);
198: textPanel.add(label);
199: textPanel.add(Box.createHorizontalGlue());
200: return textPanel;
201: }
202:
203: public boolean getResult() {
204: return result;
205: }
206:
207: // ActionListener method for the radio buttons
208: public void actionPerformed(ActionEvent e) {
209: Object src = e.getSource();
210: if (src == startOff) {
211: startChooser.setEnabled(false);
212: } else if (src == startOn) {
213: startChooser.setEnabled(true);
214: if (endOff.isSelected()) {
215: startChooser.select(new Date());
216: } else {
217: startChooser.select(endChooser.getDate());
218: }
219: } else if (src == endOff) {
220: endChooser.setEnabled(false);
221: } else if (src == endOn) {
222: endChooser.setEnabled(true);
223: if (startOff.isSelected()) {
224: endChooser.select(new Date());
225: } else {
226: endChooser.select(startChooser.getDate());
227: }
228: }
229: }
230:
231: }
|