Ejemplo n.º 1
0
  /**
   * Create a chart with the underlying dataset.
   *
   * @return The chart.
   */
  protected JFreeChart createChart() {
    String title = (String) getProperty("title");
    String labelx = (String) getProperty("labelx");
    String labely = (String) getProperty("labely");
    boolean legend =
        getProperty("legend") == null ? true : ((Boolean) getProperty("legend")).booleanValue();
    boolean tooltips =
        getProperty("tooltips") == null ? true : ((Boolean) getProperty("tooltips")).booleanValue();
    boolean urls =
        getProperty("urls") == null ? false : ((Boolean) getProperty("urls")).booleanValue();
    boolean autorepaint =
        getProperty("autorepaint") == null
            ? false
            : ((Boolean) getProperty("autorepaint")).booleanValue();

    XYDataset dataset = new VectorSeriesCollection();
    JFreeChart chart =
        ChartFactory.createXYLineChart(
            title, labelx, labely, dataset, PlotOrientation.VERTICAL, legend, tooltips, urls);
    chart.setNotify(autorepaint);
    //		chart.setBackgroundPaint(new Color(100,100,100,100));
    //		chart.getPlot().setBackgroundAlpha(0.5f);

    String bgimagefn = (String) getProperty("bgimage");
    if (bgimagefn != null) {
      try {
        IApplication app = getSpace().getContext();
        ClassLoader cl =
            ((ILibraryService)
                    SServiceProvider.getService(app.getServiceProvider(), ILibraryService.class)
                        .get(new ThreadSuspendable()))
                .getClassLoader();
        ResourceInfo rinfo =
            getResourceInfo(bgimagefn, app.getApplicationType().getAllImports(), cl);
        Image image = ImageIO.read(rinfo.getInputStream());
        rinfo.getInputStream().close();

        //				chart.setBackgroundImage(image);
        chart.getPlot().setBackgroundImage(image);
      } catch (Exception e) {
        System.out.println("Background image not found: " + bgimagefn);
      }
    }

    //		ChartPanel panel = new ChartPanel(chart);
    //		panel.setFillZoomRectangle(true);
    //		JFrame f = new JFrame();
    //		JPanel content = new JPanel(new BorderLayout());
    //		content.add(panel, BorderLayout.CENTER);
    //		f.setContentPane(panel);
    //		f.pack();
    //		f.setVisible(true);

    return chart;
  }
Ejemplo n.º 2
0
  /** Open a project. Asks the user for a project file name. */
  protected void openProject() {
    if (filechooser.showDialog(this, "Open Project") == JFileChooser.APPROVE_OPTION) {
      final File file = filechooser.getSelectedFile();

      SServiceProvider.getService(controlcenter.getServiceProvider(), ILibraryService.class)
          .addResultListener(
              new SwingDefaultResultListener(ControlCenterWindow.this) {
                public void customResultAvailable(Object source, Object result) {
                  ClassLoader cl = ((ILibraryService) result).getClassLoader();

                  boolean canopen =
                      file != null
                          && file.canWrite()
                          && file.getName()
                              .toLowerCase()
                              .endsWith(ControlCenter.JCCPROJECT_EXTENSION);
                  if (canopen) {
                    controlcenter.saveProject();
                    controlcenter.closeProject();
                    try {
                      controlcenter.openProject(file, cl); // , true);
                    } catch (Exception e) {
                      canopen = false;
                    }
                  }

                  if (!canopen) {
                    SwingUtilities.invokeLater(
                        new Runnable() {
                          public void run() {
                            String msg =
                                SUtil.wrapText("Cannot open the project from file:\n" + file);
                            JOptionPane.showMessageDialog(
                                ControlCenterWindow.this,
                                msg,
                                "Cannot open the project",
                                JOptionPane.ERROR_MESSAGE);
                          }
                        });
                  }
                }
              });
    }
  }
Ejemplo n.º 3
0
  /** The plan body. */
  public void body() {
    IComponentManagementService cms =
        (IComponentManagementService)
            SServiceProvider.getService(
                    getScope().getServiceProvider(), IComponentManagementService.class)
                .get(this);

    TestReport tr = new TestReport("#1", "Start agent as suspended.");
    CreationInfo ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setSuspend(Boolean.TRUE);
    IComponentIdentifier cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    IComponentDescription desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (IComponentDescription.STATE_SUSPENDED.equals(desc.getState())) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not suspended: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#2", "Start agent as master.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setMaster(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getMaster() != null && desc.getMaster().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not master: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#3", "Start agent as daemon.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setDaemon(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getDaemon() != null && desc.getDaemon().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not daemon: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#4", "Start agent as autoshutdown.");
    ci = new CreationInfo("donothing", null, getComponentIdentifier());
    ci.setAutoshutdown(Boolean.TRUE);
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getAutoShutdown() != null && desc.getAutoShutdown().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not autoshutdown: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#5", "Start agent as suspended.");
    ci = new CreationInfo("suspend", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (IComponentDescription.STATE_SUSPENDED.equals(desc.getState())) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not suspended: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#6", "Start agent as master.");
    ci = new CreationInfo("master", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getMaster() != null && desc.getMaster().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not master: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#7", "Start agent as daemon.");
    ci = new CreationInfo("daemon", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getDaemon() != null && desc.getDaemon().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not daemon: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);

    tr = new TestReport("#8", "Start agent as autoshutdown.");
    ci = new CreationInfo("autoshutdown", null, getComponentIdentifier());
    cid =
        (IComponentIdentifier)
            cms.createComponent(null, "jadex/bdi/testcases/misc/Flag.agent.xml", ci, null)
                .get(this);
    desc = (IComponentDescription) cms.getComponentDescription(cid).get(this);

    if (desc.getAutoShutdown() != null && desc.getAutoShutdown().booleanValue()) {
      tr.setSucceeded(true);
    } else {
      tr.setReason("Component not autoshutdown: " + desc);
    }
    getBeliefbase().getBeliefSet("testcap.reports").addFact(tr);
  }
Ejemplo n.º 4
0
    InputDialog(final boolean buy) {
      super(getFrame(), addorderlabel, true);

      // Add some default entry for easy testing of the gui.
      // This order are not added to the agent (see manager.agent.xml).
      SServiceProvider.getService(agent.getServiceProvider(), IClockService.class)
          .addResultListener(
              new SwingDefaultResultListener(GuiPanel.this) {

                public void customResultAvailable(Object source, Object result) {
                  IClockService clock = (IClockService) result;
                  if (buy) {
                    orders.addItem(new Order("All about agents", null, 100, 120, buy, clock));
                    orders.addItem(new Order("All about web services", null, 40, 60, buy, clock));
                    orders.addItem(new Order("Harry Potter", null, 5, 10, buy, clock));
                    orders.addItem(new Order("Agents in the real world", null, 30, 65, buy, clock));
                  } else {
                    orders.addItem(new Order("All about agents", null, 130, 110, buy, clock));
                    orders.addItem(new Order("All about web services", null, 50, 30, buy, clock));
                    orders.addItem(new Order("Harry Potter", null, 15, 9, buy, clock));
                    orders.addItem(
                        new Order("Agents in the real world", null, 100, 60, buy, clock));
                  }

                  JPanel center = new JPanel(new GridBagLayout());
                  center.setBorder(new EmptyBorder(5, 5, 5, 5));
                  getContentPane().add(BorderLayout.CENTER, center);

                  JLabel label;
                  Dimension labeldim = new JLabel("Preset orders ").getPreferredSize();
                  int row = 0;
                  GridBagConstraints leftcons =
                      new GridBagConstraints(
                          0,
                          0,
                          1,
                          1,
                          0,
                          0,
                          GridBagConstraints.WEST,
                          GridBagConstraints.HORIZONTAL,
                          new Insets(1, 1, 1, 1),
                          0,
                          0);
                  GridBagConstraints rightcons =
                      new GridBagConstraints(
                          1,
                          0,
                          GridBagConstraints.REMAINDER,
                          1,
                          1,
                          0,
                          GridBagConstraints.WEST,
                          GridBagConstraints.HORIZONTAL,
                          new Insets(1, 1, 1, 1),
                          0,
                          0);

                  leftcons.gridy = rightcons.gridy = row++;
                  label = new JLabel("Preset orders");
                  label.setMinimumSize(labeldim);
                  label.setPreferredSize(labeldim);
                  center.add(label, leftcons);
                  center.add(orders, rightcons);

                  leftcons.gridy = rightcons.gridy = row++;
                  label = new JLabel("Title");
                  label.setMinimumSize(labeldim);
                  label.setPreferredSize(labeldim);
                  center.add(label, leftcons);
                  center.add(title, rightcons);

                  leftcons.gridy = rightcons.gridy = row++;
                  label = new JLabel("Start price");
                  label.setMinimumSize(labeldim);
                  label.setPreferredSize(labeldim);
                  center.add(label, leftcons);
                  center.add(start, rightcons);

                  leftcons.gridy = rightcons.gridy = row++;
                  label = new JLabel("Price limit");
                  label.setMinimumSize(labeldim);
                  label.setPreferredSize(labeldim);
                  center.add(label, leftcons);
                  center.add(limit, rightcons);

                  leftcons.gridy = rightcons.gridy = row++;
                  label = new JLabel("Deadline");
                  label.setMinimumSize(labeldim);
                  label.setPreferredSize(labeldim);
                  center.add(label, leftcons);
                  center.add(deadline, rightcons);

                  JPanel south = new JPanel();
                  // south.setBorder(new TitledBorder(new EtchedBorder(), " Control "));
                  getContentPane().add(BorderLayout.SOUTH, south);

                  JButton ok = new JButton("Ok");
                  JButton cancel = new JButton("Cancel");
                  ok.setMinimumSize(cancel.getMinimumSize());
                  ok.setPreferredSize(cancel.getPreferredSize());
                  south.add(ok);
                  south.add(cancel);

                  ok.addActionListener(
                      new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                          aborted = false;
                          setVisible(false);
                        }
                      });
                  cancel.addActionListener(
                      new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                          setVisible(false);
                        }
                      });

                  orders.addActionListener(
                      new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                          Order order = (Order) orders.getSelectedItem();
                          title.setText(order.getTitle());
                          limit.setText("" + order.getLimit());
                          start.setText("" + order.getStartPrice());
                        }
                      });
                }
              });
    }