1 /************************************************************** 2 * 3 * Licensed to the Apache Software Foundation (ASF) under one 4 * or more contributor license agreements. See the NOTICE file 5 * distributed with this work for additional information 6 * regarding copyright ownership. The ASF licenses this file 7 * to you under the Apache License, Version 2.0 (the 8 * "License"); you may not use this file except in compliance 9 * with the License. You may obtain a copy of the License at 10 * 11 * http://www.apache.org/licenses/LICENSE-2.0 12 * 13 * Unless required by applicable law or agreed to in writing, 14 * software distributed under the License is distributed on an 15 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY 16 * KIND, either express or implied. See the License for the 17 * specific language governing permissions and limitations 18 * under the License. 19 * 20 *************************************************************/ 21 22 23 24 package org.openoffice.accessibility.awb.view.text; 25 26 import java.awt.BorderLayout; 27 import java.awt.Color; 28 import java.awt.Component; 29 import java.awt.Graphics; 30 import java.awt.event.ActionListener; 31 import java.awt.event.ActionEvent; 32 import javax.swing.BoxLayout; 33 import javax.swing.Icon; 34 import javax.swing.JButton; 35 import javax.swing.JCheckBox; 36 import javax.swing.JColorChooser; 37 import javax.swing.JPanel; 38 import javax.swing.text.JTextComponent; 39 40 import com.sun.star.accessibility.XAccessibleContext; 41 import com.sun.star.accessibility.XAccessibleEditableText; 42 import com.sun.star.beans.PropertyValue; 43 import com.sun.star.lang.IndexOutOfBoundsException; 44 import com.sun.star.uno.UnoRuntime; 45 46 47 class TextAttributeDialog 48 extends TextActionDialog 49 { TextAttributeDialog(XAccessibleContext xContext)50 public TextAttributeDialog (XAccessibleContext xContext) 51 { 52 super (xContext, 53 "Choose attributes, select text, and press 'Set':", 54 "set"); 55 } 56 Layout()57 protected void Layout () 58 { 59 super.Layout (); 60 61 maForeground = Color.black; 62 maBackground = Color.white; 63 64 JPanel aPanel = new JPanel(); 65 aPanel.setLayout (new BoxLayout (aPanel, BoxLayout.Y_AXIS)); 66 67 maBoldCheckBox = new JCheckBox ("bold"); 68 maUnderlineCheckBox = new JCheckBox ("underline"); 69 maItalicsCheckBox = new JCheckBox ("italics"); 70 71 JButton aForegroundButton = new JButton ("Foreground", 72 new TextAttributeDialog.ColorIcon(true)); 73 aForegroundButton.addActionListener (new ActionListener() 74 { 75 public void actionPerformed (ActionEvent aEvent) 76 { 77 maForeground = JColorChooser.showDialog ( 78 TextAttributeDialog.this, 79 "Select Foreground Color", 80 maForeground); 81 } 82 } ); 83 84 JButton aBackgroundButton = new JButton("Background", 85 new TextAttributeDialog.ColorIcon(false)); 86 aBackgroundButton.addActionListener (new ActionListener() 87 { 88 public void actionPerformed (ActionEvent eEvent) 89 { 90 maBackground = JColorChooser.showDialog( 91 TextAttributeDialog.this, 92 "Select Background Color", 93 maBackground); 94 } 95 } ); 96 97 aPanel.add (maBoldCheckBox); 98 aPanel.add (maUnderlineCheckBox); 99 aPanel.add (maItalicsCheckBox); 100 aPanel.add (aForegroundButton); 101 aPanel.add (aBackgroundButton); 102 103 getContentPane().add (aPanel, BorderLayout.WEST); 104 } 105 106 107 /** edit the text */ EditableTextAction(XAccessibleEditableText xText)108 boolean EditableTextAction (XAccessibleEditableText xText) 109 throws IndexOutOfBoundsException 110 { 111 PropertyValue[] aSequence = new PropertyValue[6]; 112 aSequence[0] = new PropertyValue(); 113 aSequence[0].Name = "CharWeight"; 114 aSequence[0].Value = new Integer (maBoldCheckBox.isSelected() ? 150 : 100); 115 aSequence[1] = new PropertyValue(); 116 aSequence[1].Name = "CharUnderline"; 117 aSequence[1].Value = new Integer (maUnderlineCheckBox.isSelected() ? 1 : 0); 118 aSequence[2] = new PropertyValue(); 119 aSequence[2].Name = "CharBackColor"; 120 aSequence[2].Value = new Integer (maBackground.getRGB()); 121 aSequence[3] = new PropertyValue(); 122 aSequence[3].Name = "CharColor"; 123 aSequence[3].Value = new Integer (maForeground.getRGB()); 124 aSequence[4] = new PropertyValue(); 125 aSequence[4].Name = "CharPosture"; 126 aSequence[4].Value = new Integer (maItalicsCheckBox.isSelected() ? 1 : 0); 127 aSequence[5] = new PropertyValue(); 128 aSequence[5].Name = "CharBackTransparent"; 129 aSequence[5].Value = new Boolean (false); 130 131 return xText.setAttributes ( 132 GetSelectionStart(), 133 GetSelectionEnd(), 134 aSequence); 135 } 136 137 class ColorIcon 138 implements Icon 139 { ColorIcon(boolean bWhich)140 public ColorIcon(boolean bWhich) { bForeground = bWhich; } getIconHeight()141 public int getIconHeight() { return nHeight; } getIconWidth()142 public int getIconWidth() { return nWidth; } paintIcon(Component c, Graphics g, int x, int y)143 public void paintIcon (Component c, Graphics g, int x, int y) 144 { 145 g.setColor( getColor() ); 146 g.fillRect( x, y, nHeight, nWidth ); 147 g.setColor( c.getForeground() ); 148 g.drawRect( x, y, nHeight, nWidth ); 149 } getColor()150 Color getColor() 151 { 152 if (bForeground) 153 return maForeground; 154 else 155 return maBackground; 156 } 157 158 private static final int nHeight = 16; 159 private static final int nWidth = 16; 160 private boolean bForeground; 161 } 162 163 164 165 166 private JCheckBox 167 maBoldCheckBox, 168 maUnderlineCheckBox, 169 maItalicsCheckBox; 170 private Color 171 maForeground, 172 maBackground; 173 174 } 175 176