simplyhtml-0.17.3/ 0040755 0000000 0000000 00000000000 13147565156 012553 5 ustar 00 0000000 0000000 simplyhtml-0.17.3/dist.gradle 0100644 0000000 0000000 00000001600 12677550144 014666 0 ustar 00 0000000 0000000 task binDistrib(type: Zip) {
archiveName = 'simplyhtml_bin-' + project.version + '.zip'
destinationDir = rootDir
from(configurations.compile)
from(mainJar.outputs.files)
from(helpJar.outputs.files)
from(rootDir) {
include('*.txt')
}
into('simplyhtml-' + project.version)
dependsOn mainJar
dependsOn helpJar
}
task sourceDistrib(type: Tar) {
archiveName = 'simplyhtml_src-' + project.version + '.tar.gz'
destinationDir = rootDir
compression = 'GZIP'
includeEmptyDirs = false
from(rootDir) {
include('src/**')
include('*.txt')
include('*.gradle')
}
into('simplyhtml-' + project.version)
}
task dist {
dependsOn binDistrib
dependsOn sourceDistrib
}
task cleanDist(type: Delete) {
delete binDistrib.outputs.files
delete sourceDistrib.outputs.files
}
clean.dependsOn cleanDist
simplyhtml-0.17.3/readme.txt 0100644 0000000 0000000 00000006301 12114157751 014535 0 ustar 00 0000000 0000000 SimplyHTML readme file
Stage 13, May 24th, 2009
Copyright (c) 2002, 2003 Ulrich Hilger, 2008 Dimitri Polivaev
http://simplyhtml.sf.net/
(see 'License' below)
This file contains
------------------
About SimplyHTML
Downloads
Requirements
Installation
Usage
Compilation
License
About SimplyHTML
----------------
SimplyHTML is an application for text processing. It
stores documents as HTML files in combination with
Cascading Style Sheets (CSS).
SimplyHTML is not intended to be used as an editor for
web pages. The application combines text processing
features as known from popular word processors with a
simple and generic way of storing textual information
and styles.
Downloads
---------
The SimplyHTML offers 3 packages you can download:
- SimplyHTML_bin_ It can be used in drag and drop operations or in copy and paste
* operations. Additional to updates the image preview and property displays according
* to the current selection (if any) used on the JScrollPane holding the image preview
* to adjust the preview to size changes and to synchronize
* property displays accordingly. Used to adjust preview properties according to
* user settings in the scale text field Used to adjust preview properties according to
* user settings in the scale text field Used to adjust preview properties according to
* user settings in SizeSelectorPanels Swing already uses three types of classes to implement a model, view,
* controller (MVC) approach for a document: JTextComponent - the view implementation For a GUI representation of a document, additional parts are needed, such
* as a JScrollPane as well as listeners and fields to track the state of
* the document while it is represented on a GUI. If for instance an application wants to create a new document, it simply
* creates an instance of this class instead of having to implement own
* methods for instatiating each element (editor pane, scroll pane, etc.)
* separately. A document still has to be either created or loaded after using
* this constructor, so it is better to use the constructor doing this
* right away instead. With stage 8, saves a style sheet by merging it with the existing
* one with the same name/location. Styles in this style sheet overwrite
* styles in the already existing style sheet. The name is built byHTMLText it supports the
* String data flavor.HTMLTextSelection with a chunk
* of styled text.
*
* @param data - a HTMLText object
*
* @see com.lightdev.app.shtm.HTMLText
*/
public HTMLTextSelection(final HTMLText data) {
this.data = data;
}
/* ---- start of Transferable implementation ----------------------------*/
/**
* Returns an array of DataFlavor objects indicating the flavors the data
* can be provided in. The array should be ordered according to preference
* for providing the data (from most richly descriptive to least descriptive).
* @return an array of data flavors in which this data can be transferred
*/
public DataFlavor[] getTransferDataFlavors() {
return (DataFlavor[]) flavors.clone();
}
/**
* Returns whether or not the specified data flavor is supported for
* this object.
* @param flavor the requested flavor for the data
* @return boolean indicating wjether or not the data flavor is supported
*/
public boolean isDataFlavorSupported(final DataFlavor flavor) {
for (int i = 0; i < flavors.length; i++) {
if (flavors[i].equals(flavor)) {
return true;
}
}
return false;
}
/**
* Returns an object which represents the data to be transferred. The class
* of the object returned is defined by the representation class of the flavor.
*
* @param flavor the requested flavor for the data
* @see DataFlavor#getRepresentationClass
* @exception IOException if the data is no longer available
* in the requested flavor.
* @exception UnsupportedFlavorException if the requested data flavor is
* not supported.
*/
public Object getTransferData(final DataFlavor flavor) throws UnsupportedFlavorException, IOException {
if (flavor.equals(flavors[HTML_TEXT])) {
return data;
}
else {
throw new UnsupportedFlavorException(flavor);
}
}
/* ----------- end of Transferable implementation ------------------- */
}
simplyhtml-0.17.3/src/com/lightdev/app/shtm/ImageDialog.java 0100644 0000000 0000000 00000064476 12114157751 022473 0 ustar 00 0000000 0000000 /*
* SimplyHTML, a word processor based on Java, HTML and CSS
* Copyright (C) 2002 Ulrich Hilger
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.lightdev.app.shtm;
import java.awt.BorderLayout;
import java.awt.Container;
import java.awt.Dialog;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.ComponentAdapter;
import java.awt.event.ComponentEvent;
import java.awt.event.FocusAdapter;
import java.awt.event.FocusEvent;
import java.awt.event.KeyAdapter;
import java.awt.event.KeyEvent;
import java.io.File;
import java.io.StringWriter;
import java.util.Vector;
import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTextField;
import javax.swing.SwingConstants;
import javax.swing.border.EtchedBorder;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import javax.swing.text.AttributeSet;
import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import com.sun.demo.ExampleFileFilter;
/**
* A dialog providing an image repository and a way to edit display options
* for images from the repository.
*
* @author Ulrich Hilger
* @author Light Development
* @author http://www.lightdev.com
* @author info@lightdev.com
* @author published under the terms and conditions of the
* GNU General Public License,
* for details see file gpl.txt in the distribution
* package of this software
*
*
*/
class ImageDialog extends DialogShell implements ActionListener, ListSelectionListener, ChangeListener {
/** directory this ImageDialog maintains */
private File imgDir;
/** KeyListener for watching changes in the scale text field */
private final KeyHandler keyHandler = new KeyHandler();
/** FocusListener for watching changes in the scale text field */
private final FocusHandler focusHandler = new FocusHandler();
private final SimpleAttributeSet originalAttributes = new SimpleAttributeSet();
/**
* indicates whether or not changes in a SizeSelectorPanel are
* to be processed. Usually, changes caused by a method of this
* class are to be ignored
*/
private boolean ignoreChangeEvents = false;
/** list with images in this image repository */
private JList imgFileList;
/** button to add an image file to the repository */
private JButton addImgBtn;
/** button to delete an image file from the repository */
private JButton delImgBtn;
/** text field for manipulating the scale of an image */
private JTextField scale;
/** component to manipulate the image width */
private SizeSelectorPanel imgWidth;
/** component to manipulate the image height */
private SizeSelectorPanel imgHeight;
/** component to display the original width of an image */
private JLabel oWidth;
/** component to display the original height of an image */
private JLabel oHeight;
/** component to preview an image */
private ImagePreview preview;
/** component to scroll an image inside the preview */
private JScrollPane scPrev;
/**
* contains all components having attributes for the image represented
* in this ImageDialog
*/
private final Vector attributeComponents = new Vector();
/** the help id for this dialog */
private static final String helpTopicId = "item166";
/** the document the image came from, if any */
private SHTMLDocument doc;
/**
* construct a new ImageDialog
*
* @param parent the parent frame of this ImageDialog
* @param title the title of this ImageDialog
* @param imgDir the directory of the image repository
*/
public ImageDialog(final Dialog parent, final String title, final File imgDir) {
super(parent, title, helpTopicId);
initDialog(title, imgDir);
}
/**
* construct a new ImageDialog
*
* @param parent the parent frame of this ImageDialog
* @param title the title of this ImageDialog
* @param imgDir the directory of the image repository
*/
public ImageDialog(final Frame parent, final String title, final File imgDir) {
super(parent, title, helpTopicId);
initDialog(title, imgDir);
}
public ImageDialog(final Frame parent, final String title, final File imgDir, final SHTMLDocument sourceDoc) {
super(parent, title, helpTopicId);
doc = sourceDoc;
initDialog(title, imgDir);
}
/**
* build the dialog contents after construction
*
* @param title the title of this ImageDialog
* @param imgDir the directory of the image repository
*/
private void initDialog(final String title, final File imgDir) {
//System.out.println("ImageDialog.initDialog imgDir=" + imgDir.getAbsolutePath());
this.imgDir = imgDir;
Dimension dim;
// create an image directory panel
final JPanel dirPanel = new JPanel(new BorderLayout());
dirPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), Util
.getResourceString("imgDirPanelTitle")));
// create a list to disply image files in
imgFileList = new JList();
dim = new Dimension(100, 100);
imgFileList.setMinimumSize(dim);
imgFileList.setPreferredSize(dim);
imgFileList.addListSelectionListener(this);
updateFileList();
// create a panel with action buttons for image files
final JPanel dirBtnPanel = new JPanel();
// create image directory action buttons
addImgBtn = new JButton(Util.getResourceString("addImgBtnTitle"));
addImgBtn.addActionListener(this);
delImgBtn = new JButton(Util.getResourceString("delImgBtnTitle"));
delImgBtn.addActionListener(this);
// add action buttons to button panel
dirBtnPanel.add(addImgBtn);
dirBtnPanel.add(delImgBtn);
// add components to image directory panel
dirPanel.add(imgFileList, BorderLayout.CENTER);
dirPanel.add(dirBtnPanel, BorderLayout.SOUTH);
// create an image preview panel
final JPanel previewPanel = new JPanel(new BorderLayout());
previewPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), Util
.getResourceString("imgPreviewPanelTitle")));
// add a new ImagePreview object to the preview panel
preview = new ImagePreview();
dim = new Dimension(250, 250);
preview.setMinimumSize(dim);
preview.setPreferredSize(dim);
scPrev = new JScrollPane(preview);
previewPanel.add(scPrev, BorderLayout.CENTER);
// layout and constraints to use later on
final GridBagLayout g = new GridBagLayout();
final GridBagConstraints c = new GridBagConstraints();
// create an image properties panel
final JPanel eastPanel = new JPanel(new BorderLayout());
final JPanel propertiesPanel = new JPanel(g);
eastPanel.add(propertiesPanel, BorderLayout.NORTH);
eastPanel.setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), Util
.getResourceString("imgPropertiesPanelTitle")));
// add scale component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgScaleLabel")), g, c, 0, 0,
GridBagConstraints.EAST);
scale = new JTextField();
scale.addKeyListener(keyHandler);
scale.addFocusListener(focusHandler);
dim = new Dimension(50, 20);
scale.setMinimumSize(dim);
scale.setPreferredSize(dim);
final JPanel helperPanel = new JPanel();
helperPanel.add(scale);
helperPanel.add(new JLabel(SizeSelectorPanel.UNIT_PERCENT, SwingConstants.LEFT));
Util.addGridBagComponent(propertiesPanel, helperPanel, g, c, 1, 0, GridBagConstraints.WEST);
// add width component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgWidthLabel")), g, c, 0, 1,
GridBagConstraints.EAST);
imgWidth = new SizeSelectorPanel(HTML.Attribute.WIDTH, null, false, SizeSelectorPanel.TYPE_LABEL);
attributeComponents.addElement(imgWidth);
imgWidth.getValueSelector().addChangeListener(this);
Util.addGridBagComponent(propertiesPanel, imgWidth, g, c, 1, 1, GridBagConstraints.WEST);
// add height component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgHeightLabel")), g, c, 0, 2,
GridBagConstraints.EAST);
imgHeight = new SizeSelectorPanel(HTML.Attribute.HEIGHT, null, false, SizeSelectorPanel.TYPE_LABEL);
attributeComponents.addElement(imgHeight);
imgHeight.getValueSelector().addChangeListener(this);
Util.addGridBagComponent(propertiesPanel, imgHeight, g, c, 1, 2, GridBagConstraints.WEST);
// add hspace component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgHSpaceLabel")), g, c, 0, 3,
GridBagConstraints.EAST);
final SizeSelectorPanel hSpace = new SizeSelectorPanel(HTML.Attribute.HSPACE, null, false,
SizeSelectorPanel.TYPE_LABEL);
attributeComponents.addElement(hSpace);
Util.addGridBagComponent(propertiesPanel, hSpace, g, c, 1, 3, GridBagConstraints.WEST);
// add vspace component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgVSpaceLabel")), g, c, 0, 4,
GridBagConstraints.EAST);
final SizeSelectorPanel vSpace = new SizeSelectorPanel(HTML.Attribute.VSPACE, null, false,
SizeSelectorPanel.TYPE_LABEL);
attributeComponents.addElement(vSpace);
Util.addGridBagComponent(propertiesPanel, vSpace, g, c, 1, 4, GridBagConstraints.WEST);
// add alignment component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgAlignLabel")), g, c, 0, 5,
GridBagConstraints.EAST);
final String[] items = new String[] { Util.getResourceString("imgAlignTop"),
Util.getResourceString("imgAlignMiddle"), Util.getResourceString("imgAlignBottom"),
Util.getResourceString("imgAlignLeft"), Util.getResourceString("imgAlignCenter"),
Util.getResourceString("imgAlignRight") };
final String[] names = new String[] { "top", "middle", "bottom", "left", "center", "right" };
final AttributeComboBox imgAlign = new AttributeComboBox(items, names, null, HTML.Attribute.ALIGN);
attributeComponents.addElement(imgAlign);
Util.addGridBagComponent(propertiesPanel, imgAlign, g, c, 1, 5, GridBagConstraints.WEST);
// add original width component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("oWidthLabel")), g, c, 0, 6,
GridBagConstraints.EAST);
oWidth = new JLabel("");
Util.addGridBagComponent(propertiesPanel, oWidth, g, c, 1, 6, GridBagConstraints.WEST);
// add original height component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("oHeightLabel")), g, c, 0, 7,
GridBagConstraints.EAST);
oHeight = new JLabel("");
Util.addGridBagComponent(propertiesPanel, oHeight, g, c, 1, 7, GridBagConstraints.WEST);
// add border component
Util.addGridBagComponent(propertiesPanel, new JLabel(Util.getResourceString("imgBorderLabel")), g, c, 0, 8,
GridBagConstraints.EAST);
final SizeSelectorPanel imgBorder = new SizeSelectorPanel(HTML.Attribute.BORDER, null, false,
SizeSelectorPanel.TYPE_LABEL);
attributeComponents.addElement(imgBorder);
Util.addGridBagComponent(propertiesPanel, imgBorder, g, c, 1, 8, GridBagConstraints.WEST);
// add to content pane of DialogShell
final Container contentPane = super.getContentPane();
contentPane.add(dirPanel, BorderLayout.WEST);
contentPane.add(previewPanel, BorderLayout.CENTER);
contentPane.add(eastPanel, BorderLayout.EAST);
// cause optimal placement of all elements
pack();
scPrev.addComponentListener(new ResizeListener());
}
public Integer getImgWidth() {
return imgWidth.getIntValue();
}
public Integer getImgHeight() {
return imgHeight.getIntValue();
}
/**
* set dialog content from a given set of image attributes
*
* @param a the set of attributes to set dialog contents from
*/
public void setImageAttributes(final AttributeSet a) {
//System.out.println("ImageDialog.setImageAttributes");
ignoreChangeEvents = true;
originalAttributes.addAttributes(a);
if (a.isDefined(HTML.Attribute.SRC)) {
File imgFile = null;
if (doc != null) {
imgFile = new File(Util.resolveRelativePath(a.getAttribute(HTML.Attribute.SRC).toString(), doc
.getBase().getFile()));
}
else {
imgFile = new File(a.getAttribute(HTML.Attribute.SRC).toString());
}
//System.out.println("ImageDialog.setImageAttribute imgFile=" + imgFile.getAbsolutePath());
imgFileList.setSelectedValue(imgFile.getName().toLowerCase(), true);
}
for (int i = 0; i < attributeComponents.size(); i++) {
((AttributeComponent) attributeComponents.get(i)).setValue(a);
}
if (a.isDefined(HTML.Attribute.WIDTH)) {
preview.setPreviewWidth(Integer.parseInt(a.getAttribute(HTML.Attribute.WIDTH).toString()));
}
if (a.isDefined(HTML.Attribute.HEIGHT)) {
preview.setPreviewHeight(Integer.parseInt(a.getAttribute(HTML.Attribute.HEIGHT).toString()));
}
final int scalePct = preview.getScale();
scale.setText(Integer.toString(scalePct));
ignoreChangeEvents = false;
}
public void setImage(final String fName, final String w, final String h) {
//System.out.println("ImageDialog.setImage fName=" + fName);
imgFileList.setSelectedValue(new File(fName).getName(), true);
preview.setImage(new ImageIcon(fName));
try {
if (w != null && w.length() > 0) {
preview.setPreviewWidth(Integer.parseInt(w));
}
if (h != null && h.length() > 0) {
preview.setPreviewHeight(Integer.parseInt(h));
}
}
catch (final Exception e) {
Util.errMsg(this, null, e);
}
}
/**
* get the HTML representing the image selected in this
* ImageDialog
*/
public String getImageHTML() {
final SimpleAttributeSet set = new SimpleAttributeSet(originalAttributes);
final StringWriter sw = new StringWriter();
final SHTMLWriter w = new SHTMLWriter(sw, doc == null ? new HTMLDocument() : doc);
for (int i = 0; i < attributeComponents.size(); i++) {
set.addAttributes(((AttributeComponent) attributeComponents.get(i)).getValue());
}
set.addAttribute(HTML.Attribute.SRC, getImageSrc());
try {
w.writeStartTag(HTML.Tag.IMG.toString(), set);
}
catch (final Exception e) {
Util.errMsg(this, e.getMessage(), e);
}
return sw.getBuffer().toString();
}
/**
* get the value for the SRC attribute of an image tag
*
* @return the value of the SRC attribute of an image tag
*/
public String getImageSrc() {
final StringBuffer buf = new StringBuffer();
final Object value = imgFileList.getSelectedValue();
if (value != null) {
buf.append(SHTMLPanelImpl.IMAGE_DIR);
buf.append(Util.URL_SEPARATOR);
buf.append(value.toString());
}
return buf.toString();
}
/**
* handle the event when the user pressed the 'Add...' button
* to add a new image to the repository
*/
private void handleAddImage() {
try {
final JFileChooser chooser = new JFileChooser();
chooser.setMultiSelectionEnabled(true);
final ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("gif");
filter.addExtension("jpg");
filter.addExtension("jpeg");
filter.setDescription(Util.getResourceString("imageFileDesc"));
chooser.setFileFilter(filter);
if (chooser.showOpenDialog(this) == JFileChooser.APPROVE_OPTION) {
final File[] sFiles = chooser.getSelectedFiles();
if (!imgDir.exists()) {
imgDir.mkdirs();
}
final String imgDirName = imgDir.getAbsolutePath();
for (int i = 0; i < sFiles.length; i++) {
//System.out.println("file selected: " + sFiles[i] + " new name= " + imgDirName + File.separator + sFiles[i].getName());
Util.copyFile(sFiles[i], new File(imgDirName + File.separator + sFiles[i].getName()));
updateFileList();
}
}
}
catch (final Exception e) {
Util.errMsg(this, e.getMessage(), e);
}
}
/**
* handle the event occurring when the user pressed the 'Delete' button
* to remove an image from the repository
*/
private void handleDeleteImage() {
final String fName = imgFileList.getSelectedValue().toString();
if (Util.msg(JOptionPane.YES_NO_OPTION, "confirmDelete", "deleteFileQuery", fName, "\r\n")) {
final File delFile = new File(imgDir.getAbsolutePath() + File.separator + fName);
delFile.delete();
updateFileList();
}
}
/**
* display all files found in the image directory
*/
private void updateFileList() {
if (imgDir != null && imgFileList != null) {
final String[] files = imgDir.list();
if (files != null && files.length > 0) {
for (int i = 0; i < files.length; i++) {
files[i] = files[i].toLowerCase();
}
imgFileList.setListData(files);
}
}
}
/**
* update all image property displays to the current setting
*/
private void updateControls() {
ignoreChangeEvents = true;
final int scalePct = preview.getScale();
final SimpleAttributeSet set = new SimpleAttributeSet();
oWidth.setText(Integer.toString(preview.getOriginalWidth()));
oHeight.setText(Integer.toString(preview.getOriginalHeight()));
//System.out.println("updateControls origW=" + preview.getOriginalWidth());
//System.out.println("updateControls add WIDTH attr as " + Integer.toString(
// preview.getOriginalWidth() * scalePct / 100) + SizeSelectorPanel.UNIT_PT);
set.addAttribute(HTML.Attribute.WIDTH, Integer.toString(preview.getOriginalWidth() * scalePct / 100)
+ SizeSelectorPanel.UNIT_PT);
set.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(preview.getOriginalHeight() * scalePct / 100)
+ SizeSelectorPanel.UNIT_PT);
imgWidth.setValue(set);
imgHeight.setValue(set);
scale.setText(Integer.toString(scalePct));
ignoreChangeEvents = false;
}
/**
* apply a scale set by the user through respective text field and
* update all related image property displays
*/
private void applyPreviewScale() {
//System.out.println("applyPreviewScale scale=" + scale.getText());
ignoreChangeEvents = true;
try {
preview.setScale(Integer.parseInt(scale.getText()));
updateControls();
}
catch (final Exception e) {
}
ignoreChangeEvents = false;
}
/**
* apply a new width set by the user and update
* all related image property displays
*/
private void applyPreviewWidth() {
//System.out.println("applyPreviewWidth width=" + imgWidth.getIntValue().intValue());
ignoreChangeEvents = true;
preview.setPreviewWidth(imgWidth.getIntValue().intValue());
final int scalePct = preview.getScale();
//System.out.println("applyPreviewWidth scale now " + scalePct);
final SimpleAttributeSet set = new SimpleAttributeSet();
scale.setText(Integer.toString(scalePct));
set.addAttribute(HTML.Attribute.HEIGHT, Integer.toString(preview.getOriginalHeight() * scalePct / 100)
+ SizeSelectorPanel.UNIT_PT);
//System.out.println("applyPreviewWidth, changing height to " + Integer.toString(
// preview.getOriginalHeight() * scalePct / 100) + SizeSelectorPanel.UNIT_PT);
imgHeight.setValue(set);
ignoreChangeEvents = false;
}
/**
* apply a new height set by the user and update
* all related image property displays
*/
private void applyPreviewHeight() {
//System.out.println("applyPreviewHeight height=" + imgHeight.getIntValue().intValue());
ignoreChangeEvents = true;
preview.setPreviewHeight(imgHeight.getIntValue().intValue());
final int scalePct = preview.getScale();
//System.out.println("applyPreviewHeight scale now " + scalePct);
final SimpleAttributeSet set = new SimpleAttributeSet();
scale.setText(Integer.toString(scalePct));
set.addAttribute(HTML.Attribute.WIDTH, Integer.toString(preview.getOriginalWidth() * scalePct / 100)
+ SizeSelectorPanel.UNIT_PT);
//System.out.println("applyPreviewHeight, changing width to " + Integer.toString(
// preview.getOriginalWidth() * scalePct / 100) + SizeSelectorPanel.UNIT_PT);
imgWidth.setValue(set);
ignoreChangeEvents = false;
}
/* ---------------- event handling start ------------------------- */
/**
* implements the ActionListener interface to be notified of
* clicks onto the file repository buttons.
*/
public void actionPerformed(final ActionEvent e) {
final Object src = e.getSource();
if (src == addImgBtn) {
handleAddImage();
}
else if (src == delImgBtn) {
handleDeleteImage();
}
else {
super.actionPerformed(e);
}
}
/**
* Listener for changes in the image list.
*
* AttributeComponent
*
* @param a the set of attributes possibly having an
* attribute this component can display
*
* @return true, if the set of attributes had a matching attribute,
* false if not
*/
public boolean setValue(final AttributeSet a) {
final boolean success = true;
final Enumeration e = components.elements();
bWidth = new CombinedAttribute(CSS.Attribute.BORDER_WIDTH, a, true);
bColor = new CombinedAttribute(CSS.Attribute.BORDER_COLOR, a, true);
if (++setValueCalls < 2) {
oColor = bColor.getAttribute();
oWidth = bWidth.getAttribute();
}
while (e.hasMoreElements()) {
((BorderSettings) e.nextElement()).setValue(bWidth, bColor);
}
return success;
}
/**
* get the value of this AttributeComponent
*
* @return the value selected from this component
*/
public AttributeSet getValue() {
final SimpleAttributeSet set = new SimpleAttributeSet();
BorderSettings bs;
for (int i = 0; i < components.size(); i++) {
bs = (BorderSettings) components.elementAt(i);
bColor.setAttribute(i, bs.getBorderColor());
bWidth.setAttribute(i, bs.getBorderWidth());
}
String newValue = bColor.getAttribute();
newValue = bWidth.getAttribute(CombinedAttribute.ATTR_TOP);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_TOP_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_RIGHT_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_BOTTOM_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_LEFT_WIDTH, newValue);
return set;
}
public AttributeSet getValue(final boolean includeUnchanged) {
if (includeUnchanged) {
final SimpleAttributeSet set = new SimpleAttributeSet();
BorderSettings bs;
for (int i = 0; i < components.size(); i++) {
bs = (BorderSettings) components.elementAt(i);
bColor.setAttribute(i, bs.getBorderColor());
bWidth.setAttribute(i, bs.getBorderWidth());
}
String newValue = bColor.getAttribute();
newValue = bWidth.getAttribute(CombinedAttribute.ATTR_TOP);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_TOP_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_RIGHT_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_BOTTOM_WIDTH, newValue);
Util.styleSheet().addCSSAttribute(set, CSS.Attribute.BORDER_LEFT_WIDTH, newValue);
return set;
}
else {
return getValue();
}
}
/**
* Panel to show and manipulate border settings
*/
private class BorderSettings extends JPanel {
/** the border side */
private final int side;
/** selector for border width */
private final SizeSelectorPanel bWidth;
/** selector for border color */
private final ColorPanel bColor;
/**
* construct a BorderSettings panel
*
* @param title the title of this object
* @param borderKey the attribute key for the border width this
* object represents
* @param colorKey the attribute key for the border color this
* object represents
*/
public BorderSettings(final String title, final int side) {
super();
this.side = side;
// set layout
final GridBagLayout g = new GridBagLayout();
setLayout(g);
// constraints to use on our GridBagLayout
final GridBagConstraints c = new GridBagConstraints();
// set border and title
setBorder(new TitledBorder(new EtchedBorder(EtchedBorder.LOWERED), title));
// add the width control and label
Util.addGridBagComponent(this, new JLabel(Util.getResourceString("borderWidthLabel")), g, c, 0, 0,
GridBagConstraints.EAST);
bWidth = new SizeSelectorPanel(CSS.Attribute.BORDER_WIDTH, null, false, SizeSelectorPanel.TYPE_LABEL);
Util.addGridBagComponent(this, bWidth, g, c, 1, 0, GridBagConstraints.WEST);
// add the color control and label
Util.addGridBagComponent(this, new JLabel(Util.getResourceString("borderColorLabel")), g, c, 0, 1,
GridBagConstraints.EAST);
bColor = new ColorPanel(null, Color.black, CSS.Attribute.BORDER_COLOR);
Util.addGridBagComponent(this, bColor, g, c, 1, 1, GridBagConstraints.WEST);
}
public String getBorderColor() {
return bColor.getAttr();
}
public String getBorderWidth() {
return bWidth.getAttr();
}
/**
* set the value of this AttributeComponent
*
* @param color the CombinedAttribute to take the color from
*
*/
public void setValue(final CombinedAttribute borderWidths, final CombinedAttribute borderColors) {
String attr = borderColors.getAttribute(side);
//System.out.println("BorderSettings setValue attr='" + attr + "'");
if (attr != null) {
bColor.setValue(attr);
}
attr = borderWidths.getAttribute(side);
if (attr != null) {
bWidth.setValue(attr);
}
}
}
}
simplyhtml-0.17.3/src/com/lightdev/app/shtm/Remover.java 0100644 0000000 0000000 00000005171 12114157751 021733 0 ustar 00 0000000 0000000 package com.lightdev.app.shtm;
import java.util.Locale;
class Remover {
final private String searchedText;
private String searchedSubstring;
private int begin;
private int end;
private int removedCharacterNumber;
private String processedText;
public String getProcessedText() {
return processedText;
}
public Remover(String text) {
super();
this.processedText = text;
this.searchedText = text.toLowerCase(Locale.ENGLISH);
begin = end = removedCharacterNumber = 0;
}
public int getBegin() {
return begin;
}
public int getEnd() {
return end;
}
private String createSearchedSubstring(final String substring) {
return "<" + substring.toLowerCase(Locale.ENGLISH);
}
public boolean findFirst(){
begin = removedCharacterNumber;
return findNext();
}
public boolean findNext(){
begin = searchedText.indexOf(searchedSubstring, begin);
return findEndOfElement();
}
public boolean findLast(){
begin = searchedText.lastIndexOf(searchedSubstring);
return findEndOfElement();
}
private boolean findEndOfElement() {
if(begin == -1)
{
end = -1;
return false;
}
end = searchedText.indexOf('>', begin + searchedSubstring.length());
if(end == -1){
begin = -1;
return false;
}
end++;
return true;
}
public int getWhiteSpaceBefore(){
if(begin <= 0)
return begin;
for(int i = begin - 1; i > 0; i--){
if(! Character.isWhitespace(searchedText.charAt(i)))
return i + 1;
}
return 0;
}
public int getWhiteSpaceAfter(){
if(end == -1)
return -1;
for(int i = end + 1; i < searchedText.length(); i++){
if(! Character.isWhitespace(searchedText.charAt(i)))
return i;
}
return searchedText.length();
}
public Remover removeFirstAndBefore(String element){
searchedSubstring = createSearchedSubstring(element);
if(findFirst()){
final int lastIndex = getWhiteSpaceAfter() - removedCharacterNumber;
processedText = processedText.substring(lastIndex);
removedCharacterNumber += lastIndex;
}
return this;
}
public Remover removeLastAndAfter(String element){
searchedSubstring = createSearchedSubstring(element);
if(findLast()){
final int firstIndex = getWhiteSpaceBefore() - removedCharacterNumber;
processedText = processedText.substring(0, firstIndex);
}
return this;
}
static public void main(String[] argv){
String text = "\n\t 1 ";
final Remover removeFirstAndBefore = new Remover(text).removeFirstAndBefore("body");
String removeLastAndAfter = removeFirstAndBefore.removeLastAndAfter("/body").getProcessedText();
System.out.println ('"' + removeLastAndAfter + '"');
// assert removeLastAndAfter.equals("1");
}
}
simplyhtml-0.17.3/src/com/lightdev/app/shtm/DocumentPane.java 0100644 0000000 0000000 00000105263 12534067656 022713 0 ustar 00 0000000 0000000 /*
* SimplyHTML, a word processor based on Java, HTML and CSS
* Copyright (C) 2002 Ulrich Hilger
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
*/
package com.lightdev.app.shtm;
import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.EventQueue;
import java.awt.Font;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Enumeration;
import java.util.EventObject;
import java.util.Vector;
import javax.swing.JComponent;
import javax.swing.JEditorPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTabbedPane;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import javax.swing.text.Document;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.StyleSheet;
import com.sun.demo.ExampleFileFilter;
/**
* GUI representation of a document.
*
*
* Document - the model implementation
* EditorKit - the controller implementationDocumentPane wraps all those elements to implement a single
* document centric external view to all elements.DocumentPane.
*
* JEditorPane of this DocumentPane
*
* @return the JEditorPane of this DocumentPane
*/
public SHTMLEditorPane getEditor() {
return editorPane;
}
/**
* get the SyntaxPane of this DocumentPane
*
* @return the SyntaxPane of this DocumentPane
*/
public SyntaxPane getHtmlEditor() {
return sourceEditorPane;
}
/**
* @return the selected tab index
*/
public int getSelectedTab() {
if (paneHoldingScrollPanes instanceof JTabbedPane) {
return ((JTabbedPane) paneHoldingScrollPanes).getSelectedIndex();
}
return activeView;
}
/**
* create a new HTMLDocument and attach it to the editor
*/
public void createNewDocument() {
try {
final SHTMLEditorKit kit = (SHTMLEditorKit) editorPane.getEditorKit();
final SHTMLDocument doc = (SHTMLDocument) kit.createDefaultDocument();
//insertStyleRef(doc); // create style sheet reference in HTML header tag
//styles = kit.getStyleSheet();
doc.addDocumentListener(this); // listen to changes
doc.setBase(createTempDir());
editorPane.setDocument(doc); // let the document be edited in our editor
//doc.putProperty(Document.TitleProperty, getDocumentName());
final boolean useStyle = Util.useSteStyleSheet();
if (useStyle) {
doc.insertStyleRef();
}
}
catch (final Exception e) {
Util.errMsg(this, e.getMessage(), e);
}
}
public void setDocument(final Document docToSet) {
try {
editorPane.getEditorKit();
final HTMLDocument doc = (HTMLDocument) getDocument();
if (doc != null) {
doc.removeDocumentListener(this);
}
docToSet.addDocumentListener(this); // listen to changes
editorPane.setDocument(docToSet); // let the document be edited in our editor
}
catch (final Exception e) {
Util.errMsg(this, e.getMessage(), e);
}
}
/**
* create temporary directory for a newly created document
* so that images can be stored and referenced until the document
* is saved.
*
* @return URL of created temporary document directoy
*/
private URL createTempDir() throws MalformedURLException {
docTempDir = new File(SHTMLPanelImpl.getAppTempDir().getAbsolutePath() + File.separator + getDocumentName()
+ File.separator);
return docTempDir.toURI().toURL();
}
/**
* remove the temporary storage created for this DocumentPane
*/
public void deleteTempDir() {
if (docTempDir != null) {
Util.deleteDir(docTempDir);
docTempDir = null;
}
}
/**
* load a document found at a certain URL.
*
* @param url the URL to look for the document
*/
public void loadDocument(final URL url) {
try {
final SHTMLEditorKit kit = (SHTMLEditorKit) editorPane.getEditorKit();
final SHTMLDocument doc = (SHTMLDocument) kit.createEmptyDocument();
doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
doc.setBase(new File(url.getPath()).getParentFile().toURI().toURL()); // set the doc base
final InputStream in = url.openStream(); // get an input stream
kit.read(in, doc, 0); // ..and read the document contents from it
in.close(); // .. then properly close the stream
doc.addDocumentListener(this); // listen to changes
editorPane.setDocument(doc); // let the document be edited in our editor
setSource(url); // remember where the document came from
loadedFromFile = true;
}
catch (final Exception ex) {
Util.errMsg(this, "An exception occurred while loading the file", ex);
ex.printStackTrace();
}
}
/**
* load the rules from a given style sheet file into a new StyleSheet object.
*
* @param cssFile the file object referring to the style sheet to load from
*
* @return the style sheet with rules loaded
*/
private StyleSheet loadStyleSheet(final File cssFile) throws MalformedURLException, IOException {
final StyleSheet s = new StyleSheet();
s.importStyleSheet(cssFile.toURI().toURL());
return s;
}
/**
* saves the document to the file specified in the source of the
* DocumentPane and creates the associated style sheet.
*
* The actual save process only is done, when there is a name to save
* to. The class(es) calling this method have to make sure that a
* name for new documents is requested from the user, for instance.
*
* The desired name and location for the save need then to be set using method
* setSource prior to a call to this method
*
* @throws DocNameMissingException to ensure the caller gets notified
* that a save did not take place because of a missing name
* and location
*/
public void saveDocument() throws DocNameMissingException {
if (!saveInProgress()) {
saveThread = Thread.currentThread(); // store thread for saveInProgress
saveSuccessful = false; // if something goes wrong, this remains false
File file = null;
try {
if (sourceUrl != null) {
/* write the HTML document */
if (getSelectedTab() == VIEW_TAB_HTML) {
editorPane.setText(sourceEditorPane.getText());
}
final SHTMLDocument doc = (SHTMLDocument) getDocument();
final OutputStream os = new FileOutputStream(sourceUrl.getPath());
final OutputStreamWriter osw = new OutputStreamWriter(os);
final SHTMLWriter hw = new SHTMLWriter(osw, doc);
hw.write();
osw.flush();
osw.close();
os.flush();
os.close();
/* write the style sheet */
if (doc.hasStyleRef()) {
saveStyleSheet();
}
/*
copy image directory,
if new document or saved from different location
*/
saveImages();
/* clean up */
//System.out.println("DocumentPane textChanged = false");
setDocumentChanged(false); // indicate no changes pending anymore after the save
file = new File(sourceUrl.getPath()).getParentFile();
((HTMLDocument) getDocument()).setBase(file.toURI().toURL()); // set the doc base
deleteTempDir();
//System.out.println("DocumentPane saveSuccessful = true");
saveSuccessful = true; // signal that saving was successful
}
else {
saveThread = null;
throw new DocNameMissingException();
}
}
catch (final MalformedURLException mue) {
if (file != null) {
Util.errMsg(this, "Can not create a valid URL for\n" + file.getAbsolutePath(), mue);
}
else {
Util.errMsg(this, mue.getMessage(), mue);
}
}
catch (final Exception e) {
if (savedUrl != null) {
sourceUrl = savedUrl;
}
Util.errMsg(this, "An exception occurred while saving the file", e);
}
saveThread = null;
savedUrl = sourceUrl;
}
}
/**
* determine the directory this DocumentPane references image
* files from
*
* @return the directory image files referenced by this
* DocumentPane are found
*/
public File getImageDir() {
File srcDir = null;
if (savedUrl == null && newDocNo > 0) {
// new Document: use temp dir as source
srcDir = new File(docTempDir + File.separator + SHTMLPanelImpl.IMAGE_DIR + File.separator);
}
else {
if (savedUrl == null) {
// document has been saved before: source is 'sourceUrl'
srcDir = new File(new File(sourceUrl.getPath()).getParent() + File.separator + SHTMLPanelImpl.IMAGE_DIR
+ File.separator);
}
else {
/*
document has been saved before but now is
to be saved under new name: source is 'old' url
*/
srcDir = new File(new File(savedUrl.getPath()).getParent() + File.separator + SHTMLPanelImpl.IMAGE_DIR
+ File.separator);
}
}
return srcDir;
}
/**
* save image files
*/
private void saveImages() {
final File srcDir = getImageDir();
final File destDir = new File(new File(sourceUrl.getPath()).getParent() + File.separator
+ SHTMLPanelImpl.IMAGE_DIR + File.separator);
try {
if (srcDir.exists()) {
final ExampleFileFilter filter = new ExampleFileFilter();
filter.addExtension("gif");
filter.addExtension("jpg");
filter.addExtension("jpeg");
final File[] imgFiles = srcDir.listFiles();
for (int i = 0; i < imgFiles.length; i++) {
Util.copyFile(imgFiles[i],
new File(destDir.getAbsolutePath() + File.separator + imgFiles[i].getName()));
}
}
}
catch (final Exception e) {
Util.errMsg(this, e.getMessage(), e);
}
}
/**
* indicates whether or not a save process is in progress
*
* @return true, if a save process is going on, else false
*/
public boolean saveInProgress() {
//System.out.println("DocumentPane.saveInProgress=" + (saveThread != null) + " for document " + getDocumentName());
return saveThread != null;
}
/**
* Saves the style sheet of this document to a CSS file.
*
*
*
This is only to be used when it is made sure, * that the document is saved at the location specified * by 'source'.
* * @param the URL of the source this document is to be loaded from */ public void setSource(final URL source) { savedUrl = sourceUrl; sourceUrl = source; final String fName = source.getFile(); docName = fName.substring(fName.lastIndexOf("/") + 1); fireNameChanged(); } /** * get the source, this document was having before its current sourceUrl * was set. * * @return the source URL before a name change */ public URL getOldSource() { if (savedUrl == null) { return sourceUrl; } else { return savedUrl; } } /** * get the source this document can be loaded from * * @return the URL this document can be loaded from */ public URL getSource() { return sourceUrl; } /** * indicates whether or not this document was newly created and not saved so * far. * * @return true, if this is a new document that has not been saved so far */ public boolean isNewDoc() { return sourceUrl == null; } /** * get the document of thisDocumentPane
*
* @return the Document of this DocumentPane
*/
public Document getDocument() {
return editorPane.getDocument();
}
HTMLDocument getHTMLDocument() {
return (HTMLDocument) sourceEditorPane.getDocument();
}
/**
* Switches between the rich text view and the source view, given
* tabbed panes are not used. Has no corresponding action; calling
* this method is up to the caller application of SimplyHTML; the
* application should call the method of the same name available at
* SHTMLPanel.
*/
public void switchViews() {
if (paneHoldingScrollPanes instanceof JTabbedPane) {
return;
}
// [ Tabbed pane not used ]
if (activeView == VIEW_TAB_LAYOUT) {
setHTMLView();
paneHoldingScrollPanes.remove(richViewScrollPane);
paneHoldingScrollPanes.add(sourceViewScrollPane);
activeView = VIEW_TAB_HTML;
}
else {
setLayoutView();
paneHoldingScrollPanes.remove(sourceViewScrollPane);
paneHoldingScrollPanes.add(richViewScrollPane);
activeView = VIEW_TAB_LAYOUT;
}
}
/**
* Switches the DocumentPane to HTML view.
*/
private void setHTMLView() {
try {
editorPane.getDocument().removeDocumentListener(this);
final StringWriter stringWriter = new StringWriter();
if (isHtmlChanged()) {
editorPane.getEditorKit().write(stringWriter, editorPane.getDocument(), 0,
editorPane.getDocument().getLength());
stringWriter.close();
String newText = stringWriter.toString();
if (!Util.preferenceIsTrue("writeHead", "true")) {
newText = newText.replaceAll("(?ims).*?(