mirror of
https://github.com/geometer/FBReaderJ.git
synced 2025-10-04 02:09:35 +02:00
git-svn-id: https://only.mawhrin.net/repos/FBReaderJ/trunk@798 6a642e6f-84f6-412e-ac94-c4a38d5a04b0
This commit is contained in:
parent
43495c888a
commit
4675cefc4c
9 changed files with 707 additions and 16 deletions
|
@ -0,0 +1,576 @@
|
||||||
|
package org.zlibrary.ui.swing.dialogs;
|
||||||
|
|
||||||
|
import java.awt.Component;
|
||||||
|
import java.awt.Graphics;
|
||||||
|
import java.awt.GridBagLayout;
|
||||||
|
import java.awt.event.ActionEvent;
|
||||||
|
import java.awt.event.ActionListener;
|
||||||
|
import java.awt.event.ItemListener;
|
||||||
|
import java.awt.event.MouseAdapter;
|
||||||
|
import java.awt.event.MouseEvent;
|
||||||
|
import java.awt.event.MouseListener;
|
||||||
|
import java.io.Serializable;
|
||||||
|
|
||||||
|
import javax.swing.AbstractAction;
|
||||||
|
import javax.swing.ActionMap;
|
||||||
|
import javax.swing.ButtonGroup;
|
||||||
|
import javax.swing.ButtonModel;
|
||||||
|
import javax.swing.Icon;
|
||||||
|
import javax.swing.JCheckBox;
|
||||||
|
import javax.swing.SwingUtilities;
|
||||||
|
import javax.swing.event.ChangeEvent;
|
||||||
|
import javax.swing.event.ChangeListener;
|
||||||
|
import javax.swing.plaf.ActionMapUIResource;
|
||||||
|
import javax.swing.plaf.UIResource;
|
||||||
|
import javax.swing.plaf.metal.MetalLookAndFeel;
|
||||||
|
|
||||||
|
import org.zlibrary.core.dialogs.ZLBoolean3OptionEntry;
|
||||||
|
import org.zlibrary.core.util.ZLBoolean3;
|
||||||
|
|
||||||
|
public class ZLBoolean3OptionView extends ZLSwingOptionView {
|
||||||
|
private TristateCheckBox myTristateCheckBox;
|
||||||
|
|
||||||
|
public ZLBoolean3OptionView(String name, ZLBoolean3OptionEntry option, ZLSwingDialogContent tab, GridBagLayout layout) {
|
||||||
|
super(name, option, tab, layout);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void _onAccept() {
|
||||||
|
((ZLBoolean3OptionEntry) myOption).onAccept(stateToInt(myTristateCheckBox.getState()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void _setActive(boolean active) {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
myTristateCheckBox.setEnabled(active);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void createItem() {
|
||||||
|
myTristateCheckBox = new TristateCheckBox(myName, intToState(((ZLBoolean3OptionEntry) myOption).initialState()));
|
||||||
|
myTab.insertWidget(myTristateCheckBox);
|
||||||
|
myTristateCheckBox.addChangeListener(new ChangeListener() {
|
||||||
|
public void stateChanged(ChangeEvent e) {
|
||||||
|
((ZLBoolean3OptionEntry) myOption).onStateChanged(stateToInt(myTristateCheckBox.getState()));
|
||||||
|
}});
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void hide() {
|
||||||
|
hide(myTristateCheckBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void show() {
|
||||||
|
show(myTristateCheckBox);
|
||||||
|
}
|
||||||
|
|
||||||
|
private static int stateToInt(TristateCheckBox.State state) {
|
||||||
|
if (state == TristateCheckBox.NOT_SELECTED) {
|
||||||
|
return ZLBoolean3.B3_FALSE;
|
||||||
|
}
|
||||||
|
if (state == TristateCheckBox.SELECTED) {
|
||||||
|
return ZLBoolean3.B3_TRUE;
|
||||||
|
}
|
||||||
|
return ZLBoolean3.B3_UNDEFINED;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static TristateCheckBox.State intToState(int state) {
|
||||||
|
switch (state) {
|
||||||
|
case ZLBoolean3.B3_TRUE:
|
||||||
|
return TristateCheckBox.SELECTED;
|
||||||
|
case ZLBoolean3.B3_FALSE:
|
||||||
|
return TristateCheckBox.NOT_SELECTED;
|
||||||
|
default:
|
||||||
|
return TristateCheckBox.DONT_CARE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static class TristateCheckBox extends JCheckBox {
|
||||||
|
public static class State {
|
||||||
|
private String desc = "";
|
||||||
|
|
||||||
|
private State() {
|
||||||
|
}
|
||||||
|
|
||||||
|
private State(String desc) {
|
||||||
|
this.desc = desc;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String toString() {
|
||||||
|
return desc;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public static final State NOT_SELECTED = new State("NOT_SELECTED");
|
||||||
|
public static final State SELECTED = new State("SELECTED");
|
||||||
|
public static final State DONT_CARE = new State("DONT_CARE");
|
||||||
|
|
||||||
|
private final TristateModel model;
|
||||||
|
|
||||||
|
public TristateCheckBox(String text, State initial) {
|
||||||
|
super(text);
|
||||||
|
|
||||||
|
Icon icon = new TristateCheckBoxIcon();
|
||||||
|
super.setIcon(icon);
|
||||||
|
|
||||||
|
// Add a listener for when the mouse is pressed and released
|
||||||
|
super.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
TristateCheckBox.this.mousePressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void mouseReleased(MouseEvent e) {
|
||||||
|
TristateCheckBox.this.mouseReleased();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Reset the keyboard action map
|
||||||
|
ActionMap map = new ActionMapUIResource();
|
||||||
|
map.put("pressed", new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
TristateCheckBox.this.mousePressed();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.put("released", new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
TristateCheckBox.this.mouseReleased();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
SwingUtilities.replaceUIActionMap(this, map);
|
||||||
|
// set the model to the adapted model
|
||||||
|
model = new TristateModel(getModel());
|
||||||
|
setModel(model);
|
||||||
|
setState(initial);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mousePressed() {
|
||||||
|
grabFocus();
|
||||||
|
model.setPressed(true);
|
||||||
|
model.setArmed(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void mouseReleased() {
|
||||||
|
model.nextState();
|
||||||
|
model.setArmed(false);
|
||||||
|
model.setPressed(false);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void doClick() {
|
||||||
|
mousePressed();
|
||||||
|
mouseReleased();
|
||||||
|
}
|
||||||
|
|
||||||
|
public TristateCheckBox(String text) {
|
||||||
|
this(text, NOT_SELECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
public TristateCheckBox() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** No one may add mouse listeners, not even Swing! */
|
||||||
|
public void addMouseListener(MouseListener l) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/** No one may set a new icon */
|
||||||
|
public void setIcon(Icon icon) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Set the new state to either CHECKED, CROSSED or NOT_SELECTED.
|
||||||
|
*/
|
||||||
|
public void setState(State state) {
|
||||||
|
model.setState(state);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the current state, which is determined by the selection status of
|
||||||
|
* the model.
|
||||||
|
*/
|
||||||
|
public State getState() {
|
||||||
|
return model.getState();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean selected) {
|
||||||
|
if (selected) {
|
||||||
|
setState(SELECTED);
|
||||||
|
} else {
|
||||||
|
setState(NOT_SELECTED);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TristateModel implements ButtonModel {
|
||||||
|
private final ButtonModel other;
|
||||||
|
|
||||||
|
private State currentState = NOT_SELECTED;
|
||||||
|
|
||||||
|
private TristateModel(ButtonModel other) {
|
||||||
|
this.other = other;
|
||||||
|
}
|
||||||
|
|
||||||
|
private State getState() {
|
||||||
|
return currentState;
|
||||||
|
}
|
||||||
|
|
||||||
|
private void setState(State state) {
|
||||||
|
this.currentState = state;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isSelected() {
|
||||||
|
return (currentState == SELECTED || currentState == DONT_CARE);
|
||||||
|
}
|
||||||
|
|
||||||
|
/** We rotate between NOT_SELECTED, SELECTED and DONT_CARE. */
|
||||||
|
private void nextState() {
|
||||||
|
State current = getState();
|
||||||
|
if (current == NOT_SELECTED) {
|
||||||
|
setState(SELECTED);
|
||||||
|
} else if (current == SELECTED) {
|
||||||
|
setState(DONT_CARE);
|
||||||
|
} else if (current == DONT_CARE) {
|
||||||
|
setState(NOT_SELECTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
//This is to enforce a call to the fireStateChanged method
|
||||||
|
other.setSelected(!other.isSelected());
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void setArmed(boolean b) {
|
||||||
|
other.setArmed(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* We disable focusing on the component when it is not enabled.
|
||||||
|
*/
|
||||||
|
public void setEnabled(boolean b) {
|
||||||
|
try {
|
||||||
|
setFocusable(b);
|
||||||
|
} catch (Exception ex) {
|
||||||
|
ex.printStackTrace();
|
||||||
|
}//catch
|
||||||
|
|
||||||
|
other.setEnabled(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* All these methods simply delegate to the "other" model that is being
|
||||||
|
* decorated.
|
||||||
|
*/
|
||||||
|
public boolean isArmed() {
|
||||||
|
return other.isArmed();
|
||||||
|
}
|
||||||
|
|
||||||
|
/* public boolean isSelected() { return other.isSelected(); } */
|
||||||
|
public boolean isEnabled() {
|
||||||
|
return other.isEnabled();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isPressed() {
|
||||||
|
return other.isPressed();
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isRollover() {
|
||||||
|
return other.isRollover();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setSelected(boolean b) {
|
||||||
|
other.setSelected(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPressed(boolean b) {
|
||||||
|
other.setPressed(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setRollover(boolean b) {
|
||||||
|
other.setRollover(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setMnemonic(int key) {
|
||||||
|
other.setMnemonic(key);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMnemonic() {
|
||||||
|
return other.getMnemonic();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setActionCommand(String s) {
|
||||||
|
other.setActionCommand(s);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getActionCommand() {
|
||||||
|
return other.getActionCommand();
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGroup(ButtonGroup group) {
|
||||||
|
other.setGroup(group);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addActionListener(ActionListener l) {
|
||||||
|
other.addActionListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeActionListener(ActionListener l) {
|
||||||
|
other.removeActionListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addItemListener(ItemListener l) {
|
||||||
|
other.addItemListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeItemListener(ItemListener l) {
|
||||||
|
other.removeItemListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void addChangeListener(ChangeListener l) {
|
||||||
|
other.addChangeListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void removeChangeListener(ChangeListener l) {
|
||||||
|
other.removeChangeListener(l);
|
||||||
|
}
|
||||||
|
|
||||||
|
public Object[] getSelectedObjects() {
|
||||||
|
return other.getSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TristateCheckBoxIcon implements Icon, UIResource,
|
||||||
|
Serializable {
|
||||||
|
|
||||||
|
protected int getControlSize() {
|
||||||
|
return 13;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void paintIcon(Component c, Graphics g, int x, int y) {
|
||||||
|
JCheckBox cb = (JCheckBox) c;
|
||||||
|
TristateModel model = (TristateModel) cb.getModel();
|
||||||
|
int controlSize = getControlSize();
|
||||||
|
|
||||||
|
boolean drawCheck = model.getState() == SELECTED;
|
||||||
|
boolean drawCross = model.getState() == DONT_CARE;
|
||||||
|
|
||||||
|
if (model.isEnabled()) {
|
||||||
|
if (model.isPressed() && model.isArmed()) {
|
||||||
|
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||||
|
g.fillRect(x, y, controlSize - 1, controlSize - 1);
|
||||||
|
drawPressed3DBorder(g, x, y, controlSize, controlSize);
|
||||||
|
} else {
|
||||||
|
drawFlush3DBorder(g, x, y, controlSize, controlSize);
|
||||||
|
}
|
||||||
|
g.setColor(MetalLookAndFeel.getControlInfo());
|
||||||
|
} else {
|
||||||
|
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||||
|
g.drawRect(x, y, controlSize - 1, controlSize - 1);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawCross) {
|
||||||
|
drawCross(c, g, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (drawCheck) {
|
||||||
|
if (cb.isBorderPaintedFlat()) {
|
||||||
|
x++;
|
||||||
|
}
|
||||||
|
drawCheck(c, g, x, y);
|
||||||
|
}
|
||||||
|
|
||||||
|
}// paintIcon
|
||||||
|
|
||||||
|
protected void drawCross(Component c, Graphics g, int x, int y) {
|
||||||
|
int controlSize = getControlSize();
|
||||||
|
g.drawLine(x + (controlSize - 4), y + 2, x + 3, y
|
||||||
|
+ (controlSize - 5));
|
||||||
|
g.drawLine(x + (controlSize - 4), y + 3, x + 3, y
|
||||||
|
+ (controlSize - 4));
|
||||||
|
g.drawLine(x + 3, y + 2, x + (controlSize - 4), y
|
||||||
|
+ (controlSize - 5));
|
||||||
|
g.drawLine(x + 3, y + 3, x + (controlSize - 4), y
|
||||||
|
+ (controlSize - 4));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void drawCheck(Component c, Graphics g, int x, int y) {
|
||||||
|
int controlSize = getControlSize();
|
||||||
|
g.fillRect(x + 3, y + 5, 2, controlSize - 8);
|
||||||
|
g.drawLine(x + (controlSize - 4), y + 3, x + 5, y
|
||||||
|
+ (controlSize - 6));
|
||||||
|
g.drawLine(x + (controlSize - 4), y + 4, x + 5, y
|
||||||
|
+ (controlSize - 5));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawFlush3DBorder(Graphics g, int x, int y, int w, int h) {
|
||||||
|
g.translate(x, y);
|
||||||
|
g.setColor(MetalLookAndFeel.getControlDarkShadow());
|
||||||
|
g.drawRect(0, 0, w - 2, h - 2);
|
||||||
|
g.setColor(MetalLookAndFeel.getControlHighlight());
|
||||||
|
g.drawRect(1, 1, w - 2, h - 2);
|
||||||
|
g.setColor(MetalLookAndFeel.getControl());
|
||||||
|
g.drawLine(0, h - 1, 1, h - 2);
|
||||||
|
g.drawLine(w - 1, 0, w - 2, 1);
|
||||||
|
g.translate(-x, -y);
|
||||||
|
}
|
||||||
|
|
||||||
|
private void drawPressed3DBorder(Graphics g, int x, int y, int w, int h) {
|
||||||
|
g.translate(x, y);
|
||||||
|
drawFlush3DBorder(g, 0, 0, w, h);
|
||||||
|
g.setColor(MetalLookAndFeel.getControlShadow());
|
||||||
|
g.drawLine(1, 1, 1, h - 2);
|
||||||
|
g.drawLine(1, 1, w - 2, 1);
|
||||||
|
g.translate(-x, -y);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIconWidth() {
|
||||||
|
return getControlSize();
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getIconHeight() {
|
||||||
|
return getControlSize();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
private static class TristateCheckBox extends JCheckBox {
|
||||||
|
private final TristateDecorator model;
|
||||||
|
|
||||||
|
public TristateCheckBox(String text, Icon icon, int initialState){
|
||||||
|
super(text, icon);
|
||||||
|
// Add a listener for when the mouse is pressed
|
||||||
|
super.addMouseListener(new MouseAdapter() {
|
||||||
|
public void mousePressed(MouseEvent e) {
|
||||||
|
grabFocus();
|
||||||
|
model.nextState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
// Reset the keyboard action map
|
||||||
|
ActionMap map = new ActionMapUIResource();
|
||||||
|
map.put("pressed", new AbstractAction() {
|
||||||
|
public void actionPerformed(ActionEvent e) {
|
||||||
|
grabFocus();
|
||||||
|
model.nextState();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
map.put("released", null);
|
||||||
|
SwingUtilities.replaceUIActionMap(this, map);
|
||||||
|
// set the model to the adapted model
|
||||||
|
model = new TristateDecorator(getModel());
|
||||||
|
setModel(model);
|
||||||
|
setState(initialState);
|
||||||
|
}
|
||||||
|
public TristateCheckBox(String text, int initialState) {
|
||||||
|
this(text, null, initialState);
|
||||||
|
}
|
||||||
|
public TristateCheckBox(String text) {
|
||||||
|
this(text, ZLBoolean3.B3_UNDEFINED);
|
||||||
|
}
|
||||||
|
public TristateCheckBox() {
|
||||||
|
this(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
public void addMouseListener(MouseListener l) { }
|
||||||
|
|
||||||
|
public void setState(int state) { model.setState(state); }
|
||||||
|
|
||||||
|
public int getState() { return model.getState(); }
|
||||||
|
public void setSelected(boolean b) {
|
||||||
|
if (b) {
|
||||||
|
setState(ZLBoolean3.B3_TRUE);
|
||||||
|
} else {
|
||||||
|
setState(ZLBoolean3.B3_FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private class TristateDecorator implements ButtonModel {
|
||||||
|
private final ButtonModel other;
|
||||||
|
private TristateDecorator(ButtonModel other) {
|
||||||
|
this.other = other;
|
||||||
|
}
|
||||||
|
private void setState(int state) {
|
||||||
|
if (state == ZLBoolean3.B3_FALSE) {
|
||||||
|
other.setArmed(false);
|
||||||
|
setPressed(false);
|
||||||
|
setSelected(false);
|
||||||
|
} else if (state == ZLBoolean3.B3_TRUE) {
|
||||||
|
other.setArmed(false);
|
||||||
|
setPressed(false);
|
||||||
|
setSelected(true);
|
||||||
|
} else {
|
||||||
|
other.setArmed(true);
|
||||||
|
setPressed(true);
|
||||||
|
setSelected(true);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getState() {
|
||||||
|
if (isSelected() && !isArmed()) {
|
||||||
|
|
||||||
|
return ZLBoolean3.B3_TRUE;
|
||||||
|
} else if (isSelected() && isArmed()) {
|
||||||
|
|
||||||
|
return ZLBoolean3.B3_UNDEFINED;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
return ZLBoolean3.B3_FALSE;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void nextState() {
|
||||||
|
int current = getState();
|
||||||
|
if (current == ZLBoolean3.B3_FALSE) {
|
||||||
|
setState(ZLBoolean3.B3_TRUE);
|
||||||
|
} else if (current == ZLBoolean3.B3_TRUE) {
|
||||||
|
setState(ZLBoolean3.B3_UNDEFINED);
|
||||||
|
} else if (current == ZLBoolean3.B3_UNDEFINED) {
|
||||||
|
setState(ZLBoolean3.B3_FALSE);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setArmed(boolean b) {
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEnabled(boolean b) {
|
||||||
|
setFocusable(b);
|
||||||
|
other.setEnabled(b);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isArmed() { return other.isArmed(); }
|
||||||
|
public boolean isSelected() { return other.isSelected(); }
|
||||||
|
public boolean isEnabled() { return other.isEnabled(); }
|
||||||
|
public boolean isPressed() { return other.isPressed(); }
|
||||||
|
public boolean isRollover() { return other.isRollover(); }
|
||||||
|
public void setSelected(boolean b) { other.setSelected(b); }
|
||||||
|
public void setPressed(boolean b) { other.setPressed(b); }
|
||||||
|
public void setRollover(boolean b) { other.setRollover(b); }
|
||||||
|
public void setMnemonic(int key) { other.setMnemonic(key); }
|
||||||
|
public int getMnemonic() { return other.getMnemonic(); }
|
||||||
|
public void setActionCommand(String s) {
|
||||||
|
other.setActionCommand(s);
|
||||||
|
}
|
||||||
|
public String getActionCommand() {
|
||||||
|
return other.getActionCommand();
|
||||||
|
}
|
||||||
|
public void setGroup(ButtonGroup group) {
|
||||||
|
other.setGroup(group);
|
||||||
|
}
|
||||||
|
public void addActionListener(ActionListener l) {
|
||||||
|
other.addActionListener(l);
|
||||||
|
}
|
||||||
|
public void removeActionListener(ActionListener l) {
|
||||||
|
other.removeActionListener(l);
|
||||||
|
}
|
||||||
|
public void addItemListener(ItemListener l) {
|
||||||
|
other.addItemListener(l);
|
||||||
|
}
|
||||||
|
public void removeItemListener(ItemListener l) {
|
||||||
|
other.removeItemListener(l);
|
||||||
|
}
|
||||||
|
public void addChangeListener(ChangeListener l) {
|
||||||
|
other.addChangeListener(l);
|
||||||
|
}
|
||||||
|
public void removeChangeListener(ChangeListener l) {
|
||||||
|
other.removeChangeListener(l);
|
||||||
|
}
|
||||||
|
public Object[] getSelectedObjects() {
|
||||||
|
return other.getSelectedObjects();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
}
|
|
@ -34,8 +34,8 @@ public class ZLComboOptionView extends ZLSwingOptionView {
|
||||||
|
|
||||||
protected void createItem() {
|
protected void createItem() {
|
||||||
final ZLComboOptionEntry option = (ZLComboOptionEntry) myOption;
|
final ZLComboOptionEntry option = (ZLComboOptionEntry) myOption;
|
||||||
final ArrayList values = (option).getValues();
|
final ArrayList values = option.getValues();
|
||||||
final String initialValue = (option).initialValue();
|
final String initialValue = option.initialValue();
|
||||||
int index = 0;
|
int index = 0;
|
||||||
for (int i = 0; i < values.size(); ++i) {
|
for (int i = 0; i < values.size(); ++i) {
|
||||||
if (values.get(i).equals(initialValue)) {
|
if (values.get(i).equals(initialValue)) {
|
||||||
|
|
|
@ -68,7 +68,7 @@ public class ZLSwingDialogContent extends ZLDialogContent {
|
||||||
view = new ZLBooleanOptionView(name, (ZLBooleanOptionEntry) option, this, myLayout);
|
view = new ZLBooleanOptionView(name, (ZLBooleanOptionEntry) option, this, myLayout);
|
||||||
break;
|
break;
|
||||||
case ZLOptionKind.BOOLEAN3:
|
case ZLOptionKind.BOOLEAN3:
|
||||||
// view = new Boolean3OptionView(name, (ZLBoolean3OptionEntry*)option, *this, from, to);
|
view = new ZLBoolean3OptionView(name, (ZLBoolean3OptionEntry) option, this, myLayout);
|
||||||
break;
|
break;
|
||||||
case ZLOptionKind.STRING:
|
case ZLOptionKind.STRING:
|
||||||
view = new ZLStringOptionView(name, (ZLStringOptionEntry) option, this, myLayout);
|
view = new ZLStringOptionView(name, (ZLStringOptionEntry) option, this, myLayout);
|
||||||
|
|
|
@ -68,9 +68,9 @@ public class ZLEncodingCollection {
|
||||||
return myProviders;
|
return myProviders;
|
||||||
}
|
}
|
||||||
|
|
||||||
private ArrayList/*<ZLEncodingSet>*/ mySets;
|
private final ArrayList/*<ZLEncodingSet>*/ mySets = new ArrayList();
|
||||||
private HashMap/*<String,ZLEncodingConverterInfo>*/ myInfosByName;
|
private final HashMap/*<String,ZLEncodingConverterInfo>*/ myInfosByName = new HashMap();
|
||||||
private ArrayList/*<ZLEncodingConverterProvider>*/ myProviders;
|
private final ArrayList/*<ZLEncodingConverterProvider>*/ myProviders = new ArrayList();
|
||||||
|
|
||||||
//private ZLEncodingCollection();
|
//private ZLEncodingCollection();
|
||||||
private void init() {
|
private void init() {
|
||||||
|
|
84
src/org/fbreader/encodingOption/EncodingEntry.java
Normal file
84
src/org/fbreader/encodingOption/EncodingEntry.java
Normal file
|
@ -0,0 +1,84 @@
|
||||||
|
package org.fbreader.encodingOption;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
|
||||||
|
import org.fbreader.encoding.ZLEncodingCollection;
|
||||||
|
import org.fbreader.encoding.ZLEncodingConverterInfo;
|
||||||
|
import org.fbreader.encoding.ZLEncodingSet;
|
||||||
|
import org.zlibrary.core.options.ZLStringOption;
|
||||||
|
import org.zlibrary.core.util.*;
|
||||||
|
|
||||||
|
import org.zlibrary.core.dialogs.ZLComboOptionEntry;
|
||||||
|
|
||||||
|
public class EncodingEntry extends ZLComboOptionEntry {
|
||||||
|
private static final String AUTO = "auto";
|
||||||
|
private static ArrayList/*<String>*/ AUTO_ENCODING;
|
||||||
|
final ArrayList/*<std::string>*/ mySetNames = new ArrayList();
|
||||||
|
private final HashMap/*<String, ArrayList<String>>*/ myValues = new HashMap();
|
||||||
|
private final HashMap/*<String,String>*/ myInitialValues = new HashMap();
|
||||||
|
private final HashMap/*<String,String>*/ myValueByName = new HashMap();
|
||||||
|
private ZLStringOption myEncodingOption;
|
||||||
|
String myInitialSetName = "";
|
||||||
|
|
||||||
|
public EncodingEntry(ZLStringOption encodingOption) {
|
||||||
|
myEncodingOption = encodingOption;
|
||||||
|
final String value = myEncodingOption.getValue();
|
||||||
|
if (AUTO.equals(value)) {
|
||||||
|
myInitialSetName = value;
|
||||||
|
myInitialValues.put(value, value);
|
||||||
|
setActive(false);
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
final ArrayList/*<ZLEncodingSet>*/ sets = ZLEncodingCollection.instance().sets();
|
||||||
|
for (int i = 0; i < sets.size(); i++) {
|
||||||
|
ZLEncodingSet es = (ZLEncodingSet) sets.get(i);
|
||||||
|
final ArrayList/*<ZLEncodingConverterInfo>*/ infos = es.infos();
|
||||||
|
mySetNames.add(es.name());
|
||||||
|
ArrayList/*<String>*/ names = (ArrayList) myValues.get(es.name());
|
||||||
|
for (int j = 0; j < infos.size(); j++) {
|
||||||
|
ZLEncodingConverterInfo eci = (ZLEncodingConverterInfo) infos.get(j);
|
||||||
|
if (eci.name().equals(value)) {
|
||||||
|
myInitialSetName = es.name();
|
||||||
|
myInitialValues.put(myInitialSetName, eci.visibleName());
|
||||||
|
}
|
||||||
|
names.add(eci.visibleName());
|
||||||
|
myValueByName.put(eci.visibleName(), eci.name());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (myInitialSetName.length() == 0 && ! mySetNames.isEmpty()) {
|
||||||
|
myInitialSetName = (String) mySetNames.get(0);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList getValues() {
|
||||||
|
if (AUTO.equals(initialValue())) {
|
||||||
|
if (AUTO_ENCODING == null) {
|
||||||
|
AUTO_ENCODING = new ArrayList();
|
||||||
|
AUTO_ENCODING.add(AUTO);
|
||||||
|
}
|
||||||
|
return AUTO_ENCODING;
|
||||||
|
}
|
||||||
|
return (ArrayList) myValues.get(myInitialSetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public String initialValue() {
|
||||||
|
if (((ArrayList) myInitialValues.get(myInitialSetName)) == null) {
|
||||||
|
myInitialValues.put(myInitialSetName, ((ArrayList) myValues.get(myInitialSetName)).get(0));
|
||||||
|
}
|
||||||
|
return (String) myInitialValues.get(myInitialSetName);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAccept(String value) {
|
||||||
|
if (!AUTO.equals(initialValue())) {
|
||||||
|
myEncodingOption.setValue((String) myValueByName.get(value));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onValueSelected(int index) {
|
||||||
|
myInitialValues.put(myInitialSetName, getValues().get(index));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
29
src/org/fbreader/encodingOption/EncodingSetEntry.java
Normal file
29
src/org/fbreader/encodingOption/EncodingSetEntry.java
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
package org.fbreader.encodingOption;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
|
||||||
|
import org.zlibrary.core.dialogs.ZLComboOptionEntry;
|
||||||
|
|
||||||
|
public class EncodingSetEntry extends ZLComboOptionEntry {
|
||||||
|
private EncodingEntry myEncodingEntry;
|
||||||
|
|
||||||
|
public EncodingSetEntry(EncodingEntry encodingEntry) {
|
||||||
|
myEncodingEntry = encodingEntry;
|
||||||
|
}
|
||||||
|
|
||||||
|
public ArrayList getValues() {
|
||||||
|
return myEncodingEntry.mySetNames;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String initialValue() {
|
||||||
|
return myEncodingEntry.myInitialSetName;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void onAccept(String value) {}
|
||||||
|
|
||||||
|
public void onValueSelected(int index) {
|
||||||
|
myEncodingEntry.myInitialSetName = (String) getValues().get(index);
|
||||||
|
myEncodingEntry.resetView();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -1,5 +1,7 @@
|
||||||
package org.fbreader.optionsDialog;
|
package org.fbreader.optionsDialog;
|
||||||
|
import org.fbreader.encoding.ZLEncodingCollection;
|
||||||
|
import org.fbreader.encodingOption.EncodingEntry;
|
||||||
|
import org.fbreader.encodingOption.EncodingSetEntry;
|
||||||
import org.fbreader.fbreader.*;
|
import org.fbreader.fbreader.*;
|
||||||
import org.fbreader.formats.FormatPlugin.PluginCollection;
|
import org.fbreader.formats.FormatPlugin.PluginCollection;
|
||||||
import org.zlibrary.core.dialogs.*;
|
import org.zlibrary.core.dialogs.*;
|
||||||
|
@ -24,7 +26,6 @@ public class OptionsDialog {
|
||||||
libraryTab.addOption("lookInSubdirectories", collectionView.getCollection().ScanSubdirsOption);
|
libraryTab.addOption("lookInSubdirectories", collectionView.getCollection().ScanSubdirsOption);
|
||||||
RecentBooksView recentBooksView = (RecentBooksView) fbreader.getRecentBooksView();
|
RecentBooksView recentBooksView = (RecentBooksView) fbreader.getRecentBooksView();
|
||||||
libraryTab.addOption("recentListSize", new ZLSimpleSpinOptionEntry(recentBooksView.lastBooks().MaxListSizeOption, 1));
|
libraryTab.addOption("recentListSize", new ZLSimpleSpinOptionEntry(recentBooksView.lastBooks().MaxListSizeOption, 1));
|
||||||
|
|
||||||
ZLToggleBooleanOptionEntry showTagsEntry = new ZLToggleBooleanOptionEntry(collectionView.ShowTagsOption);
|
ZLToggleBooleanOptionEntry showTagsEntry = new ZLToggleBooleanOptionEntry(collectionView.ShowTagsOption);
|
||||||
ZLOptionEntry showAllBooksTagEntry = new ZLSimpleBooleanOptionEntry(collectionView.ShowAllBooksTagOption);
|
ZLOptionEntry showAllBooksTagEntry = new ZLSimpleBooleanOptionEntry(collectionView.ShowAllBooksTagOption);
|
||||||
showTagsEntry.addDependentEntry(showAllBooksTagEntry);
|
showTagsEntry.addDependentEntry(showAllBooksTagEntry);
|
||||||
|
@ -34,13 +35,15 @@ public class OptionsDialog {
|
||||||
|
|
||||||
ZLDialogContent encodingTab = myDialog.createTab("Language");
|
ZLDialogContent encodingTab = myDialog.createTab("Language");
|
||||||
encodingTab.addOption("autoDetect", new ZLSimpleBooleanOptionEntry(PluginCollection.instance().LanguageAutoDetectOption));
|
encodingTab.addOption("autoDetect", new ZLSimpleBooleanOptionEntry(PluginCollection.instance().LanguageAutoDetectOption));
|
||||||
new ZLLanguageOptionEntry(PluginCollection.instance().DefaultLanguageOption, ZLLanguageList.languageCodes());
|
|
||||||
encodingTab.addOption("defaultLanguage", new ZLLanguageOptionEntry(PluginCollection.instance().DefaultLanguageOption, ZLLanguageList.languageCodes()));
|
encodingTab.addOption("defaultLanguage", new ZLLanguageOptionEntry(PluginCollection.instance().DefaultLanguageOption, ZLLanguageList.languageCodes()));
|
||||||
|
EncodingEntry encodingEntry = new EncodingEntry(PluginCollection.instance().DefaultEncodingOption);
|
||||||
|
EncodingSetEntry encodingSetEntry = new EncodingSetEntry(encodingEntry);
|
||||||
|
// encodingTab.addOption("defaultEncodingSet", encodingSetEntry);
|
||||||
|
// encodingTab.addOption("defaultEncoding", encodingEntry);
|
||||||
|
encodingTab.addOption("useWindows1252Hack", new ZLSimpleBooleanOptionEntry(ZLEncodingCollection.useWindows1252HackOption()));
|
||||||
|
|
||||||
// myDialog.createTab("Scrolling");
|
|
||||||
new ScrollingOptionsPage(myDialog.createTab("Scrolling"), fbreader);
|
new ScrollingOptionsPage(myDialog.createTab("Scrolling"), fbreader);
|
||||||
|
|
||||||
|
|
||||||
ZLDialogContent selectionTab = myDialog.createTab("Selection");
|
ZLDialogContent selectionTab = myDialog.createTab("Selection");
|
||||||
selectionTab.addOption("enableSelection", FBView.selectionOption());
|
selectionTab.addOption("enableSelection", FBView.selectionOption());
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package org.zlibrary.core.dialogs;
|
package org.zlibrary.core.dialogs;
|
||||||
|
|
||||||
import org.zlibrary.core.util.ZLBoolean3;
|
|
||||||
|
|
||||||
public abstract class ZLBoolean3OptionEntry extends ZLOptionEntry {
|
public abstract class ZLBoolean3OptionEntry extends ZLOptionEntry {
|
||||||
protected ZLBoolean3OptionEntry() {
|
protected ZLBoolean3OptionEntry() {
|
||||||
}
|
}
|
||||||
|
@ -10,7 +8,7 @@ public abstract class ZLBoolean3OptionEntry extends ZLOptionEntry {
|
||||||
return ZLOptionKind.BOOLEAN3;
|
return ZLOptionKind.BOOLEAN3;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void onStateChanged(ZLBoolean3 state) {
|
public void onStateChanged(int state) {
|
||||||
}
|
}
|
||||||
|
|
||||||
public abstract int initialState();
|
public abstract int initialState();
|
||||||
|
|
|
@ -19,4 +19,5 @@ public class ZLSimpleBoolean3OptionEntry extends ZLBoolean3OptionEntry {
|
||||||
public void onAccept(int state) {
|
public void onAccept(int state) {
|
||||||
myOption.setValue(state);
|
myOption.setValue(state);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue