示例#1
1
  // --------------------------------actionConnect------------------------------
  private void actionConnect() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    String[] oResults = (String[]) DialogManager.show(DialogManager.CONNECT, frame);

    if (oResults[DialogManager.RETURN_IP].equals("cancel")) return;

    lblStatus3.setText("Connecting...");
    try {
      oConn.connect(
          oResults[DialogManager.RETURN_IP], Integer.parseInt(oResults[DialogManager.RETURN_PORT]));
    } catch (UnknownHostException e) {
      JOptionPane.showMessageDialog(
          frame,
          "The IP of the host cannot be determined.",
          "Unknown Host Exception",
          JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    } catch (IOException e) {
      JOptionPane.showMessageDialog(
          frame, e.getMessage(), "Input/Output Exception", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();
  }
示例#2
1
  // --------------------------------actionHost---------------------------------
  private void actionHost() {
    if (oParty == null) {
      JOptionPane.showMessageDialog(frame, "Make a party before trying to connect.");
      return;
    }

    JFileChooser oFC = new JFileChooser(DEFAULT_MAP_DIRECTORY);
    int nReturn = oFC.showOpenDialog(frame);

    if (nReturn == JFileChooser.CANCEL_OPTION) {
      return;
    }

    int nPort = Integer.parseInt((String) (DialogManager.show(DialogManager.HOST, frame)));

    JDialog dlgBox = (JDialog) (DialogManager.show(DialogManager.WAITING_FOR_CONN, frame));
    dlgBox.pack();
    try {
      oConn.host(nPort);
    } catch (IOException e) {
      JOptionPane.showMessageDialog(frame, e.getMessage(), "Error!", JOptionPane.ERROR_MESSAGE);
      frame.repaint();
      return;
    }
    dlgBox.setVisible(false);
    echo("Connected to opponent!");

    tConn = new Thread(oConn, "conn");
    tConn.start();
    tMain = new Thread(this, "main");
    tMain.start();

    try {
      oMap.loadMap(oFC.getSelectedFile());
      oConn.send("loadmap", oFC.getName(oFC.getSelectedFile()));
    } catch (Exception e) {
      e.printStackTrace();
      System.exit(-1);
    }
  }
示例#3
0
  public synchronized void run() {

    byte[] buffer = new byte[BUFFER_SIZE];

    for (; ; ) {
      try {
        this.wait(100);
      } catch (InterruptedException ie) {
      }

      int len = 0;
      try {
        int noBytes = pin.available();

        if (noBytes > 0) {
          len = pin.read(buffer, 0, Math.min(noBytes, BUFFER_SIZE));
          if (len > 0) {
            jTextArea.append(new String(buffer, 0, len));
            jTextArea.setCaretPosition(jTextArea.getText().length());
          }
        }
      } catch (IOException ioe) {
        throw new UIError("Unable to read from input stream! " + ioe.getMessage());
      }
    }
  }
示例#4
0
  void lookUpTaxonID(String taxonID) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url =
          new URI(
              "http://www.itis.gov/servlet/SingleRpt/SingleRpt?search_topic=TSN&search_value="
                  + taxonID);
    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
示例#5
0
  void searchName(String nameToMatch) {
    URI url;

    try {
      // We should look up the miITIS_TSN status, but since we don't
      // have any options there ...
      url = new URI("http", "www.google.com", "/search", "q=" + nameToMatch);
      // I think the URI handles the URL encoding?

    } catch (URISyntaxException e) {
      throw new RuntimeException(e);
    }

    try {
      Desktop desktop = Desktop.getDesktop();
      desktop.browse(url);

    } catch (IOException e) {
      MessageBox.messageBox(
          mainFrame,
          "Could not open URL '" + url + "'",
          "The following error occurred while looking up URL '" + url + "': " + e.getMessage(),
          MessageBox.ERROR);
    }
  }
示例#6
0
文件: Client.java 项目: Eneru/l3s6
  public void init() {
    add(intitule);
    add(texte);
    add(bouton);
    bouton.addActionListener(this);

    try {
      ORB orb = ORB.init(this, null);
      FileReader file = new FileReader(iorfile.value);
      BufferedReader in = new BufferedReader(file);
      String ior = in.readLine();
      file.close();
      org.omg.CORBA.Object obj = orb.string_to_object(ior);
      annuaire = AnnuaireHelper.narrow(obj);

    } catch (org.omg.CORBA.SystemException ex) {
      System.err.println("Error");
      ex.printStackTrace();
    } catch (FileNotFoundException fnfe) {
      System.err.println(fnfe.getMessage());
    } catch (IOException io) {
      System.err.println(io.getMessage());
    } catch (Exception e) {
      System.err.println(e.getMessage());
    }
  }
 public static void writeArray(String s, int[] x) {
   try {
     RandomAccessFile output = new RandomAccessFile(s, "rw");
     for (int i = 0; i < x.length; i++) output.writeInt(x[i]);
   } catch (IOException e) {
     System.out.println(e.getMessage());
   }
 }
示例#8
0
 public String getValue() {
   Array value = att.getValues();
   try {
     return NCdumpW.printArray(value, null, null);
   } catch (IOException e) {
     return e.getMessage();
   }
 }
示例#9
0
    @Override
    @SuppressWarnings("SleepWhileHoldingLock")
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum(doc.getLength());
        status.add(progress);
        status.revalidate();

        // start writing
        Writer out = new FileWriter(f);
        Segment text = new Segment();
        text.setPartialReturn(true);
        int charsLeft = doc.getLength();
        int offset = 0;
        while (charsLeft > 0) {
          doc.getText(offset, Math.min(4096, charsLeft), text);
          out.write(text.array, text.offset, text.count);
          charsLeft -= text.count;
          offset += text.count;
          progress.setValue(offset);
          try {
            Thread.sleep(10);
          } catch (InterruptedException e) {
            Logger.getLogger(FileSaver.class.getName()).log(Level.SEVERE, null, e);
          }
        }
        out.flush();
        out.close();
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not save file: " + msg,
                    "Error saving file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();
    }
示例#10
0
    @Override
    public void run() {
      try {
        // initialize the statusbar
        status.removeAll();
        JProgressBar progress = new JProgressBar();
        progress.setMinimum(0);
        progress.setMaximum((int) f.length());
        status.add(progress);
        status.revalidate();

        // try to start reading
        Reader in = new FileReader(f);
        char[] buff = new char[4096];
        int nch;
        while ((nch = in.read(buff, 0, buff.length)) != -1) {
          doc.insertString(doc.getLength(), new String(buff, 0, nch), null);
          progress.setValue(progress.getValue() + nch);
        }
      } catch (IOException e) {
        final String msg = e.getMessage();
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                JOptionPane.showMessageDialog(
                    getFrame(),
                    "Could not open file: " + msg,
                    "Error opening file",
                    JOptionPane.ERROR_MESSAGE);
              }
            });
      } catch (BadLocationException e) {
        System.err.println(e.getMessage());
      }
      doc.addUndoableEditListener(undoHandler);
      // we are done... get rid of progressbar
      status.removeAll();
      status.revalidate();

      resetUndoManager();

      if (elementTreePanel != null) {
        SwingUtilities.invokeLater(
            new Runnable() {

              public void run() {
                elementTreePanel.setEditor(getEditor());
              }
            });
      }
    }
