Example #1
0
 private void enableButtonOnSelection(JList list, JButton target) {
   if (list.isSelectionEmpty()) {
     target.setEnabled(false);
   } else {
     target.setEnabled(true);
   }
 }
Example #2
0
  private void updateDisplays() {
    if (sliceList.isSelectionEmpty()) return;

    Slice d = (Slice) sliceList.getSelectedValue();

    if (d.urn.equals(textFieldSliceURN.getText())) // is an updated really necessary?
    return;

    textFieldSliceURN.setText(d.urn);
    textAreaDesc.setText(d.desc);
    textFieldExpiry.setText(Utils.utcTolocal(d.expiry));
    textFieldCreation.setText(Utils.utcTolocal(d.creation));
    textFieldProjectURN.setText(d.urnProject);
    tableModel.clear();
    // if(d.members.size() == 0)
    LinkedList<Membership> members = SliceAuthorityAPI.lookupMembers(d.urn, "SLICE");
    if (members == null) {
      showErrorMessage();
      return;
    }
    d.members = members;

    for (int i = 0; i < members.size(); i++) {
      tableModel.add(members.get(i).urn, members.get(i).role);
    }
  }
Example #3
0
 /** TODO use model instead of model in view */
 void findExpand(Order param) {
   if (param == Order.Ascent) {
     int index;
     if (mainView.isSelectionEmpty()) {
       index = 0;
     } else {
       index = mainView.getSelectedIndex();
     }
     ListModel model = mainView.getModel();
     while (index++ < model.getSize() - 1) {
       if (((Line) model.getElementAt(index)).getFlag() == Line.Type.PLAIN) {
         break;
       }
     }
     while (index < model.getSize()) {
       if (((Line) model.getElementAt(index)).getFlag() != Line.Type.PLAIN) {
         mainView.setSelectedIndex(index);
         mainView.ensureIndexIsVisible(index);
         break;
       }
       index++;
     }
   } else {
     ListModel model = mainView.getModel();
     int index;
     if (mainView.isSelectionEmpty()) {
       index = model.getSize();
     } else {
       index = mainView.getSelectedIndex();
     }
     while (index-- > 0) {
       if (((Line) model.getElementAt(index)).getFlag() == Line.Type.PLAIN) {
         break;
       }
     }
     while (index >= 0) {
       if (((Line) model.getElementAt(index)).getFlag() != Line.Type.PLAIN) {
         mainView.setSelectedIndex(index);
         mainView.ensureIndexIsVisible(index);
         break;
       }
       index--;
     }
   }
   mainView.repaint(); // TODO for popup menu garbage
 }
Example #4
0
 void selectionChanged(String name) { // TODO unused???
   if (!mainView.isSelectionEmpty()) {
     Debug.println(mainView.getSelectedIndex());
     names.setText(name);
     //      } else {
     // Debug.println("A: " + min + ", " + max);
     //          mainView.setValueIsAdjusting(false);
   }
 }
Example #5
0
  public void valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;

    JList theList = (JList) e.getSource();
    if (theList.isSelectionEmpty()) {
      label.setText("Nothing selected.");
    } else {
      int index = theList.getSelectedIndex();
      label.setText("Selected image number " + index);
    }
  }
Example #6
0
  void jList1_valueChanged(ListSelectionEvent e) {
    if (e.getValueIsAdjusting()) return;

    JList theList = (JList) e.getSource();
    if (!theList.isSelectionEmpty()) {
      registerJID = (JID) services.get(theList.getSelectedValue());
      if (registerJID != null)
        backend.send(new InfoQuery(registerJID, "get", backend.getIdentifier(), new IQRegister()));
    }
    theList.clearSelection();
  }
Example #7
0
 /**
  * Shows the html description from the currently selected item. The description is displayed in
  * the JEditorPane itemView.
  */
 public void showDescForCurrentItemSelection() {
   if (itemList.isSelectionEmpty()) {
     return;
   }
   FeedItem selectedFeedItem = (FeedItem) this.itemList.getSelectedValue();
   logger.info("Selected Feed: " + selectedFeedItem);
   System.out.println(selectedFeedItem);
   // Should this behaviour be in the Controller?
   selectedFeedItem.setIsRead(true);
   String description = selectedFeedItem.getHtmlDescription();
   this.itemView.setText(description);
 }
 public void valueChanged(ListSelectionEvent e) {
   if (e.getValueIsAdjusting() == false) {
     if (!schemaList.isSelectionEmpty()) {
       String namespace = (String) schemaList.getSelectedValue();
       if (namespace.equals(NO_NAMESPACE)) namespace = "";
       xsd.setText(
           XmlUtils.prettyPrintXml(
               InferredSchemaManager.getInferredSchema(service).getXsdForNamespace(namespace)));
       xsd.scrollTo(0, 0);
     }
   }
 }
Example #9
0
  /** Shows all items for the currently selected feed in the Jlist itemList. */
  public void showItemsForCurrentFeedSelection() {
    logger.info("Adding items, thread is: " + Thread.currentThread().toString());
    if (feedList.isSelectionEmpty()) {
      logger.warning("No feed selected");
      return;
    }

    Feed selectedFeed = getSelectedFeed();
    System.out.println(selectedFeed);
    FeedItem[] items = this.jeedModel.getItemsForFeed(selectedFeed);

    this.itemList.setListData(items);
  }
Example #10
0
 @Override
 public void valueChanged(ListSelectionEvent selectEvent) {
   correctionsListModel.clear();
   if (!errorsList.getValueIsAdjusting() && !errorsList.isSelectionEmpty()) {
     List<String> selectionValues = errorsList.getSelectedValuesList();
     String selection = (String) selectionValues.get(0);
     String[] nearWords = closeMatches(selection);
     if (!arrayIsEmpty(nearWords)) {
       for (int i = 0; i < nearWords.length; i++) {
         correctionsListModel.addElement(nearWords[i]);
       }
     }
   }
 }
Example #11
0
  public void valueChanged(ListSelectionEvent e) {
    @SuppressWarnings("unchecked")
    JList<String> sender = (JList<String>) e.getSource();

    if (!sender.isSelectionEmpty()) {
      if (sender.equals(boxList())) updateTubList(sender.getSelectedValue());

      if (sender.equals(machineList())) selectedMachine = sender.getSelectedValue();

      if (sender.equals(tubList())) selectedTub = sender.getSelectedValue();
    }

    assignButton().setEnabled(!tubList().isSelectionEmpty() && !machineList().isSelectionEmpty());
  }
Example #12
0
 /** Find next or prev diffs. TODO use model instead of model in view */
 void findOutline(Order param) {
   if (param == Order.Ascent) {
     int index;
     if (mainView.isSelectionEmpty()) {
       index = 0;
     } else {
       index = mainView.getSelectedIndex();
     }
     ListModel model = mainView.getModel();
     while (index++ < model.getSize() - 1) {
       Pair.Type diff = ((Pair) model.getElementAt(index)).getDiff();
       if (diff.isDifferent()) {
         mainView.setSelectedIndex(index);
         mainView.ensureIndexIsVisible(index);
         break;
       }
     }
   } else {
     ListModel model = mainView.getModel();
     int index;
     if (mainView.isSelectionEmpty()) {
       index = model.getSize();
     } else {
       index = mainView.getSelectedIndex();
     }
     while (index-- > 0) {
       Pair.Type diff = ((Pair) model.getElementAt(index)).getDiff();
       if (diff.isDifferent()) {
         mainView.setSelectedIndex(index);
         mainView.ensureIndexIsVisible(index);
         break;
       }
     }
   }
   mainView.repaint(); // TODO for popup menu garbage
 }
Example #13
0
 public void update() {
   String[] namespaces = InferredSchemaManager.getInferredSchema(service).getNamespaces();
   for (int i = 0; i < namespaces.length; i++)
     if (namespaces[i].equals("")) namespaces[i] = NO_NAMESPACE;
   schemaList.setListData(namespaces);
   if (schemaList.isSelectionEmpty()) {
     xsd.setText("");
   } else {
     xsd.setText(
         XmlUtils.prettyPrintXml(
             InferredSchemaManager.getInferredSchema(service)
                 .getXsdForNamespace((String) schemaList.getSelectedValue())));
     xsd.scrollTo(0, 0);
   }
 }
Example #14
0
  /*
   * Shows a contextmenu which contains highlighting options
   *
   * @param evt Mouse Event
   */
  private void showMenu(final MouseEvent evt) {

    /*
     * Disables some options if no item is selected because these
     * options need a selected Item
     */
    if (m_hiliteSelected != null) { // if hiliting is enabled
      if (m_jLabelList.isSelectionEmpty()) {
        m_hiliteSelected.setEnabled(false);
        m_unhiliteSelected.setEnabled(false);
      } else {
        m_hiliteSelected.setEnabled(true);
        m_unhiliteSelected.setEnabled(true);
      }
    }

    m_contextMenu.show(m_jLabelList, evt.getX(), evt.getY());
  }
  /** actualiza */
  @Override
  public void actualiza(Object obj) {
    if (obj instanceof Casilla) {
      Casilla casilla = (Casilla) obj;

      // si hay imagen en la casilla la quitamos y al revés
      if (tableroVista.getIconCasilla(casilla) == null)
        tableroVista.ponerIconoCasilla(
            casilla.getFil(), casilla.getCol(), recSwingApp.getIconoApp());
      else tableroVista.ponerIconoCasilla(casilla.getFil(), casilla.getCol(), null);

      // indicamos la casilla seleccionada en la línea de estado
      estadoTablero.setText(recSwingApp.getEtiqueta(ESTADO_TABLERO) + obj.toString());

      // desactivamos selección de nuevo jugador
      if (!listaJugadores.isSelectionEmpty()) listaJugadores.clearSelection();
      botonInvitar.setEnabled(false);
    }
  }
Example #16
0
 public Object g() throws Exception {
   if (list.isSelectionEmpty()) return null;
   return list.getSelectedValue();
 }
Example #17
0
  public ChatClient(String n) {
    super(n + "'s Client");
    name = n;

    this.setDefaultCloseOperation(DISPOSE_ON_CLOSE);
    this.addWindowListener(this);

    setSize(545, 345);

    JPanel panel = new JPanel();

    panel.add(active);
    panel.add(activelist);

    scrollactive.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    scrollactive.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS);
    scrollactive.setViewportView(activelist);
    panel.add(scrollactive);

    activelist.addListSelectionListener(
        e -> {
          selectedIndex = activelist.getSelectedIndex();
          System.out.println(selectedIndex);
        });

    panel.add(history);

    JScrollPane scroll_bars =
        new JScrollPane(
            history,
            ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    panel.add(scroll_bars);
    panel.add(msglab);
    panel.add(message);

    history.setEditable(false);

    DefaultCaret caret = (DefaultCaret) history.getCaret();
    caret.setUpdatePolicy(DefaultCaret.ALWAYS_UPDATE);

    message.addActionListener(
        e -> {
          try {
            output = new PrintWriter(s.getOutputStream(), true);
          } catch (Exception e1) {

            e1.printStackTrace();
          }

          String tmp = message.getText();
          if (!tmp.equals("")) {
            if (!activelist.isSelectionEmpty()) {
              output.println("@#$PW@#$");
              output.println(selectedIndex);
              output.println(name + ": " + tmp);
              history.append("(PW) " + name + ": " + tmp + "\n");
            } else {
              output.println(name + ": " + tmp);
            }
          }

          message.setText("");
        });

    String[] test = {"Anonymous", "Anonymous"};
    activelist.setListData(test);

    this.setContentPane(panel);

    Thread t = new Thread(this);
    t.start();

    setVisible(true);
  }
Example #18
0
  /**
   * This method populates the ProjectSelector with all the subpanels and buttons
   *
   * @param main The object to notify when the ok button is pressed.
   */
  public void populate(Object main) {
    this.main = main;

    // gather all projects
    String[] projects = getAllProjectNames();
    if (projects == null) {
      Main.fatalError(
          "Cannot find the project folder. Please ensure that the framework is installed properly.");
    }
    Arrays.sort(projects); // sort the projects in ascending order

    this.addComponentListener(
        new ComponentListener() {
          int oldX = appConfig.projectSelectorWindowPosX,
              oldY = appConfig.projectSelectorWindowPosY;

          public void componentResized(ComponentEvent e) {
            if (ProjectSelector.this.getExtendedState() == JFrame.MAXIMIZED_BOTH) {
              appConfig.projectSelectorIsMaximized = true;
              appConfig.projectSelectorWindowPosX = oldX;
              appConfig.projectSelectorWindowPosY = oldY;
            } else {
              appConfig.projectSelectorIsMaximized = false;
              appConfig.projectSelectorWindowWidth = ProjectSelector.this.getWidth();
              appConfig.projectSelectorWindowHeight = ProjectSelector.this.getHeight();
            }
            customParameters.setSize(
                100,
                customParameters
                    .getHeight()); // needed to ensure that the text field shrinks as well
          }

          public void componentMoved(ComponentEvent e) {
            oldX = appConfig.projectSelectorWindowPosX;
            oldY = appConfig.projectSelectorWindowPosY;
            appConfig.projectSelectorWindowPosX = ProjectSelector.this.getX();
            appConfig.projectSelectorWindowPosY = ProjectSelector.this.getY();
          }

          public void componentShown(ComponentEvent e) {}

          public void componentHidden(ComponentEvent e) {}
        });

    // safe the overal config file when the project selector closes
    this.addWindowListener(
        new WindowListener() {
          public void windowOpened(WindowEvent e) {}

          public void windowClosing(WindowEvent e) {
            appConfig.projectSelectorSelectedTab = 1 + right.getSelectedIndex();
            appConfig.writeConfig();
          }

          public void windowClosed(WindowEvent e) {}

          public void windowIconified(WindowEvent e) {}

          public void windowDeiconified(WindowEvent e) {}

          public void windowActivated(WindowEvent e) {}

          public void windowDeactivated(WindowEvent e) {}
        });

    this.setLayout(new BorderLayout());
    this.setResizable(true);
    if (appConfig.projectSelectorIsMaximized) {
      setExtendedState(JFrame.MAXIMIZED_BOTH);
    }
    this.setSize(
        new Dimension(appConfig.projectSelectorWindowWidth, appConfig.projectSelectorWindowHeight));
    this.setLocation(appConfig.projectSelectorWindowPosX, appConfig.projectSelectorWindowPosY);

    JPanel left = new JPanel();
    left.setLayout(new BorderLayout());
    // List of all projects
    selection.setListData(projects);
    selection.setSelectedValue(appConfig.lastChosenProject, true);
    if (!selection.isSelectionEmpty()) {
      selectedProjectName = (String) selection.getSelectedValue();
    } else {
      selectedProjectName = "";
    }
    selection.addListSelectionListener(this);
    selection.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 0));
    selection.setBackground(listPanel.getBackground());
    listScroller = new JScrollPane(selection);
    listPanel.setLayout(new BorderLayout());
    listScroller.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 0));
    listPanel.add(listScroller, BorderLayout.CENTER);
    listPanel.setBorder(BorderFactory.createTitledBorder("Available Projects"));
    left.add(listPanel, BorderLayout.CENTER);

    // OK / Cancel buttons
    buttonPanel.add(ok);
    buttonPanel.add(cancel);
    ok.addActionListener(this);
    cancel.addActionListener(this);
    buttonPanel.setPreferredSize(new Dimension(projectListWidth, 40));
    left.add(buttonPanel, BorderLayout.SOUTH);

    this.add(left, BorderLayout.WEST);

    // right.setBorder(BorderFactory.createTitledBorder("Project Description & Configuration"));

    // The tab containing the description of the selected project
    JPanel description = new JPanel();
    description.setLayout(new BorderLayout());
    scrollableDescriptionPane = new JScrollPane(descriptionText);
    description.add(scrollableDescriptionPane);
    descriptionText.setEditable(false);
    descriptionText.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    int i = selection.getSelectedIndex();
    if (i == -1) {
      // there was no defaultProject
      descriptionText.setText("Please select a project.");
    } else {
      generateGUIDescription(selectedProjectName);
    }
    right.addTab("Description", description);

    // The tab containing the config-file entries
    configuration.setLayout(new BoxLayout(configuration, BoxLayout.Y_AXIS));

    scrollableConfigurationPane = new JScrollPane(frameworkConfigurationPanel);
    // increment the scroll speed (for some reason the speed for the scrollableConfigurationPane is
    // very low)
    scrollableConfigurationPane.getVerticalScrollBar().setUnitIncrement(15);

    frameworkConfigurationPanel.setBorder(BorderFactory.createEmptyBorder(3, 3, 3, 3));

    configuration.add(scrollableConfigurationPane);
    JPanel bp = new JPanel();
    bp.add(saveConfig);
    saveConfig.addActionListener(this);
    saveConfig.setMnemonic(java.awt.event.KeyEvent.VK_S);
    configuration.add(bp);

    expand = createFrameworkIconButton("expand", "expand.gif", "Show advanced settings");
    collapse = createFrameworkIconButton("collapse", "collapse.gif", "Hide advanced settings");

    customConfigurationPanel.setLayout(new BorderLayout());

    JPanel mainCustomConfigurationPanel = new JPanel();
    mainCustomConfigurationPanel.setLayout(
        new BoxLayout(mainCustomConfigurationPanel, BoxLayout.Y_AXIS));
    mainCustomConfigurationPanel.add(customConfigurationPanel);
    // and the save button
    JPanel bp2 = new JPanel();
    bp2.add(saveConfig2);
    saveConfig2.addActionListener(this);
    saveConfig2.setMnemonic(java.awt.event.KeyEvent.VK_S);
    mainCustomConfigurationPanel.add(bp2);

    right.addTab("Framework Config", configuration);
    right.addTab("Project Config", mainCustomConfigurationPanel);
    right.setMnemonicAt(0, java.awt.event.KeyEvent.VK_D);
    right.setMnemonicAt(1, java.awt.event.KeyEvent.VK_F);
    right.setMnemonicAt(2, java.awt.event.KeyEvent.VK_P);
    right.setSelectedIndex(appConfig.projectSelectorSelectedTab - 1);

    if (i == -1) {
      JTextField msg = new JTextField("Please select a project.");
      msg.setEditable(false);
      frameworkConfigurationPanel.add(msg);
    } else {
      generateGUIGonfiguration(selectedProjectName);
    }

    this.add(right, BorderLayout.CENTER);

    this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);

    this.getRootPane().setDefaultButton(ok);

    this.setVisible(true);

    // this.setUndecorated(true);
    // GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().setFullScreenWindow(this);
  }
  /** Initializes the GUI components with the values from the model. */
  protected void initializeGUI() {
    boolean b;
    float f;
    int i;
    String s;

    // General options
    enableDoubleBuffering.setSelected(model.getBoolean(PREFERENCE_KEY_ENABLE_DOUBLE_BUFFERING));
    showRendering.setSelected(model.getBoolean(PREFERENCE_KEY_SHOW_RENDERING));
    autoAdjustWindow.setSelected(model.getBoolean(PREFERENCE_KEY_AUTO_ADJUST_WINDOW));
    selectionXorMode.setSelected(model.getBoolean(PREFERENCE_KEY_SELECTION_XOR_MODE));

    switch (model.getInteger(PREFERENCE_KEY_ANIMATION_RATE_LIMITING_MODE)) {
      case 0: // unlimited
        animationLimitUnlimited.setSelected(true);
        break;
      case 2: // fps
        animationLimitFPS.setSelected(true);
        break;
        // case 1: // %cpu
      default:
        animationLimitCPU.setSelected(true);
        break;
    }
    f = model.getFloat(PREFERENCE_KEY_ANIMATION_RATE_LIMITING_CPU);
    if (f <= 0f || f > 100f) {
      f = 85f;
    } else {
      f *= 100;
    }
    if (((int) f) == f) {
      animationLimitCPUAmount.setText(Integer.toString((int) f));
    } else {
      animationLimitCPUAmount.setText(Float.toString(f));
    }
    f = model.getFloat(PREFERENCE_KEY_ANIMATION_RATE_LIMITING_FPS);
    if (f <= 0f) {
      f = 10f;
    }
    if (((int) f) == f) {
      animationLimitFPSAmount.setText(Integer.toString((int) f));
    } else {
      animationLimitFPSAmount.setText(Float.toString(f));
    }

    showDebugTrace.setSelected(model.getBoolean(PREFERENCE_KEY_SHOW_DEBUG_TRACE));
    isXMLParserValidating.setSelected(model.getBoolean(PREFERENCE_KEY_IS_XML_PARSER_VALIDATING));

    // Security options
    enforceSecureScripting.setSelected(model.getBoolean(PREFERENCE_KEY_ENFORCE_SECURE_SCRIPTING));
    grantScriptFileAccess.setSelected(model.getBoolean(PREFERENCE_KEY_GRANT_SCRIPT_FILE_ACCESS));
    grantScriptNetworkAccess.setSelected(
        model.getBoolean(PREFERENCE_KEY_GRANT_SCRIPT_NETWORK_ACCESS));
    loadJava.setSelected(model.getBoolean(PREFERENCE_KEY_LOAD_JAVA));
    loadEcmascript.setSelected(model.getBoolean(PREFERENCE_KEY_LOAD_ECMASCRIPT));

    i = model.getInteger(PREFERENCE_KEY_ALLOWED_SCRIPT_ORIGIN);
    switch (i) {
      case ResourceOrigin.ANY:
        allowedScriptOrigin.setSelectedIndex(0);
        break;
      case ResourceOrigin.DOCUMENT:
        allowedScriptOrigin.setSelectedIndex(1);
        break;
      case ResourceOrigin.EMBEDED:
        allowedScriptOrigin.setSelectedIndex(2);
        break;
      default:
        allowedScriptOrigin.setSelectedIndex(3);
        break;
    }

    i = model.getInteger(PREFERENCE_KEY_ALLOWED_EXTERNAL_RESOURCE_ORIGIN);
    switch (i) {
      case ResourceOrigin.ANY:
        allowedResourceOrigin.setSelectedIndex(0);
        break;
      case ResourceOrigin.DOCUMENT:
        allowedResourceOrigin.setSelectedIndex(1);
        break;
      case ResourceOrigin.EMBEDED:
        allowedResourceOrigin.setSelectedIndex(2);
        break;
      default:
        allowedResourceOrigin.setSelectedIndex(3);
        break;
    }

    // Language options
    languagePanel.setLanguages(model.getString(PREFERENCE_KEY_LANGUAGES));

    // Stylesheet options
    s = model.getString(PREFERENCE_KEY_CSS_MEDIA);
    mediaListModel.removeAllElements();
    StringTokenizer st = new StringTokenizer(s, " ");
    while (st.hasMoreTokens()) {
      mediaListModel.addElement(st.nextToken());
    }

    userStylesheet.setText(model.getString(PREFERENCE_KEY_USER_STYLESHEET));
    b = model.getBoolean(PREFERENCE_KEY_USER_STYLESHEET_ENABLED);
    userStylesheetEnabled.setSelected(b);

    // Network options
    host.setText(model.getString(PREFERENCE_KEY_PROXY_HOST));
    port.setText(model.getString(PREFERENCE_KEY_PROXY_PORT));

    // Set some components disabled initially
    b = enableDoubleBuffering.isSelected();
    showRendering.setEnabled(b);

    b = animationLimitCPU.isSelected();
    animationLimitCPUAmount.setEnabled(b);
    animationLimitCPULabel.setEnabled(b);

    b = animationLimitFPS.isSelected();
    animationLimitFPSAmount.setEnabled(b);
    animationLimitFPSLabel.setEnabled(b);

    b = enforceSecureScripting.isSelected();
    grantScriptFileAccess.setEnabled(b);
    grantScriptNetworkAccess.setEnabled(b);

    b = userStylesheetEnabled.isSelected();
    userStylesheetLabel.setEnabled(b);
    userStylesheet.setEnabled(b);
    userStylesheetBrowse.setEnabled(b);

    mediaListRemoveButton.setEnabled(!mediaList.isSelectionEmpty());
    mediaListClearButton.setEnabled(!mediaListModel.isEmpty());
  }
 /** Updates the disabled state of the buttons next to the media type list. */
 protected void updateMediaListButtons() {
   mediaListRemoveButton.setEnabled(!mediaList.isSelectionEmpty());
   mediaListClearButton.setEnabled(!mediaListModel.isEmpty());
 }
Example #21
0
  public void actionPerformed(ActionEvent e) {
    Object src = e.getSource();

    if (src == binfo) {
      JOptionPane.showMessageDialog(
          frame,
          "Programme crée par Sarathai\n"
              + "Licence creative commons\n"
              + "\n"
              + "Pour envoyer des fichiers sur le serveur, cliquer d'abord sur le bouton ajouter,\n"
              + "puis sélectionnez le dossier ou fichier à ajouter. Répétez cette opération autant de foi que nécessaire.\n"
              + "Puis cliquez sur le bouton envoyer en ayant d'abord rempli les champs de l'adresse ip et du port.\n"
              + "\n"
              + "Pour recevoir des fichiers sauvegardés sur le serveur, cliquez sur le bouton recevoir,\n"
              + "puis sélectionnez le ou les fichier(s) voulu(s) dans la liste de gauche, et enfin recliquez\n"
              + "sur le bouton recevoir pour importer les fichiers.\n"
              + "\n"
              + "Pour toutes les infos, bien lire le texte qui s'affiche dans le champ de texte en bas.",
          "Informations",
          JOptionPane.INFORMATION_MESSAGE);
    } else if (src == ajouter) {
      JFileChooser chooser = new JFileChooser();
      chooser.setFileFilter(chooser.getAcceptAllFileFilter());
      chooser.setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);

      int i = chooser.showOpenDialog(Fenetre.frame);
      if (i == JFileChooser.APPROVE_OPTION) {
        frame.setCursor(waitCursor);

        File file = chooser.getSelectedFile();

        if (file.isDirectory()) {
          name = file.getAbsolutePath().toString() + sep;
          selection.addElement(name);
          new WhatIDo("Ajouté à la séléction", name);
        } else {
          name = file.getAbsolutePath().toString();
          selection.addElement(name);
          new WhatIDo("Ajouté à la séléction", name);
        }
        liste.updateUI();
        enlever.setEnabled(true);
        frame.setCursor(Cursor.getDefaultCursor());
      }
    } else if (src == enlever) {
      try {
        int j = liste.getSelectedIndex();
        new WhatIDo("Supprimé de la séléction", selection.elementAt(j).toString());
        selection.removeElementAt(j);
      } catch (ArrayIndexOutOfBoundsException e1) {
        new WhatIDo("Supprimé de la séléction", selection.elementAt(0).toString());
        selection.removeElementAt(0);
      }
      if (selection.size() == 0) {
        selection.clear();
        liste.clearSelection();
        enlever.setEnabled(false);
      }
      liste.updateUI();
    } else if (src == bquitter) {
      System.exit(0);
    } else if (src == bnouveau) {
      selection.clear();
      liste.clearSelection();
      liste.updateUI();
      new WhatIDo("Nouvelle sauvegarde");
    } else if (src == benvoyer) {
      if (!selection.isEmpty()) {
        new Envoyer(selection);
      } else {
        new WhatIDo("Veuillez ajouter des fichiers ou dossiers");
      }
    } else if (src == brecevoir) {
      if (!liste.isSelectionEmpty()) {
        Vector<String> vec = new Vector<String>();
        for (int i : liste.getSelectedIndices()) {
          vec.addElement(selection.elementAt(i));
        }
        new Recevoir(vec);
      } else {
        new Recevoir();
      }
    }
  }