copiando arquivos para a area de transferencia

On October 11, 2010, in java, programacao, trecos, by athanazio
0

maquina nova = problemas novos !
agora usando um macbook estou estava enfrentando um probleminha que era recuperar imagens capturadas com o Jing no mac para dentro de uma maquina virtual virtualbox windows.
Trocando em miudos …
Tenho o jing instalado no Mac e copio uma parte da tela e quero usar na area de transferencia dentro de um windows xp rodando numa maquina virtual.
solução encontrada : configurei o Jing para salvar a imagem numa pasta :

apos isto mapeamos a pasta no virtualbox para ser uma pasta compartilhada dentro do virtualbox, selecione o icone de pastas compartilhadas a partir da janela da maquina virtual rodando

e depois clique para criar uma uma pasta compartilhada permanente

Agora estamos prontos para ler os arquivos no windows, que esta rodando na maquina virtual, para isto vamos mapear a pasta compartilhada para o drive X: no windows

abra uma janela do windows explorer e escolha a opção tools / map network drive

escolha o drive X, ou outra letra q preferir, e associe a pasta \\VBOXSVR\nome-da-pasta, se o nome da pasta compartilhada que vc escolheu foi “minha-pasta” o mapeamento do drive sera para \\VBOXSVR\minha-pasta, não esqueça de marcar para o mapeamento funcionar apos o boot também.

apos isto procurei um pouco na internet e achei um codigo quase pronto para copiar uma imagem para a area de transferencia, foi soh fazer um codigo para ler a pasta procurando por uma imagem e copiando ela para a area de transferencia … facim facim … :)

depois fiz um bat para executar o jar que fica em loop procurando por imagens numa pasta, funcionou que eh uma maravilha e ainda copia a imagem recem processada para a pasta old, ahhhh o cheiro no ar de codigo java sendo executado huauhahuahuau

para os curiosos de plantão eis ai o codigo

package com.athanazio.image;
import java.awt.Image;
import java.awt.Toolkit;
import java.awt.datatransfer.DataFlavor;
import java.awt.datatransfer.Transferable;
import java.awt.datatransfer.UnsupportedFlavorException;
import java.io.File;
import java.io.IOException;

import javax.swing.ImageIcon;

public class CopyImageToClipboard {

	public static void main(String[] args) throws InterruptedException {

		String start = "x:/clipboard/";
		File folder = new File(start);
		File folderOld = new File(start + "old");
		folderOld.mkdir();

		while(true){
			String [] files = folder.list();
			for (int i = 0; i < files.length; i++) {
				if( files[i].endsWith(".png")){
					System.out.println("copy file : " + files[i]);
					ImageIcon icon = new ImageIcon(start + files[i]);
					setClipboard( icon.getImage());
					File image = new File(start + files[i]);
					image.renameTo( new File(start + "old/" + files[i]));
					break;
				}

			}
			Thread.sleep(300);
		}
	}

	public static void setClipboard(Image image) {
		ImageSelection imgSel = new ImageSelection(image);
		Toolkit.getDefaultToolkit().getSystemClipboard().setContents(imgSel, null);
	}

	// This class is used to hold an image while on the clipboard.
	public static class ImageSelection implements Transferable {
		private Image image;

		public ImageSelection(Image image) {
			this.image = image;
		}

		// Returns supported flavors
		public DataFlavor[] getTransferDataFlavors() {
			return new DataFlavor[] { DataFlavor.imageFlavor };
		}

		// Returns true if flavor is supported
		public boolean isDataFlavorSupported(DataFlavor flavor) {
			return DataFlavor.imageFlavor.equals(flavor);
		}

		// Returns image
		public Object getTransferData(DataFlavor flavor) throws UnsupportedFlavorException, IOException {
			if (!DataFlavor.imageFlavor.equals(flavor)) {
				throw new UnsupportedFlavorException(flavor);
			}
			return image;
		}
	}

}

parte do codigo usado de http://elliotth.blogspot.com/2005/09/copying-images-to-clipboard-with-java.html

Tagged with:
 

midia de elevador

On June 21, 2010, in trecos, by athanazio
3


muito legal esta nova forma de midia, as telinhas que ficam no elevador passando noticias, e propagandas, melhor do que as musicas constrangedoras, ou os sons espremidos entre os dentes de “boa tarde” que nem o pensamento das pessoas escuta. mas como tecnologia que se assemelha ao liquidificador, escangalha !!! dai já viu o fetiche vira contra o feticheiro :P e se ve um majestoso sistema operacional controlando as vibrantes maquininhas.

adoro liquidificadores !!

Tagged with:
 

alt+tab modernozo

On October 26, 2008, in Uncategorized, by athanazio
1

Acidentalmente descobri que o Windows Vista tem um novo sistema de Alt Tab muito maneiro, que eh o Janelinha (tecla windows) + Tab mor maneiro que mostra um trecho da janela junto com outro, prático prático … veja soh que legal

Tagged with:
 

windows registry with Java

On June 20, 2007, in java, by athanazio
0

Oh well, I already saw some hacks around but this one was great ! whoever implement this, used the internal methods of Preferences class that uses windows registry, to allow access to any other node in the registry bellow HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE, it´s a pretty cool idea, you can check the original code at http://www.jroller.com/page/lenkite?entry=use_pure_java_to_access

and some changes that I made over the code …





import java.lang.reflect.Method;
import java.util.prefs.Preferences;

/**

 * used to read data from windows registry in the rootkeys :

 * HKEY_CURRENT_USER and HKEY_LOCAL_MACHINE

 

 * see the usage at the main method bellow

 

 */

public class Registry {

  final int KEY_READ = 0×20019;

  private boolean invalidState = true;

  private final Preferences userRoot = Preferences.userRoot();

  private final Class clz = userRoot.getClass();

  private Method mOpenKey = null;

  private Method mCloseKey = null;

  private Method mWinRegQueryValue = null;

  private Method mWinRegEnumValue = null;

  private Method mWinRegQueryInfo = null;

  private static final Class[] parms1 = byte[].class, int.class, int.class };

  private static Registry instance;

  // sample usage

  public static void main(String[] argsthrows Exception {

    System.out.println(Registry.getInstance().readKey(“HKEY_CURRENT_USER/Software/Microsoft/Windows/CurrentVersion/Run/Skype”));

    System.out.println(Registry.getInstance().readKey(“HKEY_LOCAL_MACHINE/SOFTWARE/Adobe/Acrobat Reader/7.0/Language/UI”));

  }

  public static Registry getInstance() throws Exception {

    if (instance == null) {

      instance = new Registry();

    }

    if (instance.invalidState) {

      throw new Exception(“Windows Registry reader invalid state”);

    }

    return instance;

  }

  private Registry() {

    try {

      mOpenKey = clz.getDeclaredMethod(“openKey”, parms1);

      mOpenKey.setAccessible(true);

      Class[] parms2 = int.class };

      mCloseKey = clz.getDeclaredMethod(“closeKey”, parms2);

      mCloseKey.setAccessible(true);

      Class[] parms3 = int.class, byte[].class };

      mWinRegQueryValue = clz.getDeclaredMethod(“WindowsRegQueryValueEx”, parms3);

      mWinRegQueryValue.setAccessible(true);

      Class[] parms4 = int.class, int.class, int.class };

      mWinRegEnumValue = clz.getDeclaredMethod(“WindowsRegEnumValue1″, parms4);

      mWinRegEnumValue.setAccessible(true);

      Class[] parms5 = int.class };

      mWinRegQueryInfo = clz.getDeclaredMethod(“WindowsRegQueryInfoKey1″, parms5);

      mWinRegQueryInfo.setAccessible(true);

      invalidState = false;

    catch (SecurityException e) {

      invalidState = true;

    catch (NoSuchMethodException e) {

      invalidState = true;

    }

  }

  public static final String HKEY_CURRENT_USER = “HKEY_CURRENT_USER”;

  public static final String HKEY_LOCAL_MACHINE = “HKEY_LOCAL_MACHINE”;

  public String readKey(String fullName) {

    String result = null;

    String[] tokens = fullName.split(“/”);

    String rootNode = tokens[0];

    StringBuffer key = new StringBuffer();

    for (int i = 1; i < tokens.length - 1; i++) {

      key.append(tokens[i]);

      key.append(‘\\’);

    }

    if (key.length() 0)

      key.deleteCharAt(key.length() 1);

    String name = tokens[tokens.length - 1];

    if (rootNode.equals(HKEY_CURRENT_USER)) {

      result = readKey(Preferences.userRoot(), key.toString(), name);

    }

    if (rootNode.equals(HKEY_LOCAL_MACHINE)) {

      result = readKey(Preferences.systemRoot(), key.toString(), name);

    }

    return result;

  }

  public String readKey(Preferences preferences, String key, String name) {

    String value = null;

    try {

      Object[] openKeyParameters = toByteArray(key)new Integer(KEY_READ)new Integer(KEY_READ) };

      Integer hSettings = (IntegermOpenKey.invoke(preferences, openKeyParameters);

      Object[] queryParameters = hSettings, toByteArray(name) };

      byte[] b = (byte[]) mWinRegQueryValue.invoke(preferences, queryParameters);

      value = (b != null new String(b).trim() null);

      Object[] objects3 = hSettings };

      mCloseKey.invoke(Preferences.userRoot(), objects3);

    catch (Exception e) {

      System.out.println(“Error getting user’s data from Windows registry:”);

      e.printStackTrace();

    }

    return value;

  }

  private static byte[] toByteArray(String str) {

    byte[] result = new byte[str.length() 1];

    for (int i = 0; i < str.length(); i++) {

      result[i(bytestr.charAt(i);

    }

    result[str.length()] 0;

    return result;

  }

}


Other way to do this would be a call to the command line “reg” [I didn´t klnow this guy ....=) ] that have pretty cool options , and using this any key from the registry would be accessible.

these are the options :

E:>regConsole Registry Tool for Windows - version 3.0Copyright (C) Microsoft Corp. 1981-2001.  All rights reserved

REG Operation [Parameter List]

Operation  [ QUERY   | ADD    | DELETE  | COPY    |

SAVE    | LOAD   | UNLOAD  | RESTORE |

COMPARE | EXPORT | IMPORT ]

Return Code: (Except of REG COMPARE)

0 - Succussful

1 - Failed

For help on a specific operation type:

REG Operation /?

Examples:

REG QUERY /?

REG ADD /?

REG DELETE /?

REG COPY /?

REG SAVE /?

REG RESTORE /?

REG LOAD /?

REG UNLOAD /?

REG COMPARE /?

REG EXPORT /?

REG IMPORT /?
Tagged with: