Exemplo n.º 1
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);
 }
Exemplo n.º 2
0
 public void commitChanges() {
   res.put(PGameInformation.BACKGROUND_COLOR, editor.getBackground());
   ByteArrayOutputStream baos = new ByteArrayOutputStream();
   try {
     StyledDocument doc = (StyledDocument) editor.getDocument();
     rtf.write(baos, doc, doc.getStartPosition().getOffset(), doc.getLength());
     res.put(PGameInformation.TEXT, baos.toString("UTF-8")); // $NON-NLS-1$
   } catch (IOException e) { // Nevermind
     e.printStackTrace();
   } catch (BadLocationException e) { // Should never happen, but we have to catch this anyways
     e.printStackTrace();
   }
 }
Exemplo n.º 3
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 out = new FileOutputStream(new File(name));
     StyledDocument doc = (StyledDocument) editor.getDocument();
     rtf.write(out, doc, doc.getStartPosition().getOffset(), doc.getLength());
     out.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
 }
Exemplo n.º 4
0
  public void setSelectionAlignment(int alignment) {
    setAlignmentOptions(alignment);

    StyledDocument sd = (StyledDocument) editor.getDocument();
    int a = editor.getSelectionStart();
    int b = editor.getSelectionEnd();
    if (a == b) {
      rtf.getInputAttributes().addAttribute(StyleConstants.Alignment, alignment);
      return;
    }
    SimpleAttributeSet sas = new SimpleAttributeSet();
    StyleConstants.setAlignment(sas, alignment);
    sd.setParagraphAttributes(a, b - a, sas, false);
    return;
  }
Exemplo n.º 5
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);
     editor.setCaretPosition(0);
   } catch (IOException e) { // Nevermind
   } catch (BadLocationException e) { // Should never happen, but we have to catch this anyways
   }
   undoManager.discardAllEdits();
   undoManager.updateActions();
 }
Exemplo n.º 6
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(
         fc,
         fc.getSelectedFile().getName()
             + Messages.getString("GameInformationFrame.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();
   }
 }