예제 #1
0
  @Override
  public JComponent createUI(
      DescriptionType inputOrOutput, Map<URI, Object> dataMap, Orientation orientation) {
    // Create the main panel
    JComponent component = new JPanel(new MigLayout("fill"));

    boolean isOptional = false;
    if (inputOrOutput instanceof InputDescriptionType) {
      isOptional =
          ((InputDescriptionType) inputOrOutput).getMinOccurs().equals(new BigInteger("0"));
    }
    // Display the SourceCA into a JTextField
    JTextField jtf = new JTextField();
    jtf.setToolTipText(inputOrOutput.getAbstract().get(0).getValue());
    // "Save" the CA inside the JTextField
    jtf.getDocument().putProperty(DATA_MAP_PROPERTY, dataMap);
    URI uri = URI.create(inputOrOutput.getIdentifier().getValue());
    jtf.getDocument().putProperty(URI_PROPERTY, uri);
    // add the listener for the text changes in the JTextField
    jtf.getDocument()
        .addDocumentListener(
            EventHandler.create(DocumentListener.class, this, "saveDocumentText", "document"));
    if (isOptional) {
      if (dataMap.containsKey(uri)) {
        jtf.setText(dataMap.get(uri).toString());
      }
    }

    GeometryData geometryData = null;
    if (inputOrOutput instanceof InputDescriptionType) {
      geometryData =
          (GeometryData) ((InputDescriptionType) inputOrOutput).getDataDescription().getValue();
    }
    // If the DescriptionType is an output, there is nothing to show, so exit
    if (geometryData == null) {
      return null;
    }

    component.add(jtf, "growx");

    if (orientation.equals(Orientation.VERTICAL)) {
      JPanel buttonPanel = new JPanel(new MigLayout());

      // Create the button Browse
      JButton pasteButton = new JButton(ToolBoxIcon.getIcon(ToolBoxIcon.PASTE));
      // "Save" the sourceCA and the JTextField in the button
      pasteButton.putClientProperty(TEXT_FIELD_PROPERTY, jtf);
      pasteButton.setBorderPainted(false);
      pasteButton.setContentAreaFilled(false);
      pasteButton.setMargin(new Insets(0, 0, 0, 0));
      // Add the listener for the click on the button
      pasteButton.addActionListener(EventHandler.create(ActionListener.class, this, "onPaste", ""));
      buttonPanel.add(pasteButton);

      component.add(buttonPanel, "dock east");
    }

    return component;
  }
예제 #2
0
  private static void createAndShowGUI() {
    JFrame frame = new JFrame("Fractal");
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    SpringLayout layout = new SpringLayout();
    frame.setLayout(layout);

    Orientation nw = new Orientation();
    nw.setOffset(0, 0);
    Orientation sw = new Orientation();
    sw.setOffset(0, regionSize);
    Orientation se = new Orientation();
    se.setOffset(regionSize, regionSize);

    Fractal fractal = new Fractal(regionSize);
    fractal.setOrientations(nw, sw, se);

    layout.putConstraint(SpringLayout.WEST, fractal, 5, SpringLayout.WEST, frame.getContentPane());
    layout.putConstraint(
        SpringLayout.NORTH, fractal, 5, SpringLayout.NORTH, frame.getContentPane());

    layout.putConstraint(SpringLayout.WEST, nw, 5, SpringLayout.EAST, fractal);
    layout.putConstraint(SpringLayout.NORTH, nw, 0, SpringLayout.NORTH, fractal);

    layout.putConstraint(SpringLayout.NORTH, sw, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, sw, 0, SpringLayout.WEST, nw);

    layout.putConstraint(SpringLayout.NORTH, se, 5, SpringLayout.SOUTH, nw);
    layout.putConstraint(SpringLayout.WEST, se, 5, SpringLayout.EAST, sw);

    layout.putConstraint(
        SpringLayout.SOUTH, frame.getContentPane(), 5, SpringLayout.SOUTH, fractal);
    layout.putConstraint(SpringLayout.EAST, frame.getContentPane(), 5, SpringLayout.EAST, se);

    frame.add(nw);
    frame.add(sw);
    frame.add(se);

    frame.add(fractal);

    frame.setResizable(false);
    frame.pack();
    frame.setVisible(true);
  }
예제 #3
0
  private void majgrid1(Player player) {
    gridtest = new Grid();
    gridtest = player.getGridJoueur();

    ShipType type = ShipType.AIRCRAFT_CARRIER;
    Ship ship = new Ship(type);
    Orientation orient = Orientation.HORIZONTAL;
    for (int i = 0; i < 10; i++) // ligne
    {
      for (int j = 0; j < 10; j++) // colonne
      {
        if (gridtest.getCell(i, j) instanceof OceanCell) {
          tabbout1[i][j].setIcon(iconeau);
        }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(iconeautouch);
        //                }
        //                else if(gridtest.getCell(i, j) instanceof TouchOceanCell)
        //                {
        //                    tabbout1[i][j].setIcon(icondebristouch);
        //                }
        else if (gridtest.getCell(i, j) instanceof ShipCell) {
          ship = ((ShipCell) gridtest.getCell(i, j)).getShip();
          int size = ship.getSize();
          orient = ((ShipCell) gridtest.getCell(i, j)).getOrient();

          if (orient.isHorizontal()) {
            if (ship.getSize() == 2) {
              tabbout1[i][j].setIcon(iconsub1h);
              tabbout1[i][j + 1].setIcon(iconsub2h);
              tabbout1[i][j + 2].setIcon(iconsub3h);
              j = j + 2;

            } else if (ship.getSize() == 3) // battleship
            {
              tabbout1[i][j].setIcon(iconbattle1h);
              tabbout1[i][j + 1].setIcon(iconbattle2h);
              tabbout1[i][j + 2].setIcon(iconbattle3h);
              tabbout1[i][j + 3].setIcon(iconbattle4h);
              j = j + 3;
            } else {
              tabbout1[i][j].setIcon(iconair1h);
              tabbout1[i][j + 1].setIcon(iconair2h);
              tabbout1[i][j + 2].setIcon(iconair3h);
              tabbout1[i][j + 3].setIcon(iconair4h);
              tabbout1[i][j + 4].setIcon(iconair5h);
              j = j + 4;
            }
          }
        }
      }

      for (int i2 = 0; i2 < 10; i2++) // ligne
      {
        for (int j2 = 0; j2 < 10; j2++) // colonne
        {
          if (gridtest.getCell(i2, j2) instanceof ShipCell) {
            ship = ((ShipCell) gridtest.getCell(i2, j2)).getShip();
            orient = ((ShipCell) gridtest.getCell(i2, j2)).getOrient();

            if (!orient.isHorizontal()) {
              if (ship.getSize() == 2) {
                tabbout1[i2][j2].setIcon(iconsub1v);
                tabbout1[i2 + 1][j2].setIcon(iconsub2v);
                tabbout1[i2 + 2][j2].setIcon(iconsub3v);
                i2 = i2 + 2;
              } else if (ship.getSize() == 3) // battleship
              {
                tabbout1[i2][j2].setIcon(iconbattle1v);
                tabbout1[i2 + 1][j2].setIcon(iconbattle2v);
                tabbout1[i2 + 2][j2].setIcon(iconbattle3v);
                tabbout1[i2 + 3][j2].setIcon(iconbattle4v);
                i2 = i2 + 3;
              } else {
                tabbout1[i2][j2].setIcon(iconair1v);
                tabbout1[i2 + 1][j2].setIcon(iconair2v);
                tabbout1[i2 + 2][j2].setIcon(iconair3v);
                tabbout1[i2 + 3][j2].setIcon(iconair4v);
                tabbout1[i2 + 4][j2].setIcon(iconair5v);
                i2 = i2 + 4;
              }
            }
          }
        }
      }
    }
  }