ICU-6448 Moving ICU4J richedit to icuapps.
X-SVN-Rev: 26122
This commit is contained in:
parent
07b0822b13
commit
fb6a056259
2
.gitattributes
vendored
2
.gitattributes
vendored
@ -253,8 +253,6 @@ icu4j/perf-tests/data/collation/TestNames_SerbianSH.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_SerbianSR.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Simplified_Chinese.txt -text
|
||||
icu4j/perf-tests/data/collation/TestNames_Thai.txt -text
|
||||
icu4j/richedit/classes/src/com/ibm/richtext/textapps/resources/unicode.arabic.red -text
|
||||
icu4j/richedit/classes/src/com/ibm/richtext/textapps/resources/unicode.hebrew.red -text
|
||||
icu4j/tools/build/icu4j28.api.gz -text
|
||||
icu4j/tools/build/icu4j30.api.gz -text
|
||||
icu4j/tools/build/icu4j32.api.gz -text
|
||||
|
@ -1,18 +0,0 @@
|
||||
#*******************************************************************************
|
||||
#* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
#* others. All Rights Reserved. *
|
||||
#*******************************************************************************
|
||||
|
||||
icu4j.core.jar = <icu4j core jar file path>
|
||||
icu4j.test-framework.jar = <icu4j test framework jar file path>
|
||||
icu4j.license.html = <icu4j license HTML file>
|
||||
|
||||
javac.source = 1.3
|
||||
javac.target = 1.3
|
||||
javac.debug = on
|
||||
javac.deprecation = off
|
||||
javac.encoding = ascii
|
||||
|
||||
jar.spec.version = 2.6
|
||||
jar.impl.version = 2.6
|
||||
jar.copyright.info = Copyright 2000-2009, International Business Machines Corporation and others. All Rights Reserved.
|
@ -1,111 +0,0 @@
|
||||
<!--
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2009, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
-->
|
||||
<project name="richedit" default="jar" basedir=".">
|
||||
<property file="build-local.properties"/>
|
||||
<property file="build.properties"/>
|
||||
|
||||
<target name="clean" description="Clean up the build outputs">
|
||||
<delete dir="out"/>
|
||||
<delete dir="classes/out"/>
|
||||
<delete dir="tests/out"/>
|
||||
<delete dir="doc"/>
|
||||
</target>
|
||||
|
||||
<target name="compile" description="Compile ICU richedit java files">
|
||||
<path id="cpref.richedit.classes"/>
|
||||
<antcall target="_do-compile">
|
||||
<param name="comp.dir" value="classes"/>
|
||||
<reference refid="cpref.richedit.classes" torefid="javac.cpref"/>
|
||||
</antcall>
|
||||
|
||||
<path id="cpref.richedit.tests">
|
||||
<pathelement location="${icu4j.core.jar}"/>
|
||||
<pathelement location="${icu4j.test-framework.jar}"/>
|
||||
<pathelement path="classes/out/bin"/>
|
||||
</path>
|
||||
<antcall target="_do-compile">
|
||||
<param name="comp.dir" value="tests"/>
|
||||
<reference refid="cpref.richedit.tests" torefid="javac.cpref"/>
|
||||
</antcall>
|
||||
|
||||
</target>
|
||||
|
||||
<target name="_do-compile">
|
||||
<echo message="${toString:javac.cpref}"/>
|
||||
<mkdir dir="${comp.dir}/out/bin"/>
|
||||
<javac srcdir="${comp.dir}/src"
|
||||
destdir="${comp.dir}/out/bin"
|
||||
classpathref="javac.cpref"
|
||||
source="${javac.source}"
|
||||
target="${javac.target}"
|
||||
debug="${javac.debug}"
|
||||
deprecation="${javac.deprecation}"
|
||||
encoding="${javac.encoding}"/>
|
||||
</target>
|
||||
|
||||
<target name="jar" depends="compile" description="Create ICU richedit runtime jar file">
|
||||
<copy todir="classes/out/bin/com/ibm/richtext/textapps/resources">
|
||||
<fileset dir="classes/src/com/ibm/richtext/textapps/resources" includes="*.red"/>
|
||||
</copy>
|
||||
|
||||
<copy file="classes/manifest.stub" todir="classes/out">
|
||||
<filterset>
|
||||
<filter token="SPECVERSION" value="${jar.spec.version}"/>
|
||||
<filter token="IMPLVERSION" value="${jar.impl.version}"/>
|
||||
<filter token="COPYRIGHT" value="${jar.copyright.info}"/>
|
||||
</filterset>
|
||||
</copy>
|
||||
|
||||
<mkdir dir="out"/>
|
||||
<jar jarfile="out/richedit.jar"
|
||||
compress="true"
|
||||
basedir="classes/out/bin"
|
||||
manifest="classes/out/manifest.stub"/>
|
||||
</target>
|
||||
|
||||
<target name="docs" description="Generate ICU richedit javadoc">
|
||||
<mkdir dir="doc"/>
|
||||
<javadoc destdir="doc"
|
||||
nodeprecatedlist="true"
|
||||
windowtitle="RichEdit Control"
|
||||
doctitle="RichEdit Control"
|
||||
encoding="iso-8859-1"
|
||||
bottom="<font size=-1>Copyright (c) 1998-2009 IBM Corporation and others.</font>"
|
||||
source="1.3">
|
||||
<packageset dir="classes/src">
|
||||
<include name="com/ibm/richtext/demo"/>
|
||||
<include name="com/ibm/richtext/awtui"/>
|
||||
<include name="com/ibm/richtext/swingui"/>
|
||||
<include name="com/ibm/richtext/textpanel"/>
|
||||
<include name="com/ibm/richtext/styledtext"/>
|
||||
<include name="com/ibm/richtext/textlayout/attributes"/>
|
||||
<include name="com/ibm/richtext/print"/>
|
||||
</packageset>
|
||||
</javadoc>
|
||||
</target>
|
||||
|
||||
<target name="dist-zip" depends="jar, docs" description="Create ICU richedit zip file for distribution">
|
||||
<copy file="${icu4j.license.html}" tofile="out/license.html"/>
|
||||
<zip zipfile="out/richedit.zip">
|
||||
<fileset dir="out" includes="richedit.jar,license.html"/>
|
||||
<fileset dir="." includes="doc/**/*"/>
|
||||
</zip>
|
||||
</target>
|
||||
|
||||
<target name="check" depends="jar" description="Run the ICU richedit test suite">
|
||||
<java classname="com.ibm.richtext.test.unit.TestAll" fork="yes" failonerror="true">
|
||||
<arg line="-n"/>
|
||||
<classpath>
|
||||
<pathelement location="${icu4j.core.jar}"/>
|
||||
<pathelement location="${icu4j.test-framework.jar}"/>
|
||||
<pathelement location="out/richedit.jar"/>
|
||||
<pathelement path="tests/out/bin"/>
|
||||
</classpath>
|
||||
</java>
|
||||
</target>
|
||||
|
||||
</project>
|
@ -1,7 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<classpath>
|
||||
<classpathentry kind="src" path="src"/>
|
||||
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/J2SE-1.5"/>
|
||||
<classpathentry combineaccessrules="false" kind="src" path="/icu4j-core"/>
|
||||
<classpathentry kind="output" path="out/bin"/>
|
||||
</classpath>
|
@ -1,17 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<projectDescription>
|
||||
<name>icu4j-richedit</name>
|
||||
<comment></comment>
|
||||
<projects>
|
||||
</projects>
|
||||
<buildSpec>
|
||||
<buildCommand>
|
||||
<name>org.eclipse.jdt.core.javabuilder</name>
|
||||
<arguments>
|
||||
</arguments>
|
||||
</buildCommand>
|
||||
</buildSpec>
|
||||
<natures>
|
||||
<nature>org.eclipse.jdt.core.javanature</nature>
|
||||
</natures>
|
||||
</projectDescription>
|
@ -1,326 +0,0 @@
|
||||
#Tue Jun 09 16:57:43 EDT 2009
|
||||
eclipse.preferences.version=1
|
||||
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
|
||||
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
|
||||
org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
|
||||
org.eclipse.jdt.core.compiler.compliance=1.5
|
||||
org.eclipse.jdt.core.compiler.debug.lineNumber=generate
|
||||
org.eclipse.jdt.core.compiler.debug.localVariable=generate
|
||||
org.eclipse.jdt.core.compiler.debug.sourceFile=generate
|
||||
org.eclipse.jdt.core.compiler.problem.annotationSuperInterface=warning
|
||||
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.autoboxing=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.deprecation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationInDeprecatedCode=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.deprecationWhenOverridingDeprecatedMethod=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.discouragedReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.emptyStatement=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
|
||||
org.eclipse.jdt.core.compiler.problem.fallthroughCase=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.fatalOptionalError=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.fieldHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finalParameterBound=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.finallyBlockNotCompletingNormally=warning
|
||||
org.eclipse.jdt.core.compiler.problem.forbiddenReference=error
|
||||
org.eclipse.jdt.core.compiler.problem.hiddenCatchBlock=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompatibleNonInheritedInterfaceMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.incompleteEnumSwitch=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.indirectStaticAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.localVariableHiding=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.methodWithConstructorName=warning
|
||||
org.eclipse.jdt.core.compiler.problem.missingDeprecatedAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingOverrideAnnotation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.missingSerialVersion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noEffectAssignment=warning
|
||||
org.eclipse.jdt.core.compiler.problem.noImplicitStringConversion=warning
|
||||
org.eclipse.jdt.core.compiler.problem.nonExternalizedStringLiteral=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.nullReference=warning
|
||||
org.eclipse.jdt.core.compiler.problem.overridingPackageDefaultMethod=warning
|
||||
org.eclipse.jdt.core.compiler.problem.parameterAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.possibleAccidentalBooleanAssignment=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.potentialNullReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.rawTypeReference=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantNullCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.redundantSuperinterface=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.specialParameterHidingField=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.staticAccessReceiver=warning
|
||||
org.eclipse.jdt.core.compiler.problem.suppressWarnings=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.syntheticAccessEmulation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.typeParameterHiding=warning
|
||||
org.eclipse.jdt.core.compiler.problem.uncheckedTypeOperation=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.undocumentedEmptyBlock=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unhandledWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryElse=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unnecessaryTypeCheck=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unqualifiedFieldAccess=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownException=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionExemptExceptionAndThrowable=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedDeclaredThrownExceptionWhenOverriding=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedImport=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLabel=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedLocal=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameter=ignore
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterIncludeDocCommentReference=enabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenImplementingAbstract=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedParameterWhenOverridingConcrete=disabled
|
||||
org.eclipse.jdt.core.compiler.problem.unusedPrivateMember=warning
|
||||
org.eclipse.jdt.core.compiler.problem.unusedWarningToken=warning
|
||||
org.eclipse.jdt.core.compiler.problem.varargsArgumentNeedCast=warning
|
||||
org.eclipse.jdt.core.compiler.source=1.5
|
||||
org.eclipse.jdt.core.formatter.align_type_members_on_columns=false
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_enum_constant=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_explicit_constructor_call=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_arguments_in_qualified_allocation_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_assignment=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_binary_expression=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_compact_if=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_conditional_expression=80
|
||||
org.eclipse.jdt.core.formatter.alignment_for_enum_constants=0
|
||||
org.eclipse.jdt.core.formatter.alignment_for_expressions_in_array_initializer=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_multiple_fields=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_parameters_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_selector_in_method_invocation=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superclass_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_enum_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_superinterfaces_in_type_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_constructor_declaration=16
|
||||
org.eclipse.jdt.core.formatter.alignment_for_throws_clause_in_method_declaration=16
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_after_package=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_field=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_first_class_body_declaration=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_imports=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_member_type=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_method=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_new_chunk=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_before_package=0
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_import_groups=1
|
||||
org.eclipse.jdt.core.formatter.blank_lines_between_type_declarations=1
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_annotation_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_anonymous_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_array_initializer=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_block_in_case=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_constructor_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_constant=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_enum_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_method_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_switch=end_of_line
|
||||
org.eclipse.jdt.core.formatter.brace_position_for_type_declaration=end_of_line
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_block_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.clear_blank_lines_in_javadoc_comment=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_block_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_header=false
|
||||
org.eclipse.jdt.core.formatter.comment.format_html=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_javadoc_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_line_comments=true
|
||||
org.eclipse.jdt.core.formatter.comment.format_source_code=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_parameter_description=true
|
||||
org.eclipse.jdt.core.formatter.comment.indent_root_tags=true
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_before_root_tags=insert
|
||||
org.eclipse.jdt.core.formatter.comment.insert_new_line_for_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.comment.line_length=120
|
||||
org.eclipse.jdt.core.formatter.compact_else_if=true
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation=2
|
||||
org.eclipse.jdt.core.formatter.continuation_indentation_for_array_initializer=2
|
||||
org.eclipse.jdt.core.formatter.format_guardian_clause_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_annotation_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_constant_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_enum_declaration_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_body_declarations_compare_to_type_header=true
|
||||
org.eclipse.jdt.core.formatter.indent_breaks_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_empty_lines=false
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_block=true
|
||||
org.eclipse.jdt.core.formatter.indent_statements_compare_to_body=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_cases=true
|
||||
org.eclipse.jdt.core.formatter.indent_switchstatements_compare_to_switch=false
|
||||
org.eclipse.jdt.core.formatter.indentation.size=4
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_local_variable=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_member=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_annotation_on_parameter=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_after_opening_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_at_end_of_file_if_missing=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_catch_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_closing_brace_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_else_in_if_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_finally_in_try_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_before_while_in_do_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_annotation_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_method_body=insert
|
||||
org.eclipse.jdt.core.formatter.insert_new_line_in_empty_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_at_in_annotation_type_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_angle_bracket_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_closing_paren_in_cast=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_case=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_colon_in_labeled_statement=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_allocation_expression=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_annotation=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_constructor_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_constant_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_enum_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_explicitconstructorcall_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_increments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_for_inits=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_declaration_throws=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_method_invocation_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_field_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_multiple_local_declarations=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_parameterized_type_reference=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_superinterfaces=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_arguments=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_comma_in_type_parameters=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_ellipsis=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_opening_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_semicolon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_after_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_and_in_type_parameter=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_assignment_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_at_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_binary_operator=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_cast=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_catch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_if=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_switch=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_synchronized=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_closing_paren_in_while=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_assert=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_case=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_default=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_colon_in_labeled_statement=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_constructor_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_constant_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_enum_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_explicitconstructorcall_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_increments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_for_inits=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_declaration_throws=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_method_invocation_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_field_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_multiple_local_declarations=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_superinterfaces=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_comma_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_ellipsis=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_parameterized_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_arguments=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_angle_bracket_in_type_parameters=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_annotation_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_anonymous_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_array_initializer=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_block=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_constructor_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_constant=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_enum_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_method_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_brace_in_type_declaration=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_bracket_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_catch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_for=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_if=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_parenthesized_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_switch=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_synchronized=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_opening_paren_in_while=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_return=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_parenthesized_expression_in_throw=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_postfix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_prefix_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_conditional=insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_question_in_wildcard=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_semicolon_in_for=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_before_unary_operator=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_brackets_in_array_type_reference=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_braces_in_array_initializer=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_brackets_in_array_allocation_expression=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_annotation_type_member_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_constructor_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_enum_constant=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_declaration=do not insert
|
||||
org.eclipse.jdt.core.formatter.insert_space_between_empty_parens_in_method_invocation=do not insert
|
||||
org.eclipse.jdt.core.formatter.keep_else_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_empty_array_initializer_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_imple_if_on_one_line=false
|
||||
org.eclipse.jdt.core.formatter.keep_then_statement_on_same_line=false
|
||||
org.eclipse.jdt.core.formatter.lineSplit=120
|
||||
org.eclipse.jdt.core.formatter.never_indent_block_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.never_indent_line_comments_on_first_column=false
|
||||
org.eclipse.jdt.core.formatter.number_of_blank_lines_at_beginning_of_method_body=0
|
||||
org.eclipse.jdt.core.formatter.number_of_empty_lines_to_preserve=1
|
||||
org.eclipse.jdt.core.formatter.put_empty_statement_on_new_line=true
|
||||
org.eclipse.jdt.core.formatter.tabulation.char=space
|
||||
org.eclipse.jdt.core.formatter.tabulation.size=4
|
||||
org.eclipse.jdt.core.formatter.use_tabs_only_for_leading_indentations=false
|
||||
org.eclipse.jdt.core.formatter.wrap_before_binary_operator=true
|
File diff suppressed because one or more lines are too long
@ -1,13 +0,0 @@
|
||||
Manifest-Version: 1.0
|
||||
Main-Class: com.ibm.richtext.demo.EditDemo
|
||||
|
||||
Name: com/ibm/richtext
|
||||
Specification-Title: ICU for Java RichEdit
|
||||
Specification-Version: @SPECVERSION@
|
||||
Specification-Vendor: ICU
|
||||
Implementation-Title: ICU for Java RichEdit
|
||||
Implementation-Version: @IMPLVERSION@
|
||||
Implementation-Vendor: IBM Corporation
|
||||
Implementation-Vendor-Id: com.ibm
|
||||
Copyright-Info: @COPYRIGHT@
|
||||
|
@ -1,236 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Window;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
|
||||
import com.ibm.richtext.uiimpl.*;
|
||||
import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
|
||||
|
||||
// TO DO: Don't hard-code menu configurations. Instead, specify them with
|
||||
// strings somehow. This is an improvement over what we had, and it'll do
|
||||
// for now.
|
||||
|
||||
/**
|
||||
* AwtMenuBuilder creates a set of AWT menus for interacting
|
||||
* with an MTextPanel. Future versions of this class may allow
|
||||
* clients to control the menu contents.
|
||||
* @see MTextPanel
|
||||
*/
|
||||
public final class AwtMenuBuilder extends MenuBuilder {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final AwtMenuBuilder INSTANCE = new AwtMenuBuilder();
|
||||
|
||||
/**
|
||||
* Id for an Edit menu. The Edit menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Undo</b> - invoke undo() on the MTextPanel</li>
|
||||
* <li><b>Redo</b> - invoke redo() on the MTextPanel</li>
|
||||
* <li><b>Cut</b> - invoke cut() on the MTextPanel</li>
|
||||
* <li><b>Copy</b> - invoke copy() on the MTextPanel</li>
|
||||
* <li><b>Paste</b> - invoke paste() on the MTextPanel</li>
|
||||
* <li><b>Clear</b> - invoke clear() on the MTextPanel</li>
|
||||
* <li><b>Select All</b> - invoke selectAll() on the MTextPanel</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int EDIT = MenuBuilder.EDIT;
|
||||
/**
|
||||
* Id for the point sizes menu. The menu has items that set the size of a character
|
||||
* in a typeface.
|
||||
*/
|
||||
public static final int SIZE = MenuBuilder.SIZE;
|
||||
/**
|
||||
* Id for a Style menu. The Style menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Plain</b> - remove <code>WEIGHT</code>,
|
||||
* <code>POSTURE</code>,
|
||||
* <code>UNDERLINE</code> and
|
||||
* <code>STRIKETHROUGH</code> attributes from the
|
||||
* current selection</li>
|
||||
* <li><b>Bold</b> - add <code>{WEIGHT,WEIGHT_BOLD}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Italic</b> - add <code>{POSTURE,POSTURE_ITALIC}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Underline</b> - add <code>{UNDERLINE,UNDERLINE_ON}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Strikethrough</b> - add <code>{STRIKETHROUGH,STRIKETHROUGH_ON}</code>
|
||||
* to the current selection</li>
|
||||
* <li><b>Font...</b> - display a dialog allowing the user to
|
||||
* select a typeface (font family) for the current selection</li>
|
||||
* <li><b>Forecolor...</b> - display a dialog allowing the user to
|
||||
* select a foreground color for the current selection</li>
|
||||
* <li><b>Backcolor...</b> - display a dialog allowing the user to
|
||||
* select a background color for the current selection</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int STYLE = MenuBuilder.STYLE;
|
||||
/**
|
||||
* Id for a paragraph alignment menu. The menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Leading</b> - give selected paragraph(s) LEADING flush</li>
|
||||
* <li><b>Center</b> - give selected paragraph(s) CENTER flush</li>
|
||||
* <li><b>Trailing</b> - give selected paragraph(s) TRAILING flush</li>
|
||||
* <li><b>Justified</b> - give selected paragraph(s) full justification</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int FLUSH = MenuBuilder.FLUSH;
|
||||
/**
|
||||
* Id for a menu that sets the KeyRemap
|
||||
* on an MTextPanel. The menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Default</b> - set KeyRemap to identity remap</li>
|
||||
* <li><b>Arabic</b> - set KeyRemap to Arabic transliteration</li>
|
||||
* <li><b>Hebrew</b> - set KeyRemap to Hebrew transliteration</li>
|
||||
* <li><b>Israel Nikud</b> - set KeyRemap to Israel Nikud</li>
|
||||
* <li><b>Thai Ketmanee</b> - set KeyRemap to Thai Ketmanee</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int KEYMAP = MenuBuilder.KEYMAP;
|
||||
/**
|
||||
* Id for a menu that sets
|
||||
* the primary run direction for a paragraph. Run direction can be left-to-right,
|
||||
* right-to-left, or can use the default run direction from the Unicode bidi algorithm.
|
||||
*/
|
||||
public static final int BIDI = MenuBuilder.BIDI;
|
||||
/**
|
||||
* Id for a menu with an <b>About</b> item. When selected,
|
||||
* the item displays a Frame containing some
|
||||
* self-promotional text.
|
||||
*/
|
||||
public static final int ABOUT = MenuBuilder.ABOUT;
|
||||
|
||||
/**
|
||||
* Return an instance of AwtMenuBuilder.
|
||||
*/
|
||||
public static AwtMenuBuilder getInstance() {
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private MenuBar fMenuBar;
|
||||
|
||||
private AwtMenuBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a standard set of menus to the given menu bar. The menus
|
||||
* will interact with the given MTextPanel.
|
||||
* @param menuBar the MenuBar to which menus are added
|
||||
* @param textPanel the MTextPanel with which the menus interact
|
||||
* @param frame a Frame to use as the parent of any dialogs created by a
|
||||
* a menu item. If null, menu items which create dialogs will be omitted.
|
||||
*/
|
||||
public void createMenus(MenuBar menuBar,
|
||||
MTextPanel textPanel,
|
||||
Frame frame) {
|
||||
|
||||
createMenus(menuBar, textPanel, frame, defaultMenus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of menus to the given menu bar. The menus
|
||||
* will interact with the given MTextPanel.
|
||||
* @param menuBar the MenuBar to which menus are added
|
||||
* @param textPanel the MTextPanel with which the menus interact
|
||||
* @param frame a Frame to use as the parent of any dialogs created by a
|
||||
* a menu item. If null, menu items which create dialogs will be omitted.
|
||||
* @param menus an array of integer menu id's. Each element of the
|
||||
* array must be one of this class's menu id constants. If null,
|
||||
* the default menus are created.
|
||||
*/
|
||||
public void createMenus(MenuBar menuBar,
|
||||
MTextPanel textPanel,
|
||||
Frame frame,
|
||||
int[] menus) {
|
||||
|
||||
if (menus == null) {
|
||||
menus = defaultMenus;
|
||||
}
|
||||
|
||||
synchronized (MItem.LOCK) {
|
||||
|
||||
fMenuBar = menuBar;
|
||||
doCreateMenus(textPanel, frame, menus);
|
||||
fMenuBar = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleAddMenu(String key) {
|
||||
|
||||
Menu menu = new Menu(ResourceUtils.getResourceString(key));
|
||||
fMenuBar.add(menu);
|
||||
MItem.setItemFactory(new AwtMenuFactory(menu));
|
||||
}
|
||||
|
||||
protected DialogFactory createObjectDialogFactory(final String dialogTitle,
|
||||
final String dialogMessage,
|
||||
final Object key,
|
||||
final boolean character,
|
||||
final String[] names,
|
||||
final Object[] values) {
|
||||
|
||||
final Frame dialogParent = fDialogParent;
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel textPanel) {
|
||||
return new ObjectDialog(dialogParent,
|
||||
dialogTitle,
|
||||
dialogMessage,
|
||||
textPanel,
|
||||
key,
|
||||
character,
|
||||
names,
|
||||
values);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected DialogFactory createNumberDialogFactory(final String dialogTitle,
|
||||
final String dialogMessage,
|
||||
final Object key,
|
||||
final boolean character) {
|
||||
|
||||
final Frame dialogParent = fDialogParent;
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel textPanel) {
|
||||
return new NumberDialog(dialogParent,
|
||||
dialogTitle,
|
||||
dialogMessage,
|
||||
textPanel,
|
||||
key,
|
||||
character,
|
||||
1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected DialogFactory createAboutDialogFactory() {
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel textPanel) {
|
||||
String title = ResourceUtils.getResourceString(FrameResources.ABOUT_TITLE);
|
||||
return new MessageDialog(title, AboutText.getAboutText());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.CheckboxMenuItem;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.MenuShortcut;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ItemEvent;
|
||||
import java.awt.event.ItemListener;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
import com.ibm.richtext.uiimpl.MItem;
|
||||
import com.ibm.richtext.uiimpl.MItem.ItemFactory;
|
||||
|
||||
final class AwtMenuFactory implements ItemFactory {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private final class AwtMItem extends MItem {
|
||||
|
||||
private MenuItem fItem;
|
||||
|
||||
AwtMItem(MenuItem item) {
|
||||
|
||||
fItem = item;
|
||||
try {
|
||||
CheckboxMenuItem chItem = (CheckboxMenuItem) fItem;
|
||||
chItem.addItemListener(new ItemListener() {
|
||||
public void itemStateChanged(ItemEvent e) {
|
||||
handleSelected();
|
||||
}
|
||||
});
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent evt) {
|
||||
handleSelected();
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
// Ack - how do you do this from inner classes??
|
||||
protected void handleSelected() {
|
||||
|
||||
super.handleSelected();
|
||||
}
|
||||
|
||||
public final void setEnabled(boolean enabled) {
|
||||
|
||||
fItem.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setState(boolean checked) {
|
||||
|
||||
try {
|
||||
CheckboxMenuItem item = (CheckboxMenuItem) fItem;
|
||||
item.setState(checked);
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
throw new Error("Cannot perform setChecked on non-checkbox item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Menu fMenu;
|
||||
|
||||
AwtMenuFactory(Menu menu) {
|
||||
|
||||
fMenu = menu;
|
||||
}
|
||||
|
||||
private MItem handleCreate(MenuItem item,
|
||||
MenuData menuData) {
|
||||
|
||||
if (menuData.hasShortcut()) {
|
||||
item.setShortcut(new MenuShortcut(menuData.getShortcutChar()));
|
||||
}
|
||||
|
||||
fMenu.add(item);
|
||||
|
||||
return new AwtMItem(item);
|
||||
}
|
||||
|
||||
public MItem createItem(MenuData menuData) {
|
||||
|
||||
return handleCreate(new MenuItem(menuData.getName()), menuData);
|
||||
}
|
||||
|
||||
public MItem createCheckboxItem(MenuData menuData) {
|
||||
|
||||
return handleCreate(new CheckboxMenuItem(menuData.getName()), menuData);
|
||||
}
|
||||
|
||||
public void createSeparator() {
|
||||
|
||||
fMenu.add(new MenuItem("-"));
|
||||
}
|
||||
}
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.Color;
|
||||
import com.ibm.richtext.styledtext.MTabRuler;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
|
||||
/**
|
||||
* MTabRulerComponent is implemented by components which provide a tab-ruler
|
||||
* interface for interacting with an MTextPanel.
|
||||
* <p>
|
||||
* Users interact with MTabRulerComponent implementations as follows:
|
||||
* <ul>
|
||||
* <li>The leading margin can be set by dragging the bottom half
|
||||
* of the leftmost triangle. The first-line indent will "stick" with
|
||||
* the leading margin.</li>
|
||||
* <li>The first-line indent can be set by dragging the top half of the
|
||||
* leftmost triangle. The first-line indent applies to the first line of
|
||||
* a paragraph.</li>
|
||||
* <li>The trailing margin can be set by dragging the rightmost triangle.</li>
|
||||
* <li>Tabs can be added to the ruler by clicking the mouse on the ruler with the
|
||||
* control key pressed. Four kinds of tabs are provided: leading, trailing, center,
|
||||
* and decimal. The type of a tab can be changed by double-clicking the tab.</li>
|
||||
* <li>Tabs can be repositioned by dragging them with the mouse.</li>
|
||||
* </ul>
|
||||
* <p>
|
||||
* MTabRulerComponent's appearance will reflect the paragraph styles in the
|
||||
* first selected paragraph. Style changes performed with an
|
||||
* MTabRulerComponent will apply to all selected paragraphs.
|
||||
*/
|
||||
public interface MTabRulerComponent {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
/**
|
||||
* Listen to the given MTextPanel and reflect its changes,
|
||||
* and update its paragraph styles when TabRuler is
|
||||
* manipulated.
|
||||
* @param textPanel the MTextPanel to listen to
|
||||
*/
|
||||
public void listenToTextPanel(MTextPanel textPanel);
|
||||
|
||||
/**
|
||||
* Return the background color of this TabRuler.
|
||||
* @return the background color of this TabRuler
|
||||
*/
|
||||
public Color getBackColor();
|
||||
|
||||
/**
|
||||
* Set the background color of this TabRuler.
|
||||
* @param backColor the new background color of this TabRuler
|
||||
*/
|
||||
public void setBackColor(Color backColor);
|
||||
|
||||
/**
|
||||
* Return the MTabRuler represented by this TabRuler.
|
||||
* @return the MTabRuler represented by this TabRuler
|
||||
*/
|
||||
public MTabRuler getRuler();
|
||||
|
||||
/**
|
||||
* Return the leading margin of this TabRuler.
|
||||
* @return the leading margin of this TabRuler
|
||||
*/
|
||||
public int getLeadingMargin();
|
||||
|
||||
/**
|
||||
* Return the first line indent of this TabRuler.
|
||||
* @return the first line indent of this TabRuler
|
||||
*/
|
||||
public int getFirstLineIndent();
|
||||
|
||||
/**
|
||||
* Return the trailing margin of this TabRuler.
|
||||
* @return the trailing margin of this TabRuler
|
||||
*/
|
||||
public int getTrailingMargin();
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Frame;
|
||||
import java.awt.CardLayout;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelSettings;
|
||||
|
||||
/**
|
||||
* MessageDialog is a simple Frame which displays a styled
|
||||
* text message in a TextPanel.
|
||||
* The text in the message is not selectable or editable.
|
||||
* @see MConstText
|
||||
* @see TextPanel
|
||||
*/
|
||||
public final class MessageDialog extends Frame {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -2328512662551827628L;
|
||||
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Create a new MessageDialog.
|
||||
* @param title the dialog's title
|
||||
* @param message the text which will appear in the dialog
|
||||
*/
|
||||
public MessageDialog(String title, MConstText message)
|
||||
{
|
||||
super(title);
|
||||
|
||||
setLayout(new CardLayout());
|
||||
TextPanelSettings settings = TextPanel.getDefaultSettings();
|
||||
settings.setScrollable(false);
|
||||
settings.setSelectable(false);
|
||||
TextPanel panel = new TextPanel(settings, message, null);
|
||||
|
||||
panel.setBackground(Color.black);
|
||||
add("Center", panel);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
setSize(450,320);
|
||||
}
|
||||
}
|
@ -1,157 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.TextField;
|
||||
import java.awt.Button;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Panel;
|
||||
import java.awt.Label;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.MenuItemSet;
|
||||
import com.ibm.richtext.uiimpl.ResourceUtils;
|
||||
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
|
||||
/**
|
||||
* Simple dialog which gets a number, and sends an appropriate command
|
||||
*/
|
||||
final class NumberDialog extends Dialog implements ActionListener
|
||||
{
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -2181405364377952745L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private MTextPanel fTextPanel;
|
||||
private TextField fInput = null;
|
||||
private Button fOKButton = null;
|
||||
private Button fCancelButton = null;
|
||||
private boolean fCharacter;
|
||||
private Object fKey;
|
||||
private float fMultiplier;
|
||||
|
||||
/**
|
||||
* @param multiplier the factor by which to multiply the user's
|
||||
* selection before creating the attribute value. This
|
||||
* is useful for subscripting.
|
||||
*/
|
||||
NumberDialog(Frame parent,
|
||||
String title,
|
||||
String message,
|
||||
MTextPanel textPanel,
|
||||
Object key,
|
||||
boolean character,
|
||||
float multiplier) {
|
||||
|
||||
super(parent, title, false);
|
||||
fTextPanel = textPanel;
|
||||
fKey = key;
|
||||
fCharacter = character;
|
||||
fMultiplier = multiplier;
|
||||
setLayout(new java.awt.GridLayout(2,1));
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
|
||||
fInput = new TextField(5);
|
||||
panel.add(new Label(message));
|
||||
panel.add(fInput);
|
||||
add("Center", panel);
|
||||
|
||||
fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
|
||||
fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
|
||||
Panel p = new Panel();
|
||||
p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
p.add(fCancelButton);
|
||||
p.add(fOKButton);
|
||||
add("South", p);
|
||||
|
||||
pack();
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closeWindow(false);
|
||||
}
|
||||
});
|
||||
|
||||
fOKButton.addActionListener(this);
|
||||
fCancelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
private void closeWindow(boolean sendAction) {
|
||||
|
||||
setVisible(false);
|
||||
|
||||
int num = 0;
|
||||
if (sendAction) {
|
||||
try {
|
||||
String text = fInput.getText();
|
||||
num = NumberFormat.getInstance().parse(text).intValue();
|
||||
}
|
||||
catch (ParseException exception) {
|
||||
sendAction = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendAction) {
|
||||
sendAction(num);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
Object source = e.getSource();
|
||||
|
||||
if (source == fOKButton) {
|
||||
closeWindow(true);
|
||||
}
|
||||
else if (source == fCancelButton) {
|
||||
closeWindow(false);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid ActionEvent!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user input
|
||||
* @param the number the user typed in
|
||||
*/
|
||||
private void sendAction(int number) {
|
||||
float num = number * fMultiplier;
|
||||
StyleModifier modifier = StyleModifier.createAddModifier(
|
||||
fKey,
|
||||
new Float(num));
|
||||
if (fCharacter == MenuItemSet.CHARACTER) {
|
||||
fTextPanel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
fTextPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeSet;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.uiimpl.MenuItemSet;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.ResourceUtils;
|
||||
|
||||
import java.awt.Dialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Button;
|
||||
import java.awt.Choice;
|
||||
import java.awt.Label;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Panel;
|
||||
import java.awt.GridLayout;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
/**
|
||||
* Simple dialog which gets a color
|
||||
*/
|
||||
final class ObjectDialog extends Dialog implements ActionListener
|
||||
{
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 8667616278985420231L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private final MTextPanel fTextPanel;
|
||||
private final Object fKey;
|
||||
private boolean fCharacter;
|
||||
|
||||
private final Button fOKButton;
|
||||
private final Button fCancelButton;
|
||||
private final Choice fItems;
|
||||
private final Hashtable fNameToValueMap;
|
||||
/**
|
||||
* Construct a new ColorDialog.
|
||||
* @param parent the dialog's parent frame
|
||||
* @param title the dialogs title
|
||||
* @param message the message displayed next to the input box
|
||||
*/
|
||||
ObjectDialog(Frame parent,
|
||||
String title,
|
||||
String message,
|
||||
MTextPanel textPanel,
|
||||
Object key,
|
||||
boolean character,
|
||||
String[] names,
|
||||
Object[] values) {
|
||||
|
||||
super(parent, title, false);
|
||||
fTextPanel = textPanel;
|
||||
fKey = key;
|
||||
fCharacter = character;
|
||||
|
||||
setLayout(new GridLayout(2, 1));
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 10));
|
||||
fItems = new Choice();
|
||||
|
||||
if (names.length != values.length) {
|
||||
throw new IllegalArgumentException("Must have same number of names and values.");
|
||||
}
|
||||
|
||||
fNameToValueMap = new Hashtable(names.length);
|
||||
|
||||
for (int i=0; i < names.length; i++) {
|
||||
fItems.add(names[i]);
|
||||
if (values[i] != null) {
|
||||
fNameToValueMap.put(names[i], values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
panel.add(new Label(message));
|
||||
panel.add(fItems);
|
||||
|
||||
add("North", panel);
|
||||
|
||||
fCancelButton = new Button(ResourceUtils.getResourceString(FrameResources.CANCEL));
|
||||
fOKButton = new Button(ResourceUtils.getResourceString(FrameResources.OK));
|
||||
Panel p = new Panel();
|
||||
p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
p.add(fCancelButton);
|
||||
p.add(fOKButton);
|
||||
add("South", p);
|
||||
|
||||
pack();
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closeWindow(false);
|
||||
}
|
||||
});
|
||||
|
||||
fOKButton.addActionListener(this);
|
||||
fCancelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
private void closeWindow(boolean sendAction) {
|
||||
|
||||
setVisible(false);
|
||||
if (sendAction) {
|
||||
Object value = fNameToValueMap.get(fItems.getSelectedItem());
|
||||
sendAction(value);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
Object source = e.getSource();
|
||||
|
||||
if (source == fOKButton) {
|
||||
closeWindow(true);
|
||||
}
|
||||
else if (source == fCancelButton) {
|
||||
closeWindow(false);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid ActionEvent!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user input
|
||||
* @param obj the value object
|
||||
*/
|
||||
private void sendAction(Object value) {
|
||||
|
||||
StyleModifier modifier;
|
||||
if (value != null) {
|
||||
modifier = StyleModifier.createAddModifier(fKey, value);
|
||||
}
|
||||
else {
|
||||
AttributeSet set = new AttributeSet(fKey);
|
||||
modifier = StyleModifier.createRemoveModifier(set);
|
||||
}
|
||||
|
||||
if (fCharacter == MenuItemSet.CHARACTER) {
|
||||
fTextPanel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
fTextPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,133 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Component;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.uiimpl.TabRulerImpl;
|
||||
import com.ibm.richtext.styledtext.MTabRuler;
|
||||
|
||||
/**
|
||||
* TabRuler is an implementation of MTabRulerComponent in an AWT component.
|
||||
*/
|
||||
public final class TabRuler extends Component implements MTabRulerComponent {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -8418099860214866635L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private TabRulerImpl fImpl;
|
||||
|
||||
/**
|
||||
* Create a new TabRuler.
|
||||
* @param baseline the y-coordinate of the ruler's baseline
|
||||
* @param origin the x-coordinate in this Component where
|
||||
* the left margin appears
|
||||
* @param textPanel the MTextPanel to listen to. This TabRuler
|
||||
* will reflect the MTextPanel's paragraph styles, and update
|
||||
* the paragraph styles when manipulated.
|
||||
*/
|
||||
public TabRuler(int baseline, int origin, MTextPanel textPanel) {
|
||||
|
||||
fImpl = new TabRulerImpl(baseline, origin, textPanel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the given MTextPanel and reflect its changes,
|
||||
* and update its paragraph styles when TabRuler is
|
||||
* manipulated.
|
||||
* @param textPanel the MTextPanel to listen to
|
||||
*/
|
||||
public void listenToTextPanel(MTextPanel textPanel) {
|
||||
|
||||
fImpl.listenToTextPanel(textPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the background color of this TabRuler.
|
||||
* @return the background color of this TabRuler
|
||||
*/
|
||||
public Color getBackColor() {
|
||||
|
||||
return fImpl.getBackColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of this TabRuler.
|
||||
* @param backColor the new background color of this TabRuler
|
||||
*/
|
||||
public void setBackColor(Color backColor) {
|
||||
|
||||
fImpl.setBackColor(backColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MTabRuler represented by this TabRuler.
|
||||
* @return the MTabRuler represented by this TabRuler
|
||||
*/
|
||||
public MTabRuler getRuler() {
|
||||
|
||||
return fImpl.getRuler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the leading margin of this TabRuler.
|
||||
* @return the leading margin of this TabRuler
|
||||
*/
|
||||
public int getLeadingMargin() {
|
||||
|
||||
return fImpl.getLeadingMargin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first line indent of this TabRuler.
|
||||
* @return the first line indent of this TabRuler
|
||||
*/
|
||||
public int getFirstLineIndent() {
|
||||
|
||||
return fImpl.getFirstLineIndent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the trailing margin of this TabRuler.
|
||||
* @return the trailing margin of this TabRuler
|
||||
*/
|
||||
public final int getTrailingMargin() {
|
||||
|
||||
return fImpl.getTrailingMargin();
|
||||
}
|
||||
|
||||
// The following are Component methods which need to be delegated to
|
||||
// the implementation:
|
||||
|
||||
public void paint(Graphics g) {
|
||||
|
||||
fImpl.paint(g);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
|
||||
return fImpl.getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
|
||||
return fImpl.getMinimumSize();
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.awtui;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
/**
|
||||
* TextFrame is a Frame containing an editable TextPanel, a set of standard
|
||||
* menus, and a TabRuler. This class can be used as-is, but is
|
||||
* primarily intended to be a simple example of how to use the other classes
|
||||
* in this package.
|
||||
* @see com.ibm.richtext.textpanel.TextPanel
|
||||
* @see AwtMenuBuilder
|
||||
* @see TabRuler
|
||||
*/
|
||||
public final class TextFrame extends Frame {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 8436822743736641732L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private TextPanel fTextPanel;
|
||||
|
||||
/**
|
||||
* Create a new TextFrame with no text and no title.
|
||||
*/
|
||||
public TextFrame() {
|
||||
|
||||
super();
|
||||
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new TextFrame with no text and the given title.
|
||||
* @param title the title of this Frame
|
||||
*/
|
||||
public TextFrame(String title) {
|
||||
|
||||
super(title);
|
||||
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new TextFrame with the given text and title, whose
|
||||
* TextPanel will use the given clipboard.
|
||||
* @param text the initial text in the TextPanel. If null the
|
||||
* TextPanel will initially be empty
|
||||
* @param title the title of this Frame
|
||||
* @param clipboard the Clipboard which the TextPanel will use.
|
||||
* If null the TextPanel will use a private Clipboard
|
||||
*/
|
||||
public TextFrame(MConstText text,
|
||||
String title,
|
||||
Clipboard clipboard) {
|
||||
|
||||
super(title);
|
||||
init(text, clipboard);
|
||||
}
|
||||
|
||||
private void init(MConstText text, Clipboard clipboard) {
|
||||
|
||||
fTextPanel = new TextPanel(text, clipboard);
|
||||
|
||||
TabRuler tabRuler = new TabRuler(14, 10, fTextPanel);
|
||||
|
||||
createMenus();
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add(fTextPanel, "Center");
|
||||
add(tabRuler, "North");
|
||||
pack();
|
||||
}
|
||||
|
||||
private void createMenus() {
|
||||
|
||||
MenuBar menuBar = new MenuBar();
|
||||
|
||||
AwtMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);
|
||||
|
||||
setMenuBar(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MTextPanel in this frame.
|
||||
*/
|
||||
public MTextPanel getTextPanel() {
|
||||
|
||||
return fTextPanel;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
TextFrame frame = new TextFrame();
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
frame.setSize(550, 700);
|
||||
frame.show();
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<!--
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
-->
|
||||
<html>
|
||||
<body bgcolor="white">
|
||||
Provides classes for building an AWT-based user interface for a TextPanel.
|
||||
</body>
|
||||
</html>
|
@ -1,362 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import com.ibm.richtext.awtui.TabRuler;
|
||||
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelListener;
|
||||
import com.ibm.richtext.textpanel.TextPanelSettings;
|
||||
|
||||
import com.ibm.richtext.awtui.AwtMenuBuilder;
|
||||
|
||||
import com.ibm.richtext.print.PrintingUtils;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Button;
|
||||
import java.awt.Dialog;
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.GridLayout;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuBar;
|
||||
import java.awt.Label;
|
||||
import java.awt.Panel;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* AwtDocumentWindow is a Frame containing a TextPanel, with a document
|
||||
* for storing the text in the TextPanel.
|
||||
*/
|
||||
public final class AwtDocumentWindow extends Frame implements DocumentWindow {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -8075495366541764458L;
|
||||
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private TextPanel fTextPanel;
|
||||
private EditApplication fApplication;
|
||||
private TextDocument fDocument;
|
||||
|
||||
/**
|
||||
* Create a new AwtDocumentWindow.
|
||||
* @param application the application that owns this document
|
||||
* @param clipboard the clipboard to use
|
||||
* @param document the document to show in this AwtDocumentWindow
|
||||
*/
|
||||
AwtDocumentWindow(EditApplication application,
|
||||
TextDocument document,
|
||||
TextPanelSettings textPanelSettings,
|
||||
boolean useTabRuler,
|
||||
TextPanelListener listener,
|
||||
boolean supportStyledText,
|
||||
boolean supportPlainText,
|
||||
int[] menus) {
|
||||
|
||||
fApplication = application;
|
||||
|
||||
fTextPanel = new TextPanel(textPanelSettings, null, application.getClipboard());
|
||||
if (listener != null) {
|
||||
fTextPanel.addListener(listener);
|
||||
}
|
||||
setDocument(document);
|
||||
|
||||
addMenuBar(supportStyledText, supportPlainText, menus);
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
if (useTabRuler) {
|
||||
TabRuler tabRuler = new TabRuler(14, 10, fTextPanel);
|
||||
add(tabRuler, "North");
|
||||
}
|
||||
|
||||
add(fTextPanel, "Center");
|
||||
pack();
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
doClose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addMenuBar(boolean supportStyledText,
|
||||
boolean supportPlainText,
|
||||
int[] menus) {
|
||||
|
||||
MenuBar menuBar = new MenuBar();
|
||||
String menuTitle = ResourceUtils.getString(EditorResources.FILE);
|
||||
Menu menu = new Menu(menuTitle);
|
||||
new AwtFileMenuManager(menu, fApplication, this,
|
||||
supportStyledText, supportPlainText);
|
||||
menuBar.add(menu);
|
||||
|
||||
AwtMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this, menus);
|
||||
setMenuBar(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if it is OK to set the document text and file to
|
||||
* something different.
|
||||
*/
|
||||
private boolean canChangeDocuments() {
|
||||
|
||||
// If the text is modified, give the user a chance to
|
||||
// save it. Otherwise return true.
|
||||
|
||||
if (fDocument.isModified()) {
|
||||
byte save = askSave(this, getTitle());
|
||||
if (save == YES) {
|
||||
return doSave();
|
||||
}
|
||||
else {
|
||||
return save == NO;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void setDocument(TextDocument document) {
|
||||
|
||||
fDocument = document;
|
||||
fDocument.setTextPanel(fTextPanel);
|
||||
setTitle(fDocument.getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document to empty text with no associated file. If
|
||||
* the document text is not saved, prompt the user to save the
|
||||
* the text first. If this operation is canceled, the document
|
||||
* is unchanged.
|
||||
*/
|
||||
public void doNew() {
|
||||
|
||||
if (!canChangeDocuments()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDocument(fApplication.createNewDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for a file from which to load a text document.
|
||||
* If the current text is not saved, first prompt the user to
|
||||
* save. If either operation is canceled or fails, the document
|
||||
* is unchanged.
|
||||
*/
|
||||
public void doOpen() {
|
||||
|
||||
if (!canChangeDocuments()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextDocument document = fApplication.openDocument(this);
|
||||
|
||||
if (document != null) {
|
||||
setDocument(document);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for a file in which to save the document text.
|
||||
* If this operation is not canceled, save the text in the file.
|
||||
* The file becomes this document's file.
|
||||
*/
|
||||
public boolean doSaveAs(int format) {
|
||||
|
||||
String title = ResourceUtils.getString(EditorResources.SAVE_TITLE);
|
||||
File file = getFileFromDialog(fDocument.getFile(), title, this, FileDialog.SAVE);
|
||||
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fDocument.setFile(file);
|
||||
setTitle(fDocument.getTitle());
|
||||
|
||||
fDocument.setFormat(format);
|
||||
|
||||
return fDocument.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the text in this document. If there is no file associated
|
||||
* with the text, this is equivalent to <code>doSaveAs</code>.
|
||||
* This method returns true if the document was successfully saved.
|
||||
*/
|
||||
public boolean doSave() {
|
||||
|
||||
if (fDocument.getFile() == null) {
|
||||
return doSaveAs(fDocument.getFormat());
|
||||
}
|
||||
|
||||
return fDocument.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the contents of this window.
|
||||
*/
|
||||
public void doPrint() {
|
||||
|
||||
PrintingUtils.userPrintText(fDocument.getText(),
|
||||
fTextPanel.getDefaultValues(),
|
||||
this,
|
||||
this.getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to close this window. If the text has not been saved,
|
||||
* give the user a chance to save the text before closing the
|
||||
* window. If the user cancels this operation, this method returns
|
||||
* false and the window is not closed; otherwise this method
|
||||
* returns true and the window is closed.
|
||||
*/
|
||||
public boolean doClose() {
|
||||
|
||||
if (canChangeDocuments()) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
fApplication.removeDocumentWindow(this);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Retrieve a file from a dialog. If the user does not
|
||||
* select a file in the dialog this method returns null.
|
||||
* @param kind either FileDialog.LOAD or FileDialog.SAVE.
|
||||
*/
|
||||
public static File getFileFromDialog(File origFile,
|
||||
String dialogTitle,
|
||||
Frame owner,
|
||||
int kind) {
|
||||
|
||||
FileDialog dialog = new FileDialog(owner,
|
||||
dialogTitle,
|
||||
kind);
|
||||
if (origFile != null) {
|
||||
dialog.setDirectory(origFile.getParent());
|
||||
dialog.setFile(origFile.getName());
|
||||
}
|
||||
dialog.show();
|
||||
String fileStr = dialog.getFile();
|
||||
String dirStr = dialog.getDirectory();
|
||||
|
||||
File file = null;
|
||||
|
||||
if (fileStr != null) {
|
||||
file = new File(dirStr, fileStr);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
private static final byte YES = 0;
|
||||
private static final byte NO = 1;
|
||||
private static final byte CANCEL = 2;
|
||||
|
||||
private static final class DialogListener implements ActionListener {
|
||||
|
||||
Dialog fDialog;
|
||||
Button fYes, fNo, fCancel;
|
||||
byte fState;
|
||||
|
||||
DialogListener(Dialog dialog,
|
||||
Button yes,
|
||||
Button no,
|
||||
Button cancel) {
|
||||
|
||||
fDialog = dialog;
|
||||
fYes = yes;
|
||||
fNo = no;
|
||||
fCancel = cancel;
|
||||
fYes.addActionListener(this);
|
||||
fNo.addActionListener(this);
|
||||
fCancel.addActionListener(this);
|
||||
fState = -1;
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
|
||||
Object source = event.getSource();
|
||||
if (source == fYes) {
|
||||
fState = YES;
|
||||
}
|
||||
else if (source == fNo) {
|
||||
fState = NO;
|
||||
}
|
||||
else if (source == fCancel) {
|
||||
fState = CANCEL;
|
||||
}
|
||||
else {
|
||||
return;
|
||||
}
|
||||
|
||||
fDialog.dispose();
|
||||
}
|
||||
|
||||
byte getState() {
|
||||
|
||||
return fState;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a dialog that asks whether the user wants to
|
||||
* save a document. Possible reponses are Yes, No, and
|
||||
* Cancel. The returned value indicates which response
|
||||
* was chosen.
|
||||
*/
|
||||
private static byte askSave(Frame parent, String fileName) {
|
||||
|
||||
Dialog dialog = new Dialog(parent, true);
|
||||
dialog.setLayout(new GridLayout(0, 1));
|
||||
|
||||
String pattern = ResourceUtils.getString(EditorResources.SAVE_MSG);
|
||||
String text = MessageFormat.format(pattern, new Object[] {fileName});
|
||||
dialog.add(new Label(text, Label.CENTER));
|
||||
|
||||
Button yes = new Button(ResourceUtils.getString(EditorResources.YES));
|
||||
Button no = new Button(ResourceUtils.getString(EditorResources.NO));
|
||||
Button cancel = new Button(ResourceUtils.getString(EditorResources.CANCEL));
|
||||
|
||||
Panel panel = new Panel();
|
||||
panel.add(yes);
|
||||
panel.add(no);
|
||||
panel.add(cancel);
|
||||
dialog.add(panel);
|
||||
|
||||
DialogListener listener = new DialogListener(dialog, yes, no, cancel);
|
||||
|
||||
dialog.setSize(220, 130);
|
||||
dialog.show();
|
||||
|
||||
return listener.getState();
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.Menu;
|
||||
import java.awt.MenuItem;
|
||||
|
||||
final class AwtFileMenuManager extends FileMenuManager {
|
||||
|
||||
private Menu fMenu;
|
||||
|
||||
public AwtFileMenuManager(Menu menu,
|
||||
EditApplication application,
|
||||
DocumentWindow document,
|
||||
boolean supportStyledFormat,
|
||||
boolean supportPlainFormat) {
|
||||
|
||||
super(application, document);
|
||||
|
||||
fMenu = menu;
|
||||
createItems(supportStyledFormat, supportPlainFormat);
|
||||
fMenu = null;
|
||||
}
|
||||
|
||||
protected Object addMenuItem(String key) {
|
||||
|
||||
MenuItem item = ResourceUtils.createMenuItem(key);
|
||||
item.addActionListener(this);
|
||||
fMenu.add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
protected void addSeparator() {
|
||||
|
||||
fMenu.add(new MenuItem("-"));
|
||||
}
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.textlayout.attributes.TextAttribute;
|
||||
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelSettings;
|
||||
import com.ibm.richtext.awtui.AwtMenuBuilder;
|
||||
|
||||
public class CodeEdit extends EditApplication {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
protected final TextPanelSettings fSettings;
|
||||
|
||||
public static synchronized void main(String[] args) {
|
||||
|
||||
if (args.length > 0 && args[0].equals("-swing")) {
|
||||
new com.ibm.richtext.swingdemo.SwingCodeEdit(args,1);
|
||||
}
|
||||
else {
|
||||
new CodeEdit(args, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected CodeEdit(String[] args, int start) {
|
||||
|
||||
super(Toolkit.getDefaultToolkit().getSystemClipboard(),
|
||||
TextDocument.PLAIN_TEXT);
|
||||
|
||||
AttributeMap defaultStyle = new AttributeMap(TextAttribute.SIZE, new Float(12))
|
||||
.addAttribute(TextAttribute.FAMILY, "Monospaced");
|
||||
|
||||
fSettings = TextPanel.getDefaultSettings();
|
||||
fSettings.setWraps(false);
|
||||
fSettings.addDefaultValues(defaultStyle);
|
||||
|
||||
if (args.length == start) {
|
||||
doNewWindow();
|
||||
}
|
||||
else {
|
||||
boolean openedADocument = false;
|
||||
for (int i=start; i < args.length; i++) {
|
||||
|
||||
File file = new File(args[i]);
|
||||
TextDocument document = null;
|
||||
Throwable error = null;
|
||||
try {
|
||||
document = TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
|
||||
}
|
||||
catch(Exception e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
}
|
||||
else {
|
||||
addDocument(document);
|
||||
openedADocument = true;
|
||||
}
|
||||
}
|
||||
if (!openedADocument) {
|
||||
quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected DocumentWindow createDocumentWindow(TextDocument document) {
|
||||
|
||||
return new AwtDocumentWindow(this,
|
||||
document,
|
||||
fSettings,
|
||||
false,
|
||||
new SyntaxColorer(),
|
||||
false,
|
||||
true,
|
||||
menus);
|
||||
}
|
||||
|
||||
protected static final int[] menus = { AwtMenuBuilder.EDIT,
|
||||
AwtMenuBuilder.BIDI,
|
||||
AwtMenuBuilder.ABOUT };
|
||||
|
||||
public TextDocument openDocument(Frame dialogParent) {
|
||||
|
||||
String title = ResourceUtils.getString(EditorResources.OPEN_TITLE);
|
||||
|
||||
File file = AwtDocumentWindow.getFileFromDialog(null, title, dialogParent, FileDialog.LOAD);
|
||||
if (file != null) {
|
||||
try {
|
||||
return TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
|
||||
}
|
||||
catch(Exception e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
public interface DocumentWindow {
|
||||
|
||||
public void doNew();
|
||||
|
||||
public void doOpen();
|
||||
|
||||
public boolean doClose();
|
||||
|
||||
public boolean doSave();
|
||||
|
||||
public boolean doSaveAs(int format);
|
||||
|
||||
public void doPrint();
|
||||
|
||||
public void setSize(int wd, int ht);
|
||||
|
||||
public void show();
|
||||
}
|
@ -1,119 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
public abstract class EditApplication {
|
||||
|
||||
private Clipboard fClipboard;
|
||||
private int fDefaultFormat;
|
||||
private Vector fWindows = new Vector();
|
||||
private int fUntitledCount = 0;
|
||||
|
||||
protected EditApplication(Clipboard clipboard, int defaultFormat) {
|
||||
|
||||
fClipboard = clipboard;
|
||||
fDefaultFormat = defaultFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* New documents are named "Untitled 1", "Untitled 2", etc. This
|
||||
* method returns the appropriate name for the next new document.
|
||||
* @return the next new document name
|
||||
*/
|
||||
private String getNextNewName() {
|
||||
|
||||
fUntitledCount += 1;
|
||||
String pattern = ResourceUtils.getString(EditorResources.UNTITLED_MSG);
|
||||
return MessageFormat.format(pattern,
|
||||
new Object[]{new Integer(fUntitledCount)});
|
||||
}
|
||||
|
||||
public final Clipboard getClipboard() {
|
||||
|
||||
return fClipboard;
|
||||
}
|
||||
|
||||
protected abstract DocumentWindow createDocumentWindow(TextDocument document);
|
||||
|
||||
public abstract TextDocument openDocument(Frame dialogParent);
|
||||
|
||||
public final TextDocument createNewDocument() {
|
||||
|
||||
String name = getNextNewName();
|
||||
int format = fDefaultFormat;
|
||||
return TextDocument.createEmpty(name, format);
|
||||
}
|
||||
|
||||
public final void doNewWindow() {
|
||||
|
||||
addDocument(TextDocument.createEmpty(getNextNewName(), fDefaultFormat));
|
||||
}
|
||||
|
||||
public final void addDocument(TextDocument document) {
|
||||
|
||||
final DocumentWindow window = createDocumentWindow(document);
|
||||
|
||||
window.setSize(500, 400);
|
||||
window.show();
|
||||
fWindows.addElement(window);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove document from list of documents. Quit application if list
|
||||
* length falls to zero.
|
||||
* @param window window of the document to remove
|
||||
*/
|
||||
public final void removeDocumentWindow(DocumentWindow window) {
|
||||
|
||||
fWindows.removeElement(window);
|
||||
if (fWindows.isEmpty()) {
|
||||
quit();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Go through list of documents and attempt to close each document.
|
||||
* If all documents close successfully, then exit.
|
||||
*/
|
||||
public final void doExit() {
|
||||
|
||||
// Clone fWindows since it can get modified while being traversed.
|
||||
Vector windows = (Vector) fWindows.clone();
|
||||
|
||||
int size = windows.size();
|
||||
for (int i=0; i < size; i++) {
|
||||
DocumentWindow window = (DocumentWindow) windows.elementAt(i);
|
||||
if (!window.doClose()) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
// quit will be called when last document removes itself
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when last document window closes. Default implementation
|
||||
* calls System.exit.
|
||||
*/
|
||||
protected void quit() {
|
||||
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
@ -1,126 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.StreamCorruptedException;
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
|
||||
/**
|
||||
* EditDemo is the main class for a simple, multiple-document
|
||||
* styled text editor, built with the classes in the textpanel
|
||||
* and textframe packages.
|
||||
* <p>
|
||||
* To run EditDemo, type:
|
||||
* <blockquote><pre>
|
||||
* java com.ibm.richtext.demo.EditDemo [file1] [file2] [...]
|
||||
* </pre></blockquote>
|
||||
* where the filenames are files saved with this demo.
|
||||
*/
|
||||
public class EditDemo extends EditApplication {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public static synchronized void main(String[] args) {
|
||||
|
||||
if (args.length > 0 && args[0].equals("-swing")) {
|
||||
new com.ibm.richtext.swingdemo.SwingEditDemo(args,1);
|
||||
}
|
||||
else {
|
||||
new EditDemo(args, 0);
|
||||
}
|
||||
}
|
||||
|
||||
protected EditDemo(String[] args, int start) {
|
||||
|
||||
super(Toolkit.getDefaultToolkit().getSystemClipboard(),
|
||||
TextDocument.STYLED_TEXT);
|
||||
|
||||
if (args.length == start) {
|
||||
doNewWindow();
|
||||
}
|
||||
else {
|
||||
boolean openedADocument = false;
|
||||
for (int i=start; i < args.length; i++) {
|
||||
|
||||
File file = new File(args[i]);
|
||||
TextDocument document = getDocumentFromFile(file);
|
||||
|
||||
if (document != null) {
|
||||
addDocument(document);
|
||||
openedADocument = true;
|
||||
}
|
||||
}
|
||||
if (!openedADocument) {
|
||||
quit();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static TextDocument getDocumentFromFile(File file) {
|
||||
|
||||
Exception exception = null;
|
||||
|
||||
try {
|
||||
return TextDocument.createFromFile(file, TextDocument.STYLED_TEXT);
|
||||
}
|
||||
catch(StreamCorruptedException e) {
|
||||
try {
|
||||
return TextDocument.createFromFile(file, TextDocument.PLAIN_TEXT);
|
||||
}
|
||||
catch(Exception e2) {
|
||||
exception = e2;
|
||||
}
|
||||
}
|
||||
catch(Exception e) {
|
||||
exception = e;
|
||||
}
|
||||
|
||||
System.err.println("Exception opening file.");
|
||||
exception.printStackTrace();
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
protected DocumentWindow createDocumentWindow(TextDocument document) {
|
||||
|
||||
return new AwtDocumentWindow(this,
|
||||
document,
|
||||
TextPanel.getDefaultSettings(),
|
||||
true,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
null);
|
||||
}
|
||||
|
||||
public TextDocument openDocument(Frame dialogParent) {
|
||||
|
||||
String title = ResourceUtils.getString(EditorResources.OPEN_TITLE);
|
||||
File file = AwtDocumentWindow.getFileFromDialog(null,
|
||||
title,
|
||||
dialogParent,
|
||||
FileDialog.LOAD);
|
||||
if (file != null) {
|
||||
return getDocumentFromFile(file);
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
import java.awt.event.KeyEvent;
|
||||
|
||||
public final class EditorResources extends ListResourceBundle {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
// menu names - values are Strings
|
||||
public static final String FILE = "File";
|
||||
|
||||
// file menu items - values are MenuData instances
|
||||
public static final String NEW = "New";
|
||||
public static final String NEW_WINDOW = "New Window";
|
||||
public static final String OPEN = "Open...";
|
||||
public static final String SAVE = "Save";
|
||||
public static final String SAVE_AS = "Save As...";
|
||||
public static final String SAVE_AS_STYLED = "Save As Styled Text...";
|
||||
public static final String SAVE_AS_TEXT = "Save As Plain Text...";
|
||||
public static final String CLOSE = "Close";
|
||||
public static final String PRINT = "Print";
|
||||
public static final String EXIT = "Exit";
|
||||
|
||||
// button labels - values are Strings
|
||||
public static final String YES = "Yes";
|
||||
public static final String NO = "No";
|
||||
public static final String CANCEL = "Cancel";
|
||||
|
||||
// message strings - values are Strings
|
||||
public static final String SAVE_MSG = "Save {0} before closing?";
|
||||
public static final String UNTITLED_MSG = "Untitled {0}";
|
||||
|
||||
// window and dialog titles - values are Strings
|
||||
public static final String OPEN_TITLE = "Open Document";
|
||||
public static final String SAVE_TITLE = "Save As";
|
||||
|
||||
/**
|
||||
* Convenience method that returns a two-element
|
||||
* Object array. The first element is name, the
|
||||
* second is a MenuData instance with the given
|
||||
* shortcut.
|
||||
*/
|
||||
private static Object[] makeEntry(String name,
|
||||
char shortCut,
|
||||
int keyCode) {
|
||||
|
||||
return new Object[] { name, new MenuData(name, shortCut, keyCode) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that returns a two-element
|
||||
* Object array. The first element is name, the
|
||||
* second is a MenuData instance.
|
||||
*/
|
||||
private static Object[] makeEntry(String name) {
|
||||
|
||||
return new Object[] { name, new MenuData(name) };
|
||||
}
|
||||
|
||||
/**
|
||||
* Convenience method that returns a two-element
|
||||
* Object array in which both elements are obj.
|
||||
*/
|
||||
private static Object[] duplicate(Object obj) {
|
||||
|
||||
return new Object[] { obj, obj };
|
||||
}
|
||||
|
||||
protected Object[][] getContents() {
|
||||
|
||||
return new Object[][] {
|
||||
duplicate(FILE),
|
||||
duplicate(YES),
|
||||
duplicate(NO),
|
||||
duplicate(CANCEL),
|
||||
duplicate(SAVE_MSG),
|
||||
duplicate(SAVE_TITLE),
|
||||
duplicate(OPEN_TITLE),
|
||||
duplicate(UNTITLED_MSG),
|
||||
makeEntry(NEW, 'n', KeyEvent.VK_N),
|
||||
makeEntry(NEW_WINDOW),
|
||||
makeEntry(OPEN, 'o', KeyEvent.VK_O),
|
||||
makeEntry(SAVE, 's', KeyEvent.VK_S),
|
||||
makeEntry(SAVE_AS),
|
||||
makeEntry(SAVE_AS_STYLED),
|
||||
makeEntry(SAVE_AS_TEXT),
|
||||
makeEntry(CLOSE),
|
||||
makeEntry(PRINT),
|
||||
makeEntry(EXIT),
|
||||
};
|
||||
}
|
||||
}
|
@ -1,114 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.ActionEvent;
|
||||
|
||||
/**
|
||||
* This class creates a File menu and manages user interactions
|
||||
* with the menu.
|
||||
*/
|
||||
public abstract class FileMenuManager implements ActionListener {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private EditApplication fApplication;
|
||||
private DocumentWindow fDocumentWindow;
|
||||
private Object fNew, fNewWindow, fOpen, fSave;
|
||||
private Object fSaveAsStyled, fSaveAsText, fClose, fPrint, fExit;
|
||||
|
||||
protected FileMenuManager(EditApplication application,
|
||||
DocumentWindow document) {
|
||||
|
||||
fApplication = application;
|
||||
fDocumentWindow = document;
|
||||
}
|
||||
|
||||
protected final void createItems(boolean supportStyledFormat,
|
||||
boolean supportPlainFormat) {
|
||||
|
||||
if (!supportStyledFormat && !supportPlainFormat) {
|
||||
throw new IllegalArgumentException("Must support at least one format.");
|
||||
}
|
||||
|
||||
fNew = addMenuItem(EditorResources.NEW);
|
||||
fNewWindow = addMenuItem(EditorResources.NEW_WINDOW);
|
||||
|
||||
addSeparator();
|
||||
|
||||
fOpen = addMenuItem(EditorResources.OPEN);
|
||||
|
||||
fSave = addMenuItem(EditorResources.SAVE);
|
||||
|
||||
if (supportStyledFormat) {
|
||||
if (supportPlainFormat) {
|
||||
fSaveAsStyled = addMenuItem(EditorResources.SAVE_AS_STYLED);
|
||||
fSaveAsText = addMenuItem(EditorResources.SAVE_AS_TEXT);
|
||||
}
|
||||
else {
|
||||
fSaveAsStyled = addMenuItem(EditorResources.SAVE_AS);
|
||||
}
|
||||
}
|
||||
else {
|
||||
fSaveAsText = addMenuItem(EditorResources.SAVE_AS);
|
||||
}
|
||||
|
||||
addSeparator();
|
||||
fClose = addMenuItem(EditorResources.CLOSE);
|
||||
addSeparator();
|
||||
fPrint = addMenuItem(EditorResources.PRINT);
|
||||
addSeparator();
|
||||
fExit = addMenuItem(EditorResources.EXIT);
|
||||
}
|
||||
|
||||
protected abstract Object addMenuItem(String key);
|
||||
|
||||
protected abstract void addSeparator();
|
||||
|
||||
public final void actionPerformed(ActionEvent event) {
|
||||
|
||||
Object source = event.getSource();
|
||||
|
||||
if (source == fNew) {
|
||||
fDocumentWindow.doNew();
|
||||
}
|
||||
else if (source == fNewWindow) {
|
||||
fApplication.doNewWindow();
|
||||
}
|
||||
else if (source == fOpen) {
|
||||
fDocumentWindow.doOpen();
|
||||
}
|
||||
else if (source == fClose) {
|
||||
fDocumentWindow.doClose();
|
||||
}
|
||||
else if (source == fSave) {
|
||||
fDocumentWindow.doSave();
|
||||
}
|
||||
else if (source == fSaveAsStyled) {
|
||||
fDocumentWindow.doSaveAs(TextDocument.STYLED_TEXT);
|
||||
}
|
||||
else if (source == fSaveAsText) {
|
||||
fDocumentWindow.doSaveAs(TextDocument.PLAIN_TEXT);
|
||||
}
|
||||
else if (source == fPrint) {
|
||||
fDocumentWindow.doPrint();
|
||||
}
|
||||
else if (source == fExit) {
|
||||
fApplication.doExit();
|
||||
}
|
||||
else {
|
||||
throw new Error("Unknown event source: " + source);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
public final class MenuData {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private String fName;
|
||||
private boolean fHasShortcut;
|
||||
private char fShortcut;
|
||||
private int fShortcutKeyCode;
|
||||
|
||||
public MenuData(String name) {
|
||||
|
||||
fName = name;
|
||||
fHasShortcut = false;
|
||||
}
|
||||
|
||||
public MenuData(String name, char ch, int keyCode) {
|
||||
|
||||
fName = name;
|
||||
fHasShortcut = true;
|
||||
fShortcut = ch;
|
||||
fShortcutKeyCode = keyCode;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
|
||||
return fName;
|
||||
}
|
||||
|
||||
public char getShortcut() {
|
||||
|
||||
if (!fHasShortcut) {
|
||||
throw new Error("Menu doesn't have shortcut");
|
||||
}
|
||||
return fShortcut;
|
||||
}
|
||||
|
||||
public int getShortcutKeyCode() {
|
||||
|
||||
return fShortcutKeyCode;
|
||||
}
|
||||
|
||||
public boolean hasShortcut() {
|
||||
|
||||
return fHasShortcut;
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.awt.MenuItem;
|
||||
import java.awt.MenuShortcut;
|
||||
|
||||
import java.util.MissingResourceException;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
/**
|
||||
* Utility class for dealing with resource data.
|
||||
*/
|
||||
public final class ResourceUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static ResourceBundle BUNDLE;
|
||||
static {
|
||||
String bundleName = "com.ibm.richtext.demo.EditorResources";
|
||||
try {
|
||||
BUNDLE = ResourceBundle.getBundle(bundleName);
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
System.out.println("Couldn't load " + bundleName +
|
||||
"; Exception: " + e);
|
||||
BUNDLE = new EditorResources();
|
||||
}
|
||||
}
|
||||
|
||||
public static String getString(String key) {
|
||||
|
||||
try {
|
||||
return BUNDLE.getString(key);
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
public static MenuData getMenuData(String key) {
|
||||
|
||||
try {
|
||||
return (MenuData) BUNDLE.getObject(key);
|
||||
}
|
||||
catch(MissingResourceException e) {
|
||||
return new MenuData(key);
|
||||
}
|
||||
}
|
||||
|
||||
public static MenuItem createMenuItem(String key) {
|
||||
|
||||
MenuData menuData = getMenuData(key);
|
||||
|
||||
if (menuData.hasShortcut()) {
|
||||
MenuShortcut shortcut = new MenuShortcut(menuData.getShortcut());
|
||||
return new MenuItem(menuData.getName(), shortcut);
|
||||
}
|
||||
else {
|
||||
return new MenuItem(menuData.getName());
|
||||
}
|
||||
}
|
||||
}
|
@ -1,286 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1999-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import com.ibm.richtext.awtui.TextFrame;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelEvent;
|
||||
import com.ibm.richtext.textpanel.TextPanelListener;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.textlayout.attributes.TextAttribute;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import java.text.BreakIterator;
|
||||
import java.text.CharacterIterator;
|
||||
import java.text.CollationKey;
|
||||
import java.text.Collator;
|
||||
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
|
||||
/**
|
||||
* SyntaxColorer is a TextPanelListener that applies a style
|
||||
* to a set of words in the TextPanel.
|
||||
*/
|
||||
public final class SyntaxColorer implements TextPanelListener {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private static final class Colorer {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int fStart;
|
||||
private Hashtable fStyleMap;
|
||||
private Collator fCollator = Collator.getInstance();
|
||||
private BreakIterator fBreakIter = BreakIterator.getWordInstance();
|
||||
|
||||
private String fText;
|
||||
private int fCurrentStart;
|
||||
private int fCurrentLimit;
|
||||
private AttributeMap fCurrentStyle;
|
||||
|
||||
Colorer(Hashtable styles) {
|
||||
|
||||
fStyleMap = new Hashtable(styles.size());
|
||||
|
||||
Enumeration e = styles.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
String k = (String) e.nextElement();
|
||||
fStyleMap.put(fCollator.getCollationKey(k), styles.get(k));
|
||||
}
|
||||
}
|
||||
|
||||
void set(CharacterIterator text, int start, int limit) {
|
||||
|
||||
fStart = start;
|
||||
|
||||
StringBuffer sb = new StringBuffer(limit-start);
|
||||
for (char c=text.setIndex(start); text.getIndex() != limit; c=text.next()) {
|
||||
sb.append(c);
|
||||
}
|
||||
fText = sb.toString();
|
||||
fCurrentStart = fCurrentLimit = 0;
|
||||
fCurrentStyle = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
|
||||
fBreakIter.setText(fText);
|
||||
fBreakIter.first();
|
||||
}
|
||||
|
||||
boolean next() {
|
||||
|
||||
if (fCurrentLimit == fText.length()) {
|
||||
fText = null;
|
||||
return false;
|
||||
}
|
||||
|
||||
fCurrentStart = fCurrentLimit;
|
||||
fCurrentLimit = fBreakIter.next();
|
||||
|
||||
String word = fText.substring(fCurrentStart, fCurrentLimit);
|
||||
CollationKey ck = fCollator.getCollationKey(word);
|
||||
fCurrentStyle = (AttributeMap) fStyleMap.get(ck);
|
||||
if (fCurrentStyle == null) {
|
||||
fCurrentStyle = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
int currentStart() {
|
||||
return fCurrentStart + fStart;
|
||||
}
|
||||
|
||||
int currentLimit() {
|
||||
return fCurrentLimit + fStart;
|
||||
}
|
||||
|
||||
AttributeMap currentStyle() {
|
||||
return fCurrentStyle;
|
||||
}
|
||||
}
|
||||
|
||||
private BreakIterator fBreakIter = BreakIterator.getWordInstance();
|
||||
private Colorer fColorer;
|
||||
private boolean fModifying = false;
|
||||
private AttributeMap fDefaultKeywordStyle = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
private Hashtable fModifierCache;
|
||||
|
||||
public SyntaxColorer() {
|
||||
|
||||
this(null);
|
||||
}
|
||||
|
||||
public SyntaxColorer(MTextPanel panel) {
|
||||
|
||||
Hashtable ht = new Hashtable();
|
||||
|
||||
//Uncomment this to make keywords appear right-to-left!
|
||||
//fDefaultKeywordStyle = fDefaultKeywordStyle.addAttribute(TextAttribute.BIDI_EMBEDDING,
|
||||
// new Integer(-1));
|
||||
|
||||
fDefaultKeywordStyle = fDefaultKeywordStyle.addAttribute(TextAttribute.UNDERLINE,
|
||||
TextAttribute.UNDERLINE_ON);
|
||||
fDefaultKeywordStyle = fDefaultKeywordStyle.addAttribute(TextAttribute.FOREGROUND,
|
||||
Color.blue);
|
||||
|
||||
String[] javaWords = {"abstract" , "boolean", "break", "byte",
|
||||
"byvalue", "case", "cast", "default",
|
||||
"do", "double", "else", "extends",
|
||||
"false", "final", "goto", "if",
|
||||
"implements", "import", "inner", "instanceof",
|
||||
"int", "operator", "outer", "package",
|
||||
"private", "protected", "public", "rest",
|
||||
"synchronized", "this", "throw", "throws",
|
||||
"transient", "true", "try",
|
||||
"catch", "char", "const", "continue",
|
||||
"finally", "float", "for", "future",
|
||||
"generic", "interface", "long", "native",
|
||||
"new", "null", "return", "short",
|
||||
"static", "super", "switch", "var",
|
||||
"void", "volatile", "while", "class"};
|
||||
|
||||
for (int i=0; i < javaWords.length; i++) {
|
||||
ht.put(javaWords[i], fDefaultKeywordStyle);
|
||||
}
|
||||
|
||||
fColorer = new Colorer(ht);
|
||||
|
||||
if (panel != null) {
|
||||
MConstText text = panel.getText();
|
||||
colorRange(0, text.length(), text.createCharacterIterator(), panel);
|
||||
}
|
||||
|
||||
fModifierCache = new Hashtable(2);
|
||||
fModifierCache.put(fDefaultKeywordStyle,
|
||||
StyleModifier.createReplaceModifier(fDefaultKeywordStyle));
|
||||
fModifierCache.put(AttributeMap.EMPTY_ATTRIBUTE_MAP,
|
||||
StyleModifier.createReplaceModifier(AttributeMap.EMPTY_ATTRIBUTE_MAP));
|
||||
}
|
||||
|
||||
public boolean respondsToEventType(int type) {
|
||||
|
||||
return type == TextPanelEvent.TEXT_CHANGED;
|
||||
}
|
||||
|
||||
public void textEventOccurred(TextPanelEvent e) {
|
||||
|
||||
if (fModifying) {
|
||||
return;
|
||||
}
|
||||
|
||||
MTextPanel panel = (MTextPanel) e.getSource();
|
||||
|
||||
final MConstText text = panel.getText();
|
||||
int start = text.damagedRangeStart();
|
||||
int limit = text.damagedRangeLimit();
|
||||
if (start > limit) {
|
||||
return;
|
||||
}
|
||||
|
||||
CharacterIterator textIter = text.createCharacterIterator();
|
||||
|
||||
fBreakIter.setText(textIter);
|
||||
if (start > 0) {
|
||||
if (start == text.length()) {
|
||||
fBreakIter.last();
|
||||
}
|
||||
else {
|
||||
fBreakIter.following(start-1);
|
||||
}
|
||||
start = fBreakIter.previous();
|
||||
}
|
||||
if (limit < text.length()) {
|
||||
fBreakIter.following(limit);
|
||||
//int l;
|
||||
if ((fBreakIter.previous()) <= limit) {
|
||||
limit = fBreakIter.next();
|
||||
}
|
||||
}
|
||||
|
||||
fModifying = true;
|
||||
colorRange(start, limit, textIter, panel);
|
||||
fModifying = false;
|
||||
}
|
||||
|
||||
private void colorRange(final int start,
|
||||
final int limit,
|
||||
CharacterIterator textIter,
|
||||
MTextPanel panel) {
|
||||
|
||||
fColorer.set(textIter, start, limit);
|
||||
|
||||
MConstText oldText = panel.getText();
|
||||
MText newText = null;
|
||||
|
||||
while (fColorer.next()) {
|
||||
|
||||
int rangeStart = fColorer.currentStart();
|
||||
int rangeLimit = fColorer.currentLimit();
|
||||
|
||||
AttributeMap style = fColorer.currentStyle();
|
||||
|
||||
if (oldText.characterStyleLimit(rangeStart) < rangeLimit ||
|
||||
oldText.characterStyleAt(rangeStart) != style) {
|
||||
|
||||
int cstart = rangeStart-start;
|
||||
int climit = rangeLimit-start;
|
||||
if (newText == null) {
|
||||
newText = new StyledText(oldText, start, limit);
|
||||
}
|
||||
StyleModifier mod = (StyleModifier) fModifierCache.get(style);
|
||||
newText.modifyCharacterStyles(cstart, climit, mod);
|
||||
}
|
||||
}
|
||||
|
||||
if (newText != null) {
|
||||
|
||||
int oldStart = panel.getSelectionStart();
|
||||
int oldLimit = panel.getSelectionEnd();
|
||||
|
||||
panel.replaceRange(newText, start, limit);
|
||||
|
||||
panel.select(oldStart, oldLimit);
|
||||
if (oldStart == oldLimit) {
|
||||
StyleModifier mod = (StyleModifier) fModifierCache.get(AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
panel.modifyCharacterStyleOnSelection(mod);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
TextFrame f = new TextFrame();
|
||||
f.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
f.setSize(400, 300);
|
||||
MTextPanel panel = f.getTextPanel();
|
||||
panel.addListener(new SyntaxColorer(panel));
|
||||
f.show();
|
||||
}
|
||||
}
|
@ -1,349 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.demo;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/**
|
||||
* A TextDocument handles the association between a file on disk
|
||||
* and a TextPanel.
|
||||
*/
|
||||
public final class TextDocument {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int BUF_SIZE = 1024;
|
||||
|
||||
private String fTitle;
|
||||
private MConstText fText;
|
||||
private File fFile;
|
||||
private MTextPanel fTextPanel = null;
|
||||
private boolean isModified = false;
|
||||
private int fFormat = STYLED_TEXT;
|
||||
|
||||
private TextDocument(String title,
|
||||
MConstText text,
|
||||
File file,
|
||||
int format) {
|
||||
|
||||
fTitle = title;
|
||||
fText = text;
|
||||
fFile = file;
|
||||
setFormat(format);
|
||||
}
|
||||
|
||||
public static final int STYLED_TEXT = 0;
|
||||
public static final int PLAIN_TEXT = 1;
|
||||
|
||||
/**
|
||||
* Return a new TextDocument with no associated file and
|
||||
* empty text.
|
||||
*/
|
||||
public static TextDocument createEmpty(String title, int format) {
|
||||
|
||||
return new TextDocument(title, new StyledText(), null, format);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a TextDocument created from the contents of the given
|
||||
* file. This method may throw an exception if the file cannot
|
||||
* be read. In particular, if the format is given as STYLED_TEXT
|
||||
* but the file does not contain a serialized MConstText,
|
||||
* this method will throw StreamCorruptedException.
|
||||
*/
|
||||
public static TextDocument createFromFile(File file, int format) throws Exception {
|
||||
|
||||
if (format != STYLED_TEXT && format != PLAIN_TEXT) {
|
||||
throw new IllegalArgumentException("Invalid format");
|
||||
}
|
||||
|
||||
MConstText text;
|
||||
if (format == STYLED_TEXT) {
|
||||
text = readMText(file);
|
||||
}
|
||||
else {
|
||||
text = readMTextFromTextFile(file);
|
||||
}
|
||||
|
||||
TextDocument document = new TextDocument(file.getName(),
|
||||
text,
|
||||
file,
|
||||
format);
|
||||
return document;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this document's text differs from the contents
|
||||
* of its file.
|
||||
*/
|
||||
public boolean isModified() {
|
||||
|
||||
if (fTextPanel == null) {
|
||||
return isModified;
|
||||
}
|
||||
else {
|
||||
return fTextPanel.isModified();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the MTextPanel that will be used to edit the document's
|
||||
* text. The document's text becomes the contents of the
|
||||
* MTextPanel.
|
||||
*/
|
||||
public void setTextPanel(MTextPanel textPanel) {
|
||||
|
||||
if (fTextPanel != null) {
|
||||
fText = fTextPanel.getText();
|
||||
isModified = fTextPanel.isModified();
|
||||
}
|
||||
|
||||
fTextPanel = textPanel;
|
||||
|
||||
if (fTextPanel != null) {
|
||||
fTextPanel.setText(fText);
|
||||
fText = null;
|
||||
fTextPanel.setModified(isModified);
|
||||
fTextPanel.clearCommandLog();
|
||||
}
|
||||
}
|
||||
|
||||
public File getFile() {
|
||||
|
||||
return fFile;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set this document's file. The document's title will
|
||||
* change to the file name. The file cannot be null.
|
||||
*/
|
||||
public void setFile(File file) {
|
||||
|
||||
fFile = file;
|
||||
fTitle = file.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the format of this document. The format determines
|
||||
* whether the document will be written to files as styled
|
||||
* text or plain characters.
|
||||
*/
|
||||
public void setFormat(int format) {
|
||||
|
||||
if (format != STYLED_TEXT && format != PLAIN_TEXT) {
|
||||
throw new IllegalArgumentException("Invalid format");
|
||||
}
|
||||
fFormat = format;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the format of this document.
|
||||
*/
|
||||
public int getFormat() {
|
||||
|
||||
return fFormat;
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the document's text to its file. If the document does
|
||||
* not have an associated file then this method is equivalent to
|
||||
* saveAs. This method returns true if the save operation succeeds.
|
||||
*/
|
||||
public boolean save() {
|
||||
|
||||
if (fFile == null) {
|
||||
throw new RuntimeException("Can't save without a file.");
|
||||
}
|
||||
|
||||
MConstText text = getText();
|
||||
boolean success = fFormat==STYLED_TEXT? writeMText(fFile, text) :
|
||||
writePlainMText(fFile, text);
|
||||
if (success && fTextPanel != null) {
|
||||
fTextPanel.setModified(false);
|
||||
}
|
||||
return success;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return this document's styled text.
|
||||
*/
|
||||
public MConstText getText() {
|
||||
|
||||
if (fTextPanel == null) {
|
||||
return fText;
|
||||
}
|
||||
else {
|
||||
return fTextPanel.getText();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the title of this document.
|
||||
*/
|
||||
public String getTitle() {
|
||||
|
||||
return fTitle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MText serialized in the given file.
|
||||
* In case of an error return null.
|
||||
*/
|
||||
private static MConstText readMText(File file) throws Exception {
|
||||
|
||||
FileInputStream inStream = null;
|
||||
|
||||
try {
|
||||
inStream = new FileInputStream(file);
|
||||
ObjectInputStream objStream = new ObjectInputStream(inStream);
|
||||
|
||||
return (MConstText) objStream.readObject();
|
||||
}
|
||||
finally {
|
||||
if (inStream != null) {
|
||||
try {
|
||||
inStream.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Read the given file as a plain text file, and return its
|
||||
* contents as an MConstText. The character and paragraph styles in
|
||||
* the returned text will be EMPTY_ATTRIBUTE_MAP.
|
||||
*/
|
||||
private static MConstText readMTextFromTextFile(File file) throws Exception {
|
||||
|
||||
InputStreamReader in = null;
|
||||
|
||||
try {
|
||||
in = new FileReader(file);
|
||||
|
||||
MText text = new StyledText();
|
||||
|
||||
char[] buf = new char[BUF_SIZE];
|
||||
int read;
|
||||
while ((read=in.read(buf, 0, buf.length)) != -1) {
|
||||
int len = text.length();
|
||||
text.replace(len, len, buf, 0, read, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
finally {
|
||||
if (in != null) {
|
||||
try {
|
||||
in.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to save the given text in the given file.
|
||||
* @return true if the operation succeeded
|
||||
*/
|
||||
private static boolean writeMText(File file, MConstText text) {
|
||||
|
||||
Throwable error = null;
|
||||
OutputStream outStream = null;
|
||||
|
||||
try {
|
||||
outStream = new FileOutputStream(file);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(outStream);
|
||||
|
||||
objStream.writeObject(text);
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
finally {
|
||||
if (outStream != null) {
|
||||
try {
|
||||
outStream.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Write the given MConstText to the given file as plain text.
|
||||
*/
|
||||
private static boolean writePlainMText(File file, MConstText text) {
|
||||
|
||||
Throwable error = null;
|
||||
OutputStreamWriter outStream = null;
|
||||
|
||||
try {
|
||||
outStream = new FileWriter(file);
|
||||
char[] buf = new char[BUF_SIZE];
|
||||
int length = text.length();
|
||||
int start = 0;
|
||||
do {
|
||||
int count = Math.min(length-start, buf.length);
|
||||
text.extractChars(start, start+count, buf, 0);
|
||||
outStream.write(buf, 0, count);
|
||||
start += count;
|
||||
} while (start < length);
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
finally {
|
||||
if (outStream != null) {
|
||||
try {
|
||||
outStream.close();
|
||||
}
|
||||
catch(IOException e) {
|
||||
System.out.print("");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (error != null) {
|
||||
error.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head><!-- Copyright (C) 2002, International Business Machines Corporation and
|
||||
others. All Rights Reserved.
|
||||
-->
|
||||
|
||||
<title>C:ICU4J .lang Package Overview</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>Provides EditDemo, a simple, multiple-document styled text editor, built with the richtext classes in the textpanel and textframe packages.</p>
|
||||
|
||||
<p>To run the demo, type:
|
||||
<tt><blockquote> java -classpath classes com.ibm.richtext.demo.EditDemo [-swing] [file]*</blockquote>
|
||||
It will use a Swing GUI if <code>-swing</code> is present, otherwise it will use an AWT GUI. One or more <code>file</code> arguments can be present, these must be files that have been created with the EditDemo. A separate window will be opened for each file.</p>
|
||||
|
||||
<p>Other classes in this package are supporting classes for the EditDemo.</p>
|
||||
</body>
|
||||
</html>
|
@ -1,160 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.print;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import com.ibm.richtext.textformat.MFormatter;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
/**
|
||||
* This class's interface is very close to that of the JDK 1.2 Printable
|
||||
* interface, but can execute on JDK 1.1. On 1.2, this class is wrapped
|
||||
* in a real Printable. On 1.1, the PrintContext class uses this class
|
||||
* and a PrintJob for printing.
|
||||
*
|
||||
* Note that this class paginates the text in the first call to print,
|
||||
* or to getPageCount.
|
||||
* After construction, its page size is essentially fixed. This is not
|
||||
* as flexible as the 1.2 classes allow, but it should suffice.
|
||||
*/
|
||||
final class MConstTextPrintable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
static final int PAGE_EXISTS = 0;
|
||||
static final int NO_SUCH_PAGE = 1;
|
||||
|
||||
private MConstText fText;
|
||||
private AttributeMap fDefaultStyles;
|
||||
private Rectangle fPageRect;
|
||||
|
||||
// If these two fields are null the text has not been paginated.
|
||||
private MFormatter fFormatter;
|
||||
private Vector fPageStarts;
|
||||
|
||||
/**
|
||||
* Construct an MConstTextPrintable to print the given text. Each page will fit
|
||||
* into pageRect.
|
||||
*/
|
||||
MConstTextPrintable(MConstText text,
|
||||
AttributeMap defaultStyles,
|
||||
Rectangle pageRect) {
|
||||
|
||||
fText = text;
|
||||
fDefaultStyles = defaultStyles;
|
||||
fPageRect = new Rectangle(pageRect);
|
||||
}
|
||||
|
||||
private static boolean emptyParagraphAtEndOfText(MConstText text) {
|
||||
|
||||
if (text.length() > 0) {
|
||||
char ch = text.at(text.length()-1);
|
||||
return ch == '\n' || ch == '\u2029';
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void paginate(Graphics graphics) {
|
||||
|
||||
if (fPageStarts == null) {
|
||||
|
||||
fFormatter = MFormatter.createFormatter(fText,
|
||||
fDefaultStyles,
|
||||
fPageRect.width,
|
||||
true,
|
||||
graphics);
|
||||
|
||||
fFormatter.formatToHeight(Integer.MAX_VALUE);
|
||||
fFormatter.stopBackgroundFormatting();
|
||||
|
||||
fPageStarts = new Vector();
|
||||
|
||||
int lineCount = fFormatter.getLineCount();
|
||||
if (emptyParagraphAtEndOfText(fText)) {
|
||||
lineCount -= 1;
|
||||
}
|
||||
|
||||
int startLine = 0;
|
||||
fPageStarts.addElement(new Integer(startLine));
|
||||
int startHeight = 0;
|
||||
final int pageHeight = fPageRect.height;
|
||||
|
||||
while (startLine < lineCount) {
|
||||
|
||||
int nextStart = fFormatter.lineAtHeight(startHeight + pageHeight);
|
||||
fPageStarts.addElement(new Integer(nextStart));
|
||||
startHeight = fFormatter.lineGraphicStart(nextStart);
|
||||
startLine = nextStart;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the given page in the given graphics. Page numbers are
|
||||
* 0-based. The the return value indicates whether
|
||||
* the page number is valid (as in JDK 1.2). Since you can get the page count
|
||||
* directly, there's really no excuse for passing in an invalid page
|
||||
* index.
|
||||
* @param graphics the Graphics to print to
|
||||
* @param pageNumber the 0-based page number. Should be nonnegative and
|
||||
* less than getPageCount()
|
||||
* @return PAGE_EXISTS if the page number is valid, or
|
||||
* NO_SUCH_PAGE otherwise
|
||||
*/
|
||||
int print(Graphics graphics, int pageNumber) {
|
||||
|
||||
paginate(graphics);
|
||||
|
||||
if (pageNumber < getPageCount(graphics) && pageNumber >= 0) {
|
||||
graphics.setColor(Color.black); // workaround for 1.2 printing bug
|
||||
int startLine = ((Integer)fPageStarts.elementAt(pageNumber)).intValue();
|
||||
int limitLine = ((Integer)fPageStarts.elementAt(pageNumber+1)).intValue();
|
||||
|
||||
int topOfPage = fFormatter.lineGraphicStart(startLine);
|
||||
int pageHeight = fFormatter.lineGraphicStart(limitLine) - topOfPage;
|
||||
|
||||
Point origin = new Point(fPageRect.x, fPageRect.y - topOfPage);
|
||||
Rectangle drawRect = new Rectangle(fPageRect);
|
||||
drawRect.height = pageHeight;
|
||||
|
||||
fFormatter.draw(graphics, drawRect, origin);
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
else {
|
||||
return NO_SUCH_PAGE;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of pages that can be printed.
|
||||
* @param graphics a Graphics instance representative of those
|
||||
* which will be printed into
|
||||
*/
|
||||
int getPageCount(Graphics graphics) {
|
||||
|
||||
paginate(graphics);
|
||||
return fPageStarts.size() - 1;
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
|
||||
package com.ibm.richtext.print;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.print.PageFormat;
|
||||
import java.awt.print.Printable;
|
||||
import java.awt.print.PrinterJob;
|
||||
import java.awt.print.PrinterException;
|
||||
|
||||
final class PrintContext implements Printable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private MConstTextPrintable fPrintable;
|
||||
|
||||
PrintContext(MConstText text, AttributeMap defaultStyles, PageFormat pf) {
|
||||
|
||||
int width = (int) Math.round(pf.getImageableWidth());
|
||||
int height = (int) Math.round(pf.getImageableHeight());
|
||||
int left = (((int)Math.round(pf.getWidth())) - width) / 2;
|
||||
int top = (((int)Math.round(pf.getHeight())) - height) / 2;
|
||||
|
||||
Rectangle pageRect = new Rectangle(left, top, width, height);
|
||||
fPrintable = new MConstTextPrintable(text, defaultStyles, pageRect);
|
||||
}
|
||||
|
||||
public int print(Graphics graphics,
|
||||
PageFormat format,
|
||||
int pageIndex) throws PrinterException {
|
||||
|
||||
if (false)
|
||||
throw new PrinterException("save trees");
|
||||
|
||||
if (fPrintable.print(graphics, pageIndex) == MConstTextPrintable.PAGE_EXISTS) {
|
||||
return PAGE_EXISTS;
|
||||
}
|
||||
else {
|
||||
return NO_SUCH_PAGE;
|
||||
}
|
||||
}
|
||||
|
||||
static void userPrintText(MConstText text,
|
||||
AttributeMap defaultStyles,
|
||||
Frame frame,
|
||||
String jobTitle) {
|
||||
|
||||
PrinterJob job = PrinterJob.getPrinterJob();
|
||||
job.setJobName(jobTitle);
|
||||
if (job.printDialog()) {
|
||||
job.setPrintable(new PrintContext(text, defaultStyles, job.defaultPage()));
|
||||
try {
|
||||
job.print();
|
||||
}
|
||||
catch(PrinterException e) {
|
||||
System.out.println("Printer exception: " + e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.print;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.awt.Frame;
|
||||
|
||||
/**
|
||||
* PrintingUtils contains a static method for printing styled text.
|
||||
* @see com.ibm.richtext.styledtext.MConstText
|
||||
*/
|
||||
public final class PrintingUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
// Keep it out of Javadoc...
|
||||
private PrintingUtils() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the given text. A Print dialog is presented to the user;
|
||||
* unless the user cancels, the text is printed.
|
||||
* @param text the text to print
|
||||
* @param defaultStyles default values for unspecified attributes
|
||||
* @param frame the parent of the Print dialog
|
||||
* @param jobTitle the title of the PrintJob
|
||||
*/
|
||||
public static void userPrintText(MConstText text,
|
||||
AttributeMap defaultStyles,
|
||||
Frame frame,
|
||||
String jobTitle) {
|
||||
|
||||
PrintContext.userPrintText(text, defaultStyles, frame, jobTitle);
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<!--
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
-->
|
||||
<html>
|
||||
<body bgcolor="white">
|
||||
Provides printing for styled text.
|
||||
</body>
|
||||
</html>
|
@ -1,377 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
/** An implementation of MCharBuffer that stores chars in an array with an insertion gap. */
|
||||
/*
|
||||
Change history
|
||||
072396 jf - fixed a bug in replace(int, int, char[], int, int) so that it correctly
|
||||
inserted into the middle of the buffer.
|
||||
080296 jf - added timestamp. This is strictly a debugging device to help catch
|
||||
stale iterators.
|
||||
|
||||
082296 jbr added check for 0-length iterator in replace
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
final class CharBuffer
|
||||
extends MCharBuffer implements Externalizable
|
||||
{
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int kGrowSize = 0x80; // small size for testing
|
||||
private static final int CURRENT_VERSION = 1; // version code for streaming
|
||||
private static final long serialVersionUID = 563174;
|
||||
|
||||
transient Validation fValidation = null;
|
||||
private char[] fArray;
|
||||
transient private int fArraySize;
|
||||
transient private int fGap;
|
||||
|
||||
/** Create an empty char buffer. */
|
||||
public CharBuffer()
|
||||
{
|
||||
}
|
||||
|
||||
/** Create a char buffer that can hold at least capacity chars. */
|
||||
|
||||
public CharBuffer(int capacity)
|
||||
{
|
||||
fArray = allocate(capacity);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
if (in.readInt() != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of CharBuffer");
|
||||
}
|
||||
|
||||
fArray = (char[]) in.readObject();
|
||||
if (fArray != null) {
|
||||
fArraySize = fArray.length;
|
||||
fGap = fArraySize;
|
||||
}
|
||||
else {
|
||||
fArraySize = 0;
|
||||
fGap = 0;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
compress();
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fArray);
|
||||
}
|
||||
|
||||
private void invalidate() {
|
||||
|
||||
if (fValidation != null) {
|
||||
fValidation.invalidate();
|
||||
fValidation = null;
|
||||
}
|
||||
}
|
||||
|
||||
// not ThreadSafe - could end up with two Validations
|
||||
// being generated
|
||||
private Validation getValidation() {
|
||||
|
||||
if (fValidation == null) {
|
||||
fValidation = new Validation();
|
||||
}
|
||||
return fValidation;
|
||||
}
|
||||
|
||||
/** Replace the chars from start to limit with the chars from srcStart to srcLimit in srcBuffer. */
|
||||
|
||||
/** Replace the chars from start to limit with the chars from srcStart to srcLimit in srcChars.
|
||||
* This is the core routine for manipulating the buffer.
|
||||
*/
|
||||
public void replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit)
|
||||
{
|
||||
invalidate();
|
||||
int dstLength = limit - start;
|
||||
int srcLength = srcLimit - srcStart;
|
||||
|
||||
if (dstLength < 0 || srcLength < 0) {
|
||||
throw new IllegalArgumentException("replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit)");
|
||||
}
|
||||
|
||||
int gapAlloc = 0;
|
||||
if (srcChars == null) {
|
||||
gapAlloc = srcLength;
|
||||
srcLength = 0;
|
||||
}
|
||||
|
||||
int newSize = fArraySize - dstLength + srcLength;
|
||||
|
||||
if (fArray == null) {
|
||||
if (start != 0 || limit != 0) {
|
||||
throw new IllegalArgumentException("replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit)");
|
||||
}
|
||||
if (newSize + gapAlloc > 0) {
|
||||
fArray = allocate(newSize + gapAlloc);
|
||||
if (srcLength > 0) {
|
||||
System.arraycopy(srcChars, srcStart, fArray, 0, srcLength);
|
||||
fArraySize = srcLength;
|
||||
fGap = srcLength;
|
||||
}
|
||||
}
|
||||
} else {
|
||||
int newGap = start + srcLength;
|
||||
int gapLimit = fArray.length - fArraySize + fGap;
|
||||
|
||||
if (newSize + gapAlloc > fArray.length) {
|
||||
char[] temp = allocate(newSize + gapAlloc);
|
||||
|
||||
//move stuff at beginning that we aren't writing over
|
||||
if (start > 0) {
|
||||
at(0, start, temp, 0);
|
||||
}
|
||||
//move stuff from src array that we are copying
|
||||
if (srcLength > 0) {
|
||||
System.arraycopy(srcChars, srcStart, temp, start, srcLength);
|
||||
}
|
||||
//move stuff at end that we aren't copying over
|
||||
if (limit < fArraySize) {
|
||||
at(limit, fArraySize, temp, temp.length - newSize + newGap);
|
||||
//change 7-23-96
|
||||
// at(limit, fArraySize - limit, temp, temp.length - newSize + newGap);
|
||||
}
|
||||
|
||||
fArray = temp;
|
||||
} else {
|
||||
if (start > fGap) {
|
||||
System.arraycopy(fArray, gapLimit, fArray, fGap, start - fGap);
|
||||
}
|
||||
if (limit < fGap) {
|
||||
System.arraycopy(fArray, limit, fArray, fArray.length - newSize + newGap, fGap - limit);
|
||||
}
|
||||
if (srcLength > 0) {
|
||||
System.arraycopy(srcChars, srcStart, fArray, start, srcLength);
|
||||
}
|
||||
}
|
||||
|
||||
fArraySize = newSize;
|
||||
fGap = newGap;
|
||||
}
|
||||
}
|
||||
|
||||
/** Replace the chars from start to limit with the chars from srcStart to srcLimit in srcString. */
|
||||
|
||||
/* This implements optimizations for null text or inserting text that fits at the gap,
|
||||
and defaults to call the core replace routine if these optimizations fail. */
|
||||
|
||||
public void replace(int start, int limit, String srcString, int srcStart, int srcLimit)
|
||||
{
|
||||
invalidate();
|
||||
int length = limit - start;
|
||||
int srcLength = srcLimit - srcStart;
|
||||
|
||||
if (fArray == null) {
|
||||
if (start != 0 || limit != 0) {
|
||||
throw new IllegalArgumentException("replace(int start, int limit, String srcString, int srcStart, int srcLimit)");
|
||||
}
|
||||
if (srcLength > 0) {
|
||||
fArray = allocate(srcLength);
|
||||
srcString.getChars(srcStart, srcLimit, fArray, 0);
|
||||
fArraySize = srcLength;
|
||||
fGap = srcLength;
|
||||
}
|
||||
} else {
|
||||
if (start == fGap && fArray.length >= fArraySize - length + srcLength) {
|
||||
if (srcLimit > 0) {
|
||||
srcString.getChars(srcStart, srcLimit, fArray, fGap);
|
||||
fGap += srcLength;
|
||||
}
|
||||
fArraySize += srcLength - length;
|
||||
} else {
|
||||
replace(start, limit, srcString != null ? srcString.toCharArray() : null, srcStart, srcLimit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void replace(int start, int limit, MConstText srcText, int srcStart, int srcLimit)
|
||||
{
|
||||
invalidate();
|
||||
int length = limit - start;
|
||||
int srcLength = srcLimit - srcStart;
|
||||
|
||||
if (fArray == null) {
|
||||
if (start != 0 || limit != 0) {
|
||||
throw new IllegalArgumentException("replace(int start, int limit, String srcString, int srcStart, int srcLimit)");
|
||||
}
|
||||
if (srcLength > 0) {
|
||||
fArray = allocate(srcLength);
|
||||
srcText.extractChars(srcStart, srcLimit, fArray, 0);
|
||||
fArraySize = srcLength;
|
||||
fGap = srcLength;
|
||||
}
|
||||
} else {
|
||||
if (start == fGap && fArray.length >= fArraySize - length + srcLength) {
|
||||
if (srcLimit > 0) {
|
||||
srcText.extractChars(srcStart, srcLimit, fArray, fGap);
|
||||
fGap += srcLength;
|
||||
}
|
||||
fArraySize += srcLength - length;
|
||||
} else {
|
||||
char[] temp = srcLength == 0? null : new char[srcLength];
|
||||
if (temp != null) {
|
||||
srcText.extractChars(srcStart, srcLimit, temp, 0);
|
||||
}
|
||||
replace(start, limit, temp, 0, srcLimit - srcStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Replace the chars from start to limit with srcChar. */
|
||||
|
||||
/* This implements optimizations for null text or replacing a character that fits into the gap,
|
||||
and defaults to call the core replace routine if these optimizations fail. */
|
||||
|
||||
public void replace(int start, int limit, char srcChar)
|
||||
{
|
||||
invalidate();
|
||||
if (fArray == null) {
|
||||
if (start != 0 || limit != 0) {
|
||||
throw new IllegalArgumentException("replace(int start, int limit, char srcChar)");
|
||||
}
|
||||
fArray = allocate(1);
|
||||
fArray[0] = srcChar;
|
||||
fArraySize = 1;
|
||||
fGap = 1;
|
||||
} else {
|
||||
int length = limit - start;
|
||||
if (start == fGap && fArray.length > fArraySize - length) {
|
||||
fArray[fGap] = srcChar;
|
||||
fGap += 1;
|
||||
fArraySize += 1 - length;
|
||||
} else {
|
||||
replace(start, limit, new char[] { srcChar} , 0, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the char at pos. */
|
||||
|
||||
public char at(int pos)
|
||||
{
|
||||
if (pos < 0 || pos >= fArraySize) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
return pos < fGap ? fArray[pos] : fArray[fArray.length - fArraySize + pos];
|
||||
}
|
||||
|
||||
/** Copy the chars from start to limit to dst starting at dstStart. */
|
||||
|
||||
public void at(int start, int limit, char[] dst, int dstStart)
|
||||
{
|
||||
int length = limit - start;
|
||||
|
||||
if (start < 0 || limit < start || limit > fArraySize) {
|
||||
throw new IllegalArgumentException();
|
||||
}
|
||||
|
||||
if (limit <= fGap) {
|
||||
System.arraycopy(fArray, start, dst, dstStart, length);
|
||||
} else if (start >= fGap) {
|
||||
System.arraycopy(fArray, fArray.length - fArraySize + start, dst, dstStart, length);
|
||||
} else {
|
||||
System.arraycopy(fArray, start, dst, dstStart, fGap - start);
|
||||
System.arraycopy(fArray, fArray.length - fArraySize + fGap, dst, dstStart + fGap - start, limit - fGap);
|
||||
}
|
||||
}
|
||||
|
||||
/** Return the number of chars in the buffer. */
|
||||
|
||||
public final int length()
|
||||
{
|
||||
return fArraySize;
|
||||
}
|
||||
|
||||
/** Return the number of chars the buffer can hold before it must reallocate. */
|
||||
|
||||
public final int capacity()
|
||||
{
|
||||
return fArray != null ? fArray.length : 0;
|
||||
}
|
||||
|
||||
/** Reserve capacity chars at start. Utility to optimize a sequence of operations at start. */
|
||||
|
||||
public void reserveCapacity(int start, int capacity)
|
||||
{
|
||||
replace(start, start, (char[])null, 0, capacity);
|
||||
}
|
||||
|
||||
/** Minimize the storage used by the buffer. */
|
||||
|
||||
public void compress()
|
||||
{
|
||||
invalidate();
|
||||
if (fArraySize == 0) {
|
||||
fArray = null;
|
||||
fGap = 0;
|
||||
} else if (fArraySize != fArray.length) {
|
||||
char[] temp = new char[fArraySize];
|
||||
at(0, fArraySize, temp, 0);
|
||||
fArray = temp;
|
||||
fGap = fArraySize;
|
||||
}
|
||||
}
|
||||
|
||||
/** Display the buffer. */
|
||||
|
||||
public String toString()
|
||||
{
|
||||
if (fArray != null) {
|
||||
return new StringBuffer()
|
||||
.append("limit: ").append(fArray.length)
|
||||
.append(", size: ").append(fArraySize)
|
||||
.append(", gap: ").append(fGap)
|
||||
.append(", ").append(fArray, 0, fGap)
|
||||
.append(fArray, fArray.length - fArraySize + fGap, fArraySize - fGap)
|
||||
.toString();
|
||||
} else {
|
||||
return new String("The buffer is empty.");
|
||||
}
|
||||
}
|
||||
|
||||
public CharacterIterator createCharacterIterator(int start, int limit) {
|
||||
|
||||
Validation val = getValidation();
|
||||
return new CharBufferIterator(start, limit, fArray, fArraySize, fGap, val);
|
||||
}
|
||||
|
||||
/** The resizing algorithm. Return a value >= minSize. */
|
||||
|
||||
protected int allocation(int minSize)
|
||||
{
|
||||
// return (minSize + kGrowSize) & ~(kGrowSize - 1);
|
||||
return minSize < kGrowSize ? kGrowSize : (minSize * 2 + kGrowSize) & ~(kGrowSize - 1);
|
||||
}
|
||||
|
||||
/** Allocate a new character array of limit >= minSize. */
|
||||
|
||||
protected char[] allocate(int minSize)
|
||||
{
|
||||
return new char[allocation(minSize)];
|
||||
}
|
||||
}
|
@ -1,129 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
final class CharBufferIterator implements CharacterIterator,
|
||||
Cloneable
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int fRangeStart;
|
||||
private int fRangeLimit;
|
||||
private int fCurrentIndex;
|
||||
private char fStorage[];
|
||||
private int fGap;
|
||||
private int fGapLength;
|
||||
private Validation fValidation;
|
||||
|
||||
CharBufferIterator(int start,
|
||||
int limit,
|
||||
char[] storage,
|
||||
int length,
|
||||
int gap,
|
||||
Validation validation) {
|
||||
|
||||
if (start > limit) {
|
||||
throw new IllegalArgumentException("start > limit");
|
||||
}
|
||||
fRangeStart = start;
|
||||
fRangeLimit = limit;
|
||||
fCurrentIndex = fRangeStart;
|
||||
fStorage = storage;
|
||||
fGap = gap;
|
||||
fGapLength = (storage==null? 0 : storage.length) - length;
|
||||
fValidation = validation;
|
||||
}
|
||||
|
||||
private void checkValidation() {
|
||||
|
||||
if (!fValidation.isValid()) {
|
||||
throw new Error("Iterator is no longer valid");
|
||||
}
|
||||
}
|
||||
|
||||
public char first()
|
||||
{
|
||||
return setIndex(fRangeStart);
|
||||
}
|
||||
|
||||
public char last()
|
||||
{
|
||||
return setIndex(fRangeLimit - 1);
|
||||
}
|
||||
|
||||
public char current()
|
||||
{
|
||||
checkValidation();
|
||||
if (fCurrentIndex < fRangeStart || fCurrentIndex >= fRangeLimit)
|
||||
return DONE;
|
||||
int i = (fCurrentIndex < fGap) ? fCurrentIndex : (fCurrentIndex + fGapLength);
|
||||
return fStorage[i];
|
||||
}
|
||||
|
||||
public char next()
|
||||
{
|
||||
checkValidation();
|
||||
fCurrentIndex++;
|
||||
if (fCurrentIndex >= fRangeLimit)
|
||||
{
|
||||
fCurrentIndex = fRangeLimit;
|
||||
return DONE;
|
||||
}
|
||||
int i = (fCurrentIndex < fGap) ? fCurrentIndex : (fCurrentIndex + fGapLength);
|
||||
return fStorage[i];
|
||||
}
|
||||
|
||||
public char previous()
|
||||
{
|
||||
fCurrentIndex--;
|
||||
if (fCurrentIndex >= fRangeStart)
|
||||
return current();
|
||||
fCurrentIndex = fRangeStart;
|
||||
return DONE;
|
||||
}
|
||||
|
||||
public char setIndex(int i)
|
||||
{
|
||||
if (i < fRangeStart || i > fRangeLimit)
|
||||
throw new IllegalArgumentException("Invalid position");
|
||||
fCurrentIndex = i;
|
||||
return current();
|
||||
}
|
||||
|
||||
public int getBeginIndex()
|
||||
{
|
||||
return fRangeStart;
|
||||
}
|
||||
|
||||
public int getEndIndex()
|
||||
{
|
||||
return fRangeLimit;
|
||||
}
|
||||
|
||||
public int getIndex()
|
||||
{
|
||||
return fCurrentIndex;
|
||||
}
|
||||
|
||||
public Object clone()
|
||||
{
|
||||
try {
|
||||
return super.clone();
|
||||
}
|
||||
catch (CloneNotSupportedException e) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,115 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 1996-2004, International Business Machines
|
||||
* Corporation and others. All Rights Reserved.
|
||||
*/
|
||||
|
||||
/*
|
||||
7/29/96
|
||||
Modified to search portions of an integer array. Should be retested.
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
/**
|
||||
* This class searches a segment of an array of integers. The segment
|
||||
* must be sorted in ascending order (but this class does not verify this).
|
||||
* Also, this class aliases the array; if the array is modified later the
|
||||
* search results are undefined.
|
||||
*/
|
||||
final class FastIntBinarySearch
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int dataArray[];
|
||||
private int auxStart;
|
||||
private int power;
|
||||
|
||||
private int fFirstIndex;
|
||||
|
||||
private static final int exp2[] = { 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536, 131072 };
|
||||
|
||||
public FastIntBinarySearch(int data[])
|
||||
{
|
||||
this(data, 0, data.length);
|
||||
}
|
||||
|
||||
public FastIntBinarySearch(int data[], int firstValidIndex, int validLength)
|
||||
{
|
||||
setData(data, firstValidIndex, validLength);
|
||||
}
|
||||
|
||||
public void setData(int data[]) {
|
||||
|
||||
setData(data, 0, data.length);
|
||||
}
|
||||
|
||||
public void setData(int data[], int firstValidIndex, int validLength) {
|
||||
|
||||
if (data.length < 1) throw new IllegalArgumentException();
|
||||
if (data.length >= exp2[exp2.length-1]) throw new IllegalArgumentException();
|
||||
|
||||
dataArray = data;
|
||||
fFirstIndex = firstValidIndex;
|
||||
|
||||
for (power = exp2.length-1; power > 0 && validLength < exp2[power]; power--) {}
|
||||
|
||||
// at this point, array.length >= 2^power
|
||||
|
||||
auxStart = validLength - exp2[power];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index in the array of the first element which is at least
|
||||
* as large as <tt>value</tt>. If value is larger than the largest
|
||||
* element in the array the last valid index in the array is returned.
|
||||
*/
|
||||
public int findIndex(int value)
|
||||
{
|
||||
int index = exp2[power]-1 + fFirstIndex;
|
||||
if (value >= dataArray[auxStart + fFirstIndex]) {
|
||||
index += auxStart;
|
||||
}
|
||||
|
||||
// at this point, index is the "upper limit" of the search
|
||||
|
||||
switch (power) {
|
||||
case 17:
|
||||
if (value < dataArray[index-65536]) index -= 65536;
|
||||
case 16:
|
||||
if (value < dataArray[index-32768]) index -= 32768;
|
||||
case 15:
|
||||
if (value < dataArray[index-16384]) index -= 16384;
|
||||
case 14:
|
||||
if (value < dataArray[index-8192]) index -= 8192;
|
||||
case 13:
|
||||
if (value < dataArray[index-4096]) index -= 4096;
|
||||
case 12:
|
||||
if (value < dataArray[index-2048]) index -= 2048;
|
||||
case 11:
|
||||
if (value < dataArray[index-1024]) index -= 1024;
|
||||
case 10:
|
||||
if (value < dataArray[index-512]) index -= 512;
|
||||
case 9:
|
||||
if (value < dataArray[index-256]) index -= 256;
|
||||
case 8:
|
||||
if (value < dataArray[index-128]) index -= 128;
|
||||
case 7:
|
||||
if (value < dataArray[index-64]) index -= 64;
|
||||
case 6:
|
||||
if (value < dataArray[index-32]) index -= 32;
|
||||
case 5:
|
||||
if (value < dataArray[index-16]) index -= 16;
|
||||
case 4:
|
||||
if (value < dataArray[index-8]) index -= 8;
|
||||
case 3:
|
||||
if (value < dataArray[index-4]) index -= 4;
|
||||
case 2:
|
||||
if (value < dataArray[index-2]) index -= 2;
|
||||
case 1:
|
||||
if (value < dataArray[index-1]) index -= 1;
|
||||
case 0:
|
||||
if (value < dataArray[index]) index -= 1;
|
||||
}
|
||||
return index;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
/** A dynamic character array optimized for sequences of insert
|
||||
or delete operations in a local region. */
|
||||
|
||||
abstract class MCharBuffer
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
abstract void replace(int start, int limit, MConstText text, int srcStart, int srcLimit);
|
||||
abstract void replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit);
|
||||
abstract void replace(int start, int limit, String srcString, int srcStart, int srcLimit);
|
||||
abstract void replace(int start, int limit, char srcChar);
|
||||
abstract CharacterIterator createCharacterIterator(int start, int limit);
|
||||
abstract char at(int pos);
|
||||
abstract void at(int start, int limit, char[] dst, int dstStart);
|
||||
|
||||
abstract int length();
|
||||
|
||||
abstract int capacity();
|
||||
abstract void reserveCapacity(int pos, int length);
|
||||
abstract void compress();
|
||||
}
|
@ -1,323 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import java.text.CharacterIterator;
|
||||
import java.awt.datatransfer.DataFlavor;
|
||||
|
||||
/**
|
||||
* MConstText is a base class for text with multiple character and
|
||||
* paragraph styles. The text is a sequence of Unicode characters,
|
||||
* represented by <code>char</code>. Character and paragraph
|
||||
* styles are represented by the <code>AttributeMap</code> class.
|
||||
* <p>
|
||||
* Characters in the text are accessed with an integer index using the
|
||||
* <code>at</code> method.
|
||||
* Valid indices are between 0 and (length-1), where length is the number
|
||||
* of characters in the text. Additionally, the
|
||||
* characters in the text may be accessed through a
|
||||
* <code>java.text.CharacterIterator</code>.
|
||||
* <p>
|
||||
* Every character in the text has a character style associated with it,
|
||||
* represented by the <code>AttributeMap</code> class. The character
|
||||
* style for a particular character can be obtained using the
|
||||
* <code>characterStyleAt</code> method.
|
||||
* <p>
|
||||
* Each character in the text is contained in a paragraph. A paragraph
|
||||
* is a range of text including and terminated by a
|
||||
* paragraph separator (either <code>\n</code> or <code>U+2029</code>).
|
||||
* Every
|
||||
* paragraph has a paragraph style associated with it, represented
|
||||
* by the <code>AttributeMap</code> class. Paragraph boundaries and
|
||||
* styles can be obtained from the MConstText.
|
||||
* <p>
|
||||
* This class does not have methods for modifying the text or styles.
|
||||
* However, subclasses may add this capability, so it is not safe to
|
||||
* assume that an MConstText instance is immutable. In particular,
|
||||
* the MText class adds modification protocol to this class. Clients
|
||||
* can detect whether an MConstText has changed by keeping track of its
|
||||
* timestamp.
|
||||
* <p>
|
||||
* A DataFlavor for clipboard content is defined in this class. Using
|
||||
* this DataFlavor insures that all clients will recognize MConstText
|
||||
* content on the clipboard.
|
||||
* @see MText
|
||||
* @see AttributeMap
|
||||
* @see java.text.CharacterIterator
|
||||
* @see java.awt.datatransfer.DataFlavor
|
||||
*/
|
||||
public abstract class MConstText {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* The DataFlavor for MConstText clipboard content. Used to
|
||||
* indicate that clipboard data has an MConstText representation.
|
||||
*/
|
||||
public static final DataFlavor styledTextFlavor =
|
||||
new DataFlavor(MConstText.class, "Styled Text");
|
||||
|
||||
protected MConstText() {
|
||||
}
|
||||
|
||||
//========================================================
|
||||
// CHARACTER ACCESS
|
||||
//========================================================
|
||||
/**
|
||||
* Return the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the character at offset <code>pos</code>
|
||||
*/
|
||||
public abstract char at(int pos);
|
||||
|
||||
/**
|
||||
* Copy the characters in the range [<code>start</code>, <code>limit</code>)
|
||||
* into the array <code>dst</code>, beginning at <code>dstStart</code>.
|
||||
* @param start offset of first character which will be copied into the array
|
||||
* @param limit offset immediately after the last character which will be copied into the array
|
||||
* @param dst array in which to copy characters. The length of <code>dst</code> must be at least
|
||||
* (<code>dstStart + limit - start</code>).
|
||||
*/
|
||||
public abstract void extractChars(int start, int limit, char[] dst, int dstStart);
|
||||
|
||||
/**
|
||||
* Create an MConstText containing the characters and styles in the range
|
||||
* [<code>start</code>, <code>limit</code>).
|
||||
* @param start offset of first character in the new text
|
||||
* @param limit offset immediately after the last character in the new text
|
||||
* @return an MConstText object containing the characters and styles in the given range
|
||||
*/
|
||||
public abstract MConstText extract(int start, int limit);
|
||||
|
||||
/**
|
||||
* Create a <code>java.text.CharacterIterator</code> over all
|
||||
* of the characters in the text. Default implementation calls
|
||||
* <code>createCharacterIterator(0, length())</code>
|
||||
* @return a <code>java.text.CharacterIterator</code> over all
|
||||
* of the characters in the text
|
||||
*/
|
||||
public CharacterIterator createCharacterIterator() {
|
||||
|
||||
return createCharacterIterator(0, length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>java.text.CharacterIterator</code> over the
|
||||
* given range of characters in the text.
|
||||
* @param start the first index in the iteration range
|
||||
* @param limit the index after the last character in the iteration range
|
||||
* @return a <code>java.text.CharacterIterator</code> over the
|
||||
* given range
|
||||
*/
|
||||
public abstract CharacterIterator createCharacterIterator(int start,
|
||||
int limit);
|
||||
|
||||
|
||||
//========================================================
|
||||
// SIZE/CAPACITY
|
||||
//========================================================
|
||||
/**
|
||||
* Return the length of the MConstText object. The length is the number of characters in the text.
|
||||
* @return the length of the MConstText object
|
||||
*/
|
||||
public abstract int length();
|
||||
|
||||
//========================================================
|
||||
// Character styles
|
||||
//========================================================
|
||||
|
||||
/**
|
||||
* Return the index of the first character in the character style run
|
||||
* containing pos. All characters in a style run have the same character
|
||||
* style.
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public abstract int characterStyleStart(int pos);
|
||||
|
||||
/**
|
||||
* Return the index after the last character in the character style run
|
||||
* containing pos. All characters in a style run have the same character
|
||||
* style.
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public abstract int characterStyleLimit(int pos);
|
||||
|
||||
/**
|
||||
* Return the style applied to the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public abstract AttributeMap characterStyleAt(int pos);
|
||||
|
||||
//========================================================
|
||||
// PARAGRAPH BOUNDARIES
|
||||
//========================================================
|
||||
/**
|
||||
* Return the start of the paragraph containing the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the start of the paragraph containing the character at offset <code>pos</code>
|
||||
*/
|
||||
public abstract int paragraphStart(int pos);
|
||||
|
||||
/**
|
||||
* Return the limit of the paragraph containing the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the limit of the paragraph containing the character at offset <code>pos</code>
|
||||
*/
|
||||
public abstract int paragraphLimit(int pos);
|
||||
|
||||
/**
|
||||
* Return the paragraph style applied to the paragraph containing offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the paragraph style in effect at <code>pos</code>
|
||||
*/
|
||||
public abstract AttributeMap paragraphStyleAt(int pos);
|
||||
|
||||
/**
|
||||
* Return the current time stamp. The time stamp is
|
||||
* incremented whenever the contents of the MConstText changes.
|
||||
* @return the current paragraph style time stamp
|
||||
*/
|
||||
public abstract int getTimeStamp();
|
||||
|
||||
/**
|
||||
* Return the start of the damaged range. If the start is not less
|
||||
* than the the limit of the damaged range, then the damaged range
|
||||
* is empty.
|
||||
* @return the start of the damaged range
|
||||
* @see #damagedRangeLimit
|
||||
* @see MText#resetDamagedRange
|
||||
*/
|
||||
public abstract int damagedRangeStart();
|
||||
|
||||
/**
|
||||
* Return the limit of the damaged range. If the start is not less
|
||||
* than the the limit of the damaged range, then the damaged range
|
||||
* is empty.
|
||||
* @return the start of the damaged range
|
||||
* @see #damagedRangeStart
|
||||
* @see MText#resetDamagedRange
|
||||
*/
|
||||
public abstract int damagedRangeLimit();
|
||||
|
||||
//========================================================
|
||||
// Equality and hashCode
|
||||
//========================================================
|
||||
/**
|
||||
* Compare this to another Object for equality. This is
|
||||
* equal to rhs if rhs is an MConstText which is equal
|
||||
* to this.
|
||||
* @param rhs Object to compare to
|
||||
* @return true if this equals <code>rhs</code>
|
||||
*/
|
||||
public final boolean equals(Object rhs) {
|
||||
|
||||
MConstText otherText;
|
||||
|
||||
try {
|
||||
otherText = (MConstText) rhs;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return equals(otherText);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this to another MConstText for equality. This is
|
||||
* equal to rhs if the characters and styles in rhs are the
|
||||
* same as this. Subclasses may override this implementation
|
||||
* for efficiency, but they should preserve these semantics.
|
||||
* Determining that two MConstText instances are equal may be
|
||||
* an expensive operation, since every character and style must
|
||||
* be compared.
|
||||
* @param rhs Object to compare to
|
||||
* @return true if this equals <code>rhs</code>
|
||||
*/
|
||||
public boolean equals(MConstText rhs) {
|
||||
|
||||
if (rhs == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (rhs == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (hashCode() != rhs.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
int length = length();
|
||||
if (length != rhs.length()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
for (int i=0; i < length; i++) {
|
||||
if (i < length && at(i) != rhs.at(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
for (int start = 0; start < length;) {
|
||||
if (!characterStyleAt(start).equals(rhs.characterStyleAt(start))) {
|
||||
return false;
|
||||
}
|
||||
int limit = characterStyleLimit(start);
|
||||
if (limit != rhs.characterStyleLimit(start)) {
|
||||
return false;
|
||||
}
|
||||
start = limit;
|
||||
}
|
||||
|
||||
for (int start = 0; start < length;) {
|
||||
|
||||
if (!paragraphStyleAt(start).equals(rhs.paragraphStyleAt(start))) {
|
||||
return false;
|
||||
}
|
||||
start = paragraphLimit(start);
|
||||
}
|
||||
|
||||
return paragraphStyleAt(length).equals(rhs.paragraphStyleAt(length));
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hashCode for this MConstText. An empty MConstText
|
||||
* has hashCode 0; a nonempty MConstText's hashCode is
|
||||
* <blockquote><pre>
|
||||
* at(0) +
|
||||
* at(length/2)*31^1 +
|
||||
* at(length-1)*31^2 +
|
||||
* characterStyleAt(0).hashCode()*31^3 +
|
||||
* paragraphStyleAt(length-1).hashCode()*31^4
|
||||
* </pre></blockquote>
|
||||
* where <code>^</code> is exponentiation (not bitwise XOR).
|
||||
*/
|
||||
public final int hashCode() {
|
||||
|
||||
int hashCode = 0;
|
||||
int length = length();
|
||||
|
||||
if (length > 0) {
|
||||
hashCode = paragraphStyleAt(length-1).hashCode();
|
||||
hashCode = hashCode*31 + characterStyleAt(0).hashCode();
|
||||
hashCode = hashCode*31 + at(length-1);
|
||||
hashCode = hashCode*31 + at(length/2);
|
||||
hashCode = hashCode*31 + at(0);
|
||||
}
|
||||
|
||||
return hashCode;
|
||||
}
|
||||
}
|
@ -1,91 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
abstract class MParagraphBuffer
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
/**
|
||||
* Returns the start of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
abstract int paragraphStart(int pos);
|
||||
|
||||
/**
|
||||
* Returns the limit of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
abstract int paragraphLimit(int pos);
|
||||
|
||||
/**
|
||||
* Returns the style of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
abstract AttributeMap paragraphStyleAt(int offset);
|
||||
|
||||
/**
|
||||
* Process a character insertion at offset <tt>start</tt>.
|
||||
* If a paragraph break was inserted, propogate paragraph style at
|
||||
* <tt>start</tt> to new paragraph.
|
||||
*/
|
||||
abstract void insertText(int start, char insertedChar);
|
||||
|
||||
/**
|
||||
* Process character insertion at offset <tt>start</tt>.
|
||||
* Each new paragraph gets paragraph style at
|
||||
* <tt>start</tt>.
|
||||
*/
|
||||
abstract void insertText(int start,
|
||||
char[] srcChars,
|
||||
int srcStart,
|
||||
int srcLimit);
|
||||
|
||||
/**
|
||||
* Process deletion by removing paragraph breaks contained in
|
||||
* deleted range. Propogate paragraph styles backward, if necessary.
|
||||
*/
|
||||
abstract void deleteText(int start,
|
||||
int limit,
|
||||
int[] damagedRange);
|
||||
|
||||
/*
|
||||
* Replace paragraph breaks/styles between start and limit with paragraph breaks/styles
|
||||
* from <tt>srcText</tt>.
|
||||
* @param start an offset into the text
|
||||
* @param limit the index after the last character to replace
|
||||
* @param srcText the text from which new paragraphs are taken
|
||||
* @param srcStart the start of the range in <code>srcText</code> to copy
|
||||
* @param srcLimit the first index after the range in <code>srcText</code> to copy
|
||||
*/
|
||||
abstract void replace(int start,
|
||||
int limit,
|
||||
MConstText srcText,
|
||||
int srcStart,
|
||||
int srcLimit,
|
||||
int[] damagedRange);
|
||||
|
||||
/**
|
||||
* Set the style of all paragraphs containing offsets in the range [start, limit) to
|
||||
* <tt>style</tt>.
|
||||
*/
|
||||
abstract boolean modifyParagraphStyles(int start,
|
||||
int limit,
|
||||
StyleModifier modifier,
|
||||
int[] damagedRange);
|
||||
|
||||
/**
|
||||
* Minimize the amount of memory used by this object.
|
||||
*/
|
||||
abstract void compress();
|
||||
}
|
@ -1,110 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/*
|
||||
8/1/96
|
||||
Style -> ResolvedStyle
|
||||
8/7/96 jf
|
||||
added countStyles and getStyles protocol
|
||||
8/13/96
|
||||
ResolvedStyle->Style
|
||||
8/22/96 jf
|
||||
Removed the setIterator methods.
|
||||
*/
|
||||
/*
|
||||
* MStyleBuffer is the abstract interface for a class which maintains
|
||||
* style runs in an <tt>MText</tt>. A "style run" consists of a
|
||||
* style and the interval on which the style applies.
|
||||
* <p>
|
||||
* MStyleBuffer includes methods to call when text is inserted into
|
||||
* or deleted from the <tt>MText</tt>. These methods update the
|
||||
* style runs in accordance with the commonly accepted behavior for
|
||||
* style runs.
|
||||
* <p>
|
||||
* Additionally, MStyleBuffer provides methods for replacing the style runs on a
|
||||
* text range with another set of style runs. MStyleBuffer does not do style "combining" (for
|
||||
* example, adding the bold attribute to text which is italicized); clients are
|
||||
* responsible for computing the combined styles, and passing these styles into
|
||||
* MStyleBuffer.
|
||||
* <p>
|
||||
* MStyleBuffer supplies a method for replacing the style runs on a text range with the runs
|
||||
* represented in an <tt>MStyleRunIterator</tt>. This is useful for implementing paste
|
||||
* operations, in which the style runs on a range of text are replaced by style runs
|
||||
* from an external source.
|
||||
* <p>
|
||||
*
|
||||
* @author John Raley
|
||||
*
|
||||
* @see AttributeMap
|
||||
* @see MText
|
||||
*/
|
||||
abstract class MStyleBuffer
|
||||
{
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Respond to an insertion in the text. The length of the last style run which
|
||||
* begins before <tt>start</tt> is increased by <tt>limit-start</tt>.
|
||||
* @param start the offset where the insertion began
|
||||
* @param limit the offset where the insertion ended
|
||||
*/
|
||||
abstract void insertText(int start, int limit);
|
||||
|
||||
/**
|
||||
* Respond to a deletion in the text. The last style run before
|
||||
* <tt>start</tt> is truncated to end at <tt>start</tt>. The
|
||||
* style run containing (<tt>start</tt>+<tt>length</tt>) is set to begin
|
||||
* at (<tt>start</tt>+<tt>length</tt>). Runs in between are deleted.
|
||||
* If the deletion occurs entirely within one style run, the length of the style
|
||||
* run is reduced by <tt>length</tt>.
|
||||
* @param start the offset where the deletion began
|
||||
* @param length the offset where the deletion ended
|
||||
*/
|
||||
abstract void deleteText(int start, int limit);
|
||||
|
||||
/*
|
||||
* Replace style runs between offsets <tt>start</tt> and <tt>limit</tt> with styles in
|
||||
* <tt>iter</tt>. This method can be used to perform a "paste" operation.
|
||||
* @param start the offset where the replacement begins
|
||||
* @param limit the offset where the replacement ends
|
||||
* @param iter an <tt>MStyleRunIterator</tt> containing style runs which will replace old
|
||||
* style runs.
|
||||
*/
|
||||
abstract void replace(int start, int limit, MConstText srcText, int srcStart, int srcLimit);
|
||||
|
||||
abstract int styleStart(int pos);
|
||||
abstract int styleLimit(int pos);
|
||||
|
||||
/**
|
||||
* Return style at location <tt>pos</tt>.
|
||||
* @param pos an offset into the text
|
||||
* @returns the style of the character at <tt>offset</tt>
|
||||
*/
|
||||
abstract AttributeMap styleAt(int pos);
|
||||
|
||||
/**
|
||||
* Return true if styles were modified.
|
||||
*/
|
||||
abstract boolean modifyStyles(int start,
|
||||
int limit,
|
||||
StyleModifier modifier,
|
||||
int[] damagedRange);
|
||||
|
||||
/**
|
||||
* Minimize the amount of memory used by this object.
|
||||
*/
|
||||
abstract void compress();
|
||||
}
|
@ -1,111 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
/**
|
||||
* This interface represents a sequence of TabStops, ordered by position.
|
||||
* The first
|
||||
* TabStop in the ruler can be obtained with the <code>firstTab</code>
|
||||
* method; subsequent TabStops are obtained with the <code>nextTab</code>
|
||||
* method.
|
||||
* <p>
|
||||
* If a TabStop with type <code>TabStop.kAuto</code> is returned, all tabs
|
||||
* after that TabStop will also have type <code>TabStop.kAuto</code>, and
|
||||
* their positions will be multiples of <code>autoSpacing</code>.
|
||||
* @see TabStop
|
||||
*/
|
||||
public abstract class MTabRuler
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Return first tab in the ruler. If an autoTab, it is at position zero, and
|
||||
* all subsequent tabs will be autotabs at autoSpacing intervals.
|
||||
*/
|
||||
public abstract TabStop firstTab();
|
||||
|
||||
/**
|
||||
* Return the first tab in the ruler with fPosition > position. If it is an
|
||||
* autotab, it is at an increment of autoSpacing, and all subsequent tabs will be
|
||||
* autotabs at autoSpacing intervals.
|
||||
*/
|
||||
public abstract TabStop nextTab(int position);
|
||||
|
||||
/**
|
||||
* Return the interval for autotabs.
|
||||
*/
|
||||
public abstract int autoSpacing();
|
||||
|
||||
/**
|
||||
* Compute the hashCode for this ruler. The hashCode is the
|
||||
* hashCode of the first tab multiplied by the autoSpacing
|
||||
* interval.
|
||||
*/
|
||||
public final int hashCode() {
|
||||
|
||||
return firstTab().hashCode() * autoSpacing();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this tab ruler contains the given tab.
|
||||
* @param tabToTest the tab to search for
|
||||
* @return true if this tab ruler contains <code>tabToTest</code>
|
||||
*/
|
||||
public boolean containsTab(TabStop tabToTest) {
|
||||
|
||||
for (TabStop tab = firstTab();
|
||||
tab.getType() != TabStop.kAuto;
|
||||
tab = nextTab(tab.getPosition())) {
|
||||
if (tab.getPosition() >= tabToTest.getPosition()) {
|
||||
return tabToTest.equals(tab);
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to this ruler, except with the
|
||||
* given tab added. This ruler is not modified.
|
||||
* @param tabToAdd the tab to add to the new tab ruler
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
public MTabRuler addTab(TabStop tabToAdd) {
|
||||
|
||||
return StandardTabRuler.addTabToRuler(this, tabToAdd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to the given ruler, except with the
|
||||
* tab at the given position removed. This ruler is not modified.
|
||||
* @param position the position of the tab to remove from the new tab ruler
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
public MTabRuler removeTab(int position) {
|
||||
|
||||
return StandardTabRuler.removeTabFromRuler(this, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to this ruler, except with the
|
||||
* tab at position <code>fromPosition</code> moved to position
|
||||
* <code>toPosition</code>. This ruler is not modified.
|
||||
* @param fromPosition the position of the tab to move
|
||||
* @param toPosition the new position of the tab
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
public MTabRuler moveTab(int fromPosition, int toPosition) {
|
||||
|
||||
return StandardTabRuler.moveTabOnRuler(this, fromPosition, toPosition);
|
||||
}
|
||||
}
|
@ -1,241 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/*
|
||||
Change history:
|
||||
|
||||
10/29/96 jef split the character and paragraph style access functions
|
||||
8/14/96 sfb eliminated StyleSheetIterator
|
||||
8/21/96 jef completed abstract interface (changed iterator classes etc.)
|
||||
1/30/97 rtg cleaned up interface, brought in functions from SimpleTextView
|
||||
7/31/98 jbr switched from Style to AttributeMap
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class is a mutable extension of MConstText. It has methods for
|
||||
* inserting, appending, replacing, and removing styled text. Additionally,
|
||||
* it has methods for modifying paragraph and character styles.
|
||||
* <p>
|
||||
* Styled characters (from another <code>MConstText</code> instance) added
|
||||
* to the text retain their original character styles. The style of plain characters
|
||||
* (specified as a <code>char</code> or <code>char[]</code>) is always
|
||||
* specified explicitly when they are added to the text. MText does not do
|
||||
* character style "propagation", where unstyled characters take on the
|
||||
* style of previous characters. Clients can implement this behavior by
|
||||
* specifying the styles to propagate.
|
||||
* <p>
|
||||
* When unstyled characters are added to the text, their paragraph style
|
||||
* is the paragraph style in effect immediately after the last new character.
|
||||
* If the characters contain paragraph separators, then every new paragraph
|
||||
* will have the same paragraph style. When styled characters are added
|
||||
* to the text, their resulting paragraph style is determined by the
|
||||
* following rule:
|
||||
* <blockquote>
|
||||
* The paragraph styles in the new text
|
||||
* become the paragraph styles in the target text, with the exception of the
|
||||
* last paragraph in the new text, which takes on the paragraph style in
|
||||
* effect immediately after the inserted text.
|
||||
* If the new text is added at the end of the target text, the new text's
|
||||
* paragraph styles take effect in any paragraph affected by the addition.
|
||||
* </blockquote>
|
||||
* For example, suppose there is a single paragraph of text with style 'A',
|
||||
* delimited with a paragraph separator 'P':
|
||||
* <blockquote>
|
||||
* AAAAAAP
|
||||
* </blockquote>
|
||||
* Suppose the following styled paragraphs are inserted into the above text
|
||||
* after the fourth character:
|
||||
* <blockquote>
|
||||
* BBBBPCCCPDDD
|
||||
* </blockquote>
|
||||
* Then the original paragraph style of each character is:
|
||||
* <blockquote>
|
||||
* AAAABBBBPCCCPDDDAAP
|
||||
* </blockquote>
|
||||
* The resulting paragraph styles are:
|
||||
* <blockquote>
|
||||
* BBBBBBBBPCCCPAAAAAP
|
||||
* </blockquote>
|
||||
* Similarly, if characters are deleted, the paragraph style immediately
|
||||
* after the deletion takes effect on the paragraph containing the deletion.
|
||||
* So, if characters 4-16 were deleted in the example above, the paragraph
|
||||
* styles would be:
|
||||
* <blockquote>
|
||||
* AAAAAAP
|
||||
* </blockquote>
|
||||
* This paragraph-style propagation policy is sometimes referred to as <strong>
|
||||
* following styles win</strong>, since styles at the end of the paragraph
|
||||
* become the style for the entire paragraph.
|
||||
* <p>
|
||||
* This class can accumulate a <strong>damaged range</strong> - an interval in
|
||||
* which characters, character styles, or paragraph styles have changed. This is
|
||||
* useful for clients such as text editors which reformat and draw text after
|
||||
* changes. Usually the damaged range is exactly the range of characters
|
||||
* operated upon; however, larger ranges may be damaged if paragraph styles
|
||||
* change.
|
||||
* @see StyleModifier
|
||||
*/
|
||||
|
||||
public abstract class MText extends MConstText
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
protected MText() {
|
||||
}
|
||||
|
||||
//==================================================
|
||||
// MAIN CHARACTER MODIFICATION FUNCTIONS
|
||||
//==================================================
|
||||
/**
|
||||
* Replace the characters and styles in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* and styles in <code>srcText</code> in the range [<code>srcStart</code>, <code>srcLimit</code>). <code>srcText</code> is not
|
||||
* modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character and style at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param srcText the source for the new characters and styles
|
||||
* @param srcStart the offset into <code>srcText</code> where new characters and styles will be obtained
|
||||
* @param srcLimit the offset into <code>srcText</code> where the new characters and styles end
|
||||
*/
|
||||
public abstract void replace(int start, int limit, MConstText srcText, int srcStart, int srcLimit);
|
||||
|
||||
/**
|
||||
* Replace the characters and styles in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* and styles in <code>srcText</code>. <code>srcText</code> is not
|
||||
* modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character and style at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param text the source for the new characters and styles
|
||||
*/
|
||||
public abstract void replace(int start, int limit, MConstText text);
|
||||
|
||||
/**
|
||||
* Replace the characters in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* in <code>srcChars</code> in the range [<code>srcStart</code>, <code>srcLimit</code>). New characters take on the style
|
||||
* <code>charsStyle</code>.
|
||||
* <code>srcChars</code> is not modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param srcChars the source for the new characters
|
||||
* @param srcStart the offset into <code>srcChars</code> where new characters will be obtained
|
||||
* @param srcLimit the offset into <code>srcChars</code> where the new characters end
|
||||
* @param charsStyle the style of the new characters
|
||||
*/
|
||||
public abstract void replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit, AttributeMap charsStyle);
|
||||
|
||||
/**
|
||||
* Replace the characters in the range [<code>start</code>, <code>limit</code>) with the character <code>srcChar</code>.
|
||||
* The new character takes on the style <code>charStyle</code>
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param srcChar the new character
|
||||
* @param charStyle the style of the new character
|
||||
*/
|
||||
public abstract void replace(int start, int limit, char srcChar, AttributeMap charStyle);
|
||||
|
||||
/**
|
||||
* Replace the entire contents of this MText (both characters and styles) with
|
||||
* the contents of <code>srcText</code>.
|
||||
* @param srcText the source for the new characters and styles
|
||||
*/
|
||||
public abstract void replaceAll(MConstText srcText);
|
||||
|
||||
/**
|
||||
* Insert the contents of <code>srcText</code> (both characters and styles) into this
|
||||
* MText at the position specified by <code>pos</code>.
|
||||
* @param pos The character offset where the new text is to be inserted.
|
||||
* @param srcText The text to insert. */
|
||||
public abstract void insert(int pos, MConstText srcText);
|
||||
|
||||
/**
|
||||
* Append the contents of <code>srcText</code> (both characters and styles) to the
|
||||
* end of this MText.
|
||||
* @param srcText The text to append. */
|
||||
public abstract void append(MConstText srcText);
|
||||
|
||||
/**
|
||||
* Delete the specified range of characters (and styles).
|
||||
* @param start Offset of the first character to delete.
|
||||
* @param limit Offset of the first character after the range to delete. */
|
||||
public abstract void remove(int start, int limit);
|
||||
|
||||
/**
|
||||
* Delete all characters and styles.
|
||||
*/
|
||||
public abstract void remove();
|
||||
|
||||
/**
|
||||
* Create an MText containing the characters and styles in the range
|
||||
* [<code>start</code>, <code>limit</code>).
|
||||
* @param start offset of first character in the new text
|
||||
* @param limit offset immediately after the last character in the new text
|
||||
* @return an MConstText object containing the characters and styles in the given range
|
||||
*/
|
||||
public abstract MText extractWritable(int start, int limit);
|
||||
|
||||
|
||||
//==================================================
|
||||
// STORAGE MANAGEMENT
|
||||
//==================================================
|
||||
|
||||
/**
|
||||
* Minimize the amount of memory used by the MText object.
|
||||
*/
|
||||
public abstract void compress();
|
||||
|
||||
//==================================================
|
||||
// STYLE MODIFICATION
|
||||
//==================================================
|
||||
|
||||
/**
|
||||
* Set the character style of all characters in the MText object to
|
||||
* <code>AttributeMap.EMPTY_ATTRIBUTE_MAP</code>.
|
||||
*/
|
||||
public abstract void removeCharacterStyles();
|
||||
|
||||
/**
|
||||
* Invoke the given modifier on all character styles from start to limit.
|
||||
* @param modifier the modifier to apply to the range.
|
||||
* @param start the start of the range of text to modify.
|
||||
* @param limit the limit of the range of text to modify.
|
||||
*/
|
||||
public abstract void modifyCharacterStyles(int start, int limit, StyleModifier modifier);
|
||||
|
||||
/**
|
||||
* Invoke the given modifier on all paragraph styles in paragraphs
|
||||
* containing characters in the range [start, limit).
|
||||
* @param modifier the modifier to apply to the range.
|
||||
* @param start the start of the range of text to modify.
|
||||
* @param limit the limit of the range of text to modify.
|
||||
*/
|
||||
public abstract void modifyParagraphStyles(int start, int limit, StyleModifier modifier);
|
||||
|
||||
//==================================================
|
||||
// DAMAGED RANGE
|
||||
//==================================================
|
||||
/**
|
||||
* Reset the damaged range to an empty interval, and begin accumulating the damaged
|
||||
* range. The damaged range includes every index where a character, character style,
|
||||
* or paragraph style has changed.
|
||||
* @see #damagedRangeStart
|
||||
* @see #damagedRangeLimit
|
||||
*/
|
||||
public abstract void resetDamagedRange();
|
||||
}
|
@ -1,714 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/*
|
||||
Right now, you have to construct this class with a charBuffer. That's pretty ugly... */
|
||||
|
||||
/*
|
||||
8/8/96
|
||||
Added replace method, which reads styles from a ParagraphIterator.
|
||||
Also, added a constructor which takes a ParagraphIterator.
|
||||
These methods are for copy/paste support.
|
||||
|
||||
8/22/96
|
||||
Replace method (which takes an iterator as an argument) tests for a
|
||||
0-length iterator.
|
||||
|
||||
9/30/96
|
||||
{jbr} modified paragraphLimit();
|
||||
|
||||
10/23/96
|
||||
This class now maintains paragraph styles. Also has a timestamp.
|
||||
|
||||
10/25/96
|
||||
Holds on to Style instead of Style.
|
||||
|
||||
7/31/98 Switched to AttributeMap
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class stores offsets where paragraph breaks occur, and the style applied to
|
||||
* each paragraph.
|
||||
*
|
||||
* The offsets where paragraph breaks occur are stored in a RunArray object. This is
|
||||
* not strictly necessary, but it makes scanning the text for paragraph breaks unnecessary.
|
||||
* However, it makes determining where paragraphs start a little confusing. If there is a
|
||||
* paragraph break at offset p, then there will be a paragraph start at offset p+1.
|
||||
* If the last character in the text is a paragraph break, there will be a run array entry
|
||||
* for that character (and also a paragraph style for that paragraph, even though the
|
||||
* style does not apply to any text).
|
||||
*
|
||||
* The style of the first paragraph in the text is in the fFirstStyle member. Other
|
||||
* paragraph styles are stored in the fStyleTable array, in the following manner: the
|
||||
* paragraph with begins at offset fRunArray.fRunStart[i]+1 has style fStyleTable[i].
|
||||
* The style table's "gap range" is kept in sync with the RunArray.
|
||||
*
|
||||
* This class propogates paragraph styles in the "Microsoft Word" fashion: styles
|
||||
* propogate backward from paragraph breaks.
|
||||
*
|
||||
* This class maintains a time stamp, which changes every time extra formatting (formatting
|
||||
* on a range other than the current selection) is needed; for example, when a paragraph
|
||||
* break is removed.
|
||||
*/
|
||||
|
||||
|
||||
final class ParagraphBuffer extends MParagraphBuffer implements Externalizable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int kInitialSize = 10;
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
private RunArray fRunArray;
|
||||
private AttributeMap[] fStyleTable;
|
||||
private AttributeMap fFirstStyle;
|
||||
|
||||
private static final boolean isParagraphBreak(char c) {
|
||||
|
||||
return c =='\u2029' || c == '\n';
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new paragraph buffer from the characters in <tt>charBuffer</tt>.
|
||||
*/
|
||||
ParagraphBuffer(MCharBuffer charBuffer) {
|
||||
|
||||
this(charBuffer.length());
|
||||
|
||||
// scan text for paragraph boundaries
|
||||
|
||||
int textLength = fRunArray.getCurTextLength();
|
||||
|
||||
for (int pos=0; pos < textLength; pos++) {
|
||||
|
||||
if (isParagraphBreak(charBuffer.at(pos))) {
|
||||
if (fRunArray.fPosEnd+1 >= fRunArray.fNegStart)
|
||||
expandStyleTable();
|
||||
fRunArray.fRunStart[++fRunArray.fPosEnd] = pos;
|
||||
fStyleTable[fRunArray.fPosEnd] = fFirstStyle;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Private constructor.
|
||||
*/
|
||||
private ParagraphBuffer(int initialLength) {
|
||||
|
||||
fRunArray = new RunArray(kInitialSize, initialLength);
|
||||
fStyleTable = new AttributeMap[fRunArray.getArrayLength()];
|
||||
|
||||
fFirstStyle = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this constructor is ONLY for use by the Serialization
|
||||
* mechanism. It does not leave this object in a valid state!
|
||||
*/
|
||||
public ParagraphBuffer() {
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
compress();
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fRunArray);
|
||||
out.writeObject(fStyleTable);
|
||||
out.writeObject(fFirstStyle);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
if (in.readInt() != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of ParagraphBuffer");
|
||||
}
|
||||
fRunArray = (RunArray) in.readObject();
|
||||
fStyleTable = (AttributeMap[]) in.readObject();
|
||||
fFirstStyle = (AttributeMap) in.readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift table such that the last positive run starts before pos.
|
||||
*/
|
||||
private void shiftTableTo(int pos) {
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
int oldPosEnd = fRunArray.fPosEnd;
|
||||
|
||||
fRunArray.shiftTableTo(pos);
|
||||
|
||||
if (oldPosEnd > fRunArray.fPosEnd)
|
||||
System.arraycopy(fStyleTable, fRunArray.fPosEnd+1,
|
||||
fStyleTable, fRunArray.fNegStart,
|
||||
oldPosEnd-fRunArray.fPosEnd);
|
||||
else if (oldNegStart < fRunArray.fNegStart)
|
||||
System.arraycopy(fStyleTable, oldNegStart,
|
||||
fStyleTable, oldPosEnd+1,
|
||||
fRunArray.fNegStart-oldNegStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the style table to reflect a change in the RunArray's size.
|
||||
*/
|
||||
private void handleArrayResize(int oldNegStart) {
|
||||
|
||||
AttributeMap newStyleTable[] = new AttributeMap[fRunArray.getArrayLength()];
|
||||
System.arraycopy(fStyleTable, 0, newStyleTable, 0, fRunArray.fPosEnd+1);
|
||||
System.arraycopy(fStyleTable, oldNegStart, newStyleTable, fRunArray.fNegStart, (fRunArray.getArrayLength()-fRunArray.fNegStart));
|
||||
fStyleTable = newStyleTable;
|
||||
}
|
||||
|
||||
void compress() {
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
fRunArray.compress();
|
||||
if (fRunArray.fNegStart != oldNegStart) {
|
||||
handleArrayResize(oldNegStart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Make more room in run/style tables.
|
||||
*/
|
||||
private void expandStyleTable() {
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
fRunArray.expandRunTable();
|
||||
handleArrayResize(oldNegStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process a character insertion at offset <tt>start</tt>.
|
||||
* If a paragraph break was inserted, propogate paragraph style at
|
||||
* <tt>start</tt> to new paragraph.
|
||||
*/
|
||||
public void insertText(int start, char insertedChar) {
|
||||
|
||||
shiftTableTo(start);
|
||||
if (isParagraphBreak(insertedChar)) {
|
||||
if (fRunArray.fPosEnd+1 >= fRunArray.fNegStart)
|
||||
expandStyleTable();
|
||||
fRunArray.fRunStart[++fRunArray.fPosEnd] = start;
|
||||
fStyleTable[fRunArray.fPosEnd] =
|
||||
(fRunArray.fPosEnd == 0)? fFirstStyle : fStyleTable[fRunArray.fPosEnd-1];
|
||||
fRunArray.runStartsChanged();
|
||||
}
|
||||
|
||||
//fRunArray.fCurTextLength++;
|
||||
fRunArray.addToCurTextLength(1);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process character insertion at offset <tt>start</tt>.
|
||||
* Each new paragraph gets paragraph style at
|
||||
* <tt>start</tt>.
|
||||
*/
|
||||
public void insertText(int start, char srcChars[], int srcStart, int srcLimit) {
|
||||
|
||||
shiftTableTo(start);
|
||||
|
||||
int adjust = start - srcStart;
|
||||
|
||||
for (int i=srcStart; i < srcLimit; i++)
|
||||
if (isParagraphBreak(srcChars[i])) {
|
||||
if (fRunArray.fPosEnd+1 >= fRunArray.fNegStart)
|
||||
expandStyleTable();
|
||||
fRunArray.fRunStart[++fRunArray.fPosEnd] = adjust + i;
|
||||
fStyleTable[fRunArray.fPosEnd] =
|
||||
(fRunArray.fPosEnd == 0)? fFirstStyle : fStyleTable[fRunArray.fPosEnd-1];
|
||||
fRunArray.runStartsChanged();
|
||||
}
|
||||
|
||||
//fRunArray.fCurTextLength += (srcLimit-srcStart);
|
||||
fRunArray.addToCurTextLength(srcLimit-srcStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Process deletion by removing paragraph breaks contained in
|
||||
* deleted range. Propogate paragraph styles backward, if necessary.
|
||||
*/
|
||||
public void deleteText(int start, int limit, int[] damagedRange) {
|
||||
|
||||
int length = limit - start;
|
||||
if (length < 0) {
|
||||
throw new IllegalArgumentException("Invalid range");
|
||||
}
|
||||
|
||||
shiftTableTo(limit);
|
||||
|
||||
int newEnd = fRunArray.findRunContaining(start-1);
|
||||
|
||||
if (newEnd != fRunArray.fPosEnd) {
|
||||
|
||||
AttributeMap propStyle = fStyleTable[fRunArray.fPosEnd];
|
||||
boolean propogated;
|
||||
|
||||
if (newEnd == -1) {
|
||||
propogated = !propStyle.equals(fFirstStyle);
|
||||
fFirstStyle = propStyle;
|
||||
}
|
||||
else {
|
||||
propogated = !propStyle.equals(fStyleTable[newEnd]);
|
||||
fStyleTable[newEnd] = propStyle;
|
||||
}
|
||||
|
||||
if (propogated) {
|
||||
int pStart = (newEnd==-1)? 0 : fRunArray.fRunStart[newEnd] + 1;
|
||||
damagedRange[0] = Math.min(damagedRange[0], pStart);
|
||||
}
|
||||
|
||||
fRunArray.fPosEnd = newEnd;
|
||||
}
|
||||
|
||||
fRunArray.addToCurTextLength(-length);
|
||||
|
||||
fRunArray.runStartsChanged();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the start of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
public int paragraphStart(int pos) {
|
||||
|
||||
int run = fRunArray.findRunContaining(pos-1);
|
||||
if (run == -1) {
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
return fRunArray.getLogicalRunStart(run) + 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the limit of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
public int paragraphLimit(int pos) {
|
||||
|
||||
int run = fRunArray.findRunContaining(pos-1);
|
||||
|
||||
if (run == fRunArray.fPosEnd)
|
||||
run = fRunArray.fNegStart;
|
||||
else
|
||||
run++;
|
||||
|
||||
if (run == fRunArray.getArrayLength()) {
|
||||
return fRunArray.getCurTextLength();
|
||||
}
|
||||
|
||||
int start = fRunArray.getLogicalRunStart(run);
|
||||
|
||||
return start+1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the style of the paragraph containing offset <tt>pos</tt>.
|
||||
*/
|
||||
public AttributeMap paragraphStyleAt(int offset) {
|
||||
|
||||
int run = fRunArray.findRunContaining(offset-1);
|
||||
if (run < 0)
|
||||
return fFirstStyle;
|
||||
else
|
||||
return fStyleTable[run];
|
||||
}
|
||||
|
||||
/**
|
||||
* Create paragraph iterator.
|
||||
*/
|
||||
/*
|
||||
public MParagraphIterator createParagraphIterator(int start, int limit) {
|
||||
|
||||
return new ParagraphIterator(start, limit);
|
||||
}
|
||||
*/
|
||||
|
||||
/**
|
||||
* Called by iterator to get run info.
|
||||
*/
|
||||
private void setIterator(int pos, ParagraphIterator iter) {
|
||||
|
||||
if ((pos < 0) || (pos >= fRunArray.getCurTextLength())) {
|
||||
iter.set(0, 0, kNoRun, null);
|
||||
return;
|
||||
}
|
||||
|
||||
int run;
|
||||
|
||||
if (pos > 0)
|
||||
run = fRunArray.findRunContaining(pos-1);
|
||||
else
|
||||
run = -1;
|
||||
|
||||
setIteratorUsingRun(run, iter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Called by iterator to get run info.
|
||||
*/
|
||||
private void setIteratorUsingRun(int run, ParagraphIterator iter) {
|
||||
|
||||
int lastValidRun = fRunArray.lastRun();
|
||||
|
||||
if (run < -1 || run > lastValidRun) {
|
||||
iter.set(0, 0, kNoRun, null);
|
||||
return;
|
||||
}
|
||||
|
||||
if (run == fRunArray.fPosEnd+1)
|
||||
run = fRunArray.fNegStart;
|
||||
else if (run == fRunArray.fNegStart-1)
|
||||
run = fRunArray.fPosEnd;
|
||||
|
||||
int runStart;
|
||||
AttributeMap style;
|
||||
|
||||
if (run < 0) {
|
||||
runStart = 0;
|
||||
style = fFirstStyle;
|
||||
}
|
||||
else {
|
||||
runStart = fRunArray.fRunStart[run];
|
||||
style = fStyleTable[run];
|
||||
if (runStart < 0)
|
||||
runStart += fRunArray.getCurTextLength();
|
||||
runStart++;
|
||||
}
|
||||
|
||||
int nextRun;
|
||||
|
||||
if (run == fRunArray.fPosEnd)
|
||||
nextRun = fRunArray.fNegStart;
|
||||
else
|
||||
nextRun = run + 1;
|
||||
|
||||
int runLimit;
|
||||
|
||||
if (nextRun >= fRunArray.getArrayLength())
|
||||
runLimit = fRunArray.getCurTextLength();
|
||||
else {
|
||||
runLimit = fRunArray.fRunStart[nextRun];
|
||||
if (runLimit < 0)
|
||||
runLimit += fRunArray.getCurTextLength();
|
||||
runLimit++;
|
||||
}
|
||||
|
||||
iter.set(runStart, runLimit, run, style);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace paragraph breaks/styles between start and length with paragraph breaks/styles
|
||||
* from <tt>srcText</tt>.
|
||||
* @param start an offset into the text
|
||||
* @param limit the index after the last character to replace
|
||||
* @param srcText the text from which new paragraphs are taken
|
||||
* @param srcStart the start of the range in <code>srcText</code> to copy
|
||||
* @param srcLimit the first index after the range in <code>srcText</code> to copy
|
||||
*/
|
||||
public void replace(int start,
|
||||
int limit,
|
||||
MConstText srcText,
|
||||
int srcStart,
|
||||
int srcLimit,
|
||||
int[] damagedRange) {
|
||||
|
||||
final int insLength = srcLimit - srcStart;
|
||||
if (insLength < 0) {
|
||||
throw new Error("invalid range");
|
||||
}
|
||||
final int origLength = fRunArray.getCurTextLength();
|
||||
deleteText(start, limit, damagedRange);
|
||||
|
||||
if (insLength == 0)
|
||||
return;
|
||||
|
||||
final int oldPosEnd = fRunArray.fPosEnd;
|
||||
AttributeMap origStyle;
|
||||
if (limit < origLength) {
|
||||
origStyle = (fRunArray.fPosEnd>=0)? fStyleTable[fRunArray.fPosEnd] : fFirstStyle;
|
||||
}
|
||||
else {
|
||||
origStyle = srcText.paragraphStyleAt(srcLimit);
|
||||
}
|
||||
|
||||
int paragraphStart = srcStart;
|
||||
int lastPLimit = srcText.paragraphStart(srcLimit);
|
||||
boolean separatorAtEnd = lastPLimit > srcStart && isParagraphBreak(srcText.at(lastPLimit-1));
|
||||
|
||||
if (limit == origLength && lastPLimit == paragraphStart) {
|
||||
if (fRunArray.fPosEnd > 0) {
|
||||
fStyleTable[fRunArray.fPosEnd] = origStyle;
|
||||
}
|
||||
else {
|
||||
fFirstStyle = origStyle;
|
||||
}
|
||||
}
|
||||
else {
|
||||
boolean firstPass = true;
|
||||
while (paragraphStart < lastPLimit) {
|
||||
|
||||
AttributeMap style = srcText.paragraphStyleAt(paragraphStart);
|
||||
int paragraphLimit = srcText.paragraphLimit(paragraphStart);
|
||||
|
||||
if (fRunArray.fPosEnd+1 >= fRunArray.fNegStart)
|
||||
expandStyleTable();
|
||||
|
||||
if (fRunArray.fPosEnd >= 0) {
|
||||
if (!style.equals(fStyleTable[fRunArray.fPosEnd])) {
|
||||
fStyleTable[fRunArray.fPosEnd] = style;
|
||||
if (firstPass) {
|
||||
int pStart = fRunArray.fRunStart[fRunArray.fPosEnd]+1;
|
||||
damagedRange[0] = Math.min(damagedRange[0], pStart);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (!style.equals(fFirstStyle)) {
|
||||
fFirstStyle = style;
|
||||
damagedRange[0] = 0;
|
||||
}
|
||||
|
||||
firstPass = false;
|
||||
|
||||
if (paragraphLimit < lastPLimit || separatorAtEnd) {
|
||||
fRunArray.fRunStart[++fRunArray.fPosEnd] = paragraphLimit - 1 + start - srcStart;
|
||||
}
|
||||
paragraphStart = paragraphLimit;
|
||||
}
|
||||
if (fRunArray.fPosEnd != oldPosEnd) {
|
||||
fStyleTable[fRunArray.fPosEnd] = origStyle;
|
||||
}
|
||||
}
|
||||
|
||||
fRunArray.addToCurTextLength(insLength);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the style of all paragraphs containing offsets in the range [start, limit) to
|
||||
* <tt>style</tt>.
|
||||
*/
|
||||
public boolean modifyParagraphStyles(int start,
|
||||
int limit,
|
||||
StyleModifier modifier,
|
||||
int[] damagedRange) {
|
||||
|
||||
int run = fRunArray.findRunContaining(start-1);
|
||||
int currentPStart;
|
||||
if (run == -1) {
|
||||
currentPStart = 0;
|
||||
}
|
||||
else {
|
||||
currentPStart = fRunArray.getLogicalRunStart(run) + 1;
|
||||
}
|
||||
|
||||
boolean modifiedAnywhere = false;
|
||||
|
||||
for (;;) {
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
if (run < 0) {
|
||||
|
||||
AttributeMap newStyle = modifier.modifyStyle(fFirstStyle);
|
||||
|
||||
if (!newStyle.equals(fFirstStyle)) {
|
||||
fFirstStyle = newStyle;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
AttributeMap newStyle = modifier.modifyStyle(fStyleTable[run]);
|
||||
|
||||
if (!fStyleTable[run].equals(newStyle)) {
|
||||
fStyleTable[run] = newStyle;
|
||||
modified = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (run == fRunArray.fPosEnd) {
|
||||
run = fRunArray.fNegStart;
|
||||
}
|
||||
else {
|
||||
run++;
|
||||
}
|
||||
|
||||
int nextPStart;
|
||||
if (run == fRunArray.getArrayLength()) {
|
||||
nextPStart = fRunArray.getCurTextLength();
|
||||
}
|
||||
else {
|
||||
nextPStart = fRunArray.getLogicalRunStart(run) + 1;
|
||||
}
|
||||
|
||||
if (modified) {
|
||||
modifiedAnywhere = true;
|
||||
damagedRange[0] = Math.min(damagedRange[0], currentPStart);
|
||||
damagedRange[1] = Math.max(damagedRange[1], nextPStart);
|
||||
}
|
||||
|
||||
if (limit <= nextPStart) {
|
||||
break;
|
||||
}
|
||||
else {
|
||||
currentPStart = nextPStart;
|
||||
}
|
||||
}
|
||||
|
||||
return modifiedAnywhere;
|
||||
}
|
||||
|
||||
// private static void dumpParagraphStarts(ParagraphBuffer st) {
|
||||
//
|
||||
// System.out.println("fRunArray.fPosEnd="+st.fRunArray.fPosEnd+", fRunArray.fNegStart="+st.fRunArray.fNegStart+
|
||||
// ", fRunArray.getArrayLength()="+st.fRunArray.getArrayLength()+", fRunArray.getCurTextLength()="+st.fRunArray.getCurTextLength());
|
||||
//
|
||||
// int i;
|
||||
// System.out.print("Positives: ");
|
||||
// for (i=0; i<=st.fRunArray.fPosEnd; i++)
|
||||
// System.out.print(st.fRunArray.fRunStart[i]+" ");
|
||||
//
|
||||
// System.out.print(" Negatives: ");
|
||||
// for (i=st.fRunArray.fNegStart; i<st.fRunArray.getArrayLength(); i++)
|
||||
// System.out.print(st.fRunArray.fRunStart[i]+" ");
|
||||
//
|
||||
// System.out.println(" ");
|
||||
// }
|
||||
|
||||
private static final int kNoRun = -42; // iterator use
|
||||
|
||||
private final class ParagraphIterator /*implements MParagraphIterator*/
|
||||
{
|
||||
ParagraphIterator(int start, int limit)
|
||||
{
|
||||
reset(start, limit, start);
|
||||
}
|
||||
|
||||
public void reset(int start, int limit, int pos)
|
||||
{
|
||||
fStart = start;
|
||||
fLimit = limit;
|
||||
setIterator(fStart, this);
|
||||
}
|
||||
|
||||
public boolean isValid()
|
||||
{
|
||||
return fCurrentRun != kNoRun;
|
||||
}
|
||||
|
||||
public void next()
|
||||
{
|
||||
if (fRunLimit < fLimit) {
|
||||
fCurrentRun++;
|
||||
setIteratorUsingRun(fCurrentRun, this);
|
||||
}
|
||||
else
|
||||
set(0, 0, kNoRun, null);
|
||||
}
|
||||
|
||||
public void prev()
|
||||
{
|
||||
if (fRunStart > fStart) {
|
||||
fCurrentRun--;
|
||||
setIteratorUsingRun(fCurrentRun, this);
|
||||
}
|
||||
else
|
||||
set(0, 0, kNoRun, null);
|
||||
}
|
||||
|
||||
public void set(int pos)
|
||||
{
|
||||
if (pos >= fStart && pos < fLimit) {
|
||||
setIterator(pos, this);
|
||||
} else {
|
||||
set(0, 0, kNoRun, null);
|
||||
}
|
||||
}
|
||||
|
||||
// ParagraphBuffer calls back on this to set iterators
|
||||
void set(int start, int limit, int currentRun, AttributeMap style)
|
||||
{
|
||||
fRunStart = start < fStart ? fStart : start;
|
||||
fRunLimit = limit > fLimit ? fLimit : limit;
|
||||
fCurrentRun = currentRun;
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
public void reset(int start, int limit)
|
||||
{
|
||||
reset(start, limit, start);
|
||||
}
|
||||
|
||||
public void first()
|
||||
{
|
||||
set(fStart);
|
||||
}
|
||||
|
||||
public void last()
|
||||
{
|
||||
set(fLimit - 1);
|
||||
}
|
||||
|
||||
public int rangeStart()
|
||||
{
|
||||
return fStart;
|
||||
}
|
||||
|
||||
public int rangeLimit()
|
||||
{
|
||||
return fLimit;
|
||||
}
|
||||
|
||||
public int rangeLength()
|
||||
{
|
||||
return fLimit - fStart;
|
||||
}
|
||||
|
||||
public int runStart()
|
||||
{
|
||||
return fRunStart;
|
||||
}
|
||||
|
||||
public int runLimit()
|
||||
{
|
||||
return fRunLimit;
|
||||
}
|
||||
|
||||
public int runLength()
|
||||
{
|
||||
return fRunLimit - fRunStart;
|
||||
}
|
||||
|
||||
public AttributeMap style() {
|
||||
|
||||
return fStyle;
|
||||
}
|
||||
|
||||
private int fStart;
|
||||
private int fLimit;
|
||||
private int fRunStart;
|
||||
private int fRunLimit;
|
||||
private int fCurrentRun;
|
||||
private AttributeMap fStyle;
|
||||
}
|
||||
}
|
@ -1,280 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
/**
|
||||
* This class maintains intervals within a piece of text. Interval boundaries
|
||||
* are stored in the fRunStart array. Interval boundaries may have a
|
||||
* positive or negative representation. A positive boundary is given as an offset
|
||||
* from 0. A negative boundary is given as a negative offset from the ned of the text.
|
||||
* The RunArray stores positive boundaries in the entries [0, fPosEnd], and negative
|
||||
* boundaries in the entries [fNegStart, fLength). New boundaries may be inserted into
|
||||
* the undefined middle of the RunArray. If fPosEnd < 0, there are no positive entries.
|
||||
* If fNegStart >= fRunArray.length, there are no negative netries. It's possible to have
|
||||
* a runarray with neither positive or negative entries.
|
||||
*
|
||||
* As an example of how the RunArray works, consider a piece of text with 5 intervals,
|
||||
* where each interval is 3 characters in length. The RunArray for this text could
|
||||
* look like:
|
||||
* fCurTextLength = 15, fPosEnd = 5, fNegStart = 10,
|
||||
* fRunStart = { 0, 3, 6, 9, 12, U, U, U, U, U };
|
||||
* where U is an undefined array element.
|
||||
|
||||
* An equivalent representation would be:
|
||||
* fCurTextLength = 15, fPosEnd = 3, fNegStart = 8,
|
||||
* fRunStart = { 0, 3, 6, U, U, U, U, U, -6, -3 };
|
||||
*
|
||||
* The RunArray class is used in the StyleBuffer and the ParagraphBuffer. In the StyleBuffer,
|
||||
* the entries in fRunStart give the offsets where style runs begin. In the
|
||||
* ParagraphBuffer, the fRunStart entries store offsets of paragraph breaks.
|
||||
*
|
||||
* This class provides methods for shifting the run table to a particular position, expanding the
|
||||
* run table, and returning the index of the run containing a particular offset in the text. All
|
||||
* other functionality is implemented in the RunArray clients.
|
||||
*
|
||||
* RunArray uses FastIntBinarySearch for searches. The searches are constructed on demand in
|
||||
* the findRunContaining method. The searches are invalidated when the run array is shifted;
|
||||
* however, the RunArray can be modified by other classes. Thus, if another class modifies
|
||||
* the entries in fRunArray, or modifies fPosEnd or fNegStart, it is responsible for
|
||||
* calling runStartsChanged.
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
final class RunArray implements Externalizable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
int[] fRunStart;
|
||||
private int fCurTextLength;
|
||||
int fPosEnd, fNegStart;
|
||||
|
||||
transient private FastIntBinarySearch fPosSearch;
|
||||
transient private boolean fPosSearchValid;
|
||||
transient private FastIntBinarySearch fNegSearch;
|
||||
transient private boolean fNegSearchValid;
|
||||
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
|
||||
RunArray(int initialSize, int curTextLength) {
|
||||
|
||||
fRunStart = new int[initialSize];
|
||||
fCurTextLength = curTextLength;
|
||||
fPosEnd = -1;
|
||||
fNegStart = initialSize;
|
||||
|
||||
fPosSearch = new FastIntBinarySearch(fRunStart, 0, 1);
|
||||
fNegSearch = new FastIntBinarySearch(fRunStart, 0, 1);
|
||||
fPosSearchValid = fNegSearchValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this constructor is ONLY for use by the Serialization
|
||||
* mechanism. It does not leave this object in a valid state!
|
||||
*/
|
||||
public RunArray() {
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fRunStart);
|
||||
out.writeInt(fCurTextLength);
|
||||
out.writeInt(fPosEnd);
|
||||
out.writeInt(fNegStart);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
if (in.readInt() != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of RunArray");
|
||||
}
|
||||
fRunStart = (int[]) in.readObject();
|
||||
fCurTextLength = in.readInt();
|
||||
fPosEnd = in.readInt();
|
||||
fNegStart = in.readInt();
|
||||
|
||||
fPosSearch = new FastIntBinarySearch(fRunStart, 0, 1);
|
||||
fNegSearch = new FastIntBinarySearch(fRunStart, 0, 1);
|
||||
fPosSearchValid = fNegSearchValid = false;
|
||||
}
|
||||
|
||||
public int getCurTextLength() {
|
||||
|
||||
return fCurTextLength;
|
||||
}
|
||||
|
||||
public void setCurTextLength(int curTextLength) {
|
||||
|
||||
fCurTextLength = curTextLength;
|
||||
}
|
||||
|
||||
public void addToCurTextLength(int delta) {
|
||||
|
||||
fCurTextLength += delta;
|
||||
}
|
||||
|
||||
public void runStartsChanged() {
|
||||
|
||||
fPosSearchValid = fNegSearchValid = false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the last valid run.
|
||||
*/
|
||||
int lastRun() {
|
||||
|
||||
return (fNegStart == fRunStart.length)? fPosEnd : fRunStart.length-1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the length of the run array. Replaces old fLength member.
|
||||
*/
|
||||
int getArrayLength() {
|
||||
|
||||
return fRunStart.length;
|
||||
}
|
||||
|
||||
/**
|
||||
* Shifts style table such that the last positive run
|
||||
* starts before pos.
|
||||
*/
|
||||
void shiftTableTo(int pos) {
|
||||
|
||||
int oldPosEnd = fPosEnd;
|
||||
|
||||
while (fPosEnd >= 0 && fRunStart[fPosEnd] >= pos) {
|
||||
|
||||
fNegStart--;
|
||||
fRunStart[fNegStart] = fRunStart[fPosEnd] - fCurTextLength;
|
||||
fPosEnd--;
|
||||
|
||||
}
|
||||
|
||||
pos -= fCurTextLength;
|
||||
|
||||
while (fNegStart<fRunStart.length && fRunStart[fNegStart] < pos) {
|
||||
|
||||
fPosEnd++;
|
||||
fRunStart[fPosEnd] = fRunStart[fNegStart] + fCurTextLength;
|
||||
fNegStart++;
|
||||
}
|
||||
|
||||
if (oldPosEnd != fPosEnd) {
|
||||
fPosSearchValid = fNegSearchValid = false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns index of style run containing pos. If first style run starts before
|
||||
* pos, -1 is returned. If pos is greater than text length, lastrun is returned.
|
||||
*/
|
||||
int findRunContaining(int pos) {
|
||||
|
||||
FastIntBinarySearch search;
|
||||
final int length = fRunStart.length;
|
||||
|
||||
if (fNegStart < length && (pos-fCurTextLength >= fRunStart[fNegStart])) {
|
||||
|
||||
pos -= fCurTextLength;
|
||||
|
||||
if (!fNegSearchValid) {
|
||||
fNegSearch.setData(fRunStart, fNegStart, length-fNegStart);
|
||||
}
|
||||
search = fNegSearch;
|
||||
}
|
||||
else if (fPosEnd >= 0) {
|
||||
|
||||
if (!fPosSearchValid) {
|
||||
fPosSearch.setData(fRunStart, 0, fPosEnd+1);
|
||||
}
|
||||
search = fPosSearch;
|
||||
}
|
||||
else
|
||||
return -1;
|
||||
|
||||
int run = search.findIndex(pos);
|
||||
|
||||
return run;
|
||||
}
|
||||
|
||||
int getLogicalRunStart(int run) {
|
||||
|
||||
if (run == -1) {
|
||||
return 0;
|
||||
}
|
||||
else if (run == fRunStart.length) {
|
||||
return fCurTextLength;
|
||||
}
|
||||
else {
|
||||
if (run <= fPosEnd) {
|
||||
return fRunStart[run];
|
||||
}
|
||||
else if (run >= fNegStart) {
|
||||
return fRunStart[run] + fCurTextLength;
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Illegal run");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increases size of run table. Current implementation doubles the run table's size.
|
||||
*/
|
||||
void expandRunTable() {
|
||||
|
||||
resizeRunTable(fRunStart.length * 2);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the minimum number of elements possible in fRunStart.
|
||||
*/
|
||||
private int getMinSize() {
|
||||
|
||||
return Math.max(fPosEnd + (fRunStart.length-fNegStart) + 1, 1);
|
||||
}
|
||||
|
||||
void compress() {
|
||||
|
||||
int minSize = getMinSize();
|
||||
if (fRunStart.length > minSize) {
|
||||
resizeRunTable(minSize);
|
||||
}
|
||||
}
|
||||
|
||||
private void resizeRunTable(int newSize) {
|
||||
|
||||
if (newSize < getMinSize()) {
|
||||
throw new IllegalArgumentException("Attempt to make RunArray too small.");
|
||||
}
|
||||
|
||||
final int oldLength = fRunStart.length;
|
||||
|
||||
int newRunStart[] = new int[newSize];
|
||||
System.arraycopy(fRunStart, 0, newRunStart, 0, fPosEnd+1);
|
||||
int newNegStart = newRunStart.length - (oldLength-fNegStart);
|
||||
System.arraycopy(fRunStart, fNegStart, newRunStart, newNegStart, (oldLength-fNegStart));
|
||||
|
||||
fNegStart = newNegStart;
|
||||
fRunStart = newRunStart;
|
||||
|
||||
fPosSearchValid = fNegSearchValid = false;
|
||||
}
|
||||
}
|
@ -1,372 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.util.Vector;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* This class is a standard implementation of MTabRuler.
|
||||
* It can have a finite number of client-specified TabStops. After
|
||||
* the client-specified TabStops, all TabStops have type
|
||||
* <code>TabStop.kAuto</code> and are at the autospace intervals.
|
||||
* @see TabStop
|
||||
*/
|
||||
public final class StandardTabRuler extends MTabRuler
|
||||
implements Externalizable
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
private static final TabStop AUTO_ZERO = new TabStop(0, TabStop.kAuto);
|
||||
|
||||
private TabStop[] fTabs = null;
|
||||
private int fAutoSpacing = 36; // every 1/2 inch.
|
||||
|
||||
/**
|
||||
* Create a StandardTabRuler with only auto tabs, with spacing of 36.
|
||||
*/
|
||||
public StandardTabRuler()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StandardTabRuler with only auto tabs, with the
|
||||
* given autoSpacing.
|
||||
* @param autoSpacing the autoSpacing for this tab ruler
|
||||
*/
|
||||
public StandardTabRuler(int autoSpacing)
|
||||
{
|
||||
fAutoSpacing = autoSpacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StandardTabRuler. The first TabStops on the ruler will be
|
||||
* the TabStops in the <code>tabs</code> array. After these tabs all
|
||||
* tabs are auto tabs.
|
||||
* @param tabs an array of TabStops. The TabStops in the array must
|
||||
* be in strictly increasing order (of positions), and cannot have
|
||||
* type <code>TabStop.kAuto</code>.
|
||||
* @param autoSpacing the autoSpacing interval to use after the last
|
||||
* client-specified tab.
|
||||
*/
|
||||
public StandardTabRuler(TabStop[] tabs, int autoSpacing)
|
||||
{
|
||||
if (tabs.length > 0) {
|
||||
validateTabArray(tabs);
|
||||
fTabs = (TabStop[]) tabs.clone();
|
||||
}
|
||||
else {
|
||||
fTabs = null;
|
||||
}
|
||||
fAutoSpacing = autoSpacing;
|
||||
}
|
||||
|
||||
/** Tabs as provided, then autoSpacing after the last tab to eternity. Use this constructor when
|
||||
munging a ruler, it does no validation on the tabs in the vector. Vector may not be null. */
|
||||
|
||||
/*public*/ StandardTabRuler(Vector v, int autoSpacing)
|
||||
{
|
||||
fTabs = tabArrayFromVector(v);
|
||||
fAutoSpacing = autoSpacing;
|
||||
}
|
||||
|
||||
/** Construct from another ruler. No validation. Ruler may not be null. */
|
||||
|
||||
/*public*/ StandardTabRuler(MTabRuler ruler)
|
||||
{
|
||||
if (ruler == null) {
|
||||
throw new IllegalArgumentException("ruler may not be null");
|
||||
}
|
||||
|
||||
fTabs = tabArrayFromVector(vectorFromTabRuler(ruler));
|
||||
fAutoSpacing = ruler.autoSpacing();
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
int version = in.readInt();
|
||||
if (version != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of StyledText: " + version);
|
||||
}
|
||||
fTabs = (TabStop[]) in.readObject();
|
||||
fAutoSpacing = in.readInt();
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fTabs);
|
||||
out.writeInt(fAutoSpacing);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return first tab in the ruler. If an autoTab, it is at position zero, and
|
||||
* all subsequent tabs will be autotabs at autoSpacing intervals.
|
||||
*/
|
||||
public TabStop firstTab()
|
||||
{
|
||||
if (fTabs != null && fTabs.length > 0) {
|
||||
return fTabs[0];
|
||||
}
|
||||
|
||||
return AUTO_ZERO;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first tab in the ruler with fPosition > position. If it is an
|
||||
* autotab, it is at an increment of autoSpacing, and all subsequent tabs will be
|
||||
* autotabs at autoSpacing intervals.
|
||||
* @param position the position of the TabStop returned will be greater than this parameter
|
||||
*/
|
||||
public TabStop nextTab(int position)
|
||||
{
|
||||
if (fTabs != null) {
|
||||
for (int i = 0; i < fTabs.length; ++i) {
|
||||
if (position < fTabs[i].getPosition())
|
||||
return fTabs[i];
|
||||
}
|
||||
}
|
||||
|
||||
if (position >= 4000) { // debug: sanity check
|
||||
System.out.println("auto tab past 4000");
|
||||
}
|
||||
|
||||
return new TabStop(((position / fAutoSpacing) + 1) * fAutoSpacing, TabStop.kAuto);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the interval for autotabs.
|
||||
*/
|
||||
public int autoSpacing()
|
||||
{
|
||||
return fAutoSpacing;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this to another Object. Returns true if the object
|
||||
* is an MTabRuler with the same autoSpacing and tabs.
|
||||
*/
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o == this) {
|
||||
return true;
|
||||
}
|
||||
else if (o == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
MTabRuler rhs;
|
||||
try {
|
||||
rhs = (MTabRuler)o;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (fAutoSpacing != rhs.autoSpacing())
|
||||
return false;
|
||||
|
||||
TabStop rhsTab = rhs.firstTab();
|
||||
|
||||
if (fTabs != null) {
|
||||
for (int i = 0; i < fTabs.length; ++i) {
|
||||
if (!fTabs[i].equals(rhsTab))
|
||||
return false;
|
||||
|
||||
rhsTab = rhs.nextTab(rhsTab.getPosition());
|
||||
}
|
||||
}
|
||||
|
||||
return rhsTab.getType() == TabStop.kAuto;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return debug information about this tab ruler.
|
||||
*/
|
||||
public String toString()
|
||||
{
|
||||
StringBuffer buffer = new StringBuffer(super.toString());
|
||||
buffer.append(" auto: ");
|
||||
buffer.append(Integer.toString(fAutoSpacing));
|
||||
|
||||
if (fTabs != null) {
|
||||
for (int i = 0; i < fTabs.length; ++i) {
|
||||
buffer.append(fTabs[i].toString());
|
||||
}
|
||||
}
|
||||
|
||||
return buffer.toString();
|
||||
}
|
||||
|
||||
/** Utility to convert a vector of tabs to an array. */
|
||||
|
||||
private static TabStop[] tabArrayFromVector(Vector v)
|
||||
{
|
||||
int count = v.size();
|
||||
TabStop[] tabs = new TabStop[count];
|
||||
for (int i = 0; i < count; ++i) {
|
||||
tabs[i] = (TabStop)v.elementAt(i);
|
||||
}
|
||||
|
||||
return tabs;
|
||||
}
|
||||
|
||||
/** Utility to convert a ruler to a vector of tabs, for munging. */
|
||||
|
||||
private static Vector vectorFromTabRuler(MTabRuler ruler)
|
||||
{
|
||||
Vector v = new Vector();
|
||||
for (TabStop tab = ruler.firstTab(); tab != null && tab.getType() != TabStop.kAuto; tab = ruler.nextTab(tab.getPosition())) {
|
||||
v.addElement(tab);
|
||||
}
|
||||
|
||||
return v;
|
||||
}
|
||||
|
||||
/** Utility to validate an array of tabs. The array must not be null, must not contain null
|
||||
entries, must not be kAuto, and positions must in increasing order. */
|
||||
|
||||
private static void validateTabArray(TabStop[] tabs)
|
||||
{
|
||||
int pos = Integer.MIN_VALUE;
|
||||
for (int i = 0; i < tabs.length; ++i) {
|
||||
if (tabs[i].getType() == TabStop.kAuto) {
|
||||
throw new IllegalArgumentException("can't explicitly specify an auto tab.");
|
||||
}
|
||||
int nextpos = tabs[i].getPosition();
|
||||
if (nextpos <= pos) {
|
||||
throw new IllegalArgumentException("tab positions must be in increasing order.");
|
||||
}
|
||||
pos = nextpos;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to the given ruler, except with the
|
||||
* given tab added.
|
||||
* @param ruler the original ruler. The MTabRuler will be the same as
|
||||
* this except for the additional tab. <code>ruler</code> is not modified.
|
||||
* @param tabToAdd the tab to add to the new tab ruler
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
/*public*/ static MTabRuler addTabToRuler(MTabRuler ruler, TabStop tabToAdd)
|
||||
{
|
||||
if (ruler == null || tabToAdd == null)
|
||||
throw new IllegalArgumentException("ruler and tabToAdd may not be null");
|
||||
|
||||
Vector vector = new Vector();
|
||||
|
||||
int pos = 0;
|
||||
boolean added = false;
|
||||
for (TabStop tab = ruler.firstTab(); tab.getType() != TabStop.kAuto; tab = ruler.nextTab(pos)) {
|
||||
pos = tab.getPosition();
|
||||
|
||||
if (!added && pos >= tabToAdd.getPosition()) {
|
||||
if (pos == tabToAdd.getPosition())
|
||||
tab = null;
|
||||
vector.addElement(tabToAdd);
|
||||
added = true;
|
||||
}
|
||||
|
||||
if (tab != null)
|
||||
vector.addElement(tab);
|
||||
}
|
||||
if (!added)
|
||||
vector.addElement(tabToAdd);
|
||||
|
||||
return new StandardTabRuler(vector, ruler.autoSpacing());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to the given ruler, except with the
|
||||
* given tab removed.
|
||||
* @param ruler the original ruler. The MTabRuler will be the same as
|
||||
* this except for the removed tab. <code>ruler</code> is not modified.
|
||||
* @param position the position of the tab to remove from the new tab ruler
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
/*public*/ static MTabRuler removeTabFromRuler(MTabRuler ruler, int position)
|
||||
{
|
||||
if (ruler == null)
|
||||
throw new IllegalArgumentException("ruler may not be null");
|
||||
|
||||
Vector vector = new Vector();
|
||||
|
||||
int pos = 0;
|
||||
boolean removed = false;
|
||||
for (TabStop tab = ruler.firstTab(); tab.getType() != TabStop.kAuto; tab = ruler.nextTab(pos)) {
|
||||
pos = tab.getPosition();
|
||||
|
||||
if (!removed && pos >= position) {
|
||||
if (pos == position) {
|
||||
removed = true;
|
||||
continue; // skip this tab and continue with the remainder
|
||||
}
|
||||
break; // we didn't remove a tab, but skipped position, so don't bother with the rest
|
||||
}
|
||||
|
||||
vector.addElement(tab);
|
||||
}
|
||||
if (!removed) // no change
|
||||
return ruler;
|
||||
|
||||
if (vector.size() == 0)
|
||||
return new StandardTabRuler(ruler.autoSpacing());
|
||||
|
||||
return new StandardTabRuler(vector, ruler.autoSpacing());
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a tab ruler identical to the given ruler, except with the
|
||||
* tab at position <code>fromPosition</code> moved to position
|
||||
* <code>toPosition</code>.
|
||||
* @param ruler the original ruler. The MTabRuler will be the same as
|
||||
* this except for the moved tab. <code>ruler</code> is not modified.
|
||||
* @param fromPosition the position of the tab to move
|
||||
* @param toPosition the new position of the tab
|
||||
* @return an MTabRuler resulting from this operation
|
||||
*/
|
||||
/*public*/ static MTabRuler moveTabOnRuler(MTabRuler ruler, int fromPosition, int toPosition)
|
||||
{
|
||||
if (ruler == null)
|
||||
throw new IllegalArgumentException("ruler may not be null");
|
||||
|
||||
Vector vector = new Vector();
|
||||
|
||||
int pos = 0;
|
||||
boolean moved = false;
|
||||
for (TabStop tab = ruler.firstTab(); tab.getType() != TabStop.kAuto; tab = ruler.nextTab(pos)) {
|
||||
pos = tab.getPosition();
|
||||
|
||||
if (!moved && pos == fromPosition) {
|
||||
moved = true;
|
||||
tab = new TabStop(toPosition, tab.getType()); // copy it
|
||||
}
|
||||
|
||||
vector.addElement(tab);
|
||||
}
|
||||
if (!moved) // no change
|
||||
return ruler;
|
||||
|
||||
return new StandardTabRuler(vector, ruler.autoSpacing());
|
||||
}
|
||||
|
||||
}
|
@ -1,669 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/*
|
||||
8/2/96
|
||||
Added setIteratorUsingRun method
|
||||
|
||||
8/5/96
|
||||
No longer has to be constructed with an MText.
|
||||
|
||||
8/8/96
|
||||
Added replace method, which reads styles from a StyleRunIterator.
|
||||
Also, added a constructor which takes a StyleRunIterator.
|
||||
These methods are for copy/paste support.
|
||||
8/16/96
|
||||
StyleBuffer now takes MConstText instead of MText where possible.
|
||||
|
||||
10/23/96
|
||||
Some old commented-out code removed for aesthetic reasons.
|
||||
|
||||
7/31/98 Switched to AttributeMap
|
||||
*/
|
||||
|
||||
/**
|
||||
* StyleBuffer implements <tt>MStyleBuffer</tt>. It maintains
|
||||
* <tt>AttributeMap</tt> objects to apply to the text in an <tt>MText</tt> object,
|
||||
* and the
|
||||
* intervals on which those styles apply.
|
||||
* <p>
|
||||
* StyleBuffer stores the intervals on which styles apply in a <tt>RunArray</tt>
|
||||
* object (see <tt>RunArray</tt> for more information). The styles are stored in
|
||||
* an array of <tt>AttributeMap</tt> objects.
|
||||
* <p>
|
||||
* <tt>RunArray</tt> maintains an array of integers which represent offsets into text.
|
||||
* The array has a "positive" region in which offsets are given as positive distances
|
||||
* from the start of the text, and a "negative" region in which offsets are given as
|
||||
* negative distances from the end of the text. Between the positive and negative regions
|
||||
* is a gap, into which new offsets may be inserted. This storage scheme allows for
|
||||
* efficient response to a series of editing operations which occur in the same area of the
|
||||
* text.
|
||||
* <p>
|
||||
* StyleBuffer uses the offsets in <tt>RunArray</tt> as the boundaries of style runs.
|
||||
* A style run begins at each offset in <tt>RunArray</tt>, and each style run continues to
|
||||
* the next offset. The style array is kept in sync with the array of offsets in <tt>RunArray</tt>;
|
||||
* that is, the style which begins at RunArray[i] is stored in StyleArray[i].
|
||||
* <p>
|
||||
* The first entry in the <tt>RunArray</tt> is always 0.
|
||||
*
|
||||
* @author John Raley
|
||||
*
|
||||
* @see AttributeMap
|
||||
* @see MText
|
||||
* @see RunArray
|
||||
*/
|
||||
|
||||
final class StyleBuffer extends MStyleBuffer implements Externalizable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Creates a new style buffer with length equal to the length of <tt>text</tt>,
|
||||
* and with a single run of <tt>defaultStyle</tt>.
|
||||
*/
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
private static final int kInitialSize = 10;
|
||||
private RunArray fRunArray;
|
||||
|
||||
private AttributeMap fStyleTable[];
|
||||
|
||||
StyleBuffer(MConstText text, AttributeMap initialStyle) {
|
||||
|
||||
this(text.length(), initialStyle);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a new style buffer with length <tt>initialLength</tt> and with a
|
||||
* single run of <tt>defaultStyle</tt>.
|
||||
*/
|
||||
|
||||
StyleBuffer(int initialLength, AttributeMap initialStyle) {
|
||||
|
||||
fRunArray = new RunArray(kInitialSize, initialLength);
|
||||
fRunArray.fPosEnd = 0;
|
||||
fRunArray.fRunStart[0] = 0;
|
||||
|
||||
fStyleTable = new AttributeMap[kInitialSize]; // do I really want to do this???
|
||||
|
||||
fStyleTable[0] = initialStyle;
|
||||
}
|
||||
|
||||
/**
|
||||
* Note: this constructor is ONLY for use by the Serialization
|
||||
* mechanism. It does not leave this object in a valid state!
|
||||
*/
|
||||
public StyleBuffer() {
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
compress();
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fRunArray);
|
||||
out.writeObject(fStyleTable);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
if (in.readInt() != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of StyleBuffer");
|
||||
}
|
||||
fRunArray = (RunArray) in.readObject();
|
||||
fStyleTable = (AttributeMap[]) in.readObject();
|
||||
}
|
||||
|
||||
/**
|
||||
* Shift style and run tables such that the last positive run begins before the given position.
|
||||
* Since there is always a run start at 0, this method ensures that the first run will not be shifted.
|
||||
* This is called by: <tt>insertText</tt> and <tt>deleteText</tt>.
|
||||
* @param pos a position in the text.
|
||||
*/
|
||||
|
||||
private void shiftTableTo(int pos) {
|
||||
|
||||
if (pos == 0)
|
||||
pos = 1;
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
int oldPosEnd = fRunArray.fPosEnd;
|
||||
|
||||
fRunArray.shiftTableTo(pos);
|
||||
|
||||
if (oldPosEnd > fRunArray.fPosEnd)
|
||||
System.arraycopy(fStyleTable, fRunArray.fPosEnd+1,
|
||||
fStyleTable, fRunArray.fNegStart,
|
||||
oldPosEnd-fRunArray.fPosEnd);
|
||||
else if (oldNegStart < fRunArray.fNegStart)
|
||||
System.arraycopy(fStyleTable, oldNegStart,
|
||||
fStyleTable, oldPosEnd+1,
|
||||
fRunArray.fNegStart-oldNegStart);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the style table to reflect a change in the RunArray's size.
|
||||
*/
|
||||
private void handleArrayResize(int oldNegStart) {
|
||||
|
||||
AttributeMap newStyleTable[] = new AttributeMap[fRunArray.getArrayLength()];
|
||||
System.arraycopy(fStyleTable, 0, newStyleTable, 0, fRunArray.fPosEnd+1);
|
||||
System.arraycopy(fStyleTable, oldNegStart, newStyleTable, fRunArray.fNegStart, (fRunArray.getArrayLength()-fRunArray.fNegStart));
|
||||
fStyleTable = newStyleTable;
|
||||
}
|
||||
|
||||
/**
|
||||
* Minimize the amount of storage used by this object.
|
||||
*/
|
||||
void compress() {
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
fRunArray.compress();
|
||||
if (fRunArray.fNegStart != oldNegStart) {
|
||||
handleArrayResize(oldNegStart);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Increase the storage capacity of the style and run tables if no room remains.
|
||||
*/
|
||||
private void expandStyleTableIfFull() {
|
||||
|
||||
if (fRunArray.fPosEnd + 1 == fRunArray.fNegStart) {
|
||||
|
||||
int oldNegStart = fRunArray.fNegStart;
|
||||
fRunArray.expandRunTable();
|
||||
handleArrayResize(oldNegStart);
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public MStyleRunIterator createStyleRunIterator(int start, int limit) {
|
||||
|
||||
return new StyleRunIterator(start, limit);
|
||||
}
|
||||
*/
|
||||
/**
|
||||
* Respond to an insertion in the text. The length of the last style run which
|
||||
* begins before <tt>start</tt> is increased by <tt>length</tt>. The run table
|
||||
* is shifted such that the run into which text was inserted is the last positive run.
|
||||
* This implementation assumes that all styles propogate.
|
||||
* @param start the offset where the insertion began
|
||||
* @param length the number of characters inserted
|
||||
*/
|
||||
public void insertText(int start, int limit) {
|
||||
|
||||
shiftTableTo(start);
|
||||
fRunArray.addToCurTextLength(limit - start);
|
||||
}
|
||||
|
||||
/**
|
||||
* Respond to a deletion in the text. The last style run before
|
||||
* <tt>start</tt> is truncated to end at <tt>start</tt>. The
|
||||
* style run containing (<tt>start</tt>+<tt>length</tt>) is set to begin
|
||||
* at (<tt>start</tt>+<tt>length</tt>). Runs in between are deleted.
|
||||
* If the deletion occurs entirely within one style run, the length of the style
|
||||
* run is reduced by <tt>length</tt>.
|
||||
* This implementation assumes that all styles propogate.
|
||||
* This method shifts the run table such that the run in which the delete began
|
||||
* is the last positive run. Other methods depend on this "side effect".
|
||||
* @param start the offset where the deletion began
|
||||
* @param length the offset where the deletion stopped
|
||||
*/
|
||||
public void deleteText(int start, int limit) {
|
||||
|
||||
int length = limit - start;
|
||||
|
||||
// An optimization - if a whole run wasn't deleted we don't
|
||||
// need to check for run merging, which could be expensive.
|
||||
boolean wholeRunDeleted = false;
|
||||
|
||||
shiftTableTo(start);
|
||||
|
||||
int firstRunLimit = fRunArray.getCurTextLength();
|
||||
if (fRunArray.fNegStart < fRunArray.getArrayLength())
|
||||
firstRunLimit += fRunArray.fRunStart[fRunArray.fNegStart];
|
||||
|
||||
if (limit == fRunArray.getCurTextLength()) {
|
||||
fRunArray.fNegStart = fRunArray.getArrayLength();
|
||||
}
|
||||
else if (limit >= firstRunLimit) {
|
||||
|
||||
int end = fRunArray.findRunContaining(limit);
|
||||
if (end != fRunArray.fPosEnd) {
|
||||
fRunArray.fRunStart[end] = limit - fRunArray.getCurTextLength();
|
||||
fRunArray.fNegStart = end;
|
||||
wholeRunDeleted = true;
|
||||
}
|
||||
}
|
||||
|
||||
if (fRunArray.fNegStart != fRunArray.getArrayLength()) {
|
||||
if (start == 0 && limit >= firstRunLimit) {
|
||||
// the first style run was deleted; move first "negative" run into
|
||||
// first position
|
||||
fStyleTable[0] = fStyleTable[fRunArray.fNegStart++];
|
||||
}
|
||||
else if (wholeRunDeleted) {
|
||||
if (fStyleTable[fRunArray.fNegStart].equals(fStyleTable[fRunArray.fPosEnd])) {
|
||||
// merge style runs
|
||||
fRunArray.fNegStart++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fRunArray.addToCurTextLength(-length);
|
||||
|
||||
fRunArray.runStartsChanged();
|
||||
//System.out.println("In deleteText: number of style runs = " + numRuns(this));
|
||||
}
|
||||
|
||||
/**
|
||||
* Arrange style table so that old styles in the provided range are removed, and
|
||||
* new styles can be inserted into the insertion gap.
|
||||
* After calling this method, new style starts and styles may be placed
|
||||
* in the insertion gaps of fRunArray.fStyleStart and fStyleTable.
|
||||
* @param start offset in the text where insertion operation begins
|
||||
* @param limit offset in the text where previous styles resume
|
||||
*/
|
||||
private void prepareStyleInsert(int start) {
|
||||
|
||||
if (start == 0) {
|
||||
|
||||
// fRunArray.fPosEnd should be 0 if we're in this branch.
|
||||
|
||||
if (fRunArray.getCurTextLength() > 0) {
|
||||
|
||||
/* Move first existing style run to negative end of buffer.
|
||||
Don't do this if length==0; that is, if there is no real
|
||||
style run at 0.
|
||||
*/
|
||||
|
||||
fRunArray.fNegStart--;
|
||||
fStyleTable[fRunArray.fNegStart] = fStyleTable[0];
|
||||
fRunArray.fRunStart[fRunArray.fNegStart] = -fRunArray.getCurTextLength();
|
||||
}
|
||||
|
||||
fRunArray.fPosEnd = -1;
|
||||
}
|
||||
else {
|
||||
|
||||
// consistency check: start should be in current gap
|
||||
if (fRunArray.fRunStart[fRunArray.fPosEnd] >= start) {
|
||||
throw new Error("Inconsistent state! Start should be within insertion gap.");
|
||||
}
|
||||
|
||||
int endOfInsertionGap = fRunArray.getCurTextLength();
|
||||
if (fRunArray.fNegStart < fRunArray.getArrayLength()) {
|
||||
endOfInsertionGap += fRunArray.fRunStart[fRunArray.fNegStart];
|
||||
}
|
||||
|
||||
if (endOfInsertionGap < start) {
|
||||
throw new Error("Inconsistent state! Start should be within insertion gap.");
|
||||
}
|
||||
|
||||
// if no break at start (on negative end of buffer) make one
|
||||
|
||||
if (endOfInsertionGap != start) {
|
||||
|
||||
// split style run in insertion gap
|
||||
|
||||
expandStyleTableIfFull();
|
||||
|
||||
fRunArray.fNegStart--;
|
||||
fStyleTable[fRunArray.fNegStart] = fStyleTable[fRunArray.fPosEnd];
|
||||
fRunArray.fRunStart[fRunArray.fNegStart] = start - fRunArray.getCurTextLength();
|
||||
|
||||
//System.out.println("splitting run.");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean modifyStyles(int start,
|
||||
int limit,
|
||||
StyleModifier modifier,
|
||||
int[] damagedRange) {
|
||||
|
||||
if (limit == start) {
|
||||
return false;
|
||||
}
|
||||
|
||||
shiftTableTo(start);
|
||||
|
||||
int currentRunStart = start;
|
||||
AttributeMap oldStyle;
|
||||
AttributeMap mergeStyle = fStyleTable[fRunArray.fPosEnd];
|
||||
|
||||
if (fRunArray.fNegStart < fRunArray.getArrayLength() &&
|
||||
fRunArray.fRunStart[fRunArray.fNegStart]+fRunArray.getCurTextLength() == start) {
|
||||
|
||||
oldStyle = fStyleTable[fRunArray.fNegStart];
|
||||
++fRunArray.fNegStart;
|
||||
}
|
||||
else {
|
||||
oldStyle = mergeStyle;
|
||||
}
|
||||
|
||||
boolean modifiedAnywhere = false;
|
||||
for(;;) {
|
||||
|
||||
boolean modified = false;
|
||||
|
||||
// push new style into gap on positive side
|
||||
AttributeMap newStyle = modifier.modifyStyle(oldStyle);
|
||||
if (damagedRange != null && !newStyle.equals(oldStyle)) {
|
||||
modified = modifiedAnywhere = true;
|
||||
damagedRange[0] = Math.min(currentRunStart, damagedRange[0]);
|
||||
}
|
||||
|
||||
if (!newStyle.equals(mergeStyle)) {
|
||||
|
||||
if (currentRunStart != 0) {
|
||||
expandStyleTableIfFull();
|
||||
++fRunArray.fPosEnd;
|
||||
}
|
||||
|
||||
fStyleTable[fRunArray.fPosEnd] = newStyle;
|
||||
fRunArray.fRunStart[fRunArray.fPosEnd] = currentRunStart;
|
||||
}
|
||||
|
||||
mergeStyle = newStyle;
|
||||
|
||||
int nextRunStart = fRunArray.getLogicalRunStart(fRunArray.fNegStart);
|
||||
|
||||
if (limit > nextRunStart) {
|
||||
oldStyle = fStyleTable[fRunArray.fNegStart];
|
||||
currentRunStart = nextRunStart;
|
||||
if (modified) {
|
||||
damagedRange[1] = Math.max(currentRunStart, damagedRange[1]);
|
||||
}
|
||||
++fRunArray.fNegStart;
|
||||
}
|
||||
else {
|
||||
if (limit < nextRunStart && !oldStyle.equals(mergeStyle)) {
|
||||
expandStyleTableIfFull();
|
||||
++fRunArray.fPosEnd;
|
||||
fStyleTable[fRunArray.fPosEnd] = oldStyle;
|
||||
fRunArray.fRunStart[fRunArray.fPosEnd] = limit;
|
||||
}
|
||||
if (modified) {
|
||||
damagedRange[1] = Math.max(limit, damagedRange[1]);
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
// merge last run if needed
|
||||
if ((fRunArray.fNegStart < fRunArray.getArrayLength()) &&
|
||||
(fStyleTable[fRunArray.fNegStart].equals(fStyleTable[fRunArray.fPosEnd]))) {
|
||||
fRunArray.fNegStart++;
|
||||
}
|
||||
|
||||
fRunArray.runStartsChanged();
|
||||
|
||||
return modifiedAnywhere;
|
||||
}
|
||||
|
||||
public int styleStart(int pos) {
|
||||
|
||||
if (pos == fRunArray.getCurTextLength()) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
return fRunArray.getLogicalRunStart(fRunArray.findRunContaining(pos));
|
||||
}
|
||||
|
||||
public int styleLimit(int pos) {
|
||||
|
||||
if (pos == fRunArray.getCurTextLength()) {
|
||||
return pos;
|
||||
}
|
||||
|
||||
int run = fRunArray.findRunContaining(pos);
|
||||
|
||||
if (run == fRunArray.fPosEnd) {
|
||||
run = fRunArray.fNegStart;
|
||||
}
|
||||
else {
|
||||
++run;
|
||||
}
|
||||
|
||||
return fRunArray.getLogicalRunStart(run);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return style at location <tt>pos</tt>.
|
||||
* @param pos an offset into the text
|
||||
* @returns the style of the character at <tt>offset</tt>
|
||||
*/
|
||||
public AttributeMap styleAt(int pos) {
|
||||
|
||||
return fStyleTable[ fRunArray.findRunContaining(pos) ];
|
||||
}
|
||||
|
||||
/*
|
||||
* Set run start, run length, and run value in an iterator. This method is
|
||||
* only called by a <tt>StyleRunIterator</tt>.
|
||||
* @param pos an offset into the text. The iterator's run start and run limit are
|
||||
* set to the run containing <tt>pos</tt>.
|
||||
* @param iter the iterator to set
|
||||
*/
|
||||
void setIterator(int pos, StyleRunIterator iter) {
|
||||
|
||||
if ((pos < 0) || (pos > fRunArray.getCurTextLength())) {
|
||||
|
||||
iter.set(null, 0, 0, kNoRun);
|
||||
return;
|
||||
}
|
||||
|
||||
int run = fRunArray.findRunContaining(pos);
|
||||
|
||||
setIteratorUsingRun(run, iter);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set run start, run length, and run value in an iterator. This method is
|
||||
* only called by a <tt>StyleRunIterator</tt>.
|
||||
* @param run the index of the run to which the iterator should be set
|
||||
* @param iter the iterator to set
|
||||
*/
|
||||
private void setIteratorUsingRun(int run, StyleRunIterator iter) {
|
||||
|
||||
int lastValidRun = fRunArray.lastRun();
|
||||
|
||||
if (run < 0 || run > lastValidRun) {
|
||||
|
||||
iter.set(null, 0, 0, kNoRun);
|
||||
return;
|
||||
}
|
||||
|
||||
if (run == fRunArray.fPosEnd+1)
|
||||
run = fRunArray.fNegStart;
|
||||
else if (run == fRunArray.fNegStart-1)
|
||||
run = fRunArray.fPosEnd;
|
||||
|
||||
int runStart = fRunArray.fRunStart[run];
|
||||
if (runStart < 0)
|
||||
runStart += fRunArray.getCurTextLength();
|
||||
|
||||
AttributeMap style = fStyleTable[run];
|
||||
|
||||
int nextRun;
|
||||
|
||||
if (run == fRunArray.fPosEnd)
|
||||
nextRun = fRunArray.fNegStart;
|
||||
else
|
||||
nextRun = run + 1;
|
||||
|
||||
int runLimit;
|
||||
|
||||
if (nextRun >= fRunArray.getArrayLength())
|
||||
runLimit = fRunArray.getCurTextLength();
|
||||
else {
|
||||
runLimit = fRunArray.fRunStart[nextRun];
|
||||
if (runLimit < 0)
|
||||
runLimit += fRunArray.getCurTextLength();
|
||||
}
|
||||
|
||||
//System.out.println("setIterator: pos="+pos+", runStart="+runStart+", runLimit="+runLimit+
|
||||
// ", run="+run+", fPosEnd="+fPosEnd);
|
||||
|
||||
iter.set(style, runStart, runLimit, run);
|
||||
}
|
||||
|
||||
public void replace(int start, int limit, MConstText srcText, int srcStart, int srcLimit)
|
||||
{
|
||||
deleteText(start, limit);
|
||||
if (srcStart == srcLimit)
|
||||
return;
|
||||
prepareStyleInsert(start);
|
||||
for (int j2 = srcStart; j2 < srcLimit; j2 = srcText.characterStyleLimit(j2))
|
||||
{
|
||||
AttributeMap attributeMap = srcText.characterStyleAt(j2);
|
||||
if (fRunArray.fPosEnd < 0 || !fStyleTable[fRunArray.fPosEnd].equals(attributeMap))
|
||||
{
|
||||
expandStyleTableIfFull();
|
||||
fRunArray.fPosEnd++;
|
||||
fRunArray.fRunStart[fRunArray.fPosEnd] = j2 - srcStart + start;
|
||||
fStyleTable[fRunArray.fPosEnd] = attributeMap;
|
||||
}
|
||||
}
|
||||
fRunArray.addToCurTextLength(srcLimit - srcStart);
|
||||
if (fRunArray.fNegStart < fRunArray.getArrayLength() && fStyleTable[fRunArray.fNegStart].equals(fStyleTable[fRunArray.fPosEnd]))
|
||||
fRunArray.fNegStart++;
|
||||
}
|
||||
|
||||
private static final int kNoRun = -42; // iterator use
|
||||
|
||||
private final class StyleRunIterator /*implements MStyleRunIterator*/ {
|
||||
|
||||
StyleRunIterator(int start, int limit)
|
||||
{
|
||||
reset(start, limit, start);
|
||||
}
|
||||
|
||||
public void reset(int start, int limit, int pos)
|
||||
{
|
||||
fStart = start;
|
||||
fLimit = limit;
|
||||
setIterator(fStart, this);
|
||||
}
|
||||
|
||||
public boolean isValid()
|
||||
{
|
||||
return fStyle != null;
|
||||
}
|
||||
|
||||
public void next()
|
||||
{
|
||||
if (fRunLimit < fLimit) {
|
||||
fCurrentRun++;
|
||||
setIteratorUsingRun(fCurrentRun, this);
|
||||
}
|
||||
else
|
||||
set(null, 0, 0, kNoRun);
|
||||
}
|
||||
|
||||
public void prev()
|
||||
{
|
||||
if (fRunStart > fStart) {
|
||||
fCurrentRun--;
|
||||
setIteratorUsingRun(fCurrentRun, this);
|
||||
}
|
||||
else
|
||||
set(null, 0, 0, kNoRun);
|
||||
}
|
||||
|
||||
public void set(int pos)
|
||||
{
|
||||
if (pos >= fStart && pos < fLimit) {
|
||||
setIterator(pos, this);
|
||||
} else {
|
||||
set(null, 0, 0, kNoRun);
|
||||
}
|
||||
}
|
||||
|
||||
void set(AttributeMap style, int start, int limit, int currentRun)
|
||||
{
|
||||
fStyle = style;
|
||||
fCurrentRun = currentRun;
|
||||
fRunStart = start < fStart ? fStart : start;
|
||||
fRunLimit = limit > fLimit ? fLimit : limit;
|
||||
}
|
||||
|
||||
public void reset(int start, int limit)
|
||||
{
|
||||
reset(start, limit, start);
|
||||
}
|
||||
|
||||
public void first()
|
||||
{
|
||||
set(fStart);
|
||||
}
|
||||
|
||||
public void last()
|
||||
{
|
||||
set(fLimit - 1);
|
||||
}
|
||||
|
||||
public int rangeStart()
|
||||
{
|
||||
return fStart;
|
||||
}
|
||||
|
||||
public int rangeLimit()
|
||||
{
|
||||
return fLimit;
|
||||
}
|
||||
|
||||
public int rangeLength()
|
||||
{
|
||||
return fLimit - fStart;
|
||||
}
|
||||
|
||||
public AttributeMap style()
|
||||
{
|
||||
return fStyle;
|
||||
}
|
||||
|
||||
public int runStart()
|
||||
{
|
||||
return fRunStart;
|
||||
}
|
||||
|
||||
public int runLimit()
|
||||
{
|
||||
return fRunLimit;
|
||||
}
|
||||
|
||||
public int runLength()
|
||||
{
|
||||
return fRunLimit - fRunStart;
|
||||
}
|
||||
|
||||
private int fStart;
|
||||
private int fLimit;
|
||||
private AttributeMap fStyle;
|
||||
private int fRunStart;
|
||||
private int fRunLimit;
|
||||
private int fCurrentRun;
|
||||
}
|
||||
}
|
@ -1,190 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeSet;
|
||||
|
||||
/**
|
||||
* StyleModifier is the base class for operations on AttributeMap. To implement
|
||||
* an operation on AttributeMap, subclass StyleModifier and override
|
||||
* <code>modifyStyle</code>. StyleModifiers are used by MText.
|
||||
* <p>
|
||||
* For convenience, this class contains factory methods which will create a
|
||||
* StyleModifier for
|
||||
* certain common operations: attribute union, attribute removal, and AttributeMap
|
||||
* replacement.
|
||||
* @see AttributeMap
|
||||
* @see AttributeSet
|
||||
* @see MText
|
||||
*/
|
||||
/*
|
||||
* {jbr} StyleModifier is not the best name for this class - styles are immutable and never
|
||||
* really modified.
|
||||
*/
|
||||
public class StyleModifier
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Create a StyleModifier.
|
||||
*/
|
||||
protected StyleModifier() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the result of this StyleModifier's operation on the given style.
|
||||
* Default implementation just returns the given style.
|
||||
* @param style the AttributeMap to perform the operation on
|
||||
*/
|
||||
public AttributeMap modifyStyle(AttributeMap style)
|
||||
{
|
||||
return style;
|
||||
}
|
||||
|
||||
/**
|
||||
* A StyleModifier which simply returns the given style.
|
||||
*/
|
||||
public static final StyleModifier IDENTITY = new StyleModifier();
|
||||
|
||||
/**
|
||||
* Create a StyleModifier whose operation is
|
||||
* <code>style.addAttributes(s)</code>,
|
||||
* where <code>style</code> is the AttributeMap passed to
|
||||
* <code>modifyStyle</code>.
|
||||
* @param s the AttributeMap to union with
|
||||
* @return a StyleModifier for this operation
|
||||
*/
|
||||
public static StyleModifier createAddModifier(AttributeMap s) {
|
||||
|
||||
return new StyleAddModifier(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StyleModifier whose operation is
|
||||
* <code>style.addAttribute(key, value)</code>,
|
||||
* where <code>style</code> is the AttributeMap passed to
|
||||
* <code>modifyStyle</code>.
|
||||
* @param key the key to add
|
||||
* @param value the value to add
|
||||
* @return a StyleModifier for this operation
|
||||
*/
|
||||
public static StyleModifier createAddModifier(Object key,
|
||||
Object value) {
|
||||
|
||||
return new AttributeAddModifier(key, value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StyleModifier whose operation returns <code>s</code>,
|
||||
* ignoring the parameter to <code>modifyStyle</code>.
|
||||
* @param s the AttributeMap which will replace any other AttributeMap
|
||||
* @return a StyleModifier for this operation
|
||||
*/
|
||||
public static StyleModifier createReplaceModifier(AttributeMap s) {
|
||||
|
||||
return new StyleReplaceModifier(s);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a StyleModifier whose operation is
|
||||
* <code>style.removeAttributes(s)</code>,
|
||||
* where <code>style</code> is the AttributeMap passed to
|
||||
* <code>modifyStyle</code>.
|
||||
* @param s the AttributeSet of attributes to remove
|
||||
* @return a StyleModifier for this operation
|
||||
*/
|
||||
public static StyleModifier createRemoveModifier(AttributeSet s) {
|
||||
|
||||
return new StyleRemoveModifier(s);
|
||||
}
|
||||
|
||||
static final class AttributeAddModifier extends StyleModifier {
|
||||
|
||||
private Object fKey;
|
||||
private Object fValue;
|
||||
|
||||
public AttributeAddModifier(Object key, Object value) {
|
||||
|
||||
fKey = key;
|
||||
fValue = value;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap style) {
|
||||
|
||||
return style.addAttribute(fKey, fValue);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this with the styles to add. These styles will add to and override any already
|
||||
* present in the style passed to modifyStyle.
|
||||
*/
|
||||
static final class StyleAddModifier extends StyleModifier
|
||||
{
|
||||
private AttributeMap fStyle;
|
||||
|
||||
public StyleAddModifier(AttributeMap style)
|
||||
{
|
||||
if (style == null) {
|
||||
throw new IllegalArgumentException("style is null");
|
||||
}
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap style)
|
||||
{
|
||||
return style.addAttributes(fStyle);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Create this with the styles to replace. All style runs will have only these
|
||||
* styles.
|
||||
*/
|
||||
static final class StyleReplaceModifier extends StyleModifier
|
||||
{
|
||||
private AttributeMap fStyle;
|
||||
|
||||
public StyleReplaceModifier(AttributeMap style)
|
||||
{
|
||||
if (style == null) {
|
||||
throw new IllegalArgumentException("style is null");
|
||||
}
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap style)
|
||||
{
|
||||
return fStyle;
|
||||
}
|
||||
}
|
||||
|
||||
static final class StyleRemoveModifier extends StyleModifier {
|
||||
|
||||
private AttributeSet fRemoveSet;
|
||||
|
||||
public StyleRemoveModifier(AttributeSet removeSet) {
|
||||
|
||||
if (removeSet == null) {
|
||||
throw new IllegalArgumentException("set is null");
|
||||
}
|
||||
fRemoveSet = removeSet;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap style) {
|
||||
|
||||
return style.removeAttributes(fRemoveSet);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,684 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
/**
|
||||
* This class is an implementation of MText, a modifyable, styled text
|
||||
* storage model. Additionally, it supports persistance through the
|
||||
* Externalizable interface.
|
||||
* @see MText
|
||||
*/
|
||||
|
||||
/*
|
||||
10/28/96 {jf} - split the character and paragraph style access and setter function around...
|
||||
just to keep things interesting.
|
||||
8/7/96 {jf} - moved paragraph break implementation from AbstractText into Style text.
|
||||
- added countStyles, getStyles, and ReplaceStyles implementation.
|
||||
|
||||
8/14/96 sfb eliminated StyleSheetIterator
|
||||
|
||||
8/29/96 {jbr} changed iter-based replace method - doesn't call at() unless it is safe to do so
|
||||
Also, added checkStartAndLimit for debugging
|
||||
|
||||
7/31/98 Switched from Style to AttributeMap
|
||||
|
||||
*/
|
||||
|
||||
public final class StyledText extends MText implements Externalizable
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
/* unicode storage */
|
||||
private MCharBuffer fCharBuffer;
|
||||
/* character style storage */
|
||||
private MStyleBuffer fStyleBuffer;
|
||||
/* paragraph style storage */
|
||||
private MParagraphBuffer fParagraphBuffer;
|
||||
|
||||
private transient int fTimeStamp = 0;
|
||||
private transient int[] fDamagedRange = { Integer.MAX_VALUE,
|
||||
Integer.MIN_VALUE };
|
||||
|
||||
private static class ForceModifier extends StyleModifier {
|
||||
|
||||
private AttributeMap fStyle = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
|
||||
void setStyle(AttributeMap style) {
|
||||
|
||||
fStyle = style;
|
||||
}
|
||||
|
||||
public AttributeMap modifyStyle(AttributeMap style) {
|
||||
|
||||
return fStyle;
|
||||
}
|
||||
}
|
||||
|
||||
// Keep this around foruse in replaceCharStylesWith. OK since
|
||||
// this class isn't threadsafe anyway.
|
||||
private transient ForceModifier forceModifier = null;
|
||||
|
||||
//======================================================
|
||||
// CONSTRUCTORS
|
||||
//======================================================
|
||||
/**
|
||||
* Create an empty text object.
|
||||
*/
|
||||
public StyledText()
|
||||
{
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an empty text object ready to hold at least capacity chars.
|
||||
* @param capacity the minimum capacity of the internal text buffer
|
||||
*/
|
||||
public StyledText(int capacity)
|
||||
{
|
||||
fCharBuffer = capacity>0? new CharBuffer(capacity) : new CharBuffer();
|
||||
fStyleBuffer = new StyleBuffer(this, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
fParagraphBuffer = new ParagraphBuffer(fCharBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text object with the characters in the string,
|
||||
* in the given style.
|
||||
* @param string the initial contents
|
||||
* @param initialStyle the style of the initial text
|
||||
*/
|
||||
public StyledText(String string, AttributeMap initialStyle)
|
||||
{
|
||||
fCharBuffer = new CharBuffer(string.length());
|
||||
fCharBuffer.replace(0, 0, string, 0, string.length());
|
||||
|
||||
fStyleBuffer = new StyleBuffer(this, initialStyle);
|
||||
fParagraphBuffer = new ParagraphBuffer(fCharBuffer);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text object from the given source.
|
||||
* @param source the text to copy
|
||||
*/
|
||||
public StyledText(MConstText source) {
|
||||
this();
|
||||
append(source);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a text object from a subrange of the given source.
|
||||
* @param source the text to copy from
|
||||
* @param srcStart the index of the first character to copy
|
||||
* @param srcLimit the index after the last character to copy
|
||||
*/
|
||||
public StyledText(MConstText source, int srcStart, int srcLimit) {
|
||||
this();
|
||||
replace(0, 0, source, srcStart, srcLimit);
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeObject(fCharBuffer);
|
||||
out.writeObject(fStyleBuffer);
|
||||
out.writeObject(fParagraphBuffer);
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
int version = in.readInt();
|
||||
if (version != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of StyledText: " + version);
|
||||
}
|
||||
fCharBuffer = (MCharBuffer) in.readObject();
|
||||
fStyleBuffer = (MStyleBuffer) in.readObject();
|
||||
fParagraphBuffer = (MParagraphBuffer) in.readObject();
|
||||
|
||||
resetDamagedRange();
|
||||
}
|
||||
|
||||
//======================================================
|
||||
// MConstText INTERFACES
|
||||
//======================================================
|
||||
|
||||
//--------------------------------------------------------
|
||||
// character access
|
||||
//--------------------------------------------------------
|
||||
/**
|
||||
* Return the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the character at offset <code>pos</code>
|
||||
*/
|
||||
public char at(int pos)
|
||||
{
|
||||
return fCharBuffer.at(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the characters in the range [<code>start</code>, <code>limit</code>)
|
||||
* into the array <code>dst</code>, beginning at <code>dstStart</code>.
|
||||
* @param start offset of first character which will be copied into the array
|
||||
* @param limit offset immediately after the last character which will be copied into the array
|
||||
* @param dst array in which to copy characters. The length of <code>dst</code> must be at least
|
||||
* (<code>dstStart + limit - start</code>).
|
||||
*/
|
||||
public void extractChars(int start, int limit, char[] dst, int dstStart)
|
||||
{
|
||||
fCharBuffer.at(start, limit, dst, dstStart);
|
||||
}
|
||||
|
||||
//-------------------------------------------------------
|
||||
// text model creation
|
||||
//-------------------------------------------------------
|
||||
/**
|
||||
* Create an MConstText containing the characters and styles in the range
|
||||
* [<code>start</code>, <code>limit</code>).
|
||||
* @param start offset of first character in the new text
|
||||
* @param limit offset immediately after the last character in the new text
|
||||
* @return an MConstText object containing the characters and styles in the given range
|
||||
*/
|
||||
public MConstText extract(int start, int limit)
|
||||
{
|
||||
return extractWritable(start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an MText containing the characters and styles in the range
|
||||
* [<code>start</code>, <code>limit</code>).
|
||||
* @param start offset of first character in the new text
|
||||
* @param limit offset immediately after the last character in the new text
|
||||
* @return an MConstText object containing the characters and styles in the given range
|
||||
*/
|
||||
public MText extractWritable(int start, int limit)
|
||||
{
|
||||
MText text = new StyledText();
|
||||
text.replace(0, 0, this, start, limit);
|
||||
text.resetDamagedRange();
|
||||
return text;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// size/capacity
|
||||
//--------------------------------------------------------
|
||||
/**
|
||||
* Return the length of the MConstText object. The length is the number of characters in the text.
|
||||
* @return the length of the MConstText object
|
||||
*/
|
||||
public int length()
|
||||
{
|
||||
return fCharBuffer.length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a <code>CharacterIterator</code> over the range [<code>start</code>, <code>limit</code>).
|
||||
* @param start the beginning of the iterator's range
|
||||
* @param limit the limit of the iterator's range
|
||||
* @return a valid <code>CharacterIterator</code> over the specified range
|
||||
* @see java.text.CharacterIterator
|
||||
*/
|
||||
public CharacterIterator createCharacterIterator(int start, int limit)
|
||||
{
|
||||
return fCharBuffer.createCharacterIterator(start, limit);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// character styles
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Return the index of the first character in the character style run
|
||||
* containing pos. All characters in a style run have the same character
|
||||
* style.
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public int characterStyleStart(int pos) {
|
||||
|
||||
checkPos(pos, LESS_THAN_LENGTH);
|
||||
return fStyleBuffer.styleStart(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the index after the last character in the character style run
|
||||
* containing pos. All characters in a style run have the same character
|
||||
* style.
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public int characterStyleLimit(int pos) {
|
||||
|
||||
checkPos(pos, NOT_GREATER_THAN_LENGTH);
|
||||
return fStyleBuffer.styleLimit(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the style applied to the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the style at offset <code>pos</code>
|
||||
*/
|
||||
public AttributeMap characterStyleAt(int pos)
|
||||
{
|
||||
checkPos(pos, NOT_GREATER_THAN_LENGTH);
|
||||
return fStyleBuffer.styleAt(pos);
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// paragraph boundaries and styles
|
||||
//--------------------------------------------------------
|
||||
/**
|
||||
* Return the start of the paragraph containing the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the start of the paragraph containing the character at offset <code>pos</code>
|
||||
*/
|
||||
public int paragraphStart(int pos)
|
||||
{
|
||||
checkPos(pos, NOT_GREATER_THAN_LENGTH);
|
||||
return fParagraphBuffer.paragraphStart(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the limit of the paragraph containing the character at offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the limit of the paragraph containing the character at offset <code>pos</code>
|
||||
*/
|
||||
public int paragraphLimit(int pos)
|
||||
{
|
||||
checkPos(pos, NOT_GREATER_THAN_LENGTH);
|
||||
return fParagraphBuffer.paragraphLimit(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the paragraph style applied to the paragraph containing offset <code>pos</code>.
|
||||
* @param pos a valid offset into the text
|
||||
* @return the paragraph style in effect at <code>pos</code>
|
||||
*/
|
||||
public AttributeMap paragraphStyleAt(int pos)
|
||||
{
|
||||
checkPos(pos, NOT_GREATER_THAN_LENGTH);
|
||||
return fParagraphBuffer.paragraphStyleAt(pos);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the current time stamp. The time stamp is
|
||||
* incremented whenever the contents of the MConstText changes.
|
||||
* @return the current paragraph style time stamp
|
||||
*/
|
||||
public int getTimeStamp() {
|
||||
|
||||
return fTimeStamp;
|
||||
}
|
||||
|
||||
//======================================================
|
||||
// MText INTERFACES
|
||||
//======================================================
|
||||
//--------------------------------------------------------
|
||||
// character modfication functions
|
||||
//--------------------------------------------------------
|
||||
|
||||
private void updateDamagedRange(int deleteStart,
|
||||
int deleteLimit,
|
||||
int insertLength) {
|
||||
|
||||
fDamagedRange[0] = Math.min(fDamagedRange[0], deleteStart);
|
||||
|
||||
if (fDamagedRange[1] >= deleteLimit) {
|
||||
int lengthChange = insertLength - (deleteLimit-deleteStart);
|
||||
fDamagedRange[1] += lengthChange;
|
||||
}
|
||||
else {
|
||||
fDamagedRange[1] = deleteStart + insertLength;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the characters and styles in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* and styles in <code>srcText</code> in the range [<code>srcStart</code>, <code>srcLimit</code>). <code>srcText</code> is not
|
||||
* modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character and style at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param text the source for the new characters and styles
|
||||
* @param srcStart the offset into <code>srcText</code> where new characters and styles will be obtained
|
||||
* @param srcLimit the offset into <code>srcText</code> where the new characters and styles end
|
||||
*/
|
||||
public void replace(int start, int limit, MConstText text, int srcStart, int srcLimit)
|
||||
{
|
||||
if (text == this) {
|
||||
text = new StyledText(text);
|
||||
}
|
||||
|
||||
if (start == limit && srcStart == srcLimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
checkStartLimit(start, limit);
|
||||
|
||||
updateDamagedRange(start, limit, srcLimit-srcStart);
|
||||
|
||||
fCharBuffer.replace(start, limit, text, srcStart, srcLimit);
|
||||
fStyleBuffer.replace(start, limit, text, srcStart, srcLimit);
|
||||
fParagraphBuffer.replace(start, limit, text, srcStart, srcLimit, fDamagedRange);
|
||||
fTimeStamp += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the characters and styles in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* and styles in <code>srcText</code>. <code>srcText</code> is not
|
||||
* modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character and style at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param text the source for the new characters and styles
|
||||
*/
|
||||
public void replace(int start, int limit, MConstText text) {
|
||||
|
||||
replace(start, limit, text, 0, text.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the characters in the range [<code>start</code>, <code>limit</code>) with the characters
|
||||
* in <code>srcChars</code> in the range [<code>srcStart</code>, <code>srcLimit</code>). New characters take on the style
|
||||
* <code>charsStyle</code>.
|
||||
* <code>srcChars</code> is not modified.
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param srcChars the source for the new characters
|
||||
* @param srcStart the offset into <code>srcChars</code> where new characters will be obtained
|
||||
* @param srcLimit the offset into <code>srcChars</code> where the new characters end
|
||||
* @param charsStyle the style of the new characters
|
||||
*/
|
||||
public void replace(int start, int limit, char[] srcChars, int srcStart, int srcLimit, AttributeMap charsStyle)
|
||||
{
|
||||
checkStartLimit(start, limit);
|
||||
|
||||
if (start == limit && srcStart == srcLimit) {
|
||||
return;
|
||||
}
|
||||
|
||||
updateDamagedRange(start, limit, srcLimit-srcStart);
|
||||
|
||||
fCharBuffer.replace(start, limit, srcChars, srcStart, srcLimit);
|
||||
|
||||
replaceCharStylesWith(start, limit, start + (srcLimit-srcStart), charsStyle);
|
||||
|
||||
fParagraphBuffer.deleteText(start, limit, fDamagedRange);
|
||||
fParagraphBuffer.insertText(start, srcChars, srcStart, srcLimit);
|
||||
|
||||
fTimeStamp += 1;
|
||||
}
|
||||
|
||||
private void replaceCharStylesWith(int start, int oldLimit, int newLimit, AttributeMap style) {
|
||||
|
||||
if (start < oldLimit) {
|
||||
fStyleBuffer.deleteText(start, oldLimit);
|
||||
}
|
||||
if (start < newLimit) {
|
||||
if (forceModifier == null) {
|
||||
forceModifier = new ForceModifier();
|
||||
}
|
||||
forceModifier.setStyle(style);
|
||||
fStyleBuffer.insertText(start, newLimit);
|
||||
fStyleBuffer.modifyStyles(start, newLimit, forceModifier, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the characters in the range [<code>start</code>, <code>limit</code>) with the character <code>srcChar</code>.
|
||||
* The new character takes on the style <code>charStyle</code>
|
||||
* @param start the offset at which the replace operation begins
|
||||
* @param limit the offset at which the replace operation ends. The character at
|
||||
* <code>limit</code> is not modified.
|
||||
* @param srcChar the new character
|
||||
* @param charStyle the style of the new character
|
||||
*/
|
||||
public void replace(int start, int limit, char srcChar, AttributeMap charStyle)
|
||||
{
|
||||
checkStartLimit(start, limit);
|
||||
|
||||
updateDamagedRange(start, limit, 1);
|
||||
|
||||
fCharBuffer.replace(start, limit, srcChar);
|
||||
|
||||
replaceCharStylesWith(start, limit, start + 1, charStyle);
|
||||
|
||||
if (start < limit) {
|
||||
fParagraphBuffer.deleteText(start, limit, fDamagedRange);
|
||||
}
|
||||
|
||||
fParagraphBuffer.insertText(start, srcChar);
|
||||
|
||||
fTimeStamp += 1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the entire contents of this MText (both characters and styles) with
|
||||
* the contents of <code>srcText</code>.
|
||||
* @param srcText the source for the new characters and styles
|
||||
*/
|
||||
public void replaceAll(MConstText srcText)
|
||||
{
|
||||
replace(0, length(), srcText, 0, srcText.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the contents of <code>srcText</code> (both characters and styles) into this
|
||||
* MText at the position specified by <code>pos</code>.
|
||||
* @param pos The character offset where the new text is to be inserted.
|
||||
* @param srcText The text to insert.
|
||||
*/
|
||||
public void insert(int pos, MConstText srcText)
|
||||
{
|
||||
replace(pos, pos, srcText, 0, srcText.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the contents of <code>srcText</code> (both characters and styles) to the
|
||||
* end of this MText.
|
||||
* @param srcText The text to append.
|
||||
*/
|
||||
public void append(MConstText srcText)
|
||||
{
|
||||
replace(length(), length(), srcText, 0, srcText.length());
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete the specified range of characters (and styles).
|
||||
* @param start Offset of the first character to delete.
|
||||
* @param limit Offset of the first character after the range to delete.
|
||||
*/
|
||||
public void remove(int start, int limit)
|
||||
{
|
||||
replace(start, limit, (char[])null, 0, 0, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete all characters and styles. Always increments time stamp.
|
||||
*/
|
||||
public void remove()
|
||||
{
|
||||
// rather than going through replace(), just reinitialize the StyledText,
|
||||
// letting the old data structures fall on the floor
|
||||
fCharBuffer = new CharBuffer();
|
||||
fStyleBuffer = new StyleBuffer(this, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
fParagraphBuffer = new ParagraphBuffer(fCharBuffer);
|
||||
fTimeStamp += 1;
|
||||
fDamagedRange[0] = fDamagedRange[1] = 0;
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// storage management
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Minimize the amount of memory used by the MText object.
|
||||
*/
|
||||
public void compress() {
|
||||
|
||||
fCharBuffer.compress();
|
||||
fStyleBuffer.compress();
|
||||
fParagraphBuffer.compress();
|
||||
}
|
||||
|
||||
//--------------------------------------------------------
|
||||
// style modification
|
||||
//--------------------------------------------------------
|
||||
|
||||
/**
|
||||
* Set the style of all characters in the MText object to
|
||||
* <code>AttributeMap.EMPTY_ATTRIBUTE_MAP</code>.
|
||||
*/
|
||||
public void removeCharacterStyles() {
|
||||
|
||||
fStyleBuffer = new StyleBuffer(this, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
fTimeStamp += 1;
|
||||
fDamagedRange[0] = 0;
|
||||
fDamagedRange[1] = length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the given modifier on all character styles from start to limit.
|
||||
* @param modifier the modifier to apply to the range.
|
||||
* @param start the start of the range of text to modify.
|
||||
* @param limit the limit of the range of text to modify.
|
||||
*/
|
||||
public void modifyCharacterStyles(int start, int limit, StyleModifier modifier) {
|
||||
|
||||
checkStartLimit(start, limit);
|
||||
boolean modified = fStyleBuffer.modifyStyles(start,
|
||||
limit,
|
||||
modifier,
|
||||
fDamagedRange);
|
||||
if (modified) {
|
||||
fTimeStamp += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Invoke the given modifier on all paragraph styles in paragraphs
|
||||
* containing characters in the range [start, limit).
|
||||
* @param modifier the modifier to apply to the range.
|
||||
* @param start the start of the range of text to modify.
|
||||
* @param limit the limit of the range of text to modify.
|
||||
*/
|
||||
public void modifyParagraphStyles(int start, int limit, StyleModifier modifier) {
|
||||
|
||||
checkStartLimit(start, limit);
|
||||
boolean modified = fParagraphBuffer.modifyParagraphStyles(start,
|
||||
limit,
|
||||
modifier,
|
||||
fDamagedRange);
|
||||
if (modified) {
|
||||
fTimeStamp += 1;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Reset the damaged range to an empty interval, and begin accumulating the damaged
|
||||
* range. The damaged range includes every index where a character, character style,
|
||||
* or paragraph style has changed.
|
||||
* @see #damagedRangeStart
|
||||
* @see #damagedRangeLimit
|
||||
*/
|
||||
public void resetDamagedRange() {
|
||||
|
||||
fDamagedRange[0] = Integer.MAX_VALUE;
|
||||
fDamagedRange[1] = Integer.MIN_VALUE;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the start of the damaged range.
|
||||
* If the start is
|
||||
* <code>Integer.MAX_VALUE</code> and the limit is
|
||||
* <code>Integer.MIN_VALUE</code>, then the damaged range
|
||||
* is empty.
|
||||
* @return the start of the damaged range
|
||||
* @see #damagedRangeLimit
|
||||
* @see #resetDamagedRange
|
||||
*/
|
||||
public int damagedRangeStart() {
|
||||
|
||||
return fDamagedRange[0];
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the limit of the damaged range.
|
||||
* If the start is
|
||||
* <code>Integer.MAX_VALUE</code> and the limit is
|
||||
* <code>Integer.MIN_VALUE</code>, then the damaged range
|
||||
* is empty.
|
||||
* @return the limit of the damaged range
|
||||
* @see #damagedRangeStart
|
||||
* @see #resetDamagedRange
|
||||
*/
|
||||
public int damagedRangeLimit() {
|
||||
|
||||
return fDamagedRange[1];
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
String result ="";
|
||||
for (int i = 0; i < length(); i++) {
|
||||
result += at(i);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
//======================================================
|
||||
// IMPLEMENTATION
|
||||
//======================================================
|
||||
|
||||
/* check a range to see if it is well formed and within the bounds of the text */
|
||||
private void checkStartLimit(int start, int limit)
|
||||
{
|
||||
if (start > limit) {
|
||||
//System.out.println("Start is less than limit. start:"+start+"; limit:"+limit);
|
||||
throw new IllegalArgumentException("Start is greater than limit. start:"+start+"; limit:"+limit);
|
||||
}
|
||||
|
||||
if (start < 0) {
|
||||
//System.out.println("Start is negative. start:"+start);
|
||||
throw new IllegalArgumentException("Start is negative. start:"+start);
|
||||
}
|
||||
|
||||
if (limit > length()) {
|
||||
//System.out.println("Limit is greater than length. limit:"+limit);
|
||||
throw new IllegalArgumentException("Limit is greater than length. limit:"+limit);
|
||||
}
|
||||
}
|
||||
|
||||
private static final boolean LESS_THAN_LENGTH = false;
|
||||
private static final boolean NOT_GREATER_THAN_LENGTH = true;
|
||||
|
||||
private void checkPos(int pos, boolean endAllowed) {
|
||||
|
||||
int lastValidPos = length();
|
||||
if (endAllowed == LESS_THAN_LENGTH) {
|
||||
--lastValidPos;
|
||||
}
|
||||
|
||||
if (pos < 0 || pos > lastValidPos) {
|
||||
throw new IllegalArgumentException("Position is out of range.");
|
||||
}
|
||||
}
|
||||
}
|
@ -1,183 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
/**
|
||||
* TabStop represents a position on a tab ruler. Each tab stop has a
|
||||
* position, giving its location on the ruler, and one of several
|
||||
* types. The type determines how a segment controled by this TabStop
|
||||
* is positioned on a line:
|
||||
* <ul>
|
||||
* <li><code>kLeading</code> - the leading edge of the segment is aligned to
|
||||
* the TabStop's position</li>
|
||||
* <li><code>kCenter</code> - the segment is centered on this TabStop's
|
||||
* position</li>
|
||||
* <li><code>kTrailing</code> - the trailing edge of the segment is aligned to
|
||||
* the TabStop's position</li>
|
||||
* <li><code>kDecimal</code> - the first decimal in the segment is aligned to
|
||||
* the TabStop's position</li>
|
||||
* <li><code>kAuto</code> - semantically the same as <code>kLeading</code>.
|
||||
* Used by tab rulers to indicate that all subsequent tab stops
|
||||
* will be at autospaced intervals.</li>
|
||||
* </ul>
|
||||
* @see MTabRuler
|
||||
*/
|
||||
public final class TabStop implements Externalizable
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
private static final long serialVersionUID = 22356934;
|
||||
|
||||
private byte fType; // left, center, right, decimal
|
||||
private int fPosition; // tab stop position from line origin.
|
||||
|
||||
/**
|
||||
* A TabStop with this type aligns its segment's leading edge
|
||||
* to the TabStop's position.
|
||||
*/
|
||||
public static final byte kLeading = 0;
|
||||
|
||||
/**
|
||||
* A TabStop with this type aligns its segment's center
|
||||
* to the TabStop's position.
|
||||
*/
|
||||
public static final byte kCenter = 1;
|
||||
|
||||
/**
|
||||
* A TabStop with this type aligns its segment's trailing edge
|
||||
* to the TabStop's position.
|
||||
*/
|
||||
public static final byte kTrailing = 2;
|
||||
|
||||
/**
|
||||
* A TabStop with this type aligns its segment's first decimal
|
||||
* to the TabStop's position.
|
||||
*/
|
||||
public static final byte kDecimal = 3;
|
||||
|
||||
/**
|
||||
* A TabStop with this type aligns its segment's leading edge
|
||||
* to the TabStop's position. After a TabStop of this type,
|
||||
* all tabs are at autospace intervals. Usually, clients will
|
||||
* not construct TabStops with this type.
|
||||
*/
|
||||
public static final byte kAuto = 4;
|
||||
|
||||
/**
|
||||
* Create a TabStop with position 0 and type <code>kLeading</code>.
|
||||
*/
|
||||
public TabStop() {
|
||||
|
||||
this(0, kLeading);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a TabStop with the given position and type.
|
||||
* @param position the TabStop's position
|
||||
* @param type the TabStop's type. Must be one of constants
|
||||
* in this class.
|
||||
*/
|
||||
public TabStop(int position, byte type) {
|
||||
|
||||
if (type < kLeading || type > kAuto) {
|
||||
throw new IllegalArgumentException("Invalid tab type");
|
||||
}
|
||||
|
||||
fPosition = position;
|
||||
fType = type;
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
int version = in.readInt();
|
||||
if (version != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of TabStop.");
|
||||
}
|
||||
fPosition = in.readInt();
|
||||
fType = in.readByte();
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeInt(fPosition);
|
||||
out.writeByte(fType);
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this to another Object. TabStops are equal if
|
||||
* their position and type are the same.
|
||||
*/
|
||||
public boolean equals(Object rhs)
|
||||
{
|
||||
if (rhs == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TabStop rhsTab;
|
||||
try {
|
||||
rhsTab = (TabStop) rhs;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return fType == rhsTab.fType && fPosition == rhsTab.fPosition;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hash code for this TabStop. The hash code is
|
||||
* <code>position << type</code>.
|
||||
*/
|
||||
public int hashCode() {
|
||||
|
||||
return fPosition << fType;
|
||||
}
|
||||
|
||||
public String toString()
|
||||
{
|
||||
char typeChar;
|
||||
switch (fType) {
|
||||
case kLeading: typeChar = 'L'; break;
|
||||
case kCenter: typeChar = 'C'; break;
|
||||
case kTrailing: typeChar = 'R'; break;
|
||||
case kDecimal: typeChar = 'D'; break;
|
||||
case kAuto: typeChar = 'A'; break;
|
||||
default: typeChar = '?'; break;
|
||||
}
|
||||
return "TabStop[" + Integer.toString(fPosition) + typeChar + ']';
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the type of this TabStop. Will be one of the constants
|
||||
* in this class.
|
||||
*/
|
||||
public byte getType() {
|
||||
return fType;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the position of this TabStop.
|
||||
*/
|
||||
public int getPosition() {
|
||||
return fPosition;
|
||||
}
|
||||
}
|
||||
|
@ -1,58 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
final class TestFastIntBinarySearch {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
boolean result = new TestFastIntBinarySearch().test();
|
||||
System.out.println(result? "PASSED" : "FAILED");
|
||||
}
|
||||
|
||||
public boolean test() {
|
||||
|
||||
boolean result = true;
|
||||
int[] test = {-5, -3, 0, 2, 5};
|
||||
FastIntBinarySearch fibs = new FastIntBinarySearch(test);
|
||||
|
||||
for (int i=0; i < 2; i++) {
|
||||
int beforeAny = fibs.findIndex(-6);
|
||||
if (beforeAny != -1) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
int atEnd = fibs.findIndex(5);
|
||||
if (atEnd != test.length-1) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
int afterAny = fibs.findIndex(6);
|
||||
if (afterAny != test.length-1) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
int exactly = fibs.findIndex(-3);
|
||||
if (exactly != 1) {
|
||||
result = false;
|
||||
}
|
||||
|
||||
fibs = new FastIntBinarySearch(new int[] {20, 40});
|
||||
fibs.setData(test);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.styledtext;
|
||||
|
||||
/**
|
||||
* Iterators use this class to keep from getting out of sync with
|
||||
* their underlying data. When created, the iterator gets a
|
||||
* Validation instance. If the underlying data changes, the Validation
|
||||
* becomes invalid. Usually iterators will throw exceptions if accessed
|
||||
* after becoming invalid.
|
||||
*/
|
||||
final class Validation {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private boolean fIsValid = true;
|
||||
|
||||
boolean isValid() {
|
||||
|
||||
return fIsValid;
|
||||
}
|
||||
|
||||
void invalidate() {
|
||||
|
||||
fIsValid = false;
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<!--
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
-->
|
||||
<html>
|
||||
<body bgcolor="white">
|
||||
Provides styled text storage and related classes.
|
||||
</body>
|
||||
</html>
|
@ -1,46 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingdemo;
|
||||
|
||||
import com.ibm.richtext.demo.CodeEdit;
|
||||
import com.ibm.richtext.demo.DocumentWindow;
|
||||
import com.ibm.richtext.demo.SyntaxColorer;
|
||||
import com.ibm.richtext.demo.TextDocument;
|
||||
|
||||
public class SwingCodeEdit extends CodeEdit {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new SwingCodeEdit(args, 0);
|
||||
}
|
||||
|
||||
public SwingCodeEdit(String[] args, int start) {
|
||||
|
||||
super(args, start);
|
||||
}
|
||||
|
||||
protected DocumentWindow createDocumentWindow(TextDocument document) {
|
||||
|
||||
return new SwingDocumentWindow(this,
|
||||
document,
|
||||
fSettings,
|
||||
false,
|
||||
new SyntaxColorer(),
|
||||
false,
|
||||
true,
|
||||
menus);
|
||||
}
|
||||
}
|
@ -1,275 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingdemo;
|
||||
|
||||
import com.ibm.richtext.textpanel.JTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelListener;
|
||||
import com.ibm.richtext.textpanel.TextPanelSettings;
|
||||
|
||||
import com.ibm.richtext.swingui.JTabRuler;
|
||||
import com.ibm.richtext.swingui.SwingMenuBuilder;
|
||||
|
||||
import com.ibm.richtext.print.PrintingUtils;
|
||||
|
||||
import com.ibm.richtext.demo.AwtDocumentWindow;
|
||||
import com.ibm.richtext.demo.DocumentWindow;
|
||||
import com.ibm.richtext.demo.EditApplication;
|
||||
import com.ibm.richtext.demo.EditorResources;
|
||||
import com.ibm.richtext.demo.ResourceUtils;
|
||||
import com.ibm.richtext.demo.TextDocument;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.FileDialog;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.JOptionPane;
|
||||
import javax.swing.WindowConstants;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.text.MessageFormat;
|
||||
|
||||
/**
|
||||
* AwtDocumentWindow is a Frame containing a TextPanel, with a document
|
||||
* for storing the text in the TextPanel.
|
||||
*/
|
||||
final class SwingDocumentWindow extends JFrame implements DocumentWindow {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -1514405707157485775L;
|
||||
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private JTextPanel fTextPanel;
|
||||
private EditApplication fApplication;
|
||||
private TextDocument fDocument;
|
||||
|
||||
/**
|
||||
* Create a new AwtDocumentWindow.
|
||||
* @param application the application that owns this document
|
||||
* @param document the document to show in this AwtDocumentWindow
|
||||
*/
|
||||
SwingDocumentWindow(EditApplication application,
|
||||
TextDocument document,
|
||||
TextPanelSettings textPanelSettings,
|
||||
boolean useTabRuler,
|
||||
TextPanelListener listener,
|
||||
boolean supportStyledText,
|
||||
boolean supportPlainText,
|
||||
int[] menus) {
|
||||
|
||||
fApplication = application;
|
||||
setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
|
||||
|
||||
fTextPanel = new JTextPanel(textPanelSettings, null, application.getClipboard());
|
||||
if (listener != null) {
|
||||
fTextPanel.addListener(listener);
|
||||
}
|
||||
setDocument(document);
|
||||
|
||||
addMenuBar(supportStyledText, supportPlainText, menus);
|
||||
|
||||
getContentPane().setLayout(new BorderLayout());
|
||||
|
||||
if (useTabRuler) {
|
||||
JTabRuler tabRuler = new JTabRuler(14, 10, fTextPanel);
|
||||
getContentPane().add(tabRuler, "North");
|
||||
}
|
||||
|
||||
getContentPane().add(fTextPanel, "Center");
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
doClose();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
private void addMenuBar(boolean supportStyledText,
|
||||
boolean supportPlainText,
|
||||
int[] menus) {
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
String menuTitle = ResourceUtils.getString(EditorResources.FILE);
|
||||
JMenu menu = new JMenu(menuTitle);
|
||||
new SwingFileMenuManager(menu, fApplication, this,
|
||||
supportStyledText, supportPlainText);
|
||||
menuBar.add(menu);
|
||||
|
||||
SwingMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this, menus);
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if it is OK to set the document text and file to
|
||||
* something different.
|
||||
*/
|
||||
private boolean canChangeDocuments() {
|
||||
|
||||
// If the text is modified, give the user a chance to
|
||||
// save it. Otherwise return true.
|
||||
|
||||
if (fDocument.isModified()) {
|
||||
int save = askSave();
|
||||
if (save == JOptionPane.YES_OPTION) {
|
||||
return doSave();
|
||||
}
|
||||
else {
|
||||
return save == JOptionPane.NO_OPTION;
|
||||
}
|
||||
}
|
||||
else {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void setDocument(TextDocument document) {
|
||||
|
||||
fDocument = document;
|
||||
fDocument.setTextPanel(fTextPanel);
|
||||
setTitle(fDocument.getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the document to empty text with no associated file. If
|
||||
* the document text is not saved, prompt the user to save the
|
||||
* the text first. If this operation is canceled, the document
|
||||
* is unchanged.
|
||||
*/
|
||||
public void doNew() {
|
||||
|
||||
if (!canChangeDocuments()) {
|
||||
return;
|
||||
}
|
||||
|
||||
setDocument(fApplication.createNewDocument());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for a file from which to load a text document.
|
||||
* If the current text is not saved, first prompt the user to
|
||||
* save. If either operation is canceled or fails, the document
|
||||
* is unchanged.
|
||||
*/
|
||||
public void doOpen() {
|
||||
|
||||
if (!canChangeDocuments()) {
|
||||
return;
|
||||
}
|
||||
|
||||
TextDocument document = fApplication.openDocument(this);
|
||||
|
||||
if (document != null) {
|
||||
setDocument(document);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for a file in which to save the document text.
|
||||
* If this operation is not canceled, save the text in the file.
|
||||
* The file becomes this document's file.
|
||||
*/
|
||||
public boolean doSaveAs(int format) {
|
||||
|
||||
String title = ResourceUtils.getString(EditorResources.SAVE_TITLE);
|
||||
File file = AwtDocumentWindow.getFileFromDialog(fDocument.getFile(), title, this, FileDialog.SAVE);
|
||||
|
||||
if (file == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
fDocument.setFile(file);
|
||||
setTitle(fDocument.getTitle());
|
||||
|
||||
fDocument.setFormat(format);
|
||||
|
||||
return fDocument.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Save the text in this document. If there is no file associated
|
||||
* with the text, this is equivalent to <code>doSaveAs</code>.
|
||||
* This method returns true if the document was successfully saved.
|
||||
*/
|
||||
public boolean doSave() {
|
||||
|
||||
if (fDocument.getFile() == null) {
|
||||
return doSaveAs(fDocument.getFormat());
|
||||
}
|
||||
|
||||
return fDocument.save();
|
||||
}
|
||||
|
||||
/**
|
||||
* Print the contents of this window.
|
||||
*/
|
||||
public void doPrint() {
|
||||
|
||||
PrintingUtils.userPrintText(fDocument.getText(),
|
||||
fTextPanel.getDefaultValues(),
|
||||
this,
|
||||
this.getTitle());
|
||||
}
|
||||
|
||||
/**
|
||||
* Attempt to close this window. If the text has not been saved,
|
||||
* give the user a chance to save the text before closing the
|
||||
* window. If the user cancels this operation, this method returns
|
||||
* false and the window is not closed; otherwise this method
|
||||
* returns true and the window is closed.
|
||||
*/
|
||||
public boolean doClose() {
|
||||
|
||||
if (canChangeDocuments()) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
fApplication.removeDocumentWindow(this);
|
||||
return true;
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a dialog that asks whether the user wants to
|
||||
* save a document. The returned value will be YES_OPTION,
|
||||
* NO_OPTION, or CANCEL_OPTION from JOptionPane.
|
||||
*/
|
||||
private int askSave() {
|
||||
|
||||
String pattern = ResourceUtils.getString(EditorResources.SAVE_MSG);
|
||||
String message = MessageFormat.format(pattern, new Object[] {getTitle()});
|
||||
|
||||
String yes = ResourceUtils.getString(EditorResources.YES);
|
||||
String no = ResourceUtils.getString(EditorResources.NO);
|
||||
String cancel = ResourceUtils.getString(EditorResources.CANCEL);
|
||||
|
||||
return JOptionPane.showOptionDialog(this,
|
||||
message,
|
||||
"",
|
||||
JOptionPane.YES_NO_CANCEL_OPTION,
|
||||
JOptionPane.QUESTION_MESSAGE,
|
||||
null,
|
||||
new Object[]{yes,no,cancel},
|
||||
yes);
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingdemo;
|
||||
|
||||
import com.ibm.richtext.demo.EditDemo;
|
||||
import com.ibm.richtext.demo.DocumentWindow;
|
||||
import com.ibm.richtext.demo.TextDocument;
|
||||
|
||||
import com.ibm.richtext.textpanel.JTextPanel;
|
||||
|
||||
public class SwingEditDemo extends EditDemo {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new SwingCodeEdit(args, 0);
|
||||
}
|
||||
|
||||
public SwingEditDemo(String[] args, int start) {
|
||||
|
||||
super(args, start);
|
||||
}
|
||||
|
||||
protected DocumentWindow createDocumentWindow(TextDocument document) {
|
||||
|
||||
return new SwingDocumentWindow(this,
|
||||
document,
|
||||
JTextPanel.getDefaultSettings(),
|
||||
true,
|
||||
null,
|
||||
true,
|
||||
true,
|
||||
null);
|
||||
}
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingdemo;
|
||||
|
||||
import java.awt.Event;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import com.ibm.richtext.demo.DocumentWindow;
|
||||
import com.ibm.richtext.demo.EditApplication;
|
||||
import com.ibm.richtext.demo.FileMenuManager;
|
||||
import com.ibm.richtext.demo.MenuData;
|
||||
import com.ibm.richtext.demo.ResourceUtils;
|
||||
|
||||
final class SwingFileMenuManager extends FileMenuManager {
|
||||
|
||||
private JMenu fMenu;
|
||||
|
||||
public SwingFileMenuManager(JMenu menu,
|
||||
EditApplication application,
|
||||
DocumentWindow document,
|
||||
boolean supportStyledFormat,
|
||||
boolean supportPlainFormat) {
|
||||
|
||||
super(application, document);
|
||||
|
||||
fMenu = menu;
|
||||
createItems(supportStyledFormat, supportPlainFormat);
|
||||
fMenu = null;
|
||||
}
|
||||
|
||||
protected Object addMenuItem(String key) {
|
||||
|
||||
MenuData menuData = ResourceUtils.getMenuData(key);
|
||||
JMenuItem item = new JMenuItem(menuData.getName());
|
||||
if (menuData.hasShortcut()) {
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(menuData.getShortcutKeyCode(),
|
||||
Event.CTRL_MASK);
|
||||
item.setAccelerator(ks);
|
||||
}
|
||||
item.addActionListener(this);
|
||||
fMenu.add(item);
|
||||
return item;
|
||||
}
|
||||
|
||||
protected void addSeparator() {
|
||||
|
||||
fMenu.add(new JSeparator());
|
||||
}
|
||||
}
|
@ -1,73 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Container;
|
||||
import java.awt.CardLayout;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import com.ibm.richtext.textpanel.JTextPanel;
|
||||
import com.ibm.richtext.textpanel.TextPanelSettings;
|
||||
|
||||
/**
|
||||
* MessageDialog is a simple Frame which displays a styled
|
||||
* text message in a TextPanel.
|
||||
* The text in the message is not selectable or editable.
|
||||
* @see MConstText
|
||||
* @see JTextPanel
|
||||
*/
|
||||
public final class JMessageDialog extends JFrame {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 5012952859760456427L;
|
||||
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Create a new MessageDialog.
|
||||
* @param title the dialog's title
|
||||
* @param message the text which will appear in the dialog
|
||||
*/
|
||||
public JMessageDialog(String title, MConstText message)
|
||||
{
|
||||
super(title);
|
||||
|
||||
Container content = getContentPane();
|
||||
content.setLayout(new CardLayout());
|
||||
TextPanelSettings settings = JTextPanel.getDefaultSettings();
|
||||
settings.setScrollable(false);
|
||||
settings.setSelectable(false);
|
||||
JTextPanel panel = new JTextPanel(settings, message, null);
|
||||
|
||||
panel.setBackground(Color.black);
|
||||
content.add("Center", panel);
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
setVisible(false);
|
||||
dispose();
|
||||
}
|
||||
});
|
||||
|
||||
setSize(450,320);
|
||||
}
|
||||
}
|
@ -1,164 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.awt.Container;
|
||||
import java.awt.FlowLayout;
|
||||
import java.awt.Frame;
|
||||
|
||||
import java.text.NumberFormat;
|
||||
import java.text.ParseException;
|
||||
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JTextField;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JLabel;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.MenuItemSet;
|
||||
import com.ibm.richtext.uiimpl.ResourceUtils;
|
||||
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
|
||||
/**
|
||||
* Simple dialog which gets a number, and sends an appropriate command
|
||||
*/
|
||||
final class JNumberDialog extends JDialog implements ActionListener
|
||||
{
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 8948601172508147011L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private MTextPanel fTextPanel;
|
||||
private JTextField fInput = null;
|
||||
|
||||
private JButton fOKButton = null;
|
||||
private JButton fCancelButton = null;
|
||||
private boolean fCharacter;
|
||||
private Object fKey;
|
||||
private float fMultiplier;
|
||||
|
||||
/**
|
||||
* @param multiplier the factor by which to multiply the user's
|
||||
* selection before creating the attribute value. This
|
||||
* is useful for subscripting.
|
||||
*/
|
||||
JNumberDialog(Frame parent,
|
||||
String title,
|
||||
String message,
|
||||
MTextPanel textPanel,
|
||||
Object key,
|
||||
boolean character,
|
||||
float multiplier) {
|
||||
|
||||
super(parent, title, false);
|
||||
fTextPanel = textPanel;
|
||||
fKey = key;
|
||||
fCharacter = character;
|
||||
fMultiplier = multiplier;
|
||||
|
||||
Container content = getContentPane();
|
||||
|
||||
content.setLayout(new java.awt.GridLayout(2,1));
|
||||
|
||||
JPanel panel = new JPanel();
|
||||
panel.setLayout(new FlowLayout(FlowLayout.CENTER, 10, 15));
|
||||
fInput = new JTextField(5);
|
||||
|
||||
panel.add(new JLabel(message));
|
||||
panel.add(fInput);
|
||||
content.add("Center", panel);
|
||||
|
||||
fCancelButton = new JButton(ResourceUtils.getResourceString(FrameResources.CANCEL));
|
||||
fOKButton = new JButton(ResourceUtils.getResourceString(FrameResources.OK));
|
||||
JPanel p = new JPanel();
|
||||
p.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
p.add(fCancelButton);
|
||||
p.add(fOKButton);
|
||||
content.add("South", p);
|
||||
|
||||
pack();
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closeWindow(false);
|
||||
}
|
||||
});
|
||||
|
||||
fOKButton.addActionListener(this);
|
||||
fCancelButton.addActionListener(this);
|
||||
}
|
||||
|
||||
private void closeWindow(boolean sendAction) {
|
||||
|
||||
setVisible(false);
|
||||
|
||||
int num = 0;
|
||||
if (sendAction) {
|
||||
try {
|
||||
String text = fInput.getText();
|
||||
num = NumberFormat.getInstance().parse(text).intValue();
|
||||
}
|
||||
catch (ParseException exception) {
|
||||
sendAction = false;
|
||||
}
|
||||
}
|
||||
|
||||
if (sendAction) {
|
||||
sendAction(num);
|
||||
}
|
||||
|
||||
dispose();
|
||||
}
|
||||
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
Object source = e.getSource();
|
||||
|
||||
if (source == fOKButton) {
|
||||
closeWindow(true);
|
||||
}
|
||||
else if (source == fCancelButton) {
|
||||
closeWindow(false);
|
||||
}
|
||||
else {
|
||||
throw new IllegalArgumentException("Invalid ActionEvent!");
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user input
|
||||
* @param number The number the user typed in
|
||||
*/
|
||||
private void sendAction(int number) {
|
||||
float num = number * fMultiplier;
|
||||
StyleModifier modifier = StyleModifier.createAddModifier(
|
||||
fKey,
|
||||
new Float(num));
|
||||
if (fCharacter == MenuItemSet.CHARACTER) {
|
||||
fTextPanel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
fTextPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,280 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import javax.swing.Box;
|
||||
import javax.swing.BorderFactory;
|
||||
import javax.swing.BoxLayout;
|
||||
import javax.swing.JDialog;
|
||||
import javax.swing.JPanel;
|
||||
import javax.swing.JScrollPane;
|
||||
import javax.swing.JButton;
|
||||
import javax.swing.JList;
|
||||
import javax.swing.JLabel;
|
||||
import javax.swing.ListSelectionModel;
|
||||
|
||||
import javax.swing.event.ListSelectionEvent;
|
||||
import javax.swing.event.ListSelectionListener;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Container;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Frame;
|
||||
import java.awt.FlowLayout;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.awt.event.MouseEvent;
|
||||
import java.awt.event.MouseAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.event.WindowAdapter;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeSet;
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.uiimpl.MenuItemSet;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
import com.ibm.richtext.uiimpl.ResourceUtils;
|
||||
|
||||
/**
|
||||
* Simple dialog that sets an attribute.
|
||||
*/
|
||||
final class JObjectDialog extends JDialog {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -9183651131772308979L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private final MTextPanel fTextPanel;
|
||||
private final Object fKey;
|
||||
private boolean fCharacter;
|
||||
private Hashtable fNameToValueMap;
|
||||
|
||||
private final JButton fOKButton;
|
||||
private final JButton fCancelButton;
|
||||
private final JList fItems;
|
||||
|
||||
/**
|
||||
* Construct a new JObjectDialog.
|
||||
* @param parent the dialog's parent frame
|
||||
* @param title the dialogs title
|
||||
* @param message the message displayed next to the input box
|
||||
*/
|
||||
JObjectDialog(Frame parent,
|
||||
String title,
|
||||
String message,
|
||||
MTextPanel textPanel,
|
||||
Object key,
|
||||
boolean character,
|
||||
String[] names,
|
||||
Object[] values) {
|
||||
|
||||
super(parent, title, false);
|
||||
|
||||
setupMap(names, values);
|
||||
|
||||
Dimension size = new Dimension(250, 200);
|
||||
|
||||
fTextPanel = textPanel;
|
||||
fKey = key;
|
||||
fCharacter = character;
|
||||
|
||||
fItems = new JList(names);
|
||||
fItems.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
|
||||
|
||||
fItems.addMouseListener(new MouseAdapter() {
|
||||
public void mouseClicked(MouseEvent e) {
|
||||
if (e.getClickCount() == 2) {
|
||||
closeWindow(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
JScrollPane listScroller = new JScrollPane(fItems);
|
||||
listScroller.setPreferredSize(size);
|
||||
listScroller.setPreferredSize(size);
|
||||
listScroller.setAlignmentX(LEFT_ALIGNMENT);
|
||||
|
||||
JLabel label = new JLabel(message);
|
||||
label.setLabelFor(fItems);
|
||||
|
||||
JPanel itemPanel = new JPanel();
|
||||
itemPanel.add(label);
|
||||
itemPanel.add(Box.createRigidArea(new Dimension(0,5)));
|
||||
itemPanel.add(listScroller);
|
||||
itemPanel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
|
||||
|
||||
itemPanel.setLayout(new BoxLayout(itemPanel, BoxLayout.Y_AXIS));
|
||||
|
||||
fCancelButton = new JButton(ResourceUtils.getResourceString(FrameResources.CANCEL));
|
||||
fOKButton = new JButton(ResourceUtils.getResourceString(FrameResources.OK));
|
||||
|
||||
JPanel buttonPanel = new JPanel();
|
||||
buttonPanel.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
|
||||
buttonPanel.add(fCancelButton);
|
||||
buttonPanel.add(fOKButton);
|
||||
|
||||
Container content = getContentPane();
|
||||
content.add(itemPanel, BorderLayout.CENTER);
|
||||
content.add(buttonPanel, BorderLayout.SOUTH);
|
||||
|
||||
pack();
|
||||
|
||||
addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
closeWindow(false);
|
||||
}
|
||||
});
|
||||
|
||||
ActionListener listener = new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
|
||||
Object source = e.getSource();
|
||||
if (source == fOKButton) {
|
||||
closeWindow(true);
|
||||
}
|
||||
else if (source == fCancelButton) {
|
||||
closeWindow(false);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
fOKButton.addActionListener(listener);
|
||||
fCancelButton.addActionListener(listener);
|
||||
|
||||
selectStyles(values);
|
||||
}
|
||||
|
||||
private void setupMap(String[] names, Object[] values) {
|
||||
|
||||
if (names.length != values.length) {
|
||||
throw new IllegalArgumentException("Must have same number of names and values.");
|
||||
}
|
||||
|
||||
fNameToValueMap = new Hashtable(names.length);
|
||||
|
||||
for (int i=0; i < names.length; i++) {
|
||||
if (values[i] != null) {
|
||||
fNameToValueMap.put(names[i], values[i]);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void closeWindow(boolean sendAction) {
|
||||
|
||||
setVisible(false);
|
||||
|
||||
if (sendAction && fItems.getMinSelectionIndex() != fItems.getMaxSelectionIndex()) {
|
||||
sendAction = false;
|
||||
}
|
||||
|
||||
if (sendAction) {
|
||||
Object value = fNameToValueMap.get(fItems.getSelectedValue());
|
||||
sendAction(value);
|
||||
}
|
||||
dispose();
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the user input
|
||||
* @param value The value object
|
||||
*/
|
||||
private void sendAction(Object value) {
|
||||
|
||||
StyleModifier modifier;
|
||||
if (value != null) {
|
||||
modifier = StyleModifier.createAddModifier(fKey, value);
|
||||
}
|
||||
else {
|
||||
AttributeSet set = new AttributeSet(fKey);
|
||||
modifier = StyleModifier.createRemoveModifier(set);
|
||||
}
|
||||
|
||||
if (fCharacter == MenuItemSet.CHARACTER) {
|
||||
fTextPanel.modifyCharacterStyleOnSelection(modifier);
|
||||
}
|
||||
else {
|
||||
fTextPanel.modifyParagraphStyleOnSelection(modifier);
|
||||
}
|
||||
}
|
||||
|
||||
private void selectValue(Object value, Object[] values) {
|
||||
|
||||
for (int i=0; i < values.length; i++) {
|
||||
|
||||
if ((value != null && value.equals(values[i])) || (value == null && values[i] == null)) {
|
||||
fItems.addSelectionInterval(i, i);
|
||||
fItems.ensureIndexIsVisible(i);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void selectStyles(Object[] values) {
|
||||
|
||||
Object value;
|
||||
|
||||
if (fCharacter) {
|
||||
value = fTextPanel.getCharacterStyleOverSelection(fKey);
|
||||
}
|
||||
else {
|
||||
value = fTextPanel.getParagraphStyleOverSelection(fKey);
|
||||
}
|
||||
|
||||
if (value != MTextPanel.MULTIPLE_VALUES) {
|
||||
selectValue(value, values);
|
||||
}
|
||||
else {
|
||||
fOKButton.setEnabled(false);
|
||||
|
||||
int selLimit = fTextPanel.getSelectionEnd();
|
||||
MConstText text = fTextPanel.getText();
|
||||
for (int runStart = fTextPanel.getSelectionStart(); runStart <= selLimit;
|
||||
runStart = fCharacter? text.characterStyleLimit(runStart) :
|
||||
text.paragraphLimit(runStart)) {
|
||||
|
||||
Object runVal;
|
||||
if (fCharacter) {
|
||||
runVal = text.characterStyleAt(runStart).get(fKey);
|
||||
}
|
||||
else {
|
||||
runVal = text.paragraphStyleAt(runStart).get(fKey);
|
||||
}
|
||||
if (runVal == null) {
|
||||
runVal = fTextPanel.getDefaultValues().get(fKey);
|
||||
}
|
||||
|
||||
selectValue(runVal, values);
|
||||
if (runStart == text.length()) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fItems.addListSelectionListener(new ListSelectionListener() {
|
||||
public void valueChanged(ListSelectionEvent e) {
|
||||
fItems.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
|
||||
fOKButton.setEnabled(true);
|
||||
fItems.removeListSelectionListener(this);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Graphics;
|
||||
|
||||
import javax.swing.JComponent;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.styledtext.MTabRuler;
|
||||
|
||||
import com.ibm.richtext.uiimpl.TabRulerImpl;
|
||||
import com.ibm.richtext.awtui.MTabRulerComponent;
|
||||
|
||||
/**
|
||||
* JTabRuler is an implementation of MTabRulerComponent in a Swing component.
|
||||
*/
|
||||
public final class JTabRuler extends JComponent implements MTabRulerComponent {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 8547581956295504028L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private TabRulerImpl fImpl;
|
||||
|
||||
/**
|
||||
* Create a new TabRuler.
|
||||
* @param baseline the y-coordinate of the ruler's baseline
|
||||
* @param origin the x-coordinate in this Component where
|
||||
* the left margin appears
|
||||
* @param textPanel the MTextPanel to listen to. This TabRuler
|
||||
* will reflect the MTextPanel's paragraph styles, and update
|
||||
* the paragraph styles when manipulated.
|
||||
*/
|
||||
public JTabRuler(int baseline, int origin, MTextPanel textPanel) {
|
||||
|
||||
fImpl = new TabRulerImpl(baseline, origin, textPanel, this);
|
||||
}
|
||||
|
||||
/**
|
||||
* Listen to the given MTextPanel and reflect its changes,
|
||||
* and update its paragraph styles when TabRuler is
|
||||
* manipulated.
|
||||
* @param textPanel the MTextPanel to listen to
|
||||
*/
|
||||
public void listenToTextPanel(MTextPanel textPanel) {
|
||||
|
||||
fImpl.listenToTextPanel(textPanel);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the background color of this TabRuler.
|
||||
* @return the background color of this TabRuler
|
||||
*/
|
||||
public Color getBackColor() {
|
||||
|
||||
return fImpl.getBackColor();
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the background color of this TabRuler.
|
||||
* @param backColor the new background color of this TabRuler
|
||||
*/
|
||||
public void setBackColor(Color backColor) {
|
||||
|
||||
fImpl.setBackColor(backColor);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MTabRuler represented by this TabRuler.
|
||||
* @return the MTabRuler represented by this TabRuler
|
||||
*/
|
||||
public MTabRuler getRuler() {
|
||||
|
||||
return fImpl.getRuler();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the leading margin of this TabRuler.
|
||||
* @return the leading margin of this TabRuler
|
||||
*/
|
||||
public int getLeadingMargin() {
|
||||
|
||||
return fImpl.getLeadingMargin();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the first line indent of this TabRuler.
|
||||
* @return the first line indent of this TabRuler
|
||||
*/
|
||||
public int getFirstLineIndent() {
|
||||
|
||||
return fImpl.getFirstLineIndent();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the trailing margin of this TabRuler.
|
||||
* @return the trailing margin of this TabRuler
|
||||
*/
|
||||
public final int getTrailingMargin() {
|
||||
|
||||
return fImpl.getTrailingMargin();
|
||||
}
|
||||
|
||||
// The following are Component methods which need to be delegated to
|
||||
// the implementation:
|
||||
|
||||
public void paint(Graphics g) {
|
||||
|
||||
fImpl.paint(g);
|
||||
}
|
||||
|
||||
public Dimension getPreferredSize() {
|
||||
|
||||
return fImpl.getPreferredSize();
|
||||
}
|
||||
|
||||
public Dimension getMinimumSize() {
|
||||
|
||||
return fImpl.getMinimumSize();
|
||||
}
|
||||
}
|
@ -1,145 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
import com.ibm.richtext.textpanel.JTextPanel;
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import java.awt.BorderLayout;
|
||||
import java.awt.Toolkit;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
|
||||
import javax.swing.JFrame;
|
||||
import javax.swing.JMenuBar;
|
||||
import javax.swing.UIManager;
|
||||
|
||||
import java.awt.Container;
|
||||
|
||||
/**
|
||||
* JTextFrame is a JFrame containing an editable JTextPanel, a set of standard
|
||||
* menus, and a JTabRuler. This class can be used as-is, but is
|
||||
* primarily intended to be a simple example of how to use the other classes
|
||||
* in this package.
|
||||
* @see com.ibm.richtext.textpanel.JTextPanel
|
||||
* @see SwingMenuBuilder
|
||||
* @see JTabRuler
|
||||
*/
|
||||
public final class JTextFrame extends JFrame {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = -1026126723995559230L;
|
||||
//static final String COPYRIGHT =
|
||||
// "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private JTextPanel fTextPanel;
|
||||
|
||||
/**
|
||||
* Create a new JTextFrame with no text, no title,
|
||||
* and a private clipboard.
|
||||
*/
|
||||
public JTextFrame() {
|
||||
|
||||
super();
|
||||
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JTextFrame with no text and the given title.
|
||||
* The JTextPanel will use a private clipboard.
|
||||
* @param title the title of this Frame
|
||||
*/
|
||||
public JTextFrame(String title) {
|
||||
|
||||
super(title);
|
||||
init(null, Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new JTextFrame with the given text and title, whose
|
||||
* TextPanel will use the given clipboard.
|
||||
* @param text the initial text in the TextPanel. If null the
|
||||
* TextPanel will initially be empty
|
||||
* @param title the title of this Frame
|
||||
* @param clipboard the Clipboard which the TextPanel will use.
|
||||
* If null the TextPanel will use a private Clipboard
|
||||
*/
|
||||
public JTextFrame(MConstText text,
|
||||
String title,
|
||||
Clipboard clipboard) {
|
||||
|
||||
super(title);
|
||||
init(text, clipboard);
|
||||
}
|
||||
|
||||
private void init(MConstText text, Clipboard clipboard) {
|
||||
|
||||
fTextPanel = new JTextPanel(text, clipboard);
|
||||
|
||||
JTabRuler tabRuler = new JTabRuler(14, 10, fTextPanel);
|
||||
|
||||
createMenus();
|
||||
|
||||
Container contentPane = getContentPane();
|
||||
contentPane.setLayout(new BorderLayout());
|
||||
contentPane.add(fTextPanel, "Center");
|
||||
contentPane.add(tabRuler, "North");
|
||||
pack();
|
||||
}
|
||||
|
||||
private void createMenus() {
|
||||
|
||||
JMenuBar menuBar = new JMenuBar();
|
||||
|
||||
SwingMenuBuilder.getInstance().createMenus(menuBar, fTextPanel, this);
|
||||
|
||||
setJMenuBar(menuBar);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MTextPanel in this frame.
|
||||
*/
|
||||
public MTextPanel getTextPanel() {
|
||||
|
||||
return fTextPanel;
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String laf = UIManager.getSystemLookAndFeelClassName();
|
||||
if (args.length == 1) {
|
||||
if (args[0].equals("cp")) {
|
||||
laf = UIManager.getCrossPlatformLookAndFeelClassName();
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
UIManager.setLookAndFeel(laf);
|
||||
}
|
||||
catch(Throwable th) {
|
||||
th.printStackTrace();
|
||||
}
|
||||
JTextFrame frame = new JTextFrame();
|
||||
frame.addWindowListener(new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
});
|
||||
frame.setSize(550, 700);
|
||||
frame.show();
|
||||
}
|
||||
}
|
@ -1,234 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2008. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuBar;
|
||||
|
||||
import com.ibm.richtext.textpanel.MTextPanel;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.FrameResources;
|
||||
|
||||
import com.ibm.richtext.uiimpl.*;
|
||||
import com.ibm.richtext.uiimpl.DialogItem.DialogFactory;
|
||||
|
||||
/**
|
||||
* SwingMenuBuilder provides a method for creating a set of Swing menus for interacting
|
||||
* with an MTextPanel. Future versions of this class may provide greater control
|
||||
* over the menu contents.
|
||||
* @see MTextPanel
|
||||
*/
|
||||
public final class SwingMenuBuilder extends MenuBuilder {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final SwingMenuBuilder INSTANCE = new SwingMenuBuilder();
|
||||
|
||||
/**
|
||||
* Id for an Edit menu. The Edit menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Undo</b> - invoke undo() on the MTextPanel</li>
|
||||
* <li><b>Redo</b> - invoke redo() on the MTextPanel</li>
|
||||
* <li><b>Cut</b> - invoke cut() on the MTextPanel</li>
|
||||
* <li><b>Copy</b> - invoke copy() on the MTextPanel</li>
|
||||
* <li><b>Paste</b> - invoke paste() on the MTextPanel</li>
|
||||
* <li><b>Clear</b> - invoke clear() on the MTextPanel</li>
|
||||
* <li><b>Select All</b> - invoke selectAll() on the MTextPanel</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int EDIT = MenuBuilder.EDIT;
|
||||
/**
|
||||
* Id for the point sizes menu. The menu has items that set the size of a character
|
||||
* in a typeface.
|
||||
*/
|
||||
public static final int SIZE = MenuBuilder.SIZE;
|
||||
/**
|
||||
* Id for a Style menu. The Style menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Plain</b> - remove <code>WEIGHT</code>,
|
||||
* <code>POSTURE</code>,
|
||||
* <code>UNDERLINE</code> and
|
||||
* <code>STRIKETHROUGH</code> attributes from the
|
||||
* current selection</li>
|
||||
* <li><b>Bold</b> - add <code>{WEIGHT,WEIGHT_BOLD}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Italic</b> - add <code>{POSTURE,POSTURE_ITALIC}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Underline</b> - add <code>{UNDERLINE,UNDERLINE_ON}</code> to
|
||||
* the current selection</li>
|
||||
* <li><b>Strikethrough</b> - add <code>{STRIKETHROUGH,STRIKETHROUGH_ON}</code>
|
||||
* to the current selection</li>
|
||||
* <li><b>Font...</b> - display a dialog allowing the user to
|
||||
* select a typeface (font family) for the current selection</li>
|
||||
* <li><b>Forecolor...</b> - display a dialog allowing the user to
|
||||
* select a foreground color for the current selection</li>
|
||||
* <li><b>Backcolor...</b> - display a dialog allowing the user to
|
||||
* select a background color for the current selection</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int STYLE = MenuBuilder.STYLE;
|
||||
/**
|
||||
* Id for a paragraph alignment menu. The menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Leading</b> - give selected paragraph(s) LEADING flush</li>
|
||||
* <li><b>Center</b> - give selected paragraph(s) CENTER flush</li>
|
||||
* <li><b>Trailing</b> - give selected paragraph(s) TRAILING flush</li>
|
||||
* <li><b>Justified</b> - give selected paragraph(s) full justification</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int FLUSH = MenuBuilder.FLUSH;
|
||||
/**
|
||||
* Id for a menu that sets the KeyRemap
|
||||
* on an MTextPanel. The menu has the following items:
|
||||
* <ul>
|
||||
* <li><b>Default</b> - set KeyRemap to identity remap</li>
|
||||
* <li><b>Arabic</b> - set KeyRemap to Arabic transliteration</li>
|
||||
* <li><b>Hebrew</b> - set KeyRemap to Hebrew transliteration</li>
|
||||
* <li><b>Israel Nikud</b> - set KeyRemap to Israel Nikud</li>
|
||||
* <li><b>Thai Ketmanee</b> - set KeyRemap to Thai Ketmanee</li>
|
||||
* </ul>
|
||||
*/
|
||||
public static final int KEYMAP = MenuBuilder.KEYMAP;
|
||||
/**
|
||||
* Id for a menu that sets
|
||||
* the primary run direction for a paragraph. Run direction can be left-to-right,
|
||||
* right-to-left, or can use the default run direction from the Unicode bidi algorithm.
|
||||
*/
|
||||
public static final int BIDI = MenuBuilder.BIDI;
|
||||
/**
|
||||
* Id for a menu with an <b>About</b> item. When selected,
|
||||
* the item displays a Frame containing some
|
||||
* self-promotional text.
|
||||
*/
|
||||
public static final int ABOUT = MenuBuilder.ABOUT;
|
||||
/**
|
||||
* Return an instance of SwingMenuBuilder.
|
||||
*/
|
||||
|
||||
public static SwingMenuBuilder getInstance() {
|
||||
|
||||
return INSTANCE;
|
||||
}
|
||||
|
||||
private JMenuBar fMenuBar;
|
||||
|
||||
private SwingMenuBuilder() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a standard set of menus to the given menu bar. The menus
|
||||
* will interact with the given MTextPanel.
|
||||
* @param menuBar the MenuBar to which menus are added
|
||||
* @param textPanel the MTextPanel with which the menus interact
|
||||
* @param frame a Frame to use as the parent of any dialogs created by a
|
||||
* a menu item. If null, menu items which create dialogs will be omitted.
|
||||
*/
|
||||
public void createMenus(JMenuBar menuBar,
|
||||
MTextPanel textPanel,
|
||||
Frame frame) {
|
||||
|
||||
createMenus(menuBar, textPanel, frame, defaultMenus);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add a set of menus to the given menu bar. The menus
|
||||
* will interact with the given MTextPanel.
|
||||
* @param menuBar the MenuBar to which menus are added
|
||||
* @param textPanel the MTextPanel with which the menus interact
|
||||
* @param frame a Frame to use as the parent of any dialogs created by a
|
||||
* a menu item. If null, menu items which create dialogs will be omitted.
|
||||
* @param menus an array of integer menu id's. Each element of the
|
||||
* array must be one of this class's menu id constants. If null,
|
||||
* the default menus are created.
|
||||
*/
|
||||
public void createMenus(JMenuBar menuBar,
|
||||
MTextPanel textPanel,
|
||||
Frame frame,
|
||||
int[] menus) {
|
||||
|
||||
if (menus == null) {
|
||||
menus = defaultMenus;
|
||||
}
|
||||
|
||||
synchronized (MItem.LOCK) {
|
||||
|
||||
fMenuBar = menuBar;
|
||||
doCreateMenus(textPanel, frame, menus);
|
||||
fMenuBar = null;
|
||||
}
|
||||
}
|
||||
|
||||
protected void handleAddMenu(String key) {
|
||||
|
||||
JMenu menu = new JMenu(ResourceUtils.getResourceString(key));
|
||||
fMenuBar.add(menu);
|
||||
MItem.setItemFactory(new SwingMenuFactory(menu));
|
||||
}
|
||||
|
||||
protected DialogFactory createObjectDialogFactory(final String dialogTitle,
|
||||
final String dialogMessage,
|
||||
final Object key,
|
||||
final boolean character,
|
||||
final String[] names,
|
||||
final Object[] values) {
|
||||
|
||||
final Frame dialogParent = fDialogParent;
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel textPanel) {
|
||||
return new JObjectDialog(dialogParent,
|
||||
dialogTitle,
|
||||
dialogMessage,
|
||||
textPanel,
|
||||
key,
|
||||
character,
|
||||
names,
|
||||
values);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected DialogFactory createNumberDialogFactory(final String dialogTitle,
|
||||
final String dialogMessage,
|
||||
final Object key,
|
||||
final boolean character) {
|
||||
|
||||
final Frame dialogParent = fDialogParent;
|
||||
// variable not used final MTextPanel textPanel = fTextPanel;
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel fTxtPanel) {
|
||||
return new JNumberDialog(dialogParent,
|
||||
dialogTitle,
|
||||
dialogMessage,
|
||||
fTxtPanel,
|
||||
key,
|
||||
character,
|
||||
1);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
protected DialogFactory createAboutDialogFactory() {
|
||||
|
||||
return new DialogFactory() {
|
||||
public Window createDialog(MTextPanel textPanel) {
|
||||
String title = ResourceUtils.getResourceString(FrameResources.ABOUT_TITLE);
|
||||
return new JMessageDialog(title, AboutText.getAboutText());
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
@ -1,105 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.swingui;
|
||||
|
||||
import java.awt.Event;
|
||||
|
||||
import javax.swing.JCheckBoxMenuItem;
|
||||
import javax.swing.JMenu;
|
||||
import javax.swing.JMenuItem;
|
||||
import javax.swing.JSeparator;
|
||||
import javax.swing.KeyStroke;
|
||||
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
|
||||
import com.ibm.richtext.uiimpl.resources.MenuData;
|
||||
import com.ibm.richtext.uiimpl.MItem;
|
||||
import com.ibm.richtext.uiimpl.MItem.ItemFactory;
|
||||
|
||||
final class SwingMenuFactory implements ItemFactory {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private final class SwingMItem extends MItem {
|
||||
|
||||
private JMenuItem fItem;
|
||||
|
||||
SwingMItem(JMenuItem item) {
|
||||
|
||||
fItem = item;
|
||||
item.addActionListener(new ActionListener() {
|
||||
public void actionPerformed(ActionEvent e) {
|
||||
handleSelected();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
protected void handleSelected() {
|
||||
|
||||
super.handleSelected();
|
||||
}
|
||||
|
||||
public final void setEnabled(boolean enabled) {
|
||||
|
||||
fItem.setEnabled(enabled);
|
||||
}
|
||||
|
||||
public void setState(boolean checked) {
|
||||
|
||||
try {
|
||||
JCheckBoxMenuItem item = (JCheckBoxMenuItem) fItem;
|
||||
item.setState(checked);
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
throw new Error("Cannot perform setChecked on non-checkbox item");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private JMenu fMenu;
|
||||
|
||||
SwingMenuFactory(JMenu menu) {
|
||||
|
||||
fMenu = menu;
|
||||
}
|
||||
|
||||
private MItem handleCreate(JMenuItem item,
|
||||
MenuData menuData) {
|
||||
|
||||
if (menuData.hasShortcut()) {
|
||||
KeyStroke ks = KeyStroke.getKeyStroke(menuData.getShortcutKeyCode(),
|
||||
Event.CTRL_MASK);
|
||||
item.setAccelerator(ks);
|
||||
}
|
||||
|
||||
fMenu.add(item);
|
||||
|
||||
return new SwingMItem(item);
|
||||
}
|
||||
|
||||
public MItem createItem(MenuData menuData) {
|
||||
|
||||
return handleCreate(new JMenuItem(menuData.getName()), menuData);
|
||||
}
|
||||
|
||||
public MItem createCheckboxItem(MenuData menuData) {
|
||||
|
||||
return handleCreate(new JCheckBoxMenuItem(menuData.getName()), menuData);
|
||||
}
|
||||
|
||||
public void createSeparator() {
|
||||
|
||||
fMenu.add(new JSeparator());
|
||||
}
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
<!--
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
-->
|
||||
<html>
|
||||
<body bgcolor="white">
|
||||
Provides classes for building a Swing-based user interface for a TextPanel.
|
||||
</body>
|
||||
</html>
|
@ -1,44 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import java.awt.event.WindowAdapter;
|
||||
import java.awt.event.WindowEvent;
|
||||
import java.awt.Frame;
|
||||
import java.awt.Window;
|
||||
|
||||
class AppCloser {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int fCount = 0;
|
||||
|
||||
private WindowAdapter fAdapter = new WindowAdapter() {
|
||||
|
||||
public void windowClosing(WindowEvent e) {
|
||||
--fCount;
|
||||
if (fCount == 0) {
|
||||
System.exit(0);
|
||||
}
|
||||
Window w = e.getWindow();
|
||||
w.setVisible(false);
|
||||
w.dispose();
|
||||
}
|
||||
};
|
||||
|
||||
public void listenToFrame(Frame frame) {
|
||||
|
||||
++fCount;
|
||||
frame.addWindowListener(fAdapter);
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.awtui.TextFrame;
|
||||
|
||||
import java.awt.Toolkit;
|
||||
|
||||
import java.io.*;
|
||||
import java.net.URL;
|
||||
import java.util.ResourceBundle;
|
||||
|
||||
public class BidiDemo {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final AppCloser fgListener = new AppCloser();
|
||||
|
||||
private static final String BUNDLE_NAME = "com.ibm.richtext.textapps.resources.Sample";
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
String docName;
|
||||
|
||||
if (args.length == 0) {
|
||||
docName = "default";
|
||||
}
|
||||
else {
|
||||
docName = args[0];
|
||||
}
|
||||
|
||||
openText(docName);
|
||||
}
|
||||
|
||||
private static void openText(String docName) {
|
||||
|
||||
try {
|
||||
ResourceBundle bundle = ResourceBundle.getBundle(BUNDLE_NAME);
|
||||
|
||||
Object document = bundle.getObject(docName+".sample");
|
||||
MConstText text;
|
||||
|
||||
if (document instanceof String) {
|
||||
text = new StyledText((String)document,
|
||||
AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
}
|
||||
else {
|
||||
URL url = (URL) document;
|
||||
ObjectInputStream in = new ObjectInputStream(url.openStream());
|
||||
text = (MConstText) in.readObject();
|
||||
}
|
||||
|
||||
String name = bundle.getString(docName+".name");
|
||||
|
||||
makeFrame(text, name);
|
||||
}
|
||||
catch(Throwable t) {
|
||||
t.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
private static void makeFrame(MConstText text, String title) {
|
||||
|
||||
TextFrame frame = new TextFrame(text, title,
|
||||
Toolkit.getDefaultToolkit().getSystemClipboard());
|
||||
frame.setSize(550, 700);
|
||||
frame.show();
|
||||
fgListener.listenToFrame(frame);
|
||||
}
|
||||
}
|
@ -1,128 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import java.awt.FileDialog;
|
||||
import java.awt.Frame;
|
||||
import java.io.*;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
|
||||
public class FileUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Present the user with a file dialog, and replace
|
||||
* dest with the MText in the selected file, and return
|
||||
* the file objct. If any errors occur, return null and
|
||||
* do not modify dest.
|
||||
*/
|
||||
public static File userLoadMText(String title, MText dest, Frame owner) {
|
||||
|
||||
FileDialog dialog = new FileDialog(owner, title, FileDialog.LOAD);
|
||||
dialog.show();
|
||||
String fileStr = dialog.getFile();
|
||||
String dirStr = dialog.getDirectory();
|
||||
|
||||
if (fileStr != null) {
|
||||
File rval = new File(dirStr, fileStr);
|
||||
MConstText src = loadMText(rval);
|
||||
if (src != null) {
|
||||
dest.replaceAll(src);
|
||||
return rval;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the MText serialized in the given file.
|
||||
* In case of an error return null.
|
||||
*/
|
||||
public static MConstText loadMText(File file) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
FileInputStream inStream = new FileInputStream(file);
|
||||
ObjectInputStream objStream = new ObjectInputStream(inStream);
|
||||
|
||||
MConstText text = (MConstText) objStream.readObject();
|
||||
inStream.close();
|
||||
return text;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassNotFoundException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Prompt the user for the file if file is null. Then save the
|
||||
* text in the file, if any.
|
||||
*/
|
||||
public static File userSaveMText(File file, String title, MConstText text, Frame owner) {
|
||||
|
||||
if (file == null) {
|
||||
|
||||
FileDialog dialog = new FileDialog(owner, title, FileDialog.SAVE);
|
||||
dialog.show();
|
||||
String fileStr = dialog.getFile();
|
||||
String dirStr = dialog.getDirectory();
|
||||
|
||||
if (fileStr != null) {
|
||||
file = new File(dirStr, fileStr);
|
||||
}
|
||||
}
|
||||
|
||||
if (file != null) {
|
||||
|
||||
saveMText(file, text);
|
||||
}
|
||||
|
||||
return file;
|
||||
}
|
||||
|
||||
public static void saveMText(File file, MConstText text) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
OutputStream outStream = new FileOutputStream(file);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(outStream);
|
||||
|
||||
objStream.writeObject(text);
|
||||
outStream.close();
|
||||
return;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
@ -1,82 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public final class MTextToString {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
if (args.length != 2) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
writeMTextAsString(args[0], args[1]);
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: MTextToString inFile outFile");
|
||||
System.out.println("inFile must be a serialized MConstText");
|
||||
System.out.println("On exit, outFile will be a serialized String ");
|
||||
System.out.println("containing the characters in the text.");
|
||||
System.out.println("inFile and outFile must not be the same.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static void writeMTextAsString(String inFile, String outFile) {
|
||||
|
||||
File file = new File(inFile);
|
||||
MConstText text = FileUtils.loadMText(file);
|
||||
|
||||
if (text != null) {
|
||||
char[] ch = new char[text.length()];
|
||||
text.extractChars(0, ch.length, ch, 0);
|
||||
String str = new String(ch);
|
||||
writeString(str, outFile);
|
||||
}
|
||||
else {
|
||||
System.out.println("Can't read inFile.");
|
||||
}
|
||||
}
|
||||
|
||||
public static void writeString(String stringToWrite, String outFile) {
|
||||
|
||||
File file = new File(outFile);
|
||||
Throwable error = null;
|
||||
|
||||
try {
|
||||
OutputStream outStream = new FileOutputStream(file);
|
||||
ObjectOutputStream objStream = new ObjectOutputStream(outStream);
|
||||
|
||||
objStream.writeObject(stringToWrite);
|
||||
outStream.close();
|
||||
return;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
}
|
||||
}
|
@ -1,76 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import java.io.*;
|
||||
|
||||
public final class StringToMText {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
|
||||
if (args.length != 2 || args[0].equals(args[1])) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
String str = loadString(new File(args[0]));
|
||||
if (str == null) {
|
||||
throw new Error("Couldn't load String from file " + args[0]);
|
||||
}
|
||||
MConstText text = new StyledText(str, AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
FileUtils.saveMText(new File(args[1]), text);
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: StringToMText inFile outFile");
|
||||
System.out.println("inFile must be a serialized String");
|
||||
System.out.println("On exit, outFile will be a serialized MText ");
|
||||
System.out.println("containing the characters in the string.");
|
||||
System.out.println("inFile and outFile must not be the same.");
|
||||
System.exit(1);
|
||||
}
|
||||
|
||||
public static String loadString(File file) {
|
||||
|
||||
Throwable error;
|
||||
|
||||
try {
|
||||
FileInputStream inStream = new FileInputStream(file);
|
||||
ObjectInputStream objStream = new ObjectInputStream(inStream);
|
||||
|
||||
String str = (String) objStream.readObject();
|
||||
inStream.close();
|
||||
return str;
|
||||
}
|
||||
catch(IOException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassNotFoundException e) {
|
||||
error = e;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
error = e;
|
||||
}
|
||||
|
||||
error.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textapps;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import java.io.File;
|
||||
|
||||
public final class TestMTextToString {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public static void main(String[] args) {
|
||||
|
||||
if (args.length != 2 || args[0].equals(args[1])) {
|
||||
usage();
|
||||
}
|
||||
else {
|
||||
boolean success = testMTextToString(args[0], args[1]);
|
||||
System.out.println(success? "PASSED" : "FAILED");
|
||||
}
|
||||
}
|
||||
|
||||
private static void usage() {
|
||||
|
||||
System.out.println("Usage: TestMTextToString mtextFile stringFile");
|
||||
System.out.println("Compares the characters in mtextFile to the");
|
||||
System.out.println("String in stringFile.");
|
||||
System.exit(0);
|
||||
}
|
||||
|
||||
public static boolean testMTextToString(String mtextFile, String stringFile) {
|
||||
|
||||
boolean success = false;
|
||||
|
||||
File mtext = new File(mtextFile);
|
||||
MConstText text = FileUtils.loadMText(mtext);
|
||||
if (text != null) {
|
||||
String str = StringToMText.loadString(new File(stringFile));
|
||||
if (str != null) {
|
||||
success = compareMTextToString(text, str);
|
||||
}
|
||||
else {
|
||||
System.out.println("Couldn't load String.");
|
||||
}
|
||||
}
|
||||
else {
|
||||
System.out.println("Couldn't load MText.");
|
||||
}
|
||||
|
||||
return success;
|
||||
}
|
||||
|
||||
public static boolean compareMTextToString(MConstText text, String str) {
|
||||
|
||||
if (text.length() != str.length()) {
|
||||
return false;
|
||||
}
|
||||
for (int i=str.length()-1; i >= 0; i--) {
|
||||
if (text.at(i) != str.charAt(i)) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
@ -1,26 +0,0 @@
|
||||
/**
|
||||
*******************************************************************************
|
||||
* Copyright (C) 2000-2004, International Business Machines Corporation and *
|
||||
* others. All Rights Reserved. *
|
||||
*******************************************************************************
|
||||
*/
|
||||
package com.ibm.richtext.textapps.resources;
|
||||
|
||||
import java.util.ListResourceBundle;
|
||||
|
||||
public final class Sample extends ListResourceBundle {
|
||||
|
||||
public Object[][] getContents() {
|
||||
|
||||
/*Object sample =*/ this.getClass().getResource("hagan");
|
||||
|
||||
return new Object[][] {
|
||||
{ "default.sample", this.getClass().getResource("unicode.hebrew.red") },
|
||||
{ "default.name", "What is Unicode - Hebrew" },
|
||||
{ "arabic.sample", this.getClass().getResource("unicode.arabic.red") },
|
||||
{ "arabic.name", "What is Unicode - Arabic" },
|
||||
{ "japanese.sample", "\u6ce8: {1} \u306e\u30e1\u30bd\u30c3\u30c9 {0} \u306f\u63a8\u5968\u3055\u308c\u307e\u305b\u3093\u3002" },
|
||||
{ "japanese.name", "Japanese Message" },
|
||||
};
|
||||
}
|
||||
}
|
Binary file not shown.
Binary file not shown.
File diff suppressed because it is too large
Load Diff
File diff suppressed because it is too large
Load Diff
@ -1,140 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import java.awt.Shape;
|
||||
///*JDK12IMPORTS
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.geom.Rectangle2D;
|
||||
import java.awt.geom.PathIterator;
|
||||
import java.awt.geom.Line2D;
|
||||
//JDK12IMPORTS*/
|
||||
/*JDK11IMPORTS
|
||||
import com.ibm.richtext.textlayout.Graphics2D;
|
||||
import com.ibm.richtext.textlayout.Rectangle2D;
|
||||
JDK11IMPORTS*/
|
||||
|
||||
/**
|
||||
* This class exists to work around a clipping bug in JDK 1.2.
|
||||
*/
|
||||
final class ClipWorkaround {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
///*JDK12IMPORTS
|
||||
private static final String excuse =
|
||||
"Sorry, this method is a very limited workaround for a JDK 1.2 bug.";
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
static Object saveClipState(Graphics2D g) {
|
||||
///*JDK12IMPORTS
|
||||
return null;
|
||||
//JDK12IMPORTS*/
|
||||
/*JDK11IMPORTS
|
||||
return g.getClip();
|
||||
JDK11IMPORTS*/
|
||||
}
|
||||
|
||||
static void restoreClipState(Graphics2D g, Object state) {
|
||||
///*JDK12IMPORTS
|
||||
if (state != null) {
|
||||
throw new Error("Invalid clip state for this class.");
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
/*JDK11IMPORTS
|
||||
g.setClip((Shape)state);
|
||||
JDK11IMPORTS*/
|
||||
}
|
||||
|
||||
/**
|
||||
* Draw the given Shape into the Graphics, translated by (dx, dy)
|
||||
* and clipped to clipRect.
|
||||
*/
|
||||
static void translateAndDrawShapeWithClip(Graphics2D g,
|
||||
int dx,
|
||||
int dy,
|
||||
Rectangle2D clipRect,
|
||||
Shape shape) {
|
||||
///*JDK12IMPORTS
|
||||
// really bogus implementation right now: basically only
|
||||
// draws carets from a TextLayout.
|
||||
// Oh yeah, it doesn't really clip correctly either...
|
||||
|
||||
PathIterator pathIter = shape.getPathIterator(null);
|
||||
float[] points = new float[6];
|
||||
|
||||
int type = pathIter.currentSegment(points);
|
||||
if (type != PathIterator.SEG_MOVETO) {
|
||||
throw new Error(excuse);
|
||||
}
|
||||
float x1 = points[0] + dx;
|
||||
float y1 = points[1] + dy;
|
||||
|
||||
if (pathIter.isDone()) {
|
||||
throw new Error(excuse);
|
||||
}
|
||||
|
||||
pathIter.next();
|
||||
type = pathIter.currentSegment(points);
|
||||
if (type != PathIterator.SEG_LINETO) {
|
||||
throw new Error(excuse);
|
||||
}
|
||||
float x2 = points[0] + dx;
|
||||
float y2 = points[1] + dy;
|
||||
|
||||
float minY = (float) clipRect.getY();
|
||||
float maxY = (float) clipRect.getMaxY();
|
||||
|
||||
// Now clip within vertical limits in clipRect
|
||||
if (y1 == y2) {
|
||||
if (y1 < minY || y1 >= maxY) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
else {
|
||||
if (y1 > y2) {
|
||||
float t = x1;
|
||||
x1 = x2;
|
||||
x2 = t;
|
||||
t = y1;
|
||||
y1 = y2;
|
||||
y2 = t;
|
||||
}
|
||||
|
||||
float invSlope = (x2-x1) / (y2-y1);
|
||||
if (y1 < minY) {
|
||||
x1 -= (minY-y1) * invSlope;
|
||||
y1 = minY;
|
||||
}
|
||||
if (y2 >= maxY) {
|
||||
x1 += (y2-maxY) * invSlope;
|
||||
y2 = maxY;
|
||||
}
|
||||
}
|
||||
|
||||
g.draw(new Line2D.Float(x1, y1, x2, y2));
|
||||
//JDK12IMPORTS*/
|
||||
/*JDK11IMPORTS
|
||||
g.setClip(clipRect);
|
||||
g.translate(dx, dy);
|
||||
try {
|
||||
g.draw(shape);
|
||||
}
|
||||
finally {
|
||||
g.translate(-dx, -dy);
|
||||
}
|
||||
JDK11IMPORTS*/
|
||||
}
|
||||
}
|
@ -1,93 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import java.util.Hashtable;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
///*JDK12IMPORTS
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.TextLayout;
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/*JDK11IMPORTS
|
||||
import com.ibm.richtext.textlayout.FontRenderContext;
|
||||
import com.ibm.richtext.textlayout.TextLayout;
|
||||
JDK11IMPORTS*/
|
||||
|
||||
/**
|
||||
* This class is used by the Formatter to estimate the height
|
||||
* of characters in a particular style.
|
||||
*/
|
||||
final class DefaultCharacterMetric {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
final class Metric {
|
||||
|
||||
private float fAscent;
|
||||
private float fDescent;
|
||||
private float fLeading;
|
||||
|
||||
private Metric(float ascent, float descent, float leading) {
|
||||
|
||||
fAscent = ascent;
|
||||
fDescent = descent;
|
||||
fLeading = leading;
|
||||
}
|
||||
|
||||
public int getAscent() {
|
||||
return (int) Math.ceil(fAscent);
|
||||
}
|
||||
|
||||
public int getDescent() {
|
||||
return (int) Math.ceil(fDescent);
|
||||
}
|
||||
|
||||
public int getLeading() {
|
||||
return (int) Math.ceil(fLeading);
|
||||
}
|
||||
}
|
||||
|
||||
private final Hashtable fCache = new Hashtable();
|
||||
private /*final*/ FontResolver fResolver;
|
||||
private /*final*/ FontRenderContext fFrc;
|
||||
|
||||
public DefaultCharacterMetric(FontResolver resolver,
|
||||
FontRenderContext frc) {
|
||||
|
||||
fResolver = resolver;
|
||||
fFrc = frc;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a DefaultCharacterMetric instance for the given style. The
|
||||
* style is first resolved with FontResolver.
|
||||
*/
|
||||
public Metric getMetricForStyle(AttributeMap style) {
|
||||
|
||||
style = fResolver.applyFont(style);
|
||||
Metric metric = (Metric) fCache.get(style);
|
||||
if (metric == null) {
|
||||
TextLayout layout = new TextLayout(" ", style, fFrc);
|
||||
metric = new Metric(layout.getAscent(),
|
||||
layout.getDescent(),
|
||||
layout.getLeading());
|
||||
fCache.put(style, metric);
|
||||
}
|
||||
return metric;
|
||||
}
|
||||
}
|
@ -1,83 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
import com.ibm.richtext.textlayout.attributes.TextAttribute;
|
||||
|
||||
import com.ibm.richtext.textlayout.FontUtils;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.awt.Font;
|
||||
|
||||
final class FontResolver {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
static {
|
||||
// Even though it violates the Prime Directive I'll conditionalize
|
||||
// this anyway, since it is just a 1.2 workaround which I greatly
|
||||
// resent.
|
||||
///*JDK12IMPORTS
|
||||
java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment().getAllFonts();
|
||||
//JDK12IMPORTS*/
|
||||
}
|
||||
|
||||
private Hashtable styleMap;
|
||||
private final AttributeMap fDefaultFontMap;
|
||||
|
||||
public FontResolver(AttributeMap defaults) {
|
||||
|
||||
styleMap = new Hashtable();
|
||||
Hashtable tempMap = new Hashtable();
|
||||
tempMap.put(TextAttribute.FAMILY, defaults.get(TextAttribute.FAMILY));
|
||||
tempMap.put(TextAttribute.WEIGHT, defaults.get(TextAttribute.WEIGHT));
|
||||
tempMap.put(TextAttribute.POSTURE, defaults.get(TextAttribute.POSTURE));
|
||||
tempMap.put(TextAttribute.SIZE, defaults.get(TextAttribute.SIZE));
|
||||
fDefaultFontMap = new AttributeMap(tempMap);
|
||||
}
|
||||
|
||||
/**
|
||||
* Fetch result of resolve(style) from cache, if present.
|
||||
*/
|
||||
public AttributeMap applyFont(AttributeMap style) {
|
||||
|
||||
Object cachedMap = styleMap.get(style);
|
||||
|
||||
if (cachedMap == null) {
|
||||
AttributeMap resolvedMap = resolve(style);
|
||||
styleMap.put(style, resolvedMap);
|
||||
return resolvedMap;
|
||||
}
|
||||
else {
|
||||
return (AttributeMap) cachedMap;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeMap containing a Font computed from the
|
||||
* attributes in <tt>style</tt>.
|
||||
*/
|
||||
public AttributeMap resolve(AttributeMap style) {
|
||||
|
||||
if (style.get(TextAttribute.FONT) != null) {
|
||||
return style;
|
||||
}
|
||||
|
||||
Font font = FontUtils.getFont(fDefaultFontMap.addAttributes(style));
|
||||
|
||||
return style.addAttribute(TextAttribute.FONT, font);
|
||||
}
|
||||
}
|
@ -1,197 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
/** LayoutInfo
|
||||
|
||||
A line of text, possibly containing tab-segments.
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
///*JDK12IMPORTS
|
||||
import java.awt.Graphics2D;
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/*JDK11IMPORTS
|
||||
import com.ibm.richtext.textlayout.Graphics2D;
|
||||
JDK11IMPORTS*/
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
abstract class LayoutInfo
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private int fCharStart; // offset in text to start of line (was fStart)
|
||||
// neg. values indicate distance from end of text
|
||||
private int fGraphicStart; // min pixel offset in fill direction
|
||||
// negative values indicate distance from bottom of text view
|
||||
|
||||
/*
|
||||
These methods are for storing Layouts in a gap-storage,
|
||||
relative to either the start of end of text. See AsyncFormatter.
|
||||
|
||||
If you just want absolute (that is, start-relative) char and
|
||||
graphic starts, don't make them end-relative.
|
||||
*/
|
||||
|
||||
public final int getCharStart(int lengthBasis) {
|
||||
|
||||
if (fCharStart >= 0) {
|
||||
return fCharStart;
|
||||
}
|
||||
else {
|
||||
return lengthBasis + fCharStart;
|
||||
}
|
||||
}
|
||||
|
||||
public final int getGraphicStart(int graphicBasis) {
|
||||
|
||||
if (fGraphicStart >= 0) {
|
||||
return fGraphicStart;
|
||||
}
|
||||
else {
|
||||
return graphicBasis + fGraphicStart;
|
||||
}
|
||||
}
|
||||
|
||||
public final void setCharStart(int beginningRelativeStart) {
|
||||
|
||||
if (beginningRelativeStart < 0) {
|
||||
throw new IllegalArgumentException("charStart must be nonnegavitve");
|
||||
}
|
||||
fCharStart = beginningRelativeStart;
|
||||
}
|
||||
|
||||
public final void setGraphicStart(int beginningRelativeStart) {
|
||||
|
||||
if (beginningRelativeStart < 0) {
|
||||
throw new IllegalArgumentException("charStart must be nonnegavitve");
|
||||
}
|
||||
fGraphicStart = beginningRelativeStart;
|
||||
}
|
||||
|
||||
public final void makeRelativeToBeginning(int lengthBasis,
|
||||
int graphicBasis) {
|
||||
|
||||
if (lengthBasis < 0 || graphicBasis < 0) {
|
||||
throw new IllegalArgumentException("Bases must be positive.");
|
||||
}
|
||||
if (fCharStart >= 0 || fGraphicStart >= 0) {
|
||||
throw new Error("Already start-relative.");
|
||||
}
|
||||
|
||||
fCharStart += lengthBasis;
|
||||
fGraphicStart += graphicBasis;
|
||||
}
|
||||
|
||||
public final void makeRelativeToEnd(int lengthBasis,
|
||||
int graphicBasis) {
|
||||
|
||||
if (lengthBasis < 0 || graphicBasis < 0) {
|
||||
throw new IllegalArgumentException("Bases must be positive.");
|
||||
}
|
||||
if (fCharStart < 0 || fGraphicStart < 0) {
|
||||
throw new Error("Already end-relative.");
|
||||
}
|
||||
|
||||
fCharStart -= lengthBasis;
|
||||
fGraphicStart -= graphicBasis;
|
||||
}
|
||||
|
||||
|
||||
public abstract int getCharLength();
|
||||
public abstract int getAscent();
|
||||
public abstract int getDescent();
|
||||
public abstract int getLeading();
|
||||
|
||||
public abstract int getVisibleAdvance();
|
||||
public abstract int getTotalAdvance();
|
||||
public abstract int getLeadingMargin();
|
||||
|
||||
public abstract boolean isLeftToRight();
|
||||
|
||||
public int getHeight() {
|
||||
|
||||
return getAscent()+getDescent()+getLeading();
|
||||
}
|
||||
|
||||
/**
|
||||
* Draws text with highlighting.
|
||||
*/
|
||||
public void renderWithHighlight(int lengthBasis,
|
||||
Graphics2D g,
|
||||
int lineBound,
|
||||
int x,
|
||||
int y,
|
||||
TextOffset selStart,
|
||||
TextOffset selStop,
|
||||
Color highlightColor)
|
||||
{
|
||||
}
|
||||
|
||||
/** Use layout information to render the line at x, y.*/
|
||||
|
||||
public void render(int lengthBasis,
|
||||
Graphics2D g,
|
||||
int lineBound,
|
||||
int x,
|
||||
int y)
|
||||
{
|
||||
}
|
||||
|
||||
public void renderCaret(MConstText text,
|
||||
int lengthBasis,
|
||||
Graphics2D g,
|
||||
int lineBound,
|
||||
int x,
|
||||
int y,
|
||||
int charOffset,
|
||||
Color strongCaretColor,
|
||||
Color weakCaretColor)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Given a point within this line, return the character offset corresponding to that point.
|
||||
*
|
||||
* @param result. This may be null, in which case a new TextOffset will be allocated.
|
||||
* This object is modified in place, and also returned as the function result.
|
||||
* @param text Text to inspect.
|
||||
* @param lineX Position on this line relative to top left corner of this line.
|
||||
* @param lineY Position on this line relative to top left corner of this line.
|
||||
*/
|
||||
public abstract TextOffset pixelToOffset(int lengthBasis,
|
||||
TextOffset result,
|
||||
int lineBound,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
public abstract int strongCaretBaselinePosition(int lengthBasis,
|
||||
int lineBound,
|
||||
int charOffset);
|
||||
|
||||
public abstract Rectangle caretBounds(MConstText text,
|
||||
int lengthBasis,
|
||||
int lineBound,
|
||||
int charOffset,
|
||||
int x,
|
||||
int y);
|
||||
|
||||
public abstract int getNextOffset(int lengthBasis,
|
||||
int charOffset,
|
||||
short dir);
|
||||
}
|
@ -1,351 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Point;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
/**
|
||||
*
|
||||
* This class formats lines of text to a given length.
|
||||
* It provides services needed for static text display,
|
||||
* and also editable text, including: displaying text,
|
||||
* reformatting text after an edit, converting between
|
||||
* screen locations and offsets into the text, calculating
|
||||
* areas of the screen for "highlighting," and computing
|
||||
* offsets into the text resulting from arrow keys.
|
||||
* <p>
|
||||
* Text clients instantiate this class with an
|
||||
* <tt>MConstText</tt> object and a format width. Text
|
||||
* can be formatted such that all lines fit within the
|
||||
* format length. Alternatively, text can be formatted
|
||||
* such that lines end only at the end of paragraphs.
|
||||
* <p>
|
||||
* The format length is specified with the <tt>setLineBound()</tt>
|
||||
* method.
|
||||
* <p>
|
||||
* Methods in the formatter which interact with the graphics
|
||||
* system generally take as a paramter a <tt>Point</tt> object
|
||||
* which represents the "origin" of the text display. The
|
||||
* origin represents the location, in the graphics system used to display the text, of
|
||||
* the top-left corner of the text.
|
||||
* <p>
|
||||
* To display the text, call <tt>draw()</tt>, passing the
|
||||
* a rectangle in which to draw as a parameter. Only lines
|
||||
* of text in the draw rectangle will be drawn.
|
||||
* <p>
|
||||
* When the formatter's text changes, it is important to first call
|
||||
* <tt>stopBackgroundFormatting()</tt> to prevent the Formatter from
|
||||
* accessing the text from a background thread. After modifications are
|
||||
* complete,
|
||||
* call the <tt>updateFormat()</tt> method before invoking any other
|
||||
* methods of the formatter. <tt>updateFormat()</tt> reformats the
|
||||
* new text, formatting no more text than is necessary.
|
||||
* <p>
|
||||
* The formatter provides services for responding to user input from the
|
||||
* mouse and keyboard. The method <tt>pointToTextOffset()</tt> converts
|
||||
* a screen location to an offset in the text. The method <tt>textOffsetToPoint</tt>
|
||||
* converts an offset in the text to an array of two <tt>Point</tt> objects, which can be
|
||||
* used to draw a verticle caret, denoting an insertion point. <tt>highlightArea</tt>
|
||||
* accepts two offsets into the text as paramters, and returns an array of <tt>Polygon</tt>
|
||||
* objects representing areas where visual highlighting should be applied.
|
||||
* <p>
|
||||
* Finally, for
|
||||
* keyboard handling, the <tt>findNewInsertionOffset()</tt> method accepts an "initial"
|
||||
* offset, a "previous" offset, as well as a direction, and returns a new offset. The direction
|
||||
* can be up, down, left, or right. The previous offset is the insertion point location, before
|
||||
* the arrow key is processed. The initial offset is the offset where an up or down arrow
|
||||
* key sequence began. Using the initial offset allows for "intelligent" handling of up and down
|
||||
* arrow keys.
|
||||
* <p>
|
||||
* Examples of using the MFormatter class
|
||||
* are given in the <tt>AsyncFormatter</tt> class
|
||||
* documentation.
|
||||
* <p>
|
||||
* @author John Raley
|
||||
*
|
||||
* @see com.ibm.richtext.styledtext.MText
|
||||
*/
|
||||
|
||||
public abstract class MFormatter {
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public abstract AttributeMap getDefaultValues();
|
||||
|
||||
/**
|
||||
* Display text in drawArea, with highlighting.
|
||||
* Does not reformat text
|
||||
* @param g the Graphics object in which to draw
|
||||
* @param drawArea the rectangle, in g's coordinate system, in which to draw
|
||||
* @param origin the top-left corner of the text, in g's coordinate system
|
||||
* @param selStart the offset where the current selection begins; pass <tt>null</tt> if no selection
|
||||
* @param selStop the offset where the current selection ends
|
||||
* @param highlight the color of the highlighting
|
||||
*/
|
||||
public abstract void draw(Graphics g, Rectangle drawArea, Point origin,
|
||||
TextOffset selStart, TextOffset selStop, Color highlight);
|
||||
|
||||
public abstract void draw(Graphics g, Rectangle drawArea, Point origin);
|
||||
|
||||
/**
|
||||
* Specify whether to wrap line at the edge of the destination area.
|
||||
* <tt>true</tt> means wrap lines; <tt>false</tt> means to break lines
|
||||
* only when an end-of-line character is reached.
|
||||
* @param wrap <tt>true</tt> to break lines at the edge of the destination
|
||||
* area; <tt>false</tt> otherwise.
|
||||
*/
|
||||
|
||||
public abstract void setWrap(boolean wrap);
|
||||
|
||||
/**
|
||||
* Return whether text is wrapped at the edge of the destination area.
|
||||
* @see #setWrap
|
||||
*/
|
||||
public abstract boolean wrap();
|
||||
|
||||
/**
|
||||
* Specify the number of pixels along the "line dimension".
|
||||
* Lines are formatted to fit within the line dimension. The
|
||||
* line dimension in Roman script is horizontal.
|
||||
* @param lineBound the length, in pixels, to which lines will be formatted
|
||||
*/
|
||||
public abstract void setLineBound(int lineBound);
|
||||
|
||||
/**
|
||||
* Return the number of pixels along the line dimension.
|
||||
* @return the number of pixels along the line dimension.
|
||||
*/
|
||||
public abstract int lineBound();
|
||||
|
||||
/**
|
||||
* Format text down to given height.
|
||||
* @param height the height to which text will be formatted
|
||||
*/
|
||||
public abstract void formatToHeight(int height);
|
||||
|
||||
/**
|
||||
* Reformat text after a change.
|
||||
* After the formatter's text changes, call this method to reformat. Does
|
||||
* not redraw.
|
||||
* @param afStart the offset into the text where modification began; ie, the
|
||||
* first character in the text which is "different" in some way. Does not
|
||||
* have to be nonnegative.
|
||||
* @param afLength the number of new or changed characters in the text. Should never
|
||||
* be less than 0.
|
||||
* @param viewRect the Rectangle in which the text will be displayed. This is needed for
|
||||
* returning the "damaged" area - the area of the screen in which the text must be redrawn.
|
||||
* @param origin the top-left corner of the text, in the display's coordinate system
|
||||
* @return a <tt>Rectangle</tt> which specifies the area in which text must be
|
||||
* redrawn to reflect the change to the text.
|
||||
*/
|
||||
public abstract Rectangle updateFormat(int afStart,
|
||||
int afLength,
|
||||
Rectangle viewRect,
|
||||
Point origin);
|
||||
|
||||
|
||||
public abstract int minY();
|
||||
|
||||
/**
|
||||
* Return the maximum vertical coordinate of the document area.
|
||||
*/
|
||||
public abstract int maxY();
|
||||
|
||||
public abstract int minX();
|
||||
|
||||
/**
|
||||
* Return the maximum horizontal coordinate of the document area.
|
||||
*/
|
||||
public abstract int maxX();
|
||||
|
||||
/**
|
||||
* Return the actual pixel length of the text which has been formatted.
|
||||
*/
|
||||
public abstract int formattedHeight();
|
||||
|
||||
public static final short eUp = -10, eDown = 10, eLeft = -1, eRight = 1;
|
||||
|
||||
/**
|
||||
* Given a screen location p, return the offset of the character in the text nearest to p.
|
||||
*
|
||||
* The offset may or may not include a newline at the end of a line, determined by anchor and infiniteMode.
|
||||
* The newline is not included if infiniteMode is true and the anchor is the position before the newline.
|
||||
*
|
||||
* @param result TextOffset to modify and return. If null, one will be allocated, modified, and returned.
|
||||
* @param px the x component of the point.
|
||||
* @param py the y component of the point.
|
||||
* @param origin the top-left corner of the text, in the display's coordinate system
|
||||
* @param anchor the previous offset. May be null. Used to determine whether newlines are included.
|
||||
* @param infiniteMode if true, treat newlines at end of line as having infinite width.
|
||||
*/
|
||||
public abstract TextOffset pointToTextOffset(TextOffset result, int px, int py, Point origin, TextOffset anchor, boolean infiniteMode);
|
||||
|
||||
/**
|
||||
* Given an offset, return the Rectangle bounding the caret at the offset.
|
||||
* @param offset an offset into the text
|
||||
* @param origin the top-left corner of the text, in the display's coordinate system
|
||||
* @return a Rectangle bounding the caret.
|
||||
*/
|
||||
public abstract Rectangle getCaretRect(TextOffset offset, Point origin);
|
||||
|
||||
/**
|
||||
* Draw the caret(s) associated with the given offset into the given Graphics.
|
||||
* @param g the Graphics to draw into
|
||||
* @param offset the offset in the text for which the caret is drawn
|
||||
* @param origin the top-left corner of the text, in the display's coordinate system
|
||||
* @param strongCaretColor the color of the strong caret
|
||||
* @param weakCaretColor the color of the weak caret (if any)
|
||||
*/
|
||||
public abstract void drawCaret(Graphics g,
|
||||
TextOffset offset,
|
||||
Point origin,
|
||||
Color strongCaretColor,
|
||||
Color weakCaretColor);
|
||||
|
||||
/**
|
||||
* @see #getBoundingRect
|
||||
*/
|
||||
public static final boolean LOOSE = false;
|
||||
/**
|
||||
* @see #getBoundingRect
|
||||
*/
|
||||
public static final boolean TIGHT = true;
|
||||
|
||||
/**
|
||||
* Given two offsets in the text, return a rectangle which encloses the lines containing the offsets.
|
||||
* Offsets do not need to be ordered or nonnegative.
|
||||
* @param offset1 an offset into the text
|
||||
* @param offset2 the other offset into the text
|
||||
* @param origin the top-left corner of the text, in the display's coordinate system
|
||||
* @param tight if equal to TIGHT, the bounds is as small as possible. If LOOSE, the width
|
||||
* of the bounds is allowed to be wider than necesary. Loose bounds are easier to compute.
|
||||
* @return a <tt>Rectangle</tt>, relative to <tt>origin</tt>, which encloses the lines containing the offsets
|
||||
*/
|
||||
public abstract Rectangle getBoundingRect(TextOffset offset1,
|
||||
TextOffset offset2,
|
||||
Point origin,
|
||||
boolean tight);
|
||||
|
||||
public abstract void getBoundingRect(Rectangle boundingRect,
|
||||
TextOffset offset1,
|
||||
TextOffset offset2,
|
||||
Point origin,
|
||||
boolean tight);
|
||||
|
||||
/**
|
||||
* Compute the offset resulting from moving from a previous offset in direction dir.
|
||||
* For arrow keys.
|
||||
* @param previousOffset the insertion offset prior to the arrow key press
|
||||
* @param direction the direction of the arrow key (eUp, eDown, eLeft, or eRight)
|
||||
* @return new offset based on direction and previous offset.
|
||||
*/
|
||||
public abstract TextOffset findInsertionOffset(TextOffset result,
|
||||
TextOffset previousOffset,
|
||||
short direction);
|
||||
|
||||
/**
|
||||
* Compute the offset resulting from moving from a previous offset, starting at an original offset, in direction dir.
|
||||
* For arrow keys. Use this for "smart" up/down keys.
|
||||
* @param result TextOffset to modify and return. If null, a new TextOffset is created, modified, and returned.
|
||||
* @param initialOffset The offset at which an up-down arrow key sequence began.
|
||||
* @param previousOffset The insertion offset prior to the arrow key press.
|
||||
* @param direction The direction of the arrow key (eUp, eDown, eLeft, or eRight)
|
||||
* @return new offset based on direction and previous offset(s).
|
||||
*/
|
||||
public abstract TextOffset findNewInsertionOffset(TextOffset result,
|
||||
TextOffset initialOffset,
|
||||
TextOffset previousOffset,
|
||||
short direction);
|
||||
|
||||
/**
|
||||
* Return the index of the line containing the given character index.
|
||||
* This method has complicated semantics, arising from not knowing
|
||||
* which side of the index to check. The index will be given an
|
||||
* implicit AFTER bias, unless the index is the last index in the text,
|
||||
* the text length is non-zero, and there is not a paragraph separator
|
||||
* at the end of the text.
|
||||
*/
|
||||
public abstract int lineContaining(int index);
|
||||
|
||||
/**
|
||||
* Return the index of the line containing the given offset.
|
||||
*/
|
||||
public abstract int lineContaining(TextOffset offset);
|
||||
|
||||
/**
|
||||
* Return the number of lines.
|
||||
*/
|
||||
public abstract int getLineCount();
|
||||
|
||||
/**
|
||||
* Return the index of the first character on the given line.
|
||||
*/
|
||||
public abstract int lineRangeLow(int lineNumber);
|
||||
|
||||
/**
|
||||
* Return the index of the first character following the given line.
|
||||
*/
|
||||
public abstract int lineRangeLimit(int lineNumber);
|
||||
|
||||
/**
|
||||
* Tells the formatter to stop accessing the text until updateFormat is called.
|
||||
*/
|
||||
public abstract void stopBackgroundFormatting();
|
||||
|
||||
/**
|
||||
* Return the line number at the given graphic height. If height is greater than
|
||||
* the text height, maxLineNumber + 1 is returned.
|
||||
*/
|
||||
public abstract int lineAtHeight(int height);
|
||||
|
||||
/**
|
||||
* Return the graphic height where the given line begins. If the lineNumber is
|
||||
* maxLineNumber the entire text height is returned.
|
||||
*/
|
||||
public abstract int lineGraphicStart(int lineNumber);
|
||||
|
||||
/**
|
||||
* Return true if the given line is left-to-right.
|
||||
* @param lineNumber a valid line
|
||||
* @return true if lineNumber is left-to-right
|
||||
*/
|
||||
public abstract boolean lineIsLeftToRight(int lineNumber);
|
||||
|
||||
/**
|
||||
* Return a new <tt>MFormatter</tt>.
|
||||
* @param text the text to format
|
||||
* @param defaultValues values to use when certain attributes are not specified.
|
||||
* <tt>defaultValues</tt> must contain values for the following attributes:
|
||||
* <tt>FAMILY</tt>, <tt>WEIGHT</tt>, <tt>POSTURE</tt>, <tt>SIZE</tt>, <tt>SUPERSCRIPT</tt>,
|
||||
* <tt>FOREGROUND</tt>, <tt>UNDERLINE</tt>, <tt>STRIKETHROUGH</tt>,
|
||||
* <tt>EXTRA_LINE_SPACING</tt>, <tt>FIRST_LINE_INDENT</tt>,<tt>MIN_LINE_SPACING</tt>,
|
||||
* <tt>LINE_FLUSH</tt>, <tt>LEADING_MARGIN</tt>, <tt>TRAILING_MARGIN</tt>, <tt>TAB_RULER</tt>
|
||||
* @param lineBound length to which lines are formatted
|
||||
* @param wrap <tt>true</tt> if text should be "line wrapped" (formatted to fit destination area)
|
||||
*/
|
||||
public static MFormatter createFormatter(MConstText text,
|
||||
AttributeMap defaultValues,
|
||||
int lineBound,
|
||||
boolean wrap,
|
||||
Graphics g) {
|
||||
|
||||
return new AsyncFormatter(text, defaultValues, lineBound, wrap, g);
|
||||
}
|
||||
}
|
@ -1,402 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import java.text.CharacterIterator;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
///*JDK12IMPORTS
|
||||
import java.text.AttributedCharacterIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/*JDK11IMPORTS
|
||||
import com.ibm.richtext.textlayout.attributes.AttributedCharacterIterator;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributedCharacterIterator.Attribute;
|
||||
import com.ibm.richtext.textlayout.attributes.Map;
|
||||
JDK11IMPORTS*/
|
||||
|
||||
/**
|
||||
* An AttributedCharacterIterator over an MConstText.
|
||||
*/
|
||||
public final class MTextIterator implements AttributedCharacterIterator,
|
||||
Cloneable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
// memory leak, since this cache is never flushed
|
||||
|
||||
private static class Matcher {
|
||||
|
||||
boolean matches(Map lhs, Map rhs, Object query) {
|
||||
|
||||
Object lhsVal = lhs.get(query);
|
||||
Object rhsVal = rhs.get(query);
|
||||
|
||||
if (lhsVal == null) {
|
||||
return rhsVal == null;
|
||||
}
|
||||
else {
|
||||
return lhsVal.equals(rhsVal);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static final Matcher ATTR_MATCHER = new Matcher();
|
||||
|
||||
// Not quite optimal. Could have a matcher that would decompose
|
||||
// a set once for repeated queries. Of course that would require
|
||||
// allocation...
|
||||
///*JDK12IMPORTS
|
||||
private static final Matcher SET_MATCHER = new Matcher() {
|
||||
|
||||
boolean matches(Map lhs, Map rhs, Object query) {
|
||||
|
||||
// Not using Iterator to simplify 1.1 port.
|
||||
Object[] elements = ((Set)query).toArray();
|
||||
for (int i=0; i < elements.length; i++) {
|
||||
if (!super.matches(lhs, rhs, elements[i])) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
};
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
private final class StyleCache {
|
||||
|
||||
private int fRunStart = 0;
|
||||
private int fRunLimit = -1;
|
||||
private int fRangeStart;
|
||||
private int fRangeLimit;
|
||||
private AttributeMap fStyle;
|
||||
|
||||
StyleCache(MConstText text, int start, int limit) {
|
||||
fText = text;
|
||||
fRangeStart = start;
|
||||
fRangeLimit = limit;
|
||||
update(start);
|
||||
}
|
||||
|
||||
private void update(int pos) {
|
||||
if (pos < fRunStart || pos >= fRunLimit) {
|
||||
AttributeMap style = AttributeMap.EMPTY_ATTRIBUTE_MAP;
|
||||
if (pos < fRangeStart) {
|
||||
fRunLimit = fRangeStart;
|
||||
fRunStart = Integer.MIN_VALUE;
|
||||
}
|
||||
else if (pos > fRangeLimit) {
|
||||
fRunStart = fRangeLimit;
|
||||
fRunLimit = Integer.MAX_VALUE;
|
||||
}
|
||||
else {
|
||||
fRunStart = Math.max(fRangeStart, fText.characterStyleStart(pos));
|
||||
fRunStart = Math.max(fRunStart, fText.paragraphStart(pos));
|
||||
|
||||
fRunLimit = Math.min(fRangeLimit, fText.characterStyleLimit(pos));
|
||||
fRunLimit = Math.min(fRunLimit, fText.paragraphLimit(pos));
|
||||
if (fRunStart < fRunLimit) {
|
||||
style = fText.paragraphStyleAt(pos);
|
||||
style = style.addAttributes(fText.characterStyleAt(pos));
|
||||
}
|
||||
}
|
||||
fStyle = fFontResolver.applyFont(style);
|
||||
}
|
||||
}
|
||||
|
||||
int getRunStart(int pos) {
|
||||
update(pos);
|
||||
return fRunStart;
|
||||
}
|
||||
|
||||
int getRunLimit(int pos) {
|
||||
update(pos);
|
||||
return fRunLimit;
|
||||
}
|
||||
|
||||
Map getStyle(int pos) {
|
||||
update(pos);
|
||||
return fStyle;
|
||||
}
|
||||
}
|
||||
|
||||
private MConstText fText;
|
||||
private CharacterIterator fCharIter;
|
||||
private FontResolver fFontResolver;
|
||||
|
||||
private StyleCache fStyleCache;
|
||||
|
||||
/**
|
||||
* Create an MTextIterator over the range [start, limit).
|
||||
*/
|
||||
public MTextIterator(MConstText text,
|
||||
FontResolver resolver,
|
||||
int start,
|
||||
int limit) {
|
||||
|
||||
fText = text;
|
||||
fFontResolver = resolver;
|
||||
fCharIter = text.createCharacterIterator(start, limit);
|
||||
|
||||
fStyleCache = new StyleCache(text, start, limit);
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position to getBeginIndex() and returns the character at that
|
||||
* position.
|
||||
* @return the first character in the text, or DONE if the text is empty
|
||||
* @see #getBeginIndex
|
||||
*/
|
||||
public char first() {
|
||||
return fCharIter.first();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position to getEndIndex()-1 (getEndIndex() if the text is empty)
|
||||
* and returns the character at that position.
|
||||
* @return the last character in the text, or DONE if the text is empty
|
||||
* @see #getEndIndex
|
||||
*/
|
||||
public char last() {
|
||||
return fCharIter.last();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the character at the current position (as returned by getIndex()).
|
||||
* @return the character at the current position or DONE if the current
|
||||
* position is off the end of the text.
|
||||
* @see #getIndex
|
||||
*/
|
||||
public char current() {
|
||||
return fCharIter.current();
|
||||
}
|
||||
|
||||
/**
|
||||
* Increments the iterator's index by one and returns the character
|
||||
* at the new index. If the resulting index is greater or equal
|
||||
* to getEndIndex(), the current index is reset to getEndIndex() and
|
||||
* a value of DONE is returned.
|
||||
* @return the character at the new position or DONE if the new
|
||||
* position is off the end of the text range.
|
||||
*/
|
||||
public char next() {
|
||||
return fCharIter.next();
|
||||
}
|
||||
|
||||
/**
|
||||
* Decrements the iterator's index by one and returns the character
|
||||
* at the new index. If the current index is getBeginIndex(), the index
|
||||
* remains at getBeginIndex() and a value of DONE is returned.
|
||||
* @return the character at the new position or DONE if the current
|
||||
* position is equal to getBeginIndex().
|
||||
*/
|
||||
public char previous() {
|
||||
return fCharIter.previous();
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the position to the specified position in the text and returns that
|
||||
* character.
|
||||
* @param position the position within the text. Valid values range from
|
||||
* getBeginIndex() to getEndIndex(). An IllegalArgumentException is thrown
|
||||
* if an invalid value is supplied.
|
||||
* @return the character at the specified position or DONE if the specified position is equal to getEndIndex()
|
||||
*/
|
||||
public char setIndex(int position) {
|
||||
return fCharIter.setIndex(position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the start index of the text.
|
||||
* @return the index at which the text begins.
|
||||
*/
|
||||
public int getBeginIndex() {
|
||||
return fCharIter.getBeginIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the end index of the text. This index is the index of the first
|
||||
* character following the end of the text.
|
||||
* @return the index after the last character in the text
|
||||
*/
|
||||
public int getEndIndex() {
|
||||
return fCharIter.getEndIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the current index.
|
||||
* @return the current index.
|
||||
*/
|
||||
public int getIndex() {
|
||||
return fCharIter.getIndex();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character of the run
|
||||
* with respect to all attributes containing the current character.
|
||||
*/
|
||||
public int getRunStart() {
|
||||
return fStyleCache.getRunStart(fCharIter.getIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character of the run
|
||||
* with respect to the given attribute containing the current character.
|
||||
*/
|
||||
public int getRunStart(Object attribute) {
|
||||
|
||||
return getRunStart(attribute, ATTR_MATCHER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character of the run
|
||||
* with respect to the given attribute containing the current character.
|
||||
*/
|
||||
///*JDK12IMPORTS
|
||||
public int getRunStart(Attribute attribute) {
|
||||
|
||||
return getRunStart(attribute, ATTR_MATCHER);
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/**
|
||||
* Returns the index of the first character of the run
|
||||
* with respect to the given attributes containing the current character.
|
||||
*/
|
||||
///*JDK12IMPORTS
|
||||
public int getRunStart(Set attributes) {
|
||||
|
||||
return getRunStart(attributes, SET_MATCHER);
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
private int getRunStart(Object query, Matcher matcher) {
|
||||
|
||||
int runStart = getRunStart();
|
||||
int rangeStart = getBeginIndex();
|
||||
Map initialStyle = getAttributes();
|
||||
|
||||
while (runStart > rangeStart) {
|
||||
AttributeMap style = fText.characterStyleAt(runStart-1);
|
||||
if (!matcher.matches(initialStyle, style, query)) {
|
||||
return runStart;
|
||||
}
|
||||
runStart = fText.characterStyleStart(runStart-1);
|
||||
}
|
||||
return rangeStart;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character following the run
|
||||
* with respect to all attributes containing the current character.
|
||||
*/
|
||||
public int getRunLimit() {
|
||||
return fStyleCache.getRunLimit(fCharIter.getIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character following the run
|
||||
* with respect to the given attribute containing the current character.
|
||||
*/
|
||||
public int getRunLimit(Object attribute) {
|
||||
|
||||
return getRunLimit(attribute, ATTR_MATCHER);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the index of the first character following the run
|
||||
* with respect to the given attribute containing the current character.
|
||||
*/
|
||||
///*JDK12IMPORTS
|
||||
public int getRunLimit(Attribute attribute) {
|
||||
|
||||
return getRunLimit(attribute, ATTR_MATCHER);
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/**
|
||||
* Returns the index of the first character following the run
|
||||
* with respect to the given attributes containing the current character.
|
||||
*/
|
||||
///*JDK12IMPORTS
|
||||
public int getRunLimit(Set attributes) {
|
||||
|
||||
return getRunLimit(attributes, SET_MATCHER);
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
private int getRunLimit(Object query, Matcher matcher) {
|
||||
|
||||
int runLimit = getRunLimit();
|
||||
int rangeLimit = getEndIndex();
|
||||
Map initialStyle = getAttributes();
|
||||
|
||||
while (runLimit < rangeLimit) {
|
||||
AttributeMap style = fText.characterStyleAt(runLimit);
|
||||
if (!matcher.matches(initialStyle, style, query)) {
|
||||
return runLimit;
|
||||
}
|
||||
runLimit = fText.characterStyleLimit(runLimit);
|
||||
}
|
||||
return rangeLimit;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns a map with the attributes defined on the current
|
||||
* character.
|
||||
*/
|
||||
public Map getAttributes() {
|
||||
return fStyleCache.getStyle(fCharIter.getIndex());
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the named attribute for the current character.
|
||||
* Returns null if the attribute is not defined.
|
||||
* @param attribute the key of the attribute whose value is requested.
|
||||
*/
|
||||
public Object getAttribute(Object attribute) {
|
||||
return getAttributes().get(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the value of the named attribute for the current character.
|
||||
* Returns null if the attribute is not defined.
|
||||
* @param attribute the key of the attribute whose value is requested.
|
||||
*/
|
||||
public Object getAttribute(Attribute attribute) {
|
||||
return getAttributes().get(attribute);
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the keys of all attributes defined on the
|
||||
* iterator's text range. The set is empty if no
|
||||
* attributes are defined.
|
||||
*/
|
||||
///*JDK12IMPORTS
|
||||
public Set getAllAttributeKeys() {
|
||||
throw new Error("Implement this method!");
|
||||
}
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
public Object clone() {
|
||||
return new MTextIterator(fText,
|
||||
fFontResolver,
|
||||
getBeginIndex(),
|
||||
getEndIndex());
|
||||
}
|
||||
}
|
@ -1,79 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
|
||||
|
||||
///*JDK12IMPORTS
|
||||
import java.awt.font.FontRenderContext;
|
||||
import java.awt.font.LineBreakMeasurer;
|
||||
//JDK12IMPORTS*/
|
||||
|
||||
/*JDK11IMPORTS
|
||||
import com.ibm.richtext.textlayout.FontRenderContext;
|
||||
import com.ibm.richtext.textlayout.LineBreakMeasurer;
|
||||
import com.ibm.richtext.textlayout.Graphics2D;
|
||||
JDK11IMPORTS*/
|
||||
|
||||
/**
|
||||
* ParagraphRenderer is a factory for LayoutInfo objects.
|
||||
*/
|
||||
abstract class ParagraphRenderer {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
// If renderers can ever travel with their styles, then this attribute will denote a
|
||||
// renderer. For now, renderers are not added as styles so this isn't needed.
|
||||
//static final TextAttribute PARAGRAPH_RENDERER = new TextAttribute("Paragraph_Renderer") {};
|
||||
|
||||
/**
|
||||
* Reset the renderer to use information from this style. Since renderers may be shared, you should
|
||||
* make sure the renderer is initialized for the style you wish to render before you use it.
|
||||
*/
|
||||
public void initRenderer(AttributeMap pStyle) {
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a LayoutInfo for the paragraph represented by
|
||||
* measurer.
|
||||
* @param text the text containing the paragraph
|
||||
* @param layoutToReuse clients can pass in a LayoutInfo
|
||||
* which the ParagraphRenderer may choose to reuse
|
||||
* and return. If null, a new LayoutInfo will be
|
||||
* created and returned.
|
||||
* @param measurer the LineBreakMeasurer for this paragraph.
|
||||
* Current position should be the first character on the line.
|
||||
* If null, a 0-length line is generated. If measurer is null
|
||||
* then paragraphStart and paragraphLimit should be equal.
|
||||
* @param frc the FontRenderContext used for measurerment
|
||||
* @param paragraphStart the index in the text where the
|
||||
* current paragraph begins
|
||||
* @param paragraphLimit the index of the first character
|
||||
* after the current paragraph
|
||||
* @param totalFormatWidth the width in which the line should fit
|
||||
* @param lineBound where right-aligned lines are aligned
|
||||
*/
|
||||
public abstract LayoutInfo layout(MConstText text,
|
||||
LayoutInfo layoutToReuse,
|
||||
LineBreakMeasurer measurer,
|
||||
FontRenderContext frc,
|
||||
int paragraphStart,
|
||||
int paragraphLimit,
|
||||
int totalFormatWidth,
|
||||
int lineBound);
|
||||
|
||||
}
|
@ -1,118 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.TextAttribute;
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import com.ibm.richtext.textpanel.TextPanel;
|
||||
|
||||
/**
|
||||
* Test for MTextIterator.
|
||||
*/
|
||||
class TestMTextIterator {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final FontResolver FONT_MAPPER;
|
||||
static {
|
||||
AttributeMap attrs = TextPanel.getDefaultSettings().getDefaultValues();
|
||||
FONT_MAPPER = new FontResolver(attrs);
|
||||
}
|
||||
|
||||
public static void compareIterToText(MTextIterator iter,
|
||||
MConstText text) {
|
||||
|
||||
//System.out.println("Text: " + text);
|
||||
final int beginIndex = iter.getBeginIndex();
|
||||
final int endIndex = iter.getEndIndex();
|
||||
|
||||
char ch = iter.setIndex(beginIndex);
|
||||
|
||||
for (int i=beginIndex; i < endIndex; i++) {
|
||||
//System.out.print(ch+ " ");
|
||||
if (ch != text.at(i)) {
|
||||
throw new Error("Characters are not the same.");
|
||||
}
|
||||
ch = iter.next();
|
||||
}
|
||||
|
||||
if (ch != MTextIterator.DONE) {
|
||||
throw new Error("Iterator is not done.");
|
||||
}
|
||||
|
||||
for (int i=endIndex-1; i >= beginIndex; i--) {
|
||||
ch = iter.previous();
|
||||
//System.out.print(ch+ " ");
|
||||
if (ch != text.at(i)) {
|
||||
throw new Error("Backward iteration failed.");
|
||||
}
|
||||
}
|
||||
|
||||
iter.setIndex(beginIndex);
|
||||
|
||||
int runLimit;
|
||||
for (int runStart = beginIndex; runStart < endIndex; runStart = runLimit) {
|
||||
|
||||
runLimit = Math.min(endIndex, text.characterStyleLimit(runStart));
|
||||
|
||||
if (iter.getRunStart() != runStart) {
|
||||
System.out.println(iter.getRunStart() + "; " + runStart);
|
||||
throw new Error("getRunStart is wrong.");
|
||||
}
|
||||
if (iter.getRunLimit() != runLimit) {
|
||||
System.out.println(iter.getRunLimit() + "; " + runLimit);
|
||||
throw new Error("getRunLimit is wrong.");
|
||||
}
|
||||
|
||||
AttributeMap style = text.characterStyleAt(runStart);
|
||||
|
||||
while (iter.getIndex() < runLimit) {
|
||||
AttributeMap resolved = FONT_MAPPER.applyFont(style);
|
||||
if (!iter.getAttributes().equals(resolved)) {
|
||||
throw new Error("Style is wrong.");
|
||||
}
|
||||
iter.next();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void test() {
|
||||
|
||||
AttributeMap bold = new AttributeMap(TextAttribute.WEIGHT,
|
||||
TextAttribute.WEIGHT_BOLD);
|
||||
MText text = new StyledText("Hello there!", AttributeMap.EMPTY_ATTRIBUTE_MAP);
|
||||
text.replace(2, 2, 'V', bold);
|
||||
|
||||
MTextIterator iter = new MTextIterator(text, FONT_MAPPER, 0, text.length());
|
||||
compareIterToText(iter, text);
|
||||
|
||||
text.replace(6, 8, new StyledText("ALL_BOLD", bold), 0, 8);
|
||||
iter = new MTextIterator(text, FONT_MAPPER, 1, text.length()-3);
|
||||
compareIterToText(iter, text);
|
||||
|
||||
iter = new MTextIterator(text, FONT_MAPPER, 0, text.length());
|
||||
compareIterToText(iter, text);
|
||||
}
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
||||
new TestMTextIterator().test();
|
||||
System.out.println("PASSED");
|
||||
}
|
||||
}
|
@ -1,196 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Revision: 03 1.16 richtext/TextOffset.java, richtext, richtext
|
||||
|
||||
/*
|
||||
9/5/96 {jbr} added set and equals methods
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.textformat;
|
||||
|
||||
/**
|
||||
* A TextOffset indicates both an integer offset into text and a placement
|
||||
* on one of the characters adjacent to the offset. An offset is a
|
||||
* position between two characters; offset n
|
||||
* is between character n-1 and character n. The placement specifies whether
|
||||
* it is associated with the character
|
||||
* after the offset
|
||||
* (character n) or the character before the offset (character n-1).
|
||||
* <p>
|
||||
* Knowing which character the TextOffset is associated with is necessary
|
||||
* when displaying carets. In bidirectional text, a single offset may
|
||||
* have two distinct carets. Also, in multiline text, an offset at a line
|
||||
* break has a possible caret on each line.
|
||||
* <p>
|
||||
* Most clients will not be interested in the placement, and will just use
|
||||
* the offset.
|
||||
*/
|
||||
public final class TextOffset
|
||||
{
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Indicates that the TextOffset is associated with character
|
||||
* <code>fOffset - 1</code> - ie the character before its offset.
|
||||
*/
|
||||
public final static boolean BEFORE_OFFSET = true;
|
||||
|
||||
/**
|
||||
* Indicates that the TextOffset is associated with character
|
||||
* <code>fOffset</code> - ie the character after its offset.
|
||||
*/
|
||||
public final static boolean AFTER_OFFSET = false;
|
||||
|
||||
/**
|
||||
* The offset into the text.
|
||||
*/
|
||||
public int fOffset = 0;
|
||||
|
||||
/**
|
||||
* The placement - before or after.
|
||||
*/
|
||||
public boolean fPlacement = AFTER_OFFSET;
|
||||
|
||||
/**
|
||||
* Constructs a new TextOffset
|
||||
* @param offset the offset into the text to represent. Placement is implicitly AFTER_OFFSET.
|
||||
*/
|
||||
public TextOffset(int offset)
|
||||
{
|
||||
if (offset < 0)
|
||||
throw new IllegalArgumentException("Offset is negative in TextOffset constructor.");
|
||||
|
||||
fOffset = offset;
|
||||
|
||||
fPlacement = AFTER_OFFSET;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new TextOffset at 0, with placement AFTER_OFFSET.
|
||||
*/
|
||||
public TextOffset() {
|
||||
this(0);
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new TextOffset with the given offset and placement.
|
||||
* @param offset the offset into the text
|
||||
* @param placement indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET
|
||||
*/
|
||||
public TextOffset(int offset, boolean placement)
|
||||
{
|
||||
if (offset < 0)
|
||||
throw new IllegalArgumentException("TextOffset constructor offset < 0: " + offset);
|
||||
|
||||
fOffset = offset;
|
||||
fPlacement = placement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructs a new TextOffset from an existing one.
|
||||
* @param rhs the TextOffset to copy
|
||||
*/
|
||||
public TextOffset(TextOffset rhs) {
|
||||
|
||||
this(rhs.fOffset, rhs.fPlacement);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the value of the TextOffset
|
||||
* @param offset the offset into the text
|
||||
* @param placement indicates the position of the caret; one of BEFORE_OFFSET or AFTER_OFFSET
|
||||
*/
|
||||
public void setOffset(int offset, boolean placement)
|
||||
{
|
||||
if (offset < 0)
|
||||
throw new IllegalArgumentException("TextOffset setOffset offset < 0: " + offset);
|
||||
|
||||
fOffset = offset;
|
||||
fPlacement = placement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare this to another Object.
|
||||
*/
|
||||
public boolean equals(Object other) {
|
||||
|
||||
try {
|
||||
return equals((TextOffset)other);
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if offset and placement are the same.
|
||||
*
|
||||
* @param other offset to compare against
|
||||
* @return true if both offsets are equal
|
||||
*/
|
||||
public boolean equals(TextOffset other) {
|
||||
|
||||
return fOffset == other.fOffset && fPlacement == other.fPlacement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the hashCode for this object.
|
||||
*/
|
||||
public int hashCode() {
|
||||
|
||||
return fPlacement==AFTER_OFFSET? fOffset : -fOffset;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this offset is 'greaterThan' other. If the fOffset fields are equal, the
|
||||
* placement field is considered, and AFTER_OFFSET is considered 'greaterThan' BEFORE_OFFSET.
|
||||
*
|
||||
* @param other the other offset
|
||||
* @return true if this offset appears after other
|
||||
*/
|
||||
public boolean greaterThan(TextOffset other)
|
||||
{
|
||||
return fOffset > other.fOffset ||
|
||||
(fOffset == other.fOffset && fPlacement == AFTER_OFFSET && other.fPlacement == BEFORE_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this offset is 'lessThan' other. If the fOffset fields are equal, the
|
||||
* placement field is considered, and BEFORE_OFFSET is considered 'lessThan' AFTER_OFFSET.
|
||||
*
|
||||
* @param other the other offset
|
||||
* @return true if this offset appears before other
|
||||
*/
|
||||
public boolean lessThan(TextOffset other) {
|
||||
|
||||
return fOffset < other.fOffset ||
|
||||
(fOffset == other.fOffset && fPlacement == BEFORE_OFFSET && other.fPlacement == AFTER_OFFSET);
|
||||
}
|
||||
|
||||
/**
|
||||
* Copy the value of another TextOffset into this
|
||||
* @param other the TextOffset to copy
|
||||
*/
|
||||
public void assign(TextOffset other) {
|
||||
fOffset = other.fOffset;
|
||||
fPlacement = other.fPlacement;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a string representation of this object.
|
||||
*/
|
||||
public String toString() {
|
||||
|
||||
return "[" + (fPlacement ? "before " : "after ") + fOffset + "]";
|
||||
}
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head><!-- Copyright (C) 2002, International Business Machines Corporation and
|
||||
others. All Rights Reserved.
|
||||
-->
|
||||
|
||||
<title>C:ICU4J .lang Package Overview</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>Classes that format text in a background thread and render the formatted text to a graphics.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,27 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout;
|
||||
|
||||
import java.awt.Font;
|
||||
|
||||
public final class FontUtils {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public static Font getFont(java.util.Map attributes) {
|
||||
|
||||
return Font.getFont(attributes);
|
||||
}
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Graphics2D;
|
||||
import java.awt.Paint;
|
||||
|
||||
/**
|
||||
* This class allows JDK 1.1 code to use a "fake" Graphics2D
|
||||
* for source-code compatibility with Java2 code. On Java2 it's
|
||||
* a trivial class. The JDK 1.1 version of this class does interesting
|
||||
* work.
|
||||
*/
|
||||
public final class Graphics2DConversion {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
public static Graphics2D getGraphics2D(Graphics g) {
|
||||
return (Graphics2D) g;
|
||||
}
|
||||
|
||||
public static Graphics getGraphics(Graphics2D g) {
|
||||
return g;
|
||||
}
|
||||
|
||||
/**
|
||||
* Will return an instance of Paint.
|
||||
*/
|
||||
public static Object getColorState(Graphics2D g) {
|
||||
|
||||
return g.getPaint();
|
||||
}
|
||||
|
||||
/**
|
||||
* State must be an instance of Paint.
|
||||
*/
|
||||
public static void restoreColorState(Graphics2D g, Object state) {
|
||||
|
||||
g.setPaint((Paint) state);
|
||||
}
|
||||
}
|
@ -1,163 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textlayout.attributes;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
/**
|
||||
* This class provides a cannonical mapping between fields in TextAttribute
|
||||
* and instances of itself. It is used by AttributeMap to serialize
|
||||
* and deserialize TextAttribute to preserve uniqueness of TextAttribute
|
||||
* instances (ie so that TextAttribute instances remain singletons),
|
||||
* and to provide compatability between 1.1 and 1.2 versions of
|
||||
* TextAttribute.
|
||||
* <p>
|
||||
* Example use - instead of doing this:
|
||||
* <blockquote><pre>
|
||||
* out.writeObject(anAttribute);
|
||||
* </pre></blockquote>
|
||||
* do this:
|
||||
* <blockquote><pre>
|
||||
* out.writeObject(AttributeKey.mapAttributeToKey(anAttribute));
|
||||
* </pre></blockquote>
|
||||
* Similarly, instead of this:
|
||||
* <blockquote><pre>
|
||||
* anAttribute = in.readObject();
|
||||
* </pre></blockquote>
|
||||
* do this:
|
||||
* <blockquote><pre>
|
||||
* anAttribute = AttributeKey.mapKeyToAttribute(in.readObject());
|
||||
* </pre></blockquote>
|
||||
* <p>
|
||||
* If anAttribute is not a known TextAttribute, then <code>mapAttributeToKey</code>
|
||||
* will just return its argument. Similarly, <code>mapKeyToAttribute</code> will
|
||||
* return its argument if the argument is not a known AttributeKey.
|
||||
*/
|
||||
|
||||
/*public*/ final class AttributeKey implements Serializable {
|
||||
|
||||
/*
|
||||
In this implementation, two parallel Vectors are
|
||||
maintained. TextAttribute(i) maps to AttributeKey(i).
|
||||
For compatability with existing data, this mapping must
|
||||
be maintained in the future! So, when new attributes
|
||||
are added, add them to the end of the list.
|
||||
*/
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final long serialVersionUID = 3772371253277107294L;
|
||||
|
||||
private static Object[] fgTextAttributes;
|
||||
private static Object[] fgAttributeKeys;
|
||||
|
||||
static {
|
||||
fgTextAttributes = new Object[] {
|
||||
TextAttribute.FONT,
|
||||
TextAttribute.FAMILY,
|
||||
TextAttribute.WEIGHT,
|
||||
TextAttribute.POSTURE,
|
||||
TextAttribute.SIZE,
|
||||
TextAttribute.SUPERSCRIPT,
|
||||
TextAttribute.FOREGROUND,
|
||||
TextAttribute.BACKGROUND,
|
||||
TextAttribute.UNDERLINE,
|
||||
TextAttribute.STRIKETHROUGH,
|
||||
TextAttribute.CHAR_REPLACEMENT,
|
||||
TextAttribute.EXTRA_LINE_SPACING,
|
||||
TextAttribute.FIRST_LINE_INDENT,
|
||||
TextAttribute.MIN_LINE_SPACING,
|
||||
TextAttribute.LINE_FLUSH,
|
||||
TextAttribute.LEADING_MARGIN,
|
||||
TextAttribute.TRAILING_MARGIN,
|
||||
TextAttribute.TAB_RULER,
|
||||
TextAttribute.RUN_DIRECTION,
|
||||
TextAttribute.BIDI_EMBEDDING,
|
||||
TextAttribute.JUSTIFICATION,
|
||||
};
|
||||
|
||||
final int attrCount = fgTextAttributes.length;
|
||||
fgAttributeKeys = new Object[attrCount];
|
||||
|
||||
for (int i=0; i < attrCount; i += 1) {
|
||||
fgAttributeKeys[i] = new AttributeKey(i);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the TextAttribute corresponding to the given key.
|
||||
* If key is an instance of AttributeKey it will be mapped to
|
||||
* a TextAttribute. Otherwise, the key is returned.
|
||||
* @param key the key to map to a TextAttribute field
|
||||
* @return the TextAttribute for <code>key</code> if <code>key</code>
|
||||
* is an AttributeKey; otherwise <code>key</code> is returned
|
||||
*/
|
||||
/*public*/ static Object mapKeyToAttribute(Object key) {
|
||||
|
||||
try {
|
||||
AttributeKey aKey = (AttributeKey) key;
|
||||
if (aKey.fId < fgTextAttributes.length) {
|
||||
return fgTextAttributes[aKey.fId];
|
||||
}
|
||||
else {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return key;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* If attribute is a known TextAttribute, return an AttributeKey
|
||||
* for it. Otherwise the object is returned.
|
||||
* @param attribute the attribute to map to an AttributeKey
|
||||
* @return an AttributeKey for <code>attribute</code>
|
||||
* if <code>attribute</code> is a known attribute; otherwise
|
||||
* <code>attribute</code> is returned
|
||||
*/
|
||||
/*public*/ static Object mapAttributeToKey(Object attribute) {
|
||||
|
||||
final int attrCount = fgTextAttributes.length;
|
||||
|
||||
for (int index = 0; index < attrCount; index += 1) {
|
||||
if (fgTextAttributes[index].equals(attribute)) {
|
||||
return fgAttributeKeys[index];
|
||||
}
|
||||
}
|
||||
|
||||
return attribute;
|
||||
}
|
||||
|
||||
|
||||
private int fId;
|
||||
|
||||
private AttributeKey(int id) {
|
||||
|
||||
fId = id;
|
||||
}
|
||||
|
||||
public boolean equals(Object rhs) {
|
||||
|
||||
try {
|
||||
return ((AttributeKey)rhs).fId == fId;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
return fId;
|
||||
}
|
||||
}
|
@ -1,527 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout.attributes;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Hashtable;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
|
||||
import java.io.Externalizable;
|
||||
import java.io.ObjectInput;
|
||||
import java.io.ObjectOutput;
|
||||
import java.io.IOException;
|
||||
|
||||
|
||||
/**
|
||||
* AttributeMap is an immutable Map. Additionally, there are
|
||||
* several methods for common operations (union,
|
||||
* remove, intersect); these methods return new AttributeMap
|
||||
* instances.
|
||||
* <p>
|
||||
* Although any non-null Object can be a key or value in an
|
||||
* AttributeMap, typically the keys are fields of TextAttribute.
|
||||
* @see TextAttribute
|
||||
*/
|
||||
public final class AttributeMap implements java.util.Map,
|
||||
com.ibm.richtext.textlayout.attributes.Map,
|
||||
Externalizable {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private static final int CURRENT_VERSION = 1;
|
||||
|
||||
private static final long serialVersionUID = 9510803;
|
||||
|
||||
private static final String errString = "StyleSets are immutable.";
|
||||
|
||||
// This is passed to the Hashtable constructor as the
|
||||
// load factor argument. It is chosen to avoid resizing
|
||||
// the Hashtable whenever possible. I think that 1
|
||||
// does this.
|
||||
private static final int LOAD_FACTOR = 1;
|
||||
|
||||
private Hashtable styleTable;
|
||||
private transient AttributeSet cachedKeySet = null;
|
||||
private transient Collection cachedValueCollection = null;
|
||||
private transient Set cachedEntrySet = null;
|
||||
|
||||
/**
|
||||
* An empty AttributeMap.
|
||||
*/
|
||||
public static final AttributeMap EMPTY_ATTRIBUTE_MAP = new AttributeMap();
|
||||
|
||||
// ==============
|
||||
// Constructors
|
||||
// ==============
|
||||
|
||||
/**
|
||||
* Create a new, empty AttributeMap. EMPTY_STYLE_SET can be used
|
||||
* in place of an AttributeMap produced by this constructor.
|
||||
*/
|
||||
public AttributeMap() {
|
||||
|
||||
styleTable = new Hashtable(1, LOAD_FACTOR);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AttributeMap with the same key-value
|
||||
* entries as the given Map.
|
||||
* @param map a Map whose key-value entries will
|
||||
* become the entries for this AttributeMap. <code>map</code>
|
||||
* is not modified, and must not contain null keys or values.
|
||||
*/
|
||||
public AttributeMap(java.util.Map map) {
|
||||
|
||||
styleTable = new Hashtable(map.size(), LOAD_FACTOR);
|
||||
styleTable.putAll(map);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AttributeMap with the same key-value
|
||||
* entries as the given Hashtable.
|
||||
* @param hashtable a Hashtable whose key-value entries will
|
||||
* become the entries for this AttributeMap. <code>table</code>
|
||||
* is not modified.
|
||||
*/
|
||||
public AttributeMap(Hashtable hashtable) {
|
||||
|
||||
this((java.util.Map) hashtable);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create an AttributeMap with a single entry of
|
||||
* <code>{attribute, value}</code>.
|
||||
* @param key the key in this AttributeMap's single entry
|
||||
* @param value the value in this AttributeMap's single entry
|
||||
*/
|
||||
public AttributeMap(Object key, Object value) {
|
||||
|
||||
styleTable = new Hashtable(1, LOAD_FACTOR);
|
||||
|
||||
// hashtable checks value for null
|
||||
styleTable.put(key, value);
|
||||
}
|
||||
|
||||
// For internal use only.
|
||||
private AttributeMap(Hashtable table, boolean clone) {
|
||||
|
||||
if (clone) {
|
||||
styleTable = (Hashtable) table.clone();
|
||||
}
|
||||
else {
|
||||
this.styleTable = table;
|
||||
}
|
||||
}
|
||||
|
||||
public void writeExternal(ObjectOutput out) throws IOException {
|
||||
|
||||
out.writeInt(CURRENT_VERSION);
|
||||
out.writeInt(styleTable.size());
|
||||
Enumeration e = styleTable.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
Object key = e.nextElement();
|
||||
out.writeObject(AttributeKey.mapAttributeToKey(key));
|
||||
out.writeObject(styleTable.get(key));
|
||||
}
|
||||
}
|
||||
|
||||
public void readExternal(ObjectInput in) throws IOException,
|
||||
ClassNotFoundException {
|
||||
|
||||
if (in.readInt() != CURRENT_VERSION) {
|
||||
throw new IOException("Invalid version of StyleBuffer");
|
||||
}
|
||||
|
||||
int count = in.readInt();
|
||||
for (int i=0; i < count; i += 1) {
|
||||
Object key = AttributeKey.mapKeyToAttribute(in.readObject());
|
||||
Object value = in.readObject();
|
||||
styleTable.put(key, value);
|
||||
}
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Map interface
|
||||
// ==============
|
||||
|
||||
// queries
|
||||
/**
|
||||
* Return the number of entries in the AttributeMap.
|
||||
* @return the number of entries in the AttributeMap
|
||||
*/
|
||||
public int size() {
|
||||
|
||||
return styleTable.size();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the number of entries in the AttributeMap
|
||||
* is 0.
|
||||
* @return true if the number of entries in the AttributeMap
|
||||
* is 0
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
|
||||
return styleTable.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given key is in this AttributeMap.
|
||||
* @param key the key to test
|
||||
* @return true if <code>key</code> is in this AttributeMap
|
||||
*/
|
||||
public boolean containsKey(Object key) {
|
||||
|
||||
return styleTable.containsKey(key);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the given value is in this AttributeMap.
|
||||
* @param value the value to test
|
||||
* @return true if <code>value</code> is in this AttributeMap
|
||||
*/
|
||||
public boolean containsValue(Object value) {
|
||||
|
||||
return styleTable.containsValue(value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the value associated with the given key. If the
|
||||
* key is not in this AttributeMap null is returned.
|
||||
* @param key the key to look up
|
||||
* @return the value associated with <code>key</code>, or
|
||||
* null if <code>key</code> is not in this AttributeMap
|
||||
*/
|
||||
public Object get(Object key) {
|
||||
|
||||
return styleTable.get(key);
|
||||
}
|
||||
|
||||
// modifiers - all throw exceptions
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #addAttribute
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public Object put(Object key, Object value) {
|
||||
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #removeAttributes
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public Object remove(Object key) {
|
||||
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #addAttributes
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public void putAll(java.util.Map t) {
|
||||
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #EMPTY_ATTRIBUTE_MAP
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public void clear() {
|
||||
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
// views
|
||||
|
||||
/**
|
||||
* Return an AttributeSet containing every key in this AttributeMap.
|
||||
* @return an AttributeSet containing every key in this AttributeMap
|
||||
*/
|
||||
public Set keySet() {
|
||||
|
||||
return getKeySet();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet containing every key in this AttributeMap.
|
||||
* @return an AttributeSet containing every key in this AttributeMap
|
||||
*/
|
||||
public AttributeSet getKeySet() {
|
||||
|
||||
AttributeSet result = cachedKeySet;
|
||||
|
||||
if (result == null) {
|
||||
result = AttributeSet.createKeySet(styleTable);
|
||||
cachedKeySet = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Collection containing every value in this AttributeMap.
|
||||
* @return a Collection containing every value in this AttributeMap
|
||||
*/
|
||||
public Collection values() {
|
||||
|
||||
Collection result = cachedValueCollection;
|
||||
|
||||
if (result == null) {
|
||||
result = Collections.unmodifiableCollection(styleTable.values());
|
||||
cachedValueCollection = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a Set containing all entries in this AttributeMap.
|
||||
*/
|
||||
public Set entrySet() {
|
||||
|
||||
Set result = cachedEntrySet;
|
||||
|
||||
if (result == null) {
|
||||
result = Collections.unmodifiableSet(styleTable.entrySet());
|
||||
cachedEntrySet = result;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
public boolean equals(Object rhs) {
|
||||
|
||||
if (rhs == this) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (rhs == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
AttributeMap rhsStyleSet = null;
|
||||
|
||||
try {
|
||||
rhsStyleSet = (AttributeMap) rhs;
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return styleTable.equals(rhsStyleSet.styleTable);
|
||||
}
|
||||
|
||||
public int hashCode() {
|
||||
|
||||
return styleTable.hashCode();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
|
||||
return styleTable.toString();
|
||||
}
|
||||
|
||||
// ==============
|
||||
// Operations
|
||||
// ==============
|
||||
|
||||
/**
|
||||
* Return a AttributeMap which contains entries in this AttributeMap,
|
||||
* along with an entry for <attribute, value>. If attribute
|
||||
* is already present in this AttributeMap its value becomes value.
|
||||
*/
|
||||
public AttributeMap addAttribute(Object key, Object value) {
|
||||
|
||||
// try to optimize for case where <key, value> is already there?
|
||||
Hashtable newTable = new Hashtable(styleTable.size() + 1, LOAD_FACTOR);
|
||||
newTable.putAll(styleTable);
|
||||
newTable.put(key, value);
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap which contains entries in this AttributeMap
|
||||
* and in rhs. If an attribute appears in both StyleSets the
|
||||
* value from rhs is used.
|
||||
*/
|
||||
public AttributeMap addAttributes(AttributeMap rhs) {
|
||||
|
||||
int thisSize = size();
|
||||
|
||||
if (thisSize == 0) {
|
||||
return rhs;
|
||||
}
|
||||
|
||||
int otherSize = rhs.size();
|
||||
|
||||
if (otherSize == 0) {
|
||||
return this;
|
||||
}
|
||||
|
||||
Hashtable newTable = new Hashtable(thisSize + otherSize, LOAD_FACTOR);
|
||||
|
||||
newTable.putAll(styleTable);
|
||||
newTable.putAll(rhs);
|
||||
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap which contains entries in this AttributeMap
|
||||
* and in rhs. If an attribute appears in both StyleSets the
|
||||
* value from rhs is used.
|
||||
* The Map's keys and values must be non-null.
|
||||
*/
|
||||
public AttributeMap addAttributes(java.util.Map rhs) {
|
||||
|
||||
if (rhs instanceof AttributeMap) {
|
||||
return addAttributes((AttributeMap)rhs);
|
||||
}
|
||||
|
||||
Hashtable newTable = new Hashtable(size() + rhs.size(), LOAD_FACTOR);
|
||||
|
||||
newTable.putAll(styleTable);
|
||||
newTable.putAll(rhs);
|
||||
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap with the entries in this AttributeMap, but
|
||||
* without attribute as a key.
|
||||
*/
|
||||
public AttributeMap removeAttribute(Object attribute) {
|
||||
|
||||
if (!containsKey(attribute)) {
|
||||
return this;
|
||||
}
|
||||
|
||||
Hashtable newTable = new Hashtable(styleTable.size(), LOAD_FACTOR);
|
||||
newTable.putAll(styleTable);
|
||||
newTable.remove(attribute);
|
||||
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap with the entries of this AttributeMap whose
|
||||
* attributes are <b>not</b> in the Set.
|
||||
*/
|
||||
public AttributeMap removeAttributes(AttributeSet attributes) {
|
||||
|
||||
Set set = attributes;
|
||||
return removeAttributes(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap with the entries of this AttributeMap whose
|
||||
* attributes are <b>not</b> in the Set.
|
||||
*/
|
||||
public AttributeMap removeAttributes(Set attributes) {
|
||||
|
||||
// Create newTable on demand; if null at
|
||||
// end of iteration then return this set.
|
||||
// Should we intersect styleTable.keySet with
|
||||
// attributes instead?
|
||||
|
||||
Hashtable newTable = null;
|
||||
Iterator attrIter = attributes.iterator();
|
||||
while (attrIter.hasNext()) {
|
||||
Object current = attrIter.next();
|
||||
if (current != null && styleTable.containsKey(current)) {
|
||||
if (newTable == null) {
|
||||
newTable = new Hashtable(styleTable.size(), LOAD_FACTOR);
|
||||
newTable.putAll(styleTable);
|
||||
}
|
||||
newTable.remove(current);
|
||||
}
|
||||
}
|
||||
|
||||
if (newTable != null) {
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
else {
|
||||
return this;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap with the keys of this AttributeMap which
|
||||
* are also in the Set. The set must not contain null.
|
||||
*/
|
||||
public AttributeMap intersectWith(AttributeSet attributes) {
|
||||
|
||||
Set set = attributes;
|
||||
return intersectWith(set);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return a AttributeMap with the keys of this AttributeMap which
|
||||
* are also in the Set. The set must not contain null.
|
||||
*/
|
||||
public AttributeMap intersectWith(Set attributes) {
|
||||
|
||||
// For now, forget about optimizing for the case when
|
||||
// the return value is equivalent to this set.
|
||||
|
||||
int attrSize = attributes.size();
|
||||
int styleTableSize = styleTable.size();
|
||||
int size = Math.min(attrSize, styleTableSize);
|
||||
Hashtable newTable = new Hashtable(size, LOAD_FACTOR);
|
||||
|
||||
if (attrSize < styleTableSize) {
|
||||
Iterator attrIter = attributes.iterator();
|
||||
while (attrIter.hasNext()) {
|
||||
Object current = attrIter.next();
|
||||
if (current != null) {
|
||||
Object value = styleTable.get(current);
|
||||
if (value != null) {
|
||||
newTable.put(current, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
Iterator attrIter = keySet().iterator();
|
||||
while (attrIter.hasNext()) {
|
||||
Object current = attrIter.next();
|
||||
if (attributes.contains(current)) {
|
||||
newTable.put(current, styleTable.get(current));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return new AttributeMap(newTable, false);
|
||||
}
|
||||
|
||||
/**
|
||||
* Put all entries in this AttributeMap into the given Map.
|
||||
* @param rhs the Map into which entries are placed
|
||||
*/
|
||||
public void putAllInto(java.util.Map rhs) {
|
||||
|
||||
rhs.putAll(this);
|
||||
}
|
||||
}
|
@ -1,343 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout.attributes;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.util.Enumeration;
|
||||
import java.util.Iterator;
|
||||
import java.util.Set;
|
||||
import java.util.Collection;
|
||||
|
||||
/**
|
||||
* An AttributeSet is an immutable collection of unique Objects.
|
||||
* It has several operations
|
||||
* which return new AttributeSet instances.
|
||||
*/
|
||||
public final class AttributeSet implements Set {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
/**
|
||||
* An AttributeSet with no members.
|
||||
*/
|
||||
public static final AttributeSet EMPTY_SET = new AttributeSet();
|
||||
|
||||
private Hashtable elements;
|
||||
|
||||
private static final String errString = "AttributeSet is immutable.";
|
||||
|
||||
private AttributeSet(Hashtable elements) {
|
||||
|
||||
this.elements = elements;
|
||||
}
|
||||
|
||||
/**
|
||||
* Package only. For AttributeMap use.
|
||||
*/
|
||||
static AttributeSet createKeySet(Hashtable hashtable) {
|
||||
|
||||
Hashtable newElements = new Hashtable();
|
||||
|
||||
Enumeration e = hashtable.keys();
|
||||
while (e.hasMoreElements()) {
|
||||
Object next = e.nextElement();
|
||||
newElements.put(next, next);
|
||||
}
|
||||
|
||||
return new AttributeSet(newElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new, empty AttributeSet. The set is semantically
|
||||
* equivalent to EMPTY_SET.
|
||||
*/
|
||||
public AttributeSet() {
|
||||
|
||||
elements = new Hashtable();
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new AttributeSet with the single element elem.
|
||||
*/
|
||||
public AttributeSet(Object elem) {
|
||||
|
||||
elements = new Hashtable(1, 1);
|
||||
elements.put(elem, elem);
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new AttributeSet containing the items in the array elems.
|
||||
*/
|
||||
public AttributeSet(Object[] elems) {
|
||||
|
||||
elements = new Hashtable(elems.length, 1);
|
||||
for (int i=0; i < elems.length; i++) {
|
||||
Object next = elems[i];
|
||||
elements.put(next, next);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the number of elements in this set is 0.
|
||||
* @return true if the number of elements in this set is 0
|
||||
*/
|
||||
public boolean isEmpty() {
|
||||
|
||||
return elements.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of elements in this set.
|
||||
* @return the number of elements in this set
|
||||
*/
|
||||
public int size() {
|
||||
|
||||
return elements.size();
|
||||
}
|
||||
|
||||
public boolean equals(Object rhs) {
|
||||
|
||||
try {
|
||||
return equals((AttributeSet) rhs);
|
||||
}
|
||||
catch(ClassCastException e) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean equals(AttributeSet rhs) {
|
||||
|
||||
if (rhs == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return elements.equals(rhs.elements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this set contains the given Object
|
||||
* @return true if this set contains <code>o</code>
|
||||
*/
|
||||
public boolean contains(Object o) {
|
||||
|
||||
Object value = elements.get(o);
|
||||
return value != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if this set contains all elements in the given
|
||||
* Collection
|
||||
* @param coll the collection to compare with
|
||||
* @return true if this set contains all elements in the given
|
||||
* Collection
|
||||
*/
|
||||
public boolean containsAll(Collection coll) {
|
||||
|
||||
return elements.keySet().containsAll(coll);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Enumeration of the elements in this set.
|
||||
* @return an Enumeration of the elements in this set
|
||||
*/
|
||||
public Enumeration elements() {
|
||||
|
||||
return elements.keys();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an Iterator with the elements in this set.
|
||||
* @return an Iterator with the elements in this set.
|
||||
* The Iterator cannot be used to modify this AttributeSet.
|
||||
*/
|
||||
public Iterator iterator() {
|
||||
|
||||
return new EnumerationIterator(elements.keys());
|
||||
}
|
||||
|
||||
/**
|
||||
* Fill in the given array with the elements in this set.
|
||||
* @param storage an array to fill with this set's elements.
|
||||
* The array cannot be null.
|
||||
* @return the <tt>storage</tt> array.
|
||||
*/
|
||||
public Object[] toArray(Object[] storage) {
|
||||
|
||||
Enumeration keys = elements.keys();
|
||||
int n=0;
|
||||
while (keys.hasMoreElements()) {
|
||||
storage[n++] = keys.nextElement();
|
||||
}
|
||||
return storage;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array with the elements in this set.
|
||||
* @return an array with the elements in this set
|
||||
*/
|
||||
public Object[] toArray() {
|
||||
|
||||
return toArray(new Object[size()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #addElement
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public boolean add(Object o){
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public boolean remove(Object o) {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #unionWith
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public boolean addAll(Collection coll) {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #subtract
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public boolean removeAll(Collection coll) {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #intersectWith
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public boolean retainAll(Collection coll) {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Throws UnsupportedOperationException.
|
||||
* @see #EMPTY_SET
|
||||
* @throws UnsupportedOperationException
|
||||
*/
|
||||
public void clear() {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet containing the elements of this set
|
||||
* and the given element
|
||||
* @param element the element to add
|
||||
* @return an AttributeSet like this one, with <code>element</code>
|
||||
* added
|
||||
*/
|
||||
public AttributeSet addElement(Object element) {
|
||||
|
||||
Hashtable newElements = (Hashtable) elements.clone();
|
||||
newElements.put(element, element);
|
||||
return new AttributeSet(newElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet which is the union of
|
||||
* this set with the given set.
|
||||
* @param s the set to union with
|
||||
* @return an AttributeSet of the elements in this set or
|
||||
* in <code>s</code>
|
||||
*/
|
||||
public AttributeSet unionWith(AttributeSet s) {
|
||||
|
||||
Hashtable newElements = (Hashtable) elements.clone();
|
||||
|
||||
Iterator iter = s.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object next = iter.next();
|
||||
newElements.put(next, next);
|
||||
}
|
||||
|
||||
return new AttributeSet(newElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet which is the intersection of
|
||||
* this set with the given set.
|
||||
* @param s the set to intersect with
|
||||
* @return an AttributeSet of the elements in this set which
|
||||
* are in <code>s</code>
|
||||
*/
|
||||
public AttributeSet intersectWith(AttributeSet s) {
|
||||
|
||||
Hashtable newElements = new Hashtable();
|
||||
|
||||
Iterator iter = s.iterator();
|
||||
while (iter.hasNext()) {
|
||||
Object next = iter.next();
|
||||
if (elements.get(next) != null) {
|
||||
newElements.put(next, next);
|
||||
}
|
||||
}
|
||||
|
||||
return new AttributeSet(newElements);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeSet with the elements in this set which
|
||||
* are not in the given set.
|
||||
* @param s the set of elements to exclude
|
||||
* @return an AttributeSet of the elements in this set which
|
||||
* are not in <code>s</code>
|
||||
*/
|
||||
public AttributeSet subtract(AttributeSet s) {
|
||||
|
||||
Hashtable newElements = (Hashtable) elements.clone();
|
||||
|
||||
Iterator iter = s.iterator();
|
||||
while (iter.hasNext()) {
|
||||
newElements.remove(iter.next());
|
||||
}
|
||||
|
||||
return new AttributeSet(newElements);
|
||||
}
|
||||
|
||||
private static final class EnumerationIterator implements Iterator {
|
||||
|
||||
private Enumeration e;
|
||||
|
||||
EnumerationIterator(Enumeration e) {
|
||||
this.e = e;
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return e.hasMoreElements();
|
||||
}
|
||||
|
||||
public Object next() {
|
||||
return e.nextElement();
|
||||
}
|
||||
|
||||
public void remove() {
|
||||
throw new UnsupportedOperationException(errString);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,49 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout.attributes;
|
||||
|
||||
/**
|
||||
* A Map is a collection of key-value pairs (or entries), where each
|
||||
* key in the Map is unique. This interface is a subset of the
|
||||
* JDK 1.2 Map interface. It is used by JDK 1.1-compatible code.
|
||||
*/
|
||||
public interface Map {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
/**
|
||||
* Return the number of entries in this Map.
|
||||
* @return the number of entries in this Map
|
||||
*/
|
||||
public int size();
|
||||
|
||||
/**
|
||||
* Return true if this Map has no entries.
|
||||
* @return true if this Map has no entries
|
||||
*/
|
||||
public boolean isEmpty();
|
||||
|
||||
/**
|
||||
* Return the value of the given key.
|
||||
* @return the value of the given key. If the key does not have
|
||||
* a value in this Map, null is returned.
|
||||
*/
|
||||
public Object get(Object key);
|
||||
|
||||
/**
|
||||
* Return true if this Map contains the given key.
|
||||
* @return true if this Map contains the given key
|
||||
*/
|
||||
public boolean containsKey(Object key);
|
||||
}
|
@ -1,251 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2007. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
// Requires Java2
|
||||
package com.ibm.richtext.textlayout.attributes;
|
||||
|
||||
import java.util.Hashtable;
|
||||
import java.text.AttributedCharacterIterator.Attribute;
|
||||
import java.io.InvalidObjectException;
|
||||
|
||||
/**
|
||||
* This class contains a number of keys (or attributes) for specifying text styles
|
||||
* in a Map. A text style is a collection of key-value pairs, where
|
||||
* the key represents a certain characteristic (such as size) and
|
||||
* the value tells how that characteristic is realized (ie what the
|
||||
* size is).
|
||||
* <p>
|
||||
* All of the attributes in TextAttribute specify a class for their value.
|
||||
* Map does not enforce these class specifications; however, text rendering code
|
||||
* will tend to fail with a ClassCastException if a key's value
|
||||
* has an unexpected class.
|
||||
* <p>
|
||||
* Some attributes are meaningful for entire paragraphs, not individual
|
||||
* characters. These attributes are documented as applying to paragraphs.
|
||||
* All other attributes apply to characters.
|
||||
* <p>
|
||||
* Many of the field names and values in this class
|
||||
* are taken from the JDK 1.2
|
||||
* <code>java.awt.font.TextAttribute class</code>.
|
||||
* @see Map
|
||||
*/
|
||||
public class TextAttribute extends Attribute {
|
||||
|
||||
/**
|
||||
* For serialization
|
||||
*/
|
||||
private static final long serialVersionUID = 1831947517687597324L;
|
||||
|
||||
private static final Hashtable instanceMap = new Hashtable(9);
|
||||
|
||||
protected TextAttribute(String name) {
|
||||
super(name);
|
||||
if (this.getClass() == TextAttribute.class) {
|
||||
instanceMap.put(name, this);
|
||||
}
|
||||
}
|
||||
|
||||
protected Object readResolve() throws InvalidObjectException {
|
||||
if (this.getClass() != TextAttribute.class) {
|
||||
throw new InvalidObjectException("subclass didn't correctly implement readResolve");
|
||||
}
|
||||
|
||||
TextAttribute instance = (TextAttribute) instanceMap.get(getName());
|
||||
if (instance != null) {
|
||||
return instance;
|
||||
} else {
|
||||
throw new InvalidObjectException("unknown attribute name");
|
||||
}
|
||||
}
|
||||
|
||||
public static final Object FONT = java.awt.font.TextAttribute.FONT;
|
||||
|
||||
public static final Object FAMILY = java.awt.font.TextAttribute.FAMILY;
|
||||
|
||||
public static final Object WEIGHT = java.awt.font.TextAttribute.WEIGHT;
|
||||
public static final Float WEIGHT_BOLD = java.awt.font.TextAttribute.WEIGHT_BOLD;
|
||||
|
||||
public static final Object POSTURE = java.awt.font.TextAttribute.POSTURE;
|
||||
public static final Float POSTURE_OBLIQUE = java.awt.font.TextAttribute.POSTURE_OBLIQUE;
|
||||
|
||||
public static final Object SIZE = java.awt.font.TextAttribute.SIZE;
|
||||
|
||||
public static final Object SUPERSCRIPT = java.awt.font.TextAttribute.SUPERSCRIPT;
|
||||
public static final Integer SUPERSCRIPT_SUPER = java.awt.font.TextAttribute.SUPERSCRIPT_SUPER;
|
||||
public static final Integer SUPERSCRIPT_SUB = java.awt.font.TextAttribute.SUPERSCRIPT_SUB;
|
||||
|
||||
/**
|
||||
* Attribute key for the foreground and background color adornment.
|
||||
*/
|
||||
public static final Object FOREGROUND = java.awt.font.TextAttribute.FOREGROUND;
|
||||
public static final Object BACKGROUND = java.awt.font.TextAttribute.BACKGROUND;
|
||||
|
||||
public static final Object UNDERLINE = java.awt.font.TextAttribute.UNDERLINE;
|
||||
public static final Integer UNDERLINE_ON = java.awt.font.TextAttribute.UNDERLINE_ON;
|
||||
|
||||
public static final Object STRIKETHROUGH = java.awt.font.TextAttribute.STRIKETHROUGH;
|
||||
public static final Boolean STRIKETHROUGH_ON = java.awt.font.TextAttribute.STRIKETHROUGH_ON;
|
||||
|
||||
public static final Object OFFSET = new TextAttribute("offset");
|
||||
|
||||
public static final Object CHAR_REPLACEMENT = java.awt.font.TextAttribute.CHAR_REPLACEMENT;
|
||||
// Paragraph Styles
|
||||
|
||||
// values are Floats:
|
||||
public static final Object EXTRA_LINE_SPACING = new TextAttribute("extra_line_spacing");
|
||||
public static final Object EXTRA_FIRST_LINE_SPACING = new TextAttribute("extra_first_line_spacing");
|
||||
|
||||
/**
|
||||
* Amount beyond leading margin to indent the first line of a paragraph.
|
||||
*/
|
||||
public static final Object FIRST_LINE_INDENT = new TextAttribute("first_line_indent");
|
||||
|
||||
public static final Object MIN_LINE_SPACING = new TextAttribute("min_line_spacing");
|
||||
public static final Object MIN_FIRST_LINE_SPACING = new TextAttribute("min_first_line_spacing");
|
||||
|
||||
/**
|
||||
* Flush lines left, right, or center.
|
||||
*/
|
||||
public static final Object LINE_FLUSH = new TextAttribute("line_flush");
|
||||
|
||||
public static final Integer FLUSH_LEADING = new Integer(0);
|
||||
public static final Integer FLUSH_CENTER = new Integer(1);
|
||||
public static final Integer FLUSH_TRAILING = new Integer(2);
|
||||
/**
|
||||
* Value of <code>LINE_FLUSH</code> for full justification.
|
||||
*/
|
||||
public static final Integer FULLY_JUSTIFIED = new Integer(3);
|
||||
|
||||
/**
|
||||
* Leading and trailing margin in paragraph.
|
||||
*/
|
||||
public static final Object LEADING_MARGIN = new TextAttribute("leading_margin");
|
||||
public static final Object TRAILING_MARGIN = new TextAttribute("trailing_margin");
|
||||
|
||||
/**
|
||||
* Tab ruler. Values are MTabRuler instances.
|
||||
*/
|
||||
public static final Object TAB_RULER = new TextAttribute("tab_ruler");
|
||||
|
||||
/**
|
||||
* Attribute key for the run direction of the line.
|
||||
*
|
||||
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
|
||||
* <TD VALIGN="TOP">RUN_DIRECTION</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
|
||||
* <TD VALIGN="TOP">Boolean</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Constants</TH>
|
||||
* <TD VALIGN="TOP">RUN_DIRECTION_LTR = true, RUN_DIRECTION_RTL = false
|
||||
* </TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
|
||||
* <TD VALIGN="TOP">Use the default Unicode base direction from the BIDI
|
||||
* algorithm.</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
|
||||
* <TD VALIGN="TOP"><P>Specifies which base run direction to use when
|
||||
* positioning mixed directional runs within a paragraph. If this value is
|
||||
* RUN_DIRECTION_DEFAULT, <code>TextLayout</code> uses the default Unicode
|
||||
* base direction from the BIDI algorithm.</P>
|
||||
* <P><I>This attribute should have the same value over the whole
|
||||
* paragraph.</I></TD></TR>
|
||||
* </TABLE>
|
||||
*/
|
||||
public static final Object RUN_DIRECTION = java.awt.font.TextAttribute.RUN_DIRECTION;
|
||||
|
||||
/**
|
||||
* Left-to-right run direction.
|
||||
* @see #RUN_DIRECTION
|
||||
*/
|
||||
public static final Boolean RUN_DIRECTION_LTR = java.awt.font.TextAttribute.RUN_DIRECTION_LTR;
|
||||
|
||||
/**
|
||||
* Right-to-left run direction.
|
||||
* @see #RUN_DIRECTION
|
||||
*/
|
||||
public static final Boolean RUN_DIRECTION_RTL = java.awt.font.TextAttribute.RUN_DIRECTION_RTL;
|
||||
|
||||
/**
|
||||
* Attribute key for the embedding level for nested bidirectional runs.
|
||||
*
|
||||
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
|
||||
* <TD VALIGN="TOP">BIDI_EMBEDDING</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
|
||||
* <TD VALIGN="TOP">Integer</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
|
||||
* <TD VALIGN="TOP">Positive values 1 through 15 are <I>embedding</I>
|
||||
* levels, negative values<BR> through -15 are <I>override</I> levels
|
||||
* </TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
|
||||
* <TD VALIGN="TOP">Use standard BIDI to compute levels from formatting
|
||||
* characters in the text.</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
|
||||
* <TD VALIGN="TOP">Specifies the bidi embedding level of the character.
|
||||
* When this attribute is present anywhere in a paragraph, then the
|
||||
* Unicode characters RLO, LRO, RLE, LRE, PDF are disregarded in the BIDI
|
||||
* analysis of that paragraph.
|
||||
* See the Unicode Standard v. 2.0, section 3-11.
|
||||
* </TD></TR>
|
||||
* </TABLE>
|
||||
*/
|
||||
public static final Object BIDI_EMBEDDING = java.awt.font.TextAttribute.BIDI_EMBEDDING;
|
||||
|
||||
/**
|
||||
* Attribute key for the justification of a paragraph.
|
||||
*
|
||||
* <P><TABLE BORDER="0" CELLSPACING="0" CELLPADDING="1">
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Key</TH>
|
||||
* <TD VALIGN="TOP">JUSTIFICATION</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Value</TH>
|
||||
* <TD VALIGN="TOP">Float</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Limits</TH>
|
||||
* <TD VALIGN="TOP">0.0 through1.0</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Default</TH>
|
||||
* <TD VALIGN="TOP">1.0</TD></TR>
|
||||
* <TR>
|
||||
* <TH VALIGN="TOP" ALIGN="RIGHT"><P ALIGN=RIGHT>Description</TH>
|
||||
* <TD VALIGN="TOP"><P>Specifies which fraction of the extra space to use
|
||||
* when justification is requested. For example, if the line is 50 points
|
||||
* wide and the margins are 70 points apart, a value of 0.5 means that the
|
||||
* line is padded to reach a width of 60 points.</P>
|
||||
* <P><I>This attribute should have the same value over the whole
|
||||
* paragraph.</I></TD></TR>
|
||||
* </TABLE>
|
||||
*/
|
||||
public static final Object JUSTIFICATION = java.awt.font.TextAttribute.JUSTIFICATION;
|
||||
|
||||
/**
|
||||
* Justify the line to the full requested width.
|
||||
* @see #JUSTIFICATION
|
||||
*/
|
||||
public static final Float JUSTIFICATION_FULL = java.awt.font.TextAttribute.JUSTIFICATION_FULL;
|
||||
|
||||
/**
|
||||
* Do not allow the line to be justified.
|
||||
* @see #JUSTIFICATION
|
||||
*/
|
||||
public static final Float JUSTIFICATION_NONE = java.awt.font.TextAttribute.JUSTIFICATION_NONE;
|
||||
}
|
@ -1,15 +0,0 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN">
|
||||
<html>
|
||||
<head><!-- Copyright (C) 2002, International Business Machines Corporation and
|
||||
others. All Rights Reserved.
|
||||
-->
|
||||
|
||||
<title>C:ICU4J .lang Package Overview</title>
|
||||
</head>
|
||||
|
||||
<body bgcolor="white">
|
||||
|
||||
<p>Richtext attribute support. Includes tab, first line indent, and margin attributes.</p>
|
||||
|
||||
</body>
|
||||
</html>
|
@ -1,751 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
import java.awt.Adjustable;
|
||||
import java.awt.Component;
|
||||
import java.awt.datatransfer.Clipboard;
|
||||
|
||||
import com.ibm.richtext.textlayout.attributes.AttributeMap;
|
||||
|
||||
import com.ibm.richtext.styledtext.StyleModifier;
|
||||
import com.ibm.richtext.styledtext.MConstText;
|
||||
import com.ibm.richtext.styledtext.MText;
|
||||
import com.ibm.richtext.styledtext.StyledText;
|
||||
import com.ibm.richtext.textformat.TextOffset;
|
||||
|
||||
/**
|
||||
* Implementation class for TextPanel and JTextPanel.
|
||||
*/
|
||||
final class ATextPanelImpl {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
|
||||
private RunStrategy fRunStrategy = null;
|
||||
private TextComponent fTextComponent = null;
|
||||
private TextSelection fSelection = null;
|
||||
private TextEditBehavior fEditBehavior = null;
|
||||
private MText fText = null;
|
||||
|
||||
private PanelEventBroadcaster fBroadcaster;
|
||||
private KeyRemap fRemap = KeyRemap.getIdentityRemap();
|
||||
|
||||
// This is a little ugly. TextPanel supports its modified
|
||||
// flag whether or not it is editable, or even selectable.
|
||||
// So if there's no command log to keep track of the flag
|
||||
// state then its done right here in TextPanel. If the
|
||||
// panel is editable this flag is ignored.
|
||||
private boolean fModified = false;
|
||||
|
||||
static final TextPanelSettings fgDefaultSettings = new TextPanelSettings();
|
||||
|
||||
static TextPanelSettings getDefaultSettings() {
|
||||
|
||||
return (TextPanelSettings) fgDefaultSettings.clone();
|
||||
}
|
||||
|
||||
ATextPanelImpl(RunStrategy runStrategy,
|
||||
TextPanelSettings settings,
|
||||
MConstText initialText,
|
||||
Clipboard clipboard,
|
||||
MTextPanel client,
|
||||
Adjustable horzSb,
|
||||
Adjustable vertSb) {
|
||||
|
||||
fRunStrategy = runStrategy;
|
||||
fBroadcaster = new PanelEventBroadcaster(client);
|
||||
|
||||
Scroller scroller = null;
|
||||
if (settings.getScrollable()) {
|
||||
scroller = new Scroller(horzSb, vertSb);
|
||||
}
|
||||
|
||||
StyledTextClipboard textClipboard =
|
||||
StyledTextClipboard.getClipboardFor(clipboard);
|
||||
|
||||
fText = new StyledText();
|
||||
if (initialText != null) {
|
||||
fText.append(initialText);
|
||||
}
|
||||
|
||||
fTextComponent = new TextComponent(fText,
|
||||
settings.getDefaultValues(),
|
||||
settings.getWraps(),
|
||||
TextComponent.WINDOW_WIDTH,
|
||||
TextComponent.DEFAULT_INSET,
|
||||
textClipboard,
|
||||
settings.getScrollable(),
|
||||
scroller,
|
||||
fBroadcaster);
|
||||
|
||||
if (scroller != null) {
|
||||
scroller.setClient(fTextComponent);
|
||||
}
|
||||
|
||||
// May have to wait until component has host to do this:
|
||||
if (settings.getSelectable()) {
|
||||
fSelection = new TextSelection(fTextComponent,
|
||||
fBroadcaster,
|
||||
fRunStrategy);
|
||||
fSelection.addToOwner(fTextComponent);
|
||||
if (settings.getEditable()) {
|
||||
fEditBehavior = new TextEditBehavior(
|
||||
fTextComponent, fSelection, fBroadcaster, fRemap);
|
||||
fEditBehavior.addToOwner(fTextComponent);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FakeComponent getTextComponent() {
|
||||
|
||||
return fTextComponent;
|
||||
}
|
||||
|
||||
/**
|
||||
* Add the given TextPanelListener to the listeners which will
|
||||
* receive update notifications from this TextPanel.
|
||||
* @param listener the listener to add
|
||||
*/
|
||||
public void addListener(TextPanelListener listener) {
|
||||
|
||||
fBroadcaster.addListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the given TextPanelListener from the listeners which will
|
||||
* receive update notifications from this TextPanel.
|
||||
* @param listener the listener to remove
|
||||
*/
|
||||
public void removeListener(TextPanelListener listener) {
|
||||
|
||||
fBroadcaster.removeListener(listener);
|
||||
}
|
||||
|
||||
/**
|
||||
* You know what this does...
|
||||
*/
|
||||
private static int pin(int value, int min, int max) {
|
||||
|
||||
if (min > max) {
|
||||
throw new IllegalArgumentException("Invalid range");
|
||||
}
|
||||
|
||||
if (value < min) {
|
||||
value = min;
|
||||
}
|
||||
else if (value > max) {
|
||||
value = max;
|
||||
}
|
||||
return value;
|
||||
}
|
||||
|
||||
//============
|
||||
// Text Access
|
||||
//============
|
||||
|
||||
/**
|
||||
* Set the document to <tt>newText</tt>. This operation
|
||||
* modifies the text in the TextPanel. It does not modify or adopt
|
||||
* <tt>newText</tt>. This method sets the selection an insertion point at
|
||||
* the end of the text.
|
||||
* @param newText the text which will replace the current text.
|
||||
*/
|
||||
public void setText(MConstText newText) {
|
||||
|
||||
replaceRange(newText, 0, getTextLength());
|
||||
}
|
||||
|
||||
/**
|
||||
* Append the given text to the end of the document. Equivalent to
|
||||
* <tt>insert(newText, getTextLength())</tt>.
|
||||
* @param newText the text to append to the document
|
||||
*/
|
||||
public void append(MConstText newText) {
|
||||
|
||||
int length = getTextLength();
|
||||
replaceRange(newText, length, length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Insert the given text into the document at the given position.
|
||||
* Equivalent to
|
||||
* <tt>replaceRange(newText, position, position)</tt>.
|
||||
* @param newText the text to insert into the document.
|
||||
* @param position the position in the document where the
|
||||
* text will be inserted
|
||||
*/
|
||||
public void insert(MConstText newText, int position) {
|
||||
|
||||
replaceRange(newText, position, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the given range with <tt>newText</tt>. After this
|
||||
* operation the selection range is an insertion point at the
|
||||
* end of the new text.
|
||||
* @param newText the text with which to replace the range
|
||||
* @param start the beginning of the range to replace
|
||||
* @param end the end of the range to replace
|
||||
*/
|
||||
public void replaceRange(MConstText newText, int start, int end) {
|
||||
|
||||
int length = getTextLength();
|
||||
|
||||
start = pin(start, 0, length);
|
||||
end = pin(end, start, length);
|
||||
|
||||
if (fSelection != null) {
|
||||
|
||||
// If we're selectable, but not editable, we'll temporarily
|
||||
// make ourselves editable to change the text. A little funny
|
||||
// but there's a lot of code for getting caret stuff right,
|
||||
// and this is not a common operation anyway.
|
||||
|
||||
TextEditBehavior behavior;
|
||||
|
||||
if (fEditBehavior == null) {
|
||||
behavior = new TextEditBehavior(fTextComponent, fSelection, fBroadcaster, fRemap);
|
||||
behavior.addToOwner(fTextComponent);
|
||||
}
|
||||
else {
|
||||
behavior = fEditBehavior;
|
||||
}
|
||||
|
||||
TextOffset newSelection = new TextOffset(start + newText.length(),
|
||||
TextOffset.AFTER_OFFSET);
|
||||
|
||||
TextReplacement replacement = new TextReplacement(start, end,
|
||||
newText,
|
||||
newSelection,
|
||||
newSelection);
|
||||
|
||||
fTextComponent.textControlEventOccurred(Behavior.REPLACE,
|
||||
replacement);
|
||||
if (fEditBehavior == null) {
|
||||
behavior.removeFromOwner();
|
||||
}
|
||||
}
|
||||
else {
|
||||
|
||||
MText oldText = fTextComponent.getModifiableText();
|
||||
fTextComponent.stopBackgroundFormatting();
|
||||
oldText.replaceAll(newText);
|
||||
fTextComponent.reformatAndDrawText(0, newText.length(), null, null, null, null);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the length of the text document in the TextPanel.
|
||||
* @return the length of the text document in the TextPanel
|
||||
*/
|
||||
public int getTextLength() {
|
||||
|
||||
return fTextComponent.getText().length();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the text document in the TextPanel.
|
||||
* @return the text document in the TextPanel.
|
||||
*/
|
||||
public MConstText getText() {
|
||||
|
||||
return fTextComponent.getText();
|
||||
}
|
||||
|
||||
//============
|
||||
// Selection Access
|
||||
//============
|
||||
|
||||
/**
|
||||
* Return the offset of the start of the selection.
|
||||
*/
|
||||
public int getSelectionStart() {
|
||||
|
||||
if (fSelection != null) {
|
||||
return fSelection.getStart().fOffset;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the offset of the end of the selection.
|
||||
*/
|
||||
public int getSelectionEnd() {
|
||||
|
||||
if (fSelection != null) {
|
||||
return fSelection.getEnd().fOffset;
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the beginning of the selection range. This is
|
||||
* equivalent to <tt>select(selectionStart, getSelectionEnd())</tt>.
|
||||
* @param selectionStart the start of the new selection range
|
||||
*/
|
||||
public void setSelectionStart(int selectionStart) {
|
||||
|
||||
select(selectionStart, getSelectionEnd());
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the end of the selection range. This is
|
||||
* equivalent to <tt>select(getSelectionStart(), selectionEnd)</tt>.
|
||||
* @param selectionStart the start of the new selection range
|
||||
*/
|
||||
public void setSelectionEnd(int selectionEnd) {
|
||||
|
||||
select(getSelectionStart(), selectionEnd);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selection range to an insertion point at the given
|
||||
* offset. This is equivalent to
|
||||
* <tt>select(position, position)</tt>.
|
||||
* @param position the offset of the new insertion point
|
||||
*/
|
||||
public void setCaretPosition(int position) {
|
||||
|
||||
select(position, position);
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the selection range to the given range. The range start
|
||||
* is pinned between 0 and the text length; the range end is pinned
|
||||
* between the range start and the end of the text. These semantics
|
||||
* are identical to those of <tt>java.awt.TextComponent</tt>.
|
||||
* This method has no effect if the text is not selectable.
|
||||
* @param selectionStart the beginning of the selection range
|
||||
* @param selectionEnd the end of the selection range
|
||||
*/
|
||||
public void select(int selectionStart, int selectionEnd) {
|
||||
|
||||
int length = getTextLength();
|
||||
|
||||
selectionStart = pin(selectionStart, 0, length);
|
||||
selectionEnd = pin(selectionEnd, selectionStart, length);
|
||||
|
||||
TextRange range = new TextRange(selectionStart, selectionEnd);
|
||||
fTextComponent.textControlEventOccurred(Behavior.SELECT, range);
|
||||
}
|
||||
|
||||
/**
|
||||
* Select all of the text in the document. This method has no effect if
|
||||
* the text is not selectable.
|
||||
*/
|
||||
public void selectAll() {
|
||||
|
||||
select(0, getTextLength());
|
||||
}
|
||||
|
||||
|
||||
//============
|
||||
// Format Width
|
||||
//============
|
||||
|
||||
/**
|
||||
* Return the total format width, in pixels. The format width is the
|
||||
* width to which text is wrapped.
|
||||
* @return the format width
|
||||
*/
|
||||
public int getFormatWidth() {
|
||||
|
||||
return fTextComponent.getFormatWidth();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the paragraph at the given offset is left-to-right.
|
||||
* @param offset an offset in the text
|
||||
* @return true if the paragraph at the given offset is left-to-right
|
||||
*/
|
||||
public boolean paragraphIsLeftToRight(int offset) {
|
||||
|
||||
return fTextComponent.paragraphIsLeftToRight(offset);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there is a change which can be undone.
|
||||
* @return true if there is a change which can be undone.
|
||||
*/
|
||||
public boolean canUndo() {
|
||||
|
||||
if (fEditBehavior != null) {
|
||||
return fEditBehavior.canUndo();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if there is a change which can be redone.
|
||||
* @return true if there is a change which can be redone.
|
||||
*/
|
||||
public boolean canRedo() {
|
||||
|
||||
if (fEditBehavior != null) {
|
||||
return fEditBehavior.canRedo();
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return true if the clipboard contains contents which could be
|
||||
* transfered into the text.
|
||||
* @return true if the clipboard has text content.
|
||||
*/
|
||||
public boolean clipboardNotEmpty() {
|
||||
|
||||
return fTextComponent.getClipboard().hasContents();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an AttributeMap of keys with default values. The default
|
||||
* values are used when displaying text for values which are not
|
||||
* specified in the text.
|
||||
* @return an AttributeMap of default key-value pairs
|
||||
*/
|
||||
public AttributeMap getDefaultValues() {
|
||||
|
||||
return fTextComponent.getDefaultValues();
|
||||
}
|
||||
|
||||
private static boolean objectsAreEqual(Object lhs, Object rhs) {
|
||||
|
||||
if (lhs == null) {
|
||||
return rhs == null;
|
||||
}
|
||||
else {
|
||||
return lhs.equals(rhs);
|
||||
}
|
||||
}
|
||||
|
||||
private static Object consistentCharStyle(MConstText text,
|
||||
int start,
|
||||
int limit,
|
||||
Object key,
|
||||
Object defaultValue) {
|
||||
|
||||
if (start >= limit) {
|
||||
throw new IllegalArgumentException("Invalid range.");
|
||||
}
|
||||
|
||||
int runStart = start;
|
||||
Object initialValue = text.characterStyleAt(runStart).get(key);
|
||||
|
||||
if (initialValue == null) {
|
||||
initialValue = defaultValue;
|
||||
}
|
||||
|
||||
for (runStart = text.characterStyleLimit(runStart);
|
||||
runStart < limit;
|
||||
runStart = text.characterStyleLimit(runStart)) {
|
||||
|
||||
Object nextValue = text.characterStyleAt(runStart).get(key);
|
||||
|
||||
if (nextValue == null) {
|
||||
nextValue = defaultValue;
|
||||
}
|
||||
|
||||
if (!objectsAreEqual(initialValue, nextValue)) {
|
||||
return MTextPanel.MULTIPLE_VALUES;
|
||||
}
|
||||
}
|
||||
|
||||
return initialValue;
|
||||
}
|
||||
|
||||
/**
|
||||
* This method inspects the character style runs in the selection
|
||||
* range (or the typing style at the insertion point) and returns:
|
||||
* <ul>
|
||||
* <li>The value of <tt>key</tt>, if the value of <tt>key</tt>
|
||||
* is the same in all of the style runs in the selection, or</li>
|
||||
* <li>null, if two or more style runs have different values for <tt>key</tt>.</li>
|
||||
* </ul>
|
||||
* If a style run does not contain <tt>key</tt>,
|
||||
* its value is considered to be <tt>defaultStyle</tt>.
|
||||
* This method is useful for configuring style menus.
|
||||
* @param key the key used to retrieve values for comparison
|
||||
* @param defaultValue the implicit value of <tt>key</tt> in
|
||||
* style runs where <tt>key</tt> is not defined
|
||||
*/
|
||||
public Object getCharacterStyleOverSelection(Object key) {
|
||||
|
||||
TextRange selRange;
|
||||
if (fSelection != null)
|
||||
selRange = fSelection.getSelectionRange();
|
||||
else
|
||||
selRange = new TextRange(0, 0);
|
||||
|
||||
if (selRange.start == selRange.limit) {
|
||||
|
||||
AttributeMap compStyle;
|
||||
|
||||
if (fEditBehavior != null) {
|
||||
compStyle = fEditBehavior.getInsertionPointStyle();
|
||||
}
|
||||
else {
|
||||
compStyle = TextEditBehavior.typingStyleAt(fText, selRange.start, selRange.limit);
|
||||
}
|
||||
|
||||
Object value = compStyle.get(key);
|
||||
return value==null? getDefaultValues().get(key) : value;
|
||||
}
|
||||
else {
|
||||
return consistentCharStyle(fText,
|
||||
selRange.start,
|
||||
selRange.limit,
|
||||
key,
|
||||
getDefaultValues().get(key));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method inspects the paragraph style runs in the selection
|
||||
* range (or the typing style at the insertion point) and returns:
|
||||
* <ul>
|
||||
* <li>The value of <tt>key</tt>, if the value of <tt>key</tt>
|
||||
* is the same in all of the style runs in the selection, or</li>
|
||||
* <li>null, if two or more style runs have different values for <tt>key</tt>.</li>
|
||||
* </ul>
|
||||
* If a style run does not contain <tt>key</tt>,
|
||||
* its value is considered to be <tt>defaultStyle</tt>.
|
||||
* This method is useful for configuring style menus.
|
||||
* @param key the key used to retrieve values for comparison
|
||||
* @param defaultValue the implicit value of <tt>key</tt> in
|
||||
* style runs where <tt>key</tt> is not defined
|
||||
*/
|
||||
public Object getParagraphStyleOverSelection(Object key) {
|
||||
|
||||
TextRange selRange;
|
||||
if (fSelection != null) {
|
||||
selRange = fSelection.getSelectionRange();
|
||||
}
|
||||
else {
|
||||
selRange = new TextRange(0, 0);
|
||||
}
|
||||
|
||||
if (selRange.start == selRange.limit) {
|
||||
AttributeMap pStyle = fText.paragraphStyleAt(selRange.start);
|
||||
Object value = pStyle.get(key);
|
||||
return value==null? getDefaultValues().get(key) : value;
|
||||
}
|
||||
else {
|
||||
int paragraphStart = selRange.start;
|
||||
Object defaultValue = getDefaultValues().get(key);
|
||||
Object initialValue = fText.paragraphStyleAt(paragraphStart).get(key);
|
||||
if (initialValue == null) {
|
||||
initialValue = defaultValue;
|
||||
}
|
||||
|
||||
for (paragraphStart = fText.paragraphLimit(paragraphStart);
|
||||
paragraphStart < selRange.limit;
|
||||
paragraphStart = fText.paragraphLimit(paragraphStart)) {
|
||||
|
||||
Object nextValue = fText.paragraphStyleAt(paragraphStart).get(key);
|
||||
if (nextValue == null) {
|
||||
nextValue = defaultValue;
|
||||
}
|
||||
|
||||
if (!objectsAreEqual(initialValue, nextValue)) {
|
||||
return MTextPanel.MULTIPLE_VALUES;
|
||||
}
|
||||
}
|
||||
|
||||
return initialValue;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the selected text from the document and place it
|
||||
* on the clipboard. This method has no effect if the text
|
||||
* is not editable, or if no text is selected.
|
||||
*/
|
||||
public void cut() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.CUT, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Place the selected text on the clipboard. This method has
|
||||
* no effect if no text is selected.
|
||||
*/
|
||||
public void copy() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.COPY, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Replace the currently selected text with the text on the clipboard.
|
||||
* This method has no effect if the text is not editable, or if no
|
||||
* text is on the clipboard.
|
||||
*/
|
||||
public void paste() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.PASTE, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove selected text from the document, without altering the clipboard.
|
||||
* This method has no effect if the
|
||||
* text is not editable.
|
||||
*/
|
||||
public void clear() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.CLEAR, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Undo the most recent text change. This method has no effect if
|
||||
* there is no change to undo.
|
||||
*/
|
||||
public void undo() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.UNDO, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Redo the most recent text change. This method has no effect if
|
||||
* there is no change to redo.
|
||||
*/
|
||||
public void redo() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.REDO, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the number of commands the command log can hold.
|
||||
* @return the number of commands the command log can hold
|
||||
*/
|
||||
public int getCommandLogSize() {
|
||||
|
||||
if (fEditBehavior != null) {
|
||||
return fEditBehavior.getCommandLogSize();
|
||||
}
|
||||
else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the number of commands the command log can hold. All
|
||||
* redoable commands are removed when this method is called.
|
||||
* @param size the number of commands kept in the command log
|
||||
*/
|
||||
public void setCommandLogSize(int size) {
|
||||
fTextComponent.textControlEventOccurred(Behavior.SET_COMMAND_LOG_SIZE,
|
||||
new Integer(size));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove all commands from the command log.
|
||||
*/
|
||||
public void clearCommandLog() {
|
||||
fTextComponent.textControlEventOccurred(Behavior.CLEAR_COMMAND_LOG, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the character styles on the selected characters. If no characters
|
||||
* are selected, modify the typing style.
|
||||
* @param modifier the StyleModifier with which to modify the styles
|
||||
*/
|
||||
public void modifyCharacterStyleOnSelection(StyleModifier modifier) {
|
||||
fTextComponent.textControlEventOccurred(Behavior.CHARACTER_STYLE_MOD, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify the paragraph styles in paragraphs containing selected characters, or
|
||||
* the paragraph containing the insertion point.
|
||||
* @param modifier the StyleModifier with which to modify the styles
|
||||
*/
|
||||
public void modifyParagraphStyleOnSelection(StyleModifier modifier) {
|
||||
fTextComponent.textControlEventOccurred(Behavior.PARAGRAPH_STYLE_MOD, modifier);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the KeyRemap used to process key events.
|
||||
* @return the key remap used to process key events
|
||||
* @see #setKeyRemap
|
||||
*/
|
||||
public KeyRemap getKeyRemap() {
|
||||
|
||||
return fRemap;
|
||||
}
|
||||
|
||||
/**
|
||||
* Use the given KeyRemap to map key events to characters.
|
||||
* Only key
|
||||
* events are affected by the remap; other text entering the
|
||||
* control (via the clipboard, for example) is not affected
|
||||
* by the KeyRemap.
|
||||
* <p>
|
||||
* Do not pass <tt>null</tt> to this method to leave key
|
||||
* events unmapped. Instead, use <tt>KeyRemap.getIdentityRemap()</tt>
|
||||
* @param remap the KeyRemap to use for mapping key events to characters
|
||||
* @exception java.lang.NullPointerException if parameter is null
|
||||
* @see KeyRemap
|
||||
*/
|
||||
public void setKeyRemap(KeyRemap remap) {
|
||||
|
||||
if (remap == null) {
|
||||
throw new NullPointerException("remap can't be null");
|
||||
}
|
||||
|
||||
fRemap = remap;
|
||||
if (fEditBehavior != null) {
|
||||
fEditBehavior.setKeyRemap(remap);
|
||||
}
|
||||
|
||||
fBroadcaster.textStateChanged(TextPanelEvent.KEYREMAP_CHANGED);
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the modification flag of the current text change.
|
||||
* @see #setModified
|
||||
*/
|
||||
public boolean isModified() {
|
||||
|
||||
if (fEditBehavior != null) {
|
||||
return fEditBehavior.isModified();
|
||||
}
|
||||
else {
|
||||
return fModified;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Set the modification flag of the current text change.
|
||||
*/
|
||||
public void setModified(boolean modified) {
|
||||
|
||||
boolean handled = fTextComponent.textControlEventOccurred(
|
||||
Behavior.SET_MODIFIED,
|
||||
modified? Boolean.TRUE : Boolean.FALSE);
|
||||
if (!handled) {
|
||||
fModified = modified;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* This method is for perf-testing only!
|
||||
*/
|
||||
void handleKeyEvent(java.awt.event.KeyEvent keyEvent) {
|
||||
|
||||
Component host = fTextComponent.getHost();
|
||||
if (host != null) {
|
||||
host.dispatchEvent(keyEvent);
|
||||
}
|
||||
}
|
||||
}
|
@ -1,178 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
/*
|
||||
*
|
||||
* (C) Copyright IBM Corp. 1998, All Rights Reserved
|
||||
*/
|
||||
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
/*
|
||||
For any incoming character C
|
||||
if you can map C using the following FakeArabicTable, return
|
||||
FakeArabicTable(C)
|
||||
else if C is from A through Z, return FakeArabicTable(lowercase(C))
|
||||
else just return C
|
||||
|
||||
|
||||
FakeArabicTable is defined by the following mapping
|
||||
|
||||
0 0660;ARABIC-INDIC DIGIT ZERO;Nd;0;AN;;0;0;0;N;;;;;
|
||||
1 0661;ARABIC-INDIC DIGIT ONE;Nd;0;AN;;1;1;1;N;;;;;
|
||||
2 0662;ARABIC-INDIC DIGIT TWO;Nd;0;AN;;2;2;2;N;;;;;
|
||||
3 0663;ARABIC-INDIC DIGIT THREE;Nd;0;AN;;3;3;3;N;;;;;
|
||||
4 0664;ARABIC-INDIC DIGIT FOUR;Nd;0;AN;;4;4;4;N;;;;;
|
||||
5 0665;ARABIC-INDIC DIGIT FIVE;Nd;0;AN;;5;5;5;N;;;;;
|
||||
6 0666;ARABIC-INDIC DIGIT SIX;Nd;0;AN;;6;6;6;N;;;;;
|
||||
7 0667;ARABIC-INDIC DIGIT SEVEN;Nd;0;AN;;7;7;7;N;;;;;
|
||||
8 0668;ARABIC-INDIC DIGIT EIGHT;Nd;0;AN;;8;8;8;N;;;;;
|
||||
9 0669;ARABIC-INDIC DIGIT NINE;Nd;0;AN;;9;9;9;N;;;;;
|
||||
|
||||
% 066A;ARABIC PERCENT SIGN;Po;0;ET;;;;;N;;;;;
|
||||
. 066B;ARABIC DECIMAL SEPARATOR;Po;0;AN;;;;;N;;;;;
|
||||
, 060C;ARABIC COMMA;Po;0;R;;;;;N;;;;;
|
||||
- 0640;ARABIC TATWEEL;Lm;0;R;;;;;N;;;;;
|
||||
' 0652;ARABIC SUKUN;Mn;34;R;;;;;N;;;;;
|
||||
" 0651;ARABIC SHADDA;Mn;33;R;;;;;N;ARABIC SHADDAH;;;;
|
||||
; 061B;ARABIC SEMICOLON;Po;0;R;;;;;N;;;;;
|
||||
? 061F;ARABIC QUESTION MARK;Po;0;R;;;;;N;;;;;
|
||||
|
||||
a 0627;ARABIC LETTER ALEF;Lo;0;R;;;;;N;;;;;
|
||||
A 0639;ARABIC LETTER AIN;Lo;0;R;;;;;N;;;;;
|
||||
b 0628;ARABIC LETTER BEH;Lo;0;R;;;;;N;ARABIC LETTER BAA;;;;
|
||||
c 0635;ARABIC LETTER SAD;Lo;0;R;;;;;N;;;;;
|
||||
d 062F;ARABIC LETTER DAL;Lo;0;R;;;;;N;;;;;
|
||||
D 0630;ARABIC LETTER THAL;Lo;0;R;;;;;N;;;;;
|
||||
E 064B;ARABIC FATHATAN;Mn;27;R;;;;;N;;;;;
|
||||
e 064E;ARABIC FATHA;Mn;30;R;;;;;N;ARABIC FATHAH;;;;
|
||||
f 0641;ARABIC LETTER FEH;Lo;0;R;;;;;N;ARABIC LETTER FA;;;;
|
||||
g 063A;ARABIC LETTER GHAIN;Lo;0;R;;;;;N;;;;;
|
||||
h 062D;ARABIC LETTER HAH;Lo;0;R;;;;;N;ARABIC LETTER HAA;;;;
|
||||
H 0647;ARABIC LETTER HEH;Lo;0;R;;;;;N;ARABIC LETTER HA;;;;
|
||||
I 064D;ARABIC KASRATAN;Mn;29;R;;;;;N;;;;;
|
||||
i 0650;ARABIC KASRA;Mn;32;R;;;;;N;ARABIC KASRAH;;;;
|
||||
j 062C;ARABIC LETTER JEEM;Lo;0;R;;;;;N;;;;;
|
||||
K 062E;ARABIC LETTER KHAH;Lo;0;R;;;;;N;ARABIC LETTER KHAA;;;;
|
||||
k 0643;ARABIC LETTER KAF;Lo;0;R;;;;;N;ARABIC LETTER CAF;;;;
|
||||
l 0644;ARABIC LETTER LAM;Lo;0;R;;;;;N;;;;;
|
||||
m 0645;ARABIC LETTER MEEM;Lo;0;R;;;;;N;;;;;
|
||||
n 0646;ARABIC LETTER NOON;Lo;0;R;;;;;N;;;;;
|
||||
o 064F;ARABIC DAMMA;Mn;31;R;;;;;N;ARABIC DAMMAH;;;;
|
||||
p 0628;ARABIC LETTER BEH;Lo;0;R;;;;;N;ARABIC LETTER BAA;;;;
|
||||
q 0642;ARABIC LETTER QAF;Lo;0;R;;;;;N;;;;;
|
||||
r 0631;ARABIC LETTER REH;Lo;0;R;;;;;N;ARABIC LETTER RA;;;;
|
||||
s 0633;ARABIC LETTER SEEN;Lo;0;R;;;;;N;;;;;
|
||||
S 0634;ARABIC LETTER SHEEN;Lo;0;R;;;;;N;;;;;
|
||||
t 062A;ARABIC LETTER TEH;Lo;0;R;;;;;N;ARABIC LETTER TAA;;;;
|
||||
T 062B;ARABIC LETTER THEH;Lo;0;R;;;;;N;ARABIC LETTER THAA;;;;
|
||||
U 064C;ARABIC DAMMATAN;Mn;28;R;;;;;N;;;;;
|
||||
u 064F;ARABIC DAMMA;Mn;31;R;;;;;N;ARABIC DAMMAH;;;;
|
||||
v 0641;ARABIC LETTER FEH;Lo;0;R;;;;;N;ARABIC LETTER FA;;;;
|
||||
w 0648;ARABIC LETTER WAW;Lo;0;R;;;;;N;;;;;
|
||||
x 0633;ARABIC LETTER SEEN;Lo;0;R;;;;;N;;;;;
|
||||
y 064A;ARABIC LETTER YEH;Lo;0;R;;;;;N;ARABIC LETTER YA;;;;
|
||||
z 0632;ARABIC LETTER ZAIN;Lo;0;R;;;;;N;;;;;
|
||||
Z 0638;ARABIC LETTER ZAH;Lo;0;R;;;;;N;ARABIC LETTER DHAH;;;;
|
||||
|
||||
*/
|
||||
|
||||
/**
|
||||
* This class implements KeyRemap to produce transliterated Arabic
|
||||
* characters from Latin-1 characters.
|
||||
*/
|
||||
|
||||
final class ArabicTransliteration extends KeyRemap {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public char remap(char c) {
|
||||
|
||||
switch (c) {
|
||||
case '0': return '\u0660'; // ARABIC-INDIC DIGIT ZERO
|
||||
case '1': return '\u0661'; // ARABIC-INDIC DIGIT ONE
|
||||
case '2': return '\u0662'; // ARABIC-INDIC DIGIT TWO
|
||||
case '3': return '\u0663'; // ARABIC-INDIC DIGIT THREE
|
||||
case '4': return '\u0664'; // ARABIC-INDIC DIGIT FOUR
|
||||
case '5': return '\u0665'; // ARABIC-INDIC DIGIT FIVE
|
||||
case '6': return '\u0666'; // ARABIC-INDIC DIGIT SIX
|
||||
case '7': return '\u0667'; // ARABIC-INDIC DIGIT SEVEN
|
||||
case '8': return '\u0668'; // ARABIC-INDIC DIGIT EIGHT
|
||||
case '9': return '\u0669'; // ARABIC-INDIC DIGIT NINE
|
||||
|
||||
case '%': return '\u066A'; // ARABIC PERCENT SIGN
|
||||
// the Traditional Arabic font does not contain this character
|
||||
// case '.': return '\u066B'; // ARABIC DECIMAL SEPARATOR
|
||||
case ',': return '\u060C'; // ARABIC COMMA
|
||||
case '-': return '\u0640'; // ARABIC TATWEEL
|
||||
case '\'': return '\u0652'; // ARABIC SUKUN
|
||||
case '"': return '\u0651'; // ARABIC SHADDA
|
||||
case ';': return '\u061B'; // ARABIC SEMICOLON
|
||||
case '?': return '\u061F'; // ARABIC QUESTION MARK
|
||||
|
||||
case 'a': return '\u0627'; // ARABIC LETTER ALEF
|
||||
case 'A': return '\u0639'; // ARABIC LETTER AIN
|
||||
case 'b': return '\u0628'; // ARABIC LETTER BEH
|
||||
case 'B': return '\u0628'; // ARABIC LETTER BEH
|
||||
case 'c': return '\u0635'; // ARABIC LETTER SAD
|
||||
case 'C': return '\u0635'; // ARABIC LETTER SAD
|
||||
case 'd': return '\u062F'; // ARABIC LETTER DAL
|
||||
case 'D': return '\u0630'; // ARABIC LETTER THAL
|
||||
case 'e': return '\u064E'; // ARABIC FATHA
|
||||
case 'E': return '\u064B'; // ARABIC FATHATAN
|
||||
case 'f': return '\u0641'; // ARABIC LETTER FEH
|
||||
case 'F': return '\u0641'; // ARABIC LETTER FEH
|
||||
case 'g': return '\u063A'; // ARABIC LETTER GHAIN
|
||||
case 'G': return '\u063A'; // ARABIC LETTER GHAIN
|
||||
case 'h': return '\u062D'; // ARABIC LETTER HAH
|
||||
case 'H': return '\u0647'; // ARABIC LETTER HEH
|
||||
case 'i': return '\u0650'; // ARABIC KASRA
|
||||
case 'I': return '\u064D'; // ARABIC KASRATAN
|
||||
case 'j': return '\u062C'; // ARABIC LETTER JEEM
|
||||
case 'J': return '\u062C'; // ARABIC LETTER JEEM
|
||||
case 'k': return '\u0643'; // ARABIC LETTER KAF
|
||||
case 'K': return '\u062E'; // ARABIC LETTER KHAH
|
||||
case 'l': return '\u0644'; // ARABIC LETTER LAM
|
||||
case 'L': return '\u0644'; // ARABIC LETTER LAM
|
||||
case 'm': return '\u0645'; // ARABIC LETTER MEEM
|
||||
case 'M': return '\u0645'; // ARABIC LETTER MEEM
|
||||
case 'n': return '\u0646'; // ARABIC LETTER NOON
|
||||
case 'N': return '\u0646'; // ARABIC LETTER NOON
|
||||
case 'o': return '\u064F'; // ARABIC DAMMA
|
||||
case 'O': return '\u064F'; // ARABIC DAMMA
|
||||
case 'p': return '\u0628'; // ARABIC LETTER BEH
|
||||
case 'P': return '\u0628'; // ARABIC LETTER BEH
|
||||
case 'q': return '\u0642'; // ARABIC LETTER QAF
|
||||
case 'Q': return '\u0642'; // ARABIC LETTER QAF
|
||||
case 'r': return '\u0631'; // ARABIC LETTER REH
|
||||
case 'R': return '\u0631'; // ARABIC LETTER REH
|
||||
case 's': return '\u0633'; // ARABIC LETTER SEEN
|
||||
case 'S': return '\u0634'; // ARABIC LETTER SHEEN
|
||||
case 't': return '\u062A'; // ARABIC LETTER TEH
|
||||
case 'T': return '\u062B'; // ARABIC LETTER THEH
|
||||
case 'U': return '\u064C'; // ARABIC DAMMATAN
|
||||
case 'u': return '\u064F'; // ARABIC DAMMA
|
||||
case 'v': return '\u0641'; // ARABIC LETTER FEH
|
||||
case 'V': return '\u0641'; // ARABIC LETTER FEH
|
||||
case 'w': return '\u0648'; // ARABIC LETTER WAW
|
||||
case 'W': return '\u0648'; // ARABIC LETTER WAW
|
||||
case 'x': return '\u0633'; // ARABIC LETTER SEEN
|
||||
case 'X': return '\u0633'; // ARABIC LETTER SEEN
|
||||
case 'y': return '\u064A'; // ARABIC LETTER YEH
|
||||
case 'Y': return '\u064A'; // ARABIC LETTER YEH
|
||||
case 'z': return '\u0632'; // ARABIC LETTER ZAIN
|
||||
case 'Z': return '\u0638'; // ARABIC LETTER ZAH
|
||||
}
|
||||
|
||||
return c;
|
||||
}
|
||||
}
|
@ -1,201 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
import java.awt.Graphics;
|
||||
import java.awt.Rectangle;
|
||||
|
||||
import java.awt.event.FocusEvent;
|
||||
import java.awt.event.KeyEvent;
|
||||
import java.awt.event.MouseEvent;
|
||||
|
||||
/** A class that handles events for a BehaviorOwner.
|
||||
* A behavior enacpsulates some piece of the event-handling logic for a component.
|
||||
* This allows the client to separate event-handling logic out into separate classes
|
||||
* according to function, or to dynamically change the way a component handles
|
||||
* events without adding a lot of special-case code to the panel itself.
|
||||
* Behaviors are stored in a linked list, and all behaviors get a crack at an event before
|
||||
* the owner gets a crack at them (right now, we rely on objects that implement
|
||||
* BehaviorOwner to support these semantics).
|
||||
* Behavior provides all the same event-handling functions that Component provides, and
|
||||
* they all have exactly the same syntax and semantics. */
|
||||
abstract class Behavior {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private Behavior fNextBehavior = null;
|
||||
private BehaviorOwner fOwner = null;
|
||||
|
||||
static class EventType {
|
||||
|
||||
EventType() {
|
||||
}
|
||||
}
|
||||
|
||||
// events - should these be in TextPanel (or elsewhere)?
|
||||
|
||||
// This event's WHAT parameter is a TextRange instance
|
||||
static final EventType SELECT = new EventType();
|
||||
|
||||
// No WHAT param for these:
|
||||
static final EventType CUT = new EventType();
|
||||
static final EventType COPY = new EventType();
|
||||
static final EventType PASTE = new EventType();
|
||||
static final EventType CLEAR = new EventType();
|
||||
static final EventType UNDO = new EventType();
|
||||
static final EventType REDO = new EventType();
|
||||
static final EventType CLEAR_COMMAND_LOG = new EventType();
|
||||
|
||||
// WHAT param is a StyleModifier
|
||||
static final EventType CHARACTER_STYLE_MOD = new EventType();
|
||||
static final EventType PARAGRAPH_STYLE_MOD = new EventType();
|
||||
|
||||
// With this event, values of the WHAT parameter are
|
||||
// either Boolean.TRUE or Boolean.FALSE
|
||||
static final EventType SET_MODIFIED = new EventType();
|
||||
|
||||
// WHAT param is a TextReplacement
|
||||
static final EventType REPLACE = new EventType();
|
||||
|
||||
// WHAT param is an Integer
|
||||
static final EventType SET_COMMAND_LOG_SIZE = new EventType();
|
||||
|
||||
public Behavior() {
|
||||
}
|
||||
|
||||
public void addToOwner(BehaviorOwner owner) {
|
||||
removeFromOwner();
|
||||
fOwner = owner;
|
||||
setNextBehavior(owner.getBehavior());
|
||||
owner.setBehavior(this);
|
||||
}
|
||||
|
||||
public boolean focusGained(FocusEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.focusGained(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean focusLost(FocusEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.focusLost(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean keyPressed(KeyEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.keyPressed(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean keyTyped(KeyEvent e) {
|
||||
|
||||
if (fNextBehavior != null) {
|
||||
return fNextBehavior.keyTyped(e);
|
||||
}
|
||||
else {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
public boolean keyReleased(KeyEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.keyReleased(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseDragged(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mouseDragged(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseEntered(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mouseEntered(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseExited(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mouseExited(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseMoved(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mouseMoved(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mousePressed(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mousePressed(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseReleased(MouseEvent e) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.mouseReleased(e);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public final Behavior nextBehavior() {
|
||||
return fNextBehavior;
|
||||
}
|
||||
|
||||
public boolean paint(Graphics g, Rectangle drawRect) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.paint(g, drawRect);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
|
||||
public void removeFromOwner() {
|
||||
if (fOwner != null) {
|
||||
if (fOwner.getBehavior() == this)
|
||||
fOwner.setBehavior(nextBehavior());
|
||||
else {
|
||||
Behavior current = fOwner.getBehavior();
|
||||
|
||||
while (current != null && current.nextBehavior() != this)
|
||||
current = current.nextBehavior();
|
||||
if (current != null)
|
||||
current.setNextBehavior(nextBehavior());
|
||||
}
|
||||
setNextBehavior(null);
|
||||
fOwner = null;
|
||||
}
|
||||
}
|
||||
|
||||
public final void setNextBehavior(Behavior next) {
|
||||
fNextBehavior = next;
|
||||
}
|
||||
|
||||
public boolean textControlEventOccurred(EventType event, Object data) {
|
||||
if (fNextBehavior != null)
|
||||
return fNextBehavior.textControlEventOccurred(event, data);
|
||||
else
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,20 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
interface BehaviorOwner {
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
public Behavior getBehavior();
|
||||
public void setBehavior(Behavior b);
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
abstract class Command {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
private Command fPreviousCommand = null;
|
||||
|
||||
// fModified is used to keep a textModified flag for
|
||||
// clients
|
||||
private boolean fModified;
|
||||
|
||||
public Command() {
|
||||
fModified = true;
|
||||
}
|
||||
|
||||
public Command previousCommand() {
|
||||
return fPreviousCommand;
|
||||
}
|
||||
|
||||
public void setPreviousCommand(Command previousCommand) {
|
||||
fPreviousCommand = previousCommand;
|
||||
}
|
||||
|
||||
public abstract void execute();
|
||||
public abstract void undo();
|
||||
|
||||
public void redo() {
|
||||
execute();
|
||||
}
|
||||
|
||||
public final boolean isModified() {
|
||||
|
||||
return fModified;
|
||||
}
|
||||
|
||||
public final void setModified(boolean modified) {
|
||||
|
||||
fModified = modified;
|
||||
}
|
||||
}
|
@ -1,30 +0,0 @@
|
||||
/*
|
||||
* (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
|
||||
*
|
||||
* The program is provided "as is" without any warranty express or
|
||||
* implied, including the warranty of non-infringement and the implied
|
||||
* warranties of merchantibility and fitness for a particular purpose.
|
||||
* IBM will not be liable for any damages suffered by you as a result
|
||||
* of using the Program. In no event will IBM be liable for any
|
||||
* special, indirect or consequential damages or lost profits even if
|
||||
* IBM has been advised of the possibility of their occurrence. IBM
|
||||
* will not be liable for any third party claims against you.
|
||||
*/
|
||||
package com.ibm.richtext.textpanel;
|
||||
|
||||
import java.awt.Component;
|
||||
import java.awt.Graphics;
|
||||
|
||||
abstract class FakeComponent {
|
||||
|
||||
static final String COPYRIGHT =
|
||||
"(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
|
||||
protected Component fHost;
|
||||
|
||||
abstract void addNotify();
|
||||
abstract void paint(Graphics g);
|
||||
void setHost(Component host) {
|
||||
fHost = host;
|
||||
}
|
||||
abstract void requestFocus();
|
||||
}
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user