/** Hacer el insert en la tabla REFERENCEMATRIX */
  public void doInsert(int Product, int option) {

    // Asocio producto
    X_XX_VMR_ReferenceMatrix matrix = new X_XX_VMR_ReferenceMatrix(Env.getCtx(), 0, null);

    matrix.setXX_VALUE1(0);
    matrix.setXX_VALUE2(0);
    matrix.setXX_COLUMN(0);
    matrix.setXX_ROW(0);
    matrix.setXX_QUANTITYC(LineRefProv.getQty());
    matrix.setXX_QUANTITYV(LineRefProv.getSaleQty());
    matrix.setXX_QUANTITYO(LineRefProv.getXX_GiftsQty());
    matrix.setXX_VMR_PO_LineRefProv_ID((Integer) LineRefProv.get_Value("XX_VMR_PO_LineRefProv_ID"));
    matrix.setM_Product(Product);

    matrix.save();

    if (option == 1) {

      tableInit_option = 1;
      tableInit();
      tableLoad(xAssociateTable);

      bDisassociate.setEnabled(true);
      bNewProduct.setEnabled(false);
    }
  }
Ejemplo n.º 2
0
  @Test
  public void testCButton_Icon() throws InterruptedException, InvocationTargetException {
    final Icon icon =
        new Icon() {

          @Override
          public void paintIcon(final Component c, final Graphics g, final int x, final int y) {
            // stupid stub
          }

          @Override
          public int getIconWidth() {
            return 0;
          }

          @Override
          public int getIconHeight() {
            return 0;
          }
        };

    CButton button = getButton(icon);
    assertThat(button.getIcon()).isSameAs(icon);

    button = getButton((Icon) null);
    assertThat(button.getIcon()).isNull();
  }
  /** Associate Button Pressed */
  private void cmd_associate() {
    int productRow = xProductTable.getSelectedRow();
    log.config("Row=" + productRow);

    KeyNamePair product = (KeyNamePair) xProductTable.getValueAt(productRow, 0);

    doInsert(product.getKey(), 0);

    //  ** Load Table **
    tableInit_option = 1;
    tableInit();
    tableLoad(xAssociateTable);

    //  ** Load Table **
    tableInit_option = 2;
    tableInit();
    tableLoad(xProductTable);

    bDisassociate.setEnabled(true);
    bNewProduct.setEnabled(false);

    // Coloco la referencia como asociada
    // MVMRVendorProdRef vendorProdRef = new MVMRVendorProdRef(Env.getCtx(),
    // LineRefProv.getXX_VMR_VendorProdRef_ID(), null);
    // vendorProdRef.setXX_IsAssociated(true);
    // vendorProdRef.save();

  } //  cmd_associate
 /**
  * Reassigns the set of canvases that this explorer controls. Though the collection of canvas may
  * be empty, it may not be null.
  *
  * @param items
  * @requires items != null && for each element in item, element!= null && the Collection is backed
  *     by a type that gives a consistent iteration order
  */
 public void setDrawersCard(Collection<? extends Canvas> items) {
   canvases.clear();
   buttonPane.removeAll();
   int size = items.size();
   if (size % 2 == 1) size++;
   size = buttonHeight * size;
   buttonPane.setPreferredSize(new Dimension(6, size));
   int i = 0;
   for (Canvas item : items) {
     final int index = i;
     // final CButton button = new CButton(item.getColor(),
     // item.getColor().brighter().brighter().brighter(),item.getName());
     CButton button = new CBorderlessButton(item.getName());
     JComponent scroll =
         new CHoverScrollPane(
             item.getJComponent(),
             ScrollPolicy.VERTICAL_BAR_AS_NEEDED,
             ScrollPolicy.HORIZONTAL_BAR_AS_NEEDED,
             18,
             item.getColor(),
             Color.darkGray);
     canvases.add(scroll);
     button.addActionListener(
         new ActionListener() {
           public void actionPerformed(ActionEvent e) {
             selectCanvas(index);
           }
         });
     buttonPane.add(button);
     i++;
   }
   if (!canvases.isEmpty()) canvasPane.add(canvases.get(0));
   this.revalidate();
 }
 void connectionFailed() {
   login.setEnabled(true);
   logout.setEnabled(false);
   // whoIsIn.setEnabled(false);
   chatStatus.setText("Please login first");
   chatField.setText("");
   // reset port number and host name as a construction time
   tfPort.setText("" + defaultPort);
   tfServer.setText(defaultHost);
   // let the user change them
   tfServer.setEditable(false);
   tfPort.setEditable(false);
   // don't react to a <CR> after the username
   chatField.removeActionListener(this);
   connected = false;
 }
  public void validAuthenticate() {
    chatStatus.setText("Enter your message below");
    connected = true;

    // disable login button
    login.setEnabled(false);
    // enable the 2 buttons
    logout.setEnabled(true);
    // whoIsIn.setEnabled(true);
    // disable the Server and Port JTextField
    tfServer.setEditable(false);
    tfPort.setEditable(false);
    // Action listener for when the user enter a message
    chatField.addActionListener(this);

    switchCards("Menu");
  }
Ejemplo n.º 7
0
  @Test
  public void testCButton_Action() throws InterruptedException, InvocationTargetException {
    final Action act =
        new AbstractAction() {
          /** serial version UID */
          private static final long serialVersionUID = -2312442386490910405L;

          @Override
          public void actionPerformed(final ActionEvent e) {
            // do nothing, stupid stub
          }
        };
    CButton button = getButton(act);
    assertThat(button.getAction()).isSameAs(act);

    button = getButton((AbstractAction) null);
    assertThat(button.getAction()).isNull();
  }
  /** Disassociate Button Pressed */
  private void cmd_disassociate() {
    if (verify()) {
      // desasocio el producto
      X_XX_VMR_ReferenceMatrix matrix =
          new X_XX_VMR_ReferenceMatrix(Env.getCtx(), associatedReference_ID, null);
      matrix.delete(true);

      tableInit_option = 0;
      tableInit();
      tableLoad(xProductTable);

      tableInit_option = 1;
      tableInit();
      tableLoad(xAssociateTable);

      bDisassociate.setEnabled(false);
      bNewProduct.setEnabled(true);
    }
  } //  cmd_disassociate
Ejemplo n.º 9
0
  @Test
  public void testCButton_StringString() {
    CButton item = getButton("item", (String) null);
    assertThat(item.getName()).isEqualTo("item");
    assertThat(item.getText()).isEmpty();

    item = getButton("", "txt");
    assertThat(item.getName()).isEmpty();
    assertThat(item.getText()).isEqualTo("txt");

    item = getButton(null, "");
    assertThat(item.getName()).isNull();
    assertThat(item.getText()).isEmpty();

    item = getButton(" .. ", "12 <-> 34");
    assertThat(item.getName()).isEqualTo(" .. ");
    assertThat(item.getText()).isEqualTo("12 <-> 34");
  }
Ejemplo n.º 10
0
 public static void main(String[] args) {
   JFrame f = new JFrame();
   f.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
   f.setLayout(new FlowLayout());
   f.setSize(500, 300);
   f.getContentPane().setBackground(Color.red);
   final CButton c = new CGraphiteButton("hi");
   f.add(c);
   f.setVisible(true);
   f.repaint();
   final CPopupMenu menu = new CPopupMenu();
   for (int i = 0; i < 17; i++) {
     menu.add(new CMenuItem("hi"));
   }
   c.addActionListener(
       new ActionListener() {
         public void actionPerformed(ActionEvent e) {
           menu.show(c, 0, 0);
         }
       });
   c.add(menu);
   System.out.println(menu.getParent());
 }
Ejemplo n.º 11
0
  @Test
  public void testCButton_StringIcon() throws InterruptedException, InvocationTargetException {
    CButton button = getButton("St[a]rt", (Icon) null);
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_A);
    assertThat(button.getText()).isEqualTo("Start");

    button = getButton("St[ar]t", (Icon) null);
    assertThat(button.getText()).isEqualTo("St[ar]t");

    button = getButton("Star[t]", (Icon) null);
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_T);
    assertThat(button.getText()).isEqualTo("Start");

    button = getButton("[S]tart", (Icon) null);
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_S);
    assertThat(button.getText()).isEqualTo("Start");
  }
  /** Constructs new TabbedExplorer that is scrollable if specified as true. */
  public TabbedExplorer(boolean scrollable) {
    super();
    this.scrollable = scrollable;
    this.drawerCards = new ArrayList<TabCard>();
    this.canvasPane = new JPanel(new BorderLayout());
    canvasPane.setBorder(BorderFactory.createMatteBorder(5, 5, 5, 5, CGraphite.blue));

    this.setBackground(Color.black);
    this.timer = new Timer(300, this);
    menu = new JPopupMenu();
    wheeler = new CWheeler(new ArrayList<JComponent>(), false, Color.black);
    wheeler.setPreferredSize(new Dimension(wheeler.getPreferredSize().width, BUTTON_HEIGHT));

    left = new CTabButton("<<");
    left.setPreferredSize(BUTTON_DIMENSION);
    left.addMouseListener(this);
    right = new CTabButton(">>");
    right.setPreferredSize(BUTTON_DIMENSION);
    right.addMouseListener(this);
    down = new CTabButton("V");
    down.setPreferredSize(BUTTON_DIMENSION);
    down.addMouseListener(this);

    setLayout(new GridBagLayout());

    GridBagConstraints gbc = new GridBagConstraints();
    gbc.gridx = 0;
    gbc.gridy = 0;
    gbc.weightx = 0;
    gbc.weighty = 0;
    gbc.fill = GridBagConstraints.NONE;
    add(left, gbc);

    gbc.gridx++;
    gbc.weightx = 1;
    gbc.fill = GridBagConstraints.BOTH;
    add(wheeler, gbc);

    gbc.gridx++;
    gbc.weightx = 0;
    gbc.fill = GridBagConstraints.NONE;
    add(right, gbc);

    gbc.gridx++;
    add(down, gbc);

    gbc.gridx = 0;
    gbc.gridy++;
    gbc.gridwidth = 4;
    gbc.weightx = 1;
    gbc.weighty = 1;
    gbc.fill = GridBagConstraints.BOTH;
    add(canvasPane, gbc);
  }
Ejemplo n.º 13
0
  @Test
  public void testCButton_StringAction() {
    CButton item = getButton("item", (Action) null);
    assertThat(item.getName()).isEqualTo("item");
    assertThat(item.getAction()).isNull();

    item =
        getButton(
            "",
            new AbstractAction("ACTION") {
              /** ... */
              private static final long serialVersionUID = 1L;

              @Override
              public void actionPerformed(final ActionEvent e) {}
            });
    assertThat(item.getName()).isEmpty();
    assertThat(item.getText()).isEqualTo("ACTION");
    assertThat(item.getAction()).isInstanceOf(AbstractAction.class);
  }
  /**
   * Static Init.
   *
   * <pre>
   *  mainPanel
   *      northPanel
   *      centerPanel
   *          xMatched
   *          xPanel
   *          xMathedTo
   *      southPanel
   *  </pre>
   *
   * @throws Exception
   */
  private void jbInit() throws Exception {
    mainPanel.setLayout(mainLayout);
    northPanel.setLayout(northLayout);

    // LineRefProv_Label.setText(Msg.getMsg(Env.getCtx(), "RecordNo",new String[]
    // {""+LineRefProv.getXX_VMR_PO_LineRefProv_ID()}));
    LineRefProv_Label.setText("");
    southPanel.setLayout(southLayout);
    bNewProduct.setText(Msg.translate(Env.getCtx(), "NewProduct"));
    bNewProduct.setEnabled(true);
    bDisassociate.setText(Msg.translate(Env.getCtx(), "Disassociate"));
    bDisassociate.setEnabled(false);
    centerPanel.setLayout(centerLayout);
    xProductScrollPane.setBorder(xProductBorder);
    xProductScrollPane.setPreferredSize(new Dimension(450, 150));
    xAssociateScrollPane.setBorder(xAssociateBorder);
    xAssociateScrollPane.setPreferredSize(new Dimension(450, 58));

    xPanel.setLayout(xLayout);
    mainPanel.add(northPanel, BorderLayout.NORTH);
    northPanel.add(
        LineRefProv_Label,
        new GridBagConstraints(
            0,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(12, 12, 5, 5),
            0,
            0));

    mainPanel.add(southPanel, BorderLayout.SOUTH);

    mainPanel.add(centerPanel, BorderLayout.CENTER);
    centerPanel.add(xProductScrollPane, BorderLayout.NORTH);
    xProductScrollPane.getViewport().add(xProductTable, null);
    centerPanel.add(xAssociateScrollPane, BorderLayout.SOUTH);
    centerPanel.add(xPanel, BorderLayout.CENTER);
    xAssociateScrollPane.getViewport().add(xAssociateTable, null);

    southPanel.add(
        bDisassociate,
        new GridBagConstraints(
            2,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.EAST,
            GridBagConstraints.NONE,
            new Insets(5, 12, 5, 12),
            0,
            0));
    southPanel.add(
        bNewProduct,
        new GridBagConstraints(
            8,
            0,
            1,
            1,
            0.0,
            0.0,
            GridBagConstraints.WEST,
            GridBagConstraints.NONE,
            new Insets(5, 12, 5, 12),
            0,
            0));
  } //  jbInit
  // Constructor connection receiving a socket number
  public ClientGUI(String host, int port, int udpPort) {

    super("Clash of Clans");
    defaultPort = port;
    defaultUDPPort = udpPort;
    defaultHost = host;

    // the server name and the port number
    JPanel serverAndPort = new JPanel(new GridLayout(1, 5, 1, 3));
    tfServer = new JTextField(host);
    tfPort = new JTextField("" + port);
    tfPort.setHorizontalAlignment(SwingConstants.RIGHT);

    // CHAT COMPONENTS
    chatStatus = new JLabel("Please login first", SwingConstants.LEFT);
    chatField = new JTextField(18);
    chatField.setBackground(Color.WHITE);

    JPanel chatControls = new JPanel();
    chatControls.add(chatStatus);
    chatControls.add(chatField);
    chatControls.setBounds(0, 0, 200, 50);

    chatArea = new JTextArea("Welcome to the Chat room\n", 80, 80);
    chatArea.setEditable(false);
    JScrollPane jsp = new JScrollPane(chatArea);
    jsp.setBounds(0, 50, 200, 550);

    JPanel chatPanel = new JPanel(null);
    chatPanel.setSize(1000, 600);
    chatPanel.add(chatControls);
    chatPanel.add(jsp);

    // LOGIN COMPONENTS
    mainLogin = new MainPanel();
    mainLogin.add(new JLabel("Main Login"));

    usernameField = new JTextField("user", 15);
    passwordField = new JTextField("password", 15);
    login = new CButton("Login");
    login.addActionListener(this);

    sideLogin = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    sideLogin.add(usernameField);
    sideLogin.add(passwordField);
    sideLogin.add(login);

    // MAIN MENU COMPONENTS
    mainMenu = new MainPanel();
    mmLabel = new JLabel("Main Menu");
    timer = new javax.swing.Timer(1000, this);
    mainMenu.add(mmLabel);

    sideMenu = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmButton = new CButton("Customize Map");
    tmButton = new CButton("Troop Movement");
    gsButton = new CButton("Game Start");
    logout = new CButton("Logout");
    cmButton.addActionListener(this);
    tmButton.addActionListener(this);
    gsButton.addActionListener(this);
    logout.addActionListener(this);
    sideMenu.add(cmButton);
    // sideMenu.add(tmButton);
    sideMenu.add(gsButton);
    sideMenu.add(logout);

    // CM COMPONENTS
    mainCM = new MainPanel(new GridLayout(mapSize, mapSize));
    tiles = new Tile[mapSize][mapSize];
    int tileSize = mainCM.getWidth() / mapSize;
    for (int i = 0; i < mapSize; i++) {
      tiles[i] = new Tile[mapSize];
      for (int j = 0; j < mapSize; j++) {
        tiles[i][j] = new Tile(i, j);
        tiles[i][j].setPreferredSize(new Dimension(tileSize, tileSize));
        tiles[i][j].setSize(tileSize, tileSize);
        tiles[i][j].addActionListener(this);

        if ((i + j) % 2 == 0) tiles[i][j].setBackground(new Color(102, 255, 51));
        else tiles[i][j].setBackground(new Color(51, 204, 51));

        mainCM.add(tiles[i][j]);
      }
    }

    sideCM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    cmBack = new CButton("Main Menu");
    cmBack.setSize(150, 30);
    cmBack.setPreferredSize(new Dimension(150, 30));
    cmBack.addActionListener(this);
    sideCM.add(cmBack);

    // TM COMPONENTS
    mainTM = new MainPanel(null);
    mapTM = new Map(600);
    mapTM.setPreferredSize(new Dimension(600, 600));
    mapTM.setSize(600, 600);
    mapTM.setBounds(0, 0, 600, 600);
    mainTM.add(mapTM);

    sideTM = new SidePanel(new FlowLayout(FlowLayout.LEFT));
    tmBack = new CButton("Main Menu");
    tmBack.setSize(150, 30);
    tmBack.setPreferredSize(new Dimension(150, 30));
    tmBack.addActionListener(this);
    sideTM.add(tmBack);

    JRadioButton button;
    ButtonGroup group;

    ub = new ArrayList<JRadioButton>();
    group = new ButtonGroup();

    button = new JRadioButton("Barbarian");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    button = new JRadioButton("Archer");
    button.addActionListener(this);
    ub.add(button);
    sideTM.add(button);
    group.add(button);

    createBuildings();
    bb = new ArrayList<JRadioButton>();

    group = new ButtonGroup();

    JRadioButton removeButton = new JRadioButton("Remove Building");
    bb.add(removeButton);
    sideCM.add(removeButton);
    group.add(removeButton);

    for (int i = 0; i < bList.size(); i++) {
      button = new JRadioButton(bList.get(i).getName() + '-' + bList.get(i).getQuantity());
      bb.add(button);
      sideCM.add(button);
      group.add(button);
    }

    mainPanels = new MainPanel(new CardLayout());
    mainPanels.add(mainLogin, "Login");
    mainPanels.add(mainMenu, "Menu");
    mainPanels.add(mainCM, "CM");
    mainPanels.add(mainTM, "TM");

    sidePanels = new SidePanel(new CardLayout());
    sidePanels.add(sideLogin, "Login");
    sidePanels.add(sideMenu, "Menu");
    sidePanels.add(sideCM, "CM");
    sidePanels.add(sideTM, "TM");

    JPanel mainPanel = new JPanel(null);
    mainPanel.setSize(1000, 600);
    mainPanel.add(sidePanels);
    mainPanel.add(mainPanels);
    mainPanel.add(chatPanel);

    add(mainPanel, BorderLayout.CENTER);

    try {
      setIconImage(ImageIO.read(new File("images/logo.png")));
    } catch (IOException exc) {
      exc.printStackTrace();
    }

    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setSize(1000, 600);
    setVisible(true);
    setResizable(false);
    chatField.requestFocus();
  }
  public void actionPerformed(ActionEvent e) {
    Object o = e.getSource();

    for (JRadioButton u : ub) {
      if (o == u) {
        mapTM.setUnitType(u.getText());
        System.out.println("Set unit type - " + u.getText());
        return;
      }
    }

    if (o == timer) {

      /*
      mmLabel.setText("Main Menu ("+(cdTime--)+")");

      if(cdTime == 0){
      	timer.stop();
      	gsButton.setText("Game Start");
      	mmLabel.setText("Main Menu");

      	ArrayList<Building> bArr = new ArrayList<Building>();

      	String temp = "Elixir Collector-24,8-960|Elixir Collector-31,8-960|Gold Mine-17,10-960|Elixir Collector-25,21-960|Elixir Collector-11,22-960";
      	String[] bs = temp.split("\\|");
      	for(String b : bs){
      		String[] bParts = b.split("-");
      		String[] cParts = bParts[1].split(",");
      		int x = Integer.parseInt(cParts[0].trim());
      		int y = Integer.parseInt(cParts[1].trim());

      		Building tb = new Building(bParts[0], new Coordinate(x,y));
      		tb.setHp(Integer.parseInt(bParts[2].trim()));

      		bArr.add(tb);
      	}



      	mapTM.setBuildings(bArr);
      	switchCards("TM");
      }
      */

      return;
    }

    if (o == gsButton) {

      if (timer.isRunning()) {
        // timer.stop();
        gsButton.setText("Game Start");
        mmLabel.setText("Main Menu");
        // sends the leave command
        client.sendUDP("leave~" + unameUDP);
        return;
      }
      // sends the joinlobby command
      client.sendUDP("joinlobby~" + unameUDP);
      // gsButton.setText("Game Stop");
      String serverResp = client.receiveUDP();

      if (serverResp.trim().equals("false")) {

        // place false handler here

      } else {

        String[] enemies = serverResp.trim().split(",");
        ArrayList<Building> bArr = new ArrayList<Building>();
        String mapConfig = getBaseConfig(enemies[0]);
        String[] bs = mapConfig.split("\\|");
        for (String b : bs) {

          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          Building tb = new Building(bParts[0], new Coordinate(x, y));
          tb.setHp(Integer.parseInt(bParts[2].trim()));
          bArr.add(tb);
        }

        mapTM.setBuildings(bArr);
        switchCards("TM");
      }

      // System.out.println(serverResp);
      // cdTime = 10;
      // timer.start();
      return;
    }

    if (o == logout) {
      client.sendMessage(new ChatMessage(ChatMessage.LOGOUT, ""));
      chatArea.setText("");

      switchCards("Login");
      return;
    }

    if (o == cmButton) {
      String baseConfig = getBaseConfig();
      System.out.println("base config: " + baseConfig);

      for (int i = 0; i < mapSize; i++) {
        for (int j = 0; j < mapSize; j++) {
          tiles[i][j].setValue("");
        }
      }

      if (!baseConfig.equals("")) {

        String[] bs = baseConfig.split("\\|");
        for (String b : bs) {
          String[] bParts = b.split("-");
          String[] cParts = bParts[1].split(",");
          int x = Integer.parseInt(cParts[0].trim());
          int y = Integer.parseInt(cParts[1].trim());

          int index = 0;
          for (int i = 0; i < bb.size(); i++) {
            if (bb.get(i).getText().split("-")[0].trim().equals(bParts[0])) {
              index = i;
              break;
            }
          }
          insertBuilding(y, x, index);
        }
      }

      switchCards("CM");

      return;
    }

    if (o == tmButton) {

      ArrayList<Building> bArr = new ArrayList<Building>();

      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      mapTM.setBuildings(bArr);

      switchCards("TM");
      return;
    }

    // if it the who is in button
    if (o == whoIsIn) {
      client.sendMessage(new ChatMessage(ChatMessage.WHOISIN, ""));
      return;
    }

    if (o == cmBack) {
      ArrayList<Building> bArr = new ArrayList<Building>();
      for (int i = 0; i < 40; i++) {
        for (int j = 0; j < 40; j++) {
          if (tiles[i][j].getValue().equals("") || tiles[i][j].getValue().contains("-")) {
            continue;
          }
          // weird part here
          bArr.add(new Building(tiles[i][j].getValue(), new Coordinate(j, i)));
        }
      }

      String temp = "mapdata~" + unameUDP + "~";
      int tileCount = 40;
      int dim = 600;
      int tileDim = (int) (dim / tileCount);
      int counter = 0;
      for (Building b : bArr) {
        int x, y, hp;
        x = b.getPos().getX() / tileDim;
        y = b.getPos().getY() / tileDim;
        hp = b.getHp();
        temp += b.getName() + "-" + x + "," + y + "-" + hp + "|";
        counter += 1;
      }
      if (counter > 0) {
        temp = temp.substring(0, temp.length() - 1); // removes the last '|'
      } else {
        temp += "none";
      }

      client.sendUDP(temp); // allows saving of the current state of the map into the user's account

      switchCards("Menu");

      return;
    }
    if (o == tmBack) {
      switchCards("Menu");

      return;
    }

    for (int i = 0; i < 40; i++) {
      for (int j = 0; j < 40; j++) {
        if (o == tiles[i][j]) {
          for (int k = 0; k < bb.size(); k++) {
            if (bb.get(k).isSelected()) {
              if (bb.get(k).getText().equals("Remove Building")) {
                removeBuilding(i, j);
                return;
              }

              insertBuilding(i, j, k);
              // JOptionPane.showMessageDialog(null, bb.get(k).getText());
              return;
            }
          }

          // JOptionPane.showMessageDialog(null, "i-"+i+" j-"+j);
          return;
        }
      }
    }

    // ok it is coming from the JTextField
    if (connected) {
      // just have to send the message
      client.sendMessage(new ChatMessage(ChatMessage.MESSAGE, chatField.getText()));
      chatField.setText("");
      return;
    }

    if (o == login) {
      // ok it is a connection request
      String username = usernameField.getText().trim();
      String password = passwordField.getText().trim();
      // empty username ignore it
      if (username.length() == 0) return;
      // empty serverAddress ignore it
      String server = tfServer.getText().trim();
      if (server.length() == 0) return;
      // empty or invalid port numer, ignore it
      String portNumber = tfPort.getText().trim();
      if (portNumber.length() == 0) return;
      int port = 0;
      try {
        port = Integer.parseInt(portNumber);
      } catch (Exception en) {
        return; // nothing I can do if port number is not valid
      }

      // try creating a new Client with GUI
      client = new Client(server, port, username, password, this);
      // test if we can start the Client
      if (!client.start()) return;

      unameUDP = username;

      switchCards("Menu");
      // fetching of the base_config string from the database

      chatField.setText("");
      chatArea.setText("");
    }
  }
Ejemplo n.º 17
0
 public void Draw() {
   if (!enabled) return;
   super.Draw();
   // DrawText(x+2,y+2,text,color);
 }
Ejemplo n.º 18
0
  @Test
  public void testCButton_StringStringIcon() {
    Icon icon = new ImageIcon(new byte[214]);
    CButton item = getButton("item", (String) null, icon);
    assertThat(item.getName()).isEqualTo("item");
    assertThat(item.getText()).isEmpty();
    assertThat(item.getIcon()).isEqualTo(icon);

    item = getButton("", "txt", icon);
    assertThat(item.getName()).isEmpty();
    assertThat(item.getText()).isEqualTo("txt");
    assertThat(item.getIcon()).isEqualTo(icon);

    icon = new ImageIcon(new byte[42]);
    item = getButton(null, "", icon);
    assertThat(item.getName()).isNull();
    assertThat(item.getText()).isEmpty();
    assertThat(item.getIcon()).isEqualTo(icon);

    icon = new ImageIcon();
    item = getButton(" .. ", "12 <-> 34", icon);
    assertThat(item.getName()).isEqualTo(" .. ");
    assertThat(item.getText()).isEqualTo("12 <-> 34");
    assertThat(item.getIcon()).isEqualTo(icon);
  }
  /** Dynamic Init. Table Layout, Visual, Listener */
  private void dynInit() {

    ColumnInfo[] layout =
        new ColumnInfo[] {
          new ColumnInfo(Msg.translate(Env.getCtx(), "M_Product_ID"), ".", KeyNamePair.class), //  1
          new ColumnInfo(Msg.translate(Env.getCtx(), "Name"), ".", String.class) //  2
        };

    xProductTable.prepareTable(layout, "", "", false, "");
    xAssociateTable.prepareTable(layout, "", "", true, "");

    xAssociateTable.setAutoResizeMode(3);
    xProductTable.setAutoResizeMode(3);

    //  Visual
    CompiereColor.setBackground(this);

    //  Listener
    xProductTable.getSelectionModel().addListSelectionListener(this);
    xAssociateTable.getModel().addTableModelListener(this);
    bDisassociate.addActionListener(this);
    bNewProduct.addActionListener(this);

    // pregunto si hay productos asociados para ver si cargo las tablas
    boolean ready = verify();

    if (ready == false) {

      tableInit_option = 0;
      tableInit();
      tableLoad(xProductTable);

    } else {
      tableInit_option = 1;
      tableInit();
      tableLoad(xAssociateTable);

      bNewProduct.setEnabled(false);
      bDisassociate.setEnabled(true);
    }

    xProductTable.addMouseListener(
        new MouseAdapter() {
          public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2) {

              int rowP = xProductTable.getSelectedRow();

              if (!(rowP == -1)) {
                cmd_associate();
              }
            }
          }
        });

    //  Init
    statusBar.setStatusLine("");
    statusBar.setStatusDB(0);

    MOrder order = new MOrder(Env.getCtx(), LineRefProv.getC_Order_ID(), null);

    boolean block = false;
    String oS = order.getXX_OrderStatus();
    String compS = order.getDocStatus();
    if (oS.equals("AN") || compS.equals("CO")) {
      block = true;
    }

    if (order.isXX_OrderReadyStatus() && order.getXX_OrderType().equalsIgnoreCase("Nacional"))
      block = true;

    if (order.getXX_OrderType().equalsIgnoreCase("Importada")
        && order.get_ValueAsInt("XX_ImportingCompany_ID") != 0) {

      if (order.get_ValueAsInt("XX_ImportingCompany_ID")
          != Env.getCtx().getContextAsInt("#XX_L_VSI_CLIENTCENTROBECO_ID")) {
        block = true;
      }
    }

    if (order.getXX_StoreDistribution().equals("Y") || block) {
      xProductTable.setEnabled(false);
      xAssociateTable.setEnabled(false);
      bNewProduct.setEnabled(false);
      bDisassociate.setEnabled(false);
    }
  } //  dynInit
Ejemplo n.º 20
0
  @Test
  public void testSetTextString() throws InterruptedException, InvocationTargetException {
    final CButton button = getButton();
    setText(button, "St[a]rt");
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_A);
    assertThat(button.getText()).isEqualTo("Start");

    setText(button, "St[ar]t");
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_A);
    assertThat(button.getText()).isEqualTo("St[ar]t");

    setText(button, "Star[t]");
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_T);
    assertThat(button.getText()).isEqualTo("Start");

    setText(button, "[S]tart");
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_S);
    assertThat(button.getText()).isEqualTo("Start");

    setText(button, null);
    assertThat(button.getMnemonic()).isEqualTo(KeyEvent.VK_S);
    assertThat(button.getText()).isNull();
  }