示例#1
0
 /** List results by alphabetical name */
 private void listByProgramName() {
   int nresult = datasets.size();
   String res[] = new String[nresult];
   for (int i = 0; i < nresult; i++) res[i] = (String) datasets.getElementAt(i);
   Arrays.sort(res);
   datasets.removeAllElements();
   for (int i = 0; i < nresult; i++) datasets.addElement(res[i]);
 }
示例#2
0
  private void speichern(Path saveName) {
    Properties prop = new Properties();

    if (!quellListModel.isEmpty())
      for (int i = 0; i < quellListModel.getSize(); i++)
        prop.setProperty(
            String.format("quellMenu%d", i),
            quellListModel.getElementAt(i).getValueMember().toString());

    if (!zielListModel.isEmpty())
      for (int i = 0; i < zielListModel.getSize(); i++)
        prop.setProperty(
            String.format("zielMenu%d", i),
            zielListModel.getElementAt(i).getValueMember().toString());

    try {
      FileOutputStream out = new FileOutputStream(saveName.toString());
      prop.store(out, null);
      out.close();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }
  public ListDemo() {
    super(new BorderLayout());

    listModel = new DefaultListModel();

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);
    list.setVisibleRowCount(5);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton hireButton = new JButton(hireString);
    HireListener hireListener = new HireListener(hireButton);
    hireButton.setActionCommand(hireString);
    hireButton.addActionListener(hireListener);
    hireButton.setEnabled(false);

    loadButton = new JButton(loadString);
    loadButton.setActionCommand(loadString);
    loadButton.addActionListener(new loadListener());

    employeeName = new JTextField(10);
    employeeName.addActionListener(hireListener);
    employeeName.getDocument().addDocumentListener(hireListener);
    String name;
    if (listModel.size() > 0) {
      name = listModel.getElementAt(list.getSelectedIndex()).toString();
    }
    // Create a panel that uses BoxLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.setLayout(new BoxLayout(buttonPane, BoxLayout.LINE_AXIS));
    buttonPane.add(loadButton);
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(new JSeparator(SwingConstants.VERTICAL));
    buttonPane.add(Box.createHorizontalStrut(5));
    buttonPane.add(employeeName);
    buttonPane.add(hireButton);
    buttonPane.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));

    add(listScrollPane, BorderLayout.CENTER);
    add(buttonPane, BorderLayout.PAGE_END);
  }
示例#4
0
  public ListDataEventDemo() {
    super(new BorderLayout());

    // Create and populate the list model.
    listModel = new DefaultListModel();
    listModel.addElement("Whistler, Canada");
    listModel.addElement("Jackson Hole, Wyoming");
    listModel.addElement("Squaw Valley, California");
    listModel.addElement("Telluride, Colorado");
    listModel.addElement("Taos, New Mexico");
    listModel.addElement("Snowbird, Utah");
    listModel.addElement("Chamonix, France");
    listModel.addElement("Banff, Canada");
    listModel.addElement("Arapahoe Basin, Colorado");
    listModel.addElement("Kirkwood, California");
    listModel.addElement("Sun Valley, Idaho");
    listModel.addListDataListener(new MyListDataListener());

    // Create the list and put it in a scroll pane.
    list = new JList(listModel);
    list.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);
    list.setSelectedIndex(0);
    list.addListSelectionListener(this);
    JScrollPane listScrollPane = new JScrollPane(list);

    // Create the list-modifying buttons.
    addButton = new JButton(addString);
    addButton.setActionCommand(addString);
    addButton.addActionListener(new AddButtonListener());

    deleteButton = new JButton(deleteString);
    deleteButton.setActionCommand(deleteString);
    deleteButton.addActionListener(new DeleteButtonListener());

    ImageIcon icon = createImageIcon("Up16");
    if (icon != null) {
      upButton = new JButton(icon);
      upButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
      upButton = new JButton("Move up");
    }
    upButton.setToolTipText("Move the currently selected list item higher.");
    upButton.setActionCommand(upString);
    upButton.addActionListener(new UpDownListener());

    icon = createImageIcon("Down16");
    if (icon != null) {
      downButton = new JButton(icon);
      downButton.setMargin(new Insets(0, 0, 0, 0));
    } else {
      downButton = new JButton("Move down");
    }
    downButton.setToolTipText("Move the currently selected list item lower.");
    downButton.setActionCommand(downString);
    downButton.addActionListener(new UpDownListener());

    JPanel upDownPanel = new JPanel(new GridLayout(2, 1));
    upDownPanel.add(upButton);
    upDownPanel.add(downButton);

    // Create the text field for entering new names.
    nameField = new JTextField(15);
    nameField.addActionListener(new AddButtonListener());
    String name = listModel.getElementAt(list.getSelectedIndex()).toString();
    nameField.setText(name);

    // Create a control panel, using the default FlowLayout.
    JPanel buttonPane = new JPanel();
    buttonPane.add(nameField);
    buttonPane.add(addButton);
    buttonPane.add(deleteButton);
    buttonPane.add(upDownPanel);

    // Create the log for reporting list data events.
    log = new JTextArea(10, 20);
    JScrollPane logScrollPane = new JScrollPane(log);

    // Create a split pane for the log and the list.
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, listScrollPane, logScrollPane);
    splitPane.setResizeWeight(0.5);

    // Put everything together.
    add(buttonPane, BorderLayout.PAGE_START);
    add(splitPane, BorderLayout.CENTER);
  }
示例#5
0
 // Swap two elements in the list.
 private void swap(int a, int b) {
   Object aObject = listModel.getElementAt(a);
   Object bObject = listModel.getElementAt(b);
   listModel.set(a, bObject);
   listModel.set(b, aObject);
 }
示例#6
0
  public void clientJoined(Message.ClientJoinMsg m) {

    Iterator i = clients.iterator();

    while (i.hasNext()) {
      EditorClient ec = (EditorClient) i.next();
      if (ec.isPresent()) {
        if (m.getName().equals(ec.getName())) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_NAME);
          return;
        }
        if (m.getColorCode() == ec.getColorCode()) {
          sendClientReject(m.getKeyValue(), Message.ClientRejectMsg.REASON_COLOR);
          return;
        }
      }
    }

    // clientAccepted
    // mach... added ClientIPaddress + added server to EditorClient const
    EditorClient newClient =
        new EditorClient(
            this,
            nextClientId,
            m.getName(),
            m.getColorCode(),
            m.getKeyValue(),
            m.getClientIPaddress());

    if (EditorServer_Debug)
      System.out.println(
          ">>> In EditorServer.clientJoined  : client NAME is : *"
              + m.getName()
              + "* IPAddress : is : *"
              + m.getClientIPaddress()
              + "*");

    clients.add(newClient);
    nextClientId++;
    clientsPanel.updateClientList();

    // here... match Audio & Text client
    // iterate through list of audio client

    String audioClientIP = "";

    int offset = -1;

    if (isAudioOptionSelected) {

      if (EditorServer_Debug) System.out.println("\n>>>In Client Accepted !!!");

      for (int n = 0; n < plistModel.getSize(); n++) {

        audioClientIP = (plistModel.getElementAt(n)).toString();

        offset = audioClientIP.indexOf('@');

        audioClientIP = audioClientIP.substring(offset + 1);

        if (audioClientIP.equals(m.getClientIPaddress())) {

          System.out.println("MATCH found!!!" + m.getName() + "<>" + audioClientIP);

          // change ...

          plistModel.set(n, m.getName());
        }
      }
    } // endif isAudioOptionSelected

    try {
      clientChannel.sendToOthers(client, new Data(newClient.getMessage()));
      sendDocumentState(nextClientId - 1);
      sendHighlightTypes();
      sendHighlights();
    } catch (Exception e) {
      System.err.println("EditorServer: clientJoined: error sending msg");
      if (EditorServer_Debug) e.printStackTrace();
    }
  }