use of org.netxms.client.maps.MapLayoutAlgorithm in project netxms by netxms.
the class AbstractNetworkMapView method setLayoutAlgorithm.
/**
* Set layout algorithm for map
*
* @param alg Layout algorithm
* @param forceChange
*/
protected void setLayoutAlgorithm(MapLayoutAlgorithm alg, boolean forceChange) {
if (alg == MapLayoutAlgorithm.MANUAL) {
if (!automaticLayoutEnabled)
// manual layout already
return;
automaticLayoutEnabled = false;
// TODO: rewrite, enum value should not be used as index
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
actionEnableAutomaticLayout.setChecked(false);
return;
}
if (automaticLayoutEnabled && (alg == layoutAlgorithm) && !forceChange)
// nothing to change
return;
if (!automaticLayoutEnabled) {
actionEnableAutomaticLayout.setChecked(true);
automaticLayoutEnabled = true;
}
LayoutAlgorithm algorithm;
switch(alg) {
case SPRING:
algorithm = new SpringLayoutAlgorithm();
break;
case RADIAL:
algorithm = new RadialLayoutAlgorithm();
break;
case HTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
break;
case VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
break;
case SPARSE_VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
((TreeLayoutAlgorithm) algorithm).setNodeSpace(new Dimension(100, 100));
break;
default:
algorithm = new GridLayoutAlgorithm();
break;
}
viewer.setLayoutAlgorithm(alwaysFitLayout ? algorithm : new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { algorithm, new ExpansionAlgorithm() }));
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(false);
layoutAlgorithm = alg;
actionSetAlgorithm[layoutAlgorithm.getValue()].setChecked(true);
}
use of org.netxms.client.maps.MapLayoutAlgorithm in project netxms by netxms.
the class NetworkMapWidget method setLayoutAlgorithm.
/**
* Set layout algorithm for map
* @param alg
*/
public void setLayoutAlgorithm(MapLayoutAlgorithm alg) {
LayoutAlgorithm algorithm;
switch(alg) {
case SPRING:
algorithm = new SpringLayoutAlgorithm();
break;
case RADIAL:
algorithm = new RadialLayoutAlgorithm();
break;
case HTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.LEFT_RIGHT);
break;
case VTREE:
algorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
break;
case SPARSE_VTREE:
TreeLayoutAlgorithm mainLayoutAlgorithm = new TreeLayoutAlgorithm(TreeLayoutAlgorithm.TOP_DOWN);
viewer.setComparator(new ViewerComparator() {
@Override
public int compare(Viewer viewer, Object e1, Object e2) {
return e1.toString().compareToIgnoreCase(e2.toString());
}
});
algorithm = new CompositeLayoutAlgorithm(new LayoutAlgorithm[] { mainLayoutAlgorithm, new SparseTree() });
break;
default:
algorithm = new GridLayoutAlgorithm();
break;
}
viewer.setLayoutAlgorithm(algorithm);
}
use of org.netxms.client.maps.MapLayoutAlgorithm in project netxms by netxms.
the class AbstractNetworkMapView method createActions.
/**
* Create actions
*/
protected void createActions() {
final IHandlerService handlerService = (IHandlerService) getSite().getService(IHandlerService.class);
actionRefresh = new RefreshAction(this) {
@Override
public void run() {
refreshMap();
}
};
actionShowLinkDirection = new Action("Show link direction", Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setShowLinkDirection(!labelProvider.isShowLinkDirection());
setChecked(labelProvider.isShowLinkDirection());
updateObjectPositions();
saveLayout();
viewer.refresh();
}
};
actionShowLinkDirection.setChecked(labelProvider.isShowLinkDirection());
actionShowStatusBackground = new Action(Messages.get().AbstractNetworkMapView_ShowStatusBkgnd, Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setShowStatusBackground(!labelProvider.isShowStatusBackground());
setChecked(labelProvider.isShowStatusBackground());
updateObjectPositions();
saveLayout();
viewer.refresh();
}
};
actionShowStatusBackground.setChecked(labelProvider.isShowStatusBackground());
actionShowStatusBackground.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
actionShowStatusIcon = new Action(Messages.get().AbstractNetworkMapView_ShowStatusIcon, Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setShowStatusIcons(!labelProvider.isShowStatusIcons());
setChecked(labelProvider.isShowStatusIcons());
updateObjectPositions();
saveLayout();
viewer.refresh();
}
};
actionShowStatusIcon.setChecked(labelProvider.isShowStatusIcons());
actionShowStatusIcon.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
actionShowStatusFrame = new Action(Messages.get().AbstractNetworkMapView_ShowStatusFrame, Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setShowStatusFrame(!labelProvider.isShowStatusFrame());
setChecked(labelProvider.isShowStatusFrame());
updateObjectPositions();
saveLayout();
viewer.refresh();
}
};
actionShowStatusFrame.setChecked(labelProvider.isShowStatusFrame());
actionShowStatusFrame.setEnabled(labelProvider.getObjectFigureType() == MapObjectDisplayMode.ICON);
actionZoomIn = new Action(Messages.get().AbstractNetworkMapView_ZoomIn, SharedIcons.ZOOM_IN) {
@Override
public void run() {
viewer.zoomIn();
}
};
// $NON-NLS-1$
actionZoomIn.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomIn");
// $NON-NLS-1$
actionZoomIn.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomIn");
handlerService.activateHandler(actionZoomIn.getActionDefinitionId(), new ActionHandler(actionZoomIn));
actionZoomOut = new Action(Messages.get().AbstractNetworkMapView_ZoomOut, SharedIcons.ZOOM_OUT) {
@Override
public void run() {
viewer.zoomOut();
}
};
// $NON-NLS-1$
actionZoomOut.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomOut");
// $NON-NLS-1$
actionZoomOut.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomOut");
handlerService.activateHandler(actionZoomOut.getActionDefinitionId(), new ActionHandler(actionZoomOut));
actionZoomFit = new // $NON-NLS-1$
Action(// $NON-NLS-1$
Messages.get().AbstractNetworkMapView_ZoomFit, // $NON-NLS-1$
Activator.getImageDescriptor("icons/fit.png")) {
@Override
public void run() {
viewer.zoomFit();
}
};
// $NON-NLS-1$
actionZoomFit.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ZoomToFit");
// $NON-NLS-1$
actionZoomFit.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ZoomToFit");
handlerService.activateHandler(actionZoomFit.getActionDefinitionId(), new ActionHandler(actionZoomFit));
actionZoomTo = viewer.createZoomActions(handlerService);
actionSetAlgorithm = new Action[layoutAlgorithmNames.length];
for (int i = 0; i < layoutAlgorithmNames.length; i++) {
final MapLayoutAlgorithm alg = MapLayoutAlgorithm.getByValue(i);
actionSetAlgorithm[i] = new Action(layoutAlgorithmNames[i], Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setLayoutAlgorithm(alg, true);
viewer.setInput(mapPage);
}
};
actionSetAlgorithm[i].setChecked(layoutAlgorithm.getValue() == i);
actionSetAlgorithm[i].setEnabled(automaticLayoutEnabled);
}
actionAlwaysFitLayout = new Action(Messages.get().AbstractNetworkMapView_AlwaysFitLayout, Action.AS_CHECK_BOX) {
@Override
public void run() {
alwaysFitLayout = actionAlwaysFitLayout.isChecked();
setLayoutAlgorithm(layoutAlgorithm, true);
IDialogSettings settings = Activator.getDefault().getDialogSettings();
// $NON-NLS-1$
settings.put(viewId + ".alwaysFitLayout", alwaysFitLayout);
}
};
actionAlwaysFitLayout.setChecked(alwaysFitLayout);
actionSetRouter = new Action[connectionRouterNames.length];
for (int i = 0; i < connectionRouterNames.length; i++) {
final int alg = i + 1;
actionSetRouter[i] = new Action(connectionRouterNames[i], Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setConnectionRouter(alg, true);
}
};
actionSetRouter[i].setChecked(routingAlgorithm == alg);
}
actionEnableAutomaticLayout = new Action(Messages.get().AbstractNetworkMapView_EnableAutoLayout, Action.AS_CHECK_BOX) {
@Override
public void run() {
if (automaticLayoutEnabled) {
setManualLayout();
} else {
setAutomaticLayout();
}
setChecked(automaticLayoutEnabled);
}
};
actionEnableAutomaticLayout.setChecked(automaticLayoutEnabled);
actionSaveLayout = new Action(Messages.get().AbstractNetworkMapView_SaveLayout) {
@Override
public void run() {
updateObjectPositions();
saveLayout();
}
};
actionSaveLayout.setImageDescriptor(SharedIcons.SAVE);
actionSaveLayout.setEnabled(!automaticLayoutEnabled);
actionOpenDrillDownObject = new Action("Open drill-down object") {
@Override
public void run() {
openDrillDownObject();
}
};
actionOpenDrillDownObject.setEnabled(false);
actionFiguresIcons = new Action(Messages.get().AbstractNetworkMapView_Icons, Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setObjectDisplayMode(MapObjectDisplayMode.ICON, true);
}
};
actionFiguresSmallLabels = new Action(Messages.get().AbstractNetworkMapView_SmallLabels, Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setObjectDisplayMode(MapObjectDisplayMode.SMALL_LABEL, true);
}
};
actionFiguresLargeLabels = new Action(Messages.get().AbstractNetworkMapView_LargeLabels, Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setObjectDisplayMode(MapObjectDisplayMode.LARGE_LABEL, true);
}
};
actionFiguresStatusIcons = new Action(Messages.get().AbstractNetworkMapView_StatusIcons, Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setObjectDisplayMode(MapObjectDisplayMode.STATUS, true);
}
};
actionFiguresFloorPlan = new Action("Floor plan", Action.AS_RADIO_BUTTON) {
@Override
public void run() {
setObjectDisplayMode(MapObjectDisplayMode.FLOOR_PLAN, true);
}
};
actionShowGrid = new Action(Messages.get().AbstractNetworkMapView_ShowGrid, Action.AS_CHECK_BOX) {
@Override
public void run() {
viewer.showGrid(actionShowGrid.isChecked());
}
};
// $NON-NLS-1$
actionShowGrid.setImageDescriptor(Activator.getImageDescriptor("icons/grid.png"));
actionShowGrid.setChecked(viewer.isGridVisible());
// $NON-NLS-1$
actionShowGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.ShowGrid");
// $NON-NLS-1$
actionShowGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.ShowGrid");
handlerService.activateHandler(actionShowGrid.getActionDefinitionId(), new ActionHandler(actionShowGrid));
actionSnapToGrid = new Action(Messages.get().AbstractNetworkMapView_SnapToGrid, Action.AS_CHECK_BOX) {
@Override
public void run() {
viewer.setSnapToGrid(actionSnapToGrid.isChecked());
}
};
// $NON-NLS-1$
actionSnapToGrid.setImageDescriptor(Activator.getImageDescriptor("icons/snap_to_grid.png"));
actionSnapToGrid.setChecked(viewer.isSnapToGrid());
actionAlignToGrid = new // $NON-NLS-1$
Action(// $NON-NLS-1$
Messages.get().AbstractNetworkMapView_AlignToGrid, // $NON-NLS-1$
Activator.getImageDescriptor("icons/align_to_grid.gif")) {
@Override
public void run() {
viewer.alignToGrid(false);
updateObjectPositions();
}
};
// $NON-NLS-1$
actionAlignToGrid.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.AlignToGrid");
// $NON-NLS-1$
actionAlignToGrid.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.AlignToGrid");
handlerService.activateHandler(actionAlignToGrid.getActionDefinitionId(), new ActionHandler(actionAlignToGrid));
actionShowObjectDetails = new Action(Messages.get().AbstractNetworkMapView_ShowObjDetails) {
@Override
public void run() {
showObjectDetails();
}
};
actionHideLinkLabels = new Action(Messages.get().AbstractNetworkMapView_HideLinkLabels, Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setConnectionLabelsVisible(!actionHideLinkLabels.isChecked());
viewer.refresh(true);
}
};
// $NON-NLS-1$
actionHideLinkLabels.setImageDescriptor(Activator.getImageDescriptor("icons/hide_link.png"));
actionHideLinks = new Action(Messages.get().AbstractNetworkMapView_HideLinks, Action.AS_CHECK_BOX) {
@Override
public void run() {
labelProvider.setConnectionsVisible(!actionHideLinks.isChecked());
viewer.refresh(true);
}
};
// $NON-NLS-1$
actionHideLinks.setImageDescriptor(Activator.getImageDescriptor("icons/hide_net_link.png"));
actionSelectAllObjects = new Action(Messages.get().AbstractNetworkMapView_SelectAllObjects) {
@Override
public void run() {
viewer.setSelection(new StructuredSelection(mapPage.getObjectElements()));
}
};
// $NON-NLS-1$
actionSelectAllObjects.setId("org.netxms.ui.eclipse.networkmaps.localActions.AbstractMap.SelectAllObjects");
// $NON-NLS-1$
actionSelectAllObjects.setActionDefinitionId("org.netxms.ui.eclipse.networkmaps.localCommands.AbstractMap.SelectAllObjects");
handlerService.activateHandler(actionSelectAllObjects.getActionDefinitionId(), new ActionHandler(actionSelectAllObjects));
actionLockLink = new Action("Locked") {
@Override
public void run() {
changeLinkLock();
}
};
}
Aggregations