javax.smartcardio.CardTerminals Java Examples

The following examples show how to use javax.smartcardio.CardTerminals. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: FancyChooser.java    From apdu4j with MIT License 6 votes vote down vote up
private FancyChooser(Terminal terminal, Screen screen, CardTerminals monitorObject, List<CardTerminal> terminals) {
    if (monitorObject != null)
        monitor = new MonitorThread(monitorObject);
    else monitor = null;
    this.terminal = terminal;
    this.screen = screen;
    gui = new MultiWindowTextGUI(screen, new DefaultWindowManager(), new EmptySpace(TextColor.ANSI.BLUE));
    this.initialList = terminals;
    // Create UI elements
    mainWindow = new BasicWindow(" apdu4j ");
    mainWindow.setCloseWindowWithEscape(true);
    mainWindow.setHints(Arrays.asList(Window.Hint.FIT_TERMINAL_WINDOW, Window.Hint.CENTERED));

    mainPanel = new Panel();
    mainPanel.setLayoutManager(new BorderLayout());
    mainPanel.setLayoutManager(new LinearLayout(Direction.VERTICAL));
    mainActions = new ActionListBox();
    mainActions.setLayoutData(BorderLayout.Location.CENTER);
    mainPanel.addComponent(mainActions);
    mainPanel.addComponent(new EmptySpace(new TerminalSize(0, 1)));
    quitButton = new Button("Cancel and quit", () -> mainWindow.close());
    quitButton.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.End));
    mainPanel.addComponent(quitButton);
    //mainPanel.setLayoutData(LinearLayout.createLayoutData(LinearLayout.Alignment.End));
    mainWindow.setComponent(mainPanel);
}
 
Example #2
Source File: PhysicalCard.java    From OpenPGP-Card with GNU General Public License v3.0 5 votes vote down vote up
public boolean initialize() throws CardException {
  List<CardTerminal> readersWithCards = TerminalFactory.getDefault().terminals()
      .list(CardTerminals.State.CARD_PRESENT);
  if (readersWithCards.isEmpty()) {
    logger.severe("No card found.");
    return false;
  }
  reader = readersWithCards.get(0);
  logger.info("Reader: " + reader);
  card = reader.connect("*");
  logger.info("Card: " + card);
  channel = card.getBasicChannel();
  return true;
}
 
Example #3
Source File: EmulatedTerminalProvider.java    From apdu4j with MIT License 5 votes vote down vote up
@Override
public CardTerminals engineTerminals() {
    if (instance == null) {
        instance = provider.apply(parameter);
    }
    return new EmulatedCardTerminals(Collections.unmodifiableList(Arrays.asList(instance)));
}
 
Example #4
Source File: Main.java    From openjavacard-ndef with GNU General Public License v3.0 5 votes vote down vote up
public static final void main(String[] arguments) {
    PrintStream os = System.out;
    TerminalFactory tf = TerminalFactory.getDefault();
    CardTerminals terminals = tf.terminals();

    try {
        // default command is info
        String command = "info";

        // check if user specified a reader as first argument
        if(arguments.length >= 1) {
            // if yes then use that reader
            String terminalName = arguments[0];
            CardTerminal terminal = terminals.getTerminal(terminalName);
            if(terminal == null) {
                throw new RuntimeException("Could not find terminal \"" + terminalName + "\"");
            }
            // check if the user also specified a command
            if(arguments.length >= 2) {
                command = arguments[1];
            }
            // split off the command arguments
            String[] commandArguments = new String[0];
            if(arguments.length > 2) {
                commandArguments = Arrays.copyOfRange(arguments, 2, arguments.length);
            }
            // run the command
            runCommand(terminal, command, commandArguments);
        } else {
            // else list all readers
            os.println("Available terminals:");
            for (CardTerminal t : terminals.list()) {
                os.println("  \"" + t.getName() + "\"");
            }
        }
    } catch (CardException e) {
        e.printStackTrace();
    }
}
 
Example #5
Source File: CardManager.java    From JCMathLib with MIT License 5 votes vote down vote up
private Card waitForCard(CardTerminals terminals)
        throws CardException {
    while (true) {
        for (CardTerminal ct : terminals
                .list(CardTerminals.State.CARD_INSERTION)) {

            return ct.connect("*");
        }
        terminals.waitForChange();
    }
}
 
Example #6
Source File: TerminalFactorySpiTest.java    From openjdk-jdk9 with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #7
Source File: FancyChooser.java    From apdu4j with MIT License 4 votes vote down vote up
MonitorThread(CardTerminals terminals) {
    terms = terminals;
    setName("MonitorThread");
    setDaemon(true);
}
 
Example #8
Source File: FancyChooser.java    From apdu4j with MIT License 4 votes vote down vote up
public static FancyChooser forTerminals(CardTerminals terminals) throws IOException, CardException {
    List<CardTerminal> terminalList = terminals.list();
    Terminal terminal = new DefaultTerminalFactory().createTerminal();
    Screen screen = new TerminalScreen(terminal);
    return new FancyChooser(terminal, screen, terminals, terminalList);
}
 
Example #9
Source File: TerminalFactorySpiTest.java    From jdk8u_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #10
Source File: TerminalFactorySpiTest.java    From jdk8u-jdk with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #11
Source File: TerminalFactorySpiTest.java    From dragonwell8_jdk with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #12
Source File: TerminalFactorySpiTest.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #13
Source File: TerminalFactorySpiTest.java    From openjdk-jdk8u with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}
 
Example #14
Source File: SunPCSC.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
   return new PCSCTerminals();
}
 
Example #15
Source File: SunPCSC.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
   return new PCSCTerminals();
}
 
Example #16
Source File: SunPCSC.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
   return new PCSCTerminals();
}
 
Example #17
Source File: SunPCSC.java    From freehealth-connector with GNU Affero General Public License v3.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
   return new PCSCTerminals();
}
 
Example #18
Source File: TerminalFactorySpiTest.java    From TencentKona-8 with GNU General Public License v2.0 4 votes vote down vote up
protected CardTerminals engineTerminals() {
    System.out.println("MyTerminalFactory.engineTerminals()");
    callMethod = true;
    return null;
}