/** Remove All and their listeners */
 public void removeAll() {
   m_nodes.clear();
   m_lines.clear();
   Component[] components = getComponents();
   for (int i = 0; i < components.length; i++) {
     Component component = components[i];
     component.removeMouseListener(this);
     component.removeMouseMotionListener(this);
   }
   super.removeAll();
 } //	removeAll
  /**
   * ActionListener
   *
   * @param e ActionEvent
   */
  public void actionPerformed(ActionEvent e) {
    if (e.getActionCommand().equals(ConfirmPanel.A_OK)) {
      if (fAddress1.isMandatory() && ((((String) fAddress1.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fAddress2.isMandatory() && ((((String) fAddress2.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fAddress3.isMandatory() && ((((String) fAddress3.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else if (fPostal.isMandatory() && ((((String) fPostal.getValue()).trim()).isEmpty()))
        JOptionPane.showMessageDialog(null, "Preencha todos os campos corretamente");
      else {
        action_OK();
        m_change = true;
        dispose();
      }
    } else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) {
      m_change = false;
      dispose();
    } else if (e.getSource() == fCountry) {
      //	Country Changed - display in new Format
      //	Modifier for Mouse selection is 16  - for any key selection 0
      MCountry c = (MCountry) fCountry.getSelectedItem();
      m_location.setCountry(c);
      //	refrseh
      mainPanel.removeAll();
      initLocation();
      fCountry.requestFocus(); // 	allows to use Keybord selection
    }
    // Kenos
    else if (e.getSource() == fRegion) {
      //	Modifier for Mouse selection is 16  - for any key selection 0
      MRegion r = (MRegion) fRegion.getSelectedItem();
      m_location.setRegion(r);
      //	refrseh
      mainPanel.removeAll();
      initLocation();
      fRegion.requestFocus(); // 	allows to use Keybord selection
    }
    // Kenos
    else if (e.getSource() == toLink) {
      String urlString = GOOGLE_MAPS_URL_PREFIX + getGoogleMapsLocation(m_location);
      String message = null;

      try {
        new URL(urlString);
        Env.startBrowser(urlString);
      } catch (Exception ex) {
        message = ex.getMessage();
        ADialog.warn(0, this, "URLnotValid", message);
      }
    } else if (e.getSource() == toRoute) {
      int AD_Org_ID = Env.getAD_Org_ID(Env.getCtx());
      if (AD_Org_ID != 0) {
        MOrgInfo orgInfo = MOrgInfo.get(Env.getCtx(), AD_Org_ID, null);
        MLocation orgLocation = new MLocation(Env.getCtx(), orgInfo.getC_Location_ID(), null);

        String urlString =
            GOOGLE_MAPS_ROUTE_PREFIX
                + GOOGLE_SOURCE_ADDRESS
                + getGoogleMapsLocation(orgLocation)
                + // org
                GOOGLE_DESTINATION_ADDRESS
                + getGoogleMapsLocation(m_location); // partner
        String message = null;
        try {
          new URL(urlString);
          Env.startBrowser(urlString);
        } catch (Exception ex) {
          message = ex.getMessage();
          ADialog.warn(0, this, "URLnotValid", message);
        }
      }
    } else if (e.getSource() == getAddress) {
      if (fPostal != null && !fPostal.getText().equals("")) {
        if (!fAddress1.getText().equals("")
            || !fAddress2.getText().equals("")
            || !fAddress3.getText().equals("")
            || !fAddress4.getText().equals("")
            || fCity.getSelectedIndex() > 0) {
          String warningMsg = "O endereço atual será substituido. Deseja continuar?";
          String warningTitle = "Aviso";
          int response =
              JOptionPane.showConfirmDialog(
                  null, warningMsg, warningTitle, JOptionPane.YES_NO_OPTION);
          if (response == JOptionPane.NO_OPTION) return;
        }

        WebServiceCep cep = WebServiceCep.searchCep(fPostal.getText());
        if (cep.wasSuccessful()) {
          MRegion[] regions = MRegion.getRegions(Env.getCtx(), 139);
          for (MRegion r : regions)
            if (r.getName() != null && r.getName().equals(cep.getUf())) {
              fRegion.setSelectedItem(r);
              break;
            }
          fCity.setSelectedItem(cep.getCidade());
          fAddress1.setText(cep.getLogradouroType() + " " + cep.getLogradouro());
          fAddress3.setText(cep.getBairro());
          if (cep.getCep().length() == 8)
            fPostal.setText(cep.getCep().substring(0, 5) + "-" + cep.getCep().substring(5));
          else fPostal.setText(cep.getCep());
        } else if (cep.getResulCode() == 0)
          JOptionPane.showMessageDialog(null, "CEP não encontrado na base de dados.");
        else if (cep.getResulCode() == 14)
          JOptionPane.showMessageDialog(
              null, "Não foi possível fazer a busca. (Possível problema com a Internet).");
        else JOptionPane.showMessageDialog(null, "Erro ao fazer a busca.");
      } else JOptionPane.showMessageDialog(null, "Preencha o CEP.");
    }
  } //	actionPerformed
Example #3
0
  /**
   * Descripción de Método
   *
   * @param index
   */
  private void displayData(int index) {
    MAttachmentEntry entry = m_attachment.getEntry(index);

    log.config("Index=" + index + " - " + entry);

    // Reset UI

    gifPanel.setImage(null);
    graphPanel.removeAll();

    //

    bDelete.setEnabled(false);
    bOpen.setEnabled(false);
    bSave.setEnabled(false);

    Dimension size = null;

    // no attachment

    if ((entry == null) || (entry.getData() == null)) {
      info.setText("-");
    } else {
      bOpen.setEnabled(true);
      bSave.setEnabled(true);
      bDelete.setEnabled(true);
      log.config(entry.toStringX());

      //

      info.setText(entry.toStringX());

      if (entry.isPDF()) {
        try {
          graphPanel.getInsets();

          PdfPanel pdfpanel =
              PdfPanel.loadPdf(entry.getFile(), graphPanel, false, false, true, true, true, true);

          size = pdfpanel.getSize();

          //

        } catch (Exception e) {
          log.log(Level.SEVERE, "(pdf)", e);
        }
      } else if (entry.isGraphic()) {

        // Can we display it

        Image image = Toolkit.getDefaultToolkit().createImage(entry.getData());

        if (image != null) {
          gifPanel.setImage(image);
          size = gifPanel.getPreferredSize();

          if ((size.width == -1) && (size.height == -1)) {
            log.log(Level.SEVERE, "Invalid Image");
          } else {

            // size.width += 40;
            // size.height += 40;

            graphPanel.add(gifScroll, BorderLayout.CENTER);
          }
        } else {
          log.log(Level.SEVERE, "Could not create image");
        }
      }
    }

    if (graphPanel.getComponentCount() == 0) {
      graphPanel.add(info, BorderLayout.CENTER);
    }

    log.config("Size=" + size);

    // graphPanel.setPreferredSize(size);
    // centerPane.setDividerLocation(size.width+30);
    // size.width += 100;
    // size.height += 100;
    // centerPane.setPreferredSize(size);

    pack();
  } // displayData
Example #4
0
  /** Create Grid */
  private void createGrid() {
    if (attributeCombo1 == null || m_setting) return; // 	init
    int indexAttr1 = attributeCombo1.getSelectedIndex();
    int indexAttr2 = attributeCombo2.getSelectedIndex();
    if (indexAttr1 == indexAttr2) {
      log.warning("Same Attribute Selected");
      tabbedPane.setSelectedIndex(0);
      return;
    }
    m_setting = true;
    m_M_PriceList_Version_ID = 0;
    KeyNamePair pl = (KeyNamePair) pickPriceList.getSelectedItem();
    if (pl != null) m_M_PriceList_Version_ID = pl.getKey();
    m_M_Warehouse_ID = 0;
    KeyNamePair wh = (KeyNamePair) pickWarehouse.getSelectedItem();
    if (wh != null) m_M_Warehouse_ID = wh.getKey();

    //	x dimension
    int cols = 2;
    MAttributeValue[] xValues = null;
    if (indexAttr1 > 0) xValues = m_attributes[indexAttr1 - 1].getMAttributeValues();
    if (xValues != null) {
      cols = xValues.length;
      log.info("X - " + m_attributes[indexAttr1 - 1].getName() + " #" + xValues.length);
    }

    //	y dimension
    int rows = 2;
    MAttributeValue[] yValues = null;
    if (indexAttr2 > 0) yValues = m_attributes[indexAttr2 - 1].getMAttributeValues();
    if (yValues != null) {
      rows = yValues.length;
      log.info("Y - " + m_attributes[indexAttr2 - 1].getName() + " #" + yValues.length);
    }

    //
    gridPanel.removeAll();
    CPanel grid = new CPanel(new GridLayout(rows, cols, 5, 5));
    gridPanel.add(modePanel, BorderLayout.NORTH);
    gridPanel.add(new CScrollPane(grid), BorderLayout.CENTER);
    //
    log.info("Rows=" + rows + " - Cols=" + cols);
    for (int row = 0; row < rows; row++) {
      for (int col = 0; col < cols; col++) {
        MAttributeValue xValue = null;
        if (xValues != null) xValue = xValues[col];
        MAttributeValue yValue = null;
        if (yValues != null) yValue = yValues[row];
        //	log.fine("Row=" + row + " - Col=" + col);
        //
        if (row == 0 && col == 0) {
          CPanel descr = new CPanel(new GridLayout(2, 1, 0, 0));
          if (xValues != null)
            descr.add(new JLabel(m_attributes[indexAttr1 - 1].getName(), JLabel.TRAILING));
          if (yValues != null) descr.add(new JLabel(m_attributes[indexAttr2 - 1].getName()));
          grid.add(descr);
        } else if (row == 0) // 	column labels
        {
          if (xValue != null) {
            grid.add(new JLabel(xValue.getName(), JLabel.TRAILING));
          } else grid.add(new JLabel());
        } else if (col == 0) // 	row labels
        {
          if (yValue != null) grid.add(new JLabel(yValue.getName()));
          else grid.add(new JLabel());
        } else {
          grid.add(getGridElement(xValue, yValue));
        }
      }
    }
    //
    tabbedPane.setSelectedIndex(1);
    m_setting = false;
    m_frame.pack();
  } //	createGrid
Example #5
0
  /**
   * Descripción de Método
   *
   * @param index
   */
  private void displayData(int index) {
    MAttachmentEntry entry = m_attachment.getEntry(index);

    log.config("Index=" + index + " - " + entry);

    // Reset UI

    gifPanel.setImage(null);
    graphPanel.removeAll();

    //

    bDelete.setEnabled(false);
    bOpen.setEnabled(false);
    bSave.setEnabled(false);

    Dimension size = null;

    // no attachment

    if ((entry == null) || (entry.getData() == null)) {
      info.setText("-");
    } else {
      bOpen.setEnabled(true);
      bSave.setEnabled(true);
      bDelete.setEnabled(true);
      log.config(entry.toStringX());

      //

      info.setText(entry.toStringX());

      if (entry.isPDF()) {
        try {
          graphPanel.getInsets();

          PdfPanel pdfpanel =
              PdfPanel.loadPdf(entry.getFile(), graphPanel, false, false, true, true, true, true);

          size = pdfpanel.getSize();

          //

        } catch (Exception e) {
          log.log(Level.SEVERE, "(is pdf):" + e.getMessage(), e);
        }
      } else if (entry.isGraphic()) {

        // Can we display it

        /*
         * ---------------------------------------------------------------------------------
         * Modified by Matías Cap - Disytel
         * ---------------------------------------------------------------------------------
         *
         * Image no permite manipular imágenes en formato bmp. Se debió utilizar
         * BufferedImage (extensión de Image) para usar ImageIO. ImageIo.read(f) lee el archivo
         * a adjuntar y devuelve un BufferedImage de ese archivo leído en su formato original.
         *
         * ---------------------------------------------------------------------------------
         * Código anterior
         * ---------------------------------------------------------------------------------
         *
         * Image image = Toolkit.getDefaultToolkit().createImage( entry.getData());
         *
         *
         */

        File f = entry.getFile();
        BufferedImage bufImg = null;
        try {
          bufImg = ImageIO.read(f);
        } catch (Exception e) {
          log.log(Level.SEVERE, "Invalid Image");
        }
        /*
         * ---------------------------------------------------------------------------------
         * Fin modificación Matías Cap - Disytel
         * ---------------------------------------------------------------------------------
         */

        if (bufImg != null) {
          gifPanel.setImage(bufImg);
          size = gifPanel.getPreferredSize();

          if ((size.width == -1) && (size.height == -1)) {
            log.log(Level.SEVERE, "Invalid Image");
          } else {

            // size.width += 40;
            // size.height += 40;

            graphPanel.add(gifScroll, BorderLayout.CENTER);
          }
        } else {
          log.log(Level.SEVERE, "Could not create image");
        }
      } else if (entry.isHTML() || entry.isText() || entry.isRTF()) {
        try {
          JEditorPane textPanel;
          if (entry.isRTF())
            textPanel = new RTFScaledEditorPane(entry.getInputStream(), graphPanel);
          else {
            textPanel = new JEditorPane("file:///" + entry.getFile().getAbsolutePath());
            JScrollPane jScrollPane = new JScrollPane();
            textPanel.setEditable(false);
            jScrollPane.setViewportView(textPanel);
            textPanel.setPreferredSize(new Dimension(800, 600));
            graphPanel.add(jScrollPane, BorderLayout.CENTER);
          }
        } catch (Exception e) {
          log.severe("txt html rtf attachment Exception:" + e.getMessage());
        }
      }
    }

    if (graphPanel.getComponentCount() == 0) {
      graphPanel.add(info, BorderLayout.CENTER);
    }

    log.config("Size=" + size);

    // graphPanel.setPreferredSize(size);
    // centerPane.setDividerLocation(size.width+30);
    // size.width += 100;
    // size.height += 100;
    // centerPane.setPreferredSize(size);

    pack();
  } // displayData