Component.java 142 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971
  1. /* Component.java -- a graphics component
  2. Copyright (C) 1999, 2000, 2001, 2002, 2003 Free Software Foundation
  3. This file is part of GNU Classpath.
  4. GNU Classpath is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2, or (at your option)
  7. any later version.
  8. GNU Classpath is distributed in the hope that it will be useful, but
  9. WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with GNU Classpath; see the file COPYING. If not, write to the
  14. Free Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  15. 02111-1307 USA.
  16. Linking this library statically or dynamically with other modules is
  17. making a combined work based on this library. Thus, the terms and
  18. conditions of the GNU General Public License cover the whole
  19. combination.
  20. As a special exception, the copyright holders of this library give you
  21. permission to link this library with independent modules to produce an
  22. executable, regardless of the license terms of these independent
  23. modules, and to copy and distribute the resulting executable under
  24. terms of your choice, provided that you also meet, for each linked
  25. independent module, the terms and conditions of the license of that
  26. module. An independent module is a module which is not derived from
  27. or based on this library. If you modify this library, you may extend
  28. this exception to your version of the library, but you are not
  29. obligated to do so. If you do not wish to do so, delete this
  30. exception statement from your version. */
  31. package java.awt;
  32. import java.awt.dnd.DropTarget;
  33. import java.awt.event.ComponentEvent;
  34. import java.awt.event.ComponentListener;
  35. import java.awt.event.FocusEvent;
  36. import java.awt.event.FocusListener;
  37. import java.awt.event.HierarchyBoundsListener;
  38. import java.awt.event.HierarchyEvent;
  39. import java.awt.event.HierarchyListener;
  40. import java.awt.event.KeyEvent;
  41. import java.awt.event.KeyListener;
  42. import java.awt.event.InputMethodEvent;
  43. import java.awt.event.InputMethodListener;
  44. import java.awt.event.MouseEvent;
  45. import java.awt.event.MouseListener;
  46. import java.awt.event.MouseMotionListener;
  47. import java.awt.event.MouseWheelListener;
  48. import java.awt.event.MouseWheelEvent;
  49. import java.awt.event.PaintEvent;
  50. import java.awt.im.InputContext;
  51. import java.awt.im.InputMethodRequests;
  52. import java.awt.image.BufferStrategy;
  53. import java.awt.image.ColorModel;
  54. import java.awt.image.ImageObserver;
  55. import java.awt.image.ImageProducer;
  56. import java.awt.image.VolatileImage;
  57. import java.awt.peer.ComponentPeer;
  58. import java.awt.peer.LightweightPeer;
  59. import java.beans.PropertyChangeListener;
  60. import java.beans.PropertyChangeSupport;
  61. import java.io.ObjectInputStream;
  62. import java.io.IOException;
  63. import java.io.ObjectOutputStream;
  64. import java.io.PrintStream;
  65. import java.io.PrintWriter;
  66. import java.io.Serializable;
  67. import java.lang.reflect.Array;
  68. import java.util.Collections;
  69. import java.util.EventListener;
  70. import java.util.HashSet;
  71. import java.util.Iterator;
  72. import java.util.Locale;
  73. import java.util.Set;
  74. import java.util.Vector;
  75. import javax.accessibility.Accessible;
  76. import javax.accessibility.AccessibleComponent;
  77. import javax.accessibility.AccessibleContext;
  78. import javax.accessibility.AccessibleRole;
  79. import javax.accessibility.AccessibleState;
  80. import javax.accessibility.AccessibleStateSet;
  81. /**
  82. * The root of all evil. All graphical representations are subclasses of this
  83. * giant class, which is designed for screen display and user interaction.
  84. * This class can be extended directly to build a lightweight component (one
  85. * not associated with a native window); lightweight components must reside
  86. * inside a heavyweight window.
  87. *
  88. * <p>This class is Serializable, which has some big implications. A user can
  89. * save the state of all graphical components in one VM, and reload them in
  90. * another. Note that this class will only save Serializable listeners, and
  91. * ignore the rest, without causing any serialization exceptions. However, by
  92. * making a listener serializable, and adding it to another element, you link
  93. * in that entire element to the state of this component. To get around this,
  94. * use the idiom shown in the example below - make listeners non-serializable
  95. * in inner classes, rather than using this object itself as the listener, if
  96. * external objects do not need to save the state of this object.
  97. *
  98. * <p><pre>
  99. * import java.awt.*;
  100. * import java.awt.event.*;
  101. * import java.io.Serializable;
  102. * class MyApp implements Serializable
  103. * {
  104. * BigObjectThatShouldNotBeSerializedWithAButton bigOne;
  105. * // Serializing aButton will not suck in an instance of MyApp, with its
  106. * // accompanying field bigOne.
  107. * Button aButton = new Button();
  108. * class MyActionListener implements ActionListener
  109. * {
  110. * public void actionPerformed(ActionEvent e)
  111. * {
  112. * System.out.println("Hello There");
  113. * }
  114. * }
  115. * MyApp()
  116. * {
  117. * aButton.addActionListener(new MyActionListener());
  118. * }
  119. * }
  120. *
  121. * <p>Status: Incomplete. The event dispatch mechanism is implemented. All
  122. * other methods defined in the J2SE 1.3 API javadoc exist, but are mostly
  123. * incomplete or only stubs; except for methods relating to the Drag and
  124. * Drop, Input Method, and Accessibility frameworks: These methods are
  125. * present but commented out.
  126. *
  127. * @author original author unknown
  128. * @author Eric Blake <ebb9@email.byu.edu>
  129. * @since 1.0
  130. * @status still missing 1.4 support
  131. */
  132. public abstract class Component
  133. implements ImageObserver, MenuContainer, Serializable
  134. {
  135. // Word to the wise - this file is huge. Search for '\f' (^L) for logical
  136. // sectioning by fields, public API, private API, and nested classes.
  137. /**
  138. * Compatible with JDK 1.0+.
  139. */
  140. private static final long serialVersionUID = -7644114512714619750L;
  141. /**
  142. * Constant returned by the <code>getAlignmentY</code> method to indicate
  143. * that the component wishes to be aligned to the top relative to
  144. * other components.
  145. *
  146. * @see #getAlignmentY()
  147. */
  148. public static final float TOP_ALIGNMENT = 0;
  149. /**
  150. * Constant returned by the <code>getAlignmentY</code> and
  151. * <code>getAlignmentX</code> methods to indicate
  152. * that the component wishes to be aligned to the center relative to
  153. * other components.
  154. *
  155. * @see #getAlignmentX()
  156. * @see #getAlignmentY()
  157. */
  158. public static final float CENTER_ALIGNMENT = 0.5f;
  159. /**
  160. * Constant returned by the <code>getAlignmentY</code> method to indicate
  161. * that the component wishes to be aligned to the bottom relative to
  162. * other components.
  163. *
  164. * @see #getAlignmentY()
  165. */
  166. public static final float BOTTOM_ALIGNMENT = 1;
  167. /**
  168. * Constant returned by the <code>getAlignmentX</code> method to indicate
  169. * that the component wishes to be aligned to the right relative to
  170. * other components.
  171. *
  172. * @see #getAlignmentX()
  173. */
  174. public static final float RIGHT_ALIGNMENT = 1;
  175. /**
  176. * Constant returned by the <code>getAlignmentX</code> method to indicate
  177. * that the component wishes to be aligned to the left relative to
  178. * other components.
  179. *
  180. * @see #getAlignmentX()
  181. */
  182. public static final float LEFT_ALIGNMENT = 0;
  183. /**
  184. * Make the treelock a String so that it can easily be identified
  185. * in debug dumps. We clone the String in order to avoid a conflict in
  186. * the unlikely event that some other package uses exactly the same string
  187. * as a lock object.
  188. */
  189. static final Object treeLock = new String("AWT_TREE_LOCK");
  190. // Serialized fields from the serialization spec.
  191. /**
  192. * The x position of the component in the parent's coordinate system.
  193. *
  194. * @see #getLocation()
  195. * @serial the x position
  196. */
  197. int x;
  198. /**
  199. * The y position of the component in the parent's coordinate system.
  200. *
  201. * @see #getLocation()
  202. * @serial the y position
  203. */
  204. int y;
  205. /**
  206. * The component width.
  207. *
  208. * @see #getSize()
  209. * @serial the width
  210. */
  211. int width;
  212. /**
  213. * The component height.
  214. *
  215. * @see #getSize()
  216. * @serial the height
  217. */
  218. int height;
  219. /**
  220. * The foreground color for the component. This may be null.
  221. *
  222. * @see #getForeground()
  223. * @see #setForeground(Color)
  224. * @serial the foreground color
  225. */
  226. Color foreground;
  227. /**
  228. * The background color for the component. This may be null.
  229. *
  230. * @see #getBackground()
  231. * @see #setBackground(Color)
  232. * @serial the background color
  233. */
  234. Color background;
  235. /**
  236. * The default font used in the component. This may be null.
  237. *
  238. * @see #getFont()
  239. * @see #setFont(Font)
  240. * @serial the font
  241. */
  242. Font font;
  243. /**
  244. * The font in use by the peer, or null if there is no peer.
  245. *
  246. * @serial the peer's font
  247. */
  248. Font peerFont;
  249. /**
  250. * The cursor displayed when the pointer is over this component. This may
  251. * be null.
  252. *
  253. * @see #getCursor()
  254. * @see #setCursor(Cursor)
  255. */
  256. Cursor cursor;
  257. /**
  258. * The locale for the component.
  259. *
  260. * @see #getLocale()
  261. * @see #setLocale(Locale)
  262. */
  263. Locale locale;
  264. /**
  265. * True if the object should ignore repaint events (usually because it is
  266. * not showing).
  267. *
  268. * @see #getIgnoreRepaint()
  269. * @see #setIgnoreRepaint(boolean)
  270. * @serial true to ignore repaints
  271. * @since 1.4
  272. */
  273. boolean ignoreRepaint;
  274. /**
  275. * True when the object is visible (although it is only showing if all
  276. * ancestors are likewise visible). For component, this defaults to true.
  277. *
  278. * @see #isVisible()
  279. * @see #setVisible(boolean)
  280. * @serial true if visible
  281. */
  282. boolean visible = true;
  283. /**
  284. * True if the object is enabled, meaning it can interact with the user.
  285. * For component, this defaults to true.
  286. *
  287. * @see #isEnabled()
  288. * @see #setEnabled(boolean)
  289. * @serial true if enabled
  290. */
  291. boolean enabled = true;
  292. /**
  293. * True if the object is valid. This is set to false any time a size
  294. * adjustment means the component need to be layed out again.
  295. *
  296. * @see #isValid()
  297. * @see #validate()
  298. * @see #invalidate()
  299. * @serial true if layout is valid
  300. */
  301. boolean valid;
  302. /**
  303. * The DropTarget for drag-and-drop operations.
  304. *
  305. * @see #getDropTarget()
  306. * @see #setDropTarget(DropTarget)
  307. * @serial the drop target, or null
  308. * @since 1.2
  309. */
  310. DropTarget dropTarget;
  311. /**
  312. * The list of popup menus for this component.
  313. *
  314. * @see #add(PopupMenu)
  315. * @serial the list of popups
  316. */
  317. Vector popups;
  318. /**
  319. * The component's name. May be null, in which case a default name is
  320. * generated on the first use.
  321. *
  322. * @see #getName()
  323. * @see #setName(String)
  324. * @serial the name
  325. */
  326. String name;
  327. /**
  328. * True once the user has set the name. Note that the user may set the name
  329. * to null.
  330. *
  331. * @see #name
  332. * @see #getName()
  333. * @see #setName(String)
  334. * @serial true if the name has been explicitly set
  335. */
  336. boolean nameExplicitlySet;
  337. /**
  338. * Indicates if the object can be focused. Defaults to true for components.
  339. *
  340. * @see #isFocusable()
  341. * @see #setFocusable(boolean)
  342. * @since 1.4
  343. */
  344. boolean focusable = true;
  345. /**
  346. * Tracks whether this component uses default focus traversal, or has a
  347. * different policy.
  348. *
  349. * @see #isFocusTraversableOverridden()
  350. * @since 1.4
  351. */
  352. int isFocusTraversableOverridden;
  353. /**
  354. * The focus traversal keys, if not inherited from the parent or default
  355. * keyboard manager. These sets will contain only AWTKeyStrokes that
  356. * represent press and release events to use as focus control.
  357. *
  358. * @see #getFocusTraversalKeys(int)
  359. * @see #setFocusTraversalKeys(int, Set)
  360. * @since 1.4
  361. */
  362. Set[] focusTraversalKeys;
  363. /**
  364. * True if focus traversal keys are enabled. This defaults to true for
  365. * Component. If this is true, keystrokes in focusTraversalKeys are trapped
  366. * and processed automatically rather than being passed on to the component.
  367. *
  368. * @see #getFocusTraversalKeysEnabled()
  369. * @see #setFocusTraversalKeysEnabled(boolean)
  370. * @since 1.4
  371. */
  372. boolean focusTraversalKeysEnabled = true;
  373. /**
  374. * Cached information on the minimum size. Should have been transient.
  375. *
  376. * @serial ignore
  377. */
  378. Dimension minSize;
  379. /**
  380. * Cached information on the preferred size. Should have been transient.
  381. *
  382. * @serial ignore
  383. */
  384. Dimension prefSize;
  385. /**
  386. * Set to true if an event is to be handled by this component, false if
  387. * it is to be passed up the hierarcy.
  388. *
  389. * @see #dispatchEvent(AWTEvent)
  390. * @serial true to process event locally
  391. */
  392. boolean newEventsOnly;
  393. /**
  394. * Set by subclasses to enable event handling of particular events, and
  395. * left alone when modifying listeners. For component, this defaults to
  396. * enabling only input methods.
  397. *
  398. * @see #enableInputMethods(boolean)
  399. * @see AWTEvent
  400. * @serial the mask of events to process
  401. */
  402. long eventMask = AWTEvent.INPUT_ENABLED_EVENT_MASK;
  403. /**
  404. * Describes all registered PropertyChangeListeners.
  405. *
  406. * @see #addPropertyChangeListener(PropertyChangeListener)
  407. * @see #removePropertyChangeListener(PropertyChangeListener)
  408. * @see #firePropertyChange(String, Object, Object)
  409. * @serial the property change listeners
  410. * @since 1.2
  411. */
  412. PropertyChangeSupport changeSupport;
  413. /**
  414. * True if the component has been packed (layed out).
  415. *
  416. * @serial true if this is packed
  417. */
  418. boolean isPacked;
  419. /**
  420. * The serialization version for this class. Currently at version 4.
  421. *
  422. * XXX How do we handle prior versions?
  423. *
  424. * @serial the serialization version
  425. */
  426. int componentSerializedDataVersion = 4;
  427. /**
  428. * The accessible context associated with this component. This is only set
  429. * by subclasses.
  430. *
  431. * @see #getAccessibleContext()
  432. * @serial the accessibility context
  433. * @since 1.2
  434. */
  435. AccessibleContext accessibleContext;
  436. // Guess what - listeners are special cased in serialization. See
  437. // readObject and writeObject.
  438. /** Component listener chain. */
  439. transient ComponentListener componentListener;
  440. /** Focus listener chain. */
  441. transient FocusListener focusListener;
  442. /** Key listener chain. */
  443. transient KeyListener keyListener;
  444. /** Mouse listener chain. */
  445. transient MouseListener mouseListener;
  446. /** Mouse motion listener chain. */
  447. transient MouseMotionListener mouseMotionListener;
  448. /**
  449. * Mouse wheel listener chain.
  450. *
  451. * @since 1.4
  452. */
  453. transient MouseWheelListener mouseWheelListener;
  454. /**
  455. * Input method listener chain.
  456. *
  457. * @since 1.2
  458. */
  459. transient InputMethodListener inputMethodListener;
  460. /**
  461. * Hierarcy listener chain.
  462. *
  463. * @since 1.3
  464. */
  465. transient HierarchyListener hierarchyListener;
  466. /**
  467. * Hierarcy bounds listener chain.
  468. *
  469. * @since 1.3
  470. */
  471. transient HierarchyBoundsListener hierarchyBoundsListener;
  472. // Anything else is non-serializable, and should be declared "transient".
  473. /** The parent. */
  474. transient Container parent;
  475. /** The associated native peer. */
  476. transient ComponentPeer peer;
  477. /** The preferred component orientation. */
  478. transient ComponentOrientation orientation = ComponentOrientation.UNKNOWN;
  479. /**
  480. * The associated graphics configuration.
  481. *
  482. * @since 1.4
  483. */
  484. transient GraphicsConfiguration graphicsConfig;
  485. /**
  486. * The buffer strategy for repainting.
  487. *
  488. * @since 1.4
  489. */
  490. transient BufferStrategy bufferStrategy;
  491. // Public and protected API.
  492. /**
  493. * Default constructor for subclasses. When Component is extended directly,
  494. * it forms a lightweight component that must be hosted in an opaque native
  495. * container higher in the tree.
  496. */
  497. protected Component()
  498. {
  499. }
  500. /**
  501. * Returns the name of this component.
  502. *
  503. * @return the name of this component
  504. * @see #setName(String)
  505. * @since 1.1
  506. */
  507. public String getName()
  508. {
  509. if (name == null && ! nameExplicitlySet)
  510. name = generateName();
  511. return name;
  512. }
  513. /**
  514. * Sets the name of this component to the specified name.
  515. *
  516. * @param name the new name of this component
  517. * @see #getName()
  518. * @since 1.1
  519. */
  520. public void setName(String name)
  521. {
  522. nameExplicitlySet = true;
  523. this.name = name;
  524. }
  525. /**
  526. * Returns the parent of this component.
  527. *
  528. * @return the parent of this component
  529. */
  530. public Container getParent()
  531. {
  532. return parent;
  533. }
  534. /**
  535. * Returns the native windowing system peer for this component. Only the
  536. * platform specific implementation code should call this method.
  537. *
  538. * @return the peer for this component
  539. * @deprecated user programs should not directly manipulate peers; use
  540. * {@link #isDisplayable()} instead
  541. */
  542. // Classpath's Gtk peers rely on this.
  543. public ComponentPeer getPeer()
  544. {
  545. return peer;
  546. }
  547. /**
  548. * Set the associated drag-and-drop target, which receives events when this
  549. * is enabled.
  550. *
  551. * @param dt the new drop target
  552. * @see #isEnabled()
  553. */
  554. public void setDropTarget(DropTarget dt)
  555. {
  556. this.dropTarget = dt;
  557. }
  558. /**
  559. * Gets the associated drag-and-drop target, if there is one.
  560. *
  561. * @return the drop target
  562. */
  563. public DropTarget getDropTarget()
  564. {
  565. return dropTarget;
  566. }
  567. /**
  568. * Returns the graphics configuration of this component, if there is one.
  569. * If it has not been set, it is inherited from the parent.
  570. *
  571. * @return the graphics configuration, or null
  572. * @since 1.3
  573. */
  574. public GraphicsConfiguration getGraphicsConfiguration()
  575. {
  576. return getGraphicsConfigurationImpl();
  577. }
  578. /**
  579. * Returns the object used for synchronization locks on this component
  580. * when performing tree and layout functions.
  581. *
  582. * @return the synchronization lock for this component
  583. */
  584. public final Object getTreeLock()
  585. {
  586. return treeLock;
  587. }
  588. /**
  589. * Returns the toolkit in use for this component. The toolkit is associated
  590. * with the frame this component belongs to.
  591. *
  592. * @return the toolkit for this component
  593. */
  594. public Toolkit getToolkit()
  595. {
  596. if (peer != null)
  597. {
  598. Toolkit tk = peer.getToolkit();
  599. if (tk != null)
  600. return tk;
  601. }
  602. if (parent != null)
  603. return parent.getToolkit();
  604. return Toolkit.getDefaultToolkit();
  605. }
  606. /**
  607. * Tests whether or not this component is valid. A invalid component needs
  608. * to have its layout redone.
  609. *
  610. * @return true if this component is valid
  611. * @see #validate()
  612. * @see #invalidate()
  613. */
  614. public boolean isValid()
  615. {
  616. return valid;
  617. }
  618. /**
  619. * Tests if the component is displayable. It must be connected to a native
  620. * screen resource, and all its ancestors must be displayable. A containment
  621. * hierarchy is made displayable when a window is packed or made visible.
  622. *
  623. * @return true if the component is displayable
  624. * @see Container#add(Component)
  625. * @see Container#remove(Component)
  626. * @see Window#pack()
  627. * @see Window#show()
  628. * @see Window#dispose()
  629. * @since 1.2
  630. */
  631. public boolean isDisplayable()
  632. {
  633. if (parent != null)
  634. return parent.isDisplayable();
  635. return false;
  636. }
  637. /**
  638. * Tests whether or not this component is visible. Except for top-level
  639. * frames, components are initially visible.
  640. *
  641. * @return true if the component is visible
  642. * @see #setVisible(boolean)
  643. */
  644. public boolean isVisible()
  645. {
  646. return visible;
  647. }
  648. /**
  649. * Tests whether or not this component is actually being shown on
  650. * the screen. This will be true if and only if it this component is
  651. * visible and its parent components are all visible.
  652. *
  653. * @return true if the component is showing on the screen
  654. * @see #setVisible(boolean)
  655. */
  656. public boolean isShowing()
  657. {
  658. if (! visible || peer == null)
  659. return false;
  660. return parent == null ? true : parent.isShowing();
  661. }
  662. /**
  663. * Tests whether or not this component is enabled. Components are enabled
  664. * by default, and must be enabled to receive user input or generate events.
  665. *
  666. * @return true if the component is enabled
  667. * @see #setEnabled(boolean)
  668. */
  669. public boolean isEnabled()
  670. {
  671. return enabled;
  672. }
  673. /**
  674. * Enables or disables this component. The component must be enabled to
  675. * receive events (except that lightweight components always receive mouse
  676. * events).
  677. *
  678. * @param enabled true to enable this component
  679. * @see #isEnabled()
  680. * @see #isLightweight()
  681. * @since 1.1
  682. */
  683. public void setEnabled(boolean b)
  684. {
  685. this.enabled = b;
  686. if (peer != null)
  687. peer.setEnabled(b);
  688. }
  689. /**
  690. * Enables this component.
  691. *
  692. * @deprecated use {@link #setEnabled(boolean)} instead
  693. */
  694. public void enable()
  695. {
  696. setEnabled(true);
  697. }
  698. /**
  699. * Enables or disables this component.
  700. *
  701. * @param enabled true to enable this component
  702. * @deprecated use {@link #setEnabled(boolean)} instead
  703. */
  704. public void enable(boolean b)
  705. {
  706. setEnabled(b);
  707. }
  708. /**
  709. * Disables this component.
  710. *
  711. * @deprecated use {@link #setEnabled(boolean)} instead
  712. */
  713. public void disable()
  714. {
  715. setEnabled(false);
  716. }
  717. /**
  718. * Checks if this image is painted to an offscreen image buffer that is
  719. * later copied to screen (double buffering reduces flicker). This version
  720. * returns false, so subclasses must override it if they provide double
  721. * buffering.
  722. *
  723. * @return true if this is double buffered; defaults to false
  724. */
  725. public boolean isDoubleBuffered()
  726. {
  727. return false;
  728. }
  729. /**
  730. * Enables or disables input method support for this component. By default,
  731. * components have this enabled. Input methods are given the opportunity
  732. * to process key events before this component and its listeners.
  733. *
  734. * @param enable true to enable input method processing
  735. * @see #processKeyEvent(KeyEvent)
  736. * @since 1.2
  737. */
  738. public void enableInputMethods(boolean enable)
  739. {
  740. // XXX Implement.
  741. throw new Error("not implemented");
  742. }
  743. /**
  744. * Makes this component visible or invisible. Note that it wtill might
  745. * not show the component, if a parent is invisible.
  746. *
  747. * @param visible true to make this component visible
  748. * @see #isVisible()
  749. * @since 1.1
  750. */
  751. public void setVisible(boolean b)
  752. {
  753. // Inspection by subclassing shows that Sun's implementation calls
  754. // show(boolean) which then calls show() or hide(). It is the show()
  755. // method that is overriden in subclasses like Window.
  756. if (peer != null)
  757. peer.setVisible(b);
  758. this.visible = b;
  759. }
  760. /**
  761. * Makes this component visible on the screen.
  762. *
  763. * @deprecated use {@link #setVisible(boolean)} instead
  764. */
  765. public void show()
  766. {
  767. setVisible(true);
  768. }
  769. /**
  770. * Makes this component visible or invisible.
  771. *
  772. * @param visible true to make this component visible
  773. * @deprecated use {@link #setVisible(boolean)} instead
  774. */
  775. public void show(boolean b)
  776. {
  777. setVisible(b);
  778. }
  779. /**
  780. * Hides this component so that it is no longer shown on the screen.
  781. *
  782. * @deprecated use {@link #setVisible(boolean)} instead
  783. */
  784. public void hide()
  785. {
  786. setVisible(false);
  787. }
  788. /**
  789. * Returns this component's foreground color. If not set, this is inherited
  790. * from the parent.
  791. *
  792. * @return this component's foreground color, or null
  793. * @see #setForeground(Color)
  794. */
  795. public Color getForeground()
  796. {
  797. if (foreground != null)
  798. return foreground;
  799. return parent == null ? null : parent.getForeground();
  800. }
  801. /**
  802. * Sets this component's foreground color to the specified color. This is a
  803. * bound property.
  804. *
  805. * @param c the new foreground color
  806. * @see #getForeground()
  807. */
  808. public void setForeground(Color c)
  809. {
  810. firePropertyChange("foreground", foreground, c);
  811. if (peer != null)
  812. peer.setForeground(c);
  813. foreground = c;
  814. }
  815. /**
  816. * Tests if the foreground was explicitly set, or just inherited from the
  817. * parent.
  818. *
  819. * @return true if the foreground has been set
  820. * @since 1.4
  821. */
  822. public boolean isForegroundSet()
  823. {
  824. return foreground != null;
  825. }
  826. /**
  827. * Returns this component's background color. If not set, this is inherited
  828. * from the parent.
  829. *
  830. * @return the background color of the component, or null
  831. * @see #setBackground(Color)
  832. */
  833. public Color getBackground()
  834. {
  835. if (background != null)
  836. return background;
  837. return parent == null ? null : parent.getBackground();
  838. }
  839. /**
  840. * Sets this component's background color to the specified color. The parts
  841. * of the component affected by the background color may by system dependent.
  842. * This is a bound property.
  843. *
  844. * @param c the new background color
  845. * @see #getBackground()
  846. */
  847. public void setBackground(Color c)
  848. {
  849. firePropertyChange("background", background, c);
  850. if (peer != null)
  851. peer.setBackground(c);
  852. background = c;
  853. }
  854. /**
  855. * Tests if the background was explicitly set, or just inherited from the
  856. * parent.
  857. *
  858. * @return true if the background has been set
  859. * @since 1.4
  860. */
  861. public boolean isBackgroundSet()
  862. {
  863. return background != null;
  864. }
  865. /**
  866. * Returns the font in use for this component. If not set, this is inherited
  867. * from the parent.
  868. *
  869. * @return the font for this component
  870. * @see #setFont(Font)
  871. */
  872. public Font getFont()
  873. {
  874. if (font != null)
  875. return font;
  876. return parent == null ? null : parent.getFont();
  877. }
  878. /**
  879. * Sets the font for this component to the specified font. This is a bound
  880. * property.
  881. *
  882. * @param font the new font for this component
  883. * @see #getFont()
  884. */
  885. public void setFont(Font f)
  886. {
  887. firePropertyChange("font", font, f);
  888. if (peer != null)
  889. peer.setFont(f);
  890. font = f;
  891. }
  892. /**
  893. * Tests if the font was explicitly set, or just inherited from the parent.
  894. *
  895. * @return true if the font has been set
  896. * @since 1.4
  897. */
  898. public boolean isFontSet()
  899. {
  900. return font != null;
  901. }
  902. /**
  903. * Returns the locale for this component. If this component does not
  904. * have a locale, the locale of the parent component is returned.
  905. *
  906. * @return the locale for this component
  907. * @throws IllegalComponentStateException if it has no locale or parent
  908. * @see setLocale(Locale)
  909. * @since 1.1
  910. */
  911. public Locale getLocale()
  912. {
  913. if (locale != null)
  914. return locale;
  915. if (parent == null)
  916. throw new IllegalComponentStateException
  917. ("Component has no parent: can't determine Locale");
  918. return parent.getLocale();
  919. }
  920. /**
  921. * Sets the locale for this component to the specified locale. This is a
  922. * bound property.
  923. *
  924. * @param locale the new locale for this component
  925. */
  926. public void setLocale(Locale l)
  927. {
  928. firePropertyChange("locale", locale, l);
  929. locale = l;
  930. // New writing/layout direction or more/less room for localized labels.
  931. invalidate();
  932. }
  933. /**
  934. * Returns the color model of the device this componet is displayed on.
  935. *
  936. * @return this object's color model
  937. * @see Toolkit#getColorModel()
  938. */
  939. public ColorModel getColorModel()
  940. {
  941. GraphicsConfiguration config = getGraphicsConfiguration();
  942. return config != null ? config.getColorModel()
  943. : getToolkit().getColorModel();
  944. }
  945. /**
  946. * Returns the location of this component's top left corner relative to
  947. * its parent component. This may be outdated, so for synchronous behavior,
  948. * you should use a component listner.
  949. *
  950. * @return the location of this component
  951. * @see #setLocation(int, int)
  952. * @see #getLocationOnScreen()
  953. * @since 1.1
  954. */
  955. public Point getLocation()
  956. {
  957. return new Point(x, y);
  958. }
  959. /**
  960. * Returns the location of this component's top left corner in screen
  961. * coordinates.
  962. *
  963. * @return the location of this component in screen coordinates
  964. * @throws IllegalComponentStateException if the component is not showing
  965. */
  966. public Point getLocationOnScreen()
  967. {
  968. if (! isShowing())
  969. throw new IllegalComponentStateException("component not showing");
  970. // We know peer != null here.
  971. return peer.getLocationOnScreen();
  972. }
  973. /**
  974. * Returns the location of this component's top left corner relative to
  975. * its parent component.
  976. *
  977. * @return the location of this component
  978. * @deprecated use {@link #getLocation()} instead
  979. */
  980. public Point location()
  981. {
  982. return getLocation();
  983. }
  984. /**
  985. * Moves this component to the specified location, relative to the parent's
  986. * coordinates. The coordinates are the new upper left corner of this
  987. * component.
  988. *
  989. * @param x the new X coordinate of this component
  990. * @param y the new Y coordinate of this component
  991. * @see #getLocation()
  992. * @see #setBounds(int, int, int, int)
  993. */
  994. public void setLocation(int x, int y)
  995. {
  996. if (this.x == x && this.y == y)
  997. return;
  998. invalidate();
  999. this.x = x;
  1000. this.y = y;
  1001. if (peer != null)
  1002. peer.setBounds(x, y, width, height);
  1003. }
  1004. /**
  1005. * Moves this component to the specified location, relative to the parent's
  1006. * coordinates. The coordinates are the new upper left corner of this
  1007. * component.
  1008. *
  1009. * @param x the new X coordinate of this component
  1010. * @param y the new Y coordinate of this component
  1011. * @deprecated use {@link #setLocation(int, int)} instead
  1012. */
  1013. public void move(int x, int y)
  1014. {
  1015. setLocation(x, y);
  1016. }
  1017. /**
  1018. * Moves this component to the specified location, relative to the parent's
  1019. * coordinates. The coordinates are the new upper left corner of this
  1020. * component.
  1021. *
  1022. * @param p new coordinates for this component
  1023. * @throws NullPointerException if p is null
  1024. * @see #getLocation()
  1025. * @see #setBounds(int, int, int, int)
  1026. * @since 1.1
  1027. */
  1028. public void setLocation(Point p)
  1029. {
  1030. setLocation(p.x, p.y);
  1031. }
  1032. /**
  1033. * Returns the size of this object.
  1034. *
  1035. * @return the size of this object
  1036. * @see #setSize(int, int)
  1037. * @since 1.1
  1038. */
  1039. public Dimension getSize()
  1040. {
  1041. return new Dimension(width, height);
  1042. }
  1043. /**
  1044. * Returns the size of this object.
  1045. *
  1046. * @return the size of this object
  1047. * @deprecated use {@link #getSize()} instead
  1048. */
  1049. public Dimension size()
  1050. {
  1051. return getSize();
  1052. }
  1053. /**
  1054. * Sets the size of this component to the specified width and height.
  1055. *
  1056. * @param width the new width of this component
  1057. * @param height the new height of this component
  1058. * @see #getSize()
  1059. * @see #setBounds(int, int, int, int)
  1060. */
  1061. public void setSize(int width, int height)
  1062. {
  1063. if (this.width == width && this.height == height)
  1064. return;
  1065. invalidate();
  1066. this.width = width;
  1067. this.height = height;
  1068. if (peer != null)
  1069. peer.setBounds(x, y, width, height);
  1070. }
  1071. /**
  1072. * Sets the size of this component to the specified value.
  1073. *
  1074. * @param width the new width of the component
  1075. * @param height the new height of the component
  1076. * @deprecated use {@link #setSize(int, int)} instead
  1077. */
  1078. public void resize(int width, int height)
  1079. {
  1080. setSize(width, height);
  1081. }
  1082. /**
  1083. * Sets the size of this component to the specified value.
  1084. *
  1085. * @param d the new size of this component
  1086. * @throws NullPointerException if d is null
  1087. * @see #setSize(int, int)
  1088. * @see #setBounds(int, int, int, int)
  1089. * @since 1.1
  1090. */
  1091. public void setSize(Dimension d)
  1092. {
  1093. setSize(d.width, d.height);
  1094. }
  1095. /**
  1096. * Sets the size of this component to the specified value.
  1097. *
  1098. * @param d the new size of this component
  1099. * @throws NullPointerException if d is null
  1100. * @deprecated use {@link #setSize(Dimension)} instead
  1101. */
  1102. public void resize(Dimension d)
  1103. {
  1104. setSize(d.width, d.height);
  1105. }
  1106. /**
  1107. * Returns a bounding rectangle for this component. Note that the
  1108. * returned rectange is relative to this component's parent, not to
  1109. * the screen.
  1110. *
  1111. * @return the bounding rectangle for this component
  1112. * @see #setBounds(int, int, int, int)
  1113. * @see #getLocation()
  1114. * @see #getSize()
  1115. */
  1116. public Rectangle getBounds()
  1117. {
  1118. return new Rectangle(x, y, width, height);
  1119. }
  1120. /**
  1121. * Returns a bounding rectangle for this component. Note that the
  1122. * returned rectange is relative to this component's parent, not to
  1123. * the screen.
  1124. *
  1125. * @return the bounding rectangle for this component
  1126. * @deprecated use {@link #getBounds()} instead
  1127. */
  1128. public Rectangle bounds()
  1129. {
  1130. return getBounds();
  1131. }
  1132. /**
  1133. * Sets the bounding rectangle for this component to the specified values.
  1134. * Note that these coordinates are relative to the parent, not to the screen.
  1135. *
  1136. * @param x the X coordinate of the upper left corner of the rectangle
  1137. * @param y the Y coordinate of the upper left corner of the rectangle
  1138. * @param w the width of the rectangle
  1139. * @param h the height of the rectangle
  1140. * @see #getBounds()
  1141. * @see #setLocation(int, int)
  1142. * @see #setLocation(Point)
  1143. * @see #setSize(int, int)
  1144. * @see #setSize(Dimension)
  1145. * @since 1.1
  1146. */
  1147. public void setBounds(int x, int y, int w, int h)
  1148. {
  1149. if (this.x == x && this.y == y && width == w && height == h)
  1150. return;
  1151. invalidate();
  1152. this.x = x;
  1153. this.y = y;
  1154. width = w;
  1155. height = h;
  1156. if (peer != null)
  1157. peer.setBounds(x, y, w, h);
  1158. }
  1159. /**
  1160. * Sets the bounding rectangle for this component to the specified values.
  1161. * Note that these coordinates are relative to the parent, not to the screen.
  1162. *
  1163. * @param x the X coordinate of the upper left corner of the rectangle
  1164. * @param y the Y coordinate of the upper left corner of the rectangle
  1165. * @param w the width of the rectangle
  1166. * @param h the height of the rectangle
  1167. * @deprecated use {@link #setBounds(int, int, int, int)} instead
  1168. */
  1169. public void reshape(int x, int y, int width, int height)
  1170. {
  1171. setBounds(x, y, width, height);
  1172. }
  1173. /**
  1174. * Sets the bounding rectangle for this component to the specified
  1175. * rectangle. Note that these coordinates are relative to the parent, not
  1176. * to the screen.
  1177. *
  1178. * @param r the new bounding rectangle
  1179. * @throws NullPointerException if r is null
  1180. * @see #getBounds()
  1181. * @see #setLocation(Point)
  1182. * @see #setSize(Dimension)
  1183. * @since 1.1
  1184. */
  1185. public void setBounds(Rectangle r)
  1186. {
  1187. setBounds(r.x, r.y, r.width, r.height);
  1188. }
  1189. /**
  1190. * Gets the x coordinate of the upper left corner. This is more efficient
  1191. * than getBounds().x or getLocation().x.
  1192. *
  1193. * @return the current x coordinate
  1194. * @since 1.2
  1195. */
  1196. public int getX()
  1197. {
  1198. return x;
  1199. }
  1200. /**
  1201. * Gets the y coordinate of the upper left corner. This is more efficient
  1202. * than getBounds().y or getLocation().y.
  1203. *
  1204. * @return the current y coordinate
  1205. * @since 1.2
  1206. */
  1207. public int getY()
  1208. {
  1209. return y;
  1210. }
  1211. /**
  1212. * Gets the width of the component. This is more efficient than
  1213. * getBounds().width or getSize().width.
  1214. *
  1215. * @return the current width
  1216. * @since 1.2
  1217. */
  1218. public int getWidth()
  1219. {
  1220. return width;
  1221. }
  1222. /**
  1223. * Gets the height of the component. This is more efficient than
  1224. * getBounds().height or getSize().height.
  1225. *
  1226. * @return the current width
  1227. * @since 1.2
  1228. */
  1229. public int getHeight()
  1230. {
  1231. return height;
  1232. }
  1233. /**
  1234. * Returns the bounds of this component. This allows reuse of an existing
  1235. * rectangle, if r is non-null.
  1236. *
  1237. * @param r the rectangle to use, or null
  1238. * @return the bounds
  1239. */
  1240. public Rectangle getBounds(Rectangle r)
  1241. {
  1242. if (r == null)
  1243. r = new Rectangle();
  1244. r.x = x;
  1245. r.y = y;
  1246. r.width = width;
  1247. r.height = height;
  1248. return r;
  1249. }
  1250. /**
  1251. * Returns the size of this component. This allows reuse of an existing
  1252. * dimension, if d is non-null.
  1253. *
  1254. * @param d the dimension to use, or null
  1255. * @return the size
  1256. */
  1257. public Dimension getSize(Dimension d)
  1258. {
  1259. if (d == null)
  1260. d = new Dimension();
  1261. d.width = width;
  1262. d.height = height;
  1263. return d;
  1264. }
  1265. /**
  1266. * Returns the location of this component. This allows reuse of an existing
  1267. * point, if p is non-null.
  1268. *
  1269. * @param p the point to use, or null
  1270. * @return the location
  1271. */
  1272. public Point getLocation(Point p)
  1273. {
  1274. if (p == null)
  1275. p = new Point();
  1276. p.x = x;
  1277. p.y = y;
  1278. return p;
  1279. }
  1280. /**
  1281. * Tests if this component is opaque. All "heavyweight" (natively-drawn)
  1282. * components are opaque. A component is opaque if it draws all pixels in
  1283. * the bounds; a lightweight component is partially transparent if it lets
  1284. * pixels underneath show through. Subclasses that guarantee that all pixels
  1285. * will be drawn should override this.
  1286. *
  1287. * @return true if this is opaque
  1288. * @see #isLightweight()
  1289. * @since 1.2
  1290. */
  1291. public boolean isOpaque()
  1292. {
  1293. return ! isLightweight();
  1294. }
  1295. /**
  1296. * Return whether the component is lightweight. That means the component has
  1297. * no native peer, but is displayable. This applies to subclasses of
  1298. * Component not in this package, such as javax.swing.
  1299. *
  1300. * @return true if the component has a lightweight peer
  1301. * @see #isDisplayable()
  1302. * @since 1.2
  1303. */
  1304. public boolean isLightweight()
  1305. {
  1306. return peer instanceof LightweightPeer;
  1307. }
  1308. /**
  1309. * Returns the component's preferred size.
  1310. *
  1311. * @return the component's preferred size
  1312. * @see #getMinimumSize()
  1313. * @see LayoutManager
  1314. */
  1315. public Dimension getPreferredSize()
  1316. {
  1317. if (prefSize == null)
  1318. prefSize = (peer != null ? peer.getPreferredSize()
  1319. : new Dimension(width, height));
  1320. return prefSize;
  1321. }
  1322. /**
  1323. * Returns the component's preferred size.
  1324. *
  1325. * @return the component's preferred size
  1326. * @deprecated use {@link #getPreferredSize()} instead
  1327. */
  1328. public Dimension preferredSize()
  1329. {
  1330. return getPreferredSize();
  1331. }
  1332. /**
  1333. * Returns the component's minimum size.
  1334. *
  1335. * @return the component's minimum size
  1336. * @see #getPreferredSize()
  1337. * @see LayoutManager
  1338. */
  1339. public Dimension getMinimumSize()
  1340. {
  1341. if (minSize == null)
  1342. minSize = (peer != null ? peer.getMinimumSize()
  1343. : new Dimension(width, height));
  1344. return minSize;
  1345. }
  1346. /**
  1347. * Returns the component's minimum size.
  1348. *
  1349. * @return the component's minimum size
  1350. * @deprecated use {@link #getMinimumSize()} instead
  1351. */
  1352. public Dimension minimumSize()
  1353. {
  1354. return getMinimumSize();
  1355. }
  1356. /**
  1357. * Returns the component's maximum size.
  1358. *
  1359. * @return the component's maximum size
  1360. * @see #getMinimumSize()
  1361. * @see #getPreferredSize()
  1362. * @see LayoutManager
  1363. */
  1364. public Dimension getMaximumSize()
  1365. {
  1366. return new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE);
  1367. }
  1368. /**
  1369. * Returns the preferred horizontal alignment of this component. The value
  1370. * returned will be between {@link #LEFT_ALIGNMENT} and
  1371. * {@link #RIGHT_ALIGNMENT}, inclusive.
  1372. *
  1373. * @return the preferred horizontal alignment of this component
  1374. */
  1375. public float getAlignmentX()
  1376. {
  1377. return CENTER_ALIGNMENT;
  1378. }
  1379. /**
  1380. * Returns the preferred vertical alignment of this component. The value
  1381. * returned will be between {@link #TOP_ALIGNMENT} and
  1382. * {@link #BOTTOM_ALIGNMENT}, inclusive.
  1383. *
  1384. * @return the preferred vertical alignment of this component
  1385. */
  1386. public float getAlignmentY()
  1387. {
  1388. return CENTER_ALIGNMENT;
  1389. }
  1390. /**
  1391. * Calls the layout manager to re-layout the component. This is called
  1392. * during validation of a container in most cases.
  1393. *
  1394. * @see #validate()
  1395. * @see LayoutManager
  1396. */
  1397. public void doLayout()
  1398. {
  1399. // nothing to do unless we're a container
  1400. }
  1401. /**
  1402. * Calls the layout manager to re-layout the component. This is called
  1403. * during validation of a container in most cases.
  1404. *
  1405. * @deprecated use {@link #doLayout()} instead
  1406. */
  1407. public void layout()
  1408. {
  1409. doLayout();
  1410. }
  1411. /**
  1412. * Called to ensure that the layout for this component is valid. This is
  1413. * usually called on containers.
  1414. *
  1415. * @see #invalidate()
  1416. * @see #doLayout()
  1417. * @see LayoutManager
  1418. * @see Container#validate()
  1419. */
  1420. public void validate()
  1421. {
  1422. valid = true;
  1423. }
  1424. /**
  1425. * Invalidates this component and all of its parent components. This will
  1426. * cause them to have their layout redone. This is called frequently, so
  1427. * make it fast.
  1428. */
  1429. public void invalidate()
  1430. {
  1431. valid = false;
  1432. prefSize = null;
  1433. minSize = null;
  1434. if (parent != null && parent.valid)
  1435. parent.invalidate();
  1436. }
  1437. /**
  1438. * Returns a graphics object for this component. Returns <code>null</code>
  1439. * if this component is not currently displayed on the screen.
  1440. *
  1441. * @return a graphics object for this component
  1442. * @see #paint(Graphics)
  1443. */
  1444. public Graphics getGraphics()
  1445. {
  1446. if (peer != null)
  1447. {
  1448. Graphics gfx = peer.getGraphics();
  1449. if (gfx != null)
  1450. return gfx;
  1451. // create graphics for lightweight:
  1452. Container parent = getParent();
  1453. if (parent != null)
  1454. {
  1455. gfx = parent.getGraphics();
  1456. Rectangle bounds = getBounds();
  1457. gfx.setClip(bounds);
  1458. gfx.translate(bounds.x, bounds.y);
  1459. return gfx;
  1460. }
  1461. }
  1462. return null;
  1463. }
  1464. /**
  1465. * Returns the font metrics for the specified font in this component.
  1466. *
  1467. * @param font the font to retrieve metrics for
  1468. * @return the font metrics for the specified font
  1469. * @throws NullPointerException if font is null
  1470. * @see #getFont()
  1471. * @see Toolkit#getFontMetrics(Font)
  1472. */
  1473. public FontMetrics getFontMetrics(Font font)
  1474. {
  1475. return peer == null ? getToolkit().getFontMetrics(font)
  1476. : peer.getFontMetrics(font);
  1477. }
  1478. /**
  1479. * Sets the cursor for this component to the specified cursor. The cursor
  1480. * is displayed when the point is contained by the component, and the
  1481. * component is visible, displayable, and enabled. This is inherited by
  1482. * subcomponents unless they set their own cursor.
  1483. *
  1484. * @param cursor the new cursor for this component
  1485. * @see #isEnabled()
  1486. * @see #isShowing()
  1487. * @see #getCursor()
  1488. * @see #contains(int, int)
  1489. * @see Toolkit#createCustomCursor(Image, Point, String)
  1490. */
  1491. public void setCursor(Cursor cursor)
  1492. {
  1493. this.cursor = cursor;
  1494. if (peer != null)
  1495. peer.setCursor(cursor);
  1496. }
  1497. /**
  1498. * Returns the cursor for this component. If not set, this is inherited
  1499. * from the parent, or from Cursor.getDefaultCursor().
  1500. *
  1501. * @return the cursor for this component
  1502. */
  1503. public Cursor getCursor()
  1504. {
  1505. if (cursor != null)
  1506. return cursor;
  1507. return parent != null ? parent.getCursor() : Cursor.getDefaultCursor();
  1508. }
  1509. /**
  1510. * Tests if the cursor was explicitly set, or just inherited from the parent.
  1511. *
  1512. * @return true if the cursor has been set
  1513. * @since 1.4
  1514. */
  1515. public boolean isCursorSet()
  1516. {
  1517. return cursor != null;
  1518. }
  1519. /**
  1520. * Paints this component on the screen. The clipping region in the graphics
  1521. * context will indicate the region that requires painting. This is called
  1522. * whenever the component first shows, or needs to be repaired because
  1523. * something was temporarily drawn on top. It is not necessary for
  1524. * subclasses to call <code>super.paint(g)</code>. Components with no area
  1525. * are not painted.
  1526. *
  1527. * @param g the graphics context for this paint job
  1528. * @see #update(Graphics)
  1529. */
  1530. public void paint(Graphics g)
  1531. {
  1532. }
  1533. /**
  1534. * Updates this component. This is called in response to
  1535. * <code>repaint</code>. This method fills the component with the
  1536. * background color, then sets the foreground color of the specified
  1537. * graphics context to the foreground color of this component and calls
  1538. * the <code>paint()</code> method. The coordinates of the graphics are
  1539. * relative to this component. Subclasses should call either
  1540. * <code>super.update(g)</code> or <code>paint(g)</code>.
  1541. *
  1542. * @param graphics the graphics context for this update
  1543. * @see #paint(Graphics)
  1544. * @see #repaint()
  1545. */
  1546. public void update(Graphics g)
  1547. {
  1548. paint(g);
  1549. }
  1550. /**
  1551. * Paints this entire component, including any sub-components.
  1552. *
  1553. * @param graphics the graphics context for this paint job
  1554. * @see #paint(Graphics)
  1555. */
  1556. public void paintAll(Graphics g)
  1557. {
  1558. if (! visible)
  1559. return;
  1560. if (peer != null)
  1561. peer.paint(g);
  1562. paint(g);
  1563. }
  1564. /**
  1565. * Repaint this entire component. The <code>update()</code> method
  1566. * on this component will be called as soon as possible.
  1567. *
  1568. * @see #update(Graphics)
  1569. * @see #repaint(long, int, int, int, int)
  1570. */
  1571. public void repaint()
  1572. {
  1573. repaint(0, 0, 0, width, height);
  1574. }
  1575. /**
  1576. * Repaint this entire component. The <code>update()</code> method on this
  1577. * component will be called in approximate the specified number of
  1578. * milliseconds.
  1579. *
  1580. * @param tm milliseconds before this component should be repainted
  1581. * @see #paint(Graphics)
  1582. * @see #repaint(long, int, int, int, int)
  1583. */
  1584. public void repaint(long tm)
  1585. {
  1586. repaint(tm, 0, 0, width, height);
  1587. }
  1588. /**
  1589. * Repaints the specified rectangular region within this component. The
  1590. * <code>update</code> method on this component will be called as soon as
  1591. * possible. The coordinates are relative to this component.
  1592. *
  1593. * @param x the X coordinate of the upper left of the region to repaint
  1594. * @param y the Y coordinate of the upper left of the region to repaint
  1595. * @param w the width of the region to repaint
  1596. * @param h the height of the region to repaint
  1597. * @see #update(Graphics)
  1598. * @see #repaint(long, int, int, int, int)
  1599. */
  1600. public void repaint(int x, int y, int w, int h)
  1601. {
  1602. repaint(0, x, y, w, h);
  1603. }
  1604. /**
  1605. * Repaints the specified rectangular region within this component. The
  1606. * <code>update</code> method on this component will be called in
  1607. * approximately the specified number of milliseconds. The coordinates
  1608. * are relative to this component.
  1609. *
  1610. * @param tm milliseconds before this component should be repainted
  1611. * @param x the X coordinate of the upper left of the region to repaint
  1612. * @param y the Y coordinate of the upper left of the region to repaint
  1613. * @param w the width of the region to repaint
  1614. * @param h the height of the region to repaint
  1615. * @see #update(Graphics)
  1616. */
  1617. public void repaint(long tm, int x, int y, int width, int height)
  1618. {
  1619. // Handle lightweight repainting by forwarding to native parent
  1620. if (isLightweight() && parent != null)
  1621. {
  1622. if (parent != null)
  1623. parent.repaint(tm, x + getX(), y + getY(), width, height);
  1624. }
  1625. else if (peer != null)
  1626. peer.repaint(tm, x, y, width, height);
  1627. }
  1628. /**
  1629. * Prints this component. This method is provided so that printing can be
  1630. * done in a different manner from painting. However, the implementation
  1631. * in this class simply calls the <code>paint()</code> method.
  1632. *
  1633. * @param graphics the graphics context of the print device
  1634. * @see #paint(Graphics)
  1635. */
  1636. public void print(Graphics g)
  1637. {
  1638. paint(g);
  1639. }
  1640. /**
  1641. * Prints this component, including all sub-components. This method is
  1642. * provided so that printing can be done in a different manner from
  1643. * painting. However, the implementation in this class simply calls the
  1644. * <code>paintAll()</code> method.
  1645. *
  1646. * @param graphics the graphics context of the print device
  1647. * @see #paintAll(Graphics)
  1648. */
  1649. public void printAll(Graphics g)
  1650. {
  1651. paintAll(g);
  1652. }
  1653. /**
  1654. * Called when an image has changed so that this component is repainted.
  1655. * This incrementally draws an image as more bits are available, when
  1656. * possible. Incremental drawing is enabled if the system property
  1657. * <code>awt.image.incrementalDraw</code> is not present or is true, in which
  1658. * case the redraw rate is set to 100ms or the value of the system property
  1659. * <code>awt.image.redrawrate</code>.
  1660. *
  1661. * <p>The coordinate system used depends on the particular flags.
  1662. *
  1663. * @param image the image that has been updated
  1664. * @param flags tlags as specified in <code>ImageObserver</code>
  1665. * @param x the X coordinate
  1666. * @param y the Y coordinate
  1667. * @param w the width
  1668. * @param h the height
  1669. * @return true if the image has been fully loaded
  1670. * @see ImageObserver
  1671. * @see Graphics#drawImage(Image, int, int, Color, ImageObserver)
  1672. * @see Graphics#drawImage(Image, int, int, ImageObserver)
  1673. * @see Graphics#drawImage(Image, int, int, int, int, Color, ImageObserver)
  1674. * @see Graphics#drawImage(Image, int, int, int, int, ImageObserver)
  1675. * @see ImageObserver#update(Image, int, int, int, int, int)
  1676. */
  1677. public boolean imageUpdate(Image img, int flags, int x, int y, int w, int h)
  1678. {
  1679. // XXX Implement.
  1680. throw new Error("not implemented");
  1681. }
  1682. /**
  1683. * Creates an image from the specified producer.
  1684. *
  1685. * @param producer the image procedure to create the image from
  1686. * @return the resulting image
  1687. */
  1688. public Image createImage(ImageProducer producer)
  1689. {
  1690. // XXX What if peer or producer is null?
  1691. return peer.createImage(producer);
  1692. }
  1693. /**
  1694. * Creates an image with the specified width and height for use in
  1695. * double buffering. Headless environments do not support images.
  1696. *
  1697. * @param width the width of the image
  1698. * @param height the height of the image
  1699. * @return the requested image, or null if it is not supported
  1700. */
  1701. public Image createImage(int width, int height)
  1702. {
  1703. if (GraphicsEnvironment.isHeadless())
  1704. return null;
  1705. GraphicsConfiguration config = getGraphicsConfiguration();
  1706. return config == null ? null : config.createCompatibleImage(width, height);
  1707. }
  1708. /**
  1709. * Creates an image with the specified width and height for use in
  1710. * double buffering. Headless environments do not support images.
  1711. *
  1712. * @param width the width of the image
  1713. * @param height the height of the image
  1714. * @return the requested image, or null if it is not supported
  1715. * @since 1.4
  1716. */
  1717. public VolatileImage createVolatileImage(int width, int height)
  1718. {
  1719. if (GraphicsEnvironment.isHeadless())
  1720. return null;
  1721. GraphicsConfiguration config = getGraphicsConfiguration();
  1722. return config == null ? null
  1723. : config.createCompatibleVolatileImage(width, height);
  1724. }
  1725. /**
  1726. * Creates an image with the specified width and height for use in
  1727. * double buffering. Headless environments do not support images. The image
  1728. * will support the specified capabilities.
  1729. *
  1730. * @param width the width of the image
  1731. * @param height the height of the image
  1732. * @param caps the requested capabilities
  1733. * @return the requested image, or null if it is not supported
  1734. * @throws AWTException if a buffer with the capabilities cannot be created
  1735. * @since 1.4
  1736. */
  1737. public VolatileImage createVolatileImage(int width, int height,
  1738. ImageCapabilities caps)
  1739. throws AWTException
  1740. {
  1741. if (GraphicsEnvironment.isHeadless())
  1742. return null;
  1743. GraphicsConfiguration config = getGraphicsConfiguration();
  1744. return config == null ? null
  1745. : config.createCompatibleVolatileImage(width, height, caps);
  1746. }
  1747. /**
  1748. * Prepares the specified image for rendering on this component.
  1749. *
  1750. * @param image the image to prepare for rendering
  1751. * @param observer the observer to notify of image preparation status
  1752. * @return true if the image is already fully prepared
  1753. * @throws NullPointerException if image is null
  1754. */
  1755. public boolean prepareImage(Image image, ImageObserver observer)
  1756. {
  1757. return prepareImage(image, image.getWidth(observer),
  1758. image.getHeight(observer), observer);
  1759. }
  1760. /**
  1761. * Prepares the specified image for rendering on this component at the
  1762. * specified scaled width and height
  1763. *
  1764. * @param image the image to prepare for rendering
  1765. * @param width the scaled width of the image
  1766. * @param height the scaled height of the image
  1767. * @param observer the observer to notify of image preparation status
  1768. * @return true if the image is already fully prepared
  1769. */
  1770. public boolean prepareImage(Image image, int width, int height,
  1771. ImageObserver observer)
  1772. {
  1773. return peer.prepareImage(image, width, height, observer);
  1774. }
  1775. /**
  1776. * Returns the status of the loading of the specified image. The value
  1777. * returned will be those flags defined in <code>ImageObserver</code>.
  1778. *
  1779. * @param image the image to check on
  1780. * @param observer the observer to notify of image loading progress
  1781. * @return the image observer flags indicating the status of the load
  1782. * @see #prepareImage(Image, int, int, ImageObserver)
  1783. * @see #Toolkit#checkImage(Image, int, int, ImageObserver)
  1784. * @throws NullPointerException if image is null
  1785. */
  1786. public int checkImage(Image image, ImageObserver observer)
  1787. {
  1788. return checkImage(image, image.getWidth(observer),
  1789. image.getHeight(observer), observer);
  1790. }
  1791. /**
  1792. * Returns the status of the loading of the specified image. The value
  1793. * returned will be those flags defined in <code>ImageObserver</code>.
  1794. *
  1795. * @param image the image to check on
  1796. * @param width the scaled image width
  1797. * @param height the scaled image height
  1798. * @param observer the observer to notify of image loading progress
  1799. * @return the image observer flags indicating the status of the load
  1800. * @see #prepareImage(Image, int, int, ImageObserver)
  1801. * @see #Toolkit#checkImage(Image, int, int, ImageObserver)
  1802. */
  1803. public int checkImage(Image image, int width, int height,
  1804. ImageObserver observer)
  1805. {
  1806. if (peer != null)
  1807. return peer.checkImage(image, width, height, observer);
  1808. return getToolkit().checkImage(image, width, height, observer);
  1809. }
  1810. /**
  1811. * Sets whether paint messages delivered by the operating system should be
  1812. * ignored. This does not affect messages from AWT, except for those
  1813. * triggered by OS messages. Setting this to true can allow faster
  1814. * performance in full-screen mode or page-flipping.
  1815. *
  1816. * @param ignoreRepaint the new setting for ignoring repaint events
  1817. * @see #getIgnoreRepaint()
  1818. * @see BufferStrategy
  1819. * @see GraphicsDevice.setFullScreenWindow(Window)
  1820. * @since 1.4
  1821. */
  1822. public void setIgnoreRepaint(boolean ignoreRepaint)
  1823. {
  1824. this.ignoreRepaint = ignoreRepaint;
  1825. }
  1826. /**
  1827. * Test whether paint events from the operating system are ignored.
  1828. *
  1829. * @return the status of ignoring paint events
  1830. * @see #setIgnoreRepaint(boolean)
  1831. * @since 1.4
  1832. */
  1833. public boolean getIgnoreRepaint()
  1834. {
  1835. return ignoreRepaint;
  1836. }
  1837. /**
  1838. * Tests whether or not the specified point is contained within this
  1839. * component. Coordinates are relative to this component.
  1840. *
  1841. * @param x the X coordinate of the point to test
  1842. * @param y the Y coordinate of the point to test
  1843. * @return true if the point is within this component
  1844. * @see #getComponentAt(int, int)
  1845. */
  1846. public boolean contains(int x, int y)
  1847. {
  1848. return x >= 0 && y >= 0 && x < width && y < height;
  1849. }
  1850. /**
  1851. * Tests whether or not the specified point is contained within this
  1852. * component. Coordinates are relative to this component.
  1853. *
  1854. * @param x the X coordinate of the point to test
  1855. * @param y the Y coordinate of the point to test
  1856. * @return true if the point is within this component
  1857. * @deprecated use {@link #contains(int, int)} instead
  1858. */
  1859. public boolean inside(int x, int y)
  1860. {
  1861. return contains(x, y);
  1862. }
  1863. /**
  1864. * Tests whether or not the specified point is contained within this
  1865. * component. Coordinates are relative to this component.
  1866. *
  1867. * @param p the point to test
  1868. * @return true if the point is within this component
  1869. * @throws NullPointerException if p is null
  1870. * @see #getComponentAt(Point)
  1871. * @since 1.1
  1872. */
  1873. public boolean contains(Point p)
  1874. {
  1875. return contains(p.x, p.y);
  1876. }
  1877. /**
  1878. * Returns the component occupying the position (x,y). This will either
  1879. * be this component, an immediate child component, or <code>null</code>
  1880. * if neither of the first two occupies the specified location.
  1881. *
  1882. * @param x the X coordinate to search for components at
  1883. * @param y the Y coordinate to search for components at
  1884. * @return the component at the specified location, or null
  1885. * @see #contains(int, int)
  1886. */
  1887. public Component getComponentAt(int x, int y)
  1888. {
  1889. return contains(x, y) ? this : null;
  1890. }
  1891. /**
  1892. * Returns the component occupying the position (x,y). This will either
  1893. * be this component, an immediate child component, or <code>null</code>
  1894. * if neither of the first two occupies the specified location.
  1895. *
  1896. * @param x the X coordinate to search for components at
  1897. * @param y the Y coordinate to search for components at
  1898. * @return the component at the specified location, or null
  1899. * @deprecated use {@link #getComponentAt(int, int)} instead
  1900. */
  1901. public Component locate(int x, int y)
  1902. {
  1903. return getComponentAt(x, y);
  1904. }
  1905. /**
  1906. * Returns the component occupying the position (x,y). This will either
  1907. * be this component, an immediate child component, or <code>null</code>
  1908. * if neither of the first two occupies the specified location.
  1909. *
  1910. * @param p the point to search for components at
  1911. * @return the component at the specified location, or null
  1912. * @throws NullPointerException if p is null
  1913. * @see #contains(Point)
  1914. * @since 1.1
  1915. */
  1916. public Component getComponentAt(Point p)
  1917. {
  1918. return getComponentAt(p.x, p.y);
  1919. }
  1920. /**
  1921. * AWT 1.0 event dispatcher.
  1922. *
  1923. * @param e the event to dispatch
  1924. * @deprecated use {@link #dispatchEvent(AWTEvent)} instead
  1925. */
  1926. public void deliverEvent(Event e)
  1927. {
  1928. // XXX Add backward compatibility handling.
  1929. }
  1930. /**
  1931. * Forwards AWT events to processEvent() if:<ul>
  1932. * <li>Events have been enabled for this type of event via
  1933. * <code>enableEvents()</code></li>,
  1934. * <li>There is at least one registered listener for this type of event</li>
  1935. * </ul>
  1936. *
  1937. * @param e the event to dispatch
  1938. */
  1939. public final void dispatchEvent(AWTEvent e)
  1940. {
  1941. // Some subclasses in the AWT package need to override this behavior,
  1942. // hence the use of dispatchEventImpl().
  1943. dispatchEventImpl(e);
  1944. if (peer != null && ! e.consumed)
  1945. peer.handleEvent(e);
  1946. }
  1947. /**
  1948. * AWT 1.0 event dispatcher.
  1949. *
  1950. * @param e the event to dispatch
  1951. * @return false: since the method was deprecated, the return has no meaning
  1952. * @deprecated use {@link #dispatchEvent(AWTEvent)} instead
  1953. */
  1954. public boolean postEvent(Event e)
  1955. {
  1956. // XXX Add backward compatibility handling.
  1957. return false;
  1958. }
  1959. /**
  1960. * Adds the specified listener to this component. This is harmless if the
  1961. * listener is null, but if the listener has already been registered, it
  1962. * will now be registered twice.
  1963. *
  1964. * @param listener the new listener to add
  1965. * @see ComponentEvent
  1966. * @see #removeComponentListener(ComponentListener)
  1967. * @see #getComponentListeners()
  1968. * @since 1.1
  1969. */
  1970. public synchronized void addComponentListener(ComponentListener l)
  1971. {
  1972. componentListener = AWTEventMulticaster.add(componentListener, l);
  1973. if (componentListener != null)
  1974. enableEvents(AWTEvent.COMPONENT_EVENT_MASK);
  1975. }
  1976. /**
  1977. * Removes the specified listener from the component. This is harmless if
  1978. * the listener was not previously registered.
  1979. *
  1980. * @param listener the listener to remove
  1981. * @see ComponentEvent
  1982. * @see #addComponentListener(ComponentListener)
  1983. * @see #getComponentListeners()
  1984. * @since 1.1
  1985. */
  1986. public synchronized void removeComponentListener(ComponentListener l)
  1987. {
  1988. componentListener = AWTEventMulticaster.remove(componentListener, l);
  1989. }
  1990. /**
  1991. * Returns an array of all specified listeners registered on this component.
  1992. *
  1993. * @return an array of listeners
  1994. * @see #addComponentListener(ComponentListener)
  1995. * @see #removeComponentListener(ComponentListener)
  1996. * @since 1.4
  1997. */
  1998. public synchronized ComponentListener[] getComponentListeners()
  1999. {
  2000. return (ComponentListener[])
  2001. AWTEventMulticaster.getListeners(componentListener,
  2002. ComponentListener.class);
  2003. }
  2004. /**
  2005. * Adds the specified listener to this component. This is harmless if the
  2006. * listener is null, but if the listener has already been registered, it
  2007. * will now be registered twice.
  2008. *
  2009. * @param listener the new listener to add
  2010. * @see FocusEvent
  2011. * @see #removeFocusListener(FocusListener)
  2012. * @see #getFocusListeners()
  2013. * @since 1.1
  2014. */
  2015. public synchronized void addFocusListener(FocusListener l)
  2016. {
  2017. focusListener = AWTEventMulticaster.add(focusListener, l);
  2018. if (focusListener != null)
  2019. enableEvents(AWTEvent.FOCUS_EVENT_MASK);
  2020. }
  2021. /**
  2022. * Removes the specified listener from the component. This is harmless if
  2023. * the listener was not previously registered.
  2024. *
  2025. * @param listener the listener to remove
  2026. * @see FocusEvent
  2027. * @see #addFocusListener(FocusListener)
  2028. * @see #getFocusListeners()
  2029. * @since 1.1
  2030. */
  2031. public synchronized void removeFocusListener(FocusListener l)
  2032. {
  2033. focusListener = AWTEventMulticaster.remove(focusListener, l);
  2034. }
  2035. /**
  2036. * Returns an array of all specified listeners registered on this component.
  2037. *
  2038. * @return an array of listeners
  2039. * @see #addFocusListener(FocusListener)
  2040. * @see #removeFocusListener(FocusListener)
  2041. * @since 1.4
  2042. */
  2043. public synchronized FocusListener[] getFocusListeners()
  2044. {
  2045. return (FocusListener[])
  2046. AWTEventMulticaster.getListeners(focusListener, FocusListener.class);
  2047. }
  2048. /**
  2049. * Adds the specified listener to this component. This is harmless if the
  2050. * listener is null, but if the listener has already been registered, it
  2051. * will now be registered twice.
  2052. *
  2053. * @param listener the new listener to add
  2054. * @see HierarchyEvent
  2055. * @see #removeHierarchyListener(HierarchyListener)
  2056. * @see #getHierarchyListeners()
  2057. * @since 1.3
  2058. */
  2059. public synchronized void addHierarchyListener(HierarchyListener l)
  2060. {
  2061. hierarchyListener = AWTEventMulticaster.add(hierarchyListener, l);
  2062. if (hierarchyListener != null)
  2063. enableEvents(AWTEvent.HIERARCHY_EVENT_MASK);
  2064. }
  2065. /**
  2066. * Removes the specified listener from the component. This is harmless if
  2067. * the listener was not previously registered.
  2068. *
  2069. * @param listener the listener to remove
  2070. * @see HierarchyEvent
  2071. * @see #addHierarchyListener(HierarchyListener)
  2072. * @see #getHierarchyListeners()
  2073. * @since 1.3
  2074. */
  2075. public synchronized void removeHierarchyListener(HierarchyListener l)
  2076. {
  2077. hierarchyListener = AWTEventMulticaster.remove(hierarchyListener, l);
  2078. }
  2079. /**
  2080. * Returns an array of all specified listeners registered on this component.
  2081. *
  2082. * @return an array of listeners
  2083. * @see #addHierarchyListener(HierarchyListener)
  2084. * @see #removeHierarchyListener(HierarchyListener)
  2085. * @since 1.4
  2086. */
  2087. public synchronized HierarchyListener[] getHierarchyListeners()
  2088. {
  2089. return (HierarchyListener[])
  2090. AWTEventMulticaster.getListeners(hierarchyListener,
  2091. HierarchyListener.class);
  2092. }
  2093. /**
  2094. * Adds the specified listener to this component. This is harmless if the
  2095. * listener is null, but if the listener has already been registered, it
  2096. * will now be registered twice.
  2097. *
  2098. * @param listener the new listener to add
  2099. * @see HierarchyEvent
  2100. * @see #removeHierarchyBoundsListener(HierarchyBoundsListener)
  2101. * @see #getHierarchyBoundsListeners()
  2102. * @since 1.3
  2103. */
  2104. public synchronized void
  2105. addHierarchyBoundsListener(HierarchyBoundsListener l)
  2106. {
  2107. hierarchyBoundsListener =
  2108. AWTEventMulticaster.add(hierarchyBoundsListener, l);
  2109. if (hierarchyBoundsListener != null)
  2110. enableEvents(AWTEvent.HIERARCHY_BOUNDS_EVENT_MASK);
  2111. }
  2112. /**
  2113. * Removes the specified listener from the component. This is harmless if
  2114. * the listener was not previously registered.
  2115. *
  2116. * @param listener the listener to remove
  2117. * @see HierarchyEvent
  2118. * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
  2119. * @see #getHierarchyBoundsListeners()
  2120. * @since 1.3
  2121. */
  2122. public synchronized void
  2123. removeHierarchyBoundsListener(HierarchyBoundsListener l)
  2124. {
  2125. hierarchyBoundsListener =
  2126. AWTEventMulticaster.remove(hierarchyBoundsListener, l);
  2127. }
  2128. /**
  2129. * Returns an array of all specified listeners registered on this component.
  2130. *
  2131. * @return an array of listeners
  2132. * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
  2133. * @see #removeHierarchyBoundsListener(HierarchyBoundsListener)
  2134. * @since 1.4
  2135. */
  2136. public synchronized HierarchyBoundsListener[] getHierarchyBoundsListeners()
  2137. {
  2138. return (HierarchyBoundsListener[])
  2139. AWTEventMulticaster.getListeners(hierarchyBoundsListener,
  2140. HierarchyBoundsListener.class);
  2141. }
  2142. /**
  2143. * Adds the specified listener to this component. This is harmless if the
  2144. * listener is null, but if the listener has already been registered, it
  2145. * will now be registered twice.
  2146. *
  2147. * @param listener the new listener to add
  2148. * @see KeyEvent
  2149. * @see #removeKeyListener(KeyListener)
  2150. * @see #getKeyListeners()
  2151. * @since 1.1
  2152. */
  2153. public synchronized void addKeyListener(KeyListener l)
  2154. {
  2155. keyListener = AWTEventMulticaster.add(keyListener, l);
  2156. if (keyListener != null)
  2157. enableEvents(AWTEvent.KEY_EVENT_MASK);
  2158. }
  2159. /**
  2160. * Removes the specified listener from the component. This is harmless if
  2161. * the listener was not previously registered.
  2162. *
  2163. * @param listener the listener to remove
  2164. * @see KeyEvent
  2165. * @see #addKeyListener(KeyListener)
  2166. * @see #getKeyListeners()
  2167. * @since 1.1
  2168. */
  2169. public synchronized void removeKeyListener(KeyListener l)
  2170. {
  2171. keyListener = AWTEventMulticaster.remove(keyListener, l);
  2172. }
  2173. /**
  2174. * Returns an array of all specified listeners registered on this component.
  2175. *
  2176. * @return an array of listeners
  2177. * @see #addKeyListener(KeyListener)
  2178. * @see #removeKeyListener(KeyListener)
  2179. * @since 1.4
  2180. */
  2181. public synchronized KeyListener[] getKeyListeners()
  2182. {
  2183. return (KeyListener[])
  2184. AWTEventMulticaster.getListeners(keyListener, KeyListener.class);
  2185. }
  2186. /**
  2187. * Adds the specified listener to this component. This is harmless if the
  2188. * listener is null, but if the listener has already been registered, it
  2189. * will now be registered twice.
  2190. *
  2191. * @param listener the new listener to add
  2192. * @see MouseEvent
  2193. * @see #removeMouseListener(MouseListener)
  2194. * @see #getMouseListeners()
  2195. * @since 1.1
  2196. */
  2197. public synchronized void addMouseListener(MouseListener l)
  2198. {
  2199. mouseListener = AWTEventMulticaster.add(mouseListener, l);
  2200. if (mouseListener != null)
  2201. enableEvents(AWTEvent.MOUSE_EVENT_MASK);
  2202. }
  2203. /**
  2204. * Removes the specified listener from the component. This is harmless if
  2205. * the listener was not previously registered.
  2206. *
  2207. * @param listener the listener to remove
  2208. * @see MouseEvent
  2209. * @see #addMouseListener(MouseListener)
  2210. * @see #getMouseListeners()
  2211. * @since 1.1
  2212. */
  2213. public synchronized void removeMouseListener(MouseListener l)
  2214. {
  2215. mouseListener = AWTEventMulticaster.remove(mouseListener, l);
  2216. }
  2217. /**
  2218. * Returns an array of all specified listeners registered on this component.
  2219. *
  2220. * @return an array of listeners
  2221. * @see #addMouseListener(MouseListener)
  2222. * @see #removeMouseListener(MouseListener)
  2223. * @since 1.4
  2224. */
  2225. public synchronized MouseListener[] getMouseListeners()
  2226. {
  2227. return (MouseListener[])
  2228. AWTEventMulticaster.getListeners(mouseListener, MouseListener.class);
  2229. }
  2230. /**
  2231. * Adds the specified listener to this component. This is harmless if the
  2232. * listener is null, but if the listener has already been registered, it
  2233. * will now be registered twice.
  2234. *
  2235. * @param listener the new listener to add
  2236. * @see MouseEvent
  2237. * @see #removeMouseMotionListener(MouseMotionListener)
  2238. * @see #getMouseMotionListeners()
  2239. * @since 1.1
  2240. */
  2241. public synchronized void addMouseMotionListener(MouseMotionListener l)
  2242. {
  2243. mouseMotionListener = AWTEventMulticaster.add(mouseMotionListener, l);
  2244. if (mouseMotionListener != null)
  2245. enableEvents(AWTEvent.MOUSE_EVENT_MASK);
  2246. }
  2247. /**
  2248. * Removes the specified listener from the component. This is harmless if
  2249. * the listener was not previously registered.
  2250. *
  2251. * @param listener the listener to remove
  2252. * @see MouseEvent
  2253. * @see #addMouseMotionListener(MouseMotionListener)
  2254. * @see #getMouseMotionListeners()
  2255. * @since 1.1
  2256. */
  2257. public synchronized void removeMouseMotionListener(MouseMotionListener l)
  2258. {
  2259. mouseMotionListener = AWTEventMulticaster.remove(mouseMotionListener, l);
  2260. }
  2261. /**
  2262. * Returns an array of all specified listeners registered on this component.
  2263. *
  2264. * @return an array of listeners
  2265. * @see #addMouseMotionListener(MouseMotionListener)
  2266. * @see #removeMouseMotionListener(MouseMotionListener)
  2267. * @since 1.4
  2268. */
  2269. public synchronized MouseMotionListener[] getMouseMotionListeners()
  2270. {
  2271. return (MouseMotionListener[])
  2272. AWTEventMulticaster.getListeners(mouseMotionListener,
  2273. MouseMotionListener.class);
  2274. }
  2275. /**
  2276. * Adds the specified listener to this component. This is harmless if the
  2277. * listener is null, but if the listener has already been registered, it
  2278. * will now be registered twice.
  2279. *
  2280. * @param listener the new listener to add
  2281. * @see MouseEvent
  2282. * @see MouseWheelEvent
  2283. * @see #removeMouseWheelListener(MouseWheelListener)
  2284. * @see #getMouseWheelListeners()
  2285. * @since 1.4
  2286. */
  2287. public synchronized void addMouseWheelListener(MouseWheelListener l)
  2288. {
  2289. mouseWheelListener = AWTEventMulticaster.add(mouseWheelListener, l);
  2290. if (mouseWheelListener != null)
  2291. enableEvents(AWTEvent.MOUSE_WHEEL_EVENT_MASK);
  2292. }
  2293. /**
  2294. * Removes the specified listener from the component. This is harmless if
  2295. * the listener was not previously registered.
  2296. *
  2297. * @param listener the listener to remove
  2298. * @see MouseEvent
  2299. * @see MouseWheelEvent
  2300. * @see #addMouseWheelListener(MouseWheelListener)
  2301. * @see #getMouseWheelListeners()
  2302. * @since 1.4
  2303. */
  2304. public synchronized void removeMouseWheelListener(MouseWheelListener l)
  2305. {
  2306. mouseWheelListener = AWTEventMulticaster.remove(mouseWheelListener, l);
  2307. }
  2308. /**
  2309. * Returns an array of all specified listeners registered on this component.
  2310. *
  2311. * @return an array of listeners
  2312. * @see #addMouseWheelListener(MouseWheelListener)
  2313. * @see #removeMouseWheelListener(MouseWheelListener)
  2314. * @since 1.4
  2315. */
  2316. public synchronized MouseWheelListener[] getMouseWheelListeners()
  2317. {
  2318. return (MouseWheelListener[])
  2319. AWTEventMulticaster.getListeners(mouseWheelListener,
  2320. MouseWheelListener.class);
  2321. }
  2322. /**
  2323. * Adds the specified listener to this component. This is harmless if the
  2324. * listener is null, but if the listener has already been registered, it
  2325. * will now be registered twice.
  2326. *
  2327. * @param listener the new listener to add
  2328. * @see InputMethodEvent
  2329. * @see #removeInputMethodListener(InputMethodListener)
  2330. * @see #getInputMethodListeners()
  2331. * @see #getInputMethodRequests()
  2332. * @since 1.2
  2333. */
  2334. public synchronized void addInputMethodListener(InputMethodListener l)
  2335. {
  2336. inputMethodListener = AWTEventMulticaster.add(inputMethodListener, l);
  2337. if (inputMethodListener != null)
  2338. enableEvents(AWTEvent.INPUT_METHOD_EVENT_MASK);
  2339. }
  2340. /**
  2341. * Removes the specified listener from the component. This is harmless if
  2342. * the listener was not previously registered.
  2343. *
  2344. * @param listener the listener to remove
  2345. * @see InputMethodEvent
  2346. * @see #addInputMethodListener(InputMethodListener)
  2347. * @see #getInputMethodRequests()
  2348. * @since 1.2
  2349. */
  2350. public synchronized void removeInputMethodListener(InputMethodListener l)
  2351. {
  2352. inputMethodListener = AWTEventMulticaster.remove(inputMethodListener, l);
  2353. }
  2354. /**
  2355. * Returns an array of all specified listeners registered on this component.
  2356. *
  2357. * @return an array of listeners
  2358. * @see #addInputMethodListener(InputMethodListener)
  2359. * @see #removeInputMethodListener(InputMethodListener)
  2360. * @since 1.4
  2361. */
  2362. public synchronized InputMethodListener[] getInputMethodListeners()
  2363. {
  2364. return (InputMethodListener[])
  2365. AWTEventMulticaster.getListeners(inputMethodListener,
  2366. InputMethodListener.class);
  2367. }
  2368. /**
  2369. * Returns all registered EventListers of the given listenerType.
  2370. *
  2371. * @param listenerType the class of listeners to filter
  2372. * @return an array of registered listeners
  2373. * @see #getComponentListeners()
  2374. * @see #getFocusListeners()
  2375. * @see #getHierarchyListeners()
  2376. * @see #getHierarchyBoundsListeners()
  2377. * @see #getKeyListeners()
  2378. * @see #getMouseListeners()
  2379. * @see #getMouseMotionListeners()
  2380. * @see #getMouseWheelListeners()
  2381. * @see #getInputMethodListeners()
  2382. * @see #getPropertyChangeListeners()
  2383. * @since 1.3
  2384. */
  2385. public EventListener[] getListeners(Class listenerType)
  2386. {
  2387. if (listenerType == ComponentListener.class)
  2388. return getComponentListeners();
  2389. if (listenerType == FocusListener.class)
  2390. return getFocusListeners();
  2391. if (listenerType == HierarchyListener.class)
  2392. return getHierarchyListeners();
  2393. if (listenerType == HierarchyBoundsListener.class)
  2394. return getHierarchyBoundsListeners();
  2395. if (listenerType == KeyListener.class)
  2396. return getKeyListeners();
  2397. if (listenerType == MouseListener.class)
  2398. return getMouseListeners();
  2399. if (listenerType == MouseMotionListener.class)
  2400. return getMouseMotionListeners();
  2401. if (listenerType == MouseWheelListener.class)
  2402. return getMouseWheelListeners();
  2403. if (listenerType == InputMethodListener.class)
  2404. return getInputMethodListeners();
  2405. if (listenerType == PropertyChangeListener.class)
  2406. return getPropertyChangeListeners();
  2407. return (EventListener[]) Array.newInstance(listenerType, 0);
  2408. }
  2409. /**
  2410. * Returns the input method request handler, for subclasses which support
  2411. * on-the-spot text input. By default, input methods are handled by AWT,
  2412. * and this returns null.
  2413. *
  2414. * @return the input method handler, null by default
  2415. * @since 1.2
  2416. */
  2417. public InputMethodRequests getInputMethodRequests()
  2418. {
  2419. return null;
  2420. }
  2421. /**
  2422. * Gets the input context of this component, which is inherited from the
  2423. * parent unless this is overridden.
  2424. *
  2425. * @return the text input context
  2426. * @since 1.2
  2427. */
  2428. public InputContext getInputContext()
  2429. {
  2430. return parent == null ? null : parent.getInputContext();
  2431. }
  2432. /**
  2433. * Enables the specified events. The events to enable are specified
  2434. * by OR-ing together the desired masks from <code>AWTEvent</code>.
  2435. *
  2436. * <p>Events are enabled by default when a listener is attached to the
  2437. * component for that event type. This method can be used by subclasses
  2438. * to ensure the delivery of a specified event regardless of whether
  2439. * or not a listener is attached.
  2440. *
  2441. * @param eventsToEnable the desired events to enable
  2442. * @see #processEvent(AWTEvent)
  2443. * @see #disableEvents(long)
  2444. * @see AWTEvent
  2445. * @since 1.1
  2446. */
  2447. protected final void enableEvents(long eventsToEnable)
  2448. {
  2449. eventMask |= eventsToEnable;
  2450. // TODO: Unlike Sun's implementation, I think we should try and
  2451. // enable/disable events at the peer (gtk/X) level. This will avoid
  2452. // clogging the event pipeline with useless mousemove events that
  2453. // we arn't interested in, etc. This will involve extending the peer
  2454. // interface, but thats okay because the peer interfaces have been
  2455. // deprecated for a long time, and no longer feature in the
  2456. // API specification at all.
  2457. if (isLightweight() && parent != null)
  2458. parent.enableEvents(eventsToEnable);
  2459. else if (peer != null)
  2460. peer.setEventMask(eventMask);
  2461. }
  2462. /**
  2463. * Disables the specified events. The events to disable are specified
  2464. * by OR-ing together the desired masks from <code>AWTEvent</code>.
  2465. *
  2466. * @param eventsToDisable the desired events to disable
  2467. * @see #enableEvents(long)
  2468. * @since 1.1
  2469. */
  2470. protected final void disableEvents(long eventsToDisable)
  2471. {
  2472. eventMask &= ~eventsToDisable;
  2473. // forward new event mask to peer?
  2474. }
  2475. /**
  2476. * This is called by the EventQueue if two events with the same event id
  2477. * and owner component are queued. Returns a new combined event, or null if
  2478. * no combining is done. The coelesced events are currently mouse moves
  2479. * (intermediate ones are discarded) and paint events (a merged paint is
  2480. * created in place of the two events).
  2481. *
  2482. * @param existingEvent the event on the queue
  2483. * @param newEvent the new event that might be entered on the queue
  2484. * @return null if both events are kept, or the replacement coelesced event
  2485. */
  2486. protected AWTEvent coalesceEvents(AWTEvent existingEvent, AWTEvent newEvent)
  2487. {
  2488. switch (existingEvent.id)
  2489. {
  2490. case MouseEvent.MOUSE_MOVED:
  2491. case MouseEvent.MOUSE_DRAGGED:
  2492. // Just drop the old (intermediate) event and return the new one.
  2493. return newEvent;
  2494. case PaintEvent.PAINT:
  2495. case PaintEvent.UPDATE:
  2496. return coalescePaintEvents((PaintEvent) existingEvent,
  2497. (PaintEvent) newEvent);
  2498. default:
  2499. return null;
  2500. }
  2501. }
  2502. /**
  2503. * Processes the specified event. In this class, this method simply
  2504. * calls one of the more specific event handlers.
  2505. *
  2506. * @param event the event to process
  2507. * @throws NullPointerException if e is null
  2508. * @see #processComponentEvent(ComponentEvent)
  2509. * @see #processFocusEvent(FocusEvent)
  2510. * @see #processKeyEvent(KeyEvent)
  2511. * @see #processMouseEvent(MouseEvent)
  2512. * @see #processMouseMotionEvent(MouseEvent)
  2513. * @see #processInputMethodEvent(InputMethodEvent)
  2514. * @see #processHierarchyEvent(HierarchyEvent)
  2515. * @see #processMouseWheelEvent(MouseWheelEvent)
  2516. * @since 1.1
  2517. */
  2518. protected void processEvent(AWTEvent e)
  2519. {
  2520. /* Note: the order of these if statements are
  2521. important. Subclasses must be checked first. Eg. MouseEvent
  2522. must be checked before ComponentEvent, since a MouseEvent
  2523. object is also an instance of a ComponentEvent. */
  2524. if (e instanceof FocusEvent)
  2525. processFocusEvent((FocusEvent) e);
  2526. else if (e instanceof PaintEvent)
  2527. processPaintEvent((PaintEvent) e);
  2528. else if (e instanceof MouseWheelEvent)
  2529. processMouseWheelEvent((MouseWheelEvent) e);
  2530. else if (e instanceof MouseEvent)
  2531. {
  2532. if (e.id == MouseEvent.MOUSE_MOVED
  2533. || e.id == MouseEvent.MOUSE_DRAGGED)
  2534. processMouseMotionEvent((MouseEvent) e);
  2535. else
  2536. processMouseEvent((MouseEvent) e);
  2537. }
  2538. else if (e instanceof KeyEvent)
  2539. processKeyEvent((KeyEvent) e);
  2540. else if (e instanceof InputMethodEvent)
  2541. processInputMethodEvent((InputMethodEvent) e);
  2542. else if (e instanceof ComponentEvent)
  2543. processComponentEvent((ComponentEvent) e);
  2544. else if (e instanceof HierarchyEvent)
  2545. {
  2546. if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
  2547. processHierarchyEvent((HierarchyEvent) e);
  2548. else
  2549. processHierarchyBoundsEvent((HierarchyEvent) e);
  2550. }
  2551. }
  2552. /**
  2553. * Called when a component event is dispatched and component events are
  2554. * enabled. This method passes the event along to any listeners
  2555. * that are attached.
  2556. *
  2557. * @param event the <code>ComponentEvent</code> to process
  2558. * @throws NullPointerException if e is null
  2559. * @see ComponentListener
  2560. * @see #addComponentListener(ComponentListener)
  2561. * @see #enableEvents(long)
  2562. * @since 1.1
  2563. */
  2564. protected void processComponentEvent(ComponentEvent e)
  2565. {
  2566. if (componentListener == null)
  2567. return;
  2568. switch (e.id)
  2569. {
  2570. case ComponentEvent.COMPONENT_HIDDEN:
  2571. componentListener.componentHidden(e);
  2572. break;
  2573. case ComponentEvent.COMPONENT_MOVED:
  2574. componentListener.componentMoved(e);
  2575. break;
  2576. case ComponentEvent.COMPONENT_RESIZED:
  2577. componentListener.componentResized(e);
  2578. break;
  2579. case ComponentEvent.COMPONENT_SHOWN:
  2580. componentListener.componentShown(e);
  2581. break;
  2582. }
  2583. }
  2584. /**
  2585. * Called when a focus event is dispatched and component events are
  2586. * enabled. This method passes the event along to any listeners
  2587. * that are attached.
  2588. *
  2589. * @param event the <code>FocusEvent</code> to process
  2590. * @throws NullPointerException if e is null
  2591. * @see FocusListener
  2592. * @see #addFocusListener(FocusListener)
  2593. * @see #enableEvents(long)
  2594. * @since 1.1
  2595. */
  2596. protected void processFocusEvent(FocusEvent e)
  2597. {
  2598. if (focusListener == null)
  2599. return;
  2600. switch (e.id)
  2601. {
  2602. case FocusEvent.FOCUS_GAINED:
  2603. focusListener.focusGained(e);
  2604. break;
  2605. case FocusEvent.FOCUS_LOST:
  2606. focusListener.focusLost(e);
  2607. break;
  2608. }
  2609. }
  2610. /**
  2611. * Called when a key event is dispatched and component events are
  2612. * enabled. This method passes the event along to any listeners
  2613. * that are attached.
  2614. *
  2615. * @param event the <code>KeyEvent</code> to process
  2616. * @throws NullPointerException if e is null
  2617. * @see KeyListener
  2618. * @see #addKeyListener(KeyListener)
  2619. * @see #enableEvents(long)
  2620. * @since 1.1
  2621. */
  2622. protected void processKeyEvent(KeyEvent e)
  2623. {
  2624. if (keyListener == null)
  2625. return;
  2626. switch (e.id)
  2627. {
  2628. case KeyEvent.KEY_PRESSED:
  2629. keyListener.keyPressed(e);
  2630. break;
  2631. case KeyEvent.KEY_RELEASED:
  2632. keyListener.keyReleased(e);
  2633. break;
  2634. case KeyEvent.KEY_TYPED:
  2635. keyListener.keyTyped(e);
  2636. break;
  2637. }
  2638. }
  2639. /**
  2640. * Called when a regular mouse event is dispatched and component events are
  2641. * enabled. This method passes the event along to any listeners
  2642. * that are attached.
  2643. *
  2644. * @param event the <code>MouseEvent</code> to process
  2645. * @throws NullPointerException if e is null
  2646. * @see MouseListener
  2647. * @see #addMouseListener(MouseListener)
  2648. * @see #enableEvents(long)
  2649. * @since 1.1
  2650. */
  2651. protected void processMouseEvent(MouseEvent e)
  2652. {
  2653. if (mouseListener == null)
  2654. return;
  2655. switch (e.id)
  2656. {
  2657. case MouseEvent.MOUSE_CLICKED:
  2658. mouseListener.mouseClicked(e);
  2659. break;
  2660. case MouseEvent.MOUSE_ENTERED:
  2661. mouseListener.mouseEntered(e);
  2662. break;
  2663. case MouseEvent.MOUSE_EXITED:
  2664. mouseListener.mouseExited(e);
  2665. break;
  2666. case MouseEvent.MOUSE_PRESSED:
  2667. mouseListener.mousePressed(e);
  2668. break;
  2669. case MouseEvent.MOUSE_RELEASED:
  2670. mouseListener.mouseReleased(e);
  2671. break;
  2672. }
  2673. }
  2674. /**
  2675. * Called when a mouse motion event is dispatched and component events are
  2676. * enabled. This method passes the event along to any listeners
  2677. * that are attached.
  2678. *
  2679. * @param event the <code>MouseMotionEvent</code> to process
  2680. * @throws NullPointerException if e is null
  2681. * @see MouseMotionListener
  2682. * @see #addMouseMotionListener(MouseMotionListener)
  2683. * @see #enableEvents(long)
  2684. * @since 1.1
  2685. */
  2686. protected void processMouseMotionEvent(MouseEvent e)
  2687. {
  2688. if (mouseMotionListener == null)
  2689. return;
  2690. switch (e.id)
  2691. {
  2692. case MouseEvent.MOUSE_DRAGGED:
  2693. mouseMotionListener.mouseDragged(e);
  2694. break;
  2695. case MouseEvent.MOUSE_MOVED:
  2696. mouseMotionListener.mouseMoved(e);
  2697. break;
  2698. }
  2699. }
  2700. /**
  2701. * Called when a mouse wheel event is dispatched and component events are
  2702. * enabled. This method passes the event along to any listeners that are
  2703. * attached.
  2704. *
  2705. * @param event the <code>MouseWheelEvent</code> to process
  2706. * @throws NullPointerException if e is null
  2707. * @see MouseWheelListener
  2708. * @see #addMouseWheelListener(MouseWheelListener)
  2709. * @see #enableEvents(long)
  2710. * @since 1.4
  2711. */
  2712. protected void processMouseWheelEvent(MouseWheelEvent e)
  2713. {
  2714. if (mouseWheelListener != null
  2715. && e.id == MouseEvent.MOUSE_WHEEL)
  2716. mouseWheelListener.mouseWheelMoved(e);
  2717. }
  2718. /**
  2719. * Called when an input method event is dispatched and component events are
  2720. * enabled. This method passes the event along to any listeners that are
  2721. * attached.
  2722. *
  2723. * @param event the <code>InputMethodEvent</code> to process
  2724. * @throws NullPointerException if e is null
  2725. * @see InputMethodListener
  2726. * @see #addInputMethodListener(InputMethodListener)
  2727. * @see #enableEvents(long)
  2728. * @since 1.2
  2729. */
  2730. protected void processInputMethodEvent(InputMethodEvent e)
  2731. {
  2732. if (inputMethodListener == null)
  2733. return;
  2734. switch (e.id)
  2735. {
  2736. case InputMethodEvent.CARET_POSITION_CHANGED:
  2737. inputMethodListener.caretPositionChanged(e);
  2738. break;
  2739. case InputMethodEvent.INPUT_METHOD_TEXT_CHANGED:
  2740. inputMethodListener.inputMethodTextChanged(e);
  2741. break;
  2742. }
  2743. }
  2744. /**
  2745. * Called when a hierarchy change event is dispatched and component events
  2746. * are enabled. This method passes the event along to any listeners that are
  2747. * attached.
  2748. *
  2749. * @param event the <code>HierarchyEvent</code> to process
  2750. * @throws NullPointerException if e is null
  2751. * @see HierarchyListener
  2752. * @see #addHierarchyListener(HierarchyListener)
  2753. * @see #enableEvents(long)
  2754. * @since 1.3
  2755. */
  2756. protected void processHierarchyEvent(HierarchyEvent e)
  2757. {
  2758. if (hierarchyListener == null)
  2759. return;
  2760. if (e.id == HierarchyEvent.HIERARCHY_CHANGED)
  2761. hierarchyListener.hierarchyChanged(e);
  2762. }
  2763. /**
  2764. * Called when a hierarchy bounds event is dispatched and component events
  2765. * are enabled. This method passes the event along to any listeners that are
  2766. * attached.
  2767. *
  2768. * @param event the <code>HierarchyEvent</code> to process
  2769. * @throws NullPointerException if e is null
  2770. * @see HierarchyBoundsListener
  2771. * @see #addHierarchyBoundsListener(HierarchyBoundsListener)
  2772. * @see #enableEvents(long)
  2773. * @since 1.3
  2774. */
  2775. protected void processHierarchyBoundsEvent(HierarchyEvent e)
  2776. {
  2777. if (hierarchyBoundsListener == null)
  2778. return;
  2779. switch (e.id)
  2780. {
  2781. case HierarchyEvent.ANCESTOR_MOVED:
  2782. hierarchyBoundsListener.ancestorMoved(e);
  2783. break;
  2784. case HierarchyEvent.ANCESTOR_RESIZED:
  2785. hierarchyBoundsListener.ancestorResized(e);
  2786. break;
  2787. }
  2788. }
  2789. /**
  2790. * AWT 1.0 event processor.
  2791. *
  2792. * @param evt the event to handle
  2793. * @return false: since the method was deprecated, the return has no meaning
  2794. * @deprecated use {@link #processEvent(AWTEvent)} instead
  2795. */
  2796. public boolean handleEvent(Event evt)
  2797. {
  2798. // XXX Add backward compatibility handling.
  2799. return false;
  2800. }
  2801. /**
  2802. * AWT 1.0 mouse event.
  2803. *
  2804. * @param evt the event to handle
  2805. * @param x the x coordinate, ignored
  2806. * @param y the y coordinate, ignored
  2807. * @return false: since the method was deprecated, the return has no meaning
  2808. * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
  2809. */
  2810. public boolean mouseDown(Event evt, int x, int y)
  2811. {
  2812. // XXX Add backward compatibility handling.
  2813. return false;
  2814. }
  2815. /**
  2816. * AWT 1.0 mouse event.
  2817. *
  2818. * @param evt the event to handle
  2819. * @param x the x coordinate, ignored
  2820. * @param y the y coordinate, ignored
  2821. * @return false: since the method was deprecated, the return has no meaning
  2822. * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead
  2823. */
  2824. public boolean mouseDrag(Event evt, int x, int y)
  2825. {
  2826. // XXX Add backward compatibility handling.
  2827. return false;
  2828. }
  2829. /**
  2830. * AWT 1.0 mouse event.
  2831. *
  2832. * @param evt the event to handle
  2833. * @param x the x coordinate, ignored
  2834. * @param y the y coordinate, ignored
  2835. * @return false: since the method was deprecated, the return has no meaning
  2836. * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
  2837. */
  2838. public boolean mouseUp(Event evt, int x, int y)
  2839. {
  2840. // XXX Add backward compatibility handling.
  2841. return false;
  2842. }
  2843. /**
  2844. * AWT 1.0 mouse event.
  2845. *
  2846. * @param evt the event to handle
  2847. * @param x the x coordinate, ignored
  2848. * @param y the y coordinate, ignored
  2849. * @return false: since the method was deprecated, the return has no meaning
  2850. * @deprecated use {@link #processMouseMotionEvent(MouseEvent)} instead
  2851. */
  2852. public boolean mouseMove(Event evt, int x, int y)
  2853. {
  2854. // XXX Add backward compatibility handling.
  2855. return false;
  2856. }
  2857. /**
  2858. * AWT 1.0 mouse event.
  2859. *
  2860. * @param evt the event to handle
  2861. * @param x the x coordinate, ignored
  2862. * @param y the y coordinate, ignored
  2863. * @return false: since the method was deprecated, the return has no meaning
  2864. * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
  2865. */
  2866. public boolean mouseEnter(Event evt, int x, int y)
  2867. {
  2868. // XXX Add backward compatibility handling.
  2869. return false;
  2870. }
  2871. /**
  2872. * AWT 1.0 mouse event.
  2873. *
  2874. * @param evt the event to handle
  2875. * @param x the x coordinate, ignored
  2876. * @param y the y coordinate, ignored
  2877. * @return false: since the method was deprecated, the return has no meaning
  2878. * @deprecated use {@link #processMouseEvent(MouseEvent)} instead
  2879. */
  2880. public boolean mouseExit(Event evt, int x, int y)
  2881. {
  2882. // XXX Add backward compatibility handling.
  2883. return false;
  2884. }
  2885. /**
  2886. * AWT 1.0 key press event.
  2887. *
  2888. * @param evt the event to handle
  2889. * @param key the key pressed, ignored
  2890. * @return false: since the method was deprecated, the return has no meaning
  2891. * @deprecated use {@link #processKeyEvent(KeyEvent)} instead
  2892. */
  2893. public boolean keyDown(Event evt, int key)
  2894. {
  2895. // XXX Add backward compatibility handling.
  2896. return false;
  2897. }
  2898. /**
  2899. * AWT 1.0 key press event.
  2900. *
  2901. * @param evt the event to handle
  2902. * @param key the key pressed, ignored
  2903. * @return false: since the method was deprecated, the return has no meaning
  2904. * @deprecated use {@link #processKeyEvent(KeyEvent)} instead
  2905. */
  2906. public boolean keyUp(Event evt, int key)
  2907. {
  2908. // XXX Add backward compatibility handling.
  2909. return false;
  2910. }
  2911. /**
  2912. * AWT 1.0 action event processor.
  2913. *
  2914. * @param evt the event to handle
  2915. * @param what the object acted on, ignored
  2916. * @return false: since the method was deprecated, the return has no meaning
  2917. * @deprecated in classes which support actions, use
  2918. * <code>processActionEvent(ActionEvent)</code> instead
  2919. */
  2920. public boolean action(Event evt, Object what)
  2921. {
  2922. // XXX Add backward compatibility handling.
  2923. return false;
  2924. }
  2925. /**
  2926. * Called to inform this component it has been added to a container.
  2927. * A native peer - if any - is created at this time. This method is
  2928. * called automatically by the AWT system and should not be called by
  2929. * user level code.
  2930. *
  2931. * @see #isDisplayable()
  2932. * @see #removeNotify()
  2933. */
  2934. public void addNotify()
  2935. {
  2936. if (peer == null)
  2937. peer = getToolkit().createComponent(this);
  2938. /* Now that all the children has gotten their peers, we should
  2939. have the event mask needed for this component and its
  2940. lightweight subcomponents. */
  2941. peer.setEventMask(eventMask);
  2942. /* We do not invalidate here, but rather leave that job up to
  2943. the peer. For efficiency, the peer can choose not to
  2944. invalidate if it is happy with the current dimensions,
  2945. etc. */
  2946. }
  2947. /**
  2948. * Called to inform this component is has been removed from its
  2949. * container. Its native peer - if any - is destroyed at this time.
  2950. * This method is called automatically by the AWT system and should
  2951. * not be called by user level code.
  2952. *
  2953. * @see #isDisplayable()
  2954. * @see #addNotify()
  2955. */
  2956. public void removeNotify()
  2957. {
  2958. if (peer != null)
  2959. peer.dispose();
  2960. peer = null;
  2961. }
  2962. /**
  2963. * AWT 1.0 focus event.
  2964. *
  2965. * @param evt the event to handle
  2966. * @param what the Object focused, ignored
  2967. * @return false: since the method was deprecated, the return has no meaning
  2968. * @deprecated use {@link #processFocusEvent(FocusEvent)} instead
  2969. */
  2970. public boolean gotFocus(Event evt, Object what)
  2971. {
  2972. // XXX Add backward compatibility handling.
  2973. return false;
  2974. }
  2975. /**
  2976. * AWT 1.0 focus event.
  2977. *
  2978. * @param evt the event to handle
  2979. * @param what the Object focused, ignored
  2980. * @return false: since the method was deprecated, the return has no meaning
  2981. * @deprecated use {@link #processFocusEvent(FocusEvent)} instead
  2982. */
  2983. public boolean lostFocus(Event evt, Object what)
  2984. {
  2985. // XXX Add backward compatibility handling.
  2986. return false;
  2987. }
  2988. /**
  2989. * Tests whether or not this component is in the group that can be
  2990. * traversed using the keyboard traversal mechanism (such as the TAB key).
  2991. *
  2992. * @return true if the component is traversed via the TAB key
  2993. * @see #setFocusable(boolean)
  2994. * @since 1.1
  2995. * @deprecated use {@link #isFocusable()} instead
  2996. */
  2997. public boolean isFocusTraversable()
  2998. {
  2999. return enabled && visible && (peer == null || peer.isFocusTraversable());
  3000. }
  3001. /**
  3002. * Tests if this component can receive focus.
  3003. *
  3004. * @return true if this component can receive focus
  3005. * @since 1.4
  3006. */
  3007. public boolean isFocusable()
  3008. {
  3009. return focusable;
  3010. }
  3011. /**
  3012. * Specify whether this component can receive focus.
  3013. *
  3014. * @param focusable the new focusable status
  3015. * @since 1.4
  3016. */
  3017. public void setFocusable(boolean focusable)
  3018. {
  3019. firePropertyChange("focusable", this.focusable, focusable);
  3020. this.focusable = focusable;
  3021. }
  3022. /**
  3023. * Sets the focus traversal keys for a given type of focus events. Normally,
  3024. * the default values should match the operating system's native choices. To
  3025. * disable a given traversal, use <code>Collections.EMPTY_SET</code>. The
  3026. * event dispatcher will consume PRESSED, RELEASED, and TYPED events for the
  3027. * specified key, although focus can only transfer on PRESSED or RELEASED.
  3028. *
  3029. * <p>The defauts are:
  3030. * <table>
  3031. * <th><td>Identifier</td><td>Meaning</td><td>Default</td></th>
  3032. * <tr><td>KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS</td>
  3033. * <td>Normal forward traversal</td>
  3034. * <td>TAB on KEY_PRESSED, Ctrl-TAB on KEY_PRESSED</td></tr>
  3035. * <tr><td>KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS</td>
  3036. * <td>Normal backward traversal</td>
  3037. * <td>Shift-TAB on KEY_PRESSED, Ctrl-Shift-TAB on KEY_PRESSED</td></tr>
  3038. * <tr><td>KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS</td>
  3039. * <td>Go up a traversal cycle</td><td>None</td></tr>
  3040. * </table>
  3041. *
  3042. * <p>Specifying null allows inheritance from the parent, or from the current
  3043. * KeyboardFocusManager default set. If not null, the set must contain only
  3044. * AWTKeyStrokes that are not already focus keys and are not KEY_TYPED
  3045. * events.
  3046. *
  3047. * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or
  3048. * UP_CYCLE_TRAVERSAL_KEYS
  3049. * @param keystrokes a set of keys, or null
  3050. * @throws IllegalArgumentException if id or keystrokes is invalid
  3051. * @see #getFocusTraversalKeys(int)
  3052. * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
  3053. * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
  3054. * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
  3055. * @since 1.4
  3056. */
  3057. public void setFocusTraversalKeys(int id, Set keystrokes)
  3058. {
  3059. if (keystrokes == null)
  3060. throw new IllegalArgumentException();
  3061. Set sa;
  3062. Set sb;
  3063. String name;
  3064. switch (id)
  3065. {
  3066. case KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS:
  3067. sa = getFocusTraversalKeys
  3068. (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
  3069. sb = getFocusTraversalKeys
  3070. (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
  3071. name = "forwardFocusTraversalKeys";
  3072. break;
  3073. case KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS:
  3074. sa = getFocusTraversalKeys
  3075. (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
  3076. sb = getFocusTraversalKeys
  3077. (KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS);
  3078. name = "backwardFocusTraversalKeys";
  3079. break;
  3080. case KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS:
  3081. sa = getFocusTraversalKeys
  3082. (KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
  3083. sb = getFocusTraversalKeys
  3084. (KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
  3085. name = "upCycleFocusTraversalKeys";
  3086. break;
  3087. default:
  3088. throw new IllegalArgumentException();
  3089. }
  3090. int i = keystrokes.size();
  3091. Iterator iter = keystrokes.iterator();
  3092. while (--i >= 0)
  3093. {
  3094. Object o = iter.next();
  3095. if (! (o instanceof AWTKeyStroke)
  3096. || sa.contains(o) || sb.contains(o)
  3097. || ((AWTKeyStroke) o).keyCode == KeyEvent.VK_UNDEFINED)
  3098. throw new IllegalArgumentException();
  3099. }
  3100. if (focusTraversalKeys == null)
  3101. focusTraversalKeys = new Set[3];
  3102. keystrokes = Collections.unmodifiableSet(new HashSet(keystrokes));
  3103. firePropertyChange(name, focusTraversalKeys[id], keystrokes);
  3104. focusTraversalKeys[id] = keystrokes;
  3105. }
  3106. /**
  3107. * Returns the set of keys for a given focus traversal action, as defined
  3108. * in <code>setFocusTraversalKeys</code>. If not set, this is inherited from
  3109. * the parent component, which may have gotten it from the
  3110. * KeyboardFocusManager.
  3111. *
  3112. * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or
  3113. * UP_CYCLE_TRAVERSAL_KEYS
  3114. * @throws IllegalArgumentException if id is invalid
  3115. * @see #setFocusTraversalKeys(int, Set)
  3116. * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
  3117. * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
  3118. * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
  3119. * @since 1.4
  3120. */
  3121. public Set getFocusTraversalKeys(int id)
  3122. {
  3123. if (id < KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
  3124. || id > KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
  3125. throw new IllegalArgumentException();
  3126. Set s = null;
  3127. if (focusTraversalKeys != null)
  3128. s = focusTraversalKeys[id];
  3129. if (s == null && parent != null)
  3130. s = parent.getFocusTraversalKeys(id);
  3131. return s == null ? (KeyboardFocusManager.getCurrentKeyboardFocusManager()
  3132. .getDefaultFocusTraversalKeys(id)) : s;
  3133. }
  3134. /**
  3135. * Tests whether the focus traversal keys for a given action are explicitly
  3136. * set or inherited.
  3137. *
  3138. * @param id one of FORWARD_TRAVERSAL_KEYS, BACKWARD_TRAVERSAL_KEYS, or
  3139. * UP_CYCLE_TRAVERSAL_KEYS
  3140. * @return true if that set is explicitly specified
  3141. * @throws IllegalArgumentException if id is invalid
  3142. * @see #getFocusTraversalKeys(int)
  3143. * @see KeyboardFocusManager#FORWARD_TRAVERSAL_KEYS
  3144. * @see KeyboardFocusManager#BACKWARD_TRAVERSAL_KEYS
  3145. * @see KeyboardFocusManager#UP_CYCLE_TRAVERSAL_KEYS
  3146. * @since 1.4
  3147. */
  3148. public boolean areFocusTraversalKeysSet(int id)
  3149. {
  3150. if (id < KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS
  3151. || id > KeyboardFocusManager.UP_CYCLE_TRAVERSAL_KEYS)
  3152. throw new IllegalArgumentException();
  3153. return focusTraversalKeys != null && focusTraversalKeys[id] != null;
  3154. }
  3155. /**
  3156. * Sets whether focus traversal keys are enabled, which consumes traversal
  3157. * keys and performs the focus event automatically.
  3158. *
  3159. * @param focusTraversalKeysEnabled the new value of the flag
  3160. * @see #getFocusTraversalKeysEnabled()
  3161. * @see #setFocusTraversalKeys(int, Set)
  3162. * @see #getFocusTraversalKeys(int)
  3163. * @since 1.4
  3164. */
  3165. public void setFocusTraversalKeysEnabled(boolean focusTraversalKeysEnabled)
  3166. {
  3167. firePropertyChange("focusTraversalKeysEnabled",
  3168. this.focusTraversalKeysEnabled,
  3169. focusTraversalKeysEnabled);
  3170. this.focusTraversalKeysEnabled = focusTraversalKeysEnabled;
  3171. }
  3172. /**
  3173. * Tests whether focus traversal keys are enabled. If they are, then focus
  3174. * traversal keys are consumed and focus events performed automatically,
  3175. * without the component seeing the keystrokes.
  3176. *
  3177. * @return true if focus traversal is enabled
  3178. * @see #setFocusTraversalKeysEnabled(boolean)
  3179. * @see #setFocusTraversalKeys(int, Set)
  3180. * @see #getFocusTraversalKeys(int)
  3181. * @since 1.4
  3182. */
  3183. public boolean getFocusTraversalKeysEnabled()
  3184. {
  3185. return focusTraversalKeysEnabled;
  3186. }
  3187. /**
  3188. * Requests that this component be given focus. A <code>FOCUS_GAINED</code>
  3189. * event will be fired if and only if this request is successful. To be
  3190. * successful, the component must be displayable, visible, and focusable,
  3191. * and the top-level Window must be able to receive focus. Thus, this
  3192. * request may fail, or be delayed until the window receives focus. It is
  3193. * recommended that <code>requestFocusInWindow</code> be used where
  3194. * possible to be more platform-independent.
  3195. *
  3196. * @see #requestFocusInWindow()
  3197. * @see FocusEvent
  3198. * @see #addFocusListener(FocusListener)
  3199. * @see #isFocusable()
  3200. * @see #isDisplayable()
  3201. * @see KeyboardFocusManager#clearGlobalFocusOwner()
  3202. */
  3203. public void requestFocus()
  3204. {
  3205. // If there's no peer then this component can't get the focus. We
  3206. // treat it as a silent rejection of the request.
  3207. if (peer != null)
  3208. peer.requestFocus();
  3209. }
  3210. /**
  3211. * Requests that this component be given focus. A <code>FOCUS_GAINED</code>
  3212. * event will be fired if and only if this request is successful. To be
  3213. * successful, the component must be displayable, visible, and focusable,
  3214. * and the top-level Window must be able to receive focus. Thus, this
  3215. * request may fail, or be delayed until the window receives focus. It is
  3216. * recommended that <code>requestFocusInWindow</code> be used where
  3217. * possible to be more platform-independent.
  3218. *
  3219. * <p>If the return value is false, the request is guaranteed to fail. If
  3220. * it is true, it will likely succeed unless the action is vetoed or
  3221. * something in the native windowing system intervenes. The temporary flag,
  3222. * and thus this method in general, is not designed for public use; rather
  3223. * it is a hook for lightweight components to notify their container in
  3224. * an attempt to reduce the amount of repainting necessary.
  3225. *
  3226. * @param temporary true if the focus request is temporary
  3227. * @return true if the request has a chance of success
  3228. * @see #requestFocusInWindow()
  3229. * @see FocusEvent
  3230. * @see #addFocusListener(FocusListener)
  3231. * @see #isFocusable()
  3232. * @see #isDisplayable()
  3233. * @see KeyboardFocusManager#clearGlobalFocusOwner()
  3234. * @since 1.4
  3235. */
  3236. protected boolean requestFocus(boolean temporary)
  3237. {
  3238. // XXX Implement correctly.
  3239. requestFocus();
  3240. return true;
  3241. }
  3242. /**
  3243. * Requests that this component be given focus, if it resides in the
  3244. * top-level window which already has focus. A <code>FOCUS_GAINED</code>
  3245. * event will be fired if and only if this request is successful. To be
  3246. * successful, the component must be displayable, visible, and focusable,
  3247. * and the top-level Window must be focused.
  3248. *
  3249. * <p>If the return value is false, the request is guaranteed to fail. If
  3250. * it is true, it will likely succeed unless the action is vetoed or
  3251. * something in the native windowing system intervenes. The temporary flag,
  3252. * and thus this method in general, is not designed for public use; rather
  3253. * it is a hook for lightweight components to notify their container in
  3254. * an attempt to reduce the amount of repainting necessary.
  3255. *
  3256. * @return true if the request has a chance of success
  3257. * @see #requestFocus()
  3258. * @see FocusEvent
  3259. * @see #addFocusListener(FocusListener)
  3260. * @see #isFocusable()
  3261. * @see #isDisplayable()
  3262. * @see KeyboardFocusManager#clearGlobalFocusOwner()
  3263. * @since 1.4
  3264. */
  3265. public boolean requestFocusInWindow()
  3266. {
  3267. // XXX Implement correctly.
  3268. requestFocus();
  3269. return true;
  3270. }
  3271. /**
  3272. * Requests that this component be given focus, if it resides in the
  3273. * top-level window which already has focus. A <code>FOCUS_GAINED</code>
  3274. * event will be fired if and only if this request is successful. To be
  3275. * successful, the component must be displayable, visible, and focusable,
  3276. * and the top-level Window must be focused.
  3277. *
  3278. * <p>If the return value is false, the request is guaranteed to fail. If
  3279. * it is true, it will likely succeed unless the action is vetoed or
  3280. * something in the native windowing system intervenes. The temporary flag,
  3281. * and thus this method in general, is not designed for public use; rather
  3282. * it is a hook for lightweight components to notify their container in
  3283. * an attempt to reduce the amount of repainting necessary.
  3284. *
  3285. * @param temporary true if the focus request is temporary
  3286. * @return true if the request has a chance of success
  3287. * @see #requestFocus()
  3288. * @see FocusEvent
  3289. * @see #addFocusListener(FocusListener)
  3290. * @see #isFocusable()
  3291. * @see #isDisplayable()
  3292. * @see KeyboardFocusManager#clearGlobalFocusOwner()
  3293. * @since 1.4
  3294. */
  3295. protected boolean requestFocusInWindow(boolean temporary)
  3296. {
  3297. // XXX Implement correctly.
  3298. requestFocus();
  3299. return true;
  3300. }
  3301. /**
  3302. * Transfers focus to the next component in the focus traversal order, as
  3303. * though this were the current focus owner.
  3304. *
  3305. * @see #requestFocus()
  3306. * @since 1.1
  3307. */
  3308. public void transferFocus()
  3309. {
  3310. Component next;
  3311. if (parent == null)
  3312. next = findNextFocusComponent(null);
  3313. else
  3314. next = parent.findNextFocusComponent(this);
  3315. if (next != null && next != this)
  3316. next.requestFocus();
  3317. }
  3318. /**
  3319. * Returns the root container that owns the focus cycle where this component
  3320. * resides. A focus cycle root is in two cycles, one as the ancestor, and
  3321. * one as the focusable element; this call always returns the ancestor.
  3322. *
  3323. * @return the ancestor container that owns the focus cycle
  3324. * @since 1.4
  3325. */
  3326. public Container getFocusCycleRootAncestor()
  3327. {
  3328. // XXX Implement.
  3329. throw new Error("not implemented");
  3330. }
  3331. /**
  3332. * Tests if the container is the ancestor of the focus cycle that this
  3333. * component belongs to.
  3334. *
  3335. * @param c the container to test
  3336. * @return true if c is the focus cycle root
  3337. * @since 1.4
  3338. */
  3339. public boolean isFocusCycleRoot(Container c)
  3340. {
  3341. return c == getFocusCycleRootAncestor();
  3342. }
  3343. /**
  3344. * AWT 1.0 focus event processor.
  3345. *
  3346. * @deprecated use {@link #transferFocus()} instead
  3347. */
  3348. public void nextFocus()
  3349. {
  3350. transferFocus();
  3351. }
  3352. /**
  3353. * Transfers focus to the previous component in the focus traversal order, as
  3354. * though this were the current focus owner.
  3355. *
  3356. * @see #requestFocus()
  3357. * @since 1.4
  3358. */
  3359. public void transferFocusBackward()
  3360. {
  3361. // XXX Implement.
  3362. throw new Error("not implemented");
  3363. }
  3364. /**
  3365. * Transfers focus to the focus cycle root of this component. However, if
  3366. * this is a Window, the default focus owner in the window in the current
  3367. * focus cycle is focused instead.
  3368. *
  3369. * @see #requestFocus()
  3370. * @see #isFocusCycleRoot()
  3371. * @since 1.4
  3372. */
  3373. public void transferFocusUpCycle()
  3374. {
  3375. // XXX Implement.
  3376. throw new Error("not implemented");
  3377. }
  3378. /**
  3379. * Tests if this component is the focus owner. Use {@link #isFocusOwner()}
  3380. * instead.
  3381. *
  3382. * @return true if this component owns focus
  3383. * @since 1.2
  3384. */
  3385. public boolean hasFocus()
  3386. {
  3387. return isFocusOwner();
  3388. }
  3389. /**
  3390. * Tests if this component is the focus owner.
  3391. *
  3392. * @return true if this component owns focus
  3393. * @since 1.4
  3394. */
  3395. public boolean isFocusOwner()
  3396. {
  3397. // XXX Implement.
  3398. throw new Error("not implemented");
  3399. }
  3400. /**
  3401. * Adds the specified popup menu to this component.
  3402. *
  3403. * @param menu the popup menu to be added
  3404. * @see #remove(MenuComponent)
  3405. * @since 1.1
  3406. */
  3407. public synchronized void add(PopupMenu popup)
  3408. {
  3409. if (popups == null)
  3410. popups = new Vector();
  3411. popups.add(popup);
  3412. }
  3413. /**
  3414. * Removes the specified popup menu from this component.
  3415. *
  3416. * @param menu the popup menu to remove
  3417. * @see #add(PopupMenu)
  3418. * @since 1.1
  3419. */
  3420. public synchronized void remove(MenuComponent popup)
  3421. {
  3422. if (popups != null)
  3423. popups.remove(popup);
  3424. }
  3425. /**
  3426. * Returns a debugging string representing this component. The string may
  3427. * be empty but not null.
  3428. *
  3429. * @return a string representing this component
  3430. */
  3431. protected String paramString()
  3432. {
  3433. StringBuffer param = new StringBuffer();
  3434. String name = getName();
  3435. if (name != null)
  3436. param.append(name).append(",");
  3437. param.append(width).append("x").append(height).append("+").append(x)
  3438. .append("+").append(y);
  3439. if (! isValid())
  3440. param.append(",invalid");
  3441. if (! isVisible())
  3442. param.append(",invisible");
  3443. if (! isEnabled())
  3444. param.append(",disabled");
  3445. if (! isOpaque())
  3446. param.append(",translucent");
  3447. if (isDoubleBuffered())
  3448. param.append(",doublebuffered");
  3449. return param.toString();
  3450. }
  3451. /**
  3452. * Returns a string representation of this component. This is implemented
  3453. * as <code>getClass().getName() + '[' + paramString() + ']'</code>.
  3454. *
  3455. * @return a string representation of this component
  3456. */
  3457. public String toString()
  3458. {
  3459. return getClass().getName() + '[' + paramString() + ']';
  3460. }
  3461. /**
  3462. * Prints a listing of this component to <code>System.out</code>.
  3463. *
  3464. * @see #list(PrintStream)
  3465. */
  3466. public void list()
  3467. {
  3468. list(System.out, 0);
  3469. }
  3470. /**
  3471. * Prints a listing of this component to the specified print stream.
  3472. *
  3473. * @param stream the <code>PrintStream</code> to print to
  3474. */
  3475. public void list(PrintStream out)
  3476. {
  3477. list(out, 0);
  3478. }
  3479. /**
  3480. * Prints a listing of this component to the specified print stream,
  3481. * starting at the specified indentation point.
  3482. *
  3483. * @param stream the <code>PrintStream</code> to print to
  3484. * @param indent the indentation point
  3485. */
  3486. public void list(PrintStream out, int indent)
  3487. {
  3488. for (int i = 0; i < indent; ++i)
  3489. out.print(' ');
  3490. out.println(toString());
  3491. }
  3492. /**
  3493. * Prints a listing of this component to the specified print writer.
  3494. *
  3495. * @param writer the <code>PrintWrinter</code> to print to
  3496. * @since 1.1
  3497. */
  3498. public void list(PrintWriter out)
  3499. {
  3500. list(out, 0);
  3501. }
  3502. /**
  3503. * Prints a listing of this component to the specified print writer,
  3504. * starting at the specified indentation point.
  3505. *
  3506. * @param writer the <code>PrintWriter</code> to print to
  3507. * @param indent the indentation point
  3508. * @since 1.1
  3509. */
  3510. public void list(PrintWriter out, int indent)
  3511. {
  3512. for (int i = 0; i < indent; ++i)
  3513. out.print(' ');
  3514. out.println(toString());
  3515. }
  3516. /**
  3517. * Adds the specified property listener to this component. This is harmless
  3518. * if the listener is null, but if the listener has already been registered,
  3519. * it will now be registered twice. The property listener ignores inherited
  3520. * properties. Recognized properties include:<br>
  3521. * <ul>
  3522. * <li>the font (<code>"font"</code>)</li>
  3523. * <li>the background color (<code>"background"</code>)</li>
  3524. * <li>the foreground color (<code>"foreground"</code>)</li>
  3525. * <li>the focusability (<code>"focusable"</code>)</li>
  3526. * <li>the focus key traversal enabled state
  3527. * (<code>"focusTraversalKeysEnabled"</code>)</li>
  3528. * <li>the set of forward traversal keys
  3529. * (<code>"forwardFocusTraversalKeys"</code>)</li>
  3530. * <li>the set of backward traversal keys
  3531. * (<code>"backwardFocusTraversalKeys"</code>)</li>
  3532. * <li>the set of up-cycle traversal keys
  3533. * (<code>"upCycleFocusTraversalKeys"</code>)</li>
  3534. * </ul>
  3535. *
  3536. * @param listener the new listener to add
  3537. * @see #removePropertyChangeListener(PropertyChangeListener)
  3538. * @see #getPropertyChangeListeners()
  3539. * @see #addPropertyChangeListener(String, PropertyChangeListener)
  3540. * @since 1.1
  3541. */
  3542. public void addPropertyChangeListener(PropertyChangeListener listener)
  3543. {
  3544. if (changeSupport == null)
  3545. changeSupport = new PropertyChangeSupport(this);
  3546. changeSupport.addPropertyChangeListener(listener);
  3547. }
  3548. /**
  3549. * Removes the specified property listener from the component. This is
  3550. * harmless if the listener was not previously registered.
  3551. *
  3552. * @param listener the listener to remove
  3553. * @see #addPropertyChangeListener(PropertyChangeListener)
  3554. * @see #getPropertyChangeListeners()
  3555. * @see #removePropertyChangeListener(String, PropertyChangeListener)
  3556. * @since 1.1
  3557. */
  3558. public void removePropertyChangeListener(PropertyChangeListener listener)
  3559. {
  3560. if (changeSupport != null)
  3561. changeSupport.removePropertyChangeListener(listener);
  3562. }
  3563. /**
  3564. * Returns an array of all specified listeners registered on this component.
  3565. *
  3566. * @return an array of listeners
  3567. * @see #addPropertyChangeListener(PropertyChangeListener)
  3568. * @see #removePropertyChangeListener(PropertyChangeListener)
  3569. * @see #getPropertyChangeListeners(String)
  3570. * @since 1.4
  3571. */
  3572. public PropertyChangeListener[] getPropertyChangeListeners()
  3573. {
  3574. return changeSupport == null ? new PropertyChangeListener[0]
  3575. : changeSupport.getPropertyChangeListeners();
  3576. }
  3577. /**
  3578. * Adds the specified property listener to this component. This is harmless
  3579. * if the listener is null, but if the listener has already been registered,
  3580. * it will now be registered twice. The property listener ignores inherited
  3581. * properties. The listener is keyed to a single property. Recognized
  3582. * properties include:<br>
  3583. * <ul>
  3584. * <li>the font (<code>"font"</code>)</li>
  3585. * <li>the background color (<code>"background"</code>)</li>
  3586. * <li>the foreground color (<code>"foreground"</code>)</li>
  3587. * <li>the focusability (<code>"focusable"</code>)</li>
  3588. * <li>the focus key traversal enabled state
  3589. * (<code>"focusTraversalKeysEnabled"</code>)</li>
  3590. * <li>the set of forward traversal keys
  3591. * (<code>"forwardFocusTraversalKeys"</code>)</li>
  3592. p * <li>the set of backward traversal keys
  3593. * (<code>"backwardFocusTraversalKeys"</code>)</li>
  3594. * <li>the set of up-cycle traversal keys
  3595. * (<code>"upCycleFocusTraversalKeys"</code>)</li>
  3596. * </ul>
  3597. *
  3598. * @param propertyName the property name to filter on
  3599. * @param listener the new listener to add
  3600. * @see #removePropertyChangeListener(String, PropertyChangeListener)
  3601. * @see #getPropertyChangeListeners(String)
  3602. * @see #addPropertyChangeListener(PropertyChangeListener)
  3603. * @since 1.1
  3604. */
  3605. public void addPropertyChangeListener(String propertyName,
  3606. PropertyChangeListener listener)
  3607. {
  3608. if (changeSupport == null)
  3609. changeSupport = new PropertyChangeSupport(this);
  3610. changeSupport.addPropertyChangeListener(propertyName, listener);
  3611. }
  3612. /**
  3613. * Removes the specified property listener on a particular property from
  3614. * the component. This is harmless if the listener was not previously
  3615. * registered.
  3616. *
  3617. * @param propertyName the property name to filter on
  3618. * @param listener the listener to remove
  3619. * @see #addPropertyChangeListener(String, PropertyChangeListener)
  3620. * @see #getPropertyChangeListeners(String)
  3621. * @see #removePropertyChangeListener(PropertyChangeListener)
  3622. * @since 1.1
  3623. */
  3624. public void removePropertyChangeListener(String propertyName,
  3625. PropertyChangeListener listener)
  3626. {
  3627. if (changeSupport != null)
  3628. changeSupport.removePropertyChangeListener(propertyName, listener);
  3629. }
  3630. /**
  3631. * Returns an array of all specified listeners on the named property that
  3632. * are registered on this component.
  3633. *
  3634. * @return an array of listeners
  3635. * @see #addPropertyChangeListener(String, PropertyChangeListener)
  3636. * @see #removePropertyChangeListener(String, PropertyChangeListener)
  3637. * @see #getPropertyChangeListeners()
  3638. * @since 1.4
  3639. */
  3640. public PropertyChangeListener[] getPropertyChangeListeners(String property)
  3641. {
  3642. return changeSupport == null ? new PropertyChangeListener[0]
  3643. : changeSupport.getPropertyChangeListeners(property);
  3644. }
  3645. /**
  3646. * Report a change in a bound property to any registered property listeners.
  3647. *
  3648. * @param propertyName the property that changed
  3649. * @param oldValue the old property value
  3650. * @param newValue the new property value
  3651. */
  3652. protected void firePropertyChange(String propertyName, Object oldValue,
  3653. Object newValue)
  3654. {
  3655. if (changeSupport != null)
  3656. changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  3657. }
  3658. /**
  3659. * Report a change in a bound property to any registered property listeners.
  3660. *
  3661. * @param propertyName the property that changed
  3662. * @param oldValue the old property value
  3663. * @param newValue the new property value
  3664. */
  3665. protected void firePropertyChange(String propertyName, boolean oldValue,
  3666. boolean newValue)
  3667. {
  3668. if (changeSupport != null)
  3669. changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  3670. }
  3671. /**
  3672. * Report a change in a bound property to any registered property listeners.
  3673. *
  3674. * @param propertyName the property that changed
  3675. * @param oldValue the old property value
  3676. * @param newValue the new property value
  3677. */
  3678. protected void firePropertyChange(String propertyName, int oldValue,
  3679. int newValue)
  3680. {
  3681. if (changeSupport != null)
  3682. changeSupport.firePropertyChange(propertyName, oldValue, newValue);
  3683. }
  3684. /**
  3685. * Sets the text layout orientation of this component. New components default
  3686. * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects only
  3687. * the current component, while
  3688. * {@link #applyComponentOrientation(ComponentOrientation)} affects the
  3689. * entire hierarchy.
  3690. *
  3691. * @param o the new orientation
  3692. * @throws NullPointerException if o is null
  3693. * @see #getComponentOrientation()
  3694. */
  3695. public void setComponentOrientation(ComponentOrientation o)
  3696. {
  3697. if (o == null)
  3698. throw new NullPointerException();
  3699. orientation = o;
  3700. }
  3701. /**
  3702. * Determines the text layout orientation used by this component.
  3703. *
  3704. * @return the component orientation
  3705. * @see #setComponentOrientation(ComponentOrientation)
  3706. */
  3707. public ComponentOrientation getComponentOrientation()
  3708. {
  3709. return orientation;
  3710. }
  3711. /**
  3712. * Sets the text layout orientation of this component. New components default
  3713. * to UNKNOWN (which behaves like LEFT_TO_RIGHT). This method affects the
  3714. * entire hierarchy, while
  3715. * {@link #setComponentOrientation(ComponentOrientation)} affects only the
  3716. * current component.
  3717. *
  3718. * @param o the new orientation
  3719. * @throws NullPointerException if o is null
  3720. * @see #getComponentOrientation()
  3721. * @since 1.4
  3722. */
  3723. public void applyComponentOrientation(ComponentOrientation o)
  3724. {
  3725. setComponentOrientation(o);
  3726. }
  3727. /**
  3728. * Returns the accessibility framework context of this class. Component is
  3729. * not accessible, so the default implementation returns null. Subclasses
  3730. * must override this behavior, and return an appropriate subclass of
  3731. * {@link AccessibleAWTComponent}.
  3732. *
  3733. * @return the accessibility context
  3734. */
  3735. public AccessibleContext getAccessibleContext()
  3736. {
  3737. return null;
  3738. }
  3739. // Helper methods; some are package visible for use by subclasses.
  3740. /**
  3741. * Subclasses should override this to return unique component names like
  3742. * "menuitem0".
  3743. *
  3744. * @return the generated name for this component
  3745. */
  3746. String generateName()
  3747. {
  3748. // Component is abstract.
  3749. return null;
  3750. }
  3751. /**
  3752. * Sets the peer for this component.
  3753. *
  3754. * @param peer the new peer
  3755. */
  3756. final void setPeer(ComponentPeer peer)
  3757. {
  3758. this.peer = peer;
  3759. }
  3760. /**
  3761. * Implementation method that allows classes such as Canvas and Window to
  3762. * override the graphics configuration without violating the published API.
  3763. *
  3764. * @return the graphics configuration
  3765. */
  3766. GraphicsConfiguration getGraphicsConfigurationImpl()
  3767. {
  3768. if (peer != null)
  3769. {
  3770. GraphicsConfiguration config = peer.getGraphicsConfiguration();
  3771. if (config != null)
  3772. return config;
  3773. }
  3774. if (parent != null)
  3775. return parent.getGraphicsConfiguration();
  3776. return null;
  3777. }
  3778. /**
  3779. * Implementation of dispatchEvent. Allows trusted package classes to
  3780. * dispatch additional events first.
  3781. *
  3782. * @param e the event to dispatch
  3783. */
  3784. void dispatchEventImpl(AWTEvent e)
  3785. {
  3786. // Make use of event id's in order to avoid multiple instanceof tests.
  3787. if (e.id <= ComponentEvent.COMPONENT_LAST
  3788. && e.id >= ComponentEvent.COMPONENT_FIRST
  3789. && (componentListener != null
  3790. || (eventMask & AWTEvent.COMPONENT_EVENT_MASK) != 0))
  3791. processEvent(e);
  3792. else if (e.id <= KeyEvent.KEY_LAST
  3793. && e.id >= KeyEvent.KEY_FIRST
  3794. && (keyListener != null
  3795. || (eventMask & AWTEvent.KEY_EVENT_MASK) != 0))
  3796. processEvent(e);
  3797. else if (e.id <= MouseEvent.MOUSE_LAST
  3798. && e.id >= MouseEvent.MOUSE_FIRST
  3799. && (mouseListener != null
  3800. || mouseMotionListener != null
  3801. || (eventMask & AWTEvent.MOUSE_EVENT_MASK) != 0))
  3802. processEvent(e);
  3803. else if (e.id <= FocusEvent.FOCUS_LAST
  3804. && e.id >= FocusEvent.FOCUS_FIRST
  3805. && (focusListener != null
  3806. || (eventMask & AWTEvent.FOCUS_EVENT_MASK) != 0))
  3807. processEvent(e);
  3808. else if (e.id <= InputMethodEvent.INPUT_METHOD_LAST
  3809. && e.id >= InputMethodEvent.INPUT_METHOD_FIRST
  3810. && (inputMethodListener != null
  3811. || (eventMask & AWTEvent.INPUT_METHOD_EVENT_MASK) != 0))
  3812. processEvent(e);
  3813. else if (e.id <= HierarchyEvent.HIERARCHY_LAST
  3814. && e.id >= HierarchyEvent.HIERARCHY_FIRST
  3815. && (hierarchyListener != null
  3816. || hierarchyBoundsListener != null
  3817. || (eventMask & AWTEvent.HIERARCHY_EVENT_MASK) != 0))
  3818. processEvent(e);
  3819. else if (e.id <= PaintEvent.PAINT_LAST
  3820. && e.id >= PaintEvent.PAINT_FIRST
  3821. && (eventMask & AWTEvent.PAINT_EVENT_MASK) != 0)
  3822. processEvent(e);
  3823. }
  3824. /**
  3825. * Coalesce paint events. Current heuristic is: Merge if the union of
  3826. * areas is less than twice that of the sum of the areas. The X server
  3827. * tend to create a lot of paint events that are adjacent but not
  3828. * overlapping.
  3829. *
  3830. * <pre>
  3831. * +------+
  3832. * | +-----+ ...will be merged
  3833. * | | |
  3834. * | | |
  3835. * +------+ |
  3836. * +-----+
  3837. *
  3838. * +---------------+--+
  3839. * | | | ...will not be merged
  3840. * +---------------+ |
  3841. * | |
  3842. * | |
  3843. * | |
  3844. * | |
  3845. * | |
  3846. * +--+
  3847. * </pre>
  3848. *
  3849. * @param queuedEvent the first paint event
  3850. * @param newEvent the second paint event
  3851. * @return the combined paint event, or null
  3852. */
  3853. private PaintEvent coalescePaintEvents(PaintEvent queuedEvent,
  3854. PaintEvent newEvent)
  3855. {
  3856. Rectangle r1 = queuedEvent.getUpdateRect();
  3857. Rectangle r2 = newEvent.getUpdateRect();
  3858. Rectangle union = r1.union(r2);
  3859. int r1a = r1.width * r1.height;
  3860. int r2a = r2.width * r2.height;
  3861. int ua = union.width * union.height;
  3862. if (ua > (r1a+r2a)*2)
  3863. return null;
  3864. /* The 2 factor should maybe be reconsidered. Perhaps 3/2
  3865. would be better? */
  3866. newEvent.setUpdateRect(union);
  3867. return newEvent;
  3868. }
  3869. /**
  3870. * Does the work for a paint event.
  3871. *
  3872. * @param event the event to process
  3873. */
  3874. private void processPaintEvent(PaintEvent event)
  3875. {
  3876. // Can't do graphics without peer
  3877. if (peer == null)
  3878. return;
  3879. Graphics gfx = getGraphics();
  3880. try
  3881. {
  3882. Shape clip = event.getUpdateRect();
  3883. gfx.setClip(clip);
  3884. switch (event.id)
  3885. {
  3886. case PaintEvent.PAINT:
  3887. paint(gfx);
  3888. break;
  3889. case PaintEvent.UPDATE:
  3890. update(gfx);
  3891. break;
  3892. default:
  3893. throw new IllegalArgumentException("unknown paint event");
  3894. }
  3895. }
  3896. finally
  3897. {
  3898. gfx.dispose();
  3899. }
  3900. }
  3901. /**
  3902. * This method is used to implement transferFocus(). CHILD is the child
  3903. * making the request. This is overridden by Container; when called for an
  3904. * ordinary component there is no child and so we always return null.
  3905. *
  3906. * @param child the component making the request
  3907. * @return the next component to focus on
  3908. */
  3909. Component findNextFocusComponent(Component child)
  3910. {
  3911. return null;
  3912. }
  3913. /**
  3914. * Deserializes this component. This regenerates all serializable listeners
  3915. * which were registered originally.
  3916. *
  3917. * @param s the stream to read from
  3918. * @throws ClassNotFoundException if deserialization fails
  3919. * @throws IOException if the stream fails
  3920. */
  3921. private void readObject(ObjectInputStream s)
  3922. throws ClassNotFoundException, IOException
  3923. {
  3924. s.defaultReadObject();
  3925. String key = (String) s.readObject();
  3926. while (key != null)
  3927. {
  3928. Object listener = s.readObject();
  3929. if ("componentL".equals(key))
  3930. addComponentListener((ComponentListener) listener);
  3931. else if ("focusL".equals(key))
  3932. addFocusListener((FocusListener) listener);
  3933. else if ("keyL".equals(key))
  3934. addKeyListener((KeyListener) listener);
  3935. else if ("mouseL".equals(key))
  3936. addMouseListener((MouseListener) listener);
  3937. else if ("mouseMotionL".equals(key))
  3938. addMouseMotionListener((MouseMotionListener) listener);
  3939. else if ("inputMethodL".equals(key))
  3940. addInputMethodListener((InputMethodListener) listener);
  3941. else if ("hierarchyL".equals(key))
  3942. addHierarchyListener((HierarchyListener) listener);
  3943. else if ("hierarchyBoundsL".equals(key))
  3944. addHierarchyBoundsListener((HierarchyBoundsListener) listener);
  3945. else if ("mouseWheelL".equals(key))
  3946. addMouseWheelListener((MouseWheelListener) listener);
  3947. key = (String) s.readObject();
  3948. }
  3949. }
  3950. /**
  3951. * Serializes this component. This ignores all listeners which do not
  3952. * implement Serializable, but includes those that do.
  3953. *
  3954. * @param s the stream to write to
  3955. * @throws IOException if the stream fails
  3956. */
  3957. private void writeObject(ObjectOutputStream s) throws IOException
  3958. {
  3959. s.defaultWriteObject();
  3960. AWTEventMulticaster.save(s, "componentL", componentListener);
  3961. AWTEventMulticaster.save(s, "focusL", focusListener);
  3962. AWTEventMulticaster.save(s, "keyL", keyListener);
  3963. AWTEventMulticaster.save(s, "mouseL", mouseListener);
  3964. AWTEventMulticaster.save(s, "mouseMotionL", mouseMotionListener);
  3965. AWTEventMulticaster.save(s, "inputMethodL", inputMethodListener);
  3966. AWTEventMulticaster.save(s, "hierarchyL", hierarchyListener);
  3967. AWTEventMulticaster.save(s, "hierarchyBoundsL", hierarchyBoundsListener);
  3968. AWTEventMulticaster.save(s, "mouseWheelL", mouseWheelListener);
  3969. s.writeObject(null);
  3970. }
  3971. // Nested classes.
  3972. /**
  3973. * This class provides accessibility support for subclasses of container.
  3974. *
  3975. * @author Eric Blake <ebb9@email.byu.edu>
  3976. * @since 1.3
  3977. * @status updated to 1.4
  3978. */
  3979. protected abstract class AccessibleAWTComponent extends AccessibleContext
  3980. implements Serializable, AccessibleComponent
  3981. {
  3982. /**
  3983. * Compatible with JDK 1.3+.
  3984. */
  3985. private static final long serialVersionUID = 642321655757800191L;
  3986. /**
  3987. * Converts show/hide events to PropertyChange events, and is registered
  3988. * as a component listener on this component.
  3989. *
  3990. * @serial the component handler
  3991. */
  3992. protected ComponentListener accessibleAWTComponentHandler
  3993. = new AccessibleAWTComponentHandler();
  3994. /**
  3995. * Converts focus events to PropertyChange events, and is registered
  3996. * as a focus listener on this component.
  3997. *
  3998. * @serial the focus handler
  3999. */
  4000. protected FocusListener accessibleAWTFocusHandler
  4001. = new AccessibleAWTFocusHandler();
  4002. /**
  4003. * The default constructor.
  4004. */
  4005. protected AccessibleAWTComponent()
  4006. {
  4007. Component.this.addComponentListener(accessibleAWTComponentHandler);
  4008. Component.this.addFocusListener(accessibleAWTFocusHandler);
  4009. }
  4010. /**
  4011. * Adds a global property change listener to the accessible component.
  4012. *
  4013. * @param l the listener to add
  4014. * @see #ACCESSIBLE_NAME_PROPERTY
  4015. * @see #ACCESSIBLE_DESCRIPTION_PROPERTY
  4016. * @see #ACCESSIBLE_STATE_PROPERTY
  4017. * @see #ACCESSIBLE_VALUE_PROPERTY
  4018. * @see #ACCESSIBLE_SELECTION_PROPERTY
  4019. * @see #ACCESSIBLE_TEXT_PROPERTY
  4020. * @see #ACCESSIBLE_VISIBLE_DATA_PROPERTY
  4021. */
  4022. public void addPropertyChangeListener(PropertyChangeListener l)
  4023. {
  4024. Component.this.addPropertyChangeListener(l);
  4025. super.addPropertyChangeListener(l);
  4026. }
  4027. /**
  4028. * Removes a global property change listener from this accessible
  4029. * component.
  4030. *
  4031. * @param l the listener to remove
  4032. */
  4033. public void removePropertyChangeListener(PropertyChangeListener l)
  4034. {
  4035. Component.this.removePropertyChangeListener(l);
  4036. super.removePropertyChangeListener(l);
  4037. }
  4038. /**
  4039. * Returns the accessible name of this component. It is almost always
  4040. * wrong to return getName(), since it is not localized. In fact, for
  4041. * things like buttons, this should be the text of the button, not the
  4042. * name of the object. The tooltip text might also be appropriate.
  4043. *
  4044. * @return the name
  4045. * @see #setAccessibleName(String)
  4046. */
  4047. public String getAccessibleName()
  4048. {
  4049. return accessibleName == null ? getName() : accessibleName;
  4050. }
  4051. /**
  4052. * Returns a brief description of this accessible context. This should
  4053. * be localized.
  4054. *
  4055. * @return a description of this component
  4056. * @see #setAccessibleDescription(String)
  4057. */
  4058. public String getAccessibleDescription()
  4059. {
  4060. return accessibleDescription;
  4061. }
  4062. /**
  4063. * Returns the role of this component.
  4064. *
  4065. * @return the accessible role
  4066. */
  4067. public AccessibleRole getAccessibleRole()
  4068. {
  4069. return AccessibleRole.AWT_COMPONENT;
  4070. }
  4071. /**
  4072. * Returns a state set describing this component's state.
  4073. *
  4074. * @return a new state set
  4075. * @see AccessibleState
  4076. */
  4077. public AccessibleStateSet getAccessibleStateSet()
  4078. {
  4079. AccessibleStateSet s = new AccessibleStateSet();
  4080. if (Component.this.isEnabled())
  4081. s.add(AccessibleState.ENABLED);
  4082. if (isFocusable())
  4083. s.add(AccessibleState.FOCUSABLE);
  4084. if (isFocusOwner())
  4085. s.add(AccessibleState.FOCUSED);
  4086. if (isOpaque())
  4087. s.add(AccessibleState.OPAQUE);
  4088. if (Component.this.isShowing())
  4089. s.add(AccessibleState.SHOWING);
  4090. if (Component.this.isVisible())
  4091. s.add(AccessibleState.VISIBLE);
  4092. return s;
  4093. }
  4094. /**
  4095. * Returns the parent of this component, if it is accessible.
  4096. *
  4097. * @return the accessible parent
  4098. */
  4099. public Accessible getAccessibleParent()
  4100. {
  4101. if (accessibleParent == null)
  4102. {
  4103. Container parent = getParent();
  4104. accessibleParent = parent instanceof Accessible
  4105. ? (Accessible) parent : null;
  4106. }
  4107. return accessibleParent;
  4108. }
  4109. /**
  4110. * Returns the index of this component in its accessible parent.
  4111. *
  4112. * @return the index, or -1 if the parent is not accessible
  4113. * @see #getAccessibleParent()
  4114. */
  4115. public int getAccessibleIndexInParent()
  4116. {
  4117. if (getAccessibleParent() == null)
  4118. return -1;
  4119. AccessibleContext context
  4120. = ((Component) accessibleParent).getAccessibleContext();
  4121. if (context == null)
  4122. return -1;
  4123. for (int i = context.getAccessibleChildrenCount(); --i >= 0; )
  4124. if (context.getAccessibleChild(i) == Component.this)
  4125. return i;
  4126. return -1;
  4127. }
  4128. /**
  4129. * Returns the number of children of this component which implement
  4130. * Accessible. Subclasses must override this if they can have children.
  4131. *
  4132. * @return the number of accessible children, default 0
  4133. */
  4134. public int getAccessibleChildrenCount()
  4135. {
  4136. return 0;
  4137. }
  4138. /**
  4139. * Returns the ith accessible child. Subclasses must override this if
  4140. * they can have children.
  4141. *
  4142. * @return the ith accessible child, or null
  4143. * @see #getAccessibleChildrenCount()
  4144. */
  4145. public Accessible getAccessibleChild(int i)
  4146. {
  4147. return null;
  4148. }
  4149. /**
  4150. * Returns the locale of this component.
  4151. *
  4152. * @return the locale
  4153. * @throws IllegalComponentStateException if the locale is unknown
  4154. */
  4155. public Locale getLocale()
  4156. {
  4157. return Component.this.getLocale();
  4158. }
  4159. /**
  4160. * Returns this, since it is an accessible component.
  4161. *
  4162. * @return the accessible component
  4163. */
  4164. public AccessibleComponent getAccessibleComponent()
  4165. {
  4166. return this;
  4167. }
  4168. /**
  4169. * Gets the background color.
  4170. *
  4171. * @return the background color
  4172. * @see #setBackground(Color)
  4173. */
  4174. public Color getBackground()
  4175. {
  4176. return Component.this.getBackground();
  4177. }
  4178. /**
  4179. * Sets the background color.
  4180. *
  4181. * @param c the background color
  4182. * @see #getBackground()
  4183. * @see #isOpaque()
  4184. */
  4185. public void setBackground(Color c)
  4186. {
  4187. Component.this.setBackground(c);
  4188. }
  4189. /**
  4190. * Gets the foreground color.
  4191. *
  4192. * @return the foreground color
  4193. * @see #setForeground(Color)
  4194. */
  4195. public Color getForeground()
  4196. {
  4197. return Component.this.getForeground();
  4198. }
  4199. /**
  4200. * Sets the foreground color.
  4201. *
  4202. * @param c the foreground color
  4203. * @see #getForeground()
  4204. */
  4205. public void setForeground(Color c)
  4206. {
  4207. Component.this.setForeground(c);
  4208. }
  4209. /**
  4210. * Gets the cursor.
  4211. *
  4212. * @return the cursor
  4213. * @see #setCursor(Cursor)
  4214. */
  4215. public Cursor getCursor()
  4216. {
  4217. return Component.this.getCursor();
  4218. }
  4219. /**
  4220. * Sets the cursor.
  4221. *
  4222. * @param cursor the cursor
  4223. * @see #getCursor()
  4224. */
  4225. public void setCursor(Cursor cursor)
  4226. {
  4227. Component.this.setCursor(cursor);
  4228. }
  4229. /**
  4230. * Gets the font.
  4231. *
  4232. * @return the font
  4233. * @see #setFont(Font)
  4234. */
  4235. public Font getFont()
  4236. {
  4237. return Component.this.getFont();
  4238. }
  4239. /**
  4240. * Sets the font.
  4241. *
  4242. * @param f the font
  4243. * @see #getFont()
  4244. */
  4245. public void setFont(Font f)
  4246. {
  4247. Component.this.setFont(f);
  4248. }
  4249. /**
  4250. * Gets the font metrics for a font.
  4251. *
  4252. * @param f the font to look up
  4253. * @return its metrics
  4254. * @throws NullPointerException if f is null
  4255. * @see #getFont()
  4256. */
  4257. public FontMetrics getFontMetrics(Font f)
  4258. {
  4259. return Component.this.getFontMetrics(f);
  4260. }
  4261. /**
  4262. * Tests if the component is enabled.
  4263. *
  4264. * @return true if the component is enabled
  4265. * @see #setEnabled(boolean)
  4266. * @see #getAccessibleStateSet()
  4267. * @see AccessibleState#ENABLED
  4268. */
  4269. public boolean isEnabled()
  4270. {
  4271. return Component.this.isEnabled();
  4272. }
  4273. /**
  4274. * Set whether the component is enabled.
  4275. *
  4276. * @param b the new enabled status
  4277. * @see #isEnabled()
  4278. */
  4279. public void setEnabled(boolean b)
  4280. {
  4281. Component.this.setEnabled(b);
  4282. }
  4283. /**
  4284. * Test whether the component is visible (not necesarily showing).
  4285. *
  4286. * @return true if it is visible
  4287. * @see #setVisible(boolean)
  4288. * @see #getAccessibleStateSet()
  4289. * @see AccessibleState#VISIBLE
  4290. */
  4291. public boolean isVisible()
  4292. {
  4293. return Component.this.isVisible();
  4294. }
  4295. /**
  4296. * Sets the visibility of this component.
  4297. *
  4298. * @param b the desired visibility
  4299. * @see #isVisible()
  4300. */
  4301. public void setVisible(boolean b)
  4302. {
  4303. Component.this.setVisible(b);
  4304. }
  4305. /**
  4306. * Tests if the component is showing.
  4307. *
  4308. * @return true if this is showing
  4309. */
  4310. public boolean isShowing()
  4311. {
  4312. return Component.this.isShowing();
  4313. }
  4314. /**
  4315. * Tests if the point is contained in this component.
  4316. *
  4317. * @param p the point to check
  4318. * @return true if it is contained
  4319. * @throws NullPointerException if p is null
  4320. */
  4321. public boolean contains(Point p)
  4322. {
  4323. return Component.this.contains(p.x, p.y);
  4324. }
  4325. /**
  4326. * Returns the location of this object on the screen, or null if it is
  4327. * not showing.
  4328. *
  4329. * @return the location relative to screen coordinates, if showing
  4330. * @see #getBounds()
  4331. * @see #getLocation()
  4332. */
  4333. public Point getLocationOnScreen()
  4334. {
  4335. return Component.this.isShowing() ? Component.this.getLocationOnScreen()
  4336. : null;
  4337. }
  4338. /**
  4339. * Returns the location of this object relative to its parent's coordinate
  4340. * system, or null if it is not showing.
  4341. *
  4342. * @return the location
  4343. * @see #getBounds()
  4344. * @see #getLocationOnScreen()
  4345. */
  4346. public Point getLocation()
  4347. {
  4348. return Component.this.isShowing() ? Component.this.getLocation() : null;
  4349. }
  4350. /**
  4351. * Sets the location of this relative to its parent's coordinate system.
  4352. *
  4353. * @param p the location
  4354. * @throws NullPointerException if p is null
  4355. * @see #getLocation()
  4356. */
  4357. public void setLocation(Point p)
  4358. {
  4359. Component.this.setLocation(p.x, p.y);
  4360. }
  4361. /**
  4362. * Gets the bounds of this component, or null if it is not on screen.
  4363. *
  4364. * @return the bounds
  4365. * @see #contains(Point)
  4366. * @see #setBounds(Rectangle)
  4367. */
  4368. public Rectangle getBounds()
  4369. {
  4370. return Component.this.isShowing() ? Component.this.getBounds() : null;
  4371. }
  4372. /**
  4373. * Sets the bounds of this component.
  4374. *
  4375. * @param r the bounds
  4376. * @throws NullPointerException if r is null
  4377. * @see #getBounds()
  4378. */
  4379. public void setBounds(Rectangle r)
  4380. {
  4381. Component.this.setBounds(r.x, r.y, r.width, r.height);
  4382. }
  4383. /**
  4384. * Gets the size of this component, or null if it is not showing.
  4385. *
  4386. * @return the size
  4387. * @see #setSize(Dimension)
  4388. */
  4389. public Dimension getSize()
  4390. {
  4391. return Component.this.isShowing() ? Component.this.getSize() : null;
  4392. }
  4393. /**
  4394. * Sets the size of this component.
  4395. *
  4396. * @param d the size
  4397. * @throws NullPointerException if d is null
  4398. * @see #getSize()
  4399. */
  4400. public void setSize(Dimension d)
  4401. {
  4402. Component.this.setSize(d.width, d.height);
  4403. }
  4404. /**
  4405. * Returns the Accessible child at a point relative to the coordinate
  4406. * system of this component, if one exists, or null. Since components
  4407. * have no children, subclasses must override this to get anything besides
  4408. * null.
  4409. *
  4410. * @param p the point to check
  4411. * @return the accessible child at that point
  4412. * @throws NullPointerException if p is null
  4413. */
  4414. public Accessible getAccessibleAt(Point p)
  4415. {
  4416. return null;
  4417. }
  4418. /**
  4419. * Tests whether this component can accept focus.
  4420. *
  4421. * @return true if this is focus traversable
  4422. * @see #getAccessibleStateSet()
  4423. * @see AccessibleState#FOCUSABLE
  4424. * @see AccessibleState#FOCUSED
  4425. */
  4426. public boolean isFocusTraversable()
  4427. {
  4428. return Component.this.isFocusTraversable();
  4429. }
  4430. /**
  4431. * Requests focus for this component.
  4432. *
  4433. * @see #isFocusTraversable()
  4434. */
  4435. public void requestFocus()
  4436. {
  4437. Component.this.requestFocus();
  4438. }
  4439. /**
  4440. * Adds a focus listener.
  4441. *
  4442. * @param l the listener to add
  4443. */
  4444. public void addFocusListener(FocusListener l)
  4445. {
  4446. Component.this.addFocusListener(l);
  4447. }
  4448. /**
  4449. * Removes a focus listener.
  4450. *
  4451. * @param l the listener to remove
  4452. */
  4453. public void removeFocusListener(FocusListener l)
  4454. {
  4455. Component.this.removeFocusListener(l);
  4456. }
  4457. /**
  4458. * Converts component changes into property changes.
  4459. *
  4460. * @author Eric Blake <ebb9@email.byu.edu>
  4461. * @since 1.3
  4462. * @status updated to 1.4
  4463. */
  4464. protected class AccessibleAWTComponentHandler implements ComponentListener
  4465. {
  4466. /**
  4467. * Default constructor.
  4468. */
  4469. protected AccessibleAWTComponentHandler()
  4470. {
  4471. }
  4472. /**
  4473. * Convert a component hidden to a property change.
  4474. *
  4475. * @param e the event to convert
  4476. */
  4477. public void componentHidden(ComponentEvent e)
  4478. {
  4479. AccessibleAWTComponent.this.firePropertyChange
  4480. (ACCESSIBLE_STATE_PROPERTY, AccessibleState.VISIBLE, null);
  4481. }
  4482. /**
  4483. * Convert a component shown to a property change.
  4484. *
  4485. * @param e the event to convert
  4486. */
  4487. public void componentShown(ComponentEvent e)
  4488. {
  4489. AccessibleAWTComponent.this.firePropertyChange
  4490. (ACCESSIBLE_STATE_PROPERTY, null, AccessibleState.VISIBLE);
  4491. }
  4492. /**
  4493. * Moving a component does not affect properties.
  4494. *
  4495. * @param e ignored
  4496. */
  4497. public void componentMoved(ComponentEvent e)
  4498. {
  4499. }
  4500. /**
  4501. * Resizing a component does not affect properties.
  4502. *
  4503. * @param e ignored
  4504. */
  4505. public void componentResized(ComponentEvent e)
  4506. {
  4507. }
  4508. } // class AccessibleAWTComponentHandler
  4509. /**
  4510. * Converts focus changes into property changes.
  4511. *
  4512. * @author Eric Blake <ebb9@email.byu.edu>
  4513. * @since 1.3
  4514. * @status updated to 1.4
  4515. */
  4516. protected class AccessibleAWTFocusHandler implements FocusListener
  4517. {
  4518. /**
  4519. * Default constructor.
  4520. */
  4521. protected AccessibleAWTFocusHandler()
  4522. {
  4523. }
  4524. /**
  4525. * Convert a focus gained to a property change.
  4526. *
  4527. * @param e the event to convert
  4528. */
  4529. public void focusGained(FocusEvent e)
  4530. {
  4531. AccessibleAWTComponent.this.firePropertyChange
  4532. (ACCESSIBLE_STATE_PROPERTY, null, AccessibleState.FOCUSED);
  4533. }
  4534. /**
  4535. * Convert a focus lost to a property change.
  4536. *
  4537. * @param e the event to convert
  4538. */
  4539. public void focusLost(FocusEvent e)
  4540. {
  4541. AccessibleAWTComponent.this.firePropertyChange
  4542. (ACCESSIBLE_STATE_PROPERTY, AccessibleState.FOCUSED, null);
  4543. }
  4544. } // class AccessibleAWTComponentHandler
  4545. } // class AccessibleAWTComponent
  4546. /**
  4547. * This class provides support for blitting offscreen surfaces.
  4548. *
  4549. * @author Eric Blake <ebb9@email.byu.edu>
  4550. * @since 1.4
  4551. * @XXX Shell class, to allow compilation. This needs documentation and
  4552. * correct implementation.
  4553. */
  4554. protected class BltBufferStrategy extends BufferStrategy
  4555. {
  4556. protected BufferCapabilities caps;
  4557. protected VolatileImage[] backBuffers;
  4558. protected boolean validatedContents;
  4559. protected int width;
  4560. protected int height;
  4561. protected BltBufferStrategy(int num, BufferCapabilities caps)
  4562. {
  4563. this.caps = caps;
  4564. createBackBuffers(num);
  4565. }
  4566. protected void createBackBuffers(int num)
  4567. {
  4568. backBuffers = new VolatileImage[num];
  4569. }
  4570. public BufferCapabilities getCapabilities()
  4571. {
  4572. return caps;
  4573. }
  4574. public Graphics getDrawGraphics() { return null; }
  4575. public void show() {}
  4576. protected void revalidate() {}
  4577. public boolean contentsLost() { return false; }
  4578. public boolean contentsRestored() { return false; }
  4579. } // class BltBufferStrategy
  4580. /**
  4581. * This class provides support for flipping component buffers. It is only
  4582. * designed for use by Canvas and Window.
  4583. *
  4584. * @author Eric Blake <ebb9@email.byu.edu>
  4585. * @since 1.4
  4586. * @XXX Shell class, to allow compilation. This needs documentation and
  4587. * correct implementation.
  4588. */
  4589. protected class FlipBufferStrategy extends BufferStrategy
  4590. {
  4591. protected int numBuffers;
  4592. protected BufferCapabilities caps;
  4593. protected Image drawBuffer;
  4594. protected VolatileImage drawVBuffer;
  4595. protected boolean validatedContents;
  4596. protected FlipBufferStrategy(int num, BufferCapabilities caps)
  4597. throws AWTException
  4598. {
  4599. this.caps = caps;
  4600. createBuffers(num, caps);
  4601. }
  4602. protected void createBuffers(int num, BufferCapabilities caps)
  4603. throws AWTException {}
  4604. protected Image getBackBuffer()
  4605. {
  4606. return drawBuffer;
  4607. }
  4608. protected void flip(BufferCapabilities.FlipContents flipAction) {}
  4609. protected void destroyBuffers() {}
  4610. public BufferCapabilities getCapabilities()
  4611. {
  4612. return caps;
  4613. }
  4614. public Graphics getDrawGraphics() { return null; }
  4615. protected void revalidate() {}
  4616. public boolean contentsLost() { return false; }
  4617. public boolean contentsRestored() { return false; }
  4618. public void show() {}
  4619. } // class FlipBufferStrategy
  4620. } // class Component