lokeshj / jzebra

Automatically exported from code.google.com/p/jzebra
0 stars 0 forks source link

Simple list of printers #23

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Call the getPrinters(); method
2. Display it in an alert, for example.

What is the expected output? What do you see instead?

At this moment I am getting the following list:

[Win32 Printer : Send To OneNote 2007,
Win32 Printer : PDF995,
Win32 Printer : Microsoft XPS Document Writer,
Win32 Printer : Fax,
Win32 Printer : \\SERVER2\Epson LQ-680 ESC/P 2,
Win32 Printer : \\SERVER\Kyocera-Mono,
Win32 Printer : \\SERVER\Zebra2,
Win32 Printer : \\SERVER\Samsung CLP-610 Series,
Win32 Printer : \\SERVER\Samsung-Mono,
Win32 Printer : \\SERVER\Kyocera-colour,
Win32 Printer : \\SERVER\Blaster,
Win32 Printer : \\SERVER\Generic / Text Only,
Win32 Printer : \\SERVER\Samsung-colour,
Win32 Printer : \\SERVER\Zebra],\\SERVER\Zebra

The new lines are added by me. The whole text is in one line.
I do not understand from where are the [] brackets coming from, and why there 
is ",\\SERVER\Zebra" at the end after the brackets.

The list of printers is very useful during configuration/setup steps for an 
application. 

The list is too complex. Would there be a possibility to add new method that 
will issue the following list:

Send To OneNote 2007,
PDF995,
Microsoft XPS Document Writer,
Fax,
\\SERVER2\Epson LQ-680 ESC/P 2,
\\SERVER\Kyocera-Mono,
\\SERVER\Zebra2,
\\SERVER\Samsung CLP-610 Series,
\\SERVER\Samsung-Mono,
\\SERVER\Kyocera-colour,
\\SERVER\Blaster,
\\SERVER\Generic / Text Only,
\\SERVER\Samsung-colour,
\\SERVER\Zebra

Again the new lines were added by me. It should be one line.

This would be easier to use in javascript, just one split(",").
I cannot think of a situation where user cares about the "Win32 Printer" string 
at the front. It may be important for Linux, or Mac for something.

What version of the product are you using? On what operating system?

jZebra 1.1.4

Please provide any additional information below.

I have experimented with the code as below:

class PrintApplet {

...

public String getPrintersSimple()
    {
        return PrintServiceMatcher.getPrinterListSimple();
    }

...

}

public class PrintServiceMatcher {

...

public static String getPrinterListSimple() {

        String strPrinterList = "";
        PrintService[] services = PrintServiceLookup.lookupPrintServices(null, null);

        for (int i = 0; i < services.length; i++) {
            PrintServiceAttributeSet psa = services[i].getAttributes();
            strPrinterList = strPrinterList + psa.get(PrinterName.class);
            if (i != (services.length - 1))         
                strPrinterList = strPrinterList + "|";
        }

        return strPrinterList;
    }

...

}

Original issue reported on code.google.com by Tomasz.Z...@gmail.com on 25 Feb 2011 at 2:37

GoogleCodeExporter commented 9 years ago
@Tomas

Comments:  I think the [] brackets are a bug introduced by Arrays.asList().  
I've removed the logic in favor of yours, thank you.

In regards to the pipe "|" delimiter, it is a valid Win32 printer name 
character, so I'm avoiding it (for now) and using the comma delimiter "," which 
Win32 does not allow to avoid potential conflicts.

Thanks again for the suggestions.

-Tres

Original comment by tres.fin...@gmail.com on 25 Feb 2011 at 3:49

GoogleCodeExporter commented 9 years ago
[deleted comment]
GoogleCodeExporter commented 9 years ago
Changes added, please test/verify.
http://code.google.com/p/jzebra/downloads/detail?name=jZebra%201.1.5.zip

Original comment by tres.fin...@gmail.com on 25 Feb 2011 at 5:07

GoogleCodeExporter commented 9 years ago

Original comment by tres.fin...@gmail.com on 25 Feb 2011 at 5:08

GoogleCodeExporter commented 9 years ago
Tres,

I have accidently left the pipe there after experimenting. I have noticed that 
the pipe can be used in the printer name. In the example I gave, are commas.

Best regards
Tomasz TZ

Original comment by Tomasz.Z...@gmail.com on 25 Feb 2011 at 5:18

GoogleCodeExporter commented 9 years ago
@Tomasz:  Ok, thanks!  Let me know if the new implementation works for your 
needs. :)

-Tres

Original comment by tres.fin...@gmail.com on 25 Feb 2011 at 5:58

GoogleCodeExporter commented 9 years ago
Tres,

Working OK.

Original comment by Tomasz.Z...@gmail.com on 25 Feb 2011 at 8:15

GoogleCodeExporter commented 9 years ago
Thanks Tomasz.  Marking as fixed & verified.

Original comment by tres.fin...@gmail.com on 25 Feb 2011 at 4:46