private void addButtonToPropertySheetPanel() { showAllVPButton = new JToggleButton(); showAllVPButton.setText("Show All"); showAllVPButton.setToolTipText("Show all Visual Properties"); showAllVPButton.setSelected(PropertySheetUtil.isAdvancedMode()); showAllVPButton.setUI(new BlueishButtonUI()); showAllVPButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent ae) { viewModeAction.menuSelected(null); viewModeAction.actionPerformed(null); } }); // This is a hack: get private component and add button. Field[] fields = PropertySheetPanel.class.getDeclaredFields(); for (Field f : fields) { if (f.getName().equals("actionPanel")) { f.setAccessible(true); try { JPanel buttonPanel = (JPanel) f.get(propertySheetPanel); buttonPanel.add(showAllVPButton); } catch (IllegalArgumentException e) { e.printStackTrace(); } catch (IllegalAccessException e) { e.printStackTrace(); } } } }
/** * @param netView * @param view a View<CyNode>, View<CyEdge> or View<CyNetwork> object * @return */ public CyMenuItem build(final CyNetworkView netView, final View<? extends CyIdentifiable> view) { final Class<? extends CyIdentifiable> targetClass = view.getModel().getClass(); final Queue<VisualLexiconNode> queue = new PriorityQueue<VisualLexiconNode>(50, new VisualLexiconNodeComparator()); final Map<VisualLexiconNode, JMenuItem> menuMap = new HashMap<VisualLexiconNode, JMenuItem>(); final JMenu rootJMenu = new JMenu(ROOT_MENU_LABEL); final CyMenuItem rootMenu = new CyMenuItem(rootJMenu, ROOT_GRAVITY); queue.addAll(root.getChildren()); menuMap.put(root, rootMenu.getMenuItem()); // Node size, width and height JMenuItem menuItemNodeSize = null; JMenuItem menuItemNodeWidth = null; JMenuItem menuItemNodeHeight = null; final Set<VisualLexiconNode> nextNodes = new HashSet<VisualLexiconNode>(); while (!queue.isEmpty()) { final VisualLexiconNode curretNode = queue.poll(); final VisualProperty<?> vp = curretNode.getVisualProperty(); if (vp.getTargetDataType().isAssignableFrom(targetClass)) { final Collection<VisualLexiconNode> children = curretNode.getChildren(); nextNodes.addAll(children); final JMenuItem menu; if (children.isEmpty() && PropertySheetUtil.isCompatible(vp)) { final boolean lock = view.isDirectlyLocked(vp); if (lock) { menu = new JMenu(vp.getDisplayName()); final JMenuItem clear = new JMenuItem("Clear"); clear.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { view.clearValueLock(vp); netView.updateView(); } }); final JMenuItem edit = new JMenuItem("Edit Bypass"); edit.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp); } }); menu.add(clear); menu.add(edit); // Update color menu.setForeground(ENABLED_COLOR); menu.setIcon(ENABLED_ICON); menu.setFont(ENABLED_FONT); VisualLexiconNode parent = curretNode.getParent(); while (parent != root) { JMenuItem enabledPath = menuMap.get(parent); enabledPath.setForeground(ENABLED_COLOR); enabledPath.setIcon(ENABLED_ICON); enabledPath.setFont(ENABLED_FONT); parent = parent.getParent(); } rootJMenu.setIcon(ENABLED_ICON); rootJMenu.setForeground(ENABLED_COLOR); rootJMenu.setFont(ENABLED_FONT); vpSet.add(vp); } else { menu = new JMenuItem(vp.getDisplayName()); menu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp); } }); if (vp.getDisplayName() .equalsIgnoreCase(BasicVisualLexicon.NODE_WIDTH.getDisplayName())) { menuItemNodeWidth = menu; } if (vp.getDisplayName() .equalsIgnoreCase(BasicVisualLexicon.NODE_HEIGHT.getDisplayName())) { menuItemNodeHeight = menu; } } } else { menu = new JMenu(vp.getDisplayName()); if (vp.getDisplayName().equalsIgnoreCase(BasicVisualLexicon.NODE_SIZE.getDisplayName())) { menuItemNodeSize = menu; vp_nodeSize = vp; } } if (PropertySheetUtil.isCompatible(vp)) { menuMap.get(curretNode.getParent()).add(menu); menuMap.put(curretNode, menu); } } if (queue.isEmpty()) { queue.addAll(nextNodes); nextNodes.clear(); } } // handle node size if (menuItemNodeSize != null) { // JMenuItem menuItemNodeSize1 = new JMenuItem(vp_nodeSize.getDisplayName()); menuItemNodeSize1.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { applBypassValue(netView, view, vp_nodeSize); } }); menuItemNodeSize.add(menuItemNodeSize1); // Check if nose size is locked boolean nodeSizeIsLocked = false; java.util.Iterator it = vmm.getCurrentVisualStyle().getAllVisualPropertyDependencies().iterator(); while (it.hasNext()) { org.cytoscape.view.vizmap.VisualPropertyDependency dep = (org.cytoscape.view.vizmap.VisualPropertyDependency) it.next(); if (dep.getDisplayName().equalsIgnoreCase("Lock node width and height") && dep.isDependencyEnabled()) { nodeSizeIsLocked = true; } } if (nodeSizeIsLocked) { // In case the Node size is locked, disable menuItem Node_width and Nod_height if (menuItemNodeWidth != null) menuItemNodeWidth.setEnabled(false); if (menuItemNodeHeight != null) menuItemNodeHeight.setEnabled(false); } else { // In case the Node size is not locked, disable menuItem Node_size if (menuItemNodeSize1 != null) menuItemNodeSize1.setEnabled(false); } } final JSeparator separator = new JSeparator(); final JMenuItem resetMenu = new JMenuItem("Reset All"); resetMenu.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { clearAll(netView, view); } }); rootJMenu.add(separator); rootJMenu.add(resetMenu); return rootMenu; }