miercuri, 29 octombrie 2008

How to change Shortcuts in Eclipse

English:

To change Shortcuts in Eclipse(3.2.2), you have to go to:
Window -> Preferences -> General -> Keys

In the View Window select the shortcut you want to change and click Edit. You have to Remove the old shortcut and to Add the new one.

Apply -> OK. Return to your project and the shortcut is already effective.

________________
Romanian:

Pentru a schimba o scurtatura in Eclipse(3.2.2), trebuie sa parcurgeti urmatoarele etape:
Window -> Preferences -> General -> Keys

In fereastra View selectati scurtatura pe care doriti sa o modificati si dati click pe Edit. Trebuie sa dati Remove la vechea combinatie de taste si sa dati Add pentru a o adauga pe cea noua.

Apply -> OK. Cand va intoarceti in proiectul dvs., puteti deja utiliza noua combinatie de taste.

luni, 27 octombrie 2008

Primele mele aplicatii in Java

O a doua versiune de DepozitApp arata asa:

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Iterator;
import java.util.List;

public class DepozitApp {

private Depozit depozit;

public DepozitApp(Depozit depFile){
this.depozit = depFile;
}

private void afiseazaMarfa(List depozit){
System.out.println("Depozitul contine: ");
for(Iterator it = depozit.iterator(); it.hasNext();){
Marfa mr = (Marfa)it.next();
System.out.println("codul "+mr.getCodMarfa()+" numele "+mr.getNume());
}
}

public void run () throws IOException {
int nr=0;

System.out.println("Selectati dintre optiunile existente: ");
System.out.println("1. In cazul in care datele din depozit se vor salva in memorie: ");
System.out.println("2. In cazul in care datele din depozit se vor salva intr-un fisier: ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();

try{
nr = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
}

if(nr == 1){
this.depozit = new DepozitMemory();
meniu();
}else if(nr == 2){
this.depozit = new DepozitFile();
meniu();
}else{
System.out.println("Optiunea nu este valida. Alegeti o optiune valida.");
}
}

public void meniu () throws IOException {

int nr1 = 0;
do{
System.out.println("=========== Meniu: =============");
System.out.println("Selectati dintre optiunile existente: ");

System.out.println("1. Adauga marfa");
System.out.println("2. Sterge marfa");
System.out.println("3. Cauta dupa cod");
System.out.println("4. Cauta dupa producator");
System.out.println("5. Cauta dupa nume");
System.out.println("6. Cauta produsele care contin un anumit grup de litere");
System.out.println("7. Afiseaza marfa din depozit");
System.out.println("8. Exit");

System.out.println("Selectati o optiune din cele existente: ");

BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String snr = br.readLine();

try{
nr1 = Integer.parseInt(snr);
}catch(NumberFormatException nfe){
System.out.println("Tipariti un numar!");
continue;
}

switch(nr1){
case 1:
{
System.out.println("1. Adauga marfa: ");

// FileOutputStream fout = null;
// fout = new FileOutputStream("/home/raluca/workspace/problema/src/problema080911/out.txt");
//
// OutputStreamWriter out = new OutputStreamWriter(fout);
// BufferedReader br1 = new BufferedReader(out);

System.out.println("Dati codul produsului: ");
int cod = Integer.parseInt(br.readLine());

System.out.println("Dati numele produsului: ");
String nume = br.readLine();

System.out.println("Dati producatorul: ");
String producator = br.readLine();

Marfa mrf = new Marfa();
mrf.setCodMarfa(cod);
mrf.setNume(nume);
mrf.setProducator(producator);

depozit.adauga(mrf);

// try{
// // Create file
// Writer fstream = new FileWriter("/home/raluca/workspace/problema/src/problema080911/out.txt");
// Writer out = new BufferedWriter(fstream);
//
// out.write(cod);
// out.write(", ");
// out.write(nume);
// out.write(", ");
// out.write(producator);
//
// //Close the output stream
// out.close();
//
// }catch (Exception e){//Catch exception if any
// System.err.println("Error: " + e.getMessage());
// }

break;
}
case 2:
{
System.out.println("2. Sterge marfa. Dati codul: ");

int cod = Integer.parseInt(br.readLine());

depozit.sterge(cod);

break;
}
case 3:
{
System.out.println("3. Cauta dupa cod");

int cod = Integer.parseInt(br.readLine());

// System.out.println((depMem.cautaDupaCod(cod)).getNume());

// if(depMem.cautaDupaCod(cod) == null){
// System.out.println("Produsul nu a fost gasit.");
// }else if(depMem.cautaDupaCod(cod) != null){
// System.out.println("Produsul are numele "+depMem.cautaDupaCod(cod).getNume());
// } static

Marfa mrf = depozit.cautaDupaCod(cod);

if(mrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
System.out.println("Produsul are numele "+mrf.getNume());
}

break;
}
case 4:
{
System.out.println("4. Cauta dupa producator");

String producator = br.readLine();

List listMrf = depozit.cautaDupaProducator(producator);

if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
afiseazaMarfa(listMrf);
}

break;
}
case 5:
{
System.out.println("5. Cauta dupa nume");

String nume = br.readLine();

List listMrf = depozit.cautaListaDeNume(nume);

if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}

break;
}
case 6:
{
System.out.println("6. Cauta produse ce contin");

String nume = br.readLine();

List listMrf = depozit.cautaNumeCeContin(nume);

if(listMrf == null){
System.out.println("Produsul nu a fost gasit.");
}else{
//System.out.println("Produsul are numele "+ nume +" si codul "+mrf.getCodMarfa());
afiseazaMarfa(listMrf);
}

break;
}
case 7:
{
System.out.println("7. Afiseaza marfa din depozit");

afiseazaMarfa(depozit.getAll());

break;
}
case 8:
{
System.out.println("8. Exit");

break;
}
default:
System.out.println("Operatie imposibila.");
}

}while(nr1 != 8);
}
}