< prev index next >

src/java.desktop/windows/classes/sun/awt/windows/WListPeer.java

Print this page


   1 /*
   2  * Copyright (c) 1996, 2015, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37     }
  38 
  39     // ListPeer implementation
  40 
  41     @Override
  42     public int[] getSelectedIndexes() {
  43         List l = (List)target;
  44         int len = l.getItemCount();
  45         int sel[] = new int[len];
  46         int nsel = 0;
  47         for (int i = 0 ; i < len ; i++) {
  48             if (isSelected(i)) {
  49                 sel[nsel++] = i;
  50             }
  51         }
  52         int selected[] = new int[nsel];
  53         System.arraycopy(sel, 0, selected, 0, nsel);
  54         return selected;
  55     }
  56 
  57     /* New method name for 1.1 */
  58     @Override
  59     public void add(String item, int index) {
  60         addItem(item, index);
  61     }
  62 
  63     /* New method name for 1.1 */
  64     @Override
  65     public void removeAll() {
  66         clear();
  67     }
  68 
  69     /* New method name for 1.1 */
  70     @Override
  71     public void setMultipleMode (boolean b) {
  72         setMultipleSelections(b);
  73     }
  74 
  75     /* New method name for 1.1 */
  76     @Override
  77     public Dimension getPreferredSize(int rows) {
  78         return preferredSize(rows);






  79     }
  80 
  81     /* New method name for 1.1 */
  82     @Override
  83     public Dimension getMinimumSize(int rows) {
  84         return minimumSize(rows);

  85     }
  86 
  87     private FontMetrics   fm;
  88     public void addItem(String item, int index) {
  89         addItems(new String[] {item}, index, fm.stringWidth(item));
  90     }
  91     native void addItems(String[] items, int index, int width);
  92 
  93     @Override
  94     public native void delItems(int start, int end);
  95     public void clear() {
  96         List l = (List)target;
  97         delItems(0, l.getItemCount());
  98     }
  99     @Override
 100     public native void select(int index);
 101     @Override
 102     public native void deselect(int index);
 103     @Override
 104     public native void makeVisible(int index);
 105     public native void setMultipleSelections(boolean v);
 106     public native int  getMaxWidth();
 107 
 108     public Dimension preferredSize(int v) {
 109         if ( fm == null ) {
 110             List li = (List)target;
 111             fm = getFontMetrics( li.getFont() );
 112         }
 113         Dimension d = minimumSize(v);
 114         d.width = Math.max(d.width, getMaxWidth() + 20);
 115         return d;
 116     }
 117     public Dimension minimumSize(int v) {
 118         return new Dimension(20 + fm.stringWidth("0123456789abcde"),
 119                              (fm.getHeight() * v) + 4); // include borders
 120     }
 121 
 122     // Toolkit & peer internals
 123 
 124     WListPeer(List target) {
 125         super(target);
 126     }
 127 
 128     @Override
 129     native void create(WComponentPeer parent);
 130 
 131     @Override
 132     void initialize() {
 133         List li = (List)target;
 134 
 135         fm = getFontMetrics( li.getFont() );
 136 
 137         // Fixed 6336384: setFont should be done before addItems
 138         Font  f = li.getFont();
 139         if (f != null) {
 140             setFont(f);
 141         }


   1 /*
   2  * Copyright (c) 1996, 2018, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any


  37     }
  38 
  39     // ListPeer implementation
  40 
  41     @Override
  42     public int[] getSelectedIndexes() {
  43         List l = (List)target;
  44         int len = l.getItemCount();
  45         int sel[] = new int[len];
  46         int nsel = 0;
  47         for (int i = 0 ; i < len ; i++) {
  48             if (isSelected(i)) {
  49                 sel[nsel++] = i;
  50             }
  51         }
  52         int selected[] = new int[nsel];
  53         System.arraycopy(sel, 0, selected, 0, nsel);
  54         return selected;
  55     }
  56 

  57     @Override
  58     public void add(String item, int index) {
  59         addItem(item, index);
  60     }
  61 

  62     @Override
  63     public void removeAll() {
  64         clear();
  65     }
  66 

  67     @Override
  68     public void setMultipleMode (boolean b) {
  69         setMultipleSelections(b);
  70     }
  71 

  72     @Override
  73     public Dimension getPreferredSize(int rows) {
  74         if ( fm == null ) {
  75             List li = (List)target;
  76             fm = getFontMetrics( li.getFont() );
  77         }
  78         Dimension d = getMinimumSize(rows);
  79         d.width = Math.max(d.width, getMaxWidth() + 20);
  80         return d;
  81     }
  82 

  83     @Override
  84     public Dimension getMinimumSize(int rows) {
  85         return new Dimension(20 + fm.stringWidth("0123456789abcde"),
  86                              (fm.getHeight() * rows) + 4); // include borders
  87     }
  88 
  89     private FontMetrics   fm;
  90     public void addItem(String item, int index) {
  91         addItems(new String[] {item}, index, fm.stringWidth(item));
  92     }
  93     native void addItems(String[] items, int index, int width);
  94 
  95     @Override
  96     public native void delItems(int start, int end);
  97     public void clear() {
  98         List l = (List)target;
  99         delItems(0, l.getItemCount());
 100     }
 101     @Override
 102     public native void select(int index);
 103     @Override
 104     public native void deselect(int index);
 105     @Override
 106     public native void makeVisible(int index);
 107     public native void setMultipleSelections(boolean v);
 108     public native int  getMaxWidth();















 109     // Toolkit & peer internals
 110 
 111     WListPeer(List target) {
 112         super(target);
 113     }
 114 
 115     @Override
 116     native void create(WComponentPeer parent);
 117 
 118     @Override
 119     void initialize() {
 120         List li = (List)target;
 121 
 122         fm = getFontMetrics( li.getFont() );
 123 
 124         // Fixed 6336384: setFont should be done before addItems
 125         Font  f = li.getFont();
 126         if (f != null) {
 127             setFont(f);
 128         }


< prev index next >