ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From anto...@apache.org
Subject cvs commit: ant-antidote/src/java/org/apache/tools/ant/gui About.java
Date Sat, 13 Sep 2003 19:22:56 GMT
antoine     2003/09/13 12:22:56

  Modified:    src/java/org/apache/tools/ant/gui About.java
  Log:
  In the About dialog:
  - info pane: better placement for the props and classpath
  tables
  - fix for 'System Locale' if 'user.region' is null
  - some common operations extracted to helper methods
  Submitted by: Lajos Pajtek (lajos dot pajtek at yahoo dot com)
  
  Revision  Changes    Path
  1.7       +60 -18    ant-antidote/src/java/org/apache/tools/ant/gui/About.java
  
  Index: About.java
  ===================================================================
  RCS file: /home/cvs/ant-antidote/src/java/org/apache/tools/ant/gui/About.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- About.java	10 Feb 2003 14:34:56 -0000	1.6
  +++ About.java	13 Sep 2003 19:22:56 -0000	1.7
  @@ -91,6 +91,7 @@
    */
   public class About extends JDialog {
       
  +    /** The application context for this dialog. */
       private transient AppContext _context = null;
       
       /**
  @@ -108,16 +109,30 @@
        * Alternative ctor for use without AppContext.
        */
       public About(JFrame parent) {
  -        super((Frame)((parent == null)?null:(parent instanceof Frame)?parent:JOptionPane.getFrameForComponent(parent)));
  +        // TODO seems to be unused, should go?
  +        super(getFrame(parent));
           init();
       }
       
  +    private static Frame getFrame(JFrame frame) {
  +        // should be equivalent to:
  +        // return ((frame == null)?null:(frame instanceof Frame)?frame:JOptionPane.getFrameForComponent(frame));
  +        Frame pFrame = frame;
  +        if (frame != null && !(frame instanceof Frame)) {
  +            pFrame = JOptionPane.getFrameForComponent(frame);
  +        }
  +        return pFrame;
  +    }
  +
  +    /**
  +     * Initialization (and display).
  +     */
       private void init() {
           
           setDefaultCloseOperation(DISPOSE_ON_CLOSE);
           
           setModal(true);
  -        String title = (_context!=null?_context.getResources().getString(getClass(), "title"):"");
  +        String title = getResource("title", "ANTidote");
           setTitle(title);
           JPanel mainPanel = new JPanel(new BorderLayout());
           setContentPane(mainPanel);
  @@ -131,20 +146,25 @@
           
           // Just go ahead and show it...
           pack();
  -        if (_context != null)
  +        if (_context != null) {
               WindowUtils.centerWindow(_context.getParentFrame(), this);
  +        }
           setResizable(false);
           setVisible(true);
       }
       
  +    /**
  +     * Builds the nice About panel.
  +     *
  +     * @return the About panel
  +     */
       private JPanel getImagePanel() {
           JPanel imagePanel = new JPanel(new BorderLayout());
           JLabel imageLabel = new JLabel(new ImageIcon(getClass().getResource("/org/apache/tools/ant/gui/resources/About.gif")));
           imagePanel.add(imageLabel, BorderLayout.CENTER);
           
  -        JLabel messageLabel = (_context!=null?new JLabel(_context.getResources().getMessage(getClass(),
"message",new Object[] {})):null);
  -        
  -        if (messageLabel != null) {
  +        if (_context != null) {
  +            JLabel messageLabel = new JLabel(_context.getResources().getMessage(getClass(),
"message", new Object[] {}));
               messageLabel.setBorder(BorderFactory.createEmptyBorder(0, 4, 3, 4));
               imagePanel.add(messageLabel, BorderLayout.SOUTH);
           }
  @@ -152,6 +172,11 @@
           return imagePanel;
       }
       
  +    /**
  +     * Builds the (client)info panel.
  +     *
  +     * @return the clientinfo panel
  +     */
       private JPanel getClientInfoPanel() {
           JPanel infoPanel = new JPanel(new GridBagLayout());
           
  @@ -190,15 +215,15 @@
           
           String [] dummy = {"",""};
           String[][] data = new String[11][2];
  -        data[0][0] = (_context!=null?_context.getResources().getString(getClass(), "version"):"Version");
  +        data[0][0] = getResource("version", "Version");
           data[0][1] = props.getProperty("VERSION", "??");
  -        data[1][0] = (_context!=null?_context.getResources().getString(getClass(), "date"):"Date");
  +        data[1][0] = getResource("date", "Date");
           data[1][1] = props.getProperty("DATE", "??");
  -        data[2][0] = (_context!=null?_context.getResources().getString(getClass(), "antVersion"):"Ant
Version");
  +        data[2][0] = getResource("antVersion", "Ant Version");
           data[2][1] = antProps.getProperty("VERSION", "??");
  -        data[3][0] = (_context!=null?_context.getResources().getString(getClass(), "antDate"):"Ant
Build Date");
  +        data[3][0] = getResource("antDate", "Ant Build Date");
           data[3][1] = antProps.getProperty("DATE", "??");
  -        data[4][0] = (_context!=null?_context.getResources().getString(getClass(), "operatingSystem"):"Operating
System");
  +        data[4][0] = getResource("operatingSystem", "Operating System");
           data[4][1] = System.getProperty("os.name")+" version "+System.getProperty("os.version")+"
running on "+System.getProperty("os.arch");
           data[5][0] = "Java";
           data[5][1] = System.getProperty("java.version");
  @@ -207,10 +232,10 @@
           data[7][0] = "Java Home";
           data[7][1] = System.getProperty("java.home");
           data[8][0] = "System Locale";
  -        data[8][1] = System.getProperty("user.language")+"_"+System.getProperty("user.region");
  -        data[9][0] = (_context!=null?_context.getResources().getString(getClass(), "freeMemory"):"Free
Memory");
  +        data[8][1] = System.getProperty("user.language")+(System.getProperty("user.region")==null?"":"_"+System.getProperty("user.region"));
  +        data[9][0] = getResource("freeMemory", "Free Memory");
           data[9][1] = (Runtime.getRuntime().freeMemory()/1024)+" kByte";
  -        data[10][0] = (_context!=null?_context.getResources().getString(getClass(), "totalMemory"):"Total
Memory");
  +        data[10][0] = getResource("totalMemory", "Total Memory");
           data[10][1] = (Runtime.getRuntime().totalMemory()/1024)+" kByte";
   
           clientTable.setModel(new DefaultTableModel(data, dummy) {
  @@ -223,10 +248,10 @@
           
           JScrollPane tableScrollPane = new JScrollPane(clientTable);
           tableScrollPane.setPreferredSize(new Dimension(250, 100));
  -        infoPanel.add(tableScrollPane, new GridBagConstraints(1, 4, 2, 1, 0, 1.0, GridBagConstraints.WEST,
GridBagConstraints.BOTH, new Insets(1, 6, 2, 6), 0, 0));
  +        infoPanel.add(tableScrollPane, new GridBagConstraints(0, 4, 3, 1, 0, 1.0, GridBagConstraints.WEST,
GridBagConstraints.BOTH, new Insets(1, 6, 2, 6), 0, 0));
           
           JLabel classpathLabel = new JLabel("Classpath:");
  -        infoPanel.add(classpathLabel, new GridBagConstraints(1, 5, 2, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(5, 6, 0, 0), 0, 0));
  +        infoPanel.add(classpathLabel, new GridBagConstraints(0, 5, 3, 1, 1.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.NONE, new Insets(5, 6, 0, 0), 0, 0));
   
           String classFileString = System.getProperty("java.class.path");
           Vector pathElements = new Vector();
  @@ -235,10 +260,27 @@
           JScrollPane listScrollPane = new JScrollPane(list);
           listScrollPane.setPreferredSize(new java.awt.Dimension(100, 80));
   
  -        infoPanel.add(listScrollPane, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.BOTH, new Insets(1, 6, 2, 6), 0, 0));
  +        infoPanel.add(listScrollPane, new GridBagConstraints(0, 6, 3, 1, 0.0, 0.0, GridBagConstraints.WEST,
GridBagConstraints.BOTH, new Insets(1, 6, 2, 6), 0, 0));
           
           infoPanel.setBorder(BorderFactory.createEmptyBorder(7,7,5,7));
           
           return infoPanel;
  +    }
  +
  +    /**
  +     * Helper method for retrieving a resource string.
  +     *
  +     * @param key the key to the resource
  +     * @param defaultValue value returned if the AppContext is null
  +     * @return the resource associated to the key, or defaultValue if the
  +     *     AppContext is null.
  +     * @see AppContext
  +     */
  +    private String getResource(String key, String defaultValue) {
  +        String value = defaultValue;
  +        if (_context != null) {
  +            value = _context.getResources().getString(getClass(), key);
  +        }
  +        return value;
       }
   }
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message