I'm trying to do a remote filechooser. I read a lot of information but I don't get it.
The best site I've seen is (https://code.google.com/p/otrosvfsbrowser/) because is exactly what I want but I don't fine more information. Are Someone of you using this tool? where are any example code?
I already use JSCH library to transfer via SFTP, but I want a tool to choose the remote path.
I'm starting in Java. sorry for my English.
You can check example code on Usage page
You can just create dialog and register action on approve:
JOtrosVfsBrowserDialog jOtrosVfsBrowserDialog = new JOtrosVfsBrowserDialog();
Action a = new AbstractAction("Select file") {
#Override
public void actionPerformed(ActionEvent actionEvent) {
if (JOtrosVfsBrowserDialog.ReturnValue.Approve.equals(jOtrosVfsBrowserDialog.showOpenDialog(TestDialog.this,"title"))){
String friendlyUrl = jOtrosVfsBrowserDialog.getSelectedFile().getName().getFriendlyURI();
}
}
};
Related
Hello guys I run into a problem. In my application I am storing fileId's of files which user selected before in GoogleDrive file picker. Also I am storing a local copy of that files in device. After each start I want to refresh local files, so I want to download them from drive. But it is not cleare for me, how should i do this.
I saw this documentation, but I can't understand where to get driveService, which used in this code
driveService.files().get(fileId)
.executeMediaAndDownloadTo(outputStream);
I don't know what driveService is in this code. (Which class instance) and how do I get it
Help me please, thank you.
P.S.
Sorry for my bad english
you should check the documentation under resumable Media Downloads it might give you some clues.
class CustomProgressListener implements MediaHttpDownloaderProgressListener {
public void progressChanged(MediaHttpDownloader downloader) {
switch (downloader.getDownloadState()) {
case MEDIA_IN_PROGRESS:
System.out.println(downloader.getProgress());
break;
case MEDIA_COMPLETE:
System.out.println("Download is complete!");
}
}
}
OutputStream out = new FileOutputStream("/tmp/driveFile.jpg");
DriveFiles.Get request = drive.files().get(fileId);
request.getMediaHttpDownloader().setProgressListener(new CustomProgressListener());
request.executeMediaAndDownloadTo(out);
BaseClientService service = new DriveService(new BaseClientService.Initializer()
{
HttpClientInitializer = credential,
ApplicationName = "Drive API Sample",
});
You should check this stack answer, maybe it will help you understand it:
How do you create a new Google Drive Service in C# using OAuth
At the moment , im working with java gwt and i stopped studdenly because one problem occured. I want that my information (for example string) will save after refresh button is clicked.
// user enters something in TextArea textArea1 object
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
//maybe there is a function or what
pleaseSaveInfomation(textArea1);
}
});
I tried this , but i know how to implement it correctly to my source code:
https://stackoverflow.com/a/14220746/5010218
The last(worst) chance is to store data from textArea in file.txt , after refreshing i could read info from file and thats all. But maybe GWT has a specific handler/method/class or what to handle this.
Thats for your opinion and help.
I had the same problem. You can easily overcome it with this.
import com.google.gwt.storage.client.Storage;
private Storage stockStore = null;
stockStore = Storage.getLocalStorageIfSupported();
Please read documentation
http://www.gwtproject.org/doc/latest/DevGuideHtml5Storage.html#UsingStorage
When a browser close a window (because of a refresh, or the user has closed the window, changed the url, etc), a script is not allowed to prevent this action. It's not specific to GWT.
However, you can suggest to the browser-agent to show a confirmation to the user. You can do this with the message property of the closing event.
In GWT:
Window.addWindowClosingHandler(new Window.ClosingHandler() {
public void onWindowClosing(Window.ClosingEvent closingEvent) {
closingEvent.setMessage("Confirm ?");
}
});
You shouldn't rely on this event to store your data, as a lot of condition can prevent you to do this. You should maybe periodically store a draft to the local-storage or to the server.
You probably want to store your data in sessionStorage. In GWT, this the Storage class.
I am using firebase to send Json thru my CN1 app. This is my code and it's working fine, but I want to send the stuff to Dropbox instead and I just can't make it work. (I already got my token, key and secret from their site)
Could you please tell me what I need to change in order to be able to upload my stuff into Dropbox?
#Override
protected void onPrincipal_ButtonJsonAction(Component c, ActionEvent event) {
final String data = Result.fromContent(hashtableWithInfo).toString();
String firebase = "https://fire-game-258.firebaseio.com/example.json";
ConnectionRequest request = new ConnectionRequest() {
#Override
protected void buildRequestBody(OutputStream os) throws IOException {
os.write(data.getBytes("UTF-8"));
}
};
request.setUrl(firebase);
request.setPost(true);
request.setHttpMethod("POST");
request.setContentType("application/json");
NetworkManager.getInstance().addToQueueAndWait(request);
}
Many many many thanks.
Firebase and Dropbox are completely different API's and need to go thru completely different processes. Saving a file to dropbox requires an OAuth process for the specific user whereas firebase is a global API.
I would recommend you look at parse which more closely resembles firebase and already has standardized builtin mappings in Java: https://github.com/sidiabale/parse4cn1/
I'm using NetBeans and trying to make a Jbutton play this .wav file that I have located in the build/classes/shadow part of my project. I want the .Jar to build with the .wav file so I could download the .Jar file on another computer and press the button and the music will play. The music is not locating or starting I'm not sure which it is, also please be easy on the terminology I am very very new.
private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:File Clap = new File("sanic.WAV");
display.setText("cum on step it up!!!");
}
public static void startMusic() {
{
try{
URL url = Shadow.class.getClassLoader().getResource("sanic.wav");
play(); // NetBeans says it cannot find the symbol for play.
}catch(Exception e){
}
}
}
I'm not sure in what part of your code are you using your URL... But I'd suggest you to use AudioInputStream...
Regarding the problem finding the file... I had implemented something similar some time ago, while checking the code I have in my HDD, I found that this made it for me:
URL url = Shadow.class.getResource(myfile.wav);
But nowadays, I prefer working with this:
InputStream resourceAsStream = Shadow.class.getResourceAsStream(myfile.wav);
Hope it helps for what you need to do.
Regards and... happy coding :)
I am not that new to Java Programming, but I have never worked with external libraries etc. Now I want to develop a desktop client for the "Telegram" open-source messaging platform, and I'm stuck when it comes to API-Usage.
There is pretty much documentation about the Telegram API, found at https://core.telegram.org/api, and I've already downloaded mtproto, telegram-api and tl-core from github, and compiled my own library jar from source by using gradle. As well, I've already written a small application, where the user clicks a button and is promted to enter his phone number, I'm using the Java-swing-Libraries and an ActionListener for this.
The phone number entered by the user should now be checked if it is already registered, the auth.checkPhone method seems to be capable for that. But how can I refer to it within my eclipse project? I don't see any method "checkPhone" in any of the classes! What should I do?
Please help me, I can't help myself and I am desperately stuck in my project. Even a small hint would help.
Thanks in Advance,
Lukas
Essentially you will have to fill out the blanks in the code given on GitHub in the ex3ndr/telegram-api repository. If you've got the library Jar file you built and the tl-api-v12.jarfile on your Eclipse project's Java build path, then look at the RPC Calls section of the README and
First you need to set up an AppInfo object with your API credentials, then you will also have to create some new classes that implement the AbsApiState and ApiCallback interfaces. Once these are available, you can create the TelegramApi object and make an RPC call to the Telegram service as follows; in this case using the suggested auth.checkPhone method:
// TODO set up AbsApiState, AppInfo and ApiCallback objects
TelegramApi api = new TelegramApi(state, appInfo, apiCallback);
// Create request
String phoneNumber = "1234567890";
TLRequestAuthCheckPhone checkPhone = new TLRequestAuthCheckPhone(phoneNumber);
// Call service synchronously
TLCheckedPhone checkedPhone = api.doRpcCall(checkPhone);
boolean invited = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO process response further
The TelegramApi object represents your connection to the remote service, which is a request response style of API. RPC calls are made via the doRpcCall method, which takes a request object from the org.telegram.api.requests package (the TLRequestAuthCheckPhone type in the example) filled in with the appropriate parameters. A response object (TLCheckedPhone above) is then returned with the result when it is available.
In the case of an asynchronous call the method returns immediately, and the onResult callback method is executed when the result is available:
// Call service aynchronously
api.doRpcCall(checkPhone, new RpcCallbackEx<TLCheckedPhone>() {
public void onConfirmed() { }
public void onResult(TLCheckedPhone result) {
boolean invited = checkedPhone.getPhoneInvited();
boolean registered = checkedPhone.getPhoneRegistered();
// TODO process response further
}
public void onError(int errorCode, String message) { }
});
Or just look at this API https://github.com/pengrad/java-telegram-bot-api
It is really simple to use