示例#11
0
 public File getCurrentFile(boolean shouldSave) {
   if (shouldSave && _editingFile == null && isDirty()) {
     try {
       saveAsFile(Settings.isMac());
     } catch (IOException e) {
       Debug.error(
           me + "getCurrentFile: Problem while trying to save %s\n%s",
           _editingFile.getAbsolutePath(),
           e.getMessage());
     }
   }
   return _editingFile;
 }
示例#12
0
 public String getData() {
   ByteArrayOutputStream out = new ByteArrayOutputStream();
   try {
     getDrawing().getOutputFormats().get(0).write(out, getDrawing());
     return out.toString("UTF8");
   } catch (IOException e) {
     SVGTextFigure tf = new SVGTextFigure();
     tf.setText(e.getMessage());
     tf.setBounds(new Point2D.Double(10, 10), new Point2D.Double(100, 100));
     getDrawing().add(tf);
     e.printStackTrace();
     return "";
   }
 }
示例#13
0
  @Override
  public void actionPerformed(ActionEvent ev) {
    if (ev.getSource() == btn) {
      File file;
      String string = "";
      try {
        if (radioRead.isSelected()) {
          file = new File(txt.getText());
          DataInputStream input = new DataInputStream(new FileInputStream(file));
          int inByte;
          while ((inByte = input.read()) != -1) {
            string += (char) inByte;
          }
          input.close();

        } else if (radioEncrypt.isSelected()) {
          string = fileContent.getOut();
          String strEncrypt = new String();
          for (int i = 0; i < string.length(); i++) {
            char ch = string.charAt(i);
            if (ch >= 'A' && ch <= 'Z') {
              ch += 13;
              if (ch > 'Z') {
                ch -= 26;
              }
            } else if (ch >= 'a' && ch <= 'z') {
              ch += 13;
              if (ch > 'z') {
                ch -= 26;
              }
            }
            strEncrypt += ch;
          }
          string = strEncrypt;
        }

        if (fileContent == null) {
          fileContent = new FileContent(string);
        } else {
          fileContent.setVisible(true);
          fileContent.setOut(string);
        }

      } catch (FileNotFoundException e) {
        JOptionPane.showMessageDialog(this, "Can't find the file.");
      } catch (IOException e) {
        JOptionPane.showMessageDialog(this, "IO Exception " + e.getMessage());
      }
    }
  }
示例#14
0
 public File copyFileToBundle(String filename) {
   File f = new File(filename);
   String bundlePath = getSrcBundle();
   if (f.exists()) {
     try {
       File newFile = FileManager.smartCopy(filename, bundlePath);
       return newFile;
     } catch (IOException e) {
       Debug.error(
           me + "copyFileToBundle: Problem while trying to save %s\n%s", filename, e.getMessage());
       return f;
     }
   }
   return null;
 }
  public static void main(String[] args) {

    MyCustomizableGUI custGUI = new MyCustomizableGUI();
    UserPreferences savedPrefs;

    try (FileInputStream fileIn = new FileInputStream("preferences.ser");
        ObjectInputStream objectIn = new ObjectInputStream(fileIn); ) {

      savedPrefs = (UserPreferences) objectIn.readObject();

      if (savedPrefs.getColor().contains("Red")) {
        custGUI.textField.setForeground(Color.red);
        custGUI.color.setSelectedItem("Red");
      } else if (savedPrefs.getColor().contains("Green")) {
        custGUI.textField.setForeground(Color.green);
        custGUI.color.setSelectedItem("Green");
      } else if (savedPrefs.getColor().contains("Blue")) {
        custGUI.textField.setForeground(Color.blue);
        custGUI.color.setSelectedItem("Blue");
      } else if (savedPrefs.getColor().contains("Cyan")) {
        custGUI.textField.setForeground(Color.cyan);
        custGUI.color.setSelectedItem("Cyan");
      } else if (savedPrefs.getColor().contains("Magenta")) {
        custGUI.textField.setForeground(Color.magenta);
        custGUI.color.setSelectedItem("Magenta");
      } else if (savedPrefs.getColor().contains("Yellow")) {
        custGUI.textField.setForeground(Color.yellow);
        custGUI.color.setSelectedItem("Yellow");
      } else if (savedPrefs.getColor().contains("Black")) {
        custGUI.textField.setForeground(Color.black);
        custGUI.color.setSelectedItem("Black");
      }

      custGUI.setFont(savedPrefs.getFont(), savedPrefs.getFontSize());
      custGUI.font.setSelectedItem(savedPrefs.getFont());
      custGUI.fontSize.setSelectedItem("" + savedPrefs.getFontSize());

    } catch (FileNotFoundException noFile) {
      // load default font and color
      custGUI.setFont("Arial", 25);
      custGUI.textField.setForeground(Color.black);

    } catch (ClassNotFoundException noPrefs) {
      noPrefs.printStackTrace();
    } catch (IOException e) {
      System.out.println("I/O Error: " + e.getMessage());
    }
  }
示例#16
0
  /**
   * Handle the -biojava option
   *
   * <p>Command line syntax: art -biojava org.biojava.bio.seq.io.EmblLikeFormat foo.embl
   *
   * <p>BioJava formats: EmblLikeFormat, FastaFormat, GAMEFormat, GenbankFormat, PhredFormat
   */
  private void handleBioJava(final String[] args) {
    if (args.length == 3) {
      final String class_name = args[1];
      final String location = args[2];

      final Document location_document = DocumentFactory.makeDocument(location);

      try {
        final Object biojava_object = Class.forName(class_name).newInstance();

        final EntryInformation entry_information = Options.getArtemisEntryInformation();

        final uk.ac.sanger.artemis.io.BioJavaEntry emblEntry;

        if (biojava_object instanceof SequenceFormat) {
          final SequenceFormat sequence_format = (SequenceFormat) biojava_object;

          emblEntry =
              new uk.ac.sanger.artemis.io.BioJavaEntry(
                  entry_information, location_document, sequence_format);

          final Entry new_entry = new Entry(emblEntry);
          final EntryEdit new_entry_edit = makeEntryEdit(new_entry);
          new_entry_edit.setVisible(true);
        } else new MessageDialog(this, "not a SequenceFormat: " + class_name);
      } catch (IllegalAccessException e) {
        new MessageDialog(this, "cannot create class: " + class_name + " - IllegalAccessException");
      } catch (ClassNotFoundException e) {
        new MessageDialog(this, "cannot find class: " + class_name);
      } catch (ClassCastException e) {
        new MessageDialog(this, class_name + " is not a sub-class of " + "SequenceFormat");
      } catch (IOException e) {
        new MessageDialog(this, "I/O error while reading from " + location + ": " + e.getMessage());
      } catch (NoSequenceException e) {
        new MessageDialog(this, location + " contained no sequence");
      } catch (InstantiationException e) {
        new MessageDialog(this, "cannot instantiate " + class_name);
      } catch (OutOfRangeException e) {
        new MessageDialog(
            this,
            "read failed: one of the features in "
                + location
                + " has an out of range location: "
                + e.getMessage());
      }
    } else new MessageDialog(this, "the -biojava option needs two arguments");
  }
示例#17
0
 private void actionPerformedUpdates(Window _parent) {
   boolean tempDirty = isDirty();
   if (paneNaming.isDirty()) {
     String filename = paneNaming.getAbsolutePath();
     String oldFilename = _imgBtn.getFilename();
     if (FileManager.exists(filename)) {
       String name = FileManager.getName(filename);
       int ret =
           JOptionPane.showConfirmDialog(
               _parent,
               SikuliIDEI18N._I("msgFileExists", name),
               SikuliIDEI18N._I("dlgFileExists"),
               JOptionPane.WARNING_MESSAGE,
               JOptionPane.YES_NO_OPTION);
       if (ret != JOptionPane.YES_OPTION) {
         return;
       }
     }
     try {
       FileManager.xcopy(oldFilename, filename, null);
       (new File(oldFilename)).delete();
       _imgBtn.setFilename(filename);
     } catch (IOException ioe) {
       Debug.error("renaming failed: " + oldFilename + " " + filename);
       Debug.error(ioe.getMessage());
     }
     paneNaming.updateFilename();
     addDirty(true);
   }
   addDirty(
       _imgBtn.setParameters(
           _screenshot.isExact(), _screenshot.getSimilarity(), _screenshot.getNumMatches()));
   addDirty(_imgBtn.setTargetOffset(_tarOffsetPane.getTargetOffset()));
   Debug.log(2, "update: " + _imgBtn.toString());
   if (isDirty() || tempDirty) {
     int i = _imgBtn.getWindow().getTabbedPane().getSelectedIndex();
     _imgBtn.getWindow().setMessageApplied(i, true);
     _imgBtn.repaint();
   }
 }
  public static String readArray(String s) {
    String output = "[ ";
    boolean endOfFile = false;

    try {
      RandomAccessFile input = new RandomAccessFile(s, "rw");
      input.seek(0);

      while (!endOfFile) {
        try {
          output = output + input.readInt() + " ";
        } catch (EOFException e) {
          endOfFile = true;
          output = output + "]";
        }
      }
    } catch (IOException e) {
      return e.getMessage();
    }

    return output;
  }
  public GuiFriendlizerApp() {
    super(new BorderLayout());

    // Init jPanel controls
    initComponent();

    // Clear output text area (as a logger)
    logger.setText(null);

    try {
      // Loading configuration
      moduleConfiguration = new ModuleConfiguration();

      // Print guide
      FriendlizerUtilities.Log(logger, "Steps:");
      FriendlizerUtilities.Log(logger, "1.Chosing your NetBeans IDE folder");
      FriendlizerUtilities.Log(logger, "2.Patching it.");
      FriendlizerUtilities.Log(logger, "======================================");
    } catch (IOException e) {
      FriendlizerUtilities.Log(logger, "Loading configuration error: " + e.getMessage());
    }
  }
示例#20
0
  @Override
  public void action(final Object comp) {
    final String pth = path();
    final IOFile io = new IOFile(pth);
    String inf = io.isDir() && io.children().length > 0 ? DIR_NOT_EMPTY : null;
    ok = !pth.isEmpty();

    final SerialMethod mth = SerialMethod.valueOf(method.getSelectedItem());
    final OptionsOption<? extends Options> opts =
        mth == SerialMethod.JSON
            ? SerializerOptions.JSON
            : mth == SerialMethod.CSV ? SerializerOptions.CSV : null;
    final boolean showmparams = opts != null;
    mparams.setEnabled(showmparams);

    if (ok) {
      gui.gopts.set(GUIOptions.INPUTPATH, pth);
      try {
        if (comp == method) {
          if (showmparams) {
            final Options mopts = options(null).get(opts);
            mparams.setToolTipText(tooltip(mopts));
            mparams.setText(mopts.toString());
          } else {
            mparams.setToolTipText(null);
            mparams.setText("");
          }
        }
        Serializer.get(new ArrayOutput(), options(mth));
      } catch (final IOException ex) {
        ok = false;
        inf = ex.getMessage();
      }
    }

    info.setText(inf, ok ? Msg.WARN : Msg.ERROR);
    enableOK(buttons, B_OK, ok);
  }
  MyCustomizableGUI() {

    this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS));
    textField = new JTextField(20);
    buttonPref = new JButton("Preferences");

    this.add(textField);
    this.add(buttonPref);

    buttonPref.addActionListener(evt -> prefDialog.setVisible(true));

    frame = new JFrame("My text editor");
    frame.setContentPane(this);
    frame.pack();
    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    frame.setVisible(true);

    // Preferences dialog box
    prefDialog = new JDialog(frame, "Dialog", true);
    prefDialog.setLayout(new BorderLayout());
    JPanel p1 = new JPanel();
    p1.setLayout(new GridLayout(3, 2));
    JPanel p2 = new JPanel();
    p2.setLayout(new BoxLayout(p2, BoxLayout.X_AXIS));

    buttonSave = new JButton("Save");
    buttonCancel = new JButton("Cancel");

    buttonSave.addActionListener(
        evtSave -> {
          String fontChosen;
          int fontSizeChosen;

          prefDialog.setVisible(false);

          if ((String) color.getSelectedItem() == "Red") {
            textField.setForeground(Color.red);
          } else if ((String) color.getSelectedItem() == "Green") {
            textField.setForeground(Color.green);
          } else if ((String) color.getSelectedItem() == "Blue") {
            textField.setForeground(Color.blue);
          } else if ((String) color.getSelectedItem() == "Cyan") {
            textField.setForeground(Color.cyan);
          } else if ((String) color.getSelectedItem() == "Magenta") {
            textField.setForeground(Color.magenta);
          } else if ((String) color.getSelectedItem() == "Yellow") {
            textField.setForeground(Color.yellow);
          } else if ((String) color.getSelectedItem() == "Black") {
            textField.setForeground(Color.black);
          }

          fontChosen = (String) font.getSelectedItem();
          fontSizeChosen = Integer.parseInt((String) fontSize.getSelectedItem());
          textField.setFont(new Font(fontChosen, Font.PLAIN, fontSizeChosen));

          UserPreferences userPrefs = new UserPreferences();
          userPrefs.setColor((String) color.getSelectedItem());
          userPrefs.setFont(fontChosen);
          userPrefs.setFontSize(fontSizeChosen);

          try (FileOutputStream fileOut = new FileOutputStream("preferences.ser");
              ObjectOutputStream objectOut = new ObjectOutputStream(fileOut); ) {

            objectOut.writeObject(userPrefs);

          } catch (IOException ioe) {
            System.out.println("I/O error: " + ioe.getMessage());
          }
        });

    buttonCancel.addActionListener(evt -> prefDialog.setVisible(false));

    colorLabel = new JLabel("Color:");
    fontLabel = new JLabel("Font:");
    fontSizeLabel = new JLabel("Font size:");
    color = new JComboBox(colorList);
    font = new JComboBox(fontList);
    fontSize = new JComboBox(fontSizeList);

    p1.add(colorLabel);
    p1.add(color);
    p1.add(fontLabel);
    p1.add(font);
    p1.add(fontSizeLabel);
    p1.add(fontSize);
    p2.add(buttonCancel);
    p2.add(buttonSave);

    prefDialog.add(BorderLayout.NORTH, p1);
    prefDialog.add(BorderLayout.SOUTH, p2);

    prefDialog.pack();
  }