📄 allocatableselection.java
字号:
}
public void mouseReleased(MouseEvent evt) {
showComp();
}
public void mousePressed(MouseEvent evt) {}
public void mouseClicked(MouseEvent evt) {}
public void mouseEntered(MouseEvent evt) {}
public void mouseExited(MouseEvent evt) {}
public void keyPressed(KeyEvent evt) {}
public void keyTyped(KeyEvent evt) {}
public void keyReleased(KeyEvent evt) {
showComp();
}
public void actionPerformed(ActionEvent evt) {
updateRestriction(Integer.valueOf(evt.getActionCommand()).intValue());
fireEditingStopped();
selectedTable.requestFocus();
}
public void popupMenuWillBecomeVisible(PopupMenuEvent e) {
bStopEditingCalled=false;
}
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) {
if (!bStopEditingCalled) {
AppointmentCellEditor.super.stopCellEditing();
}
}
public void popupMenuCanceled(PopupMenuEvent e) {
// BUGID: 4234793
// This method is never called
}
SmallIntMap appointmentList = new SmallIntMap();
JMenuItem allMenu = new JRadioButtonMenuItem();
private void showComp() {
Object selectedObject = selectedNode.getUserObject();
Allocatable allocatable = null;
if ( selectedObject instanceof Allocatable) {
allocatable = (Allocatable) selectedObject;
calcConflictingAppointments( allocatable );
}
Icon conflictIcon = getI18n().getIcon("icon.allocatable_taken");
allMenu.setText(getString("every_appointment"));
appointmentList.clear();
menu.removeAll();
allMenu.setActionCommand("-1");
allMenu.addActionListener(this);
menu.add(new JMenuItem(getString("cancel")));
menu.add(new JSeparator());
menu.add(allMenu);
menu.add(new JSeparator());
for (int i=0;i<appointments.length;i++) {
JMenuItem item = new JCheckBoxMenuItem();
// set conflicting icon if appointment causes conflicts
String appointmentSummary = getAppointmentFormater().getShortSummary(appointments[i]);;
if ( allocatable != null && conflictingAppointments[i])
{
item.setText( appointmentSummary );
item.setIcon( conflictIcon );
} else {
item.setText( (i + 1)+ ": " + appointmentSummary );
}
appointmentList.put(i,item);
item.setBackground(RaplaColorList.getAppointmentColor(i));
item.setActionCommand(String.valueOf(i));
item.addActionListener(this);
menu.add(item);
}
for (int i=0;i<appointments.length;i++) {
((JMenuItem)appointmentList.get(i)).setSelected(false);
}
Appointment[] apps = restriction;
((JMenuItem)allMenu).setSelected(apps.length == 0);
for (int i=0;i<apps.length;i++) {
// System.out.println("Select " + indexOf(apps[i]));
((JMenuItem)appointmentList.get(indexOf(apps[i]))).setSelected(true);
}
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
Dimension menuSize = menu.getPreferredSize();
Point location = editingComponent.getLocationOnScreen();
int diffx= Math.min(0,screenSize.width - (location.x + menuSize.width));
int diffy= Math.min(0,screenSize.height - (location.y + menuSize.height));
menu.show(editingComponent,diffx,diffy);
}
private void setRestriction(Appointment[] restriction) {
this.restriction = restriction;
}
/** select or deselect the appointment at the given index */
private void updateRestriction(int index) {
if (index <0) {
restriction = Appointment.EMPTY_ARRAY;
} else {
Collection newAppointments = new ArrayList();
// get the selected appointments
// add all previous selected appointments, except the appointment that
// is clicked
for (int i=0;i< restriction.length;i++)
if (!restriction[i] .equals(appointments[index])) {
newAppointments.add(restriction[i]);
}
// If the clicked appointment was selected then deselect
// otherwise select ist
if (!containsAppointment(appointments[index]))
newAppointments.add(appointments[index]);
restriction = (Appointment[]) newAppointments.toArray(Appointment.EMPTY_ARRAY);
}
// Workaround for JDK 1.4 Bug ID: 4234793
// We have to change the table-model after cell-editing stopped
selectedModel.setValueAt(restriction,selectedNode,selectedColumn);
}
private boolean containsAppointment(Appointment appointment) {
for (int i=0;i<restriction.length;i++)
if (restriction[i].equals ( appointment ))
return true;
return false;
}
public Component getTableCellEditorComponent(JTable table,
Object value,
boolean isSelected,
int row,
int column) {
Component component = super.getTableCellEditorComponent(table,value,isSelected,row,column);
if (value instanceof Appointment[]) {
setRestriction((Appointment[]) value);
((RestrictionTextField)component).setText("");
}
((RestrictionTextField)component).setValue(value);
// Workaround for JDK 1.4 Bug ID: 4234793
// We have to change the table-model after cell-editing stopped
this.selectedNode = (DefaultMutableTreeNode)selectedTable.getTree().getPathForRow(row).getLastPathComponent();
this.selectedColumn = column;
return component;
}
public Object getCellEditorValue() {
return restriction;
}
public boolean shouldSelectCell(EventObject event) {
return true;
}
public boolean isCellEditable(EventObject event) {
return true;
}
public boolean stopCellEditing() {
bStopEditingCalled = true;
boolean bResult = super.stopCellEditing();
menu.setVisible(false);
return bResult;
}
}
class AllocationTreeCellRenderer extends DefaultTreeCellRenderer {
private static final long serialVersionUID = 1L;
Icon conflictIcon;
Icon freeIcon;
Icon notAlwaysAvailableIcon;
Icon personIcon;
Icon personNotAlwaysAvailableIcon;
Icon forbiddenIcon;
boolean checkRestrictions;
public AllocationTreeCellRenderer(boolean checkRestrictions) {
forbiddenIcon = getI18n().getIcon("icon.no_perm");
conflictIcon = getI18n().getIcon("icon.allocatable_taken");
freeIcon = getI18n().getIcon("icon.allocatable_available");
notAlwaysAvailableIcon = getI18n().getIcon("icon.allocatable_not_always_available");
personIcon = getI18n().getIcon("icon.tree.persons");
personNotAlwaysAvailableIcon = getI18n().getIcon("icon.tree.person_not_always_available");
this.checkRestrictions = checkRestrictions;
setOpenIcon( getI18n().getIcon("icon.folder"));
setClosedIcon( getI18n().getIcon("icon.folder"));
setLeafIcon(freeIcon);
}
public Icon getAvailableIcon(Allocatable allocatable) {
if (allocatable.isPerson())
return personIcon;
else
return freeIcon;
}
public Icon getNotAlwaysAvailableIcon(Allocatable allocatable) {
if (allocatable.isPerson())
return personNotAlwaysAvailableIcon;
else
return notAlwaysAvailableIcon;
}
private Icon getIcon(Allocatable allocatable) {
calcConflictingAppointments( allocatable );
if ( conflictCount == 0 ) {
return getAvailableIcon( allocatable );
} else if ( conflictCount == appointments.length ) {
if ( conflictCount == permissionConflictCount ) {
if (!checkRestrictions) {
return forbiddenIcon;
}
} else {
return conflictIcon;
}
} else if ( !checkRestrictions ) {
return getNotAlwaysAvailableIcon( allocatable ) ;
}
for ( int i = 0 ; i < appointments.length; i++ ) {
Appointment appointment = appointments[i];
if ( mutableReservation.hasAllocated( allocatable, appointment ) &&
!getQuery().hasPermissionToAllocate( appointment,allocatable )) {
return forbiddenIcon;
}
}
if ( permissionConflictCount - conflictCount == 0 ) {
return getAvailableIcon( allocatable );
}
Appointment[] restriction =
mutableReservation.getRestriction(allocatable);
if ( restriction.length == 0 ) {
return conflictIcon;
} else {
boolean conflict = false;
for (int i = 0 ;i < restriction.length;i++) {
Set allocatables = (Set)appointmentMap.get( restriction[i]);
if (allocatables.contains(allocatable)) {
conflict = true;
break;
}
}
if ( conflict )
return conflictIcon;
else
return getNotAlwaysAvailableIcon(allocatable);
}
}
public Component getTreeCellRendererComponent(JTree tree, Object value,
boolean sel, boolean expanded,
boolean leaf,int row,boolean hasFocus) {
DefaultMutableTreeNode node = (DefaultMutableTreeNode)value;
Object nodeInfo = node.getUserObject();
if (nodeInfo != null && nodeInfo instanceof Named) {
value = ((Named)nodeInfo).getName(getI18n().getLocale());
}
if ( leaf ) {
if (nodeInfo instanceof Allocatable) {
setLeafIcon( getIcon((Allocatable)nodeInfo) );
}
}
Component result = super.getTreeCellRendererComponent(tree, value,
sel, expanded,
leaf, row, hasFocus);
return result;
}
}
class AllocatableAction extends AbstractAction {
private static final long serialVersionUID = 1L;
String command;
AllocatableAction(String command) {
this.command = command;
if (command.equals("add")) {
putValue(NAME,getString("add") );
putValue(SMALL_ICON, getIcon("icon.arrow_right"));
}
if (command.equals("remove")) {
putValue(NAME, getString("remove"));
putValue(SMALL_ICON, getIcon("icon.arrow_left"));
}
if (command.equals("calendar1") || command.equals("calendar2")) {
putValue(NAME,getString("calendar"));
putValue(SMALL_ICON,getIcon("icon.calendar"));
}
}
public void actionPerformed(ActionEvent evt) {
try {
if (command.equals("add")) {
add( getSelectedAllocatables( completeTable.getTree() ) );
}
if (command.equals("remove")) {
remove( getSelectedAllocatables( selectedTable.getTree() ) );
}
if (command.indexOf("calendar")>=0) {
JTree tree = (command.equals("calendar1") ? completeTable.getTree(): selectedTable.getTree());
CalendarAction calendarAction =new CalendarAction(getContext(),getComponent(),calendarModel);
calendarAction.changeObjects(new ArrayList(getSelectedElements( tree, false )));
calendarAction.setStart(findFirstStart());
calendarAction.actionPerformed(evt);
}
} catch (RaplaException ex) {
showException(ex,content);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -