// Openbravo POS is a point of sales application designed for touch screens.
// Copyright (C) 2007-2009 Openbravo, S.L.
// http://www.openbravo.com/product/pos
//
// This file is part of Openbravo POS.
//
// Openbravo POS is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Openbravo POS is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with Openbravo POS. If not, see <http://www.gnu.org/licenses/>.
package com.openbravo.pos.config;
import com.openbravo.data.user.DirtyManager;
import com.openbravo.pos.forms.AppConfig;
import com.openbravo.pos.forms.AppLocal;
import java.awt.Component;
import java.awt.Font;
import java.awt.GraphicsEnvironment;
import java.util.Map;
import javax.swing.LookAndFeel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
import javax.swing.UIManager.LookAndFeelInfo;
import javax.swing.UnsupportedLookAndFeelException;
import org.pushingpixels.substance.api.SubstanceLookAndFeel;
import org.pushingpixels.substance.api.SubstanceSkin;
import org.pushingpixels.substance.api.skin.SkinInfo;
/**
*
* @author adrianromero
* @author Andrey Svininykh <svininykh@gmail.com>
* @version NORD POS 3
*/
public class JPanelConfigGeneral extends javax.swing.JPanel implements PanelConfig {
private final DirtyManager dirty = new DirtyManager();
public JPanelConfigGeneral() {
initComponents();
jtxtMachineHostname.getDocument().addDocumentListener(dirty);
jcboLAF.addActionListener(dirty);
jcboFontFamilyName.addActionListener(dirty);
jtxtFontSize.addActionListener(dirty);
jcboMachineScreenmode.addActionListener(dirty);
jcboMachineLeftPanel.addActionListener(dirty);
jcboTicketsBag.addActionListener(dirty);
jcboLAF.addItem(new LAFInfo("System", UIManager.getSystemLookAndFeelClassName()));
// Installed skins
LookAndFeelInfo[] lafs = UIManager.getInstalledLookAndFeels();
for (LookAndFeelInfo laf : lafs) {
jcboLAF.addItem(new LAFInfo(laf.getName(), laf.getClassName()));
}
// Substance skins
// new SubstanceLookAndFeel(); // TODO: Remove in Substance 5.0. Workaround for Substance 4.3 to initialize static variables
Map<String, SkinInfo> skins = SubstanceLookAndFeel.getAllSkins();
for (SkinInfo skin : skins.values()) {
jcboLAF.addItem(new LAFInfo(skin.getDisplayName(), skin.getClassName()));
}
jcboLAF.addActionListener(new java.awt.event.ActionListener() {
@Override
public void actionPerformed(java.awt.event.ActionEvent evt) {
changeLAF();
}
});
for (String fontName : GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames()) {
jcboFontFamilyName.addItem(fontName);
}
jcboMachineScreenmode.addItem("window");
jcboMachineScreenmode.addItem("fullscreen");
jcboMachineLeftPanel.addItem("open");
jcboMachineLeftPanel.addItem("hide");
jcboTicketsBag.addItem("simple");
jcboTicketsBag.addItem("standard");
jcboTicketsBag.addItem("restaurant");
jcboTicketsBag.addItem("geomap");
}
@Override
public boolean hasChanged() {
return dirty.isDirty();
}
@Override
public Component getConfigComponent() {
return this;
}
@Override
public String getPanelConfigName() {
return AppLocal.getIntString("Label.CashMachine");
}
@Override
public void loadProperties(AppConfig config) {
jtxtMachineHostname.setText(config.getProperty("machine.hostname"));
String lafclass = config.getProperty("swing.defaultlaf");
jcboLAF.setSelectedItem(null);
for (int i = 0; i < jcboLAF.getItemCount(); i++) {
LAFInfo lafinfo = (LAFInfo) jcboLAF.getItemAt(i);
if (lafinfo.getClassName().equals(lafclass)) {
jcboLAF.setSelectedIndex(i);
break;
}
}
// jcboLAF.setSelectedItem(new LookAndFeelInfo());
Font defaultFont = UIManager.getDefaults().getFont("Label.font");
String fontName = config.getProperty("swing.font.name");
jcboFontFamilyName.setSelectedItem(fontName == null ? defaultFont.getFamily() : fontName);
String fontSize = config.getProperty("swing.font.size");
jtxtFontSize.setText(fontSize == null ? Integer.toString(defaultFont.getSize()) : fontSize);
jcboMachineScreenmode.setSelectedItem(config.getProperty("machine.screenmode"));
jcboMachineLeftPanel.setSelectedItem(config.getProperty("machine.leftpanel"));
jcboTicketsBag.setSelectedItem(config.getProperty("machine.ticketsbag"));
dirty.setDirty(false);
}
@Override
public void saveProperties(AppConfig config) {
config.setProperty("machine.hostname", jtxtMachineHostname.getText());
LAFInfo laf = (LAFInfo) jcboLAF.getSelectedItem();
config.setProperty("swing.defaultlaf", laf == null
? System.getProperty("swing.defaultlaf", "org.pushingpixels.substance.api.skin.CremeSkin")
: laf.getClassName());
config.setProperty("swing.font.name", comboValue(jcboFontFamilyName.getSelectedItem()));
config.setProperty("swing.font.size", jtxtFontSize.getText());
config.setProperty("machine.screenmode", comboValue(jcboMachineScreenmode.getSelectedItem()));
config.setProperty("machine.ticketsbag", comboValue(jcboTicketsBag.getSelectedItem()));
config.setProperty("machine.leftpanel", comboValue(jcboMachineLeftPanel.getSelectedItem()));
dirty.setDirty(false);
}
private String comboValue(Object value) {
return value == null ? "" : value.toString();
}
private void changeLAF() {
final LAFInfo laf = (LAFInfo) jcboLAF.getSelectedItem();
if (laf != null && !laf.getClassName().equals(UIManager.getLookAndFeel().getClass().getName())) {
// The selected look and feel is different from the current look and feel.
SwingUtilities.invokeLater(new Runnable() {
@Override
public void run() {
try {
String lafname = laf.getClassName();
Object laf = Class.forName(lafname).newInstance();
if (laf instanceof LookAndFeel) {
UIManager.setLookAndFeel((LookAndFeel) laf);
} else if (laf instanceof SubstanceSkin) {
SubstanceLookAndFeel.setSkin((SubstanceSkin) laf);
}
SwingUtilities.updateComponentTreeUI(JPanelConfigGeneral.this.getTopLevelAncestor());
} catch (ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e) {
}
}
});
}
}
private static class LAFInfo {
private final String name;
private final String classname;
public LAFInfo(String name, String classname) {
this.name = name;
this.classname = classname;
}
public String getName() {
return name;
}
public String getClassName() {
return classname;
}
@Override
public String toString() {
return name;
}
}
/**
* This method is called from within the constructor to initialize the form.
* WARNING: Do NOT modify this code. The content of this method is always
* regenerated by the Form Editor.
*/
// <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
private void initComponents() {
jPanel1 = new javax.swing.JPanel();
jLabel5 = new javax.swing.JLabel();
jtxtMachineHostname = new javax.swing.JTextField();
jLabel2 = new javax.swing.JLabel();
jcboLAF = new javax.swing.JComboBox();
jLabel6 = new javax.swing.JLabel();
jcboMachineScreenmode = new javax.swing.JComboBox();
jLabel16 = new javax.swing.JLabel();
jcboTicketsBag = new javax.swing.JComboBox();
jcboMachineLeftPanel = new javax.swing.JComboBox();
jLabel7 = new javax.swing.JLabel();
jcboFontFamilyName = new javax.swing.JComboBox();
jLabel3 = new javax.swing.JLabel();
jtxtFontSize = new javax.swing.JTextField();
setBorder(javax.swing.BorderFactory.createEmptyBorder(10, 5, 10, 5));
setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.LEADING));
jLabel5.setText(AppLocal.getIntString("Label.MachineName")); // NOI18N
jLabel2.setText(AppLocal.getIntString("label.looknfeel")); // NOI18N
jLabel6.setText(AppLocal.getIntString("Label.MachineScreen")); // NOI18N
jLabel16.setText(AppLocal.getIntString("Label.Ticketsbag")); // NOI18N
jLabel7.setText(AppLocal.getIntString("Label.MachineLeftPanel")); // NOI18N
jLabel3.setText(AppLocal.getIntString("label.font")); // NOI18N
javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
jPanel1.setLayout(jPanel1Layout);
jPanel1Layout.setHorizontalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jLabel5, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel16, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel6, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel7, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel2, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jLabel3, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE))
.addGap(5, 5, 5)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addComponent(jcboMachineScreenmode, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jcboTicketsBag, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jcboMachineLeftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jcboLAF, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jtxtMachineHostname, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addGroup(jPanel1Layout.createSequentialGroup()
.addComponent(jcboFontFamilyName, javax.swing.GroupLayout.PREFERRED_SIZE, 200, javax.swing.GroupLayout.PREFERRED_SIZE)
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addComponent(jtxtFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, 50, javax.swing.GroupLayout.PREFERRED_SIZE)))
.addContainerGap(42, Short.MAX_VALUE))
);
jPanel1Layout.setVerticalGroup(
jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
.addGroup(jPanel1Layout.createSequentialGroup()
.addContainerGap()
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel5)
.addComponent(jtxtMachineHostname, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel16)
.addComponent(jcboTicketsBag, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel6)
.addComponent(jcboMachineScreenmode, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel7)
.addComponent(jcboMachineLeftPanel, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel2)
.addComponent(jcboLAF, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
.addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.CENTER)
.addComponent(jLabel3)
.addComponent(jcboFontFamilyName, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
.addComponent(jtxtFontSize, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
.addContainerGap(50, Short.MAX_VALUE))
);
add(jPanel1);
}// </editor-fold>//GEN-END:initComponents
// Variables declaration - do not modify//GEN-BEGIN:variables
private javax.swing.JLabel jLabel16;
private javax.swing.JLabel jLabel2;
private javax.swing.JLabel jLabel3;
private javax.swing.JLabel jLabel5;
private javax.swing.JLabel jLabel6;
private javax.swing.JLabel jLabel7;
private javax.swing.JPanel jPanel1;
private javax.swing.JComboBox jcboFontFamilyName;
private javax.swing.JComboBox jcboLAF;
private javax.swing.JComboBox jcboMachineLeftPanel;
private javax.swing.JComboBox jcboMachineScreenmode;
private javax.swing.JComboBox jcboTicketsBag;
private javax.swing.JTextField jtxtFontSize;
private javax.swing.JTextField jtxtMachineHostname;
// End of variables declaration//GEN-END:variables
}