📄 reservationeditimpl.java
字号:
/*--------------------------------------------------------------------------*
| Copyright (C) 2006 Christopher Kohlhaas |
| |
| This program is free software; you can redistribute it and/or modify |
| it under the terms of the GNU General Public License as published by the |
| Free Software Foundation. A copy of the license has been included with |
| these distribution in the COPYING file, if not go to www.fsf.org |
| |
| As a special exception, you are granted the permissions to link this |
| program with every library, which license fulfills the Open Source |
| Definition as published by the Open Source Initiative (OSI). |
*--------------------------------------------------------------------------*/
package org.rapla.gui.internal.edit.reservation;
import java.awt.BorderLayout;
import java.awt.Cursor;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.KeyEvent;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyVetoException;
import java.beans.VetoableChangeListener;
import java.util.Date;
import javax.swing.AbstractAction;
import javax.swing.BorderFactory;
import javax.swing.JPanel;
import javax.swing.JToolBar;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import org.apache.avalon.framework.container.ContainerUtil;
import org.rapla.components.layout.TableLayout;
import org.rapla.components.util.Command;
import org.rapla.entities.domain.Appointment;
import org.rapla.entities.domain.RepeatingType;
import org.rapla.entities.domain.Reservation;
import org.rapla.entities.domain.ReservationHelper;
import org.rapla.facade.ModificationEvent;
import org.rapla.framework.RaplaContext;
import org.rapla.framework.RaplaException;
import org.rapla.gui.RaplaGUIComponent;
import org.rapla.gui.ReservationController;
import org.rapla.gui.ReservationEdit;
import org.rapla.gui.toolkit.DialogUI;
import org.rapla.gui.toolkit.EmptyLineBorder;
import org.rapla.gui.toolkit.RaplaButton;
import org.rapla.gui.toolkit.RaplaFrame;
class ReservationEditImpl extends RaplaGUIComponent implements ReservationEdit
{
protected Reservation mutableReservation;
JToolBar toolBar = new JToolBar();
RaplaButton saveButton = new RaplaButton();
RaplaButton deleteButton = new RaplaButton();
RaplaButton closeButton = new RaplaButton();
JPanel mainContent = new JPanel();
//JPanel split = new JSplitPane(JSplitPane.VERTICAL_SPLIT);
RaplaFrame frame;
ReservationInfoEdit reservationInfo;
AppointmentListEdit appointmentEdit ;
AllocatableSelection allocatableEdit;
boolean bSaving = false;
boolean bDeleting = false;
boolean bSaved;
boolean bNew;
TableLayout tableLayout = new TableLayout(new double[][] {
{TableLayout.FILL}
,{TableLayout.PREFERRED,TableLayout.PREFERRED,TableLayout.FILL}
} );
private Listener listener = new Listener();
ReservationEditImpl(RaplaContext sm) throws RaplaException {
super( sm);
reservationInfo = new ReservationInfoEdit(sm);
appointmentEdit = new AppointmentListEdit(sm);
allocatableEdit = new AllocatableSelection(sm,true);
// horizontalSplit.setTopComponent(appointmentEdit.getComponent());
//horizontalSplit.setBottomComponent(allocatableEdit.getComponent());
/*
try {
// If run on jdk < 1.3 this will throw a MethodNotFoundException
// horizontalSplit.setResizeWeight(0.1);
JSplitPane.class.getMethod("setResizeWeight",new Class[] {double.class}).invoke(horizontalSplit,new Object[] {new Double(0.1)});
} catch (Exception ex) {
}
*/
frame = new RaplaFrame(sm);
mainContent.setLayout( tableLayout );
mainContent.add(reservationInfo.getComponent(),"0,0");
mainContent.add(appointmentEdit.getComponent(),"0,1");
mainContent.add(allocatableEdit.getComponent(),"0,2");
//allocatableEdit.getComponent().setVisible(false);
saveButton.setAction( listener );
toolBar.setFloatable(false);
toolBar.add( saveButton);
toolBar.add( deleteButton);
toolBar.add( closeButton);
deleteButton.setAction( listener );
closeButton.addActionListener(listener);
appointmentEdit.addAppointmentListener(allocatableEdit);
appointmentEdit.addAppointmentListener(listener);
allocatableEdit.addChangeListener(listener);
reservationInfo.addChangeListener(listener);
reservationInfo.addDetailListener(listener);
frame.addVetoableChangeListener(listener);
frame.setIconImage( getI18n().getIcon("icon.edit_window_small").getImage());
JPanel contentPane = (JPanel) frame.getContentPane();
contentPane.setLayout(new BorderLayout());
mainContent.setBorder(BorderFactory.createLoweredBevelBorder());
contentPane.add(toolBar, BorderLayout.NORTH);
contentPane.add(mainContent, BorderLayout.CENTER);
Dimension dimension = java.awt.Toolkit.getDefaultToolkit().getScreenSize();
frame.setSize(new Dimension(
Math.min(dimension.width,860)
,Math.min(dimension.height-10,700)
)
);
Border emptyLineBorder = new EmptyLineBorder();
//BorderFactory.createEmptyBorder();
Border border2 = BorderFactory.createTitledBorder(emptyLineBorder,getString("reservation.appointments"));
Border border3 = BorderFactory.createTitledBorder(emptyLineBorder,getString("reservation.allocations"));
appointmentEdit.getComponent().setBorder(border2);
allocatableEdit.getComponent().setBorder(border3);
saveButton.setText(getString("save"));
saveButton.setMnemonic(KeyEvent.VK_S);
saveButton.setIcon(getIcon("icon.save"));
deleteButton.setText(getString("delete"));
deleteButton.setIcon(getIcon("icon.delete"));
closeButton.setText(getString("abort"));
closeButton.setIcon(getIcon("icon.abort"));
}
protected void setSaved(boolean flag) {
bSaved = flag;
saveButton.setEnabled(!flag);
}
/* (non-Javadoc)
* @see org.rapla.gui.edit.reservation.IReservationEdit#isModifiedSinceLastChange()
*/
public boolean isModifiedSinceLastChange() {
return !bSaved;
}
final private ReservationControllerImpl getPrivateReservationController() {
return (ReservationControllerImpl) getService(ReservationController.ROLE);
}
/* (non-Javadoc)
* @see org.rapla.gui.edit.reservation.IReservationEdit#addAppointment(java.util.Date, java.util.Date, java.lang.String, int)
*/
public void addAppointment(Date start, Date end, RepeatingType repeatingType, int repeatings) throws RaplaException {
Appointment appointment = getModification().newAppointment( start, end );
if ( repeatingType != null ) {
ReservationHelper.makeRepeatingForPeriod( getPeriodModel(),appointment, repeatingType , repeatings);
}
mutableReservation.addAppointment(appointment);
setReservation( mutableReservation, appointment );
setSaved(false);
frame.requestFocus();
}
void deleteReservation() throws RaplaException {
if (bDeleting)
return;
getLogger().debug("Reservation has been deleted.");
DialogUI dlg = DialogUI.create(
getContext()
,mainContent
,true
,getString("warning")
,getString("warning.reservation.delete")
);
dlg.setIcon(getIcon("icon.warning"));
dlg.start();
closeWindow();
}
void updateReservation(Reservation newReservation) throws RaplaException {
if (bSaving)
return;
getLogger().debug("Reservation has been changed.");
DialogUI dlg = DialogUI.create(
getContext()
,mainContent
,true
,getString("warning")
,getString("warning.reservation.update")
);
try {
dlg.setIcon(getIcon("icon.warning"));
dlg.start();
setReservation((Reservation) getModification().edit(newReservation) , null);
} catch (RaplaException ex) {
showException(ex,frame);
}
}
void refresh(ModificationEvent evt) throws RaplaException {
allocatableEdit.refresh(evt);
}
void editReservation(Reservation mutableReservation, Appointment appointment, boolean bNew) throws RaplaException {
setSaved(!bNew);
//printBlocks( appointment );
this.bNew = bNew;
deleteButton.setEnabled(!bNew);
setReservation(mutableReservation, appointment);
setTitle();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -