Changeset 6321


Ignore:
Timestamp:
2003-12-19T14:49:04+13:00 (20 years ago)
Author:
jmt12
Message:

Changed JComboBoxes for GComboBoxes to avoid Mac graphical glitch - however now I can't seem to make them the right colour

Location:
trunk/gli/src/org/greenstone/gatherer/gui
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/gli/src/org/greenstone/gatherer/gui/GComboBox.java

    r5789 r6321  
    5050    extends JComboBox {
    5151
     52    private boolean editable = true;
     53
    5254    private Color background = null;
    5355    private Color foreground = null;
     56    private Color editable_background = null;
     57    private Color editable_foreground = null;
    5458    private Color selection_background = null;
    5559    private Color selection_foreground = null;
     
    6064    }
    6165
     66    public GComboBox(boolean editable) {
     67    super();
     68    this.editable = editable;
     69    super.setEditable(editable);
     70    init();
     71    }
     72
    6273    public GComboBox(ArrayList data) {
    6374    super(data.toArray());
     
    6576    }
    6677
     78    public GComboBox(ArrayList data, boolean editable) {
     79    super(data.toArray());
     80    this.editable = editable;
     81    super.setEditable(editable);
     82    init();
     83    }
     84
    6785    public GComboBox(ComboBoxModel model) {
    6886    super(model);
     87    init();
     88    }
     89
     90    public GComboBox(ComboBoxModel model, boolean editable) {
     91    super(model);
     92    this.editable = editable;
     93    super.setEditable(editable);
    6994    init();
    7095    }
     
    81106    }
    82107
     108    public GComboBox(Object data[], boolean editable) {
     109    super(data);
     110    this.editable = editable;
     111    super.setEditable(editable);
     112    init();
     113    }
     114
    83115    public GComboBox(Vector data) {
    84116    super(data);
     117    init();
     118    }
     119
     120    public GComboBox(Vector data, boolean editable) {
     121    super(data);
     122    this.editable = editable;
     123    super.setEditable(editable);
    85124    init();
    86125    }
     
    109148    }
    110149
     150    /** Overridden to do nothing.
     151     * @param background
     152     */
     153    public void setBackground(Color background) {
     154    }
     155
     156    public void setBackgroundEditableColor(Color editable_background) {
     157    this.editable_background = editable_background;
     158    setEditor(new Editor());
     159    setRenderer(new Renderer());
     160    }
     161
    111162    public void setBackgroundNonSelectionColor(Color background) {
    112163    this.background = background;
     
    115166    }
    116167
     168    public void setBackgroundSelectionColor(Color selection_background) {
     169    this.selection_background = selection_background;
     170    setEditor(new Editor());
     171    setRenderer(new Renderer());
     172    }
     173
     174    public void setEditable(boolean editable) {
     175    super.setEditable(editable);
     176    this.editable = editable;
     177    setEditor(new Editor());
     178    setRenderer(new Renderer());
     179    }
     180
     181    public void setTextEditableColor(Color editable_foreground) {
     182    this.editable_foreground = editable_foreground;
     183    setEditor(new Editor());
     184    setRenderer(new Renderer());
     185    }
     186
    117187    public void setTextNonSelectionColor(Color foreground) {
    118188    this.foreground = foreground;
    119     setEditor(new Editor());
    120     setRenderer(new Renderer());
    121     }
    122 
    123     public void setBackgroundSelectionColor(Color selection_background) {
    124     this.selection_background = selection_background;
    125189    setEditor(new Editor());
    126190    setRenderer(new Renderer());
     
    148212    this.background = Gatherer.config.getColor("coloring.collection_tree_background", false);
    149213    this.foreground = Gatherer.config.getColor("coloring.collection_tree_foreground", false);
     214    this.editable_background = Gatherer.config.getColor("coloring.editable_background", false);
     215    this.editable_foreground = Gatherer.config.getColor("coloring.editable_foreground", false);
    150216    this.selection_background = Gatherer.config.getColor("coloring.collection_selection_background", false);
    151217    this.selection_foreground = Gatherer.config.getColor("coloring.collection_selection_foreground", false);
    152     setEditor(new Editor());
     218    if(editable) {
     219        this.setBackground(editable_background);
     220        this.setForeground(editable_foreground);
     221    }
     222    else {
     223        this.setBackground(background);
     224        this.setForeground(foreground);
     225    }
     226    setBorder(BorderFactory.createLoweredBevelBorder());
     227    setEditor(new Editor());
     228    setOpaque(true);
    153229    setRenderer(new Renderer());
    154230    }
     
    158234    implements ComboBoxEditor {
    159235    public Editor() {
    160         setBackground(background);
    161         setForeground(foreground);
    162         setSelectionColor(selection_background);
    163         setSelectedTextColor(selection_foreground);
     236        setBackground(editable_background);
     237        setForeground(editable_foreground);
     238        setOpaque(true);
     239        if(editable) {
     240        setSelectionColor(selection_background);
     241        setSelectedTextColor(selection_foreground);
     242        }
    164243    }
    165244
     
    221300    implements ListCellRenderer {
    222301    public Renderer() {
     302        super("");
     303        this.setBackground(background);
     304        this.setForeground(foreground);
     305        this.setOpaque(true);
    223306    }
    224307    public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
    225308        if(value != null) {
    226         setText(value.toString());
     309        this.setText(value.toString());
    227310        }
    228311        else {
    229         setText("");
    230         }
    231         setBackground(isSelected ? selection_background : background);
    232         setForeground(isSelected ? selection_foreground : foreground);
    233         setOpaque(true);
     312        this.setText("");
     313        }
     314        if(editable) {
     315        this.setBackground(editable_background);
     316        this.setForeground(editable_foreground);
     317        }
     318        else {
     319        this.setBackground(background);
     320        this.setForeground(foreground);
     321        }
    234322        return this;
    235323    }
  • trunk/gli/src/org/greenstone/gatherer/gui/OptionsPane.java

    r6087 r6321  
    6262public class OptionsPane
    6363    extends JPanel
    64     implements AppendLineOnlyFileDocumentOwner {
     64    implements AppendLineOnlyFileDocumentOwner, MouseListener {
    6565
    6666    static final public char SUCCESSFUL = 's';
     
    7272    public JTextArea log_textarea = null;
    7373
     74    private ArrayList current_controls;
     75
    7476    /** The <strong>BuildOptions</strong> data object contains all the option settings we wish to persist between Gatherer sessions (and thus is stored in <strong>Collection</strong>). */
    7577    private BuildOptions build_options = null;
    7678
    7779    private FileEntry file_entry = null;
     80
    7881    /** the log pane - we only create it once now, not each time */
    7982    private JPanel log_pane = null;
     
    9396    public OptionsPane(BuildOptions build_options) {
    9497    this.build_options = build_options;
     98    this.current_controls = new ArrayList();
    9599    this.writing_documents = new Vector();
    96100
     
    104108     */
    105109    public JPanel buildBuild() {
     110    current_controls.clear();
    106111    JPanel pane = new JPanel();
    107112    pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
     
    117122        ArgumentControl argument_control = new ArgumentControl(BUILD, argument, enabled, value);
    118123        pane.add(argument_control);
    119     }
     124        current_controls.add(argument_control);
     125    }
     126    pane.addMouseListener(this);
    120127    return pane;
    121128    }
     
    124131     */
    125132    public JPanel buildImport() {
     133    current_controls.clear();
    126134    JPanel pane = new JPanel();
    127135    pane.setBackground(Gatherer.config.getColor("coloring.collection_tree_background", false));
     
    137145        ArgumentControl argument_control = new ArgumentControl(IMPORT, argument, enabled, value);
    138146        pane.add(argument_control);
    139     }
     147        current_controls.add(argument_control);
     148    }
     149    pane.addMouseListener(this);
    140150    return pane;
    141151    }
     
    153163        File children[] = log_directory.listFiles();
    154164        for(int i = 0; children != null && i < children.length; i++) {
    155         if(children[i].getName().startsWith("build_log") && children[i].getName().endsWith(".txt") ) {
    156             FileEntry entry = new FileEntry(children[i].getName(), children[i].getAbsolutePath());
    157             // We are about to insert it. But where.
    158             boolean found = false;
    159             for(int j = 0; !found && j < contents.size(); j++) {
    160             FileEntry sibling = (FileEntry) contents.getElementAt(j);
    161             int order = entry.compareTo(sibling);
    162             if(order > 0) {
    163                 contents.insertElementAt(entry, j);
    164                 found = true;
     165        String filename = children[i].getName();
     166        if(filename.startsWith("build_log.") && filename.endsWith(".txt") ) {
     167            String datestamp = filename.substring(filename.indexOf(".") + 1, filename.lastIndexOf(".")).toLowerCase();
     168            if(datestamp.indexOf("s") == -1 && datestamp.indexOf("u") == -1 && datestamp.indexOf("c") == -1 && datestamp.indexOf("x") == -1) {
     169            FileEntry entry = new FileEntry(children[i].getName(), children[i].getAbsolutePath());
     170            // We are about to insert it. But where.
     171            boolean found = false;
     172            for(int j = 0; !found && j < contents.size(); j++) {
     173                FileEntry sibling = (FileEntry) contents.getElementAt(j);
     174                int order = entry.compareTo(sibling);
     175                if(order > 0) {
     176                contents.insertElementAt(entry, j);
     177                found = true;
     178                }
    165179            }
    166             }
    167             if(!found) {
    168             contents.addElement(entry);
     180            if(!found) {
     181                contents.addElement(entry);
     182            }
    169183            }
    170184        }
     
    250264    }
    251265
     266    /** Implementation side-effect
     267     * @param e a MouseEvent
     268     */
     269    public void mouseClicked(MouseEvent e) {}
     270
     271    /** Implementation side-effect
     272     * @param e a MouseEvent
     273     */
     274    public void mouseEntered(MouseEvent e) {}
     275
     276    /** Implemented to ensure that, by the time the mouse pointer leaves the current build options screen, ang changes to the value the JSpinners have been commited
     277     * @param e a MouseEvent
     278     */
     279    public void mouseExited(MouseEvent e) {
     280    // Loop through the controls, and if the current control is a JSpinner, commit its current editing
     281    for(int i = 0; i < current_controls.size(); i++) {
     282        ArgumentControl control = (ArgumentControl) current_controls.get(i);
     283        JComponent value_control = control.getValueControl();
     284        if(value_control instanceof JSpinner) {
     285        try {
     286            ((JSpinner)value_control).commitEdit();
     287        }
     288        catch(Exception exception) {
     289            Gatherer.println("Exception in OptionsPane.mouseExited() - unexpected");
     290            Gatherer.printStackTrace(exception);
     291        }
     292        }
     293        value_control = null;
     294        control = null;
     295    }
     296    }
     297
     298    /** Implementation side-effect
     299     * @param e a MouseEvent
     300     */
     301    public void mousePressed(MouseEvent e) {}
     302
     303    /** Implementation side-effect
     304     * @param e a MouseEvent
     305     */
     306    public void mouseReleased(MouseEvent e) {}
     307
    252308    private class ArgumentControl
    253309    extends JPanel {
     
    389445        add(enabled, BorderLayout.WEST);
    390446        }
     447    }
     448
     449    /** Retrieve the control used for storing values.
     450     * @return JComponent
     451     */
     452    public JComponent getValueControl() {
     453        return value_control;
    391454    }
    392455
Note: See TracChangeset for help on using the changeset viewer.