コード例 #1
0
 public void commitChanges() {
   res.put(PGameInformation.BACKGROUND_COLOR, editor.getBackground());
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try {
     rtf.write(baos, editor.getDocument(), 0, 0);
     res.put(PGameInformation.TEXT, baos.toString("UTF-8")); // $NON-NLS-1$
   } catch (IOException e) { // Nevermind
   } catch (BadLocationException e) { // Should never happen, but we have to catch this anyways
   }
 }
コード例 #2
0
 public void setSelectionAttribute(Object key, Object value) {
   StyledDocument sd = (StyledDocument) editor.getDocument();
   int a = editor.getSelectionStart();
   int b = editor.getSelectionEnd();
   if (a == b) {
     rtf.getInputAttributes().addAttribute(key, value);
     return;
   }
   SimpleAttributeSet sas = new SimpleAttributeSet();
   sas.addAttribute(key, value);
   sd.setCharacterAttributes(a, b - a, sas, false);
 }
コード例 #3
0
 public void setComponents(GameInformation info) {
   setEditorBackground((Color) res.get(PGameInformation.BACKGROUND_COLOR));
   editor.setText(null);
   try {
     rtf.read(
         new ByteArrayInputStream(
             ((String) res.get(PGameInformation.TEXT)).getBytes("UTF-8")), // $NON-NLS-1$
         editor.getDocument(),
         0);
   } catch (IOException e) { // Nevermind
   } catch (BadLocationException e) { // Should never happen, but we have to catch this anyways
   }
 }
コード例 #4
0
 public void saveToFile() {
   fc.setDialogTitle(Messages.getString("GameInformationFrame.SAVE_TITLE")); // $NON-NLS-1$
   if (fc.showSaveDialog(this) != JFileChooser.APPROVE_OPTION) return;
   String name = fc.getSelectedFile().getPath();
   if (CustomFileFilter.getExtension(name) == null) name += ".rtf"; // $NON-NLS-1$
   try {
     FileOutputStream i = new FileOutputStream(new File(name));
     rtf.write(i, editor.getDocument(), 0, 0);
     i.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
コード例 #5
0
 public void loadFromFile() {
   fc.setDialogTitle(Messages.getString("GameInformationFrame.LOAD_TITLE")); // $NON-NLS-1$
   while (true) {
     if (fc.showOpenDialog(LGM.frame) != JFileChooser.APPROVE_OPTION) return;
     if (fc.getSelectedFile().exists()) break;
     JOptionPane.showMessageDialog(
         null,
         fc.getSelectedFile().getName()
             + Messages.getString("SoundFrame.FILE_MISSING"), // $NON-NLS-1$
         Messages.getString("GameInformationFrame.LOAD_TITLE"), // $NON-NLS-1$
         JOptionPane.WARNING_MESSAGE);
   }
   try {
     FileInputStream i = new FileInputStream(fc.getSelectedFile());
     editor.setText(""); // $NON-NLS-1$
     rtf.read(i, editor.getDocument(), 0);
     i.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }