public void setCurrentPreset(PreviewPreset preset) {
   if (model != null) {
     model.setCurrentPreset(preset);
     PreviewModel previewModel = previewController.getModel();
     previewModel.getProperties().applyPreset(preset);
   }
 }
  public void initTarget(PreviewUIModel previewUIModel) {
    // inits the preview applet
    if (previewUIModel != null && target == null) {
      PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
      Color background =
          previewController
              .getModel()
              .getProperties()
              .getColorValue(PreviewProperty.BACKGROUND_COLOR);
      if (background != null) {
        setBackgroundColor(background);
      }

      target = (ProcessingTarget) previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET);
      if (target != null) {
        sketch = target.getApplet();
        sketch.init();
        sketch.registerPost(processingListener);
        sketch.registerPre(processingListener);
        sketchPanel.add(sketch, BorderLayout.CENTER);
      }
    } else if (previewUIModel == null) {
      sketchPanel.remove(sketch);
      target = null;
    }
  }
Beispiel #3
0
 /** Sets current renderers enabled state and order to the preview model. */
 private void updateModelManagedRenderers() {
   PreviewModel model = previewController.getModel();
   if (model != null) {
     ArrayList<ManagedRenderer> managedRenderers = new ArrayList<>();
     for (RendererCheckBox rendererCheckBox : renderersList) {
       managedRenderers.add(
           new ManagedRenderer(rendererCheckBox.renderer, rendererCheckBox.isSelected()));
     }
     model.setManagedRenderers(managedRenderers.toArray(new ManagedRenderer[0]));
   }
 }
 public void savePreset(String name) {
   if (model != null) {
     PreviewModel previewModel = previewController.getModel();
     Map<String, Object> map = new HashMap<String, Object>();
     for (PreviewProperty p : previewModel.getProperties().getProperties()) {
       map.put(p.getName(), p.getValue());
     }
     PreviewPreset preset = new PreviewPreset(name, map);
     presetUtils.savePreset(preset);
     model.setCurrentPreset(preset);
   }
 }
Beispiel #5
0
 /** Obtain renderers enabled state and order from the preview model. */
 private void loadModelManagedRenderers() {
   renderersList.clear();
   PreviewModel model = previewController.getModel();
   if (model != null) {
     if (model.getManagedRenderers() != null) {
       for (ManagedRenderer mr : model.getManagedRenderers()) {
         renderersList.add(new RendererCheckBox(mr.getRenderer(), mr.isEnabled()));
       }
     } else {
       restoreRenderersList();
     }
   }
 }
Beispiel #6
0
 /** Restores the original order of the renderers list, preserving their enabled state. */
 private void restoreRenderersList() {
   PreviewModel model = previewController.getModel();
   Set<Renderer> enabledRenderers = null;
   if (model != null && model.getManagedRenderers() != null) {
     enabledRenderers = new HashSet<>();
     enabledRenderers.addAll(Arrays.asList(model.getManagedEnabledRenderers()));
   }
   renderersList.clear();
   for (Renderer r : previewController.getRegisteredRenderers()) {
     renderersList.add(
         new RendererCheckBox(r, enabledRenderers == null || enabledRenderers.contains(r)));
   }
   updateModelManagedRenderers();
 }
  public void setup(PreviewUIModel previewModel) {
    propertySheet.setNodes(new Node[] {new PreviewNode(propertySheet)});
    PreviewUIController previewUIController = Lookup.getDefault().lookup(PreviewUIController.class);
    if (previewModel != null) {
      ratioSlider.setValue((int) (previewModel.getVisibilityRatio() * 100));
    }

    // Presets
    if (previewModel == null) {
      saveButton.setEnabled(false);
      labelPreset.setEnabled(false);
      presetComboBox.setEnabled(false);
      presetComboBox.setModel(new javax.swing.DefaultComboBoxModel(new String[] {"---"}));
    } else {
      saveButton.setEnabled(true);
      labelPreset.setEnabled(true);
      presetComboBox.setEnabled(true);
      DefaultComboBoxModel comboBoxModel = new DefaultComboBoxModel();
      defaultPresetLimit = 0;
      for (PreviewPreset preset : previewUIController.getDefaultPresets()) {
        comboBoxModel.addElement(preset);
        defaultPresetLimit++;
      }
      PreviewPreset[] userPresets = previewUIController.getUserPresets();
      if (userPresets.length > 0) {
        comboBoxModel.addElement(NO_SELECTION);
        for (PreviewPreset preset : userPresets) {
          comboBoxModel.addElement(preset);
        }
      }
      presetComboBox.setSelectedItem(previewModel.getCurrentPreset());
      presetComboBox.setModel(comboBoxModel);
    }

    // Refresh tabs
    if (tabbedPane != null) {
      int tabCount = tabbedPane.getTabCount();
      for (int i = 1; i < tabCount; i++) {
        tabbedPane.removeTabAt(i);
      }
      for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
        pui.unsetup();
      }
      if (previewModel != null) {
        PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
        PreviewModel pModel = previewController.getModel();
        // Add new tabs
        for (PreviewUI pui : Lookup.getDefault().lookupAll(PreviewUI.class)) {
          pui.setup(pModel);
          JPanel pluginPanel = pui.getPanel();
          if (UIUtils.isAquaLookAndFeel()) {
            pluginPanel.setBackground(UIManager.getColor("NbExplorerView.background"));
          }
          if (pui.getIcon() != null) {
            tabbedPane.addTab(pui.getPanelTitle(), pui.getIcon(), pluginPanel);
          } else {
            tabbedPane.addTab(pui.getPanelTitle(), pluginPanel);
          }
        }
      }
    }
  }
Beispiel #8
0
 private void setup() {
   PreviewModel model = previewController.getModel();
   setControlsEnabled(model != null);
   refresh();
 }
  @Test
  public void testPNG() {
    try {

      // Init a project - and therefore a workspace
      ProjectController pc = Lookup.getDefault().lookup(ProjectController.class);
      pc.newProject();
      Workspace workspace = pc.getCurrentWorkspace();

      // Append container to graph structure
      String sample = "/org/gephi/desktop/welcome/samples/Les Miserables.gexf";
      final InputStream stream = WelcomeTopComponent.class.getResourceAsStream(sample);
      ImportController importController = Lookup.getDefault().lookup(ImportController.class);
      FileImporter fileImporter = importController.getFileImporter(".gexf");
      Container container = importController.importFile(stream, fileImporter);

      importController.process(container, new DefaultProcessor(), workspace);

      // Add self loop
      GraphController graphController = Lookup.getDefault().lookup(GraphController.class);
      Graph graph = graphController.getModel().getGraph();
      Node node = graph.getNode(12);
      System.out.println("Self loop " + node.getNodeData().getLabel());
      graph.addEdge(graphController.getModel().factory().newEdge(node, node, 31, true));

      // Set label edges
      for (Edge edge : graphController.getModel().getGraph().getEdges()) {
        edge.getEdgeData().setLabel("Label test");
      }

      // svg document

      // attribute ???
      AttributeController attributeController =
          Lookup.getDefault().lookup(AttributeController.class);
      AttributeModel attributeModel = null;

      // preview
      PreviewController previewController = Lookup.getDefault().lookup(PreviewController.class);
      PreviewModel previewModel = previewController.getModel(workspace);
      PreviewProperties previewProperties = previewModel.getProperties();
      previewController.refreshPreview(workspace);

      previewModel.getProperties().putValue("width", 1000);
      previewModel.getProperties().putValue("height", 1000);
      ProcessingTarget target =
          (ProcessingTarget)
              previewController.getRenderTarget(RenderTarget.PROCESSING_TARGET, workspace);

      previewProperties.putValue(LegendModel.LEGEND_PROPERTIES, new LegendModel(workspace));

      LegendModel legendManager = previewProperties.getValue(LegendModel.LEGEND_PROPERTIES);
      Integer itemIndex = legendManager.getCurrentIndex();

      // creating item
      Item item = addGroupsItem(itemIndex, graph, attributeModel);
      //            Item item = addTextItem(itemIndex, graph, attributeModel);

      // add item
      LegendController.getInstance().addItemToLegendModel(workspace, item);

      // render
      previewController.refreshPreview(workspace);
      previewController.render(target);

      File fileToSave = new File("/Volumes/edubecks/edubecks/Untitled.png");
      OutputStream fos = new FileOutputStream(fileToSave);
      Writer writer = new OutputStreamWriter(fos, "UTF-8");

      //            // saving
      //            int width = 1000;
      //            int height = 1000;
      //            PGraphicsJava2D pg2 = (PGraphicsJava2D) target.getGraphics();
      //            BufferedImage img = new BufferedImage(width, height,
      // BufferedImage.TYPE_INT_ARGB);
      //
      //            System.out.println("@Var: pg2.pixels: "+pg2.pixels);
      //            img.setRGB(0, 0, width, height, pg2.pixels, 0, width);
      //            ImageIO.write(img, "png", fileToSave);
      //            stream.close();

      PNGExporter pngExporter = new PNGExporter();
      //            pngExporter.setHeight(2000);
      //            pngExporter.setWidth(2000);
      pngExporter.setWorkspace(workspace);
      pngExporter.setOutputStream(fos);
      pngExporter.execute();

    } catch (Exception e) {
      Exceptions.printStackTrace(e);
    }
  }