use of com.ramussoft.core.attribute.simple.CurrencyPropertyPersistent in project ramus by Vitaliy-Yakovchuk.
the class CurrencyAttributePlugin method getTableCellRenderer.
@Override
public TableCellRenderer getTableCellRenderer(Engine engine, AccessRules rules, Attribute attribute) {
CurrencyPropertyPersistent p = null;
if (attribute.getId() >= 0)
p = (CurrencyPropertyPersistent) engine.getAttribute(null, attribute);
if ((p != null) && (p.getCode() != null)) {
final DecimalFormat format;
if ((p.getCode().equals("UAH")) && (Locale.getDefault().getLanguage().equals("uk")))
format = new DecimalFormat("###,###.## \u0433\u0440\u043d\'.\'");
else {
Currency currency = Currency.getInstance(p.getCode());
String s;
if (p.getCode().equals("EUR"))
s = currency.getSymbol(Locale.UK);
else if (p.getCode().equals("USD"))
s = currency.getSymbol(Locale.US);
else
s = currency.getSymbol();
StringBuffer sb = new StringBuffer();
for (int i = 0; i < s.length(); i++) {
char c = s.charAt(i);
if (c == '.')
sb.append("\'.\'");
else if (c == ',')
sb.append("\',\'");
else if (c == '#')
sb.append("\'#\'");
else
sb.append(c);
}
s = sb.toString();
String b = "###,###";
String e = ".##";
int digits = currency.getDefaultFractionDigits();
if (digits > 0) {
e = ".";
while (digits > 0) {
digits--;
e += "#";
}
} else
e = "";
if (s.length() == 1)
format = new DecimalFormat(s + " " + b + e);
else
format = new DecimalFormat(b + e + " " + s);
}
if (Locale.getDefault().getLanguage().equals("uk")) {
format.setDecimalSeparatorAlwaysShown(false);
DecimalFormatSymbols newSymbols = new DecimalFormatSymbols();
newSymbols.setGroupingSeparator(' ');
newSymbols.setDecimalSeparator(',');
format.setDecimalFormatSymbols(newSymbols);
}
return new DefaultTableCellRenderer() {
/**
*/
private static final long serialVersionUID = -7922052040779840252L;
{
setHorizontalAlignment(SwingConstants.RIGHT);
}
@Override
public Component getTableCellRendererComponent(JTable table, Object value, boolean isSelected, boolean hasFocus, int row, int column) {
Component component = super.getTableCellRendererComponent(table, value, isSelected, hasFocus, row, column);
if (value != null)
((JLabel) component).setText(format.format(value));
return component;
}
};
}
return super.getTableCellRenderer(engine, rules, attribute);
}
use of com.ramussoft.core.attribute.simple.CurrencyPropertyPersistent in project ramus by Vitaliy-Yakovchuk.
the class CurrencyAttributePlugin method getAttributePreferenciesEditor.
@Override
public AttributePreferenciesEditor getAttributePreferenciesEditor() {
return new AttributePreferenciesEditor() {
private JComboBox comboBox = new JComboBox();
@Override
public JComponent createComponent(Attribute attribute, Engine engine, AccessRules accessRules) {
CurrencyPropertyPersistent p = null;
if (attribute != null)
p = (CurrencyPropertyPersistent) engine.getAttribute(null, attribute);
comboBox.addItem(GlobalResourcesManager.getString("ByDefault"));
int i = 1;
int index = 0;
for (Currency currency : getCurrencies()) {
comboBox.addItem(currency);
if ((p != null) && (p.getCode() != null) && (p.getCode().equals(currency.getCurrencyCode())))
index = i;
i++;
}
comboBox.setSelectedIndex(index);
double[][] size = { { 5, TableLayout.MINIMUM, 5, TableLayout.FILL, 5 }, { 5, TableLayout.MINIMUM, 5 } };
TableLayout layout = new TableLayout(size);
JPanel panel = new JPanel(layout);
panel.add(new JLabel(GlobalResourcesManager.getString("Attribute.CurrencyCode")), "1,1");
panel.add(comboBox, "3,1");
return panel;
}
@Override
public boolean canApply() {
return true;
}
@Override
public void apply(Attribute attribute, Engine engine, AccessRules accessRules) {
if (comboBox.getSelectedIndex() == 0) {
engine.setAttribute(null, attribute, null);
} else {
CurrencyPropertyPersistent p = new CurrencyPropertyPersistent();
p.setCode(((Currency) comboBox.getSelectedItem()).getCurrencyCode());
engine.setAttribute(null, attribute, p);
}
}
};
}
Aggregations