<JSTORM> Revision <1.0> ÿ JSTORM http:www.jstorm.pe.kr
Revision: <1.0> <2000128> Document Information Document title: Document file name: ( ÿ, 1.0,draft).doc Revision number: <1.0> Issued by: < ÿ > (mailto: dogjdw@nownuri.net) Issue Date: <2000228 > Status: Draft Audience Abstract Reference Benchmark information Content Information Í ì æ ì ûý. http:java.sun.comproductsjfctscindex.html JSTORM <274>
Revision: <1.0> <2000128> Document Approvals Signature date Signature date * approval. Revision History * þ Revision Date Author Description of change JSTORM <374>
Revision: <1.0> <2000128> Table of Contents 1. Ð...5 2. ë...28 3....57 JSTORM <474>
Revision: <1.0> <2000128> :7 Ð Í Ð ý. æ ý. Ì Í Ð Í Í ý. Í æ (Architecture) ý. ç Ð ý. ý ý. Ìé Ì Ì ý. ì Ð Ð ý. (?) ý. ì ý. Ì ì ( ý) (javax.swing.table) ý. Í ý. ý æ û Ì ì ý. æ ý. Í æ ç û Ì æ ý Ð ý. Ð Ð Ì Ì Ì Ì ý. ý ( ). Ì Ð ý.? (Sorting) Ð ý. ý. Í Ð 100000 $100,000 ý. Ì ý ý. Ì ý. ÿ ý Ð Í ý. Í Í ûý. ÿ ÿ Í ý. ( Ð ý) ÿ ý Ð ì ì û MVC(Model View Controller) ÿ ý JSTORM <574>
Java Coding Standard Revision: <1.0> <2000128> Ð Ð ý. Ì ÿ. 1. Ð (1) Ð Ì ý. ü ý ý. Ì õ. 1) [ 1] Ì 2 ý. (Row ) (Record) (Column ) (Field) þ ý. Ì (Cell) ý. þ ý. ý æ ý. [ 1] ý 2) ý. [Ì 1] æ ý. ý. Ì Í ÿ ( ý.) û ý. ý [Ì 1] ÿ æ ý. [Ì 1]. ý Ð ý. [Ì 1] ( ) JSTORM <674>
Revision: <1.0> <2000128> TableModel, AbstractTableModel, DefaultTableModel. (Model) ý. ÿ Í ý. [ 1] ý. [ 1] TableModel ÿ Í ý. TableModel Ð ý. AbstractTableModel þ ý. AbstractTableModel JTable ý. DefaultTableModel AbstractTableModel ý. Ì ý TableColumn, TableColumnModel, DefaultTableColumnModel. ý., Ð, ý, ý. MVC ý. ý ì Ð ý. Ð ý. JSTORM <774>
Revision: <1.0> <2000128> [ 2] TableColumn JTableColumnModel DefaultTableColumnModel TableCellRenderer, TableCellEditor. ý. TableCellRenderer æ (Visual) æ TableCellEditor æ ý. ý. [ 1] (String) Í ý. (Integer) Í ý. þ(tablecolumn) TableCellRenderer TableCellEditor ý.. [ 3] TableCellRenderer TableCellEditor ÿ ý. Ð JTable JTableColumnModel Ð ý. Ð ý. Ð ý. Í ÿ ý. ÿ Í,, Ì ý. ý Ð ý Ô ý. Ð æ ÿ ý. Ì ý Ð ý. [ 1] ý public class FirstTableDemo extends JFrame { ** * private static final String[] m_columnnames = { " ", " ", " ", " " ; ** * private Object[][] m_data = { { " ", new Integer(27), "02-123-4567", " ", { " ", new Integer(30), "02-4546-3456", " ", { " ", new Integer(24), "032-398-3214", " ", { " ", new Integer(32), "0615-323-6583", " ", { " ", new Integer(57), "02-453-7689", " ", JSTORM <874>
Revision: <1.0> <2000128> { " ", new Integer(75), "062-378-6048", " ", { " ", new Integer(27), "02-665-1297", " " ; ** Constructor * public FirstTableDemo() { super(" "); JTable table = new JTable(m_data, m_columnnames); table.setpreferredscrollableviewportsize( new Dimension(500, 70)); JScrollPane scrollpane = new JScrollPane(table); getcontentpane().add(scrollpane, BorderLayout.CENTER); public static void main(string[] args) { FirstTableDemo frame = new FirstTableDemo(); frame.pack(); frame.setvisible(true); [ 1] [ 1] Ì Ð Ð Ì ý. ( Ð ý. ý. Ì Ð ý.) ý. þ m_columnnames þ m_data JTable ì ý. JTable table = new JTable(m_data, m_columnnames); JTable ý. ý ÿ JTable Ð ý. Ð ( ) Ð Ìÿ ý ( Ð ) ý Ì Ý ý. Ð [Ì 1] ý ý. Ð ý. TableColumnModel TableColumn (Contains) ý? JTable TableColumnModel ý ListSelectionModel JSTORM <974>
Revision: <1.0> <2000128> ý? ý. Ì [ 1] Ð Ðÿ ý. 2. JTable ÿ ý(represent). Ì ÿ JTable ý ý. (Column Header) JTableHeader, TableCellRender TableCellEditor, Ì ý Ð TableColumn ý. ý TableColumnModel ý. JTable Ì ÿ ÿ (?) ý. æ þ. (1) TableModel, AbstractTableModel, DefaultTableModel TableModel JTable ý. [ 4] JDK Ð ý. [ 4] TableModel JTable ( ) (Class) ý. getcolumnclass() getcolumnclass() ý. æ ý. getcolumncount() ý. getcolumnname() Ð ý. getrowcount() ý. getvalueat() ý. iscelleditable() æý. setvalueat() ý. TableModel JTable ý. TableModel Ð AbstractTableModel ý. ý AbstractTableModel ý. AbstractTableModel ë (EventListeners) (Fire) ý. Ì ý ý. AbstractTableModel Ð ý. public int getrowcount(); public int getcolumncount(); public Object getvalueat(int rowindex, int columnindex); JSTORM <1074>
Revision: <1.0> <2000128> JTable ý. MyTableModel ý JTable ì ý. TableModel mytablemodel = new MyTableModel(); JTable table = new JTable(myTableModel); JTable setmodel() ý. [ 2] ý Ð GugudanTableModel ý. Ð ý. ý ý. TableModel ý. ý ý. [ 2] public class GugudanModelDemo extends JFrame { public GugudanModelDemo() { super(" "); GugudanTableModel mymodel = new GugudanTableModel(); JTable table = new JTable(myModel);. getcontentpane().add(table.gettableheader(), BorderLayout.NORTH); getcontentpane().add(table, BorderLayout.CENTER); public static void main(string[] args) { GugudanModelDemo frame = new GugudanModelDemo(); frame.pack(); frame.setvisible(true); ** * class GugudanTableModel extends AbstractTableModel { public int getcolumncount() { return 9; public int getrowcount() { return 9; public String getcolumnname(int col) { return "" + (col+1); public Object getvalueat(int row, int col) { return new Integer((row+1)*(col+1)); JSTORM <1174>
Java Coding Standard Revision: <1.0> <2000128> [ 2] ý Í Ð ý. DefaultTableModel JTable Ð ( ) ý. [ 1] ý. JTable DefaultTableModel ý. AbstractTableModel Ð æ ý. Ì ý. æ ý. DefaultTableModel Ð Ð ý. DefaultTableModel Ì æ ý. (2) TableColumnModel, DefaultColumnModel [Ì 1] JTable TableModel TableColumnModel ý. TableColumnModel ý. ý ÿ,, ý. [ 5] ý. [ 5] TableColumnModel addcolumn() TableColumnModel (TableColumn) ý. getcolumnindex() getcolumnatx() movecolumn() removecolumn() (TableColumn) ý. Ðý. TableColumnModel ý. TableColumnModel ý. â ûý. ý â ý. Ì ý ý Ì ý. Ì TableColumnModelListener ý. ColumnModelEvent ý. [ 5] æ þ addcolumnmodellistener() removecolumnmodellistener() TableColumnModel JSTORM <1274>
Revision: <1.0> <2000128> ý. TableColumnModelListener ý ý. columnselectionchanged() ý ý. public void columnadded(tablecolumnmodelevent e) public void columnremoved(tablecolumnmodelevent e) public void columnmoved(tablecolumnmodelevent e) public void columnmarginchanged(changeevent e) public void columnselectionchanged(listselectionevent e) DefaultTableModel TableColumnModel DefaultTableColumnModel ý. ë(tablecolumnmodellistener) ý ý. (3) TableCellRenderer, TableCellEditor ÿ TableColumn ý. TableColumn ÿ TableColumnModel TableColumn ý. Ì ý. ý ý. Ì ÿ Ð. ÿ. æ æ ý. TableCellRenderer TableCellEditor ý. Ð(Cell Renderer) Ð(Cell Editor) ý. ý. ý ý. public Component gettablecellrenderercomponent( JTable table, Object value, boolean isselected, boolean hasfocus, int row, int column) public Component gettablecelleditorcomponent( JTable table, Object value, boolean isselected, int row, int column) ì ì ý. JTable Ð Ð ý TableCellRenderer Ð DefaultTableCellRenderer TableCellEditor Ð DefaultTableCellEditor ý. DefaultTableCellRenderer gettablecellrenderercomponent ì value JSTORM <1374>
Java Coding Standard Revision: <1.0> <2000128> þ ì ý. [ 6] Ì ý. Boolean JCheckBox þ ý. [ 6] DefaultTableCellRender ì value ì Boolean JCheckBox Number JLabel ( ) ImageIcon JLabel ( ) Object JLabel (Object ) DefaultTableCellRenderer DefaultTableCellEditor ý ý Ð ý. [ 3] Ì [ 1] Ì Þ ý. Ð ý. ý ý. TableColumn job = table.getcolumnmodel().getcolumn(3);. JComboBox combojob = new JComboBox(); combojob.additem(" "); combojob.additem(" "); combojob.additem(" "); combojob.additem(" "); combojob.additem(" "); combojob.additem(" "); combojob.additem(" "); job.setcelleditor(new DefaultCellEditor(comboJob)); [ 3] Ð JSTORM <1474>
Java Coding Standard Revision: <1.0> <2000128> (4 TableColumn) æ ý Ì Ð ý. Ð setcelleditor() ý. new DefaultCellEditor(comboJob) Ð æý. DefaultCellEditor ý ý. public DefaultCellEditor(JTextField x) public DefaultCellEditor(JCheckBox x) public DefaultCellEditor(JComboBox x) DefaultCellEditor ì DefaultCellEditor gettablecelleditorcomponent() ý. DrfaultCellEditor ý Ð ý Ð ý. Ì DrfaultCellEditor Ð Ð ý. TableCellRenderer TableCellEditor Ð Ð ý. [ 4] ý. [ 4] Ð Ð CD ý. ý Ð, ý. ( þ Ì ý) CD [ 4] ý., Ð ý ý. Ì Ð Ð ý. [ 3] Ð Ð. TableColumn setcelleditor() Ð ý ý. JTable ý Ð Ð ý. public void setdefaultrenderer(class columnclass, TableCellRenderer renderer) public void setdefaulteditor(class columnclass, TableCellEditor editor) "Class" ý. ( ) ÿ Ð Ð ý. ( ) TableColumn JSTORM <1574>
Revision: <1.0> <2000128> setcellrenderer() sefcelleditor() ý. ý [ 3] Volumn æ VolumnRenderer VolumnEditor Ð Ðý. JTable setdefaultrenderer() æ Ð ý. Volume VolumeRender Ð ý Ðý. setdefaulteditor() Volume VolumeEditor ý. [ 3] Ð, Ì public class AudioDemo extends JFrame { public AudioDemo() { super(" CellRenderer, CellEditor "); AudioModel model = new AudioModel(); JTable table = new JTable(model); CellRenderer CellEditor. table.setdefaultrenderer(volume.class, new VolumeRenderer()); table.setdefaulteditor(volume.class, new VolumeEditor()); getcontentpane().add(table.gettableheader(), BorderLayout.NORTH); getcontentpane().add(table, BorderLayout.CENTER); public static void main(string args[]) { new AudioDemo(); [ 4] VolumeRenderer ** Volume * public class VolumeRenderer extends JScrollBar implements TableCellRenderer { public VolumeRenderer() {. super(jscrollbar.horizontal); public Component gettablecellrenderercomponent( JTable table, Object value, boolean isselected, JSTORM <1674>
Revision: <1.0> <2000128> boolean hasfocus, int row,int column) { if (value == null) { return this; if (value instanceof Volume) { setvalue(((volume)value).getvolume()); else { setvalue(0); return this; [ 5] VolumeEditor ** Volume * public class VolumeEditor extends JScrollBar implements TableCellEditor {. private Vector m_listeners; private int m_originalvalue; public VolumeEditor() {. super(jscrollbar.horizontal); m_listeners = new Vector(); public Component gettablecelleditorcomponent( JTable table,object value, boolean isselected, int row,int column) { if (value == null) { return this; if (value instanceof Volume) { setvalue(((volume)value).getvolume()); else { setvalue(0); table.setrowselectioninterval(row, row); table.setcolumnselectioninterval(column, column); m_originalvalue = getvalue(); return this; public void cancelcellediting() { fireeditingcanceled(); JSTORM <1774>
Revision: <1.0> <2000128> public Object getcelleditorvalue() { return new Integer(getValue()); public boolean iscelleditable(eventobject eo) { return true; public boolean shouldselectcell(eventobject eo) { return true; public boolean stopcellediting() { fireeditingstopped(); return true; public void addcelleditorlistener(celleditorlistener cel) { m_listeners.addelement(cel); public void removecelleditorlistener(celleditorlistener cel) { m_listeners.removeelement(cel); protected void fireeditingcanceled() { setvalue(m_originalvalue); ChangeEvent ce = new ChangeEvent(this); for (int i = m_listeners.size(); i >= 0; i--) { ((CellEditorListener)m_listeners.elementAt(i)).editingCanceled(ce); protected void fireeditingstopped() { ChangeEvent ce = new ChangeEvent(this); for (int i = m_listeners.size() - 1; i >= 0; i--) { ((CellEditorListener)m_listeners.elementAt(i)).editingStopped(ce); Ð þ Ð ý. Ð ý. CD ý ý. Ì Ð ý. Ð Ð ë(celleditorlistener) ý. [ 5] ë ý. editingcanceled() ë, editingstopped() ë ý. JSTORM <1874>
Revision: <1.0> <2000128> (4) JTable JTable ý. Ì JTable ý æ ý. JTable Í ÿ Ð ý. Ì ÿ JTable ý. JTable Ð ý. Ì û Document Ð ý. Ð ý Í ý. [ 7] JTable JTable() gettableheader() setdefaultrenderer() setdefaulteditor() setrowselectioninterval() getselectedrow() convertcolumnindextomodel() getvalueat() addcolumn() editcellat() getmodel() ý. Í Ð Ð ý. ì ý. ë í í ý. Ð Ð ý. ý. ( Ì ) æ ý. ý. Ì û API Ú Ð ý. Þ ý. Í ý ý. æý. ý. ( Ì ) ý. Ð ì ý. ý. Ì ý. JTable Ì ý. JTable ý ý. public class JTable extends JComponent implements TableModelListener, Scrollable, TableColumnModelListener, ListSelectionListener, CellEditorListener, Accessible JTable, Ì ý. JTable ý þ ý. JTable TableModel TableColumnModel JSTORM <1974>
Java Coding Standard Revision: <1.0> <2000128> Ì CellEditor Ð ý. Ì Ì (implements) ý. ÿ ý. 3. Ì Í ý æ ý. Ì Í Ô Ð (?) Ð û æ ý. ý ý. Ð Í ý. þ ý. Ì ý Ð ý æ Ð Ð ý. ý. Ð ý. 1. Ð 98 Ð (Sorting) Ð ý. Ð Ì Ð ý. Ð ý. Ì ý æ ý. Ì. [ 5] Ð JSTORM <2074>
Java Coding Standard Revision: <1.0> <2000128> Ð í?? ý. è Ð ý. Ì Ð í? ûý. è ý Ð ý. ý. Ì? ý. Ð þ Ì ý. Ì ý ý ý. Ì? þ ý. Ð ý. û (Strategy, Policy) 3 ý ý. æ Design Patterns" (Erich Gamma ) Ð ý. ÿ ûð ý. Ì Ð ý Ð ý. ý ý Þ ý. [Ì 2] [Ì 2] ÿ ý. Í Ô Ì ý. ý TableModel JTable ý. Ð ý Ì Sorter Ì ý. Ð ( Ð ý. ^^) ý. Ð ý ý. ý æ ý. Ð ( Ð Ð) Ð ý Ì æ ý. TableModelListener Ð Ð ý. Ð ý ý. MyTableModel mymodel = new MyTableModel(); JSTORM <2174>
Java Coding Standard Revision: <1.0> <2000128> TableSorter sorter = new TableSorter(myModel); JTable table = new JTable(sorter); sorter.addmouselistenertoheaderintable(table); Ð TableSorter ý. TableSorter TableModel Ð Ð ý. (TableMap ) ý. Ì ý. Ì ÿ Ð. 1) ý. 2) 1) TableSorter ì ý. 3) TableSorter JTable ì ý. TableSorter TableModel ì ý. 4) addmouselistenertoheaderintable() ý. TableSorter AbstractTableModel ý. ( TableMap AbstractTableModel TableSorter ý TableMap ý) è Ð ý. Ì ÿ ý ( ) æ ý. addmouselistenertoheaderintable() (Column Header) þ Ð ý. Ô Ð ý. 2. (Row Header) Í ý ý. Ì ý ý. Ð Ð ý. Ì Í þ ý. Í ý. Ì. ý. Ì ý. (Column Header) ( ) ý. [ 6] ý ý. ý. ûý. Ì. [ 6] ý JSTORM <2274>
Revision: <1.0> <2000128> ý. ý ý ý. ý. TableColumnModel ý ý. ý TableColumnModel ý ý. TableColumnModel ý. ý. ý Ðý. ì MVC Ð ý. Ì (Index=0) ý. ý. TableColumnModel.. TableColumnModel rowheadermodel = new DefaultTableColumnModel() { boolean first = true; public void addcolumn(tablecolumn tc) { if (first) {. tc.setmaxwidth(50); super.addcolumn(tc); first = false;. ; TableColumnModel. JSTORM <2374>
Revision: <1.0> <2000128>. TableColumnModel cm = new DefaultTableColumnModel() { boolean first = true; public void addcolumn(tablecolumn tc) {. if (first) { first = false; return;. tc.setminwidth(100); super.addcolumn(tc); ; DefaultTableColumnModel TableColumnModel ý. æ (Anonymous Inner Class) ý. æ ÿ Ð ý. http:java.sun.comproductsjdk1.1docsguideinnerclassesspecinn erclasses.doc.html TableColumnModel ý. JTable addcolumn() ý. TableColumnModel ý. Ì TableColumnModel ÿ ý. Ì ý TableColumnModel ý. JTable jt = new JTable(tm, cm);. JTable headercolumn = new JTable(tm, rowheadermodel); jt.createdefaultcolumnsfrommodel(); headercolumn.createdefaultcolumnsfrommodel(); createdefaultcolumnsfrommodel() ý. TableColumnModel addcolumn() Ð ý. ý. Ð ý SelectionModel ý. jt.setselectionmodel(headercolumn.getselectionmodel()); ë þ ý. JViewport ý. JSTORM <2474>
Revision: <1.0> <2000128> JViewport jv = new JViewport(); jv.setview(headercolumn); ( ). JScrollPane jsp = new JScrollPane(jt); JScrollPane RowHeader. jsp.setrowheader(jv); þ ý. Í æ Ð ( Ð ý.) æ þ Ð ý. Ì 2 ý. ý ý. API Í ÿ Ð ý. 3. Ð Ì Ì Ð ý. Ì ý. Ð ý. ÿ ì (JTable ) (Model) (View) Ð ý. MVC ( ) ÿ ý ý ý. Ì Ì ý. [ 6] Ì ý. Ì ý. æ ý ý ý. [Ì 3] æ ý. æ ý. TableModelEvent ý ý. ý ý. TableModelEvent ý. TableModelListener ý. ý setvalueat() ý. public void setvalueat(object value, int row, int col) { data[row][col] = (String)value; firetablerowsupdated(row,row); setvalueat() ý. ý firetablerowsupdated() ý. firetablerowsupdated() JSTORM <2574>
Java Coding Standard Revision: <1.0> <2000128> AbstractTableModel ý. Ì. TableModelListener ý. TableModelListener tablechanged() ý. ý ý. public void tablechanged(tablemodelevent tme) { updatelocalvalues(tme.gettype()!= TableModelEvent.UPDATE); tablechanged() ý updatelocalvalues() ý. updatelocalvalues() (Structure) (true ) û ý (false ) Ð ý. ý Ü Ð ý. [ 7] [Ì 3] ý JSTORM <2674>
Revision: <1.0> <2000128> Ð Lightweight ì ý. Lightweight ì (Sun) Ð ý. Ð ü ý ì ( Ð ). ì û MVC ý. Í ý. ý Ð Ð ý. 4. Í Ðý Ð Í ÿ ý. þ ì ý. Ì û ÿ Ì ìý. Í Ì ý. ý API ý ý ÿ ý. Ì û ÿ ý ÿ Ì Ì API Document ý. ý þ ë æ ÿ ý. JSTORM <2774>
Java Coding Standard Revision: <1.0> <2000128> ;7 ë (?) ý. ë Ì ý. ë Ì æ ý. Ì æ ë (Extensibility) (Flexibility) Í ý. ÿ Ð ý. (Architecture) ý. ì ý ì Ì Í ý. ÿ ÿ æ ÿ Ð ý. Ð ë æ Ì ÿ Ð ý. Ì ë ý. 1. (?) ý Ì ý. Ð AWT ý ý ÿ ý.. import javax.swing.*; public class ContainerDemo_1 { public static void main(string s[]) { JFrame frame = new JFrame("Swing Container Demo #1"); JButton button = new JButton("A Button"); (?) frame.getcontentpane().add(button); frame.setsize(300, 200); frame.setvisible(true); [ 1] JFrame ý JSTORM <2874>
Revision: <1.0> <2000128> ý ý. frame.getcontentpane().add(button); AWT frame.add(button) getcontentpane()? Í Ì Í ý. frame.add(button) Ì ý ý. Exception in thread "main" java.lang.error: Do not use javax.swing.jframe.add() use javax.swing.jframe.getcontentpane().add() instead at javax.swing.jframe.createrootpaneexception(jframe.java:327) at javax.swing.jframe.addimpl(jframe.java:349) at java.awt.container.add(container.java:206) at ContainerDemo_1.main(ContainerDemo_1.java:8) getcontentpane() Ì Container ý. Ì ý ë? Ì? þð ý. Ì û. Ì Ì Í ææ ý. 2. ë Í ë JApplet, JDialog, JFrame, (JInternalFrame), Ì JWindow ë(top Level Container) ý. ë ý ì þ Ð ý ë þ ý. Ì ì (HeavyweightComponent) ý ý. ( ì ÿ Ð Ð ý.) JInternalFrame ë ÿ AWT ë (extends) ý. JFrame AWT Frame ý.([ì 5] [Ì 6] ) Ð ì ý ý. Ì ë ì ÿ Ð ý. JInternalFrame ë û ( ì ûý.) ý ë Ð ë Í ý. ë Ð ý JFrame ÿ ý. Ì û Ð æ JFrame æ ü Ð ý. [Ì 1] JFrame Ì ý. Ì JFrame Menu Bar Content Pane( ) ý. Menu Bar ì þ JSTORM <2974>
Java Coding Standard Revision: <1.0> <2000128> ý. frame.getcontentpane() ý. [Ì 1] JFrame [ 1] ý. (Cyan) (JLabel) ý. [ 1] ë import java.awt.*; import javax.swing.*; public class TopLevelContainerDemo extends JFrame { public TopLevelContainerDemo() { super("top Level Container Demo");. JMenuBar menubar = new JMenuBar(); menubar.setopaque(true); menubar.setbackground(color.cyan); menubar.setpreferredsize(new Dimension(300, 20)); setjmenubar(menubar);. JLabel label = new JLabel(""); label.setopaque(true); label.setbackground(color.yellow); getcontentpane().add(label, BorderLayout.CENTER); setsize(300, 200); setvisible(true); JSTORM <3074>
Java Coding Standard Revision: <1.0> <2000128> public static void main(string args[]) { new TopLevelContainerDemo(); [ 2] ë Ð ë ÿ ý. Ì Í ûý. Í ý ý. ë æ ý. 3. ë! [Ì 2] ë æ Ì ý. ý. ý. Ì RootPane( ) ý. ý Ð ý. JFrame ý ý. [Ì 3] æ ý. ë ý. Í Í ý. ë ë RootPaneContainer (implements) ý. [ 1] RootPaneContainer ý. [Ì 3] ý ý. LayeredPane ý GlassPane ý. LayeredPane ý ì ë ý. (Layer) ì ý ý. LayeredPane ý. LayeredPane GlassPane Ð ý. JSTORM <3174>
Java Coding Standard Revision: <1.0> <2000128> [Ì 2] JFrame <--- Ì 3 ûý. [Ì 3] JRootPane <--- Ì 3 ûý. <--- Ì GlassPane <---? [ 1] RootPaneContainer JSTORM <3274>
Java Coding Standard Revision: <1.0> <2000128> getcontentpane() setcontentpane() getglasspane() setglasspane() getlayeredpane() setlayeredpane() getrootpane() ContentPane ý. GlassPane ý. LayeredPane ý. RootPane ý. 4. GlassPane? GlassPane ý.. GlassPane ([Ì 3]) Ð ý. JPanel setopaque(false); setvisible(false); ý. Ì GlassPane? GlassPane Ú ý. Ì InternalFrame ý. GlassPane ý. [Ì 3] GlassPane ý ý. GlassPane Ì þ ý. GlassPane InternalFrame (Multi-Document) GlassPane ý. [ 3] JSTORM <3374>
Revision: <1.0> <2000128> [ 3] ý. æ JInternalFrame ý. æ æ ý. Ì ý æ Ð þ ý. ý. Ì ý. [ 3] Ð æ ý. GlassPane ý. ý æ ( ) Ì æ GlassPane ý.(setvisible(true)) ( Ð GlassPane û æ.) GlassPane ý. Ì Opaque Ð GlassPane ý. GlassPane õ ý. ý Ì æ, GlassPane ý ý (setvisible(false)) æ ý. GlassPane ý. Ì GlassPane. [ 4] Ì ý. GlassPane ý. "GlassPane Ð" õ GlassPane ý. GlassPane Ð GlassPane þ þ GlassPane Ð ý GlassPane Ì ý. GlassPane Ð Ð Ðý. Ì Ì GlassPane Ð Ì ý ý. GlassPane þ Ð ý. [ 2] GlassPane import java.awt.*; import java.awt.event.*; import javax.swing.*; public class GlassPaneDemo extends JFrame implements ActionListener { GlassPane MyGlassPane m_glasspane = new MyGlassPane(); public GlassPaneDemo() { super("glasspane Demo"); JSTORM <3474>
Revision: <1.0> <2000128> GlassPane. JButton buttonshowglass = new JButton("GlassPane "); buttonshowglass.addactionlistener(this);. getcontentpane().setlayout(new GridLayout(0, 2)); getcontentpane().add(new JButton(" 1")); getcontentpane().add(new JButton(" 2")); getcontentpane().add(buttonshowglass); getcontentpane().add(new JButton(" 3"));. JMenuBar menubar = new JMenuBar(); menubar.add(new JMenu(" ")); menubar.add(new JMenu(" ")); menubar.add(new JMenu(" ")); setjmenubar(menubar); GlassPane. setglasspane(m_glasspane); <----- [1 ] setsize(300, 200); setvisible(true); public void actionperformed(actionevent e) { GlassPane. m_glasspane.setvisible(true); public static void main(string[] args) { new GlassPaneDemo(); class MyGlassPane extends JPanel implements ActionListener { private Point m_spotlocation; public MyGlassPane() { JButton button = new JButton("GlassPane "); button.addactionlistener(this); JSTORM <3574>
Java Coding Standard Revision: <1.0> <2000128> setlayout(new GridBagLayout()); add(button); addmouselistener(new MouseAdapter() { <----- [2 ] public void mouseclicked(mouseevent e) { m_spotlocation = e.getpoint(); System.out.println(m_spotLocation); repaint(); ); public void actionperformed(actionevent e) { GlassPane. setvisible(false); public void paintcomponent(graphics g) {. if (m_spotlocation!= null) { g.setcolor(color.red); g.filloval(m_spotlocation.x-15, m_spotlocation.y-15, 30, 30); [ 4] GlassPane JSTORM <3674>
Revision: <1.0> <2000128> [ 2] [1 ] JFrame setglasspane(m_glasspane) GlassPane ý.([ 1] ) [2 ] GlassPane Ì ý ì þ ý Ð ý. Ì GlassPane Ô ý LayeredPane ÿ. 5. LayeredPane AWT ý ý ý. ë ì ý. GlassPane ý. ( Ì æ ý ý.) Ì (Layer) ÿ. ý. [ 3] LayerPane import java.awt.*; import javax.swing.*; public class LayerDemo extends JFrame { public LayerDemo() { super(" Layer "); JLayeredPane layeredpane = getlayeredpane(); JButton top = new JButton(); top.setbackground(color.white); top.setbounds(50, 50, 100, 100); JButton middle = new JButton(); middle.setbackground(color.gray); middle.setbounds(100, 100, 100, 100); JButton bottom = new JButton(); bottom.setbackground(color.black); bottom.setbounds(150, 150, 100, 100);. layeredpane.add(bottom, new Integer(1)); JSTORM <3774>
Java Coding Standard Revision: <1.0> <2000128> layeredpane.add(middle, new Integer(2)); layeredpane.add(top, new Integer(3)); setsize(300, 300); setvisible(true); public static void main(string[] args) { new LayerDemo(); [ 3] LayeredPane þ ý. ý þð bottom 1 þ ý. þ ì æ þ ì ý. ì Ì æ ì Ì ì Ì Ì Ð ý. ([ 5] ) [ 5] LayerPane JLayeredPane ì þð add() ý. JLayeredPane Container æ addimpl() ý. addimpl() ý ý. protected void addimpl(component comp, Object layer, int position) comp þ ì layer ì þð ý. layer Object Ð í new Integer(3); Integer ì ý. position ì æý. ì æ ý., position ì æ JSTORM <3874>
Revision: <1.0> <2000128> ý. add() position( ) ì æ ý 2 Ë ý. 1. position æ ì Ì ý. 2. position -1 Í ë ì position ì ý position( ) ì ý. ì position Ì ý. position (Layer) ÿ ý. Ì Í ý. A, B, C ì 0, 1, 2 (position) ý. D 1 ý ý. ý E -1 ý ý. ý F 5 ý ý. A B C A D B C A D B C E A D B C E F Ì A, B, C, D, E, F ì Ì? F, E, C, B, D, A Ì ý., position F ý Ì æ position A Ì ý. (Position) (Layer) æ ý. æ æ þ ì þ ì ý Ì ý. JLayeredPane (?) ý. [Ì 4] [ 3] æ ý. ý. Ì Ì Ì ý. Ð ý. ( ý.) Ì û DEFAULT_LAYER+3 Ð ý. Ì LayeredPane ý. [ 4] LayeredPane JSTORM <3974>
Revision: <1.0> <2000128> import java.awt.*; import java.awt.event.*; import javax.swing.*; import javax.swing.border.*; public class LayeredPaneDemo extends JFrame { ** * private String[] m_layernames = { " ", " ", " ", " ", " " ; ** * private Color[] m_layercolors = { Color.yellow, Color.magenta, Color.cyan, Color.red, Color.green ; ** LayeredPane * private JLayeredPane m_layeredpane; ** ( ) * private JLabel m_dukelabel; public LayeredPaneDemo() { super("layeredpane "); LayeredPane. m_layeredpane = new JLayeredPane(); m_layeredpane.setpreferredsize(new Dimension(300, 310)); m_layeredpane.setborder(borderfactory.createtitledborder( ".")); m_layeredpane.addmousemotionlistener(new MouseMotionAdapter() { public void mousemoved(mouseevent e) { m_dukelabel.setlocation(e.getx()-32, e.gety()-32); ); JSTORM <4074>
Revision: <1.0> <2000128> Point origin = new Point(10, 20); int offset = 35; LayeredPane. for (int i = 0; i < m_layernames.length; i++) { JLabel label = createcoloredlabel(m_layernames[i], m_layercolors[i], origin); m_layeredpane.add(label, new Integer(i)); origin.x += offset; origin.y += offset; LayeredPane. ImageIcon icon = new ImageIcon("WavingDuke.gif"); m_dukelabel = new JLabel(icon); m_dukelabel.setbounds(15, 225, icon.geticonwidth(), icon.geticonheight()); m_layeredpane.add(m_dukelabel, new Integer(2), 0); LayeredPane. Container contentpane = getcontentpane(); contentpane.setlayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS)); contentpane.add(box.createrigidarea(new Dimension(0, 10))); contentpane.add(createcontrolpanel()); contentpane.add(box.createrigidarea(new Dimension(0, 10))); contentpane.add(m_layeredpane); pack(); setvisible(true); ** JLabel. * private JLabel createcoloredlabel(string text, Color color, Point origin) { JLabel label = new JLabel(text); label.setverticalalignment(jlabel.top); label.sethorizontalalignment(jlabel.center); label.setopaque(true); label.setbackground(color); label.setforeground(color.black); label.setborder(borderfactory.createlineborder(color.black)); label.setbounds(origin.x, origin.y, 140, 140); return label; JSTORM <4174>
Revision: <1.0> <2000128> **. * private JPanel createcontrolpanel() { final JCheckBox ontop = new JCheckBox( " (Layer)."); ontop.setselected(true); ontop.addactionlistener(new ActionListener() { public void actionperformed(actionevent e) { if (ontop.isselected()) m_layeredpane.movetofront(m_dukelabel); else m_layeredpane.movetoback(m_dukelabel); ); final JComboBox layerlist = new JComboBox(m_layerNames); layerlist.setselectedindex(2); Cyan layer layerlist.addactionlistener(new ActionListener () { public void actionperformed(actionevent e) { int position = ontop.isselected()? 0 : 1; m_layeredpane.setlayer(m_dukelabel, layerlist.getselectedindex(), position); ); JPanel controls = new JPanel(); controls.add(layerlist); controls.add(ontop); controls.setborder(borderfactory.createtitledborder( " ")); return controls; public static void main(string[] args) { new LayeredPaneDemo(); [ 6] Ì ý. Ð Ð (, ý.) ý. ý ý þ þð ý. position (position ý.) position ý. (position ý.) [ 6] JSTORM <4274>
Java Coding Standard Revision: <1.0> <2000128> ý ý. [ 6] LayeredPane 6.! Í ë æ Ð Í æ. ë (JApplet, JDialog, JFrame, JInternalFrame, JWindow) Ì æ (RootPane) ý. ý GlassPane LayeredPane Ì ý. GlassPane Ì ý. GlassPane Ì ý ý. JInternalFrame GlassPane ý ý ý. LayeredPane ì ý. LayeredPane ì æ (Layer) (Position) ý ý. LayeredPane þ ý. Ì ë getcontentpane() ý ý ì í ý. [Ì 5] [Ì 6] ë Ì ý. Ì (JApplet, JDialog, JFrame, JInternalFrame, JWindow, JRootPane, JLayeredPane) JSTORM <4374>
Java Coding Standard Revision: <1.0> <2000128> API [Ì 2], [Ì 3], [ 1], [ 2], [ 3] æ Ð ý. [ 2] JRootPane (Attribute) Type JMenuBar menubar. null ý. Container contentpane í ì í ý. JLayeredPane layeredpane (Layer) Ð ì þ ý. þ ý. Component glasspane ý. ý. [Ì 4] JLayeredPane [ 3] JLayeredPane JSTORM <4474>
Java Coding Standard Revision: <1.0> <2000128> FRAME_CONTENT_LAYER -3000 ý. í ý. ý ý ì ý. DEFAULT_LAYER 0 ÿ ì ý. í ì ý. PALETTE_LAYER 100 ýû ý. MODAL_LAYER 200 þ ý. þ InternalFrame þ ÿ ý. POPUP_LAYER 300 ý ì. ý. DRAG_LAYER 400 Ì ý. Ì ý ý. [Ì 5] ë JSTORM <4574>
Revision: <1.0> <2000128> [Ì 6] ë Ì (?) ý. Ð æ Ð ý. ý. Ì ý. Ð Ð Ð ý. Ì Ë Ì Ì Ð ý. Ð ÿ Ð ý. Ð Ô ý. ÿ Ð ý. Ú Ð ý. ý Í ý. Action Ð Action Ð Ð ý þ ý. ý. Ì Ð ý. ý. Ì õ ý. û ý Ð ý. Ì ý! ý. Ð Ð ý. Ì Action ý þ. Action javax.swing ý ý. public interface Action extends ActionListener {... Action ActionListener ý. ActionListener Ð Action actionperformed() Ð ý. Action (implement) Action ý. actionperformed() ý. Action actionperformed() Ð (Action) ý. ý Ð ÿ Ð. Ð JSTORM <4674>
Revision: <1.0> <2000128> DocumentSaveAction ý DocumentSaveAction ý ý. public class DocumentSaveAction implements Action {... public void actionperformed(actionevent) {....... [Ì 6] ý Í Ð ý. ö DocumentSaveAction ActionEvent æ ý. DocumentSaveAction actionperformed() Ì ý. actionperformed() Ð í Ì Ð ý. [Ì 6] Action ý. [Ì 6] Action Action "Design Patterns(Erich Gamma ) "Command Pattern" ý. Ì ý Ú ý. Ì Action(Command) Ð ý. Action (Undoable) Ð ý. Ì Í æ Ð ý ý. Ì Ð Ð ý. Ì. [ 7] Action [ 5] Action import java.awt.*; import java.awt.event.*; import javax.swing.*; public class ActionDemo extends JFrame { public ActionDemo() { super("action "); JSTORM <4774>
Revision: <1.0> <2000128> JMenuBar menubar = new JMenuBar(); JToolBar toolbar = new JToolBar();. setjmenubar(menubar); JMenu filemenu = new JMenu(" "); menubar.add(filemenu);. getcontentpane().add(toolbar, BorderLayout.SOUTH); Action. DocumentOpenAction fileopenaction = new DocumentOpenAction(); DocumentSaveAction filesaveaction = new DocumentSaveAction(); Action. filemenu.add(fileopenaction); <------- [1 ] filemenu.add(filesaveaction); <------- [1 ] Action. JButton button; button = toolbar.add(fileopenaction); <------- [2 ] button.settext(null); button = toolbar.add(filesaveaction); <------- [2 ] button.settext(null); setsize(300, 200); setvisible(true); addwindowlistener(new WindowAdapter() { public void windowclosing(windowevent ev) { System.exit(0); ); public static void main(string s[]) { new ActionDemo(); ** * class DocumentOpenAction extends AbstractAction { JSTORM <4874>
Revision: <1.0> <2000128> public DocumentOpenAction() { super(" ", new ImageIcon("DocumentOpen.gif")); public void actionperformed(actionevent e) { JOptionPane.showMessageDialog(null, "."); ** * class DocumentSaveAction extends AbstractAction { public DocumentSaveAction() { super(" ", new ImageIcon("DocumentSave.gif")); public void actionperformed(actionevent e) { JOptionPane.showMessageDialog(null, ".");. setenabled(false); <------- [3 ] [ 5] [1 ] [2 ] Action ý. JMenu JToolBar add() Action ì Ð ý. add() Action JMenuItem JButton ý. Action setenabled() Ð ý. [3 ] setenabled() false ì [ 7] ý. Action Ð AbstractionAction ý. Action ý. DocumentOpenAction DocumentSaveAction Action AbstractAction ý (Override) ý. ì Ì ý. þ Action æ JSTORM <4974>
Revision: <1.0> <2000128> ý. ý. Action ý Ð ý. Ì ý. Ð ý. Action Ð ý ý.? Undoable Ð ý ý. ý ý. [Ì 6] þ ý Ð Action ý. ý Ð ý ý. DocumentSaveAction Ì þ ý. ý. [ 7] Ì (Disabled) ý. ý ý æ ý. DocumentSaveAction æ ý. Ð ý. Ì û? [Ì 6] PropertyChangeEvent ÿ Ð? ActionEvent ÿ Ì ý. Action ý PropertyChangeEvent æ ý. DocumentSaveAction ý PropertyChangeEvent ý. ActionEvent actionperformed() þ PropertyChangeEvent propertychange() þ ý. Í PropertyChangeEvent ý. Action ý. Ð ý. ý VoiceDetector.add(fileSaveAction) ý. ý. Í Í Ì ý. Ð Ð ý Í ý. ý Ð ý. Í Ð ë þ Ð ûý. Ìé Í getcontentpane().add(acomponent); ý. Ì Ì? Ì Í Í ý. JSTORM <5074>
Revision: <1.0> <2000128> ý. Ì Ì Ì Ì? GlassPane ý. GlassPane Ì Ì Ì...? û ý. Ì ý Ð ý. Ì ý. ý. - The End - JSTORM <5174>
Java Coding Standard Revision: <1.0> <2000128> ì ì (Box Ð ) ì (Lightweight Component) ý. Ì ì ì? Ð æ. ì Ì ÿ ì (Heavyweight Component) ý. ì ý ì ý. Ð ý. ý. AWT ý ý. ( AWT ì ì ý.) Ì Í Ì ý([ì 1]). ( ý ì (peer) ý.) API þ ý ý. ì ý. ì ì ý ý. ì ý. ý. ý æ Ì ý([ì 1]). ( ÿ ì ì ý.) [Ì 1] ì ì ì ì [Ì 1] ý. ì ý. Ì þ ý ý. Ì ý JSTORM <5274>
Java Coding Standard Revision: <1.0> <2000128> ý. ì Ì ÿ ý. ì ì Ì Ì æ ûý. Ì ý. [ 1] ì ì Ð ý. [ 1] ì ì ì ì ý ý. ( ý. ì ( ý ý ý.) ý.) Look and Feel ý. ( Look and Feel ý. ( Look and Feel æ ý ý.) ý ý ý. [ 1].) ý. ( : AWT, ý. (Subset) ( Ì ý.) ý Ð ý.) í ý. ( í ý. í ) ( ) ý. ([ 2] ì ý. ì Z-Order ( æ ) ý. ì ý.) [ 1] Look and Feel JSTORM <5374>
Java Coding Standard Revision: <1.0> <2000128> Java Look and Feel MacOS Look and Feel Motif Look and Feel Windows Look and Feel [ 2] ì ý. JSTORM <5474>
Revision: <1.0> <2000128> JSTORM <5574>
Revision: <1.0> <2000128> 7 ì Ì Ë ÿ ý. Ì javax.swing.text(javax.swing.text.html, javax.swing.text.html.parser, javax.swing.text.rtf ) JTextField, JPasswordField, JTextArea, JEditorPane, JTextPane ì Ð ý.([ 1]) ý. [ 1] ì ( ) JTextField ý ý. JPasswordField ý. JTextArea ý ý. ý æ ý ì æ JEditorPane þ ý ý. JTextPane JEditorPane Ð æ ý. ì æ Ì (Icon ) ì ý. ý Ð Ì Ð ý ý Ð Ì ý Ð ûý. ë Ë ü ý. Ð ý Ð ý. ÿ Í Í ý. Ì û ì æ ÿ Ð ý.. þ ì ÿ. Ì Ì ý. Ì ý. 0 9 ý. [ 1] "12345abcde67890" ý. õ ý. õ [ 2] ý. JSTORM <5674>
Java Coding Standard Revision: <1.0> <2000128> [ 1] [ 2] AWT ý Ì ý. AWT ý ü ý. Ì Ì ý ý. 1. Ð Ð ý. 2. Ì ÿ ý. 2 ý Ì txtfield.settext(str); str ÿ ý ý. str ü ý? str ý. Ì ý. Ì ý. [ 3] ý Ð [ 4]ý. [ 5] õ ý. Ð ý. [ 3] Ð JSTORM <5774>
Java Coding Standard Revision: <1.0> <2000128> [ 4] Ð [ 5] Ð [ 1] Ì ý. Ð ý. Ì Í ý. MVC(Model View Controller)ý. Ì ì MVC Ð. [Ì 1] ì JTextComponent ý. (Ì JTextComponent JComponent ý.) JTextComponent ì ý. Ì ÿ MVC Ð ý. [Ì 1] ì (Ì Text Controls, Plain Text Areas, Styled Text Areas....) JSTORM <5874>
Java Coding Standard Revision: <1.0> <2000128> [Ì 2] ì æ (MVC) Ì ý. ì Ì æ ý. MVC ý. Ì Ì Delegate View ý ý. Delegate View Controller (ý ì Ì ý.) ì Ð View ý. ý Í Ì ý. Ì View ý. (MVC ÿ ý û ý Ð MVC ÿ Ú Ð ý.) [Ì 2] ì (Framework) ý Ð. MVC Ì ý. [ 1] æ WholeNumberDocument ý. ( ì Model Document ý.) ý PlainDocument PlainDocument ý AbstractDocument AbstractDocument Document (implements) ý. ý. Ì Ð ì Document ý ý. WholeNumberDocument Document ý ý. PlainDocument는동일한속성의문자들로만이루어진텍스트컴포넌트 (JTextField, JPasswordField, JTextArea) 모델의기본적인내용들을구현하고있다. 따라서자신이직접모델을수정하고싶을때는 PlainDocument 클래스를상속하는자신만의모델클래스를정의한다음필요한메쏘드만오버라이드하는방식을택하면된다. JSTORM <5974>
Java Coding Standard Revision: <1.0> <2000128> [ 1] 1. createdefaultmodel() JTextField ý. (WholeNumberDocument) WholeNumberDocument ý. ý ý PlainDocument ý. ý. 2 insertstring() ì ý. offset ý. ì Ð [Ì 3] æ ý. æ offset ý. offset 0 ý. [Ì 3] Offset æ æý. ý str attrset ý. ý Ð attrset AttributeSet ý. AttributeSet ÍÚ Í, þ ý. Ð ý. insertstring() BadLocationException (Exception)ý. (throw) ý. offset ý û ì ý ý. BadLocationException ì. Ð ý. [ 1] import javax.swing.*; import javax.swing.text.*; ** * public class WholeNumberField extends JTextField { public WholeNumberField() { JSTORM <6074>
Revision: <1.0> <2000128> super(); public WholeNumberField(int columns) { super(columns); ** * protected Document createdefaultmodel() { <----- 1 return new WholeNumberDocument(); ** * protected class WholeNumberDocument extends PlainDocument { public void insertstring(int offset, String str, <----- 2 AttributeSet attrset) throws BadLocationException { char[] source = str.tochararray(); char[] result = new char[source.length]; int j = 0;. for (int i = 0; i < result.length; i++) { if (Character.isDigit(source[i])) result[j++] = source[i]; else { System.err.println(" : " + source[i]);. super.insertstring(offset, new String(result, 0, j), attrset); public static void main(string[] args) { JFrame frame = new JFrame("WholeNumberField Demo"); WholeNumberField field = new WholeNumberField(20); frame.getcontentpane().add(field); JSTORM <6174>
Revision: <1.0> <2000128> frame.pack(); frame.setvisible(true); Ì Í æ. 텍스트필드는모델의 insertstring() 메쏘드를통해외부로부터문자열을받아들인다. 따라서이곳에필터링장치를설치해놓으면텍스트필드가원하는방식으로작동하도록할수있다. ì ý. JTextField JTextArea ì ì ý. EditorKit? ì (Controller) (Editor Kit) ý. Ð Ð ý. Ð Action Ð ý. (Action ÿ Ð 5 û Ð ý.) ý Ð Ð Action ý. 5 Ð ý Ì Ð Action þ ý. Ì û ý. ý ý. ý ý ý. HTML ý ý ý. ý. ý ý. [Ì 4] ý. DefaultEditorKit ý StyledEditorKit ý ÍÚ Ì ý ý. StyledEditorKit JTextPane Ð Ð ý. HTMLEditorKit RTFEditorKit ý StyledEditorKit HTML RTF ý ý. [Ì 1] JEditorPane ý Ô ý. JEditorPane Ì ý Ì ÿ JSTORM <6274>
Java Coding Standard Revision: <1.0> <2000128> þ ý. ý Ì ý registereditorkitforcontenttype() JEditorPane ý. Ì ý ý. [Ì 4] EditorKit Ì Í ý HTML Viewer. ý Ð Ð Hyper Link Ð ý. Ì ë ý ([ 2]) ë ý. ý JEditorPane URL ì ý. ([ 6]) Ì Ð ý. JEditorPane ý. setpage(string url) Ì ý. setpage() URL URL ý. JEditorPane ý setpage() ý. setpage() URL þ ý Ì ý. HTML Viewer HTMLEditorKit ý. [ 2] ý HTML Viewer import java.io.*; import javax.swing.*; public class HTMLExample { public static void main(string[] args) { JEditorPane pane = null; String url = "http:java.sun.comindex.html"; try { pane = new JEditorPane(url); JSTORM <6374>
Java Coding Standard Revision: <1.0> <2000128> catch (IOException ex) { pane.seteditable(false); JFrame frame = new JFrame("HTML Page Viewer V1.0 ^^"); frame.setcontentpane(new JScrollPane(pane)); frame.setsize(600, 400); frame.setvisible(true); [ 6] HTML Viewer. Í Í Í ý. Ì Ð ý. Ð API ë ý. Ì Ì Ì Ì ÿ (?) ý. Ð (?) Ì ý. Ì Ì ÿ. [ 7] Ì ý. þ Ì û Ì Ì ý. [ 7] û JSTORM <6474>
Java Coding Standard Revision: <1.0> <2000128> Ì (Style) ý. Í ý ý. ý ( ) Í ý. ý ý ÍÚ ý Í (Attribute) ý. Style ý ý. Style MutableAttributeSet MutableAttributeSet ý AttributeSet ý. ([Ì 5]) Ð ý ý Ð ý. StyleConstants static ý. StyleConstants ý. StyleConstants.setFontSize(style, int size) ý. style ÍÚ Ð size ý. ý ý StyleConstants.getFontSize(style) style Í Ú Ð ý. [Ì 5] JSTORM <6574>
Java Coding Standard Revision: <1.0> <2000128> [ 8] (Attribute) ÿ ý. ÿ [ 3] fillstyle() loadfromstyle() Ð ý. ÿ æ (,, ) ý. [ 3] Ð ** * public class StyleEditor extends Container {... ** * private JComboBox sizecombo;... ** (Attribute). * public void fillstyle(style style) {... String size = (String)sizeCombo.getSelectedItem(); StyleConstants.setFontSize(style, Integer.parseInt(size));... ** (Attribute). * public void loadfromstyle(style style) {... int size = StyleConstants.getFontSize(style); sizecombo.setselecteditem(integer.tostring(size));...... [ 8] Ð ÿ JSTORM <6674>
Java Coding Standard Revision: <1.0> <2000128> ý ý ý. [ 4] ý. ÿ Ð Í Ð æ Í ý. þ ý ý. ý DefaultStyledDocument ý. Ì DefaultStyledDocument ÿ. ý ý. public class DefaultStyledDocument extends AbstractDocument implements StyledDocument AbstractDocument ý. Ì AbstractDocument ÿ Ð Í ý. ý ÿ Ð ý. ý StyledDocument ý. StyledDocument ý ý. Ú ì ý. (Element) (piece) ý. ý Í ý. ý,, ý Ì ý. Ì ì ý ý. ([Ì 6]) ý Ì ý ý. ý ý. [Ì 6] JSTORM <6774>
Revision: <1.0> <2000128> ý ý ý Ð ý. ý ÍÚ Ð 24 ý Ì ý ý ý. Ì ý ý. Ì Ì Ó Ì ý. Ì Ì ý ý. Ì ý Í ý ý Í ý Ð ý. ì ý ý. Ì Í. [ 4] 1 ý. æð ý. [ 7] ÿ ( ý) 128 ý. Ì 128 ÍÚ 24 ßý. Ì 128 æ ý. ý. þ ý. 2 styleupdated() updatestylehash() ÿ ý. [ 4] ** * (Document). * (Element) *. * public class StylishDocument extends DefaultStyledDocument implements DocumentListener { **. * private Hashtable stylehash = new Hashtable(); <--- 1 JSTORM <6874>
Revision: <1.0> <2000128>... ** * public StylishDocument() { super(); init(); ** *. * Paragraph *. * protected void init() { adddocumentlistener(this); addtostylehash(getparagraphelement(0)); ** * *. * public void styleupdated(style style) { <--- 2. Hashtable ht = (Hashtable)styleHash.get(style); if (ht!= null) { Vector cleanup = new Vector(); Enumeration e = ht.keys(); while (e.hasmoreelements()) { Element el = (Element)e.nextElement(); int start = el.getstartoffset(); int end = el.getendoffset(); Style check = getlogicalstyle(start); if (check == style) { DefaultDocumentEvent ev = new DefaultDocumentEvent (start, end-start, DocumentEvent.EventType.CHANGE); firechangedupdate(ev); else { cleanup.addelement(el); JSTORM <6974>
Revision: <1.0> <2000128> e = cleanup.elements(); while (e.hasmoreelements()) { Element bad = (Element)e.nextElement(); ht.remove(bad); DocumentListener public void insertupdate(documentevent ev) { updatestylehash(ev); public void removeupdate(documentevent ev) { updatestylehash(ev); public void changedupdate(documentevent ev) { int offset = ev.getoffset(); Element para = getparagraphelement(offset); addtostylehash(para); **. * protected void updatestylehash(documentevent ev) { <- -- 2 DocumentEvent.ElementChange chg = ev.getchange(getdefaultrootelement()); if (chg!= null) { Element[] removed = chg.getchildrenremoved(); for (int i=0; i<removed.length; i++) { removefromstylehash(removed[i]); Element[] added = chg.getchildrenadded(); for (int i=0;i<added.length;i++) { addtostylehash(added[i]); **. * protected void addtostylehash(element para) { AttributeSet attrs = para.getattributes(); if (attrs!= null) { Style style = (Style)attrs.getResolveParent(); if (style!= null) { JSTORM <7074>
Revision: <1.0> <2000128> Hashtable ht = (Hashtable)styleHash.get(style); if (ht == null) { ht = new Hashtable(); stylehash.put(style, ht); if (ht.containskey(para) == false) { ht.put(para, new Object()); **. * protected void removefromstylehash(element para) { AttributeSet attrs = para.getattributes(); if (attrs!= null) { Style style = (Style)attrs.getResolveParent(); if (style!= null) { Hashtable ht = (Hashtable)styleHash.get(style); if (ht!= null) { ht.remove(para); [ 5] ** JTextPane. * public class StyleDemo extends JFrame { private StyleEditor styleeditor = new StyleEditor(); private JTextPane textpane; private StylishDocument doc; private JMenu stylemenu; private JMenu setstylemenu; private JMenu modifystylemenu; private Hashtable stylehash = new Hashtable(); public static void main(string[] args) { JFrame frame = new StyleDemo(); frame.setvisible(true); ** JTextPane. * public StyleDemo() { super(" "); doc = new StylishDocument(); JSTORM <7174>
Revision: <1.0> <2000128> textpane = new JTextPane(doc); setcontentpane(new JScrollPane(textPane)); JMenuBar menubar = createmenubar(); setjmenubar(menubar); setsize(800, 600); **. * protected JMenuBar createmenubar() { JMenuBar bar = new JMenuBar(); JMenu filemenu = new JMenu(" "); JMenuItem exititem = new JMenuItem(" "); exititem.addactionlistener(new ActionListener() { public void actionperformed(actionevent ev) { System.exit(0); ); filemenu.add(exititem); bar.add(filemenu); stylemenu = new JMenu(" "); JMenuItem createitem = new JMenuItem(" "); createitem.addactionlistener(new ActionListener() { public void actionperformed(actionevent ev) { showstyledialog(); ); setstylemenu = new JMenu(" "); modifystylemenu = new JMenu(" "); stylemenu.add(createitem); stylemenu.add(setstylemenu); stylemenu.add(modifystylemenu); bar.add(stylemenu); <--- 1 addstyletomenus(doc.getstyle(stylecontext.default_style)); return bar; **. * protected void showstyledialog() { JSTORM <7274>
Revision: <1.0> <2000128> String[] options = {" ", " "; int opt = JOptionPane.showOptionDialog(this, styleeditor, " ", JOptionPane.DEFAULT_OPTION, JOptionPane.PLAIN_MESSAGE, null, options, options[0]); if (opt == 0) { "OK" pressed String name = styleeditor.getstylename(); if (name!= null) { Style oldstyle = doc.getstyle(name); if (oldstyle!= null) { styleeditor.fillstyle(oldstyle); doc.styleupdated(oldstyle); else { Style newstyle = doc.addstyle(name, null); styleeditor.fillstyle(newstyle); addstyletomenus(newstyle); styleeditor.clear(); **. * protected void addstyletomenus(final Style newstyle) { String stylename = newstyle.getname(); JMenuItem newitem = new JMenuItem(styleName); setstylemenu.add(newitem); newitem.addactionlistener(new ActionListener() { public void actionperformed(actionevent ev) { textpane.setlogicalstyle(newstyle); <--- 2 ); newitem = new JMenuItem(styleName); modifystylemenu.add(newitem); newitem.addactionlistener(new ActionListener() { public void actionperformed(actionevent ev) { styleeditor.loadfromstyle(newstyle); showstyledialog(); ); JSTORM <7374>
Revision: <1.0> <2000128> Ì ([ 5]) ÿ æ ý. JTextPane (1 ) Ð ÿ Ì JTextPane ý. 2 ý. JTextPane setlogicalstyle() (Caret) ý. ì ÿ ý ý ý. þ JDK API javax.swing.text ý Ð ý. ý Ì æ (Inner Class) ý. û Í ý ý. ý. Ð ý æ í æ ý. Ì ý. Í ý. Ì Ì û ý. Ì Ð ý. ÿ Ð ý. í : http:java.sun.comproductsjfctsctexttext_main.html : http:java.sun.comdocsbookstutorialuiswingcomponentstext.html JSTORM <7474>