Sample listing the IltcLayer and IlvManagerLayer layers of a network component

Article ID: 2149
Last updated: 28 May, 2018
Article ID: 2149
Last updated: 28 May, 2018
Revision: 3
Views: 652
Posted: 14 Jan, 2004
by Dean J.
Updated: 28 May, 2018
by Gargani A.

Question

How to list the IltcLayer and IlvManagerLayer layers of a network component?

Answer

This sample shows an element in a network and lists the layers, both as IltcLayer and as IlvManagerLayer instances. It is possible to hide both types of layer.

import ilog.cpl.IlpNetwork;

import ilog.cpl.graphic.IlpPoint;

import ilog.tgo.composite.IltcLayer;

import ilog.tgo.datasource.IltDefaultDataSource;

import ilog.tgo.graphic.IltCompositeGrapher;

import ilog.tgo.model.IltNetworkElement;

import ilog.tgo.model.IltOSIObjectState;

import ilog.views.IlvLayerVisibilityFilter;

import ilog.views.IlvManager;

import ilog.views.IlvManagerLayer;

import ilog.views.IlvManagerView;

import java.util.Enumeration;

import javax.swing.JFrame;

public class Main {

public static void main(String[] args) {

/* UnComment the following line if using JViews TGO 8.8 or earlier. */

// ilog.views.util.IlvProductUtil.DeploymentLicenseRequired(ilog.views.util.IlvProductUtil.IBM_ILOG_JViews_TGO_Deployment);

IlpNetwork network = new IlpNetwork();

network.setDataSource(createDataSource());

listCompositeLayers(IltCompositeGrapher.FromNetworkView(network.getView()));

listManagerLayers(network.getManagerView().getManager());

createFrame("JTGO Layer Sample", network);

}

static IltDefaultDataSource createDataSource() {

IltDefaultDataSource dataSource = new IltDefaultDataSource();

IltNetworkElement element =

new IltNetworkElement(

"Network Element",

IltNetworkElement.Type.NE,

new IltOSIObjectState());

element.setPosition(new IlpPoint(180f, 170f));

dataSource.addObject(element);

return dataSource;

}

static void listCompositeLayers(IltCompositeGrapher grapher) {

Enumeration enums = grapher.getLayers();

while (enums.hasMoreElements()) {

IltcLayer layer = (IltcLayer) enum.nextElement();

System.out.print("IltcLayer: <" + layer.getName() + ">");

// Uncomment the following line in order to hide all composite layers

// layer.addVisibilityFilter(new InvisibilityFilter());

Enumeration filters = layer.getVisibilityFilters();

while (filters.hasMoreElements()) {

IlvLayerVisibilityFilter filter = (IlvLayerVisibilityFilter) filters.nextElement();

System.out.print(" " + (filter.isVisible(null, null) ? "" : "in") + "visible");

}

System.out.println(".");

}

}

static void listManagerLayers(IlvManager manager) {

for (int i = 0; i < manager.getLayersCount(); i++) {

IlvManagerLayer layer = manager.getManagerLayer(i);

// Uncomment the following line in order to hide all manager layers

// manager.setVisible(i, false, true);

System.out.println(

"IlvManagerLayer "

+ i

+ ": <"

+ layer.getName()

+ "> "

+ (layer.isVisible() ? "" : "in")

+ "visible");

}

}

static JFrame createFrame(String title, IlpNetwork network) {

JFrame frame = new JFrame(title);

frame.getContentPane().add(network);

frame.setLocation(50, 50);

frame.setSize(400, 400);

frame.setVisible(true);

frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

return frame;

}

}

class InvisibilityFilter extends IlvLayerVisibilityFilter {

public boolean isVisible(IlvManagerLayer l, IlvManagerView v) {

return false;

}

public boolean isPersistent() {

return false;

}

}]

This article was:   Helpful | Not helpful
Report an issue
Article ID: 2149
Last updated: 28 May, 2018
Revision: 3
Views: 652
Posted: 14 Jan, 2004 by Dean J.
Updated: 28 May, 2018 by Gargani A.
Also listed in


Others in this category