/* (non-Javadoc) * @see bias.extension.DashBoard.snippet.InfoSnippet#serializeSettings() */ @Override public byte[] serializeSettings() { settings.setProperty(PROPERTY_FONT_SIZE, "" + currentFontSize); JScrollBar sb = getJScrollPane().getVerticalScrollBar(); if (sb != null && sb.getValue() != 0) { settings.setProperty(PROPERTY_SCROLLBAR_VERT, "" + sb.getValue()); } else { settings.remove(PROPERTY_SCROLLBAR_VERT); } sb = getJScrollPane().getHorizontalScrollBar(); if (sb != null && sb.getValue() != 0) { settings.setProperty(PROPERTY_SCROLLBAR_HORIZ, "" + sb.getValue()); } else { settings.remove(PROPERTY_SCROLLBAR_HORIZ); } int cp = getJTextPane().getCaretPosition(); settings.setProperty(PROPERTY_CARET_POSITION, "" + cp); return PropertiesUtils.serializeProperties(settings); }
private void initialize() { this.setSize(733, 515); this.setLayout(new BorderLayout()); if (getContent() != null) { content = getContent(); getJTextPane().setText(new String(content)); } settings = PropertiesUtils.deserializeProperties(getSettings()); applySettings(); JScrollBar sb = getJScrollPane().getVerticalScrollBar(); if (sb != null) { String val = settings.getProperty(PROPERTY_SCROLLBAR_VERT); if (val != null) { sb.setVisibleAmount(0); sb.setValue(sb.getMaximum()); sb.setValue(Integer.valueOf(val)); } } sb = getJScrollPane().getHorizontalScrollBar(); if (sb != null) { String val = settings.getProperty(PROPERTY_SCROLLBAR_HORIZ); if (val != null) { sb.setVisibleAmount(0); sb.setValue(sb.getMaximum()); sb.setValue(Integer.valueOf(val)); } } String caretPos = settings.getProperty(PROPERTY_CARET_POSITION); if (!Validator.isNullOrBlank(caretPos)) { try { getJTextPane().setCaretPosition(Integer.valueOf(caretPos)); } catch (IllegalArgumentException iae) { // ignore incorrect caret positioning } } getJTextPane().getDocument().addUndoableEditListener(new UndoRedoManager(jTextPane)); getJTextPane() .getDocument() .addDocumentListener( new DocumentListener() { public void changedUpdate(DocumentEvent e) { dataChanged(); } public void insertUpdate(DocumentEvent e) { dataChanged(); } public void removeUpdate(DocumentEvent e) { dataChanged(); } private void dataChanged() { if (getJTextPane().isEditable()) { contentChanged = true; } } }); this.add(getJScrollPane(), BorderLayout.CENTER); this.add(getJToolBar(), BorderLayout.SOUTH); }