Example #1
0
  private void processExamples(String group, List<Example> examples) {
    Evaluation evaluation = new Evaluation();
    if (examples.isEmpty()) return;

    final String prefix = "iter=0." + group;
    Execution.putOutput("group", group);
    LogInfo.begin_track_printAll("Processing %s: %s examples", prefix, examples.size());
    LogInfo.begin_track("Dumping metadata");
    dumpMetadata(group, examples);
    LogInfo.end_track();
    LogInfo.begin_track("Examples");

    for (int e = 0; e < examples.size(); e++) {
      Example ex = examples.get(e);
      LogInfo.begin_track_printAll("%s: example %s/%s: %s", prefix, e, examples.size(), ex.id);
      ex.log();
      Execution.putOutput("example", e);
      StopWatchSet.begin("Parser.parse");
      ParserState state = builder.parser.parse(params, ex, false);
      StopWatchSet.end();
      out.printf("########## Example %s ##########\n", ex.id);
      dumpExample(exampleToLispTree(state));
      LogInfo.logs("Current: %s", ex.evaluation.summary());
      evaluation.add(ex.evaluation);
      LogInfo.logs("Cumulative(%s): %s", prefix, evaluation.summary());
      LogInfo.end_track();
      ex.predDerivations.clear(); // To save memory
    }

    LogInfo.end_track();
    LogInfo.logs("Stats for %s: %s", prefix, evaluation.summary());
    evaluation.logStats(prefix);
    evaluation.putOutput(prefix);
    LogInfo.end_track();
  }
Example #2
0
  private static Component createDescription(Example example, ExampleGroup group) {
    Color foreground = group.getPreferredForeground();

    WebLabel titleLabel = new WebLabel(example.getTitle(), JLabel.TRAILING);
    titleLabel.setDrawShade(true);
    titleLabel.setForeground(foreground);
    if (foreground.equals(Color.WHITE)) {
      titleLabel.setShadeColor(Color.BLACK);
    }

    if (example.getDescription() == null) {
      return titleLabel;
    } else {
      WebLabel descriptionLabel = new WebLabel(example.getDescription(), WebLabel.TRAILING);
      descriptionLabel.setForeground(Color.GRAY);
      SwingUtils.changeFontSize(descriptionLabel, -1);

      WebPanel vertical =
          new WebPanel(new VerticalFlowLayout(VerticalFlowLayout.MIDDLE, 0, 0, true, false));
      vertical.setOpaque(false);
      vertical.add(titleLabel);
      vertical.add(descriptionLabel);

      return vertical;
    }
  }
  Map<String, Set<String>> runExamples(File examplesDir, boolean verbose) {
    Map<String, Set<String>> map = new TreeMap<String, Set<String>>();
    for (Example e : getExamples(examplesDir)) {
      StringWriter sw = new StringWriter();
      PrintWriter pw = new PrintWriter(sw);
      e.run(pw, true, verbose);
      pw.close();
      String[] lines = sw.toString().split("\n");
      for (String line : lines) {
        if (!line.startsWith("compiler.")) continue;
        int colon = line.indexOf(":");
        if (colon == -1) continue;
        String key = line.substring(0, colon);
        StringBuilder sb = new StringBuilder();
        sb.append("# ");
        int i = 0;
        String[] descs = line.substring(colon + 1).split(", *");
        for (String desc : descs) {
          if (i > 0) sb.append(", ");
          sb.append(i++);
          sb.append(": ");
          sb.append(desc.trim());
        }
        Set<String> set = map.get(key);
        if (set == null) map.put(key, set = new TreeSet<String>());
        set.add(sb.toString());
      }
    }

    return map;
  }
 public static void main(String... args) {
   try {
     Example clientExample = new RealDeviceExample(System.out, args);
     clientExample.run();
   } catch (HiveException | ExampleException | IOException e) {
     System.err.println(e.getMessage());
   }
 }
 public List<BufferedImage> getExamples() {
   List<BufferedImage> list = new ArrayList<BufferedImage>();
   for (int i = 0; i < model.size(); i++) {
     Example example = (Example) model.get(i);
     list.add(example.getBufferedImage());
   }
   return list;
 }
Example #6
0
  private static Component createPresentationButton(final Example example) {
    final WebToggleButton presentation = new WebToggleButton(presentationIcon);
    presentation.setRolloverDecoratedOnly(true);
    presentation.setFocusable(false);

    presentation.setEnabled(example.isPresentationAvailable());
    TooltipManager.setTooltip(
        presentation,
        presentationIcon,
        example.isPresentationAvailable()
            ? "Show presentation"
            : "There is no presentation available for this component",
        TooltipWay.up);

    if (presentation.isEnabled()) {
      presentation.addActionListener(
          new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
              if (presentation.isSelected()) {
                example.startPresentation();
                TooltipManager.setTooltip(
                    presentation, presentationIcon, "Stop presentation", TooltipWay.up);
              } else {
                example.stopPresentation();
                TooltipManager.setTooltip(
                    presentation, presentationIcon, "Show presentation", TooltipWay.up);
              }
            }
          });

      example.doWhenPresentationFinished(
          new Runnable() {
            @Override
            public void run() {
              presentation.setSelected(false);
              TooltipManager.setTooltip(
                  presentation, presentationIcon, "Show presentation", TooltipWay.up);

              ThreadUtils.sleepSafely(250);

              final WebCustomTooltip end =
                  TooltipManager.showOneTimeTooltip(
                      presentation, null, "Presentation has ended", TooltipWay.up);
              WebTimer.delay(
                  1500,
                  new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                      end.closeTooltip();
                    }
                  });
            }
          });
    }

    return new CenterPanel(presentation, false, true);
  }
Example #7
0
 @SuppressWarnings("unchecked")
 public T findByExampleSingle(T exampleInstance, String... excludeProperty) {
   Criteria crit = getSession().createCriteria(getPersistentClass());
   Example example = Example.create(exampleInstance);
   for (String exclude : excludeProperty) {
     example.excludeProperty(exclude);
   }
   crit.add(example);
   crit.setCacheable(queriesCached);
   return (T) crit.uniqueResult();
 }
 public void testDifferentAnnotations() throws Exception {
   Persister persister = new Persister();
   Example example = new Example("a", "b");
   StringWriter writer = new StringWriter();
   persister.write(example, writer);
   String text = writer.toString();
   Example deserialized = persister.read(Example.class, text);
   assertEquals(deserialized.getKey(), "a");
   assertEquals(deserialized.getValue(), "b");
   validate(persister, deserialized);
 }
Example #9
0
  private static Component createPreview(WebLookAndFeelDemo owner, Example example) {
    WebPanel previewPanel = new WebPanel();
    previewPanel.setOpaque(false);
    previewPanel.setLayout(
        new TableLayout(
            new double[][] {
              {example.isFillWidth() ? TableLayout.FILL : TableLayout.PREFERRED},
              {TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL}
            }));

    previewPanel.add(example.getPreview(owner), "0,1");

    return previewPanel;
  }
Example #10
0
  public List regionsByExample(Countries countries) {

    Criteria cri = session.createCriteria(Countries.class);
    Example exam = Example.create(countries);
    cri.add(exam);
    return cri.list();
  }
  public static void main(String... args) throws Exception {
    jtreg = (System.getProperty("test.src") != null);
    File tmpDir;
    if (jtreg) {
      // use standard jtreg scratch directory: the current directory
      tmpDir = new File(System.getProperty("user.dir"));
    } else {
      tmpDir =
          new File(
              System.getProperty("java.io.tmpdir"),
              MessageInfo.class.getName()
                  + (new SimpleDateFormat("yyMMddHHmmss")).format(new Date()));
    }
    Example.setTempDir(tmpDir);
    Example.Compiler.factory = new ArgTypeCompilerFactory();

    MessageInfo mi = new MessageInfo();

    try {
      if (mi.run(args)) return;
    } finally {
      /* VERY IMPORTANT NOTE. In jtreg mode, tmpDir is set to the
       * jtreg scratch directory, which is the current directory.
       * In case someone is faking jtreg mode, make sure to only
       * clean tmpDir when it is reasonable to do so.
       */
      if (tmpDir.isDirectory() && tmpDir.getName().startsWith(MessageInfo.class.getName())) {
        if (clean(tmpDir)) tmpDir.delete();
      }
    }

    if (jtreg) throw new Exception(mi.errors + " errors occurred");
    else System.exit(1);
  }
Example #12
0
  //
  //  Initialize the GUI (application and applet)
  //
  public void initialize(String[] args) {
    // Initialize the window, menubar, etc.
    super.initialize(args);
    exampleFrame.setTitle("Java 3D Light Scoping Example");

    //
    //  Add a menubar menu to change node parameters
    //    Use bounding leaf
    //

    Menu m = new Menu("DirectionalLights");

    light1OnOffMenu = new CheckboxMenuItem("Red light with sphere set 1 scope", light1OnOff);
    light1OnOffMenu.addItemListener(this);
    m.add(light1OnOffMenu);

    light2OnOffMenu = new CheckboxMenuItem("Blue light with sphere set 2 scope", light2OnOff);
    light2OnOffMenu.addItemListener(this);
    m.add(light2OnOffMenu);

    light3OnOffMenu = new CheckboxMenuItem("White light with universal scope", light3OnOff);
    light3OnOffMenu.addItemListener(this);
    m.add(light3OnOffMenu);

    exampleMenuBar.add(m);
  }
  @Override
  public Predictor<I, O> train(Iterable<Example<I, O>> trainingData) {
    ParametricFactorGraph model = constructGraphicalModel(trainingData);

    Converter<I, DynamicAssignment> inputConverter = getInputConverter(model);
    Converter<O, DynamicAssignment> outputConverter = getOutputConverter(model);
    Converter<Example<I, O>, Example<DynamicAssignment, DynamicAssignment>> exampleConverter =
        Example.converter(inputConverter, outputConverter);
    List<Example<DynamicAssignment, DynamicAssignment>> trainingDataAssignments =
        Lists.newArrayList(Iterables.transform(trainingData, exampleConverter));

    SufficientStatistics initialParameters = model.getNewSufficientStatistics();
    initialParameters.perturb(parameterPerturbation);
    System.out.println(initialParameters);
    SufficientStatistics finalParameters =
        trainer.train(model, initialParameters, trainingDataAssignments);

    Predictor<DynamicAssignment, DynamicAssignment> assignmentPredictor =
        new FactorGraphPredictor(
            model.getModelFromParameters(finalParameters),
            getOutputVariables(model),
            new JunctionTree());

    return ForwardingPredictor.create(assignmentPredictor, inputConverter, outputConverter);
  }
Example #14
0
  public List byExample(StaffRole staffRole) {

    Session session = HibernateTrain.getSession();
    Criteria cri = session.createCriteria(StaffRole.class);
    Example exam = Example.create(staffRole);
    cri.add(exam);
    return cri.list();
  }
Example #15
0
 private static Component createMark(final WebLookAndFeelDemo owner, final Example example) {
   final FeatureState fs = example.getFeatureState();
   ImageIcon fsIcon = fs.getIcon();
   final WebLabel featureState = new WebLabel(fsIcon);
   TooltipManager.setTooltip(featureState, fsIcon, fs.getDescription(), TooltipWay.up);
   featureState.addMouseListener(
       new MouseAdapter() {
         @Override
         public void mousePressed(MouseEvent e) {
           owner.showLegend(featureState, fs);
         }
       });
   return new CenterPanel(featureState, true, true);
 }
  public static Example parseExample(String exampleDescription) throws InstantiationException {

    // System.out.println("INPUT: " + exampleDescription);
    int beginFirstRepIndex = exampleDescription.indexOf(DELIMITER);
    String labelsPart = exampleDescription.substring(0, beginFirstRepIndex).trim();
    String representationsPart = exampleDescription.substring(beginFirstRepIndex).trim();
    // System.out.println("Label part: " + labelsPart);
    // System.out.println("representation part: " + representationsPart);
    Example example;
    if (representationsPart.startsWith(BEGIN_PAIR)) {
      example = parseExamplePair(representationsPart);
    } else {
      example = parseSimpleExample(representationsPart);
    }
    // ADDING LABELS
    String[] stringLabels = labelsPart.split(LABEL_SEPARATOR);
    for (String labelDescription : stringLabels) {
      if (labelDescription.trim().length() > 0) {
        Label label = LabelFactory.parseLabel(labelDescription.trim());
        example.addLabel(label);
      }
    }
    return example;
  }
Example #17
0
 /**
  * Setup an example entity.
  *
  * @param type The type.
  * @param example The provided example.
  * @param <T> The type.
  * @return The example.
  */
 private <T> Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> prepareExample(
     Example<T> example, Class<?> type, Class<?>... types) {
   Map<PrimitivePropertyMethodMetadata<PropertyMetadata>, Object> exampleEntity = new HashMap<>();
   InstanceInvocationHandler invocationHandler =
       new InstanceInvocationHandler(
           exampleEntity, new ExampleProxyMethodService(type, sessionContext));
   List<Class<?>> effectiveTypes = new ArrayList<>();
   effectiveTypes.add(type);
   effectiveTypes.addAll(Arrays.asList(types));
   T instance =
       sessionContext
           .getProxyFactory()
           .createInstance(
               invocationHandler,
               effectiveTypes.toArray(new Class<?>[effectiveTypes.size()]),
               CompositeObject.class);
   example.prepare(instance);
   return exampleEntity;
 }
Example #18
0
  @Override
  public void start(Stage primaryStage) throws Exception {

    Example.checkExample();

    FXMLLoader fxmlLoader = new FXMLLoader();
    Parent root = fxmlLoader.load(getClass().getResource("gui.fxml").openStream());
    this.controller = fxmlLoader.getController();
    if (this.controller != null) {
      primaryStage.setTitle("Hud Builder v1.0 by C.R.Messen");
      Scene scene = new Scene(root);
      scene.setFill(null);
      primaryStage.setScene(scene);
      this.controller.load();
      primaryStage.show();
    } else {
      System.exit(0);
    }
  }
Example #19
0
  private static Component createSourceButton(final WebLookAndFeelDemo owner, Example example) {
    final Class classType = example.getClass();

    WebButton sourceButton = WebButton.createIconWebButton(JarEntry.javaIcon);
    TooltipManager.setTooltip(
        sourceButton, JarEntry.javaIcon, ReflectUtils.getJavaClassName(classType), TooltipWay.up);
    sourceButton.setRolloverDecoratedOnly(true);
    sourceButton.setFocusable(false);

    sourceButton.addActionListener(
        new ActionListener() {
          @Override
          public void actionPerformed(ActionEvent e) {
            owner.showSource(classType);
          }
        });

    return new CenterPanel(sourceButton, false, true);
  }
Example #20
0
  public void itemStateChanged(ItemEvent event) {
    Object src = event.getSource();

    // Check if it is the coupled background choice
    if (src == coupledBackgroundOnOffMenu) {
      coupledBackgroundOnOff = coupledBackgroundOnOffMenu.getState();
      if (coupledBackgroundOnOff) {
        currentBackgroundColor = currentColor;
        backgroundColorMenu.setCurrent(currentColor);
        Color3f color = (Color3f) colors[currentColor].value;
        background.setColor(color);
        backgroundColorMenu.setEnabled(false);
      } else {
        backgroundColorMenu.setEnabled(true);
      }
    }

    // Handle all other checkboxes
    super.itemStateChanged(event);
  }
Example #21
0
  //
  //  Handle checkboxes and menu choices
  //
  public void itemStateChanged(ItemEvent event) {
    Object src = event.getSource();
    if (src == light1OnOffMenu) {
      light1OnOff = light1OnOffMenu.getState();
      light1.setEnable(light1OnOff);
      return;
    }
    if (src == light2OnOffMenu) {
      light2OnOff = light2OnOffMenu.getState();
      light2.setEnable(light2OnOff);
      return;
    }
    if (src == light3OnOffMenu) {
      light3OnOff = light3OnOffMenu.getState();
      light3.setEnable(light3OnOff);
      return;
    }

    // Handle all other checkboxes
    super.itemStateChanged(event);
  }
Example #22
0
  //
  //  Handle checkboxes and menu choices
  //
  public void checkboxChanged(CheckboxMenu menu, int check) {
    if (menu == backgroundColorMenu) {
      // Change the background color
      currentBackgroundColor = check;
      Color3f color = (Color3f) colors[check].value;
      background.setColor(color);
      return;
    }
    if (menu == colorMenu) {
      // Change the fog color
      currentColor = check;
      Color3f color = (Color3f) colors[check].value;
      fog.setColor(color);

      // If background is coupled, set the background color
      if (coupledBackgroundOnOff) {
        currentBackgroundColor = currentColor;
        backgroundColorMenu.setCurrent(check);
        background.setColor(color);
      }
      return;
    }
    if (menu == frontMenu) {
      // Change the fog front distance
      currentFront = check;
      float front = ((Float) fronts[currentFront].value).floatValue();
      fog.setFrontDistance(front);
      return;
    }
    if (menu == backMenu) {
      // Change the fog back distance
      currentBack = check;
      float back = ((Float) backs[currentBack].value).floatValue();
      fog.setBackDistance(back);
      return;
    }

    // Handle all other checkboxes
    super.checkboxChanged(menu, check);
  }
Example #23
0
  //
  //  Initialize the GUI (application and applet)
  //
  public void initialize(String[] args) {
    // Initialize the window, menubar, etc.
    super.initialize(args);
    exampleFrame.setTitle("Java 3D LinearFog Example");

    //
    //  Add a menubar menu to change node parameters
    //    Coupled background color
    //    Background color -->
    //    Fog color -->
    //    Fog front distance -->
    //    Fog back distance -->
    //

    Menu m = new Menu("LinearFog");

    coupledBackgroundOnOffMenu =
        new CheckboxMenuItem("Couple background color", coupledBackgroundOnOff);
    coupledBackgroundOnOffMenu.addItemListener(this);
    m.add(coupledBackgroundOnOffMenu);

    backgroundColorMenu =
        new CheckboxMenu("Background color", colors, currentBackgroundColor, this);
    m.add(backgroundColorMenu);
    backgroundColorMenu.setEnabled(!coupledBackgroundOnOff);

    colorMenu = new CheckboxMenu("Fog color", colors, currentColor, this);
    m.add(colorMenu);

    frontMenu = new CheckboxMenu("Fog front distance", fronts, currentFront, this);
    m.add(frontMenu);

    backMenu = new CheckboxMenu("Fog back distance", backs, currentBack, this);
    m.add(backMenu);

    exampleMenuBar.add(m);
  }
 @Test
 public void testNetworkAndMigrations() {
   Example ex = new NetworkAndMigrations();
   ex.run();
 }
  public static void main(String[] args) throws IOException {

    Map<Integer, String> relID2rel = new HashMap<Integer, String>();
    /*
    // read relID to rel mapping
    Mappings mapping = new Mappings();
    mapping.read(mappingFile);
    for (Map.Entry<String,Integer> e : mapping.getRel2RelID().entrySet())
    	relID2rel.put(e.getValue(), e.getKey());
    */

    List<Example> predictions = new ArrayList<Example>();
    {
      BufferedReader r =
          new BufferedReader(new InputStreamReader(new FileInputStream(resultsFile), "utf-8"));
      String[] h = r.readLine().split(" ");
      for (int i = 0; i < h.length; i++) relID2rel.put(i, h[i]);

      String l = null;
      while ((l = r.readLine()) != null) {
        String[] c = l.split("\t");

        // final String[] rels = c[3].split(" ");
        final String[] scores = c[5].split(" ");
        Integer[] pos = new Integer[scores.length];
        for (int i = 0; i < pos.length; i++) pos[i] = i;
        Arrays.sort(
            pos,
            new Comparator<Integer>() {
              public int compare(Integer i1, Integer i2) {
                double d1 = Double.parseDouble(scores[i1]);
                double d2 = Double.parseDouble(scores[i2]);
                if (d1 > d2) return -1;
                else return 1;
              }
            });

        for (int i = 0; i < scores.length; i++) {
          Example e = new Example();
          e.arg1 = c[0];
          e.arg2 = c[1];
          e.mentionID = Integer.parseInt(c[2]);

          int p = pos[i];
          // e.predRelation = rels[p];
          e.predRelation = relID2rel.get(p);
          // e.predScore = Double.parseDouble(scores[i]) - Double.parseDouble(scores[0]);
          e.predScore = Double.parseDouble(scores[p]);
          e.rank = i;

          // HACK; diff rel - NA
          // e.predScore = Double.parseDouble(scores[p]) - Double.parseDouble(scores[0]);
          // e.rank = 0;
          // if (e.rank == 0)
          predictions.add(e);
        }
      }
      r.close();
    }

    // List<Example> labeled = new ArrayList<Example>();
    Map<String, List<Label>> labels = new HashMap<String, List<Label>>();
    {
      BufferedReader r =
          new BufferedReader(new InputStreamReader(new FileInputStream(labelsFile), "utf-8"));
      String l = null;
      while ((l = r.readLine()) != null) {
        String[] c = l.split("\t");
        String key = c[6] + "\t" + c[7] + "\t" + c[0]; // arg1, arg2, mentionID
        Label label = new Label();
        label.relation = c[5];
        if (label.relation.equals("/location/country/administrative_divisions")
            || label.relation.equals("/location/administrative_division/country")
            || label.relation.equals("/film/film/featured_film_locations")) continue;

        // only measure performance on location/contains
        // if (!label.relation.equals("/location/location/contains")) continue;
        /*
        if (!label.relation.equals("/location/location/contains") &&
        		!label.relation.equals("/people/person/nationality") &&
        		!label.relation.equals("/location/neighborhood/neighborhood_of") &&
        		!label.relation.equals("/people/person/children"))
        	continue;
        */
        // if (!targetsSet.contains(label.relation)) continue;

        label.tf = c[2].equals("y") || c[2].equals("indirect");
        label.name1 = c[3];
        label.name2 = c[4];
        label.sentence = c[8];

        List<Label> ll = labels.get(key);
        if (ll == null) {
          ll = new ArrayList<Label>();
          labels.put(key, ll);
        }
        ll.add(label);
      }
      r.close();
    }

    // sort predictions by decreasing score
    Collections.sort(
        predictions,
        new Comparator<Example>() {
          public int compare(Example e1, Example e2) {
            if (e1.rank < e2.rank) return -1;
            else if (e1.rank > e2.rank) return 1;
            else if (e1.predScore > e2.predScore) return -1;
            else return 1;
          }
        });

    // max recall
    int MAX_TP = 0;
    for (List<Label> ll : labels.values()) {
      for (Label l : ll) if (!l.relation.equals("NA") && l.tf) MAX_TP++;
    }

    List<double[]> curve = new ArrayList<double[]>();

    int TP = 0, FP = 0, FN = 0;
    double lastPrecision = -1, lastRecall = -1;
    for (Example e : predictions) {
      String key = e.arg1 + "\t" + e.arg2 + "\t" + e.mentionID;
      List<Label> ll = labels.get(key);
      if (ll != null) {
        for (Label l : ll) {
          if (l.relation.equals(e.predRelation)) {
            if (l.tf) TP++;
            else FP++;
          } else {
            if (l.tf) FN++; // && e.predRelation.equals("NA")) FN++;
            // else TN++;
          }
        }
        double precision = TP / (double) (TP + FP);
        double recall = TP / (double) (MAX_TP);
        if (precision != lastPrecision || recall != lastRecall) {
          curve.add(new double[] {precision, recall});
          lastPrecision = precision;
          lastRecall = recall;
        }
      }
    }

    // print to file
    {
      BufferedWriter w =
          new BufferedWriter(new OutputStreamWriter(new FileOutputStream(curveFile)));

      for (double[] d : curve) {
        w.write(d[1] + "\t" + d[0] + "\n");
      }
      w.close();
    }
  }
 @SuppressWarnings("unchecked")
 public List<T> findByExample(T exampleInstance) {
   return findByCriteria(Example.create(exampleInstance));
 }
Example #27
0
 public void testSaveExample() {
   Example ex = new Example();
   ex.name = "John Doe";
   ex.save();
 }
Example #28
0
  public static Component createGroupView(WebLookAndFeelDemo owner, ExampleGroup group) {
    // Creating group view
    Component exampleView;
    List<Example> examples = group.getGroupExamples();
    if (group.isSingleExample() && examples.size() == 1) {
      Example example = examples.get(0);
      exampleView = example.getPreview(owner);
    } else {
      final List<Component> preview = new ArrayList<Component>();

      final WebPanel groupPanel =
          new WebPanel() {
            @Override
            public void setEnabled(boolean enabled) {
              for (Component previewComponent : preview) {
                SwingUtils.setEnabledRecursively(previewComponent, enabled);
              }
              super.setEnabled(enabled);
            }
          };
      groupPanel.putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true);
      groupPanel.setOpaque(false);
      exampleView = groupPanel;

      int rowsAmount = examples.size() > 1 ? examples.size() * 2 - 1 : 1;
      double[] rows = new double[6 + rowsAmount];
      rows[0] = TableLayout.FILL;
      rows[1] = 20;
      rows[2] = TableLayout.PREFERRED;
      for (int i = 3; i < rows.length - 3; i++) {
        rows[i] = TableLayout.PREFERRED;
      }
      rows[rows.length - 3] = TableLayout.PREFERRED;
      rows[rows.length - 2] = 20;
      rows[rows.length - 1] = TableLayout.FILL;

      double[] columns = {
        20,
        1f - group.getContentPartSize(),
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        TableLayout.PREFERRED,
        group.getContentPartSize(),
        20
      };

      TableLayout groupLayout = new TableLayout(new double[][] {columns, rows});
      groupLayout.setHGap(4);
      groupLayout.setVGap(4);
      groupPanel.setLayout(groupLayout);

      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "2,0,2," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "4,0,4," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "6,0,6," + (rows.length - 1));
      groupPanel.add(
          group.modifySeparator(createVerticalSeparator()), "8,0,8," + (rows.length - 1));

      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()), "0,2," + (columns.length - 1) + ",2");
      groupPanel.add(
          group.modifySeparator(createHorizontalSeparator()),
          "0," + (rows.length - 3) + "," + (columns.length - 1) + "," + (rows.length - 3));

      int row = 3;
      for (Example example : examples) {
        // Title & description
        groupPanel.add(createDescription(example, group), "1," + row);

        // Marks
        Component mark = createMark(owner, example);
        groupPanel.add(mark, "3," + row);

        // Source code
        Component source = createSourceButton(owner, example);
        groupPanel.add(source, "5," + row);

        // More usage examples
        Component usage = createPresentationButton(example);
        groupPanel.add(usage, "7," + row);

        SwingUtils.equalizeComponentsSize(mark, source, usage);

        // Preview
        Component previewComponent = createPreview(owner, example);
        groupPanel.add(previewComponent, "9," + row);
        preview.add(previewComponent);

        // Rows separator
        if (row > 3) {
          groupPanel.add(
              group.modifySeparator(createHorizontalSeparator()),
              "0," + (row - 1) + "," + (columns.length - 1) + "," + (row - 1),
              0);
        }

        row += 2;
      }
    }

    if (group.isShowWatermark()) {
      WebImage linkImage = new WebImage(logoIcon);
      linkImage.setCursor(Cursor.getPredefinedCursor(Cursor.HAND_CURSOR));

      TooltipManager.setTooltip(linkImage, linkIcon, "Library site", TooltipWay.trailing);

      linkImage.addMouseListener(
          new MouseAdapter() {
            @Override
            public void mousePressed(MouseEvent e) {
              WebUtils.browseSiteSafely(WebLookAndFeelDemo.WEBLAF_SITE);
            }
          });

      WebOverlay linkOverlay =
          new WebOverlay(exampleView, linkImage, WebOverlay.LEADING, WebOverlay.BOTTOM);
      linkOverlay.setOverlayMargin(15, 15, 15, 15);
      linkOverlay.setOpaque(false);

      exampleView = linkOverlay;
    }

    return exampleView;
  }
Example #29
0
  public static void main(String args[]) {

    Example a = new Example();
    InterfaceTest a1 = a.getIn();
    a1.test();
  }
 @Test
 public void testAdvancedMigScheduling() {
   Example ex = new AdvancedMigScheduling();
   ex.run();
 }