Package org.nasutekds.guitools.controlpanel.datamodel

Examples of org.nasutekds.guitools.controlpanel.datamodel.BinaryValue


          editBinaryPanel.setValue(attrName, null);
        }
        editBinaryDlg.setVisible(true);
        if (editBinaryPanel.valueChanged())
        {
          BinaryValue changedValue = editBinaryPanel.getBinaryValue();
          binaryValue = changedValue;
          value = null;
          ocValue = null;
        }
        fireEditingStopped();
View Full Code Here


    final ArrayList<Message> errors = new ArrayList<Message>();

    setPrimaryValid(useFile);
    setPrimaryValid(useBase64);

    final BinaryValue oldValue = value;

    if (closeAndUpdateValue)
    {
      value = null;
    }

    if (useFile.isSelected())
    {
      String f = file.getText();
      if (f.trim().length() == 0)
      {
        if (hasImageSyntax(attrName.getText()) && (oldValue != null) &&
            !updateImage)
        {
          // Do nothing.  We do not want to regenerate the image and we
          // are on the case where the user simply did not change the image.
        }
        else
        {
          errors.add(ERR_CTRL_PANEL_FILE_NOT_PROVIDED.get());
          setPrimaryInvalid(useFile);
          setPrimaryInvalid(lFile);
        }
      }
      else
      {
        File theFile = new File(f);
        if (!theFile.exists())
        {
          errors.add(ERR_CTRL_PANEL_FILE_DOES_NOT_EXIST.get(f));
          setPrimaryInvalid(useFile);
          setPrimaryInvalid(lFile);
        }
        else if (theFile.isDirectory())
        {
          errors.add(ERR_CTRL_PANEL_PATH_IS_A_DIRECTORY.get(f));
          setPrimaryInvalid(useFile);
          setPrimaryInvalid(lFile);
        }
        else if (!theFile.canRead())
        {
          errors.add(ERR_CTRL_PANEL_CANNOT_READ_FILE.get(f));
          setPrimaryInvalid(useFile);
          setPrimaryInvalid(lFile);
        }
      }
    }
    else
    {
      String b = base64.getText();
      if (b.length() == 0)
      {
        errors.add(ERR_CTRL_PANEL_VALUE_IN_BASE_64_REQUIRED.get());
        setPrimaryInvalid(useBase64);
      }
    }
    if (errors.size() == 0)
    {
      // Read the file or encode the base 64 content.
      BackgroundTask<BinaryValue> worker = new BackgroundTask<BinaryValue>()
      {
        /**
         * {@inheritDoc}
         */
        public BinaryValue processBackgroundTask() throws Throwable
        {
          try
          {
            Thread.sleep(1000);
          }
          catch (Throwable t)
          {
          }
          BinaryValue returnValue;
          if (useBase64.isSelected())
          {
            returnValue = BinaryValue.createBase64(base64.getText());
          }
          else if (file.getText().trim().length() > 0)
          {
            File f = new File(file.getText());
            FileInputStream in = null;
            ByteArrayOutputStream out = new ByteArrayOutputStream();
            byte[] bytes = new byte[2 * 1024];
            try
            {
              in = new FileInputStream(f);
              boolean done = false;
              while (!done)
              {
                int len = in.read(bytes);
                if (len == -1)
                {
                  done = true;
                }
                else
                {
                  out.write(bytes, 0, len);
                }
              }
              returnValue = BinaryValue.createFromFile(out.toByteArray(), f);
            }
            finally
            {
              if (in != null)
              {
                in.close();
              }
              out.close();
            }
          }
          else
          {
            //  We do not want to regenerate the image and we
            // are on the case where the user simply did not change the image.
            returnValue = oldValue;
          }
          if (closeAndUpdateValue)
          {
            valueChanged = !returnValue.equals(oldValue);
          }
          if (updateImage)
          {
            updateImage(lImage, returnValue.getBytes());
          }
          return returnValue;
        }
        /**
         * {@inheritDoc}
 
View Full Code Here

   */
  static void updateBase64(JTextComponent base64, byte[] bytes)
  {
    if (bytes.length < MAX_BASE64_TO_DISPLAY)
    {
      BinaryValue value = BinaryValue.createBase64(bytes);
      base64.setText(value.getBase64());
    }
    else
    {
      base64.setText(
          INFO_CTRL_PANEL_SPECIFY_CONTENTS_IN_BASE_64.get().toString());
View Full Code Here

TOP

Related Classes of org.nasutekds.guitools.controlpanel.datamodel.BinaryValue

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.