From: Mark Wielaard
Date: Fri, 18 Nov 2005 00:59:33 +0000 (+0000)
Subject: Imported GNU Classpath gcj-import-20051117.
X-Git-Tag: releases/gcc-4.1.0~730
X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ca9e049bc145ae985bc0e2dd6079dacdd51717ac;p=thirdparty%2Fgcc.git
Imported GNU Classpath gcj-import-20051117.
* gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
* sources.am: Regenerated.
* Makefile.in: Likewise.
From-SVN: r107153
---
diff --git a/libjava/ChangeLog b/libjava/ChangeLog
index 512b4f1520f7..9219f19c7341 100644
--- a/libjava/ChangeLog
+++ b/libjava/ChangeLog
@@ -1,3 +1,10 @@
+2005-11-17 Mark Wielaard
+
+ Imported GNU Classpath gcj-import-20051117.
+ * gnu/java/net/protocol/file/Connection.java: Removed, fully merged.
+ * sources.am: Regenerated.
+ * Makefile.in: Likewise.
+
2005-11-17 Mark Wielaard
* gnu/java/net/protocol/file/Handler.java: Removed, fully merged now.
diff --git a/libjava/Makefile.in b/libjava/Makefile.in
index ac07ecf8f697..e1bff42c7cf2 100644
--- a/libjava/Makefile.in
+++ b/libjava/Makefile.in
@@ -1425,7 +1425,7 @@ gnu/java/net/protocol/gcjlib/Handler.java
gnu_java_net_header_files = $(patsubst classpath/%,%,$(patsubst %.java,%.h,$(gnu_java_net_source_files)))
gnu_java_net_protocol_file_source_files = \
-gnu/java/net/protocol/file/Connection.java \
+classpath/gnu/java/net/protocol/file/Connection.java \
classpath/gnu/java/net/protocol/file/Handler.java
gnu_java_net_protocol_file_header_files = $(patsubst classpath/%,%,$(patsubst %.java,%.h,$(gnu_java_net_protocol_file_source_files)))
@@ -4224,6 +4224,7 @@ classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java \
classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java \
classpath/javax/swing/plaf/metal/MetalLabelUI.java \
classpath/javax/swing/plaf/metal/MetalLookAndFeel.java \
+classpath/javax/swing/plaf/metal/MetalMenuBarUI.java \
classpath/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java \
classpath/javax/swing/plaf/metal/MetalProgressBarUI.java \
classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java \
diff --git a/libjava/classpath/AUTHORS b/libjava/classpath/AUTHORS
index 339138aef06e..2ef1cb7a6795 100644
--- a/libjava/classpath/AUTHORS
+++ b/libjava/classpath/AUTHORS
@@ -5,6 +5,7 @@ on either list, but should, let us know. Please keep this list in
alphabetic order.
Lillian Angel (langel@redhat.com)
+Anthony Balkissoon (abalkiss@redhat.com)
Stuart Ballard (stuart.a.ballard@gmail.com)
Mark Benvenuto (mcb54@columbia.edu)
Geoff Berry (gcb@gnu.org)
diff --git a/libjava/classpath/ChangeLog b/libjava/classpath/ChangeLog
index d40cc1a418c1..125388f5d6ff 100644
--- a/libjava/classpath/ChangeLog
+++ b/libjava/classpath/ChangeLog
@@ -1,3 +1,644 @@
+2005-11-17 Roman Kennke
+ Five-in-a-row
+ is a two player strategy game. The players
+ are connected via network using CORBA-based RMI/IIOP protocol and
+ make they moves with the help of the Swing-based
+ interface. While playing, the users can also chat.
+ The system consists of the single server and any number of
+ interconnected players. The person, willing to play, starts the
+ client and connects the server. The server redirects call to the
+ partner that has previously connected the same server, also willing
+ to play.
+ The game desk is a field where it is possible to set O's
+ and X'es, one per move. The goal is to get five O's in a row while
+ preventing your partner from getting five X's in a row. Vertical,
+ horizontal and diagonal rows are allowed. The system detects the
+ loss-victory situation on the desk, but currently does not serve as a
+ playing partner, requiring at least two human players for this game.
+ Both players can at any time reset the game (restarting it with
+ the same player) or leave the game (disconnecting). The disconnected
+ player can contact the game manager again, requesting to find another
+ partner.
+ Simple as it is, the application has some features of the typical
+ role playing game that frequently just has more states, actions,
+ possible moves and also provides far richer graphics environment. The
+ game manger serves as a World-Wide-Pub where you can always find a
+ partner to play.
+
+ The players can made both unsynchronized (chatting, game reset and
+ leaving) and synchronized (moves) actions. The game state changes
+ while playing, and the set of the available actions depends on the
+ current state. Finally, the mouse and canvas are involved. However
+ using RMI/IIOP machinery allowed to implement all this functionality
+ with just 13 classes (plus 4 generated), all of them being rather
+ simple.
+
+ This example refers to the standard classes only and must be buildable
+ from your IDE as long as it has any java 1.4 compiler.
+
+ The used IIOP protocol must ensure interoperability, allowing players
+ to use different java virtual machines and operating systems.
+ The processors may have the opposite byte order.
+ The game manager server executable class is
+ gnu.classpath.examples.CORBA.swing.x5.X5Server
+ . After start,
+ it will print to console the Internet address that must be entered to
+ the client to reach the manager.
+ The client executable class it
+ gnu.classpath.examples.CORBA.swing.x5.Demo
+ .
+ The game should run with GNU Classpath
+ 0.19 and Sun Microsystems java 1.5.0_04. Due later fixed bugs it will
+ not run with the older versions of these two implementations.
+ The game manager HTTP server uses port
+ 1500. Hence all firewalls between the server and the player must be
+ configured to allow HTTP on 1500. The ports, used by the RMI/IIOP are
+ not persistent. GNU Classpath is configured to take ports 1501, 1502
+ and 1503 (the firewalls must allow to use them for RMI/IIOP). The
+ CORBA implementation other than Classpath may use different port
+ values. Unfortunately, there is no standard method to configure the
+ used port range in a vendor-independent way.
+ The game manager is first reachable via http:// protocol (for
+ instance http://123.456.7.89:1500). The simple server at this port
+ always serves much longer string, representing the CORBA stringified
+ object reference (IOR). The
+ Five-in-a-row
+ client uses
+ this reference to find and access the remote game server object.
+ If the server player queue is empty, it simply queues this player.
+ If the queue is not empty, the server introduces the arrived player
+ and queued player to each other as leaves the them alone. When
+ playing, the two clients communicate with each other directly, so the
+ server is just a “meeting point” where the players can
+ find each other. The game server is a console-only application.
+ The initial server http:// address must be transferred to players
+ by some other means of communication (web chat, E-mail, link in a web
+ site and so on). The server writes this address to the specified
+ file, and the client can also take the default value from the same
+ file. This is convenient when all applications run on a single
+ machine, but also may be used to transfer the address via shared
+ filesystem.
+ The clients are Swing-based GUI applications, capable for remote
+ communication with each other and with the game manager. They have a
+ set of predefined states and switch between these states in
+ accordance to the preprogrammed logic. The client states are defined
+ in the
+ State
+ interface. They are displayed in the bottom left
+ corner of the window and are summarized in the following table:
+
+ Five-in-a-row
+ 0.0 supplementary documentation
+
+ Introduction and rules
+
+ Configuration and run
+
+ The game server
+
+ The game client
+
+
+
+
+
+
+
+
+
+ Our state
+
+
+ Partner state
+
+
+ Possible actions
+
+
+ Comment
+
+
+
+
+ Disconnected
+
+
+ Partner not accessible
+
+
+ Connect
+
+
+ Initial state.
+
+
+
+
+ Queued
+
+
+ Partner not accessible
+
+
+ Leave
+
+
+ Queued by the game manager.
+
+
+
+
+ I think.
+
+
+ I wait for your move
+
+
+ Make move, reset game, leave, chat.
+
+
+ The person who waited for another player to come starts
+ the game first.
+
+
+
+
+ I wait for your move
+
+
+ I think
+
+
+ Chat, reset game, leave.
+
+
+ After the partner makes the move, the state changes to
+ I think
+ , unless the end of game situation is detected by
+ the desk analyzer.
+
+
+
+
+ I have lost
+
+
+ I have won
+
+
+ Chat, reset game, leave.
+
+
+ Can be entered with the help of the desk analyzer only.
+
+
+
+
+ I have won
+
+
+ I have lost
+
+
+ Chat, reset game, leave
+
+
+ Can be entered with the help of the desk analyzer only.
+
+
+
+
+
+ Error
+
+
+ Any
+
+
+ Chat, leave
+
+
+ This should never happen under normal work, but the demo
+ program may be modified by the user.
+
+
+
+ As it is seen, being in one of the states, the client expects to
+ be the partner client in a certain defined state, and both clients
+ change they states in a synchronized manner. Each state has its own
+ set of the available actions and each action either preserves the
+ current state (chat, reset) or changes it following the rules. For
+ this simple example, the state change rules are obvious.
+ The used RMI-IIOP architecture
+
+ Both player and game manager servants are derived from the
+ org.omg.PortableServer.Servant
+ and, being servants, are simply
+ connected to the
+ POA
+ with
+ POA.servant_to_reference
+ . The
+ first remote object (game manager) is found using the stringified
+ object reference. No naming service is involved.
+
+ Executables classes + | +|
---|---|
+ Demo + | ++ The main executable class of the game client. + | +
+ X5Server + | ++ The main executable class of the game manager server. + | +
+ Interface Summary + | +|
---|---|
+ GameManager + | ++ The game manager interface. + | +
+ Player + | ++ Defines remote methods that are invoked by another player or by + the challenge server. + | +
+ State + | ++ Defines the states in that the player can be. + | +
+ Class Summary + | +|
---|---|
+ _GameManager_Stub + | ++ Normally generated with rmic compiler, this class represents + the GameManager Stub on the client side. + | +
+ _GameManagerImpl_Tie + | ++ Normally generated with rmic compiler, this class represents + the GameManager Tie on the client side. + | +
+ _Player_Stub + | ++ Generate with rmic, command line rmic -iiop -poa -keep + gnu.classpath.examples.CORBA.swing.x5.PlayerImpl (the compiled + package must be present in the current folder). + | +
+ _PlayerImpl_Tie + | ++ Generate with rmic, command line rmic -iiop -poa -keep + gnu.classpath.examples.CORBA.swing.x5.PlayerImpl (the compiled + package must be present in the current folder). + | +
+ ChatConstants + | ++ The chat color code constants, used to indicate who is talking. + | +
+ ClientFrame + | ++ The JFrame of the GUI client. + | +
+ GameManagerImpl + | ++ The manager connects two players into the game. + | +
+ IorReader + | ++ Reads the remote URL. + | +
+ OrbStarter + | ++ Starts the ORBs, involved into this application. + | +
+ PlayerImpl + | ++ The implementation of the PlayerCommunicator, providing the + local functionality. + | +
+ PlayingDesk + | ++ Manages actions, related to the game rules and also does all + painting. + | +
+ http://www.javascripter.net/games/xo/xo.htm + +
++ http://www.leepoint.net/notes-java/45examples/55games/five/five.html + +
+Copyright +
++ Copyright (C) 2005 Free Software Foundation, + Inc. This file is part of GNU Classpath. GNU Classpath is free + software; you can redistribute it and/or modify it under the terms of + the GNU General Public License as published by the Free Software + Foundation; either version 2, or (at your option) any later version. + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. You should have received a + copy of the GNU General Public License along with GNU Classpath; see + the file COPYING. If not, write to the Free Software Foundation, + Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. As a special exception, the copyright holders of this + library give you permission to link this library with independent + modules to produce an executable, regardless of the license terms of + these independent modules, and to copy and distribute the resulting + executable under terms of your choice, provided that you also meet, + for each linked independent module, the terms and conditions of the + license of that module. An independent module is a module which is + not derived from or based on this library. If you modify this + library, you may extend this exception to your version of the + library, but you are not obligated to do so. If you do not wish to do + so, delete this exception statement from your version. + +
+
+
+
+
+First version written by +Audrius Meškauskas +
+ + diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/CanvasWorld.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/CanvasWorld.java new file mode 100644 index 000000000000..9e1a70fcc165 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/CanvasWorld.java @@ -0,0 +1,307 @@ +/* CanvasWorld.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Color; +import java.awt.Dimension; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import javax.swing.JComponent; +import javax.swing.JFrame; +import javax.swing.JScrollPane; + +/** + * The purpose of this simple example is to check if the mouse events are + * correctly received in a scrollable canvas and also if the canvas are + * correctly repainted. The similar canvas are used in various games and + * interactive demonstrations. + * + * The user can set one of the three possible figures with the different + * mouse buttons. The figure must be set where the user have clicked the + * mouse. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class CanvasWorld + extends JComponent + implements MouseListener, State +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Red oval, set by the left mouse button. + */ + public static final int RED = 0; + + /** + * Black cross, set by the right mouse button. + */ + public static final int BLACK = 1; + + /** + * Blue and smaller oval, set by the middle mouse button. + */ + public static final int HINT = 2; + + /** + * The message string is displayed at the top of the window. + */ + String message = "Click left, right or middle button in to set the figure"; + + /** + * The additinal message, related to the mouse events. + */ + String mouse = "No mouse event so far"; + + /** + * The grid spacing. + */ + static int W = 16; + + /** + * The radius of the dots being painted. + */ + static int R = W / 3; + + /** + * The collection of the red dots. + */ + ArrayList reds = new ArrayList(); + + /** + * The collection of the black crosses. + */ + ArrayList blacks = new ArrayList(); + + /** + * The collection of the smaller blue crosses. + */ + ArrayList hints = new ArrayList(); + + public CanvasWorld() + { + try + { + addMouseListener(this); + } + catch (Exception e) + { + throw new AssertionError(e); + } + } + + /** + * Paint this component. + */ + public void paintComponent(Graphics g) + { + int w = getWidth(); + int h = getHeight(); + + g.setColor(Color.white); + g.fillRect(0, 0, w, h); + + drawGrid(w, h, g); + + g.setColor(Color.black); + + g.drawString(message, W, W); + g.drawString(mouse, W, 2*W); + + drawFigures(g); + } + + /** + * Check for the presence of the given point in the collection. + */ + public final boolean pointPresent(int x, int y, Collection in) + { + Iterator iter = in.iterator(); + Point p; + while (iter.hasNext()) + { + p = (Point) iter.next(); + if (p.x == x && p.y == y) + return true; + } + return false; + } + + public void drawGrid(int w, int h, Graphics g) + { + g.setColor(Color.lightGray); + + int xs = 2*W+W/2; + + // Draw vertical lines: + for (int x = 0; x < w; x += W) + { + g.drawLine(x, xs, x, h); + } + + // Draw horizontal lines: + for (int y = 3*W; y < h; y += W) + { + g.drawLine(0, y, w, y); + } + + g.setColor(Color.gray); + } + + public void drawFigures(Graphics g) + { + g.setColor(Color.red); + drawDots(reds, g, RED); + + g.setColor(Color.black); + drawDots(blacks, g, BLACK); + + g.setColor(Color.blue); + drawDots(hints, g, HINT); + } + + public Point makePoint(int x, int y) + { + return new Point(x / W, y / W); + } + + /** + * Draw a collection of dots (the collor must be set before calling the + * method). + */ + public void drawDots(Collection dots, Graphics g, int mode) + { + Iterator iter = dots.iterator(); + int x; + int y; + + int hW = W / 2; + int RR = R * 2; + int hR = R / 2; + Point p; + while (iter.hasNext()) + { + p = (Point) iter.next(); + x = p.x * W + hW; + y = p.y * W + hW; + + if (mode == RED) + g.drawOval(x - R, y - R, RR, RR); + else if (mode == BLACK) + { + g.drawLine(x - R, y - R, x + R, y + R); + g.drawLine(x - R, y + R, x + R, y - R); + } + else + { + // Hint. + g.drawOval(x - hR, y - hR, R, R); + } + } + } + + public void mouseClicked(MouseEvent e) + { + int x = e.getX(); + int y = e.getY(); + + Point p = makePoint(x, y); + + // Ignore clicks on the occupied cells. + if (pointPresent(p.x, p.y, reds) || (pointPresent(p.x, p.y, blacks))) + { + message = "Clicked on the occupied cell."; + return; + } + else + message = "Figure set at ["+p.x+","+p.y+"]"; + + if (e.getButton() == MouseEvent.BUTTON1) + reds.add(p); + else if (e.getButton() == MouseEvent.BUTTON3) + blacks.add(p); + else if (e.getButton() == MouseEvent.BUTTON2) + hints.add(p); + repaint(); + } + + public void mouseEntered(MouseEvent m) + { + mouse = "Mouse entered."; + repaint(); + } + + public void mousePressed(MouseEvent m) + { + mouse = "Mouse pressed at "+m.getX()+","+m.getY(); + repaint(); + } + + public void mouseReleased(MouseEvent m) + { + mouse = "Mouse released at "+m.getX()+","+m.getY(); + repaint(); + } + + public void mouseExited(MouseEvent m) + { + mouse = "Mouse exited"; + repaint(); + } + + public static void main(String[] args) + { + JFrame frame = new JFrame(); + CanvasWorld world = new CanvasWorld(); + world.setPreferredSize(new Dimension(1000,1000)); + frame.add(new JScrollPane(world)); + frame.setSize(400, 200); + frame.setVisible(true); + } + +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ChatConstants.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ChatConstants.java new file mode 100644 index 000000000000..b0552b439436 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ChatConstants.java @@ -0,0 +1,80 @@ +/* ChatConstants.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Color; + +/** + * The chat color code constants, used to indicate who is talking. + * Additionally, the red color is reseved for the most important messages, + * related to the start and end of the game. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ChatConstants +{ + /** + * Messages from the local system. + */ + public static byte SYSTEM = 0; + + /** + * Mirrored messsages from the local player. + */ + public static byte SELF = 1; + + /** + * Messages from the remote player. + */ + public static byte REMOTE_PLAYER = 2; + + /** + * Messages from the game server/ + */ + public static byte GAME_SERVER = 3; + + /** + * The array of the used colors. + */ + public static Color[] colors = + new Color[] + { + Color.black, new Color(0, 80, 0), new Color(0, 0, 128), Color.blue + }; +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ClientFrame.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ClientFrame.java new file mode 100644 index 000000000000..c3d8300b7c34 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/ClientFrame.java @@ -0,0 +1,417 @@ +/* ClientFrame.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.GridLayout; +import java.awt.event.*; +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; + +import java.rmi.RemoteException; + +import javax.rmi.PortableRemoteObject; + +import javax.swing.*; +import java.awt.Dimension; + +/** + * The JFrame of the GUI client. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class ClientFrame + extends JFrame +{ + /** + * The size of the playing field. + */ + public final Dimension DESK_SIZE = + new Dimension(624, 352-PlayingDesk.W); + + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + // Define the application components: + + /** + * Central panel where the main action takes place. + */ + PlayingDesk desk = new PlayingDesk(); + + /** + * The scroll pane for canvas. + */ + JScrollPane scroll = new JScrollPane(); + + /** + * Will remember the manager IOR. + */ + String mior = ""; + + // The bottom panel contains the area that is used both to enter URL and + // for chatting. + JPanel pnBottom = new JPanel(); + + BorderLayout layBottom = new BorderLayout(); + + JTextField taUrl = new JTextField(); + + // The top primitive chatting panel, composed from labels. + JPanel pnChat = new JPanel(); + + GridLayout layChat = new GridLayout(); + + JLabel lbC3 = new JLabel(); + + JLabel lbC2 = new JLabel(); + + JLabel lbC1 = new JLabel(); + + // The button panel. + JPanel pnButtons = new JPanel(); + + GridLayout layButtons = new GridLayout(); + + JButton bLeave = new JButton(); + + JButton bConnect = new JButton(); + + JButton bExit = new JButton(); + + JButton bReset = new JButton(); + + JLabel lbState = new JLabel(); + + JButton bChat = new JButton(); + + JButton bPaste = new JButton(); + + public ClientFrame() + { + try + { + jbInit(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + private void jbInit() + throws Exception + { + desk.frame = this; + + pnBottom.setLayout(layBottom); + + pnChat.setLayout(layChat); + layChat.setColumns(1); + layChat.setRows(3); + + lbC1.setText("This program needs the game server (see README on how to start it)."); + lbC2.setText("Enter the game server address (host:port)"); + lbC3.setText("Pressing \'Connect\' with the empty address will start the server on " + + "the local machine."); + bLeave.setEnabled(true); + bLeave.setToolTipText("Leave if either you have lost or do not want longer to play with " + + "this partner."); + bLeave.setText("Leave game"); + bLeave.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bLeave_actionPerformed(e); + } + }); + bConnect.setToolTipText("Connect your playing partner"); + bConnect.setText("Connect"); + bConnect.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bConnect_actionPerformed(e); + } + }); + pnButtons.setLayout(layButtons); + bExit.setToolTipText("Exit this program"); + bExit.setText("Exit"); + bExit.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bExit_actionPerformed(e); + } + }); + layButtons.setHgap(2); + bReset.setToolTipText("Restart the game. The partner may choose to exit!"); + bReset.setText("Reset game"); + bReset.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bReset_actionPerformed(e); + } + }); + lbState.setText("Disconnected"); + bChat.setToolTipText("Send message to player. Reuse the address "+ + "field to enter the message."); + bChat.setText("Chat"); + bChat.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bChat_actionPerformed(e); + } + }); + + bPaste.setText("Paste"); + bPaste.setToolTipText("Paste, same as Ctrl-V"); + bPaste.addActionListener(new java.awt.event.ActionListener() + { + public void actionPerformed(ActionEvent e) + { + bPaste_actionPerformed(e); + } + }); + + desk.setMaximumSize(DESK_SIZE); + desk.setPreferredSize(DESK_SIZE); + + scroll.getViewport().add(desk, null); + getContentPane().add(scroll, BorderLayout.CENTER); + getContentPane().add(pnBottom, BorderLayout.SOUTH); + + pnBottom.add(taUrl, BorderLayout.CENTER); + pnBottom.add(pnChat, BorderLayout.NORTH); + + pnChat.add(lbC1, null); + pnChat.add(lbC2, null); + pnChat.add(lbC3, null); + pnBottom.add(pnButtons, BorderLayout.SOUTH); + pnButtons.add(lbState, null); + pnButtons.add(bConnect, null); + pnButtons.add(bChat, null); + pnButtons.add(bLeave, null); + pnButtons.add(bReset, null); + pnButtons.add(bExit, null); + pnButtons.add(bPaste, null); + + desk.player.set_current_state(State.DISCONNECTED); + } + + /** + * Handles exit procedure. + */ + protected void processWindowEvent(WindowEvent e) + { + super.processWindowEvent(e); + if (e.getID() == WindowEvent.WINDOW_CLOSING) + { + bExit_actionPerformed(null); + } + } + + /** + * Handles the connection procedure. + */ + void bConnect_actionPerformed(ActionEvent e) + { + try + { + int state = desk.player.get_current_state(); + + if (state == State.DISCONNECTED || state == State.ERROR) + { + talk(ChatConstants.colors[0], "Connecting..."); + + if (desk.manager == null) + { + mior = taUrl.getText().trim(); + + // Obtain the manager object: + org.omg.CORBA.Object object = null; + + try + { + object = desk.orb.string_to_object(mior); + } + catch (Exception exc) + { + // Maybe CORBA 3.0.3 is not completely implemented? + if (mior.startsWith("http://") || mior.startsWith("ftp://") + || mior.startsWith("file://")) + object = desk.orb.string_to_object(IorReader.readUrl(mior)); + else + throw exc; + } + + desk.manager = (GameManager) PortableRemoteObject.narrow( + object, GameManager.class); + + // Export the desk.player as a remote object. + PortableRemoteObject.exportObject(desk.player); + } + + desk.player.set_current_state(State.QUEUED); + desk.manager.requestTheGame(desk.player); + } + + // Save the specified IOR for the future use: + File gmf = new File(OrbStarter.WRITE_URL_TO_FILE); + FileWriter f = new FileWriter(gmf); + BufferedWriter b = new BufferedWriter(f); + + b.write(mior); + b.close(); + } + catch (Exception ex) + { + talk(Color.red, "The manager is not reachable by this address."); + talk(Color.red, ex.getMessage()); + desk.player.set_current_state(State.DISCONNECTED); + } + } + + /** + * Display the new message with the given color. Shift the other messages over + * the labels. + */ + public void talk(Color color, String text) + { + lbC1.setText(lbC2.getText()); + lbC1.setForeground(lbC2.getForeground()); + + lbC2.setText(lbC3.getText()); + lbC2.setForeground(lbC3.getForeground()); + + lbC3.setText(text); + lbC3.setForeground(color); + } + + /** + * Exit this program. + */ + void bExit_actionPerformed(ActionEvent e) + { + try + { + if (desk.player.get_current_state() != State.DISCONNECTED + && desk.player.partner != null) + { + desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER, + "I close the program!"); + desk.player.partner.disconnect(); + } + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application that + // may be modified for learning purposes. + ex.printStackTrace(); + } + System.exit(0); + } + + void bReset_actionPerformed(ActionEvent e) + { + if (desk.player.partner != null) + { + try + { + desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER, + "Your partner restarted the game."); + + desk.player.start_game(desk.player.partner, false); + desk.player.partner.start_game(desk.player, true); + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application + // that + // may be modified for learning purposes. + ex.printStackTrace(); + } + } + else + talk(Color.black, "You have not started the game yet."); + } + + void bLeave_actionPerformed(ActionEvent e) + { + desk.player.leave(); + } + + void bChat_actionPerformed(ActionEvent e) + { + try + { + if (desk.player.partner != null) + { + String message = taUrl.getText(); + desk.player.partner.receive_chat(ChatConstants.REMOTE_PLAYER, message); + talk(ChatConstants.colors[ChatConstants.SELF], message); + taUrl.setText(""); + } + else + { + talk(Color.black, "Sorry, not connected to anybody"); + } + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application that + // may be modified for learning purposes. + ex.printStackTrace(); + } + } + + /** + * Work around our keyboard shortcut handling that is still not working + * properly. + */ + void bPaste_actionPerformed(ActionEvent e) + { + taUrl.paste(); + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Demo.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Demo.java new file mode 100644 index 000000000000..b83217896d57 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Demo.java @@ -0,0 +1,99 @@ +/* Demo.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Dimension; +import java.awt.Toolkit; +import java.io.BufferedReader; +import java.io.File; +import java.io.FileReader; + +/** + * The main executable class of the game client. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class Demo +{ + + public static void main(String[] args) + { + ClientFrame frame = new ClientFrame(); + frame.setSize(new Dimension(640, 480)); + frame.setTitle("Make vertical, horizontal or diagonal line of 5 dots. " + + "Click mouse to set the dot."); + frame.validate(); + + // Center the window + Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); + Dimension frameSize = frame.getSize(); + if (frameSize.height > screenSize.height) + { + frameSize.height = screenSize.height; + } + if (frameSize.width > screenSize.width) + { + frameSize.width = screenSize.width; + } + frame.setLocation((screenSize.width - frameSize.width) / 2, + (screenSize.height - frameSize.height) / 2); + frame.setVisible(true); + + // Set the ior. + try + { + if (OrbStarter.WRITE_URL_TO_FILE != null) + { + File saved_ior = new File(OrbStarter.WRITE_URL_TO_FILE); + if (saved_ior.exists()) + { + FileReader f = new FileReader(saved_ior); + String s = new BufferedReader(f).readLine(); + frame.taUrl.setText(s); + } + } + } + catch (Exception e) + { + // We will print the exception, because this is a demo program - + // expected to be modified by user. + e.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManager.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManager.java new file mode 100644 index 000000000000..4d632e8bf574 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManager.java @@ -0,0 +1,68 @@ +/* GameManager.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * The game manager interface. + * + * Defines the operations of the game server that connects two players into + * the game. The game server does not participate in the game itself. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public interface GameManager extends Remote +{ + /** + * Register the newPlayer as the person who is willing to play. When another + * player calls this method, the Manager connects them by calling + * {@link PlayerCommunicator#start_game}. The manager provides the partner + * and sets (randomly) the starting side. + */ + void requestTheGame(Player newPlayer) throws RemoteException; + + /** + * Unregister the player that left and is no longer waiting for a playing + * partner to come. + * @throws RemoteException + */ + void unregister(Player player) throws RemoteException; +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManagerImpl.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManagerImpl.java new file mode 100644 index 000000000000..fc449bc50ba2 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/GameManagerImpl.java @@ -0,0 +1,135 @@ +/* GameManagerImpl.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.rmi.RemoteException; + +import org.omg.CORBA.ORB; +import org.omg.CORBA.Object; + +/** + * The manager connects two players into the game. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class GameManagerImpl + implements GameManager +{ + /** + * The game manager IOR. + */ + static String ior; + + /** + * The game manager ORB. + */ + static ORB orb; + + /** + * True if the manager started ok. + */ + static boolean ok; + + /** + * Another player that is already waiting for the game. + */ + Player queuedPlayer = null; + + public synchronized void requestTheGame(Player newPlayer) + throws RemoteException + { + System.out.println("Game requested"); + + if (queuedPlayer == null) + { + // No other player so far. + newPlayer.receive_chat(ChatConstants.GAME_SERVER, + "Request registered, waiting for the other player to come..."); + System.out.println("Player queued."); + queuedPlayer = newPlayer; + } + else if (queuedPlayer.equals(newPlayer)) + { + // The same player applies again. + newPlayer.receive_chat(ChatConstants.GAME_SERVER, + "No other player so far... Please wait."); + } + else + { + // As the queued player waited for the game, we allow him/her + // to start the game. This is a reward for waiting. + newPlayer.receive_chat(ChatConstants.GAME_SERVER, + "The other player is waiting. The game started, your " + + "partner begins..."); + queuedPlayer.receive_chat(ChatConstants.GAME_SERVER, + "The other player arrived. Lets play, you begin the game now..."); + + newPlayer.start_game(queuedPlayer, false); + queuedPlayer.start_game(newPlayer, true); + + queuedPlayer = null; + System.out.println("Players connected."); + } + } + + /** + * Unregister the player who left and is no longer waiting for another side. + */ + public void unregister(Player player) + throws RemoteException + { + if (queuedPlayer != null) + { + // We need to verify the identity of the player being unregistered. + // The stubs, being derived from the org.omg.CORBA.Object, have the + // method for this. This method compares the player host address, + // used port and the object key. + if (player instanceof Object && queuedPlayer instanceof Object) + { + Object a = (Object) player; + Object b = (Object) queuedPlayer; + + if (a._is_equivalent(b)) + queuedPlayer = null; + } + else + queuedPlayer = null; + } + System.out.println("Unregistering player"); + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/IorReader.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/IorReader.java new file mode 100644 index 000000000000..a976def74f3a --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/IorReader.java @@ -0,0 +1,124 @@ +/* IorReader.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.io.File; +import java.io.FileReader; +import java.io.IOException; +import java.io.InputStreamReader; +import java.net.MalformedURLException; +import java.net.URL; + +import org.omg.CORBA.BAD_PARAM; +import org.omg.CORBA.DATA_CONVERSION; + +/** + * Reads the remote URL. Following formal/04-03-12, CORBA should be able to do + * this without the help of this class. However some popular class libraries + * are written using the older CORBA specifications and may not handle + * functionality, require by this game. This class substitutes the functionality, + * ensuring that these implementations will also start and we will be able + * to test the interoperability. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class IorReader +{ + /** + * Read IOR from the remote URL. + */ + public static String readUrl(String url) + { + URL u; + try + { + u = new URL(url); + } + catch (MalformedURLException mex) + { + throw new BAD_PARAM("Malformed URL: '" + url + "'"); + } + + try + { + InputStreamReader r = new InputStreamReader(u.openStream()); + + StringBuffer b = new StringBuffer(); + int c; + + while ((c = r.read()) > 0) + b.append((char) c); + + return b.toString().trim(); + } + catch (Exception exc) + { + DATA_CONVERSION d = new DATA_CONVERSION("Reading " + url + " failed."); + throw d; + } + } + + /** + * Read IOR from the file in the local file system. + */ + public static String readFile(String file) + { + File f = new File(file); + if (!f.exists()) + { + DATA_CONVERSION err = new DATA_CONVERSION(f.getAbsolutePath() + + " does not exist."); + throw err; + } + try + { + char[] c = new char[(int) f.length()]; + FileReader fr = new FileReader(f); + fr.read(c); + fr.close(); + return new String(c).trim(); + } + catch (IOException ex) + { + DATA_CONVERSION d = new DATA_CONVERSION(); + d.initCause(ex); + throw (d); + } + } +} diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/OrbStarter.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/OrbStarter.java new file mode 100644 index 000000000000..3852945c6b96 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/OrbStarter.java @@ -0,0 +1,236 @@ +/* OrbStarter.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.rmi.RemoteException; +import java.util.Properties; + +import javax.rmi.PortableRemoteObject; +import javax.rmi.CORBA.Tie; + +import org.omg.CORBA.ORB; +import org.omg.PortableServer.POA; +import org.omg.PortableServer.POAHelper; +import org.omg.PortableServer.Servant; + +/** + * Starts the ORBs, involved into this application. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class OrbStarter +{ + /** + * The game manager name server port. This server allows to access the game + * manager by host (IP) and port rather than by the rather long IOR string. + */ + static int MANAGER_NAMER_PORT = 1500; + + /** + * The used port range (understood and used by GNU Classpath only). + */ + static String USED_PORT_RANGE = "1501-1503"; + + /** + * Specify the file where under start the game manager writes its IOR. + * You may specify the path if the game manager and player clients have + * access to some share file system or if you prefer to write IOR to + * floppy and then read from the floppy on the client side. Both clients + * and server will use this constant. Set to null not to write the IOR. + */ + static String WRITE_URL_TO_FILE = "game_manager_ior.txt"; + + /** + * Start the manager ORB. + * @return the manager URL if it starts. + */ + public static String startManager(final String[] args) + { + GameManagerImpl.ior = null; + GameManagerImpl.ok = false; + + final Properties p = new Properties(); + p.put("gnu.CORBA.ListenerPort", USED_PORT_RANGE); + + try + { + new Thread() + { + public void run() + { + try + { + GameManagerImpl.orb = ORB.init(args, p); + + // Obtain the root poa: + POA rootPOA = POAHelper.narrow(GameManagerImpl.orb.resolve_initial_references("RootPOA")); + + GameManagerImpl impl = new GameManagerImpl(); + + PortableRemoteObject.exportObject(impl); + + // Construct the tie that is also the servant. + Tie tie = new _GameManagerImpl_Tie(); + + // Set the invocation target for this tie. + tie.setTarget(impl); + + // Obtain the reference to the corresponding CORBA object: + org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie); + + GameManagerImpl.ok = true; + + // Activate the root POA. + rootPOA.the_POAManager().activate(); + + // Get the IOR URL that must be passed to clients. + GameManagerImpl.ior = GameManagerImpl.orb.object_to_string(object); + + GameManagerImpl.orb.run(); + } + catch (Exception exc) + { + exc.printStackTrace(); + GameManagerImpl.ior = "Unable to start the ORB: " + exc; + } + } + }.start(); + + // Wait the thread to enter orb.run. + long t = System.currentTimeMillis(); + while (GameManagerImpl.ior == null + && System.currentTimeMillis() - t < 20000) + { + Thread.sleep(100); + } + + return GameManagerImpl.ior; + } + catch (Exception e) + { + e.printStackTrace(); + return "Exception: " + e; + } + } + + /** + * Start the client ORB. + */ + public static String startPlayer(final Player player, final PlayingDesk desk) + { + desk.ior = null; + desk.ok = false; + + final Properties p = new Properties(); + p.put("gnu.CORBA.ListenerPort", USED_PORT_RANGE); + + try + { + new Thread() + { + public void run() + { + try + { + desk.orb = ORB.init(new String[0], p); + + POA rootPOA = POAHelper.narrow(desk.orb.resolve_initial_references("RootPOA")); + rootPOA.the_POAManager().activate(); + + // Construct the tie. + Tie tie = new _PlayerImpl_Tie(); + + // Set the implementing class (invocation target). + tie.setTarget(new PlayerImpl()); + + // Connect the tie as POA servant. + org.omg.CORBA.Object object = rootPOA.servant_to_reference((Servant) tie); + + // Get the stringified reference. + desk.ior = desk.orb.object_to_string(object); + + // Mark that the object was created OK. + desk.ok = true; + desk.orb.run(); + } + catch (Exception exc) + { + exc.printStackTrace(); + desk.ior = "Unable to start the ORB: " + exc; + } + } + }.start(); + + long t = System.currentTimeMillis(); + while (desk.ior == null && System.currentTimeMillis() - t < 20000) + { + Thread.sleep(100); + } + } + catch (Exception e) + { + e.printStackTrace(); + return "Exception: " + e; + } + + // Add shutdown hook to unregister from the manager. + Runtime.getRuntime().addShutdownHook(new Thread() + { + public void run() + { + if (desk.manager != null && player != null) + { + try + { + desk.manager.unregister(player); + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo + // application that + // may be modified for learning purposes. + ex.printStackTrace(); + } + desk.manager = null; + } + } + }); + return desk.ior; + } +} diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Player.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Player.java new file mode 100644 index 000000000000..ff5624b79c42 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/Player.java @@ -0,0 +1,96 @@ +/* Player.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Point; + +import java.rmi.Remote; +import java.rmi.RemoteException; + +/** + * Defines remote methods that are invoked by another player or by the + * challenge server. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public interface Player extends Remote +{ + /** + * Receive the invitation to play from the patner or the game manager. + * + * @param address the address (host and port) of the remote partner. + * @param youStart if true, the game manager instructs to start + * the game first (another side is instructed to start the game second). + * + * @return true on success. + */ + boolean start_game(Player otherPlayer, boolean youStart) + throws RemoteException; + + /** + * Get the state of the local player (one of the constants, defined + * in this interface). + */ + int get_current_state() throws RemoteException; + + /** + * Receive the chat message from the friend or challenge server (remote). + * Possible at any state, always remote. + * + * @param color the color code, used to highlight the message. + * @param text the message text. + */ + void receive_chat(byte color, String test) throws RemoteException; + + /** + * Indicated that the remote side leaves the game (capitulating). + */ + void disconnect() throws RemoteException; + + /** + * Receive friends move (possible at I_WAIT_FOR_YOUR_MOVE). + * + * @param x grid position. + * @param y grid position. + * + * @param sessionId the session id, must match (otherwise the call is ignored). + * @param victory if not a null, the friend thinks that it has won, the parameter + * containing the ends of the builded line. + */ + void receive_move(int x, int y, Point[] victory) throws RemoteException; +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayerImpl.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayerImpl.java new file mode 100644 index 000000000000..c30f7d51a42c --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayerImpl.java @@ -0,0 +1,275 @@ +/* PlayerImpl.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Color; +import java.awt.Point; + +import java.rmi.RemoteException; + +/** + * The implementation of the PlayerCommunicator, providing the local + * functionality. Apart remote methods, the class also defines some local + * methods, needed for the co-ordinated work with the game user interface. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class PlayerImpl + implements Player, State +{ + /** + * The playing table. + */ + PlayingDesk desk; + + /** + * The state of this player (one of the constants, defined in the player + * interface. + */ + private int state = DISCONNECTED; + + /** + * The other player. + */ + Player partner; + + /** + * Called when the local player refuses to continue the game. + */ + public void leave() + { + try + { + if (state == I_THINK || state == I_WAIT_FOR_YOUR_MOVE) + { + partner.receive_chat(ChatConstants.REMOTE_PLAYER, + "Your partner has left the game."); + partner.disconnect(); + } + else if (state == State.QUEUED) + { + if (desk.manager != null) + desk.manager.unregister(desk.player); + receive_chat(ChatConstants.SYSTEM, + "Do not be so pessimistic, try to play first!"); + } + set_current_state(State.DISCONNECTED); + + desk.frame.bChat.setEnabled(false); + desk.frame.bLeave.setEnabled(false); + desk.frame.bConnect.setEnabled(true); + desk.frame.taUrl.setText(desk.frame.mior); + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application that + // may be modified for learning purposes. + ex.printStackTrace(); + } + } + + /** + * Called when we make the move. The PlayingTable is responsible for checking + * the correctness of the move and detecting the victory. + * + * @param x x position of the new dot. + * @param y y position of the new dot. + * + * @param victory array of two memebers, representing the endpoints of the + * drawn line (victory detected) or null if no such yet exists. + */ + public void we_move(int x, int y, Point[] victory) + { + try + { + set_current_state(I_WAIT_FOR_YOUR_MOVE); + partner.receive_move(x, y, victory); + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application that + // may be modified for learning purposes. + ex.printStackTrace(); + + state = ERROR; + } + } + + /** + * Set the current state. + */ + public void set_current_state(int new_state) + { + state = new_state; + + if (state == DISCONNECTED) + { + setStatus("Disconnected"); + } + else if (state == I_THINK) + { + setStatus("Our move"); + } + else if (state == I_WAIT_FOR_YOUR_MOVE) + { + setStatus("Partner's move"); + } + else if (state == ERROR) + { + setStatus("Error."); + } + else if (state == I_HAVE_LOST) + { + setStatus("We lost"); + } + else if (state == I_HAVE_WON) + { + setStatus("Victory"); + } + else if (state == QUEUED) + { + setStatus("Queued"); + } + else + { + setStatus("State " + state); + } + + boolean connected = state != State.DISCONNECTED; + + desk.frame.bConnect.setEnabled(!connected && state != State.QUEUED); + desk.frame.bReset.setEnabled(connected); + desk.frame.bLeave.setEnabled(connected); + desk.frame.bChat.setEnabled(connected); + } + + /** + * Show the state in the status line. + */ + public void setStatus(String status) + { + desk.frame.lbState.setText(status); + } + + /** + * Receive the invitation to play from the patner or the game manager. + * + * @param address the address (host and port) of the remote partner. + * @param youStart if true, the game manager instructs to start the game first + * (another side is instructed to start the game second). + * + * Game server may also chat a little bit with both players, saying that the + * game has started. + * + * @return true on success. + */ + public boolean start_game(Player otherPlayer, boolean youStart) + throws RemoteException + { + partner = otherPlayer; + desk.reset(); + + if (youStart) + { + set_current_state(I_THINK); + } + else + { + set_current_state(I_WAIT_FOR_YOUR_MOVE); + } + + desk.frame.taUrl.setText(""); + + return true; + } + + /** + * Get the state of the local player (one of the constants, defined in this + * interface). + */ + public int get_current_state() + throws RemoteException + { + return state; + } + + /** + * Receive the chat message from the friend or challenge server (remote). + * Possible at any state, always remote. + * + * @param color the color code, used to highlight the message. + * @param text the message text. + */ + public void receive_chat(byte color, String text) + throws RemoteException + { + if (color >= ChatConstants.colors.length) + color = ChatConstants.REMOTE_PLAYER; + + desk.frame.talk(ChatConstants.colors[color], text); + } + + /** + * Indicated that the remote side leaves the game (capitulating). + */ + public void disconnect() + throws RemoteException + { + desk.frame.talk(Color.red, "The partner leaves the game."); + partner = null; + set_current_state(DISCONNECTED); + + desk.frame.taUrl.setText(desk.frame.mior); + } + + /** + * Receive friends move (possible at I_WAIT_FOR_YOUR_MOVE). + * + * @param x grid position. + * @param y grid position. + * @param victory if not a null, the friend thinks that it has won, the + * parameter containing the ends of the builded line. + */ + public void receive_move(int x, int y, Point[] victory) + throws RemoteException + { + // The state changes are handled by the PlayingTable + desk.friendsMove(x, y, victory); + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayingDesk.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayingDesk.java new file mode 100644 index 000000000000..83178f93606f --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/PlayingDesk.java @@ -0,0 +1,512 @@ +/* PlayingDesk.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Color; +import java.awt.Graphics; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.rmi.RemoteException; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + +import javax.swing.JComponent; + +import org.omg.CORBA.ORB; + +/** + * Manages actions, related to the game rules and also does all painting. + * + * @author Audrius Meskauskas, Lithuania (AudriusA@Bioinformatics.org) + */ +public class PlayingDesk + extends JComponent + implements MouseListener, State +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + /** + * Indicates that the field point state is the red oval. + */ + public static final int RED = 0; + + /** + * Indicates that the field point state is the black cross. + */ + public static final int BLACK = 1; + + /** + * Indicates that the field point state is the hint, suggested by the fan. + */ + public static final int HINT = 2; + + /** + * The access to the main frame methods. + */ + ClientFrame frame; + + /** + * The access to the player communicator. + */ + PlayerImpl player; + + /** + * The game manager. + */ + GameManager manager; + + /** + * The player ORB. + */ + ORB orb; + + /** + * The player IOR. + */ + String ior; + + /** + * True if the player ORB started ok. + */ + boolean ok; + + /** + * The grid spacing. + */ + static int W = 16; + + /** + * The radius of the dots being painted. + */ + static int R = W / 3; + + /** + * The collection of the red dots. + */ + ArrayList reds = new ArrayList(); + + /** + * The collection of the black dots. + */ + ArrayList blacks = new ArrayList(); + + /** + * The array of hints. + */ + ArrayList hints = new ArrayList(); + + /** + * When the game is completed, obtains the value of the two end points of the + * created line. + */ + Point[] endOfGame; + + public PlayingDesk() + { + try + { + player = new PlayerImpl(); + player.desk = this; + + OrbStarter.startPlayer(player, this); + + jbInit(); + } + catch (Exception e) + { + e.printStackTrace(); + } + } + + /** + * Paint this component. + */ + public void paintComponent(Graphics g) + { + int w = getWidth(); + int h = getHeight(); + + g.setColor(Color.white); + g.fillRect(0, 0, w, h); + + drawGrid(w, h, g); + drawFigures(g); + } + + /** + * Check maybe a game is finished after setting the point N + */ + public Point[] checkFinished(Collection x, Point N) + { + Iterator iter = x.iterator(); + Point p; + + // The victory, if happens, must occur inside these boundaries: + int ax = N.x - 5; + int bx = N.x + 5; + + int ay = N.y - 5; + int by = N.y + 5; + + while (iter.hasNext()) + { + p = (Point) iter.next(); + + if (p.x > ax && p.x < bx && p.y > ay && p.y < by) + { + // Check the vertical line down + if (pointPresent(p.x, p.y + 1, x)) + if (pointPresent(p.x, p.y + 2, x)) + if (pointPresent(p.x, p.y + 3, x)) + if (pointPresent(p.x, p.y + 4, x)) + return new Point[] { p, new Point(p.x, p.y + 4) }; + + // Check the horizontal line left + if (pointPresent(p.x + 1, p.y, x)) + if (pointPresent(p.x + 2, p.y, x)) + if (pointPresent(p.x + 3, p.y, x)) + if (pointPresent(p.x + 4, p.y, x)) + return new Point[] { p, new Point(p.x + 4, p.y) }; + + // Check the diagonal line right down. + if (pointPresent(p.x + 1, p.y + 1, x)) + if (pointPresent(p.x + 2, p.y + 2, x)) + if (pointPresent(p.x + 3, p.y + 3, x)) + if (pointPresent(p.x + 4, p.y + 4, x)) + return new Point[] { p, new Point(p.x + 4, p.y + 4) }; + + // Check the diagonal line left down. + if (pointPresent(p.x - 1, p.y + 1, x)) + if (pointPresent(p.x - 2, p.y + 2, x)) + if (pointPresent(p.x - 3, p.y + 3, x)) + if (pointPresent(p.x - 4, p.y + 4, x)) + return new Point[] { p, new Point(p.x - 4, p.y + 4) }; + } + } + return null; + } + + /** + * Called when the "end of the game" situation is detected. + */ + public void drawFinishLine(int xa, int ya, int xb, int yb, Graphics g) + { + g.setColor(Color.blue); + + int hW = W / 2; + g.drawLine(xa * W + hW, ya * W + hW, xb * W + hW, yb * W + hW); + } + + /** + * Check for the presence of the given point in the collection. + */ + public final boolean pointPresent(int x, int y, Collection in) + { + Iterator iter = in.iterator(); + Point p; + while (iter.hasNext()) + { + p = (Point) iter.next(); + if (p.x == x && p.y == y) + return true; + } + return false; + } + + public void drawGrid(int w, int h, Graphics g) + { + g.setColor(Color.lightGray); + + // Draw vertical lines: + for (int x = 0; x < w; x += W) + { + g.drawLine(x, 0, x, h); + } + + // Draw horizontal lines: + for (int y = 0; y < h; y += W) + { + g.drawLine(0, y, w, y); + } + + g.setColor(Color.gray); + g.drawRect(0,0, frame.DESK_SIZE.width, frame.DESK_SIZE.height); + g.drawRect(0,0, frame.DESK_SIZE.width+3, frame.DESK_SIZE.height+3); + } + + public void drawFigures(Graphics g) + { + g.setColor(Color.red); + drawDots(reds, g, RED); + + g.setColor(Color.black); + drawDots(blacks, g, BLACK); + + g.setColor(Color.lightGray); + drawDots(hints, g, HINT); + + if (endOfGame != null) + drawFinishLine(endOfGame[0].x, endOfGame[0].y, endOfGame[1].x, + endOfGame[1].y, g); + } + + public Point makePoint(int x, int y) + { + return new Point(x / W, y / W); + } + + /** + * Draw a collection of dots (the collor must be set before calling the + * method). + */ + public void drawDots(Collection dots, Graphics g, int mode) + { + Iterator iter = dots.iterator(); + int x; + int y; + + int hW = W / 2; + int RR = R * 2; + int hR = R / 2; + Point p; + while (iter.hasNext()) + { + p = (Point) iter.next(); + x = p.x * W + hW; + y = p.y * W + hW; + + if (mode == RED) + g.drawOval(x - R, y - R, RR, RR); + else if (mode == BLACK) + { + g.drawLine(x - R, y - R, x + R, y + R); + g.drawLine(x - R, y + R, x + R, y - R); + } + else + { + // Hint. + g.drawOval(x - hR, y - hR, R, R); + } + } + } + + private void jbInit() + throws Exception + { + addMouseListener(this); + } + + public void mouseClicked(MouseEvent e) + { + try + { + int state = player.get_current_state(); + + // Check if the state is correct. + if (state == I_WAIT_FOR_YOUR_MOVE) + { + frame.talk(Color.black, + "It is now time for our partner's move, not ours. Please wait."); + } + else if (state == DISCONNECTED) + { + frame.talk(Color.black, + "We are not connected to the playing partner yet."); + } + else if (state == I_HAVE_LOST) + { + frame.talk(Color.black, + "We have already lost this battle, but why not to try again?"); + } + else if (state == I_HAVE_WON) + { + frame.talk(Color.black, + "The victory is ours, nothing more to do here."); + } + else if (player.partner == null) + frame.talk(Color.black, "No other player so far."); + else + { + int x = e.getX(); + int y = e.getY(); + + if (x>frame.DESK_SIZE.width || + y>frame.DESK_SIZE.height) + { + frame.talk(Color.black,"Outside the game area."); + return; + } + + Point p = makePoint(x, y); + + // Ignore clicks on the occupied cells. + if (pointPresent(p.x, p.y, reds) + || (pointPresent(p.x, p.y, blacks))) + { + frame.talk(Color.black, + "This is against the rules, select the unoccupied cell."); + return; + } + + reds.add(p); + + endOfGame = checkFinished(reds, p); + repaint(); + + if (endOfGame != null) + { + frame.talk(Color.red, "Our move " + p.x + "-" + p.y + + " and we win!"); + player.set_current_state(I_HAVE_WON); + } + else + { + frame.talk(Color.black, "Our move " + p.x + "-" + p.y + + ". Waiting for the other side move..."); + player.set_current_state(I_WAIT_FOR_YOUR_MOVE); + } + + player.partner.receive_move(p.x, p.y, endOfGame); + } + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application + // that may be modified for learning purposes. + ex.printStackTrace(); + } + } + + /** + * Handle the move of the other playing side. + */ + public void friendsMove(int x, int y, Point[] victory) + { + try + { + int state = player.get_current_state(); + if (state != I_WAIT_FOR_YOUR_MOVE || pointPresent(x, y, blacks)) + { + stateFailed("Move " + x + "-" + y); + } + else + { + blacks.add(new Point(x, y)); + repaint(); + + if (victory != null) + { + frame.talk(Color.red, + " We have lost this time, unfortunately.."); + player.set_current_state(I_HAVE_LOST); + endOfGame = victory; + } + else + { + frame.talk(Color.black, "Partner goes " + x + "-" + y + + ". Your move?"); + player.set_current_state(I_THINK); + } + } + } + catch (RemoteException rex) + { + rex.printStackTrace(); + } + } + + /** + * Prepare for the new game. + */ + public void reset() + { + blacks.clear(); + reds.clear(); + hints.clear(); + endOfGame = null; + repaint(); + } + + public void mouseEntered(MouseEvent m) + { + // Nothing to do. + } + + public void mousePressed(MouseEvent m) + { + // Nothing to do. + } + + public void mouseReleased(MouseEvent m) + { + // Nothing to do. + } + + public void mouseExited(MouseEvent m) + { + // Nothing to do. + } + + /** + * The systems detected the error conditions. The game cannot continue (the + * chat is still possible). + */ + public void stateFailed(String reason) + { + try + { + player.receive_chat(ChatConstants.REMOTE_PLAYER, + "Wrong move, game cannot continue (our state was " + + player.get_current_state() + ")"); + frame.talk(Color.red, "The remote side violates communicating rules."); + player.set_current_state(State.ERROR); + } + catch (RemoteException ex) + { + // We will print the exception because this is a demo application + // that may be modified for learning purposes. + ex.printStackTrace(); + } + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/State.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/State.java new file mode 100644 index 000000000000..7285396cdc8e --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/State.java @@ -0,0 +1,82 @@ +/* State.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +/** + * Defines the states in that the player can be. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public interface State { + /** + * The initial ("disconnected") state. + */ + int DISCONNECTED = 0; + + /** + * The state, indicating that the player has been queued for the game and + * waiting for the partner to come. + */ + int QUEUED = 1; + + /** + * The "my move" state. + */ + int I_THINK = 2; + + /** + * The "friend's move" state. + */ + int I_WAIT_FOR_YOUR_MOVE = 3; + + /** + * States that we have won. + */ + int I_HAVE_WON = 4; + + /** + * States that we have lost. + */ + int I_HAVE_LOST = 5; + + /** + * The "inconsistent" state when it is not possible to continue the game. + */ + int ERROR = -1; +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/X5Server.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/X5Server.java new file mode 100644 index 000000000000..2ef9241c5200 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/X5Server.java @@ -0,0 +1,175 @@ +/* GameManagerAddressServer.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.io.BufferedWriter; +import java.io.File; +import java.io.FileWriter; +import java.io.IOException; +import java.io.OutputStream; +import java.net.InetAddress; +import java.net.ServerSocket; +import java.net.Socket; + +/** + * The main executable class of the game manager server. + * + * The manager address server returns the IOR address string of the game + * manager. Hence the user does not need to enter the rather long IOR address + * string and only needs to specify the host and port of the machine where the + * game manager is running. + * + * The manager address server starts the main game manager as well. + * + * This server acts as a HTTP server that always returns the same response. This + * primitive functionality is sufficient for its task. + * + * The more complex CORBA applications should use the name service instead. We + * do not use the name service as this would require to start additional + * external application, specific for the different java platforms. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class X5Server +{ + /** + * Start the game manager. + */ + public static void main(String[] args) + { + // Start the game manager, write the IOR to the agreed location. + OrbStarter.startManager(args); + + if (!GameManagerImpl.ok) + { + System.out.println("Unable to start the game manager:"); + System.exit(1); + } + + // Print the IOR. + System.out.println(GameManagerImpl.ior); + + String manager_address = null; + + // Start the game manager server. + ServerSocket nameServer = null; + try + { + nameServer = new ServerSocket(OrbStarter.MANAGER_NAMER_PORT); + + System.out.println("The game manager is listening at:"); + manager_address = "http://" + + InetAddress.getLocalHost().getHostAddress() + ":" + + nameServer.getLocalPort(); + + System.out.println(manager_address); + + System.out.println("Enter this address to the " + + "input field of the game client."); + + System.out.println("Use ^C to stop the manager."); + } + catch (Exception ex) + { + System.out.println("The port " + OrbStarter.MANAGER_NAMER_PORT + + " is not available. The game manager namer will not start."); + System.exit(1); + } + + // Write the IOR to the local file system. + if (OrbStarter.WRITE_URL_TO_FILE != null) + { + try + { + File gmf = new File(OrbStarter.WRITE_URL_TO_FILE); + FileWriter f = new FileWriter(gmf); + BufferedWriter b = new BufferedWriter(f); + + b.write(manager_address); + b.close(); + } + catch (IOException e) + { + System.out.println("Local filesystem not accessible." + + "Read IOR from console."); + } + } + + // Do forever. + while (true) + { + try + { + Socket socket = nameServer.accept(); + + System.out.println("Connected."); + + // Set the two minutes timeout. + socket.setSoTimeout(1000 * 120); + + OutputStream out = socket.getOutputStream(); + + int length = GameManagerImpl.ior.length(); + + StringBuffer b = new StringBuffer(); + b.append("HTTP/1.0 200 OK\r\n"); + b.append("Content-Length: " + length + "\r\n"); + b.append("Connection: close\r\n"); + b.append("Content-Type: text/plain; charset=UTF-8\r\n"); + b.append("\r\n"); + + b.append(GameManagerImpl.ior); + + out.write(b.toString().getBytes("UTF-8")); + + socket.shutdownOutput(); + + if (!socket.isClosed()) + socket.close(); + + System.out.println("Completed."); + } + catch (Exception exc) + { + exc.printStackTrace(); + System.out.println("Network problem."); + } + } + } +} diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManagerImpl_Tie.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManagerImpl_Tie.java new file mode 100644 index 000000000000..17a62600c962 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManagerImpl_Tie.java @@ -0,0 +1,214 @@ +/* _GameManagerImpl_Tie.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.rmi.Remote; + +import javax.rmi.PortableRemoteObject; +import javax.rmi.CORBA.Tie; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.UnknownException; +import org.omg.PortableServer.Servant; + +/** + * Normally generated with rmic compiler, this class represents the GameManager + * Tie on the client side. The Game Manager methods contain the code for remote + * invocation. + * + * This class is normally generated with rmic from the {@link GameManagerImpl}: + * + *+ * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl + *+ * + * (the compiled package must be present in the current folder). + * + * In this example the class was manually edited and commented for better + * understanding of functionality. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class _GameManagerImpl_Tie + extends Servant + implements Tie +{ + /** + * The target, where remote invocations are forwarded. + */ + private GameManagerImpl target = null; + + /** + * The GameManager repository Id. + */ + private static final String[] _type_ids = + { "RMI:gnu.classpath.examples.CORBA.swing.x5.GameManager:0000000000000000" }; + + /** + * Set the target where the remote invocations are forwarded. + */ + public void setTarget(Remote a_target) + { + this.target = (GameManagerImpl) a_target; + } + + /** + * Get the target where the remote invocations are forwarded. + */ + public Remote getTarget() + { + return target; + } + + /** + * Get the CORBA object for that this Tie is currently serving the request. + * The same tie may serve multiple requests for the different objects in + * parallel threads. + */ + public org.omg.CORBA.Object thisObject() + { + return _this_object(); + } + + /** + * Deactivate this object. + */ + public void deactivate() + { + try + { + _poa().deactivate_object(_poa().servant_to_id(this)); + } + catch (org.omg.PortableServer.POAPackage.WrongPolicy exception) + { + } + catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception) + { + } + catch (org.omg.PortableServer.POAPackage.ServantNotActive exception) + { + } + } + + /** + * Get the ORB for this tie. + */ + public ORB orb() + { + return _orb(); + } + + /** + * Set the ORB for this tie. + */ + public void orb(ORB orb) + { + try + { + ((org.omg.CORBA_2_3.ORB) orb).set_delegate(this); + } + catch (ClassCastException e) + { + throw new org.omg.CORBA.BAD_PARAM( + "POA Servant requires an instance of org.omg.CORBA_2_3.ORB"); + } + } + + /** + * Return all interfaces, supported by this method. + */ + public String[] _all_interfaces(org.omg.PortableServer.POA poa, + byte[] objectId) + { + return _type_ids; + } + + /** + * This method is invoked by CORBA system to handle the remote invocation. + * + * @param method the name of the method being invoked. + * @param _in the stream to read the method parameters. + * @param reply the responsed handler that can create the output stream to + * write the parameters being returned. + */ + public OutputStream _invoke(String method, InputStream _in, + ResponseHandler reply) + throws SystemException + { + try + { + org.omg.CORBA_2_3.portable.InputStream in = + (org.omg.CORBA_2_3.portable.InputStream) _in; + if (method.equals("requestTheGame")) + { + Player p = (Player) PortableRemoteObject.narrow( + in.read_Object(), Player.class); + target.requestTheGame(p); + + OutputStream out = reply.createReply(); + return out; + } + else if (method.equals("unregister")) + { + Player p = (Player) PortableRemoteObject.narrow( + in.read_Object(), Player.class); + target.unregister(p); + + OutputStream out = reply.createReply(); + return out; + } + else + throw new BAD_OPERATION(); + } + catch (SystemException ex) + { + throw ex; + } + catch (Throwable ex) + { + ex.printStackTrace(); + throw new UnknownException(ex); + } + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManager_Stub.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManager_Stub.java new file mode 100644 index 000000000000..e9279963a6ad --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_GameManager_Stub.java @@ -0,0 +1,207 @@ +/* _GameManager_Stub.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; + +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Util; + +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ServantObject; + +/** + * Normally generated with rmic compiler, this class represents the GameManager + * Stub on the client side. The Game Manager methods contain the code for + * remote invocation. + * + * This class is normally generated with rmic from the {@link GameManagerImpl}: + *
+ * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl + *+ * (the compiled package must be present in the current folder). + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class _GameManager_Stub extends Stub implements GameManager +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + private static final String[] _type_ids = + { "RMI:gnu.classpath.examples.CORBA.swing.x5.GameManager:0000000000000000" }; + + public String[] _ids() + { + return _type_ids; + } + + /** + * Notify the manager that the player is no longer willing to play and + * should be removed from the queue. + */ + public void unregister(Player p) + throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA.portable.InputStream in = null; + try + { + OutputStream out = _request("unregister", true); + Util.writeRemoteObject(out, p); + _invoke(out); + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + unregister(p); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = + _servant_preinvoke("requestTheGame", GameManager.class); + if (so == null) + { + unregister(p); + return; + } + try + { + ((GameManager) so.servant).unregister(p); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + /** + * The method that the user should invoke. + */ + public void requestTheGame(Player arg0) throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA.portable.InputStream in = null; + try + { + OutputStream out = _request("requestTheGame", true); + Util.writeRemoteObject(out, arg0); + _invoke(out); + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + requestTheGame(arg0); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = + _servant_preinvoke("requestTheGame", GameManager.class); + if (so == null) + { + requestTheGame(arg0); + return; + } + try + { + Player arg0Copy = (Player) Util.copyObject(arg0, _orb()); + ((GameManager) so.servant).requestTheGame(arg0Copy); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_PlayerImpl_Tie.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_PlayerImpl_Tie.java new file mode 100644 index 000000000000..730c6f469a0a --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_PlayerImpl_Tie.java @@ -0,0 +1,212 @@ +/* _PlayerImpl_Tie.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Point; +import java.rmi.Remote; + +import javax.rmi.PortableRemoteObject; +import javax.rmi.CORBA.Tie; + +import org.omg.CORBA.BAD_OPERATION; +import org.omg.CORBA.ORB; +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.InputStream; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.ResponseHandler; +import org.omg.CORBA.portable.UnknownException; +import org.omg.PortableServer.Servant; + +/** + * Generate with rmic, command line + * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl + * (the compiled package must be present in the current folder). + * + * This class is normally generated with rmic from the {@link PlayerImpl}: + *
+ * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl + *+ * (the compiled package must be present in the current folder). + * + * In this example the class was manually edited and commented for better + * understanding of functionality. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class _PlayerImpl_Tie extends Servant implements Tie +{ + private PlayerImpl target = null; + private static final String[] _type_ids = + { "RMI:gnu.classpath.examples.CORBA.swing.x5.Player:0000000000000000" }; + + public void setTarget(Remote a_target) + { + this.target = (PlayerImpl) a_target; + } + + public Remote getTarget() + { + return target; + } + + public org.omg.CORBA.Object thisObject() + { + return _this_object(); + } + + public void deactivate() + { + try + { + _poa().deactivate_object(_poa().servant_to_id(this)); + } + catch (org.omg.PortableServer.POAPackage.WrongPolicy exception) + { + } + catch (org.omg.PortableServer.POAPackage.ObjectNotActive exception) + { + } + catch (org.omg.PortableServer.POAPackage.ServantNotActive exception) + { + } + } + + public ORB orb() + { + return _orb(); + } + + public void orb(ORB orb) + { + try + { + ((org.omg.CORBA_2_3.ORB) orb).set_delegate(this); + } + catch (ClassCastException e) + { + throw new org.omg.CORBA.BAD_PARAM( + "POA Servant requires an instance of org.omg.CORBA_2_3.ORB" + ); + } + } + + public String[] _all_interfaces(org.omg.PortableServer.POA poa, + byte[] objectId + ) + { + return _type_ids; + } + + public OutputStream _invoke(String method, InputStream _in, + ResponseHandler reply + ) throws SystemException + { + try + { + org.omg.CORBA_2_3.portable.InputStream in = + (org.omg.CORBA_2_3.portable.InputStream) _in; + switch (method.charAt(9)) + { + case 101 : + if (method.equals("start_game")) + { + Player arg0 = + (Player) PortableRemoteObject.narrow(in.read_Object(), + Player.class + ); + boolean arg1 = in.read_boolean(); + boolean result = target.start_game(arg0, arg1); + OutputStream out = reply.createReply(); + out.write_boolean(result); + return out; + } + + case 104 : + if (method.equals("receive_chat")) + { + byte arg0 = in.read_octet(); + String arg1 = (String) in.read_value(String.class); + target.receive_chat(arg0, arg1); + + OutputStream out = reply.createReply(); + return out; + } + + case 111 : + if (method.equals("receive_move")) + { + int arg0 = in.read_long(); + int arg1 = in.read_long(); + Point[] arg2 = (Point[]) in.read_value(Point[].class); + target.receive_move(arg0, arg1, arg2); + + OutputStream out = reply.createReply(); + return out; + } + + case 114 : + if (method.equals("_get_J_current_state")) + { + int result = target.get_current_state(); + OutputStream out = reply.createReply(); + out.write_long(result); + return out; + } + + case 116 : + if (method.equals("disconnect")) + { + target.disconnect(); + + OutputStream out = reply.createReply(); + return out; + } + } + throw new BAD_OPERATION("No such method: '"+method+"'"); + } + catch (SystemException ex) + { + throw ex; + } + catch (Throwable ex) + { + throw new UnknownException(ex); + } + } +} \ No newline at end of file diff --git a/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_Player_Stub.java b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_Player_Stub.java new file mode 100644 index 000000000000..eeb5cf0daa41 --- /dev/null +++ b/libjava/classpath/examples/gnu/classpath/examples/CORBA/swing/x5/_Player_Stub.java @@ -0,0 +1,397 @@ +/* _Player_Stub.java -- + Copyright (C) 2005 Free Software Foundation, Inc. + + This file is part of GNU Classpath. + + GNU Classpath is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2, or (at your option) + any later version. + + GNU Classpath is distributed in the hope that it will be useful, but + WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + General Public License for more details. + + You should have received a copy of the GNU General Public License + along with GNU Classpath; see the file COPYING. If not, write to the + Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA + 02110-1301 USA. + + Linking this library statically or dynamically with other modules is + making a combined work based on this library. Thus, the terms and + conditions of the GNU General Public License cover the whole + combination. + + As a special exception, the copyright holders of this library give you + permission to link this library with independent modules to produce an + executable, regardless of the license terms of these independent + modules, and to copy and distribute the resulting executable under + terms of your choice, provided that you also meet, for each linked + independent module, the terms and conditions of the license of that + module. An independent module is a module which is not derived from + or based on this library. If you modify this library, you may extend + this exception to your version of the library, but you are not + obligated to do so. If you do not wish to do so, delete this + exception statement from your version. */ + + +package gnu.classpath.examples.CORBA.swing.x5; + +import java.awt.Point; +import java.io.Serializable; +import java.rmi.RemoteException; +import java.rmi.UnexpectedException; + +import javax.rmi.CORBA.Stub; +import javax.rmi.CORBA.Util; + +import org.omg.CORBA.SystemException; +import org.omg.CORBA.portable.ApplicationException; +import org.omg.CORBA.portable.OutputStream; +import org.omg.CORBA.portable.RemarshalException; +import org.omg.CORBA.portable.ServantObject; + +/** + * Generate with rmic, command line + * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.PlayerImpl + * (the compiled package must be present in the current folder). + * + * This class is normally generated with rmic from the {@link GameManagerImpl}: + *
+ * rmic -iiop -poa -keep gnu.classpath.examples.CORBA.swing.x5.GameManagerImpl + *+ * (the compiled package must be present in the current folder). + * + * In this example the class was manually edited and commented for better + * understanding of functionality. + * + * @author Audrius Meskauskas (AudriusA@Bioinformatics.org) + */ +public class _Player_Stub extends Stub implements Player +{ + /** + * Use serialVersionUID for interoperability. + */ + private static final long serialVersionUID = 1; + + private static final String[] _type_ids = + { "RMI:gnu.classpath.examples.CORBA.swing.x5.Player:0000000000000000" }; + + public String[] _ids() + { + return _type_ids; + } + + public boolean start_game(Player arg0, boolean arg1) + throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA.portable.InputStream in = null; + try + { + OutputStream out = _request("start_game", true); + Util.writeRemoteObject(out, arg0); + out.write_boolean(arg1); + in = _invoke(out); + return in.read_boolean(); + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + return start_game(arg0, arg1); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = _servant_preinvoke("start_game", Player.class); + if (so == null) + { + return start_game(arg0, arg1); + } + try + { + Player arg0Copy = (Player) Util.copyObject(arg0, _orb()); + return ((Player) so.servant).start_game(arg0Copy, arg1); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + public int get_current_state() throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA.portable.InputStream in = null; + try + { + OutputStream out = _request("_get_J_current_state", true); + in = _invoke(out); + return in.read_long(); + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + return get_current_state(); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = + _servant_preinvoke("_get_J_current_state", Player.class); + if (so == null) + { + return get_current_state(); + } + try + { + return ((Player) so.servant).get_current_state(); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + public void receive_chat(byte arg0, String arg1) throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA_2_3.portable.InputStream in = null; + try + { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) _request("receive_chat", + true + ); + out.write_octet(arg0); + out.write_value(arg1, String.class); + _invoke(out); + } + catch (ApplicationException ex) + { + in = + (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + receive_chat(arg0, arg1); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = _servant_preinvoke("receive_chat", Player.class); + if (so == null) + { + receive_chat(arg0, arg1); + return; + } + try + { + ((Player) so.servant).receive_chat(arg0, arg1); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + public void disconnect() throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA.portable.InputStream in = null; + try + { + OutputStream out = _request("disconnect", true); + _invoke(out); + } + catch (ApplicationException ex) + { + in = ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + disconnect(); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = _servant_preinvoke("disconnect", Player.class); + if (so == null) + { + disconnect(); + return; + } + try + { + ((Player) so.servant).disconnect(); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + public void receive_move(int arg0, int arg1, Point[] arg2) + throws RemoteException + { + if (!Util.isLocal(this)) + { + try + { + org.omg.CORBA_2_3.portable.InputStream in = null; + try + { + org.omg.CORBA_2_3.portable.OutputStream out = + (org.omg.CORBA_2_3.portable.OutputStream) _request("receive_move", + true + ); + out.write_long(arg0); + out.write_long(arg1); + out.write_value(cast_array(arg2), Point[].class); + _invoke(out); + } + catch (ApplicationException ex) + { + in = + (org.omg.CORBA_2_3.portable.InputStream) ex.getInputStream(); + + String id = in.read_string(); + throw new UnexpectedException(id); + } + catch (RemarshalException ex) + { + receive_move(arg0, arg1, arg2); + } + finally + { + _releaseReply(in); + } + } + catch (SystemException ex) + { + throw Util.mapSystemException(ex); + } + } + else + { + ServantObject so = _servant_preinvoke("receive_move", Player.class); + if (so == null) + { + receive_move(arg0, arg1, arg2); + return; + } + try + { + Point[] arg2Copy = (Point[]) Util.copyObject(arg2, _orb()); + ((Player) so.servant).receive_move(arg0, arg1, arg2Copy); + } + catch (Throwable ex) + { + Throwable exCopy = (Throwable) Util.copyObject(ex, _orb()); + throw Util.wrapException(exCopy); + } + finally + { + _servant_postinvoke(so); + } + } + } + + // This method is required as a work-around for + // a bug in the JDK 1.1.6 verifier. + private Serializable cast_array(Object obj) + { + return (Serializable) obj; + } +} \ No newline at end of file diff --git a/libjava/classpath/gnu/CORBA/OrbFunctional.java b/libjava/classpath/gnu/CORBA/OrbFunctional.java index f147e817a0f9..7b9c34ada123 100644 --- a/libjava/classpath/gnu/CORBA/OrbFunctional.java +++ b/libjava/classpath/gnu/CORBA/OrbFunctional.java @@ -1612,6 +1612,18 @@ public class OrbFunctional extends OrbRestricted // TODO log it. return; } + finally + { + try + { + if (service!=null && !service.isClosed()) + service.close(); + } + catch (IOException ioex) + { + // OK. + } + } } /** diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java index f5ba3ad2c5e2..3e3125a2b388 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkDialogPeer.java @@ -44,10 +44,6 @@ import java.awt.Rectangle; import java.awt.event.PaintEvent; import java.awt.peer.DialogPeer; -import javax.swing.JDialog; -import javax.swing.JPopupMenu; -import javax.swing.JToolTip; - public class GtkDialogPeer extends GtkWindowPeer implements DialogPeer { @@ -87,27 +83,9 @@ public class GtkDialogPeer extends GtkWindowPeer void create () { Dialog dialog = (Dialog) awtComponent; - int type = GDK_WINDOW_TYPE_HINT_DIALOG; - - if (dialog instanceof JDialog) - { - Class heavyWeightClass; - try - { - heavyWeightClass = Class.forName("javax.swing.Popup$JWindowPopup"); - } - catch (ClassNotFoundException e) - { - throw new AssertionError(e); - } - - if (dialog.getClass() == heavyWeightClass - || ((JDialog) dialog).getContentPane() instanceof JToolTip) - type = GDK_WINDOW_TYPE_HINT_MENU; - } // Create a decorated dialog window. - create (type, !((Dialog) awtComponent).isUndecorated ()); + create (GDK_WINDOW_TYPE_HINT_DIALOG, !((Dialog) awtComponent).isUndecorated ()); gtkWindowSetModal (dialog.isModal ()); setTitle (dialog.getTitle ()); diff --git a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java index c84d51037e3a..57fb87f37bfe 100644 --- a/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java +++ b/libjava/classpath/gnu/java/awt/peer/gtk/GtkWindowPeer.java @@ -41,7 +41,6 @@ package gnu.java.awt.peer.gtk; import java.awt.Component; import java.awt.Frame; import java.awt.Window; -import java.awt.event.ComponentEvent; import java.awt.event.WindowEvent; import java.awt.peer.WindowPeer; @@ -80,12 +79,16 @@ public class GtkWindowPeer extends GtkContainerPeer void create (int type, boolean decorated) { + Window window = (Window) awtComponent; GtkWindowPeer parent_peer = null; Component parent = awtComponent.getParent(); - + + if (!window.isFocusableWindow()) + type = GDK_WINDOW_TYPE_HINT_MENU; + if (parent != null) parent_peer = (GtkWindowPeer) awtComponent.getParent().getPeer(); - + create (type, decorated, parent_peer); } diff --git a/libjava/classpath/gnu/java/net/protocol/file/Connection.java b/libjava/classpath/gnu/java/net/protocol/file/Connection.java index 52bd04845103..8e4a413667d1 100644 --- a/libjava/classpath/gnu/java/net/protocol/file/Connection.java +++ b/libjava/classpath/gnu/java/net/protocol/file/Connection.java @@ -59,6 +59,7 @@ import java.security.Permission; import java.text.SimpleDateFormat; import java.util.Date; import java.util.Locale; +import java.net.MalformedURLException; /** * This subclass of java.net.URLConnection models a URLConnection via @@ -124,6 +125,54 @@ public class Connection extends URLConnection permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION); } + /** + * Unquote "%" + hex quotes characters + * + * @param str The string to unquote or null. + * + * @return The unquoted string or null if str was null. + * + * @exception MalformedURLException If the given string contains invalid + * escape sequences. + * + * Sadly the same as URI.unquote, but there's nothing we can do to + * make it accessible. + * + */ + public static String unquote(String str) throws MalformedURLException + { + if (str == null) + return null; + byte[] buf = new byte[str.length()]; + int pos = 0; + for (int i = 0; i < str.length(); i++) + { + char c = str.charAt(i); + if (c > 127) + throw new MalformedURLException(str + " : Invalid character"); + if (c == '%') + { + if (i + 2 >= str.length()) + throw new MalformedURLException(str + " : Invalid quoted character"); + int hi = Character.digit(str.charAt(++i), 16); + int lo = Character.digit(str.charAt(++i), 16); + if (lo < 0 || hi < 0) + throw new MalformedURLException(str + " : Invalid quoted character"); + buf[pos++] = (byte) (hi * 16 + lo); + } + else + buf[pos++] = (byte) c; + } + try + { + return new String(buf, 0, pos, "utf-8"); + } + catch (java.io.UnsupportedEncodingException x2) + { + throw (Error) new InternalError().initCause(x2); + } + } + /** * "Connects" to the file by opening it. */ @@ -134,7 +183,7 @@ public class Connection extends URLConnection return; // If not connected, then file needs to be openned. - file = new File (getURL().getFile()); + file = new File (unquote(getURL().getFile())); if (! file.isDirectory()) { diff --git a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java index e854874208ac..e2a052ef5818 100644 --- a/libjava/classpath/gnu/java/net/protocol/jar/Connection.java +++ b/libjava/classpath/gnu/java/net/protocol/jar/Connection.java @@ -47,7 +47,10 @@ import java.net.MalformedURLException; import java.net.ProtocolException; import java.net.URL; import java.net.URLConnection; +import java.text.SimpleDateFormat; +import java.util.Date; import java.util.Hashtable; +import java.util.Locale; import java.util.jar.JarEntry; import java.util.jar.JarFile; import java.util.zip.ZipFile; @@ -60,6 +63,12 @@ import java.util.zip.ZipFile; */ public final class Connection extends JarURLConnection { + /** + * HTTP-style DateFormat, used to format the last-modified header. + * Lazy initialized since jar files are used during bootstrapping. + */ + private static SimpleDateFormat dateFormat; + private JarFile jar_file; private JarEntry jar_entry; private URL jar_url; @@ -82,7 +91,9 @@ public final class Connection extends JarURLConnection if ("file".equals (url.getProtocol())) { - File f = new File (url.getFile()); + String fn = url.getFile(); + fn = gnu.java.net.protocol.file.Connection.unquote(fn); + File f = new File (fn); jf = new JarFile (f, true, ZipFile.OPEN_READ); } else @@ -165,6 +176,38 @@ public final class Connection extends JarURLConnection return jar_file; } + public String getHeaderField(String field) + { + try + { + if (!connected) + connect(); + + if (field.equals("content-type")) + return guessContentTypeFromName(getJarEntry().getName()); + else if (field.equals("content-length")) + return Long.toString(getJarEntry().getSize()); + else if (field.equals("last-modified")) + { + // Both creating and manipulating dateFormat need synchronization. + synchronized (this.getClass()) + { + if (dateFormat == null) + dateFormat = new SimpleDateFormat + ("EEE, dd MMM yyyy hh:mm:ss 'GMT'", + new Locale ("En", "Us", "Unix")); + + return dateFormat.format(new Date(getJarEntry().getTime())); + } + } + } + catch (IOException e) + { + // Fall through. + } + return null; + } + public int getContentLength() { if (!connected) @@ -172,4 +215,19 @@ public final class Connection extends JarURLConnection return (int) jar_entry.getSize(); } + + public long getLastModified() + { + if (!connected) + return -1; + + try + { + return getJarEntry().getTime(); + } + catch (IOException e) + { + return -1; + } + } } diff --git a/libjava/classpath/java/awt/Component.java b/libjava/classpath/java/awt/Component.java index 9b389e21ed42..ec03d631dcfd 100644 --- a/libjava/classpath/java/awt/Component.java +++ b/libjava/classpath/java/awt/Component.java @@ -1409,7 +1409,6 @@ public abstract class Component { if (parent != null) { - Rectangle parentBounds = parent.getBounds(); Rectangle oldBounds = new Rectangle(oldx, oldy, oldwidth, oldheight); Rectangle newBounds = new Rectangle(x, y, width, height); @@ -1887,13 +1886,7 @@ public abstract class Component */ public void repaint() { - if(!isShowing()) - { - Component p = parent; - if (p != null) - p.repaint(0, getX(), getY(), width, height); - } - else + if (isShowing()) repaint(0, 0, 0, width, height); } @@ -1908,13 +1901,7 @@ public abstract class Component */ public void repaint(long tm) { - if(!isShowing()) - { - Component p = parent; - if (p != null) - p.repaint(tm, getX(), getY(), width, height); - } - else + if (isShowing()) repaint(tm, 0, 0, width, height); } @@ -1932,13 +1919,7 @@ public abstract class Component */ public void repaint(int x, int y, int w, int h) { - if(!isShowing()) - { - Component p = parent; - if (p != null) - p.repaint(0, x + getX(), y + getY(), width, height); - } - else + if (isShowing()) repaint(0, x, y, w, h); } @@ -1957,13 +1938,7 @@ public abstract class Component */ public void repaint(long tm, int x, int y, int width, int height) { - if(!isShowing()) - { - Component p = parent; - if (p != null) - p.repaint(tm, x + getX(), y + getY(), width, height); - } - else + if (isShowing()) { ComponentPeer p = peer; if (p != null) diff --git a/libjava/classpath/java/awt/Container.java b/libjava/classpath/java/awt/Container.java index 4676895bf640..ed791dc8b880 100644 --- a/libjava/classpath/java/awt/Container.java +++ b/libjava/classpath/java/awt/Container.java @@ -123,6 +123,7 @@ public class Container extends Component */ public Container() { + // Nothing to do here. } /** @@ -427,7 +428,8 @@ public class Container extends Component for (int j = 0; j < list.length; j++) r.removeComponentListener(list[j]); - r.removeNotify(); + if (r.isShowing()) + r.removeNotify(); System.arraycopy(component, index + 1, component, index, ncomponents - index - 1); @@ -846,7 +848,7 @@ public class Container extends Component */ public void paintComponents(Graphics g) { - super.paint(g); + paint(g); visitChildren(g, GfxPaintAllVisitor.INSTANCE, true); } @@ -1972,6 +1974,7 @@ public class Container extends Component */ protected AccessibleContainerHandler() { + // Nothing to do here. } /** @@ -2039,8 +2042,7 @@ class LightweightDispatcher implements Serializable * location, otherwise the appropriate component from the conditions * above. */ - Component getDeepestComponentForMouseEventAt ( - Component parent, int x, int y) + Component getDeepestComponentForMouseEventAt(Component parent, int x, int y) { if (parent == null || (! parent.contains(x, y))) return null; @@ -2064,8 +2066,7 @@ class LightweightDispatcher implements Serializable Point p = me.getPoint(); while (candidate == null && parent != null) { - candidate = - getDeepestComponentForMouseEventAt(parent, p.x, p.y); + candidate = getDeepestComponentForMouseEventAt(parent, p.x, p.y); if (candidate == null || (candidate.eventMask & me.getID()) == 0) { candidate = null; @@ -2147,14 +2148,12 @@ class LightweightDispatcher implements Serializable break; } - if (me.getID() == MouseEvent.MOUSE_RELEASED - || me.getID() == MouseEvent.MOUSE_PRESSED && modifiers > 0 + if (me.getID() == MouseEvent.MOUSE_PRESSED && modifiers > 0 || me.getID() == MouseEvent.MOUSE_DRAGGED) { // If any of the following events occur while a button is held down, // they should be dispatched to the same component to which the // original MOUSE_PRESSED event was dispatched: - // - MOUSE_RELEASED // - MOUSE_PRESSED: another button pressed while the first is held // down // - MOUSE_DRAGGED @@ -2204,10 +2203,13 @@ class LightweightDispatcher implements Serializable // there is a CLICKED event after this, it will do clean up. if (--pressCount == 0 && mouseEventTarget != pressedComponent) - pressedComponent = null; + { + pressedComponent = null; + pressCount = 0; + } break; } - + MouseEvent newEvt = AWTUtilities.convertMouseEvent(nativeContainer, me, mouseEventTarget); diff --git a/libjava/classpath/java/awt/image/MemoryImageSource.java b/libjava/classpath/java/awt/image/MemoryImageSource.java index c27e0bf7317d..95cd4081922c 100644 --- a/libjava/classpath/java/awt/image/MemoryImageSource.java +++ b/libjava/classpath/java/awt/image/MemoryImageSource.java @@ -187,7 +187,7 @@ public class MemoryImageSource implements ImageProducer ic = (ImageConsumer) list.elementAt(i); sendPicture(ic); if (animated) - ic.imageComplete(ImageConsumer.SINGLEFRAME); + ic.imageComplete(ImageConsumer.SINGLEFRAMEDONE); else ic.imageComplete(ImageConsumer.STATICIMAGEDONE); } diff --git a/libjava/classpath/java/io/FilePermission.java b/libjava/classpath/java/io/FilePermission.java index 356787bfa727..31802c631d6b 100644 --- a/libjava/classpath/java/io/FilePermission.java +++ b/libjava/classpath/java/io/FilePermission.java @@ -278,13 +278,13 @@ public final class FilePermission extends Permission implements Serializable break; } - if (readPerm && ! fp.readPerm) + if (fp.readPerm && ! readPerm) return false; - if (writePerm && ! fp.writePerm) + if (fp.writePerm && ! writePerm) return false; - if (executePerm && ! fp.executePerm) + if (fp.executePerm && ! executePerm) return false; - if (deletePerm && ! fp.deletePerm) + if (fp.deletePerm && ! deletePerm) return false; return true; diff --git a/libjava/classpath/java/net/URL.java b/libjava/classpath/java/net/URL.java index 627dbc391e92..1d947a0b46a6 100644 --- a/libjava/classpath/java/net/URL.java +++ b/libjava/classpath/java/net/URL.java @@ -408,10 +408,7 @@ public final class URL implements Serializable // The 1.2 doc specifically says these are copied to the new URL. host = context.host; port = context.port; - file = context.file; userInfo = context.userInfo; - if (file == null || file.length() == 0) - file = "/"; authority = context.authority; } } @@ -423,10 +420,13 @@ public final class URL implements Serializable protocol = context.protocol; host = context.host; port = context.port; - file = context.file; userInfo = context.userInfo; - if (file == null || file.length() == 0) - file = "/"; + if (spec.indexOf(":/", 1) < 0) + { + file = context.file; + if (file == null || file.length() == 0) + file = "/"; + } authority = context.authority; } else // Protocol NOT specified in spec. and no context available. diff --git a/libjava/classpath/java/net/URLClassLoader.java b/libjava/classpath/java/net/URLClassLoader.java index 726778eba0f8..9d0e5041006e 100644 --- a/libjava/classpath/java/net/URLClassLoader.java +++ b/libjava/classpath/java/net/URLClassLoader.java @@ -536,15 +536,15 @@ public class URLClassLoader extends SecureClassLoader Resource getResource(String name) { try - { - File file = new File(dir, name).getCanonicalFile(); - if (file.exists() && !file.isDirectory()) - return new FileResource(this, file); - } + { + File file = new File(dir, name).getCanonicalFile(); + if (file.exists() && !file.isDirectory()) + return new FileResource(this, file); + } catch (IOException e) - { - // Fall through... - } + { + // Fall through... + } return null; } } @@ -873,47 +873,47 @@ public class URLClassLoader extends SecureClassLoader // construct the class (and watch out for those nasty IOExceptions) try { - byte[] data; - InputStream in = resource.getInputStream(); - try - { - int length = resource.getLength(); - if (length != -1) - { - // We know the length of the data. - // Just try to read it in all at once - data = new byte[length]; - int pos = 0; - while (length - pos > 0) - { - int len = in.read(data, pos, length - pos); - if (len == -1) - throw new EOFException("Not enough data reading from: " - + in); - pos += len; - } - } - else - { - // We don't know the data length. - // Have to read it in chunks. - ByteArrayOutputStream out = new ByteArrayOutputStream(4096); - byte[] b = new byte[4096]; - int l = 0; - while (l != -1) - { - l = in.read(b); - if (l != -1) - out.write(b, 0, l); - } - data = out.toByteArray(); - } - } - finally - { - in.close(); - } - final byte[] classData = data; + byte[] data; + InputStream in = resource.getInputStream(); + try + { + int length = resource.getLength(); + if (length != -1) + { + // We know the length of the data. + // Just try to read it in all at once + data = new byte[length]; + int pos = 0; + while (length - pos > 0) + { + int len = in.read(data, pos, length - pos); + if (len == -1) + throw new EOFException("Not enough data reading from: " + + in); + pos += len; + } + } + else + { + // We don't know the data length. + // Have to read it in chunks. + ByteArrayOutputStream out = new ByteArrayOutputStream(4096); + byte[] b = new byte[4096]; + int l = 0; + while (l != -1) + { + l = in.read(b); + if (l != -1) + out.write(b, 0, l); + } + data = out.toByteArray(); + } + } + finally + { + in.close(); + } + final byte[] classData = data; // Now get the CodeSource final CodeSource source = resource.getCodeSource(); diff --git a/libjava/classpath/java/security/ProtectionDomain.java b/libjava/classpath/java/security/ProtectionDomain.java index a5851b5adf46..a8a093925049 100644 --- a/libjava/classpath/java/security/ProtectionDomain.java +++ b/libjava/classpath/java/security/ProtectionDomain.java @@ -37,6 +37,8 @@ exception statement from your version. */ package java.security; +import gnu.classpath.SystemProperties; + /** *
This ProtectionDomain
class encapsulates the characteristics
* of a domain, which encloses a set of classes whose instances are granted a
@@ -222,7 +224,7 @@ public class ProtectionDomain
*/
public String toString()
{
- String linesep = System.getProperty("line.separator");
+ String linesep = SystemProperties.getProperty("line.separator");
StringBuffer sb = new StringBuffer("ProtectionDomain (").append(linesep);
if (code_source == null)
diff --git a/libjava/classpath/javax/swing/JApplet.java b/libjava/classpath/javax/swing/JApplet.java
index 3ee1046c8022..e90c451891ee 100644
--- a/libjava/classpath/javax/swing/JApplet.java
+++ b/libjava/classpath/javax/swing/JApplet.java
@@ -189,7 +189,7 @@ public class JApplet extends Applet
protected String paramString()
{
- return "JFrame";
+ return super.paramString();
}
protected void processKeyEvent(KeyEvent e)
diff --git a/libjava/classpath/javax/swing/JComponent.java b/libjava/classpath/javax/swing/JComponent.java
index 021a2a340805..deb08c5db592 100644
--- a/libjava/classpath/javax/swing/JComponent.java
+++ b/libjava/classpath/javax/swing/JComponent.java
@@ -1918,9 +1918,15 @@ public abstract class JComponent extends Container implements Serializable
g2 = getComponentGraphics(g2);
g2.setClip(r.x, r.y, r.width, r.height);
isPaintingDoubleBuffered = true;
- paint(g2);
- isPaintingDoubleBuffered = false;
- g2.dispose();
+ try
+ {
+ paint(g2);
+ }
+ finally
+ {
+ isPaintingDoubleBuffered = false;
+ g2.dispose();
+ }
// Paint the buffer contents on screen.
g.drawImage(buffer, 0, 0, this);
@@ -2921,8 +2927,7 @@ public abstract class JComponent extends Container implements Serializable
{
super.removeNotify();
- // FIXME: remove the WHEN_IN_FOCUSED_WINDOW bindings from the
- // KeyboardManager
+ KeyboardManager.getManager().clearBindingsForComp(this);
// Notify ancestor listeners.
fireAncestorEvent(this, AncestorEvent.ANCESTOR_REMOVED);
diff --git a/libjava/classpath/javax/swing/JEditorPane.java b/libjava/classpath/javax/swing/JEditorPane.java
index 9ddf970deea0..39f7c1f142f0 100644
--- a/libjava/classpath/javax/swing/JEditorPane.java
+++ b/libjava/classpath/javax/swing/JEditorPane.java
@@ -59,6 +59,9 @@ import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
import javax.swing.text.JTextComponent;
+import javax.swing.text.View;
+import javax.swing.text.ViewFactory;
+import javax.swing.text.WrappedPlainView;
import javax.swing.text.html.HTML;
import javax.swing.text.html.HTMLDocument;
import javax.swing.text.html.HTMLEditorKit;
@@ -466,6 +469,30 @@ public class JEditorPane extends JTextComponent
}
}
+ /**
+ * An EditorKit used for plain text. This is the default editor kit for
+ * JEditorPanes.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
+ private static class PlainEditorKit extends DefaultEditorKit
+ {
+
+ /**
+ * Returns a ViewFactory that supplies WrappedPlainViews.
+ */
+ public ViewFactory getViewFactory()
+ {
+ return new ViewFactory()
+ {
+ public View create(Element el)
+ {
+ return new WrappedPlainView(el);
+ }
+ };
+ }
+ }
+
private static final long serialVersionUID = 3140472492599046285L;
private URL page;
@@ -497,12 +524,12 @@ public class JEditorPane extends JTextComponent
protected EditorKit createDefaultEditorKit()
{
- return new DefaultEditorKit();
+ return new PlainEditorKit();
}
public static EditorKit createEditorKitForContentType(String type)
{
- return new DefaultEditorKit();
+ return new PlainEditorKit();
}
/**
diff --git a/libjava/classpath/javax/swing/JList.java b/libjava/classpath/javax/swing/JList.java
index 4f5d3cc72c5b..caa7f310ea80 100644
--- a/libjava/classpath/javax/swing/JList.java
+++ b/libjava/classpath/javax/swing/JList.java
@@ -1322,7 +1322,11 @@ public class JList extends JComponent implements Accessible, Scrollable
/**
- * Returns index of the cell to which specified location is closest to
+ * Returns index of the cell to which specified location is closest to. If
+ * the location is outside the bounds of the list, then the greatest index
+ * in the list model is returned. If the list model is empty, then
+ * -1
is returned.
+ *
* @param location for which to look for in the list
*
* @return index of the cell to which specified location is closest to.
diff --git a/libjava/classpath/javax/swing/JMenu.java b/libjava/classpath/javax/swing/JMenu.java
index 9734eb8732fb..369c44d40c66 100644
--- a/libjava/classpath/javax/swing/JMenu.java
+++ b/libjava/classpath/javax/swing/JMenu.java
@@ -96,6 +96,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
public JMenu()
{
super();
+ setOpaque(false);
}
/**
@@ -107,6 +108,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
{
super(text);
popupMenu.setInvoker(this);
+ setOpaque(false);
}
/**
@@ -120,6 +122,7 @@ public class JMenu extends JMenuItem implements Accessible, MenuElement
super(action);
createActionChangeListener(this);
popupMenu.setInvoker(this);
+ setOpaque(false);
}
/**
diff --git a/libjava/classpath/javax/swing/JPanel.java b/libjava/classpath/javax/swing/JPanel.java
index 7805e92b6e9e..c02a9cfad6fe 100644
--- a/libjava/classpath/javax/swing/JPanel.java
+++ b/libjava/classpath/javax/swing/JPanel.java
@@ -137,6 +137,6 @@ public class JPanel extends JComponent implements Accessible
protected String paramString()
{
- return "JPanel";
+ return super.paramString();
}
}
diff --git a/libjava/classpath/javax/swing/JSplitPane.java b/libjava/classpath/javax/swing/JSplitPane.java
index cdab7bb6c4ef..70feefab26e9 100644
--- a/libjava/classpath/javax/swing/JSplitPane.java
+++ b/libjava/classpath/javax/swing/JSplitPane.java
@@ -170,13 +170,15 @@ public class JSplitPane extends JComponent implements Accessible
public static final int HORIZONTAL_SPLIT = 1;
/** The property fired when the last divider location property changes. */
- public static final String LAST_DIVIDER_LOCATION_PROPERTY = "lastDividerLocation";
+ public static final String LAST_DIVIDER_LOCATION_PROPERTY =
+ "lastDividerLocation";
/** The constraints string used to add components to the left. */
public static final String LEFT = "left";
/** The property fired when the one touch expandable property changes. */
- public static final String ONE_TOUCH_EXPANDABLE_PROPERTY = "oneTouchExpandable";
+ public static final String ONE_TOUCH_EXPANDABLE_PROPERTY =
+ "oneTouchExpandable";
/** The property fired when the orientation property changes. */
public static final String ORIENTATION_PROPERTY = "orientation";
@@ -199,7 +201,8 @@ public class JSplitPane extends JComponent implements Accessible
/** Whether the JSplitPane uses one touch expandable buttons. */
protected boolean oneTouchExpandable = false;
- // This is the master dividerSize variable and sets the BasicSplitPaneDivider one accordingly
+ // This is the master dividerSize variable and sets the
+ // BasicSplitPaneDivider one accordingly
/** The size of the divider. */
protected int dividerSize = 10;
@@ -286,7 +289,8 @@ public class JSplitPane extends JComponent implements Accessible
*/
public JSplitPane()
{
- this(HORIZONTAL_SPLIT, false, null, null);
+ this(HORIZONTAL_SPLIT, false, new JButton("left button"),
+ new JButton("right button"));
}
/**
@@ -300,7 +304,8 @@ public class JSplitPane extends JComponent implements Accessible
* @param constraints The constraints string to use.
* @param index Where to place to component in the list of components.
*
- * @throws IllegalArgumentException When the constraints is not a known identifier.
+ * @throws IllegalArgumentException When the constraints is not a known
+ * identifier.
*/
protected void addImpl(Component comp, Object constraints, int index)
{
@@ -310,34 +315,35 @@ public class JSplitPane extends JComponent implements Accessible
int place;
if (constraints == null)
{
- if (leftComponent == null)
- constraints = LEFT;
- else if (rightComponent == null)
- constraints = RIGHT;
+ if (leftComponent == null)
+ constraints = LEFT;
+ else if (rightComponent == null)
+ constraints = RIGHT;
}
if (constraints instanceof String)
{
- String placement = (String) constraints;
-
- if (placement.equals(BOTTOM) || placement.equals(RIGHT))
- {
- if (rightComponent != null)
- remove(rightComponent);
- rightComponent = comp;
- }
- else if (placement.equals(LEFT) || placement.equals(TOP))
- {
- if (leftComponent != null)
- remove(leftComponent);
- leftComponent = comp;
- }
- else if (placement.equals(DIVIDER))
- constraints = null;
- else
- throw new IllegalArgumentException("Constraints is not a known identifier.");
-
- super.addImpl(comp, constraints, index);
+ String placement = (String) constraints;
+
+ if (placement.equals(BOTTOM) || placement.equals(RIGHT))
+ {
+ if (rightComponent != null)
+ remove(rightComponent);
+ rightComponent = comp;
+ }
+ else if (placement.equals(LEFT) || placement.equals(TOP))
+ {
+ if (leftComponent != null)
+ remove(leftComponent);
+ leftComponent = comp;
+ }
+ else if (placement.equals(DIVIDER))
+ constraints = null;
+ else
+ throw new
+ IllegalArgumentException("Constraints is not a known identifier.");
+
+ super.addImpl(comp, constraints, index);
}
invalidate();
layout();
@@ -614,10 +620,10 @@ public class JSplitPane extends JComponent implements Accessible
{
if (newContinuousLayout != continuousLayout)
{
- boolean oldValue = continuousLayout;
- continuousLayout = newContinuousLayout;
- firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue,
- continuousLayout);
+ boolean oldValue = continuousLayout;
+ continuousLayout = newContinuousLayout;
+ firePropertyChange(CONTINUOUS_LAYOUT_PROPERTY, oldValue,
+ continuousLayout);
}
}
@@ -634,7 +640,8 @@ public class JSplitPane extends JComponent implements Accessible
public void setDividerLocation(double proportionalLocation)
{
if (proportionalLocation > 1 || proportionalLocation < 0)
- throw new IllegalArgumentException("proportion has to be between 0 and 1.");
+ throw new IllegalArgumentException
+ ("proportion has to be between 0 and 1.");
int max = (orientation == HORIZONTAL_SPLIT) ? getWidth() : getHeight();
setDividerLocation((int) (proportionalLocation * max));
@@ -649,9 +656,9 @@ public class JSplitPane extends JComponent implements Accessible
{
if (ui != null && location != getDividerLocation())
{
- int oldLocation = getDividerLocation();
- ((SplitPaneUI) ui).setDividerLocation(this, location);
- firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, location);
+ int oldLocation = getDividerLocation();
+ ((SplitPaneUI) ui).setDividerLocation(this, location);
+ firePropertyChange(DIVIDER_LOCATION_PROPERTY, oldLocation, location);
}
}
@@ -664,9 +671,9 @@ public class JSplitPane extends JComponent implements Accessible
{
if (newSize != dividerSize)
{
- int oldSize = dividerSize;
- dividerSize = newSize;
- firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize);
+ int oldSize = dividerSize;
+ dividerSize = newSize;
+ firePropertyChange(DIVIDER_SIZE_PROPERTY, oldSize, dividerSize);
}
}
@@ -683,10 +690,10 @@ public class JSplitPane extends JComponent implements Accessible
{
if (newLastLocation != lastDividerLocation)
{
- int oldValue = lastDividerLocation;
- lastDividerLocation = newLastLocation;
- firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue,
- lastDividerLocation);
+ int oldValue = lastDividerLocation;
+ lastDividerLocation = newLastLocation;
+ firePropertyChange(LAST_DIVIDER_LOCATION_PROPERTY, oldValue,
+ lastDividerLocation);
}
}
@@ -696,11 +703,11 @@ public class JSplitPane extends JComponent implements Accessible
* @param comp The left component.
*/
public void setLeftComponent(Component comp)
- {
+ {
if (comp != null)
add(comp, LEFT);
else
- add(new JButton("left button"), LEFT);
+ remove (leftComponent);
}
/**
@@ -715,10 +722,10 @@ public class JSplitPane extends JComponent implements Accessible
{
if (newValue != oneTouchExpandable)
{
- boolean oldValue = oneTouchExpandable;
- oneTouchExpandable = newValue;
- firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue,
- oneTouchExpandable);
+ boolean oldValue = oneTouchExpandable;
+ oneTouchExpandable = newValue;
+ firePropertyChange(ONE_TOUCH_EXPANDABLE_PROPERTY, oldValue,
+ oneTouchExpandable);
}
}
@@ -732,13 +739,14 @@ public class JSplitPane extends JComponent implements Accessible
public void setOrientation(int orientation)
{
if (orientation != HORIZONTAL_SPLIT && orientation != VERTICAL_SPLIT)
- throw new IllegalArgumentException("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT");
+ throw new IllegalArgumentException
+ ("orientation must be one of VERTICAL_SPLIT, HORIZONTAL_SPLIT");
if (orientation != this.orientation)
{
- int oldOrientation = this.orientation;
- this.orientation = orientation;
- firePropertyChange(ORIENTATION_PROPERTY, oldOrientation,
- this.orientation);
+ int oldOrientation = this.orientation;
+ this.orientation = orientation;
+ firePropertyChange(ORIENTATION_PROPERTY, oldOrientation,
+ this.orientation);
}
}
@@ -766,7 +774,7 @@ public class JSplitPane extends JComponent implements Accessible
if (comp != null)
add(comp, RIGHT);
else
- add(new JButton("right button"), RIGHT);
+ remove (rightComponent);
}
/**
diff --git a/libjava/classpath/javax/swing/JTextPane.java b/libjava/classpath/javax/swing/JTextPane.java
index 1f5b99e43c54..a2aebd4ca684 100644
--- a/libjava/classpath/javax/swing/JTextPane.java
+++ b/libjava/classpath/javax/swing/JTextPane.java
@@ -47,7 +47,9 @@ import javax.swing.text.Document;
import javax.swing.text.EditorKit;
import javax.swing.text.Element;
import javax.swing.text.MutableAttributeSet;
+import javax.swing.text.SimpleAttributeSet;
import javax.swing.text.Style;
+import javax.swing.text.StyleConstants;
import javax.swing.text.StyledDocument;
import javax.swing.text.StyledEditorKit;
@@ -192,9 +194,20 @@ public class JTextPane
*/
public void insertComponent(Component component)
{
- // TODO: One space must be inserted here with attributes set to indicate
- // that the component must be displayed here. Have to figure out the
- // attributes.
+ SimpleAttributeSet atts = new SimpleAttributeSet();
+ atts.addAttribute(StyleConstants.ComponentAttribute, component);
+ atts.addAttribute(StyleConstants.NameAttribute,
+ StyleConstants.ComponentElementName);
+ try
+ {
+ getDocument().insertString(getCaret().getDot(), " ", atts);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError("Unexpected bad location");
+ err.initCause(ex);
+ throw err;
+ }
}
/**
@@ -204,9 +217,20 @@ public class JTextPane
*/
public void insertIcon(Icon icon)
{
- // TODO: One space must be inserted here with attributes set to indicate
- // that the icon must be displayed here. Have to figure out the
- // attributes.
+ SimpleAttributeSet atts = new SimpleAttributeSet();
+ atts.addAttribute(StyleConstants.IconAttribute, icon);
+ atts.addAttribute(StyleConstants.NameAttribute,
+ StyleConstants.IconElementName);
+ try
+ {
+ getDocument().insertString(getCaret().getDot(), " ", atts);
+ }
+ catch (BadLocationException ex)
+ {
+ AssertionError err = new AssertionError("Unexpected bad location");
+ err.initCause(ex);
+ throw err;
+ }
}
/**
diff --git a/libjava/classpath/javax/swing/KeyboardManager.java b/libjava/classpath/javax/swing/KeyboardManager.java
index d3868309d084..aa9524cfe570 100644
--- a/libjava/classpath/javax/swing/KeyboardManager.java
+++ b/libjava/classpath/javax/swing/KeyboardManager.java
@@ -53,7 +53,7 @@ import java.util.Vector;
* Components register keyboard actions with the condition
* JComponent.WHEN_IN_FOCUSED_WINDOW.
*
- * @author Anthony Balkissoon EditorPane
in this case.
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java
index 9c6396565450..60179dc0706e 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicFileChooserUI.java
@@ -79,7 +79,6 @@ import javax.swing.ListCellRenderer;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
@@ -1429,27 +1428,25 @@ public class BasicFileChooserUI extends FileChooserUI
*/
protected void installStrings(JFileChooser fc)
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
+ acceptAllFileFilterText = UIManager.getString("FileChooser.acceptAllFileFilterText");
+ cancelButtonMnemonic = UIManager.getInt("FileChooser.cancelButtonMnemonic");
+ cancelButtonText = UIManager.getString("FileChooser.cancelButtonText");
+ cancelButtonToolTipText = UIManager.getString("FileChooser.cancelButtonToolTipText");
- acceptAllFileFilterText = defaults.getString("FileChooser.acceptAllFileFilterText");
- cancelButtonMnemonic = defaults.getInt("FileChooser.cancelButtonMnemonic");
- cancelButtonText = defaults.getString("FileChooser.cancelButtonText");
- cancelButtonToolTipText = defaults.getString("FileChooser.cancelButtonToolTipText");
+ dirDescText = UIManager.getString("FileChooser.directoryDescriptionText");
+ fileDescText = UIManager.getString("FileChooser.fileDescriptionText");
- dirDescText = defaults.getString("FileChooser.directoryDescriptionText");
- fileDescText = defaults.getString("FileChooser.fileDescriptionText");
+ helpButtonMnemonic = UIManager.getInt("FileChooser.helpButtonMnemonic");
+ helpButtonText = UIManager.getString("FileChooser.helpButtonText");
+ helpButtonToolTipText = UIManager.getString("FileChooser.helpButtonToolTipText");
- helpButtonMnemonic = defaults.getInt("FileChooser.helpButtonMnemonic");
- helpButtonText = defaults.getString("FileChooser.helpButtonText");
- helpButtonToolTipText = defaults.getString("FileChooser.helpButtonToolTipText");
+ openButtonMnemonic = UIManager.getInt("FileChooser.openButtonMnemonic");
+ openButtonText = UIManager.getString("FileChooser.openButtonText");
+ openButtonToolTipText = UIManager.getString("FileChooser.openButtonToolTipText");
- openButtonMnemonic = defaults.getInt("FileChooser.openButtonMnemonic");
- openButtonText = defaults.getString("FileChooser.openButtonText");
- openButtonToolTipText = defaults.getString("FileChooser.openButtonToolTipText");
-
- saveButtonMnemonic = defaults.getInt("FileChooser.saveButtonMnemonic");
- saveButtonText = defaults.getString("FileChooser.saveButtonText");
- saveButtonToolTipText = defaults.getString("FileChooser.saveButtonToolTipText");
+ saveButtonMnemonic = UIManager.getInt("FileChooser.saveButtonMnemonic");
+ saveButtonText = UIManager.getString("FileChooser.saveButtonText");
+ saveButtonToolTipText = UIManager.getString("FileChooser.saveButtonToolTipText");
}
/**
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java b/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
index 73d3e6173d34..56022f3331e5 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicInternalFrameTitlePane.java
@@ -66,7 +66,6 @@ import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
/**
@@ -718,13 +717,11 @@ public class BasicInternalFrameTitlePane extends JComponent
*/
protected void installDefaults()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
-
- title.setFont(defaults.getFont("InternalFrame.titleFont"));
- selectedTextColor = defaults.getColor("InternalFrame.activeTitleForeground");
- selectedTitleColor = defaults.getColor("InternalFrame.activeTitleBackground");
- notSelectedTextColor = defaults.getColor("InternalFrame.inactiveTitleForeground");
- notSelectedTitleColor = defaults.getColor("InternalFrame.inactiveTitleBackground");
+ title.setFont(UIManager.getFont("InternalFrame.titleFont"));
+ selectedTextColor = UIManager.getColor("InternalFrame.activeTitleForeground");
+ selectedTitleColor = UIManager.getColor("InternalFrame.activeTitleBackground");
+ notSelectedTextColor = UIManager.getColor("InternalFrame.inactiveTitleForeground");
+ notSelectedTitleColor = UIManager.getColor("InternalFrame.inactiveTitleBackground");
closeIcon = UIManager.getIcon("InternalFrame.closeIcon");
iconIcon = UIManager.getIcon("InternalFrame.iconifyIcon");
@@ -901,6 +898,9 @@ public class BasicInternalFrameTitlePane extends JComponent
*/
protected void paintTitleBackground(Graphics g)
{
+ if (!isOpaque())
+ return;
+
Color saved = g.getColor();
Dimension dims = getSize();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java
index 339329914739..2d66645fb7d5 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicListUI.java
@@ -703,12 +703,17 @@ public class BasicListUI extends ListUI
*/
protected int getRowHeight(int row)
{
- if (row < 0 || row >= cellHeights.length)
- return -1;
- else if (cellHeight != -1)
- return cellHeight;
+ int height;
+ if (cellHeights == null)
+ height = cellHeight;
else
- return cellHeights[row];
+ {
+ if (row < 0 || row >= cellHeights.length)
+ height = -1;
+ else
+ height = cellHeights[row];
+ }
+ return height;
}
/**
@@ -803,9 +808,7 @@ public class BasicListUI extends ListUI
// If a fixed cell height is set, then we can work more efficient.
if (cellHeight > 0)
- {
- index = Math.max(y0 / cellHeight, index);
- }
+ index = Math.min(y0 / cellHeight, index);
// If we have no fixed cell height, we must add up each cell height up
// to y0.
else
@@ -992,8 +995,7 @@ public class BasicListUI extends ListUI
*/
protected void installKeyboardActions()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- InputMap focusInputMap = (InputMap)defaults.get("List.focusInputMap");
+ InputMap focusInputMap = (InputMap) UIManager.get("List.focusInputMap");
InputMapUIResource parentInputMap = new InputMapUIResource();
// FIXME: The JDK uses a LazyActionMap for parentActionMap
ActionMap parentActionMap = new ActionMapUIResource();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java b/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java
index 8ebe650350c7..13c78add6f84 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicLookAndFeel.java
@@ -1159,7 +1159,7 @@ public abstract class BasicLookAndFeel extends LookAndFeel
"Tree.hash", new ColorUIResource(new Color(128, 128, 128)),
"Tree.leftChildIndent", new Integer(7),
"Tree.rightChildIndent", new Integer(13),
- "Tree.rowHeight", new Integer(16),
+ "Tree.rowHeight", new Integer(0),
"Tree.scrollsOnExpand", Boolean.TRUE,
"Tree.selectionBackground", new ColorUIResource(Color.black),
"Tree.nonSelectionBackground", new ColorUIResource(new Color(255, 255, 255)),
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java
index 2a3556a5db96..c8754a3e049e 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicMenuItemUI.java
@@ -475,7 +475,6 @@ public class BasicMenuItemUI extends MenuItemUI
menuItem.setHorizontalTextPosition(SwingConstants.TRAILING);
menuItem.setHorizontalAlignment(SwingConstants.LEADING);
- menuItem.setOpaque(true);
}
/**
@@ -553,11 +552,20 @@ public class BasicMenuItemUI extends MenuItemUI
*/
protected void paintBackground(Graphics g, JMenuItem menuItem, Color bgColor)
{
- Dimension size = getPreferredSize(menuItem);
- Color foreground = g.getColor();
- g.setColor(bgColor);
- g.drawRect(0, 0, size.width, size.height);
- g.setColor(foreground);
+ // Menu item is considered to be highlighted when it is selected.
+ // But we don't want to paint the background of JCheckBoxMenuItems
+ ButtonModel mod = menuItem.getModel();
+ if ((menuItem.isSelected() && checkIcon == null) || (mod != null &&
+ mod.isArmed())
+ && (menuItem.getParent() instanceof MenuElement))
+ {
+ if (menuItem.isContentAreaFilled())
+ {
+ g.setColor(selectionBackground);
+ g.fillRect(0, 0, menuItem.getWidth(), menuItem.getHeight());
+ }
+ }
+
}
/**
@@ -612,28 +620,6 @@ public class BasicMenuItemUI extends MenuItemUI
br.width += insets.right + insets.left;
br.height += insets.top + insets.bottom;
- // Menu item is considered to be highlighted when it is selected.
- // But we don't want to paint the background of JCheckBoxMenuItems
- ButtonModel mod = m.getModel();
- if ((m.isSelected() && checkIcon == null) || (mod != null &&
- mod.isArmed())
- && (m.getParent() instanceof MenuElement))
- {
- if (m.isContentAreaFilled())
- {
- g.setColor(selectionBackground);
- g.fillRect(br.x, br.y, br.width, br.height);
- }
- }
- else
- {
- if (m.isContentAreaFilled())
- {
- g.setColor(m.getBackground());
- g.fillRect(br.x, br.y, br.width, br.height);
- }
- }
-
// If this menu item is a JCheckBoxMenuItem then paint check icon
if (checkIcon != null)
{
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java
index 827cbb0f50db..e638b68e1dc3 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicMenuUI.java
@@ -211,7 +211,6 @@ public class BasicMenuUI extends BasicMenuItemUI
selectionForeground = UIManager.getColor("Menu.selectionForeground");
arrowIcon = UIManager.getIcon("Menu.arrowIcon");
oldBorderPainted = UIManager.getBoolean("Menu.borderPainted");
- menuItem.setOpaque(true);
}
/**
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java
index 88d949b1caf9..d3674664d4cc 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicProgressBarUI.java
@@ -212,6 +212,8 @@ public class BasicProgressBarUI extends ProgressBarUI
/**
* Holds the value of the bouncing box that is returned by {@link #getBox}.
+ *
+ * @since 1.5
*/
protected Rectangle boxRect;
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
index f3698e859084..66e538037221 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java
@@ -48,7 +48,6 @@ import javax.swing.AbstractButton;
import javax.swing.Icon;
import javax.swing.JComponent;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
@@ -122,8 +121,7 @@ public class BasicRadioButtonUI extends BasicToggleButtonUI
*/
public Icon getDefaultIcon()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- return defaults.getIcon(getPropertyPrefix() + "icon");
+ return UIManager.getIcon(getPropertyPrefix() + "icon");
}
/**
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java
index 2f5eaf391e17..a2f5b82dbec9 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicScrollBarUI.java
@@ -62,7 +62,6 @@ import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
@@ -501,14 +500,12 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
*/
protected void configureScrollBarColors()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
-
- trackColor = defaults.getColor("ScrollBar.track");
- trackHighlightColor = defaults.getColor("ScrollBar.trackHighlight");
- thumbColor = defaults.getColor("ScrollBar.thumb");
- thumbHighlightColor = defaults.getColor("ScrollBar.thumbHighlight");
- thumbDarkShadowColor = defaults.getColor("ScrollBar.thumbDarkShadow");
- thumbLightShadowColor = defaults.getColor("ScrollBar.thumbShadow");
+ trackColor = UIManager.getColor("ScrollBar.track");
+ trackHighlightColor = UIManager.getColor("ScrollBar.trackHighlight");
+ thumbColor = UIManager.getColor("ScrollBar.thumb");
+ thumbHighlightColor = UIManager.getColor("ScrollBar.thumbHighlight");
+ thumbDarkShadowColor = UIManager.getColor("ScrollBar.thumbDarkShadow");
+ thumbLightShadowColor = UIManager.getColor("ScrollBar.thumbShadow");
}
/**
@@ -660,11 +657,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
width += decrButton.getPreferredSize().getWidth();
width += (scrollbar.getMaximum() - scrollbar.getMinimum());
-
- height = Math.max(incrButton.getPreferredSize().height,
- decrButton.getPreferredSize().height);
- height = Math.max(getMinimumThumbSize().height, height);
- height = Math.min(getMaximumThumbSize().height, height);
+ height = UIManager.getInt("ScrollBar.width");
}
else
{
@@ -672,11 +665,7 @@ public class BasicScrollBarUI extends ScrollBarUI implements LayoutManager,
height += decrButton.getPreferredSize().getHeight();
height += (scrollbar.getMaximum() - scrollbar.getMinimum());
-
- width = Math.max(incrButton.getPreferredSize().width,
- decrButton.getPreferredSize().width);
- width = Math.max(getMinimumThumbSize().width, width);
- width = Math.min(getMaximumThumbSize().width, width);
+ width = UIManager.getInt("ScrollBar.width");
}
Insets insets = scrollbar.getInsets();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java
index 746f628df6fc..cf31e8b5df1a 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java
@@ -126,14 +126,14 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
int i = 0;
if (place == null)
- i = 2;
+ i = 2;
else if (place.equals(JSplitPane.TOP) || place.equals(JSplitPane.LEFT))
- i = 0;
+ i = 0;
else if (place.equals(JSplitPane.BOTTOM)
|| place.equals(JSplitPane.RIGHT))
- i = 1;
+ i = 1;
else
- throw new IllegalArgumentException("Illegal placement in JSplitPane");
+ throw new IllegalArgumentException("Illegal placement in JSplitPane");
components[i] = component;
resetSizeAt(i);
splitPane.revalidate();
@@ -164,7 +164,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
protected int getInitialLocation(Insets insets)
{
if (insets != null)
- return insets.left;
+ return insets.left;
return 0;
}
@@ -205,7 +205,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
Dimension dims = c.getPreferredSize();
if (dims != null)
- return dims.width;
+ return dims.width;
return 0;
}
@@ -250,23 +250,23 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (container instanceof JSplitPane)
{
- JSplitPane split = (JSplitPane) container;
- distributeExtraSpace();
- Insets insets = split.getInsets();
- int width = getInitialLocation(insets);
- Dimension dims = split.getSize();
- for (int i = 0; i < components.length; i += 2)
- {
- if (components[i] == null)
- continue;
- setComponentToSize(components[i], sizes[i], width, insets, dims);
- width += sizes[i];
- }
- if (components[1] != null)
- {
- setComponentToSize(components[1], sizes[1], width, insets, dims);
- width += sizes[1];
- }
+ JSplitPane split = (JSplitPane) container;
+ distributeExtraSpace();
+ Insets insets = split.getInsets();
+ int width = getInitialLocation(insets);
+ Dimension dims = split.getSize();
+ for (int i = 0; i < components.length; i += 2)
+ {
+ if (components[i] == null)
+ continue;
+ setComponentToSize(components[i], sizes[i], width, insets, dims);
+ width += sizes[i];
+ }
+ if (components[1] != null)
+ {
+ setComponentToSize(components[1], sizes[1], width, insets, dims);
+ width += sizes[1];
+ }
}
}
@@ -297,23 +297,23 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (target instanceof JSplitPane)
{
- JSplitPane split = (JSplitPane) target;
- Insets insets = target.getInsets();
-
- int height = 0;
- int width = 0;
- for (int i = 0; i < components.length; i++)
- {
- if (components[i] == null)
- continue;
- Dimension dims = components[i].getMinimumSize();
- if (dims != null)
- {
- width += dims.width;
- height = Math.max(height, dims.height);
- }
- }
- return new Dimension(width, height);
+ JSplitPane split = (JSplitPane) target;
+ Insets insets = target.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getMinimumSize();
+ if (dims != null)
+ {
+ width += dims.width;
+ height = Math.max(height, dims.height);
+ }
+ }
+ return new Dimension(width, height);
}
return null;
}
@@ -331,24 +331,24 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (target instanceof JSplitPane)
{
- JSplitPane split = (JSplitPane) target;
- Insets insets = target.getInsets();
-
- int height = 0;
- int width = 0;
- for (int i = 0; i < components.length; i++)
- {
- if (components[i] == null)
- continue;
- Dimension dims = components[i].getPreferredSize();
- if (dims != null)
- {
- width += dims.width;
- if (! (components[i] instanceof BasicSplitPaneDivider))
- height = Math.max(height, dims.height);
- }
- }
- return new Dimension(width, height);
+ JSplitPane split = (JSplitPane) target;
+ Insets insets = target.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ width += dims.width;
+ if (!(components[i] instanceof BasicSplitPaneDivider))
+ height = Math.max(height, dims.height);
+ }
+ }
+ return new Dimension(width, height);
}
return null;
}
@@ -362,11 +362,11 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
for (int i = 0; i < components.length; i++)
{
- if (component == components[i])
- {
- components[i] = null;
- sizes[i] = 0;
- }
+ if (component == components[i])
+ {
+ components[i] = null;
+ sizes[i] = 0;
+ }
}
}
@@ -378,7 +378,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
protected void resetSizeAt(int index)
{
if (components[index] != null)
- sizes[index] = getPreferredSizeOfComponent(components[index]);
+ sizes[index] = getPreferredSizeOfComponent(components[index]);
}
/**
@@ -387,7 +387,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
public void resetToPreferredSizes()
{
for (int i = 0; i < components.length; i++)
- resetSizeAt(i);
+ resetSizeAt(i);
}
/**
@@ -433,13 +433,13 @@ public class BasicSplitPaneUI extends SplitPaneUI
if (left != null)
{
- components[0] = left;
- resetSizeAt(0);
+ components[0] = left;
+ resetSizeAt(0);
}
if (right != null)
{
- components[1] = right;
- resetSizeAt(1);
+ components[1] = right;
+ resetSizeAt(1);
}
components[2] = divider;
resetSizeAt(2);
@@ -480,9 +480,9 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
Dimension dims = components[index].getMinimumSize();
if (dims != null)
- return dims.width;
+ return dims.width;
else
- return 0;
+ return 0;
}
} //end BasicHorizontalLayoutManager
@@ -534,7 +534,7 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
Dimension dims = c.getPreferredSize();
if (dims != null)
- return dims.height;
+ return dims.height;
return 0;
}
@@ -563,23 +563,23 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (container instanceof JSplitPane)
{
- JSplitPane split = (JSplitPane) container;
- Insets insets = container.getInsets();
-
- int height = 0;
- int width = 0;
- for (int i = 0; i < components.length; i++)
- {
- if (components[i] == null)
- continue;
- Dimension dims = components[i].getMinimumSize();
- if (dims != null)
- {
- height += dims.height;
- width = Math.max(width, dims.width);
- }
- }
- return new Dimension(width, height);
+ JSplitPane split = (JSplitPane) container;
+ Insets insets = container.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getMinimumSize();
+ if (dims != null)
+ {
+ height += dims.height;
+ width = Math.max(width, dims.width);
+ }
+ }
+ return new Dimension(width, height);
}
return null;
}
@@ -597,23 +597,23 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (container instanceof JSplitPane)
{
- JSplitPane split = (JSplitPane) container;
- Insets insets = container.getInsets();
-
- int height = 0;
- int width = 0;
- for (int i = 0; i < components.length; i++)
- {
- if (components[i] == null)
- continue;
- Dimension dims = components[i].getPreferredSize();
- if (dims != null)
- {
- height += dims.height;
- width = Math.max(width, dims.width);
- }
- }
- return new Dimension(width, height);
+ JSplitPane split = (JSplitPane) container;
+ Insets insets = container.getInsets();
+
+ int height = 0;
+ int width = 0;
+ for (int i = 0; i < components.length; i++)
+ {
+ if (components[i] == null)
+ continue;
+ Dimension dims = components[i].getPreferredSize();
+ if (dims != null)
+ {
+ height += dims.height;
+ width = Math.max(width, dims.width);
+ }
+ }
+ return new Dimension(width, height);
}
return null;
}
@@ -652,9 +652,9 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
Dimension dims = components[index].getMinimumSize();
if (dims != null)
- return dims.height;
+ return dims.height;
else
- return 0;
+ return 0;
}
}
@@ -813,27 +813,27 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (e.getPropertyName().equals(JSplitPane.DIVIDER_SIZE_PROPERTY))
{
- int newSize = splitPane.getDividerSize();
- int[] tmpSizes = layoutManager.getSizes();
- dividerSize = tmpSizes[2];
- int newSpace = newSize - tmpSizes[2];
- tmpSizes[2] = newSize;
-
- tmpSizes[0] += newSpace / 2;
- tmpSizes[1] += newSpace / 2;
+ int newSize = splitPane.getDividerSize();
+ int[] tmpSizes = layoutManager.getSizes();
+ dividerSize = tmpSizes[2];
+ int newSpace = newSize - tmpSizes[2];
+ tmpSizes[2] = newSize;
+
+ tmpSizes[0] += newSpace / 2;
+ tmpSizes[1] += newSpace / 2;
- layoutManager.setSizes(tmpSizes);
+ layoutManager.setSizes(tmpSizes);
}
else if (e.getPropertyName().equals(JSplitPane.ORIENTATION_PROPERTY))
{
- int max = layoutManager.getAvailableSize(splitPane.getSize(),
- splitPane.getInsets());
- int dividerLoc = getDividerLocation(splitPane);
- double prop = ((double) dividerLoc) / max;
-
- resetLayoutManager();
- if (prop <= 1 && prop >= 0)
- splitPane.setDividerLocation(prop);
+ int max = layoutManager.getAvailableSize(splitPane.getSize(),
+ splitPane.getInsets());
+ int dividerLoc = getDividerLocation(splitPane);
+ double prop = ((double) dividerLoc) / max;
+
+ resetLayoutManager();
+ if (prop <= 1 && prop >= 0)
+ splitPane.setDividerLocation(prop);
}
layoutManager.layoutContainer(splitPane);
splitPane.repaint();
@@ -843,13 +843,13 @@ public class BasicSplitPaneUI extends SplitPaneUI
// Don't have to deal with resize_weight (as there
// will be no extra space associated with this
// event - the changes to the weighting will
- // be taken into account the next time the
+ // be taken into account the next time the
// sizes change.)
- // Don't have to deal with divider_location
+ // Don't have to deal with divider_location
// The method in JSplitPane calls our setDividerLocation
// so we'll know about those anyway.
// Don't have to deal with last_divider_location
- // Although I'm not sure why, it doesn't seem to
+ // Although I'm not sure why, it doesn't seem to
// have any effect on Sun's JSplitPane.
// one_touch_expandable changes are dealt with
// by our divider.
@@ -962,10 +962,10 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (c instanceof JSplitPane)
{
- splitPane = (JSplitPane) c;
- installDefaults();
- installListeners();
- installKeyboardActions();
+ splitPane = (JSplitPane) c;
+ installDefaults();
+ installListeners();
+ installKeyboardActions();
}
}
@@ -1218,8 +1218,8 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
if (nonContinuousLayoutDivider == null)
{
- nonContinuousLayoutDivider = new Canvas();
- nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY);
+ nonContinuousLayoutDivider = new Canvas();
+ nonContinuousLayoutDivider.setBackground(Color.DARK_GRAY);
}
return nonContinuousLayoutDivider;
}
@@ -1300,12 +1300,14 @@ public class BasicSplitPaneUI extends SplitPaneUI
{
location = validLocation(location);
Container p = jc.getParent();
- Dimension rightPrefSize = jc.getRightComponent().getPreferredSize();
+ Component right = jc.getRightComponent();
+ Dimension rightPrefSize = right == null ? new Dimension(0, 0)
+ : right.getPreferredSize();
Dimension size = jc.getSize();
// check if the size has been set for the splitpane
if (size.width == 0 && size.height == 0)
size = jc.getPreferredSize();
-
+
if (getOrientation() == 0 && location > size.height)
{
location = size.height;
@@ -1324,11 +1326,11 @@ public class BasicSplitPaneUI extends SplitPaneUI
p = p.getParent();
}
}
-
+
setLastDragLocation(getDividerLocation(splitPane));
splitPane.setLastDividerLocation(getDividerLocation(splitPane));
int[] tmpSizes = layoutManager.getSizes();
- tmpSizes[0] = location
+ tmpSizes[0] = location
- layoutManager.getInitialLocation(splitPane.getInsets());
tmpSizes[1] = layoutManager.getAvailableSize(splitPane.getSize(),
splitPane.getInsets())
@@ -1483,19 +1485,21 @@ public class BasicSplitPaneUI extends SplitPaneUI
*/
protected void startDragging()
{
+ Component left = splitPane.getLeftComponent();
+ Component right = splitPane.getRightComponent();
dividerSize = divider.getDividerSize();
setLastDragLocation(-1);
- if (! splitPane.getLeftComponent().isLightweight()
- || ! splitPane.getRightComponent().isLightweight())
+ if ((left != null && !left.isLightweight())
+ || (right != null && !right.isLightweight()))
draggingHW = true;
if (splitPane.isContinuousLayout())
nonContinuousLayoutDivider.setVisible(false);
else
{
- nonContinuousLayoutDivider.setVisible(true);
- nonContinuousLayoutDivider.setBounds(divider.getBounds());
+ nonContinuousLayoutDivider.setVisible(true);
+ nonContinuousLayoutDivider.setBounds(divider.getBounds());
}
splitPane.revalidate();
splitPane.repaint();
@@ -1518,12 +1522,12 @@ public class BasicSplitPaneUI extends SplitPaneUI
splitPane.setDividerLocation(location);
else
{
- Point p = nonContinuousLayoutDivider.getLocation();
- if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
- p.x = location;
- else
- p.y = location;
- nonContinuousLayoutDivider.setLocation(p);
+ Point p = nonContinuousLayoutDivider.getLocation();
+ if (getOrientation() == JSplitPane.HORIZONTAL_SPLIT)
+ p.x = location;
+ else
+ p.y = location;
+ nonContinuousLayoutDivider.setLocation(p);
}
setLastDragLocation(location);
splitPane.repaint();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java
index 25a845b36b82..015443946d72 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicTableUI.java
@@ -66,7 +66,6 @@ import javax.swing.JTextField;
import javax.swing.KeyStroke;
import javax.swing.ListSelectionModel;
import javax.swing.LookAndFeel;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.event.ChangeEvent;
@@ -398,8 +397,7 @@ public class BasicTableUI extends TableUI
protected void installKeyboardActions()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- InputMap ancestorMap = (InputMap)defaults.get("Table.ancestorInputMap");
+ InputMap ancestorMap = (InputMap) UIManager.get("Table.ancestorInputMap");
InputMapUIResource parentInputMap = new InputMapUIResource();
// FIXME: The JDK uses a LazyActionMap for parentActionMap
ActionMap parentActionMap = new ActionMapUIResource();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java
index decbed56829a..a988c5a63c83 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicTextPaneUI.java
@@ -45,12 +45,9 @@ import javax.swing.JTextPane;
import javax.swing.plaf.ColorUIResource;
import javax.swing.UIDefaults;
import javax.swing.plaf.ComponentUI;
-import javax.swing.text.Element;
-import javax.swing.text.PlainView;
import javax.swing.text.Style;
import javax.swing.text.StyleConstants;
import javax.swing.text.StyleContext;
-import javax.swing.text.View;
public class BasicTextPaneUI extends BasicEditorPaneUI
{
@@ -64,11 +61,6 @@ public class BasicTextPaneUI extends BasicEditorPaneUI
return new BasicTextPaneUI();
}
- public View create(Element elem)
- {
- return new PlainView(elem);
- }
-
/**
* Returns the prefix for entries in the {@link UIDefaults} table.
*
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
index b9de92640c8b..e8eeece3b328 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicTextUI.java
@@ -58,7 +58,6 @@ import javax.swing.JComponent;
import javax.swing.LookAndFeel;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
@@ -618,13 +617,14 @@ public abstract class BasicTextUI extends TextUI
protected Keymap createKeymap()
{
String prefix = getPropertyPrefix();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
JTextComponent.KeyBinding[] bindings =
- (JTextComponent.KeyBinding[]) defaults.get(prefix + ".keyBindings");
+ (JTextComponent.KeyBinding[]) UIManager.get(prefix + ".keyBindings");
if (bindings == null)
{
bindings = new JTextComponent.KeyBinding[0];
- defaults.put(prefix + ".keyBindings", bindings);
+ // FIXME: Putting something into the defaults map is certainly wrong.
+ // Must be fixed somehow.
+ UIManager.put(prefix + ".keyBindings", bindings);
}
Keymap km = JTextComponent.addKeymap(getKeymapName(),
@@ -661,17 +661,16 @@ public abstract class BasicTextUI extends TextUI
InputMap getInputMap(int condition)
{
String prefix = getPropertyPrefix();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
switch (condition)
{
case JComponent.WHEN_IN_FOCUSED_WINDOW:
// FIXME: is this the right string? nobody seems to use it.
- return (InputMap) defaults.get(prefix + ".windowInputMap");
+ return (InputMap) UIManager.get(prefix + ".windowInputMap");
case JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT:
- return (InputMap) defaults.get(prefix + ".ancestorInputMap");
+ return (InputMap) UIManager.get(prefix + ".ancestorInputMap");
default:
case JComponent.WHEN_FOCUSED:
- return (InputMap) defaults.get(prefix + ".focusInputMap");
+ return (InputMap) UIManager.get(prefix + ".focusInputMap");
}
}
@@ -685,12 +684,14 @@ public abstract class BasicTextUI extends TextUI
ActionMap getActionMap()
{
String prefix = getPropertyPrefix();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- ActionMap am = (ActionMap) defaults.get(prefix + ".actionMap");
+ ActionMap am = (ActionMap) UIManager.get(prefix + ".actionMap");
if (am == null)
{
am = createActionMap();
- defaults.put(prefix + ".actionMap", am);
+ // FIXME: Putting something in the UIDefaults map is certainly wrong.
+ // However, the whole method seems wrong and must be replaced by
+ // something that is less wrong.
+ UIManager.put(prefix + ".actionMap", am);
}
return am;
}
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java
index ef4ed835f862..7bf2a4ab167a 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicToolBarUI.java
@@ -404,6 +404,8 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
boolean tmp = ((loc == SwingConstants.NORTH)
|| (loc == SwingConstants.SOUTH) || (loc == -1));
+ cachedOrientation = toolBar.getOrientation();
+ cachedBounds = toolBar.getSize();
if (((cachedOrientation == SwingConstants.HORIZONTAL) && tmp)
|| ((cachedOrientation == VERTICAL) && ! tmp))
{
@@ -571,9 +573,6 @@ public class BasicToolBarUI extends ToolBarUI implements SwingConstants
dragWindow = createDragWindow(toolBar);
- cachedBounds = toolBar.getPreferredSize();
- cachedOrientation = toolBar.getOrientation();
-
nonRolloverBorder = createNonRolloverBorder();
rolloverBorder = createRolloverBorder();
diff --git a/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java b/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java
index e967cd424fcb..2d54983e61f9 100644
--- a/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java
+++ b/libjava/classpath/javax/swing/plaf/basic/BasicTreeUI.java
@@ -81,7 +81,6 @@ import javax.swing.KeyStroke;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.Timer;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.event.CellEditorListener;
import javax.swing.event.ChangeEvent;
@@ -239,14 +238,14 @@ public class BasicTreeUI extends TreeUI
/** Boolean to keep track of editing. */
boolean isEditing;
- /** The bounds of the current cell. */
- Rectangle bounds;
-
/** The current path of the visible nodes in the tree. */
TreePath currentVisiblePath;
/** The gap between the icon and text. */
int gap = 4;
+
+ /** Default row height, if none was set. */
+ int rowHeight = 20;
/** Listeners */
private PropertyChangeListener propertyChangeListener;
@@ -304,7 +303,7 @@ public class BasicTreeUI extends TreeUI
*/
protected Color getHashColor()
{
- return UIManager.getLookAndFeelDefaults().getColor("Tree.hash");
+ return UIManager.getColor("Tree.hash");
}
/**
@@ -315,8 +314,8 @@ public class BasicTreeUI extends TreeUI
*/
protected void setHashColor(Color color)
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- defaults.put("Tree.hash", color);
+ // FIXME: Putting something in the UIDefaults map is certainly wrong.
+ UIManager.put("Tree.hash", color);
}
/**
@@ -437,6 +436,8 @@ public class BasicTreeUI extends TreeUI
*/
protected void setRowHeight(int rowHeight)
{
+ if (rowHeight == 0)
+ rowHeight = this.rowHeight;
treeState.setRowHeight(rowHeight);
}
@@ -624,21 +625,19 @@ public class BasicTreeUI extends TreeUI
*/
public Rectangle getPathBounds(JTree tree, TreePath path)
{
+ Rectangle bounds = null;
+ int row = -1;
+ Object cell = null;
if (path != null)
{
- Object cell = path.getLastPathComponent();
-
- if (treeModel != null)
- {
- Object root = treeModel.getRoot();
-
- if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
- root = getNextNode(root);
- Point loc = getCellLocation(0, 0, tree, treeModel, cell, root);
- return getCellBounds(loc.x, loc.y, cell);
- }
+ row = getRowForPath(tree, path);
+ cell = path.getLastPathComponent();
+ bounds = new Rectangle(0, row * getRowHeight(), 0, 0);
}
- return null;
+ return nodeDimensions.getNodeDimensions(cell, row,
+ getLevel(cell),
+ tree.isExpanded(path),
+ bounds);
}
/**
@@ -700,7 +699,6 @@ public class BasicTreeUI extends TreeUI
*/
public int getRowCount(JTree tree)
{
- updateCurrentVisiblePath();
if (currentVisiblePath != null)
return currentVisiblePath.getPathCount();
return 0;
@@ -1035,7 +1033,9 @@ public class BasicTreeUI extends TreeUI
*/
protected void uninstallKeyboardActions()
{
- // TODO: Implement this properly.
+ action = null;
+ tree.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).setParent(null);
+ tree.getActionMap().setParent(null);
}
/**
@@ -1227,7 +1227,7 @@ public class BasicTreeUI extends TreeUI
rightChildIndent = UIManager.getInt("Tree.rightChildIndent");
leftChildIndent = UIManager.getInt("Tree.leftChildIndent");
setRowHeight(UIManager.getInt("Tree.rowHeight"));
- tree.setRowHeight(UIManager.getInt("Tree.rowHeight"));
+ tree.setRowHeight(getRowHeight());
tree.requestFocusInWindow(false);
tree.setScrollsOnExpand(UIManager.getBoolean("Tree.scrollsOnExpand"));
setExpandedIcon(UIManager.getIcon("Tree.expandedIcon"));
@@ -1239,8 +1239,7 @@ public class BasicTreeUI extends TreeUI
*/
protected void installKeyboardActions()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- InputMap focusInputMap = (InputMap) defaults.get("Tree.focusInputMap");
+ InputMap focusInputMap = (InputMap) UIManager.get("Tree.focusInputMap");
InputMapUIResource parentInputMap = new InputMapUIResource();
ActionMap parentActionMap = new ActionMapUIResource();
action = new TreeAction();
@@ -1409,14 +1408,30 @@ public class BasicTreeUI extends TreeUI
JTree tree = (JTree) c;
if (currentVisiblePath == null)
updateCurrentVisiblePath();
-
- if (currentVisiblePath != null && treeModel != null)
+
+ Rectangle clip = g.getClipBounds();
+ Insets insets = tree.getInsets();
+
+ if (clip != null && treeModel != null && currentVisiblePath != null)
{
- Object root = treeModel.getRoot();
- paintRecursive(g, 0, 0, 0, tree, treeModel, root);
-
- if (hasControlIcons())
- paintControlIcons(g, 0, 0, 0, tree, treeModel, root);
+ int startIndex = tree.getClosestRowForLocation(clip.x, clip.y);
+ int endIndex = tree.getClosestRowForLocation(clip.x + clip.width,
+ clip.y + clip.height);
+
+ paintVerticalPartOfLeg(g, clip, insets, currentVisiblePath);
+ for (int i = startIndex; i <= endIndex; i++)
+ {
+ Object curr = currentVisiblePath.getPathComponent(i);
+ boolean isLeaf = treeModel.isLeaf(curr);
+ TreePath path = new TreePath(getPathToRoot(curr, 0));
+
+ boolean isExpanded = tree.isExpanded(path);
+ Rectangle bounds = getPathBounds(tree, path);
+ paintHorizontalPartOfLeg(g, clip, insets, bounds, path, i,
+ isExpanded, false, isLeaf);
+ paintRow(g, clip, insets, bounds, path, i, isExpanded, false,
+ isLeaf);
+ }
}
}
@@ -1590,7 +1605,7 @@ public class BasicTreeUI extends TreeUI
int y;
if (event == null)
{
- bounds = getPathBounds(tree, path);
+ Rectangle bounds = getPathBounds(tree, path);
x = bounds.x;
y = bounds.y;
}
@@ -1670,7 +1685,7 @@ public class BasicTreeUI extends TreeUI
if (!isLeaf(row))
{
- bounds = getPathBounds(tree, path);
+ Rectangle bounds = getPathBounds(tree, path);
if (hasControlIcons() && (mouseX < bounds.x)
&& (mouseX > (bounds.x - getCurrentControlIcon(path).getIconWidth() - gap)))
@@ -1991,7 +2006,7 @@ public class BasicTreeUI extends TreeUI
}
/**
- * Creats, if necessary, and starts a Timer to check if needed to resize the
+ * Creates, if necessary, and starts a Timer to check if needed to resize the
* bounds
*/
protected void startTimer()
@@ -2227,7 +2242,7 @@ public class BasicTreeUI extends TreeUI
if (path != null)
{
- bounds = getPathBounds(tree, path);
+ Rectangle bounds = getPathBounds(tree, path);
int row = getRowForPath(tree, path);
boolean cntlClick = isLocationInExpandControl(path, click.x, click.y);
@@ -2268,6 +2283,7 @@ public class BasicTreeUI extends TreeUI
handleExpandControlClick(path, click.x, click.y);
if (cellEditor != null)
cellEditor.cancelCellEditing();
+ tree.scrollPathToVisible(path);
}
else if (tree.isEditable())
startEditing(path, e);
@@ -2451,9 +2467,12 @@ public class BasicTreeUI extends TreeUI
}
/**
- * Responsible for getting the size of a particular node.
+ * Returns, by reference in bounds, the size and x origin to place value at.
+ * The calling method is responsible for determining the Y location.
+ * If bounds is null, a newly created Rectangle should be returned,
+ * otherwise the value should be placed in bounds and returned.
*
- * @param value
+ * @param cell
* the value to be represented
* @param row
* row being queried
@@ -2465,10 +2484,23 @@ public class BasicTreeUI extends TreeUI
* a Rectangle containing the size needed to represent value
* @return containing the node dimensions, or null if node has no dimension
*/
- public Rectangle getNodeDimensions(Object value, int row, int depth,
+ public Rectangle getNodeDimensions(Object cell, int row, int depth,
boolean expanded, Rectangle size)
{
- return null;
+ if (size == null || cell == null)
+ return null;
+
+ String s = cell.toString();
+ Font f = tree.getFont();
+ FontMetrics fm = tree.getToolkit().getFontMetrics(f);
+
+ if (s != null)
+ {
+ size.x = getRowX(row, depth);
+ size.width = SwingUtilities.computeStringWidth(fm, s);
+ size.height = fm.getHeight();
+ }
+ return size;
}
/**
@@ -2478,7 +2510,9 @@ public class BasicTreeUI extends TreeUI
*/
protected int getRowX(int row, int depth)
{
- return 0;
+ if (row == 0)
+ return 0;
+ return depth * rightChildIndent;
}
}// NodeDimensionsHandler
@@ -3056,241 +3090,6 @@ public class BasicTreeUI extends TreeUI
}
}
- /**
- * Returns the cell bounds for painting selected cells Package private for use
- * in inner classes.
- *
- * @param x
- * is the x location of the cell
- * @param y
- * is the y location of the cell
- * @param cell
- * is the Object to get the bounds for
- * @returns Rectangle that represents the cell bounds
- */
- Rectangle getCellBounds(int x, int y, Object cell)
- {
- if (cell != null)
- {
- String s = cell.toString();
- Font f = tree.getFont();
- FontMetrics fm = tree.getToolkit().getFontMetrics(f);
-
- if (s != null)
- return new Rectangle(x, y, SwingUtilities.computeStringWidth(fm, s),
- fm.getHeight());
- }
- return new Rectangle(x, y, 0, 0);
- }
-
- /**
- * Retrieves the location of some node, recursively starting at from some
- * node. Package private for use in inner classes.
- *
- * @param x
- * is the starting x position, offset
- * @param y
- * is the starting y position, offset
- * @param tree
- * is the tree to traverse
- * @param mod
- * is the TreeModel to use
- * @param node
- * is the node to get the location for
- * @param startNode
- * is the node to start searching from
- * @return Point - the location of node
- */
- Point getCellLocation(int x, int y, JTree tree, TreeModel mod, Object node,
- Object startNode)
- {
- int rowHeight = getRowHeight();
- if (startNode == null || startNode.equals(node))
- {
- int level = getLevel(node);
- if (level == 0)
- return new Point(x, y);
- if (!tree.isRootVisible() &&
- tree.isExpanded(new TreePath(mod.getRoot())))
- return new Point(x + ((level - 1) * rightChildIndent), y);
- return new Point(x + (level * rightChildIndent), y);
- }
- return getCellLocation(x, y + rowHeight, tree, mod, node,
- getNextVisibleNode(startNode));
- }
-
- /**
- * Recursively paints all elements of the tree Package private for use in
- * inner classes.
- *
- * @param g
- * the Graphics context in which to paint
- * @param indentation
- * of the current object
- * @param descent
- * is the number of elements drawn
- * @param depth
- * is the depth of the current object in the tree
- * @param tree
- * is the tree to draw to
- * @param mod
- * is the TreeModel we are using to draw
- * @param curr
- * is the current object to draw
- * @return int - current descent of the tree
- */
- int paintRecursive(Graphics g, int indentation, int descent,
- int depth, JTree tree, TreeModel mod, Object curr)
- {
- Rectangle clip = tree.getVisibleRect();
- if (indentation > clip.x + clip.width + rightChildIndent
- || descent > clip.y + clip.height + getRowHeight())
- return descent;
-
- TreePath path = new TreePath(getPathToRoot(curr, 0));
- int halfHeight = getRowHeight() / 2;
- int halfWidth = rightChildIndent / 2;
- int y0 = descent + halfHeight;
- int heightOfLine = descent + halfHeight;
- int row = getRowForPath(tree, path);
- boolean isRootVisible = tree.isRootVisible();
- boolean isExpanded = tree.isExpanded(path);
- boolean isLeaf = mod.isLeaf(curr);
- Rectangle bounds = getPathBounds(tree, path);
- Object root = mod.getRoot();
-
- if (isLeaf)
- {
- paintRow(g, clip, null, bounds, path, row, true, false, true);
- descent += getRowHeight();
- }
- else
- {
- if (depth > 0 || isRootVisible)
- {
- paintRow(g, clip, null, bounds, path, row, isExpanded, false, false);
- descent += getRowHeight();
- y0 += halfHeight;
- }
-
- if (isExpanded)
- {
- int max = mod.getChildCount(curr);
- for (int i = 0; i < max; i++)
- {
- Object child = mod.getChild(curr, i);
- boolean childVis = tree.isVisible(new TreePath
- (getPathToRoot(child, 0)));
- int indent = indentation + rightChildIndent;
- if (!isRootVisible && depth == 0)
- indent = 0;
- else if (isRootVisible ||
- (!isRootVisible && !curr.equals(root)) && childVis)
- {
- g.setColor(getHashColor());
- heightOfLine = descent + halfHeight;
- paintHorizontalLine(g, (JComponent) tree, heightOfLine,
- indentation + halfWidth, indentation + rightChildIndent);
- }
-
- descent = paintRecursive(g, indent, descent, depth + 1,
- tree, mod, child);
- }
- }
- }
-
- if (isExpanded)
- if (y0 != heightOfLine
- && (mod.getChildCount(curr) > 0 &&
- tree.isVisible(new TreePath(getPathToRoot(mod.getChild
- (curr, 0), 0)))))
- {
- g.setColor(getHashColor());
- paintVerticalLine(g, (JComponent) tree, indentation + halfWidth, y0,
- heightOfLine);
- }
- return descent;
- }
-
- /**
- * Recursively paints all the control icons on the tree. Package private for
- * use in inner classes.
- *
- * @param g
- * the Graphics context in which to paint
- * @param indentation
- * of the current object
- * @param descent
- * is the number of elements drawn
- * @param depth
- * is the depth of the current object in the tree
- * @param tree
- * is the tree to draw to
- * @param mod
- * is the TreeModel we are using to draw
- * @param node
- * is the current object to draw
- * @return int current descent of the tree
- */
- int paintControlIcons(Graphics g, int indentation, int descent,
- int depth, JTree tree, TreeModel mod,
- Object node)
- {
- int rowHeight = getRowHeight();
- TreePath path = new TreePath(getPathToRoot(node, 0));
- Icon icon = getCurrentControlIcon(path);
-
- Rectangle clip = tree.getVisibleRect();
- if (indentation > clip.x + clip.width + rightChildIndent
- || descent > clip.y + clip.height + getRowHeight())
- return descent;
-
- if (mod.isLeaf(node))
- descent += rowHeight;
- else
- {
- if (!node.equals(mod.getRoot()) &&
- (tree.isRootVisible() || getLevel(node) != 1))
- {
- int width = icon.getIconWidth();
- int height = icon.getIconHeight() + 2;
- int posX = indentation - rightChildIndent;
- int posY = descent;
- if (width > rightChildIndent)
- posX -= gap;
- else posX += width/2;
-
- if (height < rowHeight)
- posY += height/2;
-
- icon.paintIcon(tree, g, posX, posY);
- }
-
- if (depth > 0 || tree.isRootVisible())
- descent += rowHeight;
-
- if (tree.isExpanded(path))
- {
- int max = 0;
- if (!mod.isLeaf(node))
- max = mod.getChildCount(node);
-
- for (int i = 0; i < max; i++)
- {
- int indent = indentation + rightChildIndent;
- Object child = mod.getChild(node, i);
- if (depth == 0 && !tree.isRootVisible())
- indent = 1;
- if (tree.isVisible(new TreePath(getPathToRoot(child, 0))))
- descent = paintControlIcons(g, indent, descent, depth + 1,
- tree, mod, child);
- }
- }
- }
-
- return descent;
- }
-
/**
* Returns true if the LookAndFeel implements the control icons. Package
* private for use in inner classes.
@@ -3376,7 +3175,6 @@ public class BasicTreeUI extends TreeUI
*/
Object getPreviousVisibleNode(Object node)
{
- updateCurrentVisiblePath();
if (currentVisiblePath != null)
{
Object[] nodes = currentVisiblePath.getPath();
@@ -3568,16 +3366,22 @@ public class BasicTreeUI extends TreeUI
int getLevel(Object node)
{
int count = -1;
-
+
Object current = node;
- do
+ if (treeModel != null)
{
- current = getParent(treeModel.getRoot(), current);
- count++;
+ Object root = treeModel.getRoot();
+ if (!tree.isRootVisible() && tree.isExpanded(new TreePath(root)))
+ count--;
+
+ do
+ {
+ current = getParent(root, current);
+ count++;
+ }
+ while (current != null);
}
- while (current != null);
-
return count;
}
@@ -3598,6 +3402,8 @@ public class BasicTreeUI extends TreeUI
protected void paintVerticalLine(Graphics g, JComponent c, int x, int top,
int bottom)
{
+ // FIXME: Check if drawing a dashed line or not.
+ g.setColor(getHashColor());
g.drawLine(x, top, x, bottom);
}
@@ -3618,6 +3424,8 @@ public class BasicTreeUI extends TreeUI
protected void paintHorizontalLine(Graphics g, JComponent c, int y, int left,
int right)
{
+ // FIXME: Check if drawing a dashed line or not.
+ g.setColor(getHashColor());
g.drawLine(left, y, right, y);
}
@@ -3633,14 +3441,19 @@ public class BasicTreeUI extends TreeUI
* @param x
* is the center position in x-direction
* @param y
- * is the center position in y-direction FIXME what to do if x <
- * (icon.width / 2). Same with y
+ * is the center position in y-direction
*/
protected void drawCentered(Component c, Graphics g, Icon icon, int x, int y)
{
- int beginPositionX = x - icon.getIconWidth() / 2;
- int beginPositionY = y - icon.getIconHeight() / 2;
- icon.paintIcon(c, g, beginPositionX, beginPositionY);
+ x -= icon.getIconWidth() / 2;
+ y -= icon.getIconHeight() / 2;
+
+ if (x < 0)
+ x = 0;
+ if (y < 0)
+ y = 0;
+
+ icon.paintIcon(c, g, x, y);
}
/**
@@ -3653,6 +3466,7 @@ public class BasicTreeUI extends TreeUI
*/
protected void drawDashedHorizontalLine(Graphics g, int y, int x1, int x2)
{
+ g.setColor(getHashColor());
for (int i = x1; i < x2; i += 2)
g.drawLine(i, y, i + 1, y);
}
@@ -3667,6 +3481,7 @@ public class BasicTreeUI extends TreeUI
*/
protected void drawDashedVerticalLine(Graphics g, int x, int y1, int y2)
{
+ g.setColor(getHashColor());
for (int i = y1; i < y2; i += 2)
g.drawLine(x, i, x, i + 1);
}
@@ -3691,8 +3506,15 @@ public class BasicTreeUI extends TreeUI
boolean isExpanded, boolean hasBeenExpanded,
boolean isLeaf)
{
- if (treeModel != null && hasControlIcons())
- paintControlIcons(g, 0, 0, 0, tree, treeModel, path.getLastPathComponent());
+ if (shouldPaintExpandControl(path, row, isExpanded, hasBeenExpanded, isLeaf))
+ {
+ Icon icon = getCurrentControlIcon(path);
+ int iconW = icon.getIconWidth();
+ int x = bounds.x - rightChildIndent + iconW/2;
+ if (x + iconW > bounds.x)
+ x = bounds.x - rightChildIndent - gap;
+ icon.paintIcon(tree, g, x, bounds.y + bounds.height/2 - icon.getIconHeight()/2);
+ }
}
/**
@@ -3703,9 +3525,9 @@ public class BasicTreeUI extends TreeUI
* @param g - the graphics configuration
* @param clipBounds -
* @param insets -
- * @param bounds - bounds of expand control
- * @param path - path to draw control for
- * @param row - row to draw control for
+ * @param bounds - bounds of the cell
+ * @param path - path to draw leg for
+ * @param row - row to start drawing at
* @param isExpanded - is the row expanded
* @param hasBeenExpanded - has the row already been expanded
* @param isLeaf - is the path a leaf
@@ -3716,7 +3538,9 @@ public class BasicTreeUI extends TreeUI
boolean isExpanded, boolean hasBeenExpanded,
boolean isLeaf)
{
- // FIXME: not implemented
+ if (row != 0)
+ paintHorizontalLine(g, tree, bounds.y + bounds.height/2, bounds.x - gap - 2,
+ bounds.x);
}
/**
@@ -3731,7 +3555,24 @@ public class BasicTreeUI extends TreeUI
protected void paintVerticalPartOfLeg(Graphics g, Rectangle clipBounds,
Insets insets, TreePath path)
{
- // FIXME: not implemented
+ int max = tree.getVisibleRowCount();
+ for (int i = 0; i < max; i++)
+ {
+ Object curr = path.getPathComponent(i);
+ TreePath currPath = new TreePath(getPathToRoot(curr, 0));
+ int numChild = treeModel.getChildCount(curr);
+ if (numChild > 0 && tree.isExpanded(currPath))
+ {
+ Rectangle bounds = getPathBounds(tree, currPath);
+ Rectangle lastChildBounds = getPathBounds(tree,
+ new TreePath(getPathToRoot(
+ treeModel.getChild(curr, numChild - 1),
+ 0)));
+ paintVerticalLine(g, tree, bounds.x + gap + 2, bounds.y +
+ bounds.height - 2, lastChildBounds.y +
+ lastChildBounds.height/2);
+ }
+ }
}
/**
@@ -3762,7 +3603,12 @@ public class BasicTreeUI extends TreeUI
{
if (!validCachedPreferredSize)
updateCachedPreferredSize();
- bounds.x += gap;
+
+
+ paintExpandControl(g, clipBounds, insets, bounds, path, row, isExpanded, hasBeenExpanded, isLeaf);
+
+ if (row != 0)
+ bounds.x += gap;
bounds.width = preferredSize.width + bounds.x;
if (editingComponent != null && editingPath != null && isEditing(tree)
@@ -3808,10 +3654,7 @@ public class BasicTreeUI extends TreeUI
boolean isLeaf)
{
Object node = path.getLastPathComponent();
- if (treeModel != null && (!isLeaf && !node.equals(treeModel.getRoot())) &&
- (tree.isRootVisible() || getLevel(node) != 1))
- return true;
- return false;
+ return (!isLeaf && getLevel(node) != 0 && hasControlIcons());
}
/**
@@ -3824,24 +3667,28 @@ public class BasicTreeUI extends TreeUI
return;
Object next = treeModel.getRoot();
- Rectangle bounds = getCellBounds(0, 0, next);
- boolean rootVisible = isRootVisible();
+ TreePath rootPath = new TreePath(next);
+ Rectangle bounds = getPathBounds(tree, rootPath);
// If root is not a valid size to be visible, or is
// not visible and the tree is expanded, then the next node acts
// as the root
- if ((bounds.width == 0 && bounds.height == 0) || (!rootVisible
+ if ((bounds.width == 0 && bounds.height == 0) || (!isRootVisible()
&& tree.isExpanded(new TreePath(next))))
+ {
next = getNextNode(next);
+ rootPath = new TreePath(next);
+ }
Object root = next;
TreePath current = null;
while (next != null)
{
if (current == null)
- current = new TreePath(next);
- else
- current = current.pathByAddingChild(next);
+ current = rootPath;
+ else
+ current = current.pathByAddingChild(next);
+
do
{
TreePath path = new TreePath(getPathToRoot(next, 0));
@@ -3860,7 +3707,7 @@ public class BasicTreeUI extends TreeUI
{
next = getNextSibling(parent);
if (next == null)
- parent = getParent(treeModel.getRoot(), next);
+ parent = getParent(root, parent);
}
}
}
@@ -3870,9 +3717,7 @@ public class BasicTreeUI extends TreeUI
}
currentVisiblePath = current;
- if (currentVisiblePath != null)
- tree.setVisibleRowCount(currentVisiblePath.getPathCount());
- else tree.setVisibleRowCount(0);
+ tree.setVisibleRowCount(getRowCount(tree));
if (tree.getSelectionModel() != null && tree.getSelectionCount() == 0 &&
currentVisiblePath != null)
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java
index 4fa3b3640564..28143d51ecdb 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalBorders.java
@@ -56,7 +56,6 @@ import javax.swing.JTextField;
import javax.swing.JToggleButton;
import javax.swing.JToolBar;
import javax.swing.SwingConstants;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.AbstractBorder;
import javax.swing.border.Border;
@@ -130,6 +129,82 @@ public class MetalBorders
*/
public void paintBorder(Component c, Graphics g, int x, int y, int w,
int h)
+ {
+ // With the OceanTheme the button border is painted entirely different.
+ // However, I couldn't figure out how this is determined besides checking
+ // for instanceof OceanTheme. The button painting is definitely not
+ // influenced by a UI default property and it is definitely performed
+ // by the same Border class.
+ if (MetalLookAndFeel.getCurrentTheme() instanceof OceanTheme)
+ paintOceanButtonBorder(c, g, x, y, w, h);
+ else
+ {
+ ButtonModel bmodel = null;
+
+ if (c instanceof AbstractButton)
+ bmodel = ((AbstractButton) c).getModel();
+
+ Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
+ Color shadow = MetalLookAndFeel.getControlShadow();
+ Color light = MetalLookAndFeel.getControlHighlight();
+ Color middle = MetalLookAndFeel.getControl();
+
+ if (c.isEnabled())
+ {
+ // draw dark border
+ g.setColor(darkShadow);
+ g.drawRect(x, y, w - 2, h - 2);
+
+ if (!bmodel.isPressed())
+ {
+ // draw light border
+ g.setColor(light);
+ g.drawRect(x + 1, y + 1, w - 2, h - 2);
+
+ // draw crossing pixels of both borders
+ g.setColor(middle);
+ g.drawLine(x + 1, y + h - 2, x + 1, y + h - 2);
+ g.drawLine(x + w - 2, y + 1, x + w - 2, y + 1);
+ }
+ else
+ {
+ // draw light border
+ g.setColor(light);
+ g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
+ g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
+
+ // draw shadow border
+ g.setColor(middle);
+ g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
+ g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
+
+ // draw crossing pixels of both borders
+ g.setColor(shadow);
+ g.drawRect(x + 1, y + h - 2, 0, 0);
+ g.drawRect(x + w - 2, y + 1, 0, 0);
+ }
+ }
+ else
+ {
+ // draw disabled border
+ g.setColor(MetalLookAndFeel.getInactiveControlTextColor());
+ g.drawRect(x, y, w - 2, h - 2);
+ }
+ }
+ }
+
+ /**
+ * Paints the button border for the OceanTheme.
+ *
+ * @param c the button
+ * @param g the graphics context
+ * @param x the X coordinate of the upper left corner of the painting rect
+ * @param y the Y coordinate of the upper left corner of the painting rect
+ * @param w the width of the painting rect
+ * @param h the height of the painting rect
+ */
+ private void paintOceanButtonBorder(Component c, Graphics g, int x,
+ int y, int w, int h)
{
ButtonModel bmodel = null;
@@ -138,44 +213,31 @@ public class MetalBorders
Color darkShadow = MetalLookAndFeel.getControlDarkShadow();
Color shadow = MetalLookAndFeel.getControlShadow();
- Color light = MetalLookAndFeel.getWhite();
+ Color light = MetalLookAndFeel.getControlHighlight();
Color middle = MetalLookAndFeel.getControl();
if (c.isEnabled())
- {
- // draw dark border
- g.setColor(darkShadow);
- g.drawRect(x, y, w - 2, h - 2);
-
- if (!bmodel.isPressed())
- {
- // draw light border
- g.setColor(light);
- g.drawRect(x + 1, y + 1, w - 2, h - 2);
-
- // draw crossing pixels of both borders
- g.setColor(middle);
- g.drawRect(x + 1, y + h - 2, 0, 0);
- g.drawRect(x + w - 2, y + 1, 0, 0);
- }
- else
- {
- // draw light border
- g.setColor(light);
- g.drawLine(x + w - 1, y + 1, x + w - 1, y + h - 1);
- g.drawLine(x + 1, y + h - 1, x + w - 1, y + h - 1);
-
- // draw shadow border
- g.setColor(middle);
- g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
- g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
-
- // draw crossing pixels of both borders
- g.setColor(shadow);
- g.drawRect(x + 1, y + h - 2, 0, 0);
- g.drawRect(x + w - 2, y + 1, 0, 0);
- }
- }
+ {
+ if (bmodel.isPressed())
+ {
+ // draw fat border
+ g.drawLine(x + 1, y + 1, x + w - 2, y + 1);
+ g.drawLine(x + 1, y + 1, x + 1, y + h - 2);
+ }
+ else if (bmodel.isRollover())
+ {
+ g.setColor(shadow);
+ g.drawRect(x, y, w - 1, h - 1);
+ g.drawRect(x + 2, y + 2, w - 5, h - 5);
+ g.setColor(darkShadow);
+ g.drawRect(x + 1, y + 1, w - 3, h - 3);
+ }
+ else
+ {
+ g.setColor(darkShadow);
+ g.drawRect(x, y, w - 1, h - 1);
+ }
+ }
else
{
// draw disabled border
@@ -654,24 +716,23 @@ public class MetalBorders
{
JOptionPane pane = (JOptionPane) f.getContentPane();
int type = pane.getMessageType();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
if (type == JOptionPane.QUESTION_MESSAGE)
{
- Color bc = defaults.getColor(
+ Color bc = UIManager.getColor(
"OptionPane.questionDialog.border.background");
if (bc != null)
g.setColor(bc);
}
if (type == JOptionPane.WARNING_MESSAGE)
{
- Color bc = defaults.getColor(
+ Color bc = UIManager.getColor(
"OptionPane.warningDialog.border.background");
if (bc != null)
g.setColor(bc);
}
else if (type == JOptionPane.ERROR_MESSAGE)
{
- Color bc = defaults.getColor(
+ Color bc = UIManager.getColor(
"OptionPane.errorDialog.border.background");
if (bc != null)
g.setColor(bc);
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java
index 02c39c1499e9..10e51117329f 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalButtonUI.java
@@ -47,7 +47,7 @@ import java.awt.Rectangle;
import javax.swing.AbstractButton;
import javax.swing.JButton;
import javax.swing.JComponent;
-import javax.swing.UIDefaults;
+import javax.swing.SwingConstants;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.UIResource;
@@ -78,10 +78,9 @@ public class MetalButtonUI
public MetalButtonUI()
{
super();
- UIDefaults def = UIManager.getLookAndFeelDefaults();
- focusColor = def.getColor(getPropertyPrefix() + "focus");
- selectColor = def.getColor(getPropertyPrefix() + "select");
- disabledTextColor = def.getColor(getPropertyPrefix() + "disabledText");
+ focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
+ selectColor = UIManager.getColor(getPropertyPrefix() + "select");
+ disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
}
/**
@@ -135,11 +134,8 @@ public class MetalButtonUI
public void installDefaults(AbstractButton button)
{
super.installDefaults(button);
- if (button.isRolloverEnabled())
- {
- if (button.getBorder() instanceof UIResource)
- button.setBorder(MetalBorders.getRolloverBorder());
- }
+ button.setRolloverEnabled(UIManager.getBoolean(
+ getPropertyPrefix() + "rollover"));
}
/**
@@ -148,8 +144,7 @@ public class MetalButtonUI
public void uninstallDefaults(AbstractButton button)
{
super.uninstallDefaults(button);
- if (button.getBorder() instanceof UIResource)
- button.setBorder(null);
+ button.setRolloverEnabled(false);
}
/**
@@ -230,4 +225,24 @@ public class MetalButtonUI
g.drawString(text, textRect.x, textRect.y + fm.getAscent());
}
}
+
+ /**
+ * If the property Button.gradient
is set, then a gradient is
+ * painted as background, otherwise the normal superclass behaviour is
+ * called.
+ */
+ public void update(Graphics g, JComponent c)
+ {
+ AbstractButton b = (AbstractButton) c;
+ if (b.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null
+ && !b.getModel().isPressed() && b.isEnabled())
+ {
+ MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
+ SwingConstants.VERTICAL,
+ getPropertyPrefix() + "gradient");
+ paint(g, c);
+ }
+ else
+ super.update(g, c);
+ }
}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java b/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java
index 6b9f31b85b69..fb8280e44da9 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalCheckBoxIcon.java
@@ -44,6 +44,8 @@ import java.io.Serializable;
import javax.swing.Icon;
import javax.swing.JCheckBox;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
import javax.swing.plaf.UIResource;
/**
@@ -128,6 +130,9 @@ public class MetalCheckBoxIcon
*/
public void paintIcon(Component c, Graphics g, int x, int y)
{
+ if (UIManager.get("CheckBox.gradient") != null)
+ MetalUtils.paintGradient(g, x, y, getIconWidth(), getIconHeight(),
+ SwingConstants.VERTICAL, "CheckBox.gradient");
border.paintBorder(c, g, x, y, getIconWidth(), getIconHeight());
JCheckBox cb = (JCheckBox) c;
if (cb.isSelected())
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java b/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java
index 6f4feccfc37a..bcb86e610477 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalIconFactory.java
@@ -52,6 +52,8 @@ import javax.swing.JInternalFrame;
import javax.swing.JRadioButton;
import javax.swing.JRadioButtonMenuItem;
import javax.swing.JSlider;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
import javax.swing.plaf.UIResource;
@@ -779,6 +781,10 @@ public class MetalIconFactory implements Serializable
*/
public void paintIcon(Component c, Graphics g, int x, int y)
{
+ if (UIManager.get("RadioButton.gradient") != null)
+ MetalUtils.paintGradient(g, x, y, getIconWidth(), getIconHeight(),
+ SwingConstants.VERTICAL, "RadioButton.gradient");
+
Color savedColor = g.getColor();
JRadioButton b = (JRadioButton) c;
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
index 33eb3491ad0a..2cf5f67d55d4 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java
@@ -55,7 +55,6 @@ import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.basic.BasicInternalFrameTitlePane;
@@ -260,9 +259,8 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
notSelectedTextColor = MetalLookAndFeel.getInactiveControlTextColor();
notSelectedTitleColor = MetalLookAndFeel.getWindowTitleInactiveBackground();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- paletteTitleHeight = defaults.getInt("InternalFrame.paletteTitleHeight");
- paletteCloseIcon = defaults.getIcon("InternalFrame.paletteCloseIcon");
+ paletteTitleHeight = UIManager.getInt("InternalFrame.paletteTitleHeight");
+ paletteCloseIcon = UIManager.getIcon("InternalFrame.paletteCloseIcon");
minIcon = MetalIconFactory.getInternalFrameAltMaximizeIcon(16);
title = new JLabel(frame.getTitle(),
@@ -351,8 +349,14 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
{
Color savedColor = g.getColor();
Rectangle b = SwingUtilities.getLocalBounds(this);
- g.setColor(MetalLookAndFeel.getPrimaryControlShadow());
- g.fillRect(b.x, b.y, b.width, b.height);
+
+ if (UIManager.get("InternalFrame.activeTitleGradient") != null
+ && frame.isSelected())
+ {
+ MetalUtils.paintGradient(g, b.x, b.y, b.width, b.height,
+ SwingConstants.VERTICAL,
+ "InternalFrame.activeTitleGradient");
+ }
MetalUtils.fillMetalPattern(this, g, b.x + 4, b.y + 2, b.width
- paletteCloseIcon.getIconWidth() - 13, b.height - 5,
MetalLookAndFeel.getPrimaryControlHighlight(),
@@ -393,6 +397,14 @@ public class MetalInternalFrameTitlePane extends BasicInternalFrameTitlePane
g.drawLine(0, d.height - 1, d.width - 1, d.height - 1);
// draw the metal pattern
+ if (UIManager.get("InternalFrame.activeTitleGradient") != null
+ && frame.isSelected())
+ {
+ MetalUtils.paintGradient(g, 0, 0, getWidth(), getHeight(),
+ SwingConstants.VERTICAL,
+ "InternalFrame.activeTitleGradient");
+ }
+
Rectangle b = title.getBounds();
int startX = b.x + b.width + 5;
int endX = startX;
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java
index e4eaa71724da..12b858e0a934 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalLabelUI.java
@@ -43,7 +43,6 @@ import java.awt.Graphics;
import javax.swing.JComponent;
import javax.swing.JLabel;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicGraphicsUtils;
@@ -83,22 +82,20 @@ public class MetalLabelUI
/**
* Draws the text for a disabled label, using the color defined in the
- * {@link UIDefaults} with the key Label.disabledForeground
.
+ * {@link UIManager} defaults with the key
+ * Label.disabledForeground
.
*
* @param l the label.
* @param g the graphics device.
* @param s the label text.
* @param textX the x-coordinate for the label.
* @param textY the y-coordinate for the label.
- *
- * @see UIManager#getLookAndFeelDefaults()
*/
protected void paintDisabledText(JLabel l, Graphics g, String s, int textX,
int textY)
{
Color savedColor = g.getColor();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- g.setColor(defaults.getColor("Label.disabledForeground"));
+ g.setColor(UIManager.getColor("Label.disabledForeground"));
int mnemIndex = l.getDisplayedMnemonicIndex();
if (mnemIndex != -1)
BasicGraphicsUtils.drawStringUnderlineCharAt(g, s, mnemIndex, textX,
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java b/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java
index ec8014b17b39..da019379bf51 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalLookAndFeel.java
@@ -693,6 +693,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
"DesktopIconUI", "javax.swing.plaf.metal.MetalDesktopIconUI",
"InternalFrameUI", "javax.swing.plaf.metal.MetalInternalFrameUI",
"LabelUI", "javax.swing.plaf.metal.MetalLabelUI",
+ "MenuBarUI", "javax.swing.plaf.metal.MetalMenuBarUI",
"PopupMenuSeparatorUI",
"javax.swing.plaf.metal.MetalPopupMenuSeparatorUI",
"ProgressBarUI", "javax.swing.plaf.metal.MetalProgressBarUI",
@@ -1162,7 +1163,7 @@ public class MetalLookAndFeel extends BasicLookAndFeel
"Tree.line", getPrimaryControl(),
"Tree.openIcon", MetalIconFactory.getTreeFolderIcon(),
"Tree.rightChildIndent", new Integer(13),
- "Tree.rowHeight", new Integer(20),
+ "Tree.rowHeight", new Integer(0),
"Tree.scrollsOnExpand", Boolean.TRUE,
"Tree.selectionBackground", getTextHighlightColor(),
"Tree.selectionBorder", new BorderUIResource.LineBorderUIResource(new Color(102, 102, 153)),
@@ -1201,4 +1202,13 @@ public class MetalLookAndFeel extends BasicLookAndFeel
defaults.putDefaults(uiDefaults);
}
+ /**
+ * Returns the current theme setting for the Metal L&F.
+ *
+ * @return the current theme setting for the Metal L&F
+ */
+ public static MetalTheme getCurrentTheme()
+ {
+ return theme;
+ }
}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java
new file mode 100644
index 000000000000..31d8d671fa1a
--- /dev/null
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalMenuBarUI.java
@@ -0,0 +1,88 @@
+/* MetalMenuBarUI.java -- MenuBar UI for the Metal L&F
+ Copyright (C) 2005 Free Software Foundation, Inc.
+
+This file is part of GNU Classpath.
+
+GNU Classpath is free software; you can redistribute it and/or modify
+it under the terms of the GNU General Public License as published by
+the Free Software Foundation; either version 2, or (at your option)
+any later version.
+
+GNU Classpath is distributed in the hope that it will be useful, but
+WITHOUT ANY WARRANTY; without even the implied warranty of
+MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+General Public License for more details.
+
+You should have received a copy of the GNU General Public License
+along with GNU Classpath; see the file COPYING. If not, write to the
+Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+02110-1301 USA.
+
+Linking this library statically or dynamically with other modules is
+making a combined work based on this library. Thus, the terms and
+conditions of the GNU General Public License cover the whole
+combination.
+
+As a special exception, the copyright holders of this library give you
+permission to link this library with independent modules to produce an
+executable, regardless of the license terms of these independent
+modules, and to copy and distribute the resulting executable under
+terms of your choice, provided that you also meet, for each linked
+independent module, the terms and conditions of the license of that
+module. An independent module is a module which is not derived from
+or based on this library. If you modify this library, you may extend
+this exception to your version of the library, but you are not
+obligated to do so. If you do not wish to do so, delete this
+exception statement from your version. */
+
+
+package javax.swing.plaf.metal;
+
+import java.awt.Graphics;
+
+import javax.swing.JComponent;
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
+import javax.swing.plaf.ComponentUI;
+import javax.swing.plaf.basic.BasicMenuBarUI;
+
+/**
+ * A UI implementation for MenuBar in the Metal Look & Feel.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ *
+ * @since 1.5
+ */
+public class MetalMenuBarUI extends BasicMenuBarUI
+{
+ /**
+ * Creates and returns a new instance of this UI for the specified component.
+ *
+ * @param c the component to create a UI for
+ *
+ * @return the UI for the component
+ */
+ public static ComponentUI createUI(JComponent c)
+ {
+ return new MetalMenuBarUI();
+ }
+
+
+ /**
+ * If the property MenuBar.gradient
is set, then a gradient
+ * is painted as background, otherwise the normal superclass behaviour is
+ * called.
+ */
+ public void update(Graphics g, JComponent c)
+ {
+ if (c.isOpaque() && UIManager.get("MenuBar.gradient") != null)
+ {
+ MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
+ SwingConstants.VERTICAL, "MenuBar.gradient");
+ paint(g, c);
+ }
+ else
+ super.update(g, c);
+ }
+
+}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java
index f37626e630f7..de71fe8e5b2a 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java
@@ -46,7 +46,6 @@ import java.awt.Rectangle;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.JRadioButton;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicRadioButtonUI;
@@ -96,10 +95,9 @@ public class MetalRadioButtonUI
public void installDefaults(AbstractButton b)
{
super.installDefaults(b);
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- disabledTextColor = defaults.getColor("RadioButton.disabledText");
- focusColor = defaults.getColor("RadioButton.focus");
- selectColor = defaults.getColor("RadioButton.select");
+ disabledTextColor = UIManager.getColor("RadioButton.disabledText");
+ focusColor = UIManager.getColor("RadioButton.focus");
+ selectColor = UIManager.getColor("RadioButton.select");
}
/**
@@ -118,7 +116,7 @@ public class MetalRadioButtonUI
/**
* Returns the color used to fill the {@link JRadioButton}'s icon when the
* button is pressed. The default color is obtained from the
- * {@link UIDefaults} via an entry with the key
+ * {@link UIManager} defaults via an entry with the key
* RadioButton.select
.
*
* @return The select color.
@@ -130,8 +128,8 @@ public class MetalRadioButtonUI
/**
* Returns the color for the {@link JRadioButton}'s text when the button is
- * disabled. The default color is obtained from the {@link UIDefaults} via
- * an entry with the key RadioButton.disabledText
.
+ * disabled. The default color is obtained from the {@link UIManager}
+ * defaults via an entry with the key RadioButton.disabledText
.
*
* @return The disabled text color.
*/
@@ -143,7 +141,7 @@ public class MetalRadioButtonUI
/**
* Returns the color used to draw the focus rectangle when the
* {@link JRadioButton} has the focus. The default color is obtained from
- * the {@link UIDefaults} via an entry with the key
+ * the {@link UIManager} defaults via an entry with the key
* RadioButton.focus
.
*
* @return The color used to draw the focus rectangle.
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java
index 9602ade9947e..0ff501f89a9d 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalScrollBarUI.java
@@ -48,7 +48,6 @@ import java.beans.PropertyChangeListener;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JScrollBar;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicScrollBarUI;
@@ -195,8 +194,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI
*/
protected JButton createDecreaseButton(int orientation)
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- scrollBarWidth = defaults.getInt("ScrollBar.width");
+ scrollBarWidth = UIManager.getInt("ScrollBar.width");
decreaseButton = new MetalScrollButton(orientation, scrollBarWidth,
isFreeStanding);
return decreaseButton;
@@ -213,8 +211,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI
*/
protected JButton createIncreaseButton(int orientation)
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- scrollBarWidth = defaults.getInt("ScrollBar.width");
+ scrollBarWidth = UIManager.getInt("ScrollBar.width");
increaseButton = new MetalScrollButton(orientation, scrollBarWidth,
isFreeStanding);
return increaseButton;
@@ -403,8 +400,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI
}
// draw the shadow line
- UIDefaults def = UIManager.getLookAndFeelDefaults();
- g.setColor(def.getColor("ScrollBar.shadow"));
+ g.setColor(UIManager.getColor("ScrollBar.shadow"));
g.drawLine(x + w, y + 1, x + w, y + h - 1);
}
@@ -456,8 +452,7 @@ public class MetalScrollBarUI extends BasicScrollBarUI
}
// draw the shadow line
- UIDefaults def = UIManager.getLookAndFeelDefaults();
- g.setColor(def.getColor("ScrollBar.shadow"));
+ g.setColor(UIManager.getColor("ScrollBar.shadow"));
g.drawLine(x + 1, y + h, x + w - 2, y + h);
}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java
index b39fb23366ee..dbcc0910d466 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalSplitPaneUI.java
@@ -42,7 +42,6 @@ import java.awt.Color;
import javax.swing.JComponent;
import javax.swing.JSplitPane;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicSplitPaneDivider;
@@ -83,9 +82,8 @@ public class MetalSplitPaneUI extends BasicSplitPaneUI
*/
public BasicSplitPaneDivider createDefaultDivider()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- Color light = defaults.getColor("SplitPane.highlight");
- Color dark = defaults.getColor("SplitPane.darkShadow");
+ Color light = UIManager.getColor("SplitPane.highlight");
+ Color dark = UIManager.getColor("SplitPane.darkShadow");
return new MetalSplitPaneDivider(this, light, dark);
}
}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java
index 46a19bdbe9ef..0b56d5914428 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalToggleButtonUI.java
@@ -47,8 +47,8 @@ import java.awt.Rectangle;
import javax.swing.AbstractButton;
import javax.swing.JComponent;
import javax.swing.JToggleButton;
+import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicButtonUI;
@@ -131,10 +131,9 @@ public class MetalToggleButtonUI
public void installDefaults(AbstractButton b)
{
super.installDefaults(b);
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- focusColor = defaults.getColor(getPropertyPrefix() + "focus");
- selectColor = defaults.getColor(getPropertyPrefix() + "select");
- disabledTextColor = defaults.getColor(getPropertyPrefix() + "disabledText");
+ focusColor = UIManager.getColor(getPropertyPrefix() + "focus");
+ selectColor = UIManager.getColor(getPropertyPrefix() + "select");
+ disabledTextColor = UIManager.getColor(getPropertyPrefix() + "disabledText");
}
/**
@@ -200,5 +199,23 @@ public class MetalToggleButtonUI
g.drawRect(fr.x - 1, fr.y - 1, fr.width + 1, fr.height + 1);
g.setColor(saved);
}
+
+ /**
+ * If the property ToggleButton.gradient
is set, then a gradient
+ * is painted as background, otherwise the normal superclass behaviour is
+ * called.
+ */
+ public void update(Graphics g, JComponent c)
+ {
+ if (c.isOpaque() && UIManager.get(getPropertyPrefix() + "gradient") != null)
+ {
+ MetalUtils.paintGradient(g, 0, 0, c.getWidth(), c.getHeight(),
+ SwingConstants.VERTICAL,
+ getPropertyPrefix() + "gradient");
+ paint(g, c);
+ }
+ else
+ super.update(g, c);
+ }
}
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java
index 5085d170ac29..f183ed5a1496 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalToolTipUI.java
@@ -56,7 +56,6 @@ import javax.swing.JToolTip;
import javax.swing.KeyStroke;
import javax.swing.SwingConstants;
import javax.swing.SwingUtilities;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.border.Border;
import javax.swing.plaf.ComponentUI;
@@ -107,13 +106,12 @@ public class MetalToolTipUI
public MetalToolTipUI()
{
super();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- activeBorder = defaults.getBorder("ToolTip.border");
- inactiveBorder = defaults.getBorder("ToolTip.borderInactive");
- isAcceleratorHidden = defaults.getBoolean("ToolTip.hideAccelerator");
- acceleratorFont = defaults.getFont("MenuItem.acceleratorFont");
- acceleratorForeground = defaults.getColor("MenuItem.acceleratorForeground");
- acceleratorDelimiter = defaults.getString("MenuItem.acceleratorDelimiter");
+ activeBorder = UIManager.getBorder("ToolTip.border");
+ inactiveBorder = UIManager.getBorder("ToolTip.borderInactive");
+ isAcceleratorHidden = UIManager.getBoolean("ToolTip.hideAccelerator");
+ acceleratorFont = UIManager.getFont("MenuItem.acceleratorFont");
+ acceleratorForeground = UIManager.getColor("MenuItem.acceleratorForeground");
+ acceleratorDelimiter = UIManager.getString("MenuItem.acceleratorDelimiter");
}
/**
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java b/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java
index 0ffa0d17470d..24432a2b5f67 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalTreeUI.java
@@ -41,24 +41,10 @@ package javax.swing.plaf.metal;
import java.awt.Graphics;
import java.awt.Insets;
import java.awt.Rectangle;
-import java.awt.event.ComponentListener;
-import java.awt.event.FocusListener;
-import java.awt.event.KeyListener;
-import java.awt.event.MouseListener;
-import java.beans.PropertyChangeListener;
-import java.util.Hashtable;
import javax.swing.JComponent;
import javax.swing.JTree;
-import javax.swing.UIDefaults;
-import javax.swing.UIManager;
-import javax.swing.tree.TreeCellEditor;
-import javax.swing.tree.TreeModel;
import javax.swing.tree.TreePath;
-import javax.swing.event.CellEditorListener;
-import javax.swing.event.TreeExpansionListener;
-import javax.swing.event.TreeModelListener;
-import javax.swing.event.TreeSelectionListener;
import javax.swing.plaf.ComponentUI;
import javax.swing.plaf.basic.BasicTreeUI;
@@ -67,19 +53,6 @@ import javax.swing.plaf.basic.BasicTreeUI;
*/
public class MetalTreeUI extends BasicTreeUI
{
-
- /** Listeners */
- private PropertyChangeListener propertyChangeListener;
- private FocusListener focusListener;
- private TreeSelectionListener treeSelectionListener;
- private MouseListener mouseListener;
- private KeyListener keyListener;
- private PropertyChangeListener selectionModelPropertyChangeListener;
- private ComponentListener componentListener;
- private CellEditorListener cellEditorListener;
- private TreeExpansionListener treeExpansionListener;
- private TreeModelListener treeModelListener;
-
/**
* Constructs a new instance of MetalTreeUI
.
*/
@@ -128,71 +101,8 @@ public class MetalTreeUI extends BasicTreeUI
*/
public void installUI(JComponent c)
{
- tree = (JTree) c;
- configureLayoutCache();
-
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- tree.setFont(defaults.getFont("Tree.font"));
- tree.setForeground(defaults.getColor("Tree.foreground"));
- tree.setBackground(defaults.getColor("Tree.background"));
- tree.setOpaque(true);
- tree.setScrollsOnExpand(defaults.getBoolean("Tree.scrollsOnExpand"));
- rightChildIndent = defaults.getInt("Tree.rightChildIndent");
- leftChildIndent = defaults.getInt("Tree.leftChildIndent");
- setRowHeight(defaults.getInt("Tree.rowHeight"));
- tree.setRowHeight(defaults.getInt("Tree.rowHeight"));
- tree.requestFocusInWindow(false);
-
- setExpandedIcon(defaults.getIcon("Tree.expandedIcon"));
- setCollapsedIcon(defaults.getIcon("Tree.collapsedIcon"));
-
- currentCellRenderer = createDefaultCellRenderer();
- rendererPane = createCellRendererPane();
- createdRenderer = true;
- setCellEditor(createDefaultCellEditor());
- createdCellEditor = true;
- TreeModel mod = tree.getModel();
- setModel(mod);
-
- treeSelectionModel = tree.getSelectionModel();
- drawingCache = new Hashtable();
- nodeDimensions = createNodeDimensions();
-
- propertyChangeListener = createPropertyChangeListener();
- focusListener = createFocusListener();
- treeSelectionListener = createTreeSelectionListener();
- mouseListener = createMouseListener();
- keyListener = createKeyListener();
- selectionModelPropertyChangeListener = createSelectionModelPropertyChangeListener();
- componentListener = createComponentListener();
- cellEditorListener = createCellEditorListener();
- treeExpansionListener = createTreeExpansionListener();
- treeModelListener = createTreeModelListener();
-
- editingRow = -1;
- lastSelectedRow = -1;
-
- installKeyboardActions();
-
- tree.addPropertyChangeListener(propertyChangeListener);
- tree.addFocusListener(focusListener);
- tree.addTreeSelectionListener(treeSelectionListener);
- tree.addMouseListener(mouseListener);
- tree.addKeyListener(keyListener);
- tree.addPropertyChangeListener(selectionModelPropertyChangeListener);
- tree.addComponentListener(componentListener);
- tree.addTreeExpansionListener(treeExpansionListener);
- if (treeModel != null)
- treeModel.addTreeModelListener(treeModelListener);
-
- if (mod != null)
- {
- TreePath path = new TreePath(mod.getRoot());
- if (!tree.isExpanded(path))
- toggleExpandState(path);
- }
-
- completeUIInstall();
+ // TODO: What to do here, if anything?
+ super.installUI(c);
}
/**
@@ -212,31 +122,8 @@ public class MetalTreeUI extends BasicTreeUI
*/
public void uninstallUI(JComponent c)
{
- tree.setFont(null);
- tree.setForeground(null);
- tree.setBackground(null);
-
- uninstallKeyboardActions();
-
- tree.removePropertyChangeListener(propertyChangeListener);
- tree.removeFocusListener(focusListener);
- tree.removeTreeSelectionListener(treeSelectionListener);
- tree.removeMouseListener(mouseListener);
- tree.removeKeyListener(keyListener);
- tree.removePropertyChangeListener(selectionModelPropertyChangeListener);
- tree.removeComponentListener(componentListener);
- tree.removeTreeExpansionListener(treeExpansionListener);
-
- TreeCellEditor tce = tree.getCellEditor();
- if (tce != null)
- tce.removeCellEditorListener(cellEditorListener);
- TreeModel tm = tree.getModel();
- if (tm != null)
- tm.removeTreeModelListener(treeModelListener);
-
- tree = null;
- uninstallComponents();
- completeUIUninstall();
+ // TODO: What to do here?
+ super.uninstallUI(c);
}
/**
diff --git a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
index c0b4e657676d..50112ce21612 100644
--- a/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
+++ b/libjava/classpath/javax/swing/plaf/metal/MetalUtils.java
@@ -44,6 +44,10 @@ import java.awt.Graphics2D;
import java.awt.TexturePaint;
import java.awt.geom.Rectangle2D;
import java.awt.image.BufferedImage;
+import java.util.List;
+
+import javax.swing.SwingConstants;
+import javax.swing.UIManager;
/**
* Some utility and helper methods for the Metal Look & Feel.
@@ -151,4 +155,252 @@ class MetalUtils
g.fillRect(3, 3, 1, 1);
g.dispose();
}
+
+ /**
+ * Paints the typical Metal gradient. See {@link #paintGradient(Graphics,
+ * int, int, int, int, double, double, Color, Color, Color, int)}
+ * for more details.
+ *
+ * The parameters are fetched from the UIManager using the key
+ * uiProp
. The value is expected to be a {@link List} that
+ * contains 4 values: two {@link Double}s and 3 {@link Color} object that
+ * together make up the parameters passed to the painting method.
+ *
+ * @param g the graphics context to use
+ * @param x the X coordinate of the upper left corner of the rectangle
+ * @param y the Y coordinate of the upper left corner of the rectangle
+ * @param w the width of the rectangle
+ * @param h the height of the rectangle
+ * @param dir the direction of the gradient, either
+ * @param uiProp the key of the UIManager property that has the parameters
+ */
+ static void paintGradient(Graphics g, int x, int y, int w, int h,
+ int dir, String uiProp)
+ {
+ List params = (List) UIManager.get(uiProp);
+ double g1 = ((Double) params.get(0)).doubleValue();
+ double g2 = ((Double) params.get(1)).doubleValue();
+ Color c1 = (Color) params.get(2);
+ Color c2 = (Color) params.get(3);
+ Color c3 = (Color) params.get(4);
+ paintGradient(g, x, y, w, h, g1, g2, c1, c2, c3, dir);
+ }
+
+ /**
+ * Paints the typical Metal gradient. The gradient is painted as follows:
+ *
+ *
+ * +-------+--------+--------+-----------------------------+
+ * | | | | |
+ * +-------+--------+--------+-----------------------------+
+ * c1 -> c2 -- c2 -> c1 --------> c3
+ * < -g1- > < -g2- > < -g1- >
+ *
+ *
+ * There are 4 distinct areas in this gradient:
+ *
+ *
g1
g2
g1
View
. The parameter
* a
stores the allocation of this CompositeView
* and is then adjusted to hold the allocation of the child view.
- *
- * @param index the index of the child View
- * @param a the allocation of this CompositeView
before the
- * call, the allocation of the child on exit
+ *
+ * @param index
+ * the index of the child View
+ * @param a
+ * the allocation of this CompositeView
before the
+ * call, the allocation of the child on exit
*/
protected void childAllocation(int index, Rectangle a)
{
@@ -737,4 +740,22 @@ public class BoxView
yLayoutValid = false;
super.preferenceChanged(child, width, height);
}
+
+ /**
+ * Maps the document model position pos
to a Shape
+ * in the view coordinate space. This method overrides CompositeView's
+ * method to make sure the children are allocated properly before
+ * calling the super's behaviour.
+ */
+ public Shape modelToView(int pos, Shape a, Position.Bias bias)
+ throws BadLocationException
+ {
+ // Make sure everything is allocated properly and then call super
+ if (!isAllocationValid())
+ {
+ Rectangle bounds = a.getBounds();
+ setSize(bounds.width, bounds.height);
+ }
+ return super.modelToView(pos, a, bias);
+ }
}
diff --git a/libjava/classpath/javax/swing/text/ComponentView.java b/libjava/classpath/javax/swing/text/ComponentView.java
index 16112c8f4de6..830dda3ecdc4 100644
--- a/libjava/classpath/javax/swing/text/ComponentView.java
+++ b/libjava/classpath/javax/swing/text/ComponentView.java
@@ -38,10 +38,13 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
import javax.swing.SwingConstants;
+import javax.swing.SwingUtilities;
/**
* A {@link View} implementation that is able to render arbitrary
@@ -52,12 +55,17 @@ import javax.swing.SwingConstants;
* this ComponentView
, so this view must not be shared between
* multiple JTextComponent
s.
*
+ * @author Roman Kennke (kennke@aicas.com)
* @author original author unknown
- * @author Roman Kennke (roman@kennke.org)
*/
-// FIXME: This class is a complete stub and needs to be implemented properly.
public class ComponentView extends View
{
+
+ /**
+ * The component that is displayed by this view.
+ */
+ private Component comp;
+
/**
* Creates a new instance of ComponentView
for the specified
* Element
.
@@ -77,7 +85,7 @@ public class ComponentView extends View
*
* @return the component that is rendered
*/
- protected Component createComponent()
+ protected Component createComponent()
{
return StyleConstants.getComponent(getElement().getAttributes());
}
@@ -91,7 +99,14 @@ public class ComponentView extends View
*/
public float getAlignment(int axis)
{
- return 0;
+ float align;
+ if (axis == X_AXIS)
+ align = getComponent().getAlignmentX();
+ else if (axis == Y_AXIS)
+ align = getComponent().getAlignmentY();
+ else
+ throw new IllegalArgumentException();
+ return align;
}
/**
@@ -103,7 +118,9 @@ public class ComponentView extends View
*/
public final Component getComponent()
{
- return null;
+ if (comp == null)
+ comp = createComponent();
+ return comp;
}
/**
@@ -118,49 +135,115 @@ public class ComponentView extends View
*/
public float getMaximumSpan(int axis)
{
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getMaximumSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getMaximumSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public float getMinimumSpan(int axis)
{
- // TODO: Implement this properly.
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getMinimumSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getMinimumSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public float getPreferredSpan(int axis)
{
- // TODO: Implement this properly.
- return 0;
+ float span;
+ if (axis == X_AXIS)
+ span = getComponent().getPreferredSize().width;
+ else if (axis == Y_AXIS)
+ span = getComponent().getPreferredSize().height;
+ else
+ throw new IllegalArgumentException();
+ return span;
}
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException
{
- // TODO: Implement this properly.
- return null;
+ Element el = getElement();
+ if (pos < el.getStartOffset() || pos >= el.getEndOffset())
+ throw new BadLocationException("Illegal offset for this view", pos);
+ Rectangle r = a.getBounds();
+ Component c = getComponent();
+ return new Rectangle(r.x, r.y, c.getWidth(), c.getHeight());
}
-
+
+ /**
+ * The real painting behavour is performed by normal component painting,
+ * triggered by the text component that hosts this view. This method does
+ * not paint by itself. However, it sets the size of the component according
+ * to the allocation that is passed here.
+ *
+ * @param g the graphics context
+ * @param a the allocation of the child
+ */
public void paint(Graphics g, Shape a)
{
- // TODO: Implement this properly.
+ Rectangle r = a.getBounds();
+ getComponent().setBounds(r.x, r.y, r.width, r.height);
}
-
- public void setParent(View p)
+
+ /**
+ * This sets up the component when the view is added to its parent, or
+ * cleans up the view when it is removed from its parent.
+ *
+ * When this view is added to a parent view, the component of this view
+ * is added to the container that hosts this view. When p
is
+ * null
, then the view is removed from it's parent and we have
+ * to also remove the component from it's parent container.
+ *
+ * @param p the parent view or null
if this view is removed
+ * from it's parent
+ */
+ public void setParent(final View p)
{
- // TODO: Implement this properly.
+ if (SwingUtilities.isEventDispatchThread())
+ setParentImpl(p);
+ else
+ SwingUtilities.invokeLater
+ (new Runnable()
+ {
+ public void run()
+ {
+ setParentImpl(p);
+ }
+ });
}
-
- public void setSize(float width, float height)
+
+ /**
+ * The implementation of {@link #setParent}. This is package private to
+ * avoid a synthetic accessor method.
+ *
+ * @param p the parent view to set
+ */
+ void setParentImpl(View p)
{
- // TODO: Implement this properly.
+ if (p != null)
+ {
+ Component c = getComponent();
+ p.getContainer().add(c);
+ }
+ else
+ {
+ Component c = getComponent();
+ Container parent = c.getParent();
+ parent.remove(c);
+ comp = null;
+ }
}
- public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
- {
- // TODO: Implement this properly.
- return 0;
- }
-
/**
* Maps coordinates from the View
's space into a position
* in the document model.
@@ -173,10 +256,13 @@ public class ComponentView extends View
* @return the position in the document that corresponds to the screen
* coordinates x, y
*/
- public int viewToModel(float x, float y, Shape a, Position.Bias b)
+ public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- // FIXME: Implement this properly.
- return 0;
+ // The element should only have one character position and it is clear
+ // that this position is the position that best matches the given screen
+ // coordinates, simply because this view has only this one position.
+ Element el = getElement();
+ return el.getStartOffset();
}
/**
@@ -205,7 +291,7 @@ public class ComponentView extends View
Position.Bias[] biasRet)
throws BadLocationException
{
- // TODO: Implement this properly.
- throw new AssertionError("Not implemented yet.");
+ // FIXME: Implement this method.
+ throw new AssertionError("Not yet implemented");
}
}
diff --git a/libjava/classpath/javax/swing/text/CompositeView.java b/libjava/classpath/javax/swing/text/CompositeView.java
index bc626a40696a..e6c2e4cc2d8a 100644
--- a/libjava/classpath/javax/swing/text/CompositeView.java
+++ b/libjava/classpath/javax/swing/text/CompositeView.java
@@ -264,50 +264,56 @@ public abstract class CompositeView
* Maps coordinates from the View
's space into a position
* in the document model.
*
- * @param x the x coordinate in the view space
- * @param y the y coordinate in the view space
+ * @param x the x coordinate in the view space, x >= 0
+ * @param y the y coordinate in the view space, y >= 0
* @param a the allocation of this View
* @param b the bias to use
*
* @return the position in the document that corresponds to the screen
- * coordinates x, y
+ * coordinates x, y
>= 0
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- Rectangle r = getInsideAllocation(a);
- View view = getViewAtPoint((int) x, (int) y, r);
- return view.viewToModel(x, y, a, b);
+ if (x >= 0 && y >= 0)
+ {
+ Rectangle r = getInsideAllocation(a);
+ View view = getViewAtPoint((int) x, (int) y, r);
+ return view.viewToModel(x, y, a, b);
+ }
+ return 0;
}
/**
* Returns the next model location that is visible in eiter north / south
- * direction or east / west direction. This is used to determine the
- * placement of the caret when navigating around the document with
- * the arrow keys.
- *
- * This is a convenience method for
- * {@link #getNextNorthSouthVisualPositionFrom} and
- * {@link #getNextEastWestVisualPositionFrom}.
- *
- * @param pos the model position to start search from
- * @param b the bias for pos
- * @param a the allocated region for this view
- * @param direction the direction from the current position, can be one of
- * the following:
- *
- *
- * @param biasRet the bias of the return value gets stored here
- *
+ * direction or east / west direction. This is used to determine the placement
+ * of the caret when navigating around the document with the arrow keys. This
+ * is a convenience method for {@link #getNextNorthSouthVisualPositionFrom}
+ * and {@link #getNextEastWestVisualPositionFrom}.
+ *
+ * @param pos
+ * the model position to start search from
+ * @param b
+ * the bias for pos
+ * @param a
+ * the allocated region for this view
+ * @param direction
+ * the direction from the current position, can be one of the
+ * following:
+ *
+ *
+ * @param biasRet
+ * the bias of the return value gets stored here
* @return the position inside the model that represents the next visual
* location
- *
- * @throws BadLocationException if pos
is not a valid location
- * inside the document model
- * @throws IllegalArgumentException if direction
is invalid
+ * @throws BadLocationException
+ * if pos
is not a valid location inside the document
+ * model
+ * @throws IllegalArgumentException
+ * if direction
is invalid
*/
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a,
int direction, Position.Bias[] biasRet)
diff --git a/libjava/classpath/javax/swing/text/DefaultCaret.java b/libjava/classpath/javax/swing/text/DefaultCaret.java
index 66e2f4723cf7..3ebeceb947de 100644
--- a/libjava/classpath/javax/swing/text/DefaultCaret.java
+++ b/libjava/classpath/javax/swing/text/DefaultCaret.java
@@ -781,28 +781,34 @@ public class DefaultCaret extends Rectangle
*/
public void moveDot(int dot)
{
- this.dot = dot;
- handleHighlight();
- adjustVisibility(this);
- appear();
+ if (dot >= 0)
+ {
+ this.dot = dot;
+ handleHighlight();
+ adjustVisibility(this);
+ appear();
+ }
}
/**
* Sets the current position of this Caret
within the
- * Document
. This also sets the mark
to the
- * new location.
- *
- * @param dot the new position to be set
- *
+ * Document
. This also sets the mark
to the new
+ * location.
+ *
+ * @param dot
+ * the new position to be set
* @see #moveDot(int)
*/
public void setDot(int dot)
{
- this.dot = dot;
- this.mark = dot;
- handleHighlight();
- adjustVisibility(this);
- appear();
+ if (dot >= 0)
+ {
+ this.mark = dot;
+ this.dot = dot;
+ handleHighlight();
+ adjustVisibility(this);
+ appear();
+ }
}
/**
@@ -878,7 +884,7 @@ public class DefaultCaret extends Rectangle
}
Rectangle area = null;
try
- {
+ {
area = getComponent().modelToView(getDot());
}
catch (BadLocationException ex)
diff --git a/libjava/classpath/javax/swing/text/FlowView.java b/libjava/classpath/javax/swing/text/FlowView.java
index fd6785b6f183..765f515a20d5 100644
--- a/libjava/classpath/javax/swing/text/FlowView.java
+++ b/libjava/classpath/javax/swing/text/FlowView.java
@@ -601,6 +601,9 @@ public abstract class FlowView extends BoxView
*/
public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
{
+ // First we must send the insertUpdate to the logical view so it can
+ // be updated accordingly.
+ layoutPool.insertUpdate(changes, a, vf);
strategy.insertUpdate(this, changes, getInsideAllocation(a));
}
diff --git a/libjava/classpath/javax/swing/text/GlyphView.java b/libjava/classpath/javax/swing/text/GlyphView.java
index eb1fadd4f2df..d3dd75e624bd 100644
--- a/libjava/classpath/javax/swing/text/GlyphView.java
+++ b/libjava/classpath/javax/swing/text/GlyphView.java
@@ -457,9 +457,6 @@ public class GlyphView extends View implements TabableView, Cloneable
Bias[] biasRet)
{
Rectangle b = a.getBounds();
- assert b.contains(x, y) : "The coordinates are expected to be within the "
- + "view's bounds: x=" + x + ", y=" + y
- + "a=" + a;
int pos = getBoundedPosition(v, v.getStartOffset(), b.x, x - b.x);
return pos;
}
diff --git a/libjava/classpath/javax/swing/text/IconView.java b/libjava/classpath/javax/swing/text/IconView.java
index 6dd0f7ad34ab..86c27dd5fda0 100644
--- a/libjava/classpath/javax/swing/text/IconView.java
+++ b/libjava/classpath/javax/swing/text/IconView.java
@@ -39,11 +39,25 @@ exception statement from your version. */
package javax.swing.text;
import java.awt.Graphics;
+import java.awt.Rectangle;
import java.awt.Shape;
+import javax.swing.Icon;
+import javax.swing.JTextPane;
import javax.swing.SwingConstants;
-// TODO: Implement this class.
+/**
+ * A View that can render an icon. This view is created by the
+ * {@link StyledEditorKit}'s view factory for all elements that have name
+ * {@link StyleConstants#IconElementName}. This is usually created by
+ * inserting an icon into JTextPane
using
+ * {@link JTextPane#insertIcon(Icon)}
+ *
+ * The icon is determined using the attribute
+ * {@link StyleConstants#IconAttribute}, which's value must be an {@link Icon}.
+ *
+ * @author Roman Kennke (kennke@aicas.com)
+ */
public class IconView
extends View
{
@@ -67,7 +81,9 @@ public class IconView
*/
public void paint(Graphics g, Shape a)
{
- // TODO: Implement me.
+ Icon icon = StyleConstants.getIcon(getElement().getAttributes());
+ Rectangle b = a.getBounds();
+ icon.paintIcon(getContainer(), g, b.x, b.y);
}
/**
@@ -80,8 +96,15 @@ public class IconView
*/
public float getPreferredSpan(int axis)
{
- // TODO: Implement me.
- return 0F;
+ Icon icon = StyleConstants.getIcon(getElement().getAttributes());
+ float span;
+ if (axis == X_AXIS)
+ span = icon.getIconWidth();
+ else if (axis == Y_AXIS)
+ span = icon.getIconHeight();
+ else
+ throw new IllegalArgumentException();
+ return span;
}
/**
@@ -106,8 +129,12 @@ public class IconView
public Shape modelToView(int pos, Shape a, Position.Bias b)
throws BadLocationException
{
- // Implement me.
- return null;
+ Element el = getElement();
+ if (pos < el.getStartOffset() || pos >= el.getEndOffset())
+ throw new BadLocationException("Illegal offset for this view", pos);
+ Rectangle r = a.getBounds();
+ Icon icon = StyleConstants.getIcon(el.getAttributes());
+ return new Rectangle(r.x, r.y, icon.getIconWidth(), icon.getIconHeight());
}
/**
@@ -124,8 +151,11 @@ public class IconView
*/
public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
{
- // FIXME: not implemented
- return 0;
+ // The element should only have one character position and it is clear
+ // that this position is the position that best matches the given screen
+ // coordinates, simply because this view has only this one position.
+ Element el = getElement();
+ return el.getStartOffset();
}
/**
@@ -157,4 +187,5 @@ public class IconView
// TODO: Implement this properly.
throw new AssertionError("Not implemented yet.");
}
+
}
diff --git a/libjava/classpath/javax/swing/text/ParagraphView.java b/libjava/classpath/javax/swing/text/ParagraphView.java
index 6fb121f949e3..c4864503187b 100644
--- a/libjava/classpath/javax/swing/text/ParagraphView.java
+++ b/libjava/classpath/javax/swing/text/ParagraphView.java
@@ -38,6 +38,10 @@ exception statement from your version. */
package javax.swing.text;
+import java.awt.Shape;
+
+import javax.swing.event.DocumentEvent;
+
/**
* A {@link FlowView} that flows it's children horizontally and boxes the rows
* vertically.
@@ -66,6 +70,26 @@ public class ParagraphView extends FlowView implements TabExpander
}
}
+ /**
+ * The indentation of the first line of the paragraph.
+ */
+ protected int firstLineIndent;
+
+ /**
+ * The justification of the paragraph.
+ */
+ private int justification;
+
+ /**
+ * The line spacing of this paragraph.
+ */
+ private float lineSpacing;
+
+ /**
+ * The TabSet of this paragraph.
+ */
+ private TabSet tabSet;
+
/**
* Creates a new ParagraphView
for the given
* Element
.
@@ -116,4 +140,93 @@ public class ParagraphView extends FlowView implements TabExpander
else
return 0.0F;
}
+
+ /**
+ * Receives notification when some attributes of the displayed element
+ * changes. This triggers a refresh of the cached attributes of this
+ * paragraph.
+ *
+ * @param ev the document event
+ * @param a the allocation of this view
+ * @param fv the view factory to use for creating new child views
+ */
+ public void changedUpdate(DocumentEvent ev, Shape a, ViewFactory fv)
+ {
+ setPropertiesFromAttributes();
+ }
+
+ /**
+ * Fetches the cached properties from the element's attributes.
+ */
+ protected void setPropertiesFromAttributes()
+ {
+ Element el = getElement();
+ AttributeSet atts = el.getAttributes();
+ setFirstLineIndent(StyleConstants.getFirstLineIndent(atts));
+ setLineSpacing(StyleConstants.getLineSpacing(atts));
+ setJustification(StyleConstants.getAlignment(atts));
+ tabSet = StyleConstants.getTabSet(atts);
+ }
+
+ /**
+ * Sets the indentation of the first line of the paragraph.
+ *
+ * @param i the indentation to set
+ */
+ protected void setFirstLineIndent(float i)
+ {
+ firstLineIndent = (int) i;
+ }
+
+ /**
+ * Sets the justification of the paragraph.
+ *
+ * @param j the justification to set
+ */
+ protected void setJustification(int j)
+ {
+ justification = j;
+ }
+
+ /**
+ * Sets the line spacing for this paragraph.
+ *
+ * @param s the line spacing to set
+ */
+ protected void setLineSpacing(float s)
+ {
+ lineSpacing = s;
+ }
+
+ /**
+ * Returns the i-th view from the logical views, before breaking into rows.
+ *
+ * @param i the index of the logical view to return
+ *
+ * @return the i-th view from the logical views, before breaking into rows
+ */
+ protected View getLayoutView(int i)
+ {
+ return layoutPool.getView(i);
+ }
+
+ /**
+ * Returns the number of logical child views.
+ *
+ * @return the number of logical child views
+ */
+ protected int getLayoutViewCount()
+ {
+ return layoutPool.getViewCount();
+ }
+
+ /**
+ * Returns the TabSet used by this ParagraphView.
+ *
+ * @return the TabSet used by this ParagraphView
+ */
+ protected TabSet getTabSet()
+ {
+ return tabSet;
+ }
}
diff --git a/libjava/classpath/javax/swing/text/PlainDocument.java b/libjava/classpath/javax/swing/text/PlainDocument.java
index 9e600c4c9081..0c00a06ff252 100644
--- a/libjava/classpath/javax/swing/text/PlainDocument.java
+++ b/libjava/classpath/javax/swing/text/PlainDocument.java
@@ -105,10 +105,65 @@ public class PlainDocument extends AbstractDocument
return root;
}
- protected void insertUpdate(DefaultDocumentEvent event, AttributeSet attributes)
+ protected void insertUpdate(DefaultDocumentEvent event,
+ AttributeSet attributes)
{
- reindex();
+ int offset = event.getOffset();
+ int end = offset + event.getLength();
+ int elementIndex = rootElement.getElementIndex(offset);
+ Element firstElement = rootElement.getElement(elementIndex);
+
+ // added and removed are Element arrays used to add an ElementEdit
+ // to the DocumentEvent if there were entire lines added or removed.
+ Element[] removed = new Element[1];
+ Element[] added;
+ try
+ {
+ String str = content.getString(0, content.length());
+ ArrayList elts = new ArrayList();
+ // Determine how many NEW lines were added by finding the newline
+ // characters within the newly inserted text
+ int j = firstElement.getStartOffset();
+ int i = str.indexOf('\n', offset);
+ while (i != -1 && i <= end)
+ {
+ // For each new line, create a new element
+ elts.add(createLeafElement(rootElement, SimpleAttributeSet.EMPTY,
+ j, i + 1));
+ j = i + 1;
+ if (j >= str.length())
+ break;
+ i = str.indexOf('\n', j);
+ }
+ // If there were new lines added we have to add an ElementEdit to
+ // the DocumentEvent and we have to call rootElement.replace to
+ // insert the new lines
+ if (elts.size() != 0)
+ {
+ // Set up the ElementEdit by filling the added and removed
+ // arrays with the proper Elements
+ added = new Element[elts.size()];
+ for (int k = 0; k < elts.size(); ++k)
+ added[k] = (Element) elts.get(k);
+ removed[0] = firstElement;
+
+ // Now create and add the ElementEdit
+ ElementEdit e = new ElementEdit(rootElement, elementIndex, removed,
+ added);
+ event.addEdit(e);
+
+ // And call replace to actually make the changes
+ ((BranchElement) rootElement).replace(elementIndex, 1, added);
+ }
+ }
+ catch (BadLocationException e)
+ {
+ // This shouldn't happen so we throw an AssertionError
+ AssertionError ae = new AssertionError();
+ ae.initCause(e);
+ throw ae;
+ }
super.insertUpdate(event, attributes);
}
@@ -116,24 +171,37 @@ public class PlainDocument extends AbstractDocument
{
super.removeUpdate(event);
+ // added and removed are Element arrays used to add an ElementEdit
+ // to the DocumentEvent if there were entire lines added or removed
+ // from the Document
+ Element[] added = new Element[1];
+ Element[] removed;
int p0 = event.getOffset();
- int len = event.getLength();
- int p1 = len + p0;
// check if we must collapse some elements
int i1 = rootElement.getElementIndex(p0);
- int i2 = rootElement.getElementIndex(p1);
+ int i2 = rootElement.getElementIndex(p0 + event.getLength());
if (i1 != i2)
{
- Element el1 = rootElement.getElement(i1);
- Element el2 = rootElement.getElement(i2);
- int start = el1.getStartOffset();
- int end = el2.getEndOffset();
- // collapse elements if the removal spans more than 1 line
- Element newEl = createLeafElement(rootElement,
+ // If there were lines removed then we have to add an ElementEdit
+ // to the DocumentEvent so we set it up now by filling the Element
+ // arrays "removed" and "added" appropriately
+ removed = new Element [i2 - i1 + 1];
+ for (int i = i1; i <= i2; i++)
+ removed[i-i1] = rootElement.getElement(i);
+
+ int start = rootElement.getElement(i1).getStartOffset();
+ int end = rootElement.getElement(i2).getEndOffset();
+ added[0] = createLeafElement(rootElement,
SimpleAttributeSet.EMPTY,
start, end);
- rootElement.replace(i1, i2 - i1 + 1, new Element[]{ newEl });
+
+ // Now create and add the ElementEdit
+ ElementEdit e = new ElementEdit(rootElement, i1, removed, added);
+ event.addEdit(e);
+
+ // collapse elements if the removal spans more than 1 line
+ rootElement.replace(i1, i2 - i1 + 1, added);
}
}
@@ -167,7 +235,7 @@ public class PlainDocument extends AbstractDocument
throws BadLocationException
{
String string = str;
- if (Boolean.TRUE.equals(getProperty("filterNewlines")))
+ if (str != null && Boolean.TRUE.equals(getProperty("filterNewlines")))
string = str.replaceAll("\n", " ");
super.insertString(offs, string, atts);
}
diff --git a/libjava/classpath/javax/swing/text/WrappedPlainView.java b/libjava/classpath/javax/swing/text/WrappedPlainView.java
index b90519046aec..b03399d09745 100644
--- a/libjava/classpath/javax/swing/text/WrappedPlainView.java
+++ b/libjava/classpath/javax/swing/text/WrappedPlainView.java
@@ -50,7 +50,7 @@ import javax.swing.event.DocumentEvent;
import javax.swing.text.Position.Bias;
/**
- * @author abalkiss
+ * @author Anthony Balkissoon abalkiss at redhat dot com
*
*/
public class WrappedPlainView extends BoxView implements TabExpander
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
index 2891a778ee92..ae8b99c2fe5c 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellEditor.java
@@ -339,9 +339,8 @@ public class DefaultTreeCellEditor
lastPath = tree.getLeadSelectionPath();
tree.addTreeSelectionListener(this);
editingContainer = createContainer();
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
- setFont(defaults.getFont("Tree.font"));
- setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
+ setFont(UIManager.getFont("Tree.font"));
+ setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
editingIcon = renderer.getIcon();
timer = new javax.swing.Timer(1200, this);
}
@@ -735,9 +734,8 @@ public class DefaultTreeCellEditor
*/
protected TreeCellEditor createTreeCellEditor()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
realEditor = new DefaultCellEditor(new DefaultTreeCellEditor.DefaultTextField(
- defaults.getBorder("Tree.selectionBorder")));
+ UIManager.getBorder("Tree.selectionBorder")));
return realEditor;
}
}
diff --git a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
index d1cb9c0e8b70..df70ba7fb9fa 100644
--- a/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
+++ b/libjava/classpath/javax/swing/tree/DefaultTreeCellRenderer.java
@@ -51,7 +51,6 @@ import javax.swing.border.Border;
import javax.swing.Icon;
import javax.swing.JLabel;
import javax.swing.JTree;
-import javax.swing.UIDefaults;
import javax.swing.UIManager;
import javax.swing.SwingUtilities;
import javax.swing.plaf.UIResource;
@@ -133,17 +132,15 @@ public class DefaultTreeCellRenderer
*/
public DefaultTreeCellRenderer()
{
- UIDefaults defaults = UIManager.getLookAndFeelDefaults();
-
setLeafIcon(getDefaultLeafIcon());
setOpenIcon(getDefaultOpenIcon());
setClosedIcon(getDefaultClosedIcon());
- setTextNonSelectionColor(defaults.getColor("Tree.textForeground"));
- setTextSelectionColor(defaults.getColor("Tree.selectionForeground"));
- setBackgroundNonSelectionColor(defaults.getColor("Tree.nonSelectionBackground"));
- setBackgroundSelectionColor(defaults.getColor("Tree.selectionBackground"));
- setBorderSelectionColor(defaults.getColor("Tree.selectionBorderColor"));
+ setTextNonSelectionColor(UIManager.getColor("Tree.textForeground"));
+ setTextSelectionColor(UIManager.getColor("Tree.selectionForeground"));
+ setBackgroundNonSelectionColor(UIManager.getColor("Tree.nonSelectionBackground"));
+ setBackgroundSelectionColor(UIManager.getColor("Tree.selectionBackground"));
+ setBorderSelectionColor(UIManager.getColor("Tree.selectionBorderColor"));
}
// -------------------------------------------------------------
@@ -157,7 +154,7 @@ public class DefaultTreeCellRenderer
*/
public Icon getDefaultOpenIcon()
{
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.openIcon");
+ return UIManager.getIcon("Tree.openIcon");
}
/**
@@ -167,7 +164,7 @@ public class DefaultTreeCellRenderer
*/
public Icon getDefaultClosedIcon()
{
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.closedIcon");
+ return UIManager.getIcon("Tree.closedIcon");
}
/**
@@ -177,7 +174,7 @@ public class DefaultTreeCellRenderer
*/
public Icon getDefaultLeafIcon()
{
- return UIManager.getLookAndFeelDefaults().getIcon("Tree.leafIcon");
+ return UIManager.getIcon("Tree.leafIcon");
}
/**
@@ -412,7 +409,7 @@ public class DefaultTreeCellRenderer
setOpaque(false);
setVerticalAlignment(TOP);
setEnabled(true);
- super.setFont(UIManager.getLookAndFeelDefaults().getFont("Tree.font"));
+ super.setFont(UIManager.getFont("Tree.font"));
if (selected)
{
@@ -459,8 +456,7 @@ public class DefaultTreeCellRenderer
Rectangle tr = new Rectangle();
Insets insets = new Insets(0, 0, 0, 0);
- Border border = UIManager.getLookAndFeelDefaults().getBorder(
- "Tree.selectionBorder");
+ Border border = UIManager.getBorder("Tree.selectionBorder");
if (border != null)
insets = border.getBorderInsets(this);
diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
index 7f51e534dd7e..092e997a36d2 100644
--- a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
+++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphics2D.c
@@ -565,6 +565,13 @@ Java_gnu_java_awt_peer_gtk_GdkGraphics2D_gdkDrawDrawable
/* gdk_flush(); */
+ if (!GDK_IS_DRAWABLE (src->drawable) ||
+ !GDK_IS_DRAWABLE (dst->drawable))
+ {
+ gdk_threads_leave ();
+ return;
+ }
+
gdk_drawable_get_size (src->drawable, &s_width, &s_height);
gdk_drawable_get_size (dst->drawable, &d_width, &d_height);
width = min (s_width, d_width);
diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
index 59b56cf355bc..b14330e5fe22 100644
--- a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
+++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c
@@ -135,6 +135,8 @@ Java_gnu_java_awt_peer_gtk_GtkToolkit_gtkInit (JNIEnv *env,
gtkgenericpeer = (*env)->FindClass(env, "gnu/java/awt/peer/gtk/GtkGenericPeer");
+ gtkgenericpeer = (*env)->NewGlobalRef(env, gtkgenericpeer);
+
printCurrentThreadID = (*env)->GetStaticMethodID (env, gtkgenericpeer,
"printCurrentThread", "()V");
diff --git a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
index d79bbecbaf68..ac8f6a8ff1ea 100644
--- a/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
+++ b/libjava/classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkWindowPeer.c
@@ -1204,8 +1204,8 @@ Java_gnu_java_awt_peer_gtk_GtkWindowPeer_gtkWindowSetResizable
gdk_threads_enter ();
ptr = NSA_GET_PTR (env, obj);
-
gtk_window_set_resizable (GTK_WINDOW (ptr), resizable);
+ g_object_set (G_OBJECT (ptr), "allow-shrink", resizable, NULL);
gdk_threads_leave ();
}
diff --git a/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c
index 846df2e6a4fa..076f42b86a38 100644
--- a/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c
+++ b/libjava/classpath/native/jni/java-lang/java_lang_VMDouble.c
@@ -71,6 +71,11 @@ Java_java_lang_VMDouble_initIDs (JNIEnv * env, jclass cls __attribute__ ((__unus
{
DBG ("unable to get class java.lang.Double\n") return;
}
+ clsDouble = (*env)->NewGlobalRef(env, clsDouble);
+ if (clsDouble == NULL)
+ {
+ DBG ("unable to register class java.lang.Double as global ref\n") return;
+ }
isNaNID = (*env)->GetStaticMethodID (env, clsDouble, "isNaN", "(D)Z");
if (isNaNID == NULL)
{
diff --git a/libjava/gnu/java/net/protocol/file/Connection.java b/libjava/gnu/java/net/protocol/file/Connection.java
deleted file mode 100644
index 8e4a413667d1..000000000000
--- a/libjava/gnu/java/net/protocol/file/Connection.java
+++ /dev/null
@@ -1,368 +0,0 @@
-/* FileURLConnection.java -- URLConnection class for "file" protocol
- Copyright (C) 1998, 1999, 2003 Free Software Foundation, Inc.
-
-This file is part of GNU Classpath.
-
-GNU Classpath is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-GNU Classpath is distributed in the hope that it will be useful, but
-WITHOUT ANY WARRANTY; without even the implied warranty of
-MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
-General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with GNU Classpath; see the file COPYING. If not, write to the
-Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
-02110-1301 USA.
-
-Linking this library statically or dynamically with other modules is
-making a combined work based on this library. Thus, the terms and
-conditions of the GNU General Public License cover the whole
-combination.
-
-As a special exception, the copyright holders of this library give you
-permission to link this library with independent modules to produce an
-executable, regardless of the license terms of these independent
-modules, and to copy and distribute the resulting executable under
-terms of your choice, provided that you also meet, for each linked
-independent module, the terms and conditions of the license of that
-module. An independent module is a module which is not derived from
-or based on this library. If you modify this library, you may extend
-this exception to your version of the library, but you are not
-obligated to do so. If you do not wish to do so, delete this
-exception statement from your version. */
-
-package gnu.java.net.protocol.file;
-
-import gnu.classpath.SystemProperties;
-
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.ByteArrayInputStream;
-import java.io.ByteArrayOutputStream;
-import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileOutputStream;
-import java.io.FilePermission;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
-import java.io.OutputStreamWriter;
-import java.io.Writer;
-import java.net.ProtocolException;
-import java.net.URL;
-import java.net.URLConnection;
-import java.security.Permission;
-import java.text.SimpleDateFormat;
-import java.util.Date;
-import java.util.Locale;
-import java.net.MalformedURLException;
-
-/**
- * This subclass of java.net.URLConnection models a URLConnection via
- * the "file" protocol.
- *
- * @author Aaron M. Renn (arenn@urbanophile.com)
- * @author Nic Ferrier (nferrier@tapsellferrier.co.uk)
- * @author Warren Levy (warrenl@cygnus.com)
- */
-public class Connection extends URLConnection
-{
- /**
- * Default permission for a file
- */
- private static final String DEFAULT_PERMISSION = "read";
-
- private static class StaticData
- {
- /**
- * HTTP-style DateFormat, used to format the last-modified header.
- */
- static SimpleDateFormat dateFormat
- = new SimpleDateFormat("EEE, dd MMM yyyy hh:mm:ss 'GMT'",
- new Locale ("En", "Us", "Unix"));
-
- static String lineSeparator =
- SystemProperties.getProperty("line.separator");
- }
-
-
- /**
- * This is a File object for this connection
- */
- private File file;
-
- /**
- * If a directory, contains a list of files in the directory.
- */
- private byte[] directoryListing;
-
- /**
- * InputStream if we are reading from the file
- */
- private InputStream inputStream;
-
- /**
- * OutputStream if we are writing to the file
- */
- private OutputStream outputStream;
-
- /**
- * FilePermission to read the file
- */
- private FilePermission permission;
-
- /**
- * Calls superclass constructor to initialize.
- */
- public Connection(URL url)
- {
- super (url);
-
- permission = new FilePermission(getURL().getFile(), DEFAULT_PERMISSION);
- }
-
- /**
- * Unquote "%" + hex quotes characters
- *
- * @param str The string to unquote or null.
- *
- * @return The unquoted string or null if str was null.
- *
- * @exception MalformedURLException If the given string contains invalid
- * escape sequences.
- *
- * Sadly the same as URI.unquote, but there's nothing we can do to
- * make it accessible.
- *
- */
- public static String unquote(String str) throws MalformedURLException
- {
- if (str == null)
- return null;
- byte[] buf = new byte[str.length()];
- int pos = 0;
- for (int i = 0; i < str.length(); i++)
- {
- char c = str.charAt(i);
- if (c > 127)
- throw new MalformedURLException(str + " : Invalid character");
- if (c == '%')
- {
- if (i + 2 >= str.length())
- throw new MalformedURLException(str + " : Invalid quoted character");
- int hi = Character.digit(str.charAt(++i), 16);
- int lo = Character.digit(str.charAt(++i), 16);
- if (lo < 0 || hi < 0)
- throw new MalformedURLException(str + " : Invalid quoted character");
- buf[pos++] = (byte) (hi * 16 + lo);
- }
- else
- buf[pos++] = (byte) c;
- }
- try
- {
- return new String(buf, 0, pos, "utf-8");
- }
- catch (java.io.UnsupportedEncodingException x2)
- {
- throw (Error) new InternalError().initCause(x2);
- }
- }
-
- /**
- * "Connects" to the file by opening it.
- */
- public void connect() throws IOException
- {
- // Call is ignored if already connected.
- if (connected)
- return;
-
- // If not connected, then file needs to be openned.
- file = new File (unquote(getURL().getFile()));
-
- if (! file.isDirectory())
- {
- if (doInput)
- inputStream = new BufferedInputStream(new FileInputStream(file));
-
- if (doOutput)
- outputStream = new BufferedOutputStream(new FileOutputStream(file));
- }
- else
- {
- if (doInput)
- {
- inputStream = new ByteArrayInputStream(getDirectoryListing());
- }
-
- if (doOutput)
- throw new ProtocolException
- ("file: protocol does not support output on directories");
- }
-
- connected = true;
- }
-
- /**
- * Populates the directoryListing
field with a byte array
- * containing a representation of the directory listing.
- */
- byte[] getDirectoryListing()
- throws IOException
- {
- if (directoryListing == null)
- {
- ByteArrayOutputStream sink = new ByteArrayOutputStream();
- // NB uses default character encoding for this system
- Writer writer = new OutputStreamWriter(sink);
-
- String[] files = file.list();
-
- for (int i = 0; i < files.length; i++)
- {
- writer.write(files[i]);
- writer.write(StaticData.lineSeparator);
- }
-
- directoryListing = sink.toByteArray();
- }
- return directoryListing;
- }
-
- /**
- * Opens the file for reading and returns a stream for it.
- *
- * @return An InputStream for this connection.
- *
- * @exception IOException If an error occurs
- */
- public InputStream getInputStream()
- throws IOException
- {
- if (!doInput)
- throw new ProtocolException("Can't open InputStream if doInput is false");
-
- if (!connected)
- connect();
-
- return inputStream;
- }
-
- /**
- * Opens the file for writing and returns a stream for it.
- *
- * @return An OutputStream for this connection.
- *
- * @exception IOException If an error occurs.
- */
- public OutputStream getOutputStream()
- throws IOException
- {
- if (!doOutput)
- throw new
- ProtocolException("Can't open OutputStream if doOutput is false");
-
- if (!connected)
- connect();
-
- return outputStream;
- }
-
- /**
- * Get the last modified time of the resource.
- *
- * @return the time since epoch that the resource was modified.
- */
- public long getLastModified()
- {
- try
- {
- if (!connected)
- connect();
-
- return file.lastModified();
- }
- catch (IOException e)
- {
- return -1;
- }
- }
-
- /**
- * Get an http-style header field. Just handle a few common ones.
- */
- public String getHeaderField(String field)
- {
- try
- {
- if (!connected)
- connect();
-
- if (field.equals("content-type"))
- return guessContentTypeFromName(file.getName());
- else if (field.equals("content-length"))
- {
- if (file.isDirectory())
- {
- return Integer.toString(getContentLength());
- }
- return Long.toString(file.length());
- }
- else if (field.equals("last-modified"))
- {
- synchronized (StaticData.dateFormat)
- {
- return StaticData.dateFormat.format(
- new Date(file.lastModified()));
- }
- }
- }
- catch (IOException e)
- {
- // Fall through.
- }
- return null;
- }
-
- /**
- * Get the length of content.
- *
- * @return the length of the content.
- */
- public int getContentLength()
- {
- try
- {
- if (!connected)
- connect();
-
- if (file.isDirectory())
- {
- return getDirectoryListing().length;
- }
- return (int) file.length();
- }
- catch (IOException e)
- {
- return -1;
- }
- }
-
- /**
- * This method returns a Permission
object representing the
- * permissions required to access this URL. This method returns a
- * java.io.FilePermission
for the file's path with a read
- * permission.
- *
- * @return A Permission object
- */
- public Permission getPermission() throws IOException
- {
- return permission;
- }
-}
diff --git a/libjava/sources.am b/libjava/sources.am
index ddf5c8da5af4..6a0b3025f1c5 100644
--- a/libjava/sources.am
+++ b/libjava/sources.am
@@ -975,7 +975,7 @@ gnu/java/net.list: $(gnu_java_net_source_files)
gnu_java_net_protocol_file_source_files = \
-gnu/java/net/protocol/file/Connection.java \
+classpath/gnu/java/net/protocol/file/Connection.java \
classpath/gnu/java/net/protocol/file/Handler.java
gnu_java_net_protocol_file_header_files = $(patsubst classpath/%,%,$(patsubst %.java,%.h,$(gnu_java_net_protocol_file_source_files)))
@@ -5133,6 +5133,7 @@ classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java \
classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java \
classpath/javax/swing/plaf/metal/MetalLabelUI.java \
classpath/javax/swing/plaf/metal/MetalLookAndFeel.java \
+classpath/javax/swing/plaf/metal/MetalMenuBarUI.java \
classpath/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java \
classpath/javax/swing/plaf/metal/MetalProgressBarUI.java \
classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java \