PageRenderTime 74ms CodeModel.GetById 57ms app.highlight 12ms RepoModel.GetById 2ms app.codeStats 0ms

/src/mpv5/ui/dialogs/subcomponents/ControlPanel_Fonts.java

http://mp-rechnungs-und-kundenverwaltung.googlecode.com/
Java | 247 lines | 192 code | 41 blank | 14 comment | 10 complexity | 609a0fb690ec890e759894487ed54e38 MD5 | raw file
  1package mpv5.ui.dialogs.subcomponents;
  2
  3import java.awt.Component;
  4import java.awt.Font;
  5import javax.swing.UIManager;
  6import mpv5.data.PropertyStore;
  7import mpv5.globals.LocalSettings;
  8import mpv5.globals.Messages;
  9import mpv5.ui.dialogs.ControlApplet;
 10import mpv5.ui.dialogs.Popup;
 11import mpv5.ui.frames.MPView;
 12
 13/**
 14 *
 15 * 
 16 */
 17public class ControlPanel_Fonts extends javax.swing.JPanel implements ControlApplet {
 18
 19    private static final long serialVersionUID = -8347532498124147821L;
 20    /**
 21     * This unique name identifies this control applet
 22     */
 23    public final String UNAME = "fonts";
 24    private PropertyStore oldvalues;
 25    private static ControlPanel_Fonts ident;
 26
 27    public ControlPanel_Fonts() {
 28        initComponents();
 29
 30        font.setText(LocalSettings.getProperty(LocalSettings.DEFAULT_FONT));
 31        jFontChooser1.setSelectedFont(Font.decode(LocalSettings.getProperty(LocalSettings.DEFAULT_FONT)));
 32
 33        validate();
 34    }
 35
 36    /**
 37     * Applies the give font
 38     * @param font
 39     */
 40    public static void applyFont(Font font) {
 41        UIManager.put("Button.font", font);
 42        UIManager.put("ToggleButton.font", font);
 43        UIManager.put("RadioButton.font", font);
 44        UIManager.put("CheckBox.font", font);
 45        UIManager.put("ColorChooser.font", font);
 46        UIManager.put("ComboBox.font", font);
 47        UIManager.put("Label.font", font);
 48        UIManager.put("List.font", font);
 49        UIManager.put("MenuBar.font", font);
 50        UIManager.put("MenuItem.font", font);
 51        UIManager.put("RadioButtonMenuItem.font", font);
 52        UIManager.put("CheckBoxMenuItem.font", font);
 53        UIManager.put("Menu.font", font);
 54        UIManager.put("PopupMenu.font", font);
 55        UIManager.put("OptionPane.font", font);
 56        UIManager.put("Panel.font", font);
 57        UIManager.put("ProgressBar.font", font);
 58        UIManager.put("ScrollPane.font", font);
 59        UIManager.put("Viewport.font", font);
 60        UIManager.put("TabbedPane.font", font);
 61        UIManager.put("Table.font", font);
 62        UIManager.put("TableHeader.font", font);
 63        UIManager.put("TextField.font", font);
 64        UIManager.put("PasswordField.font", font);
 65        UIManager.put("TextArea.font", font);
 66        UIManager.put("TextPane.font", font);
 67        UIManager.put("EditorPane.font", font);
 68        UIManager.put("TitledBorder.font", font);
 69        UIManager.put("ToolBar.font", font);
 70        UIManager.put("ToolTip.font", font);
 71        UIManager.put("Tree.font", font);
 72
 73        if (mpv5.YabsViewProxy.instance().getIdentifierFrame() != null) {
 74            mpv5.YabsViewProxy.instance().getIdentifierFrame().validate();
 75        }
 76    }
 77
 78    private String getFontString(Font font) {
 79        return font.getFontName() + " " + font.getSize();
 80    }
 81
 82    private String getFontString(String string) {
 83        return Font.decode(string).getFontName() + " " + Font.decode(string).getSize();
 84    }
 85
 86    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
 87    private void initComponents() {
 88
 89        jPanel1 = new javax.swing.JPanel();
 90        jLabel1 = new javax.swing.JLabel();
 91        font = new javax.swing.JTextField();
 92        jLabel2 = new javax.swing.JLabel();
 93        jFontChooser1 = new com.l2fprod.common.swing.JFontChooser();
 94        jPanel6 = new javax.swing.JPanel();
 95        jButton2 = new javax.swing.JButton();
 96        jButton1 = new javax.swing.JButton();
 97
 98        setBackground(new java.awt.Color(255, 255, 255));
 99        setName("Form"); // NOI18N
100        setLayout(new java.awt.BorderLayout());
101
102        jPanel1.setBackground(new java.awt.Color(255, 255, 255));
103        java.util.ResourceBundle bundle = mpv5.i18n.LanguageManager.getBundle(); // NOI18N
104        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(bundle.getString("ControlPanel_Fonts.jPanel1.border.title"))); // NOI18N
105        jPanel1.setName("jPanel1"); // NOI18N
106
107        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11));
108        jLabel1.setText(bundle.getString("ControlPanel_Fonts.jLabel1.text")); // NOI18N
109        jLabel1.setName("jLabel1"); // NOI18N
110
111        font.setText(bundle.getString("ControlPanel_Fonts.font.text")); // NOI18N
112        font.setName("font"); // NOI18N
113
114        jLabel2.setText(bundle.getString("ControlPanel_Fonts.jLabel2.text")); // NOI18N
115        jLabel2.setName("jLabel2"); // NOI18N
116
117        jFontChooser1.setBorder(javax.swing.BorderFactory.createCompoundBorder(javax.swing.BorderFactory.createEtchedBorder(), javax.swing.BorderFactory.createEmptyBorder(2, 2, 2, 2)));
118        jFontChooser1.setName("jFontChooser1"); // NOI18N
119        jFontChooser1.addMouseListener(new java.awt.event.MouseAdapter() {
120            public void mouseClicked(java.awt.event.MouseEvent evt) {
121                jFontChooser1MouseClicked(evt);
122            }
123        });
124
125        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
126        jPanel1.setLayout(jPanel1Layout);
127        jPanel1Layout.setHorizontalGroup(
128            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
129            .addGroup(jPanel1Layout.createSequentialGroup()
130                .addContainerGap()
131                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
132                    .addComponent(jLabel1)
133                    .addGroup(jPanel1Layout.createSequentialGroup()
134                        .addComponent(jLabel2)
135                        .addGap(18, 18, 18)
136                        .addComponent(font, javax.swing.GroupLayout.PREFERRED_SIZE, 219, javax.swing.GroupLayout.PREFERRED_SIZE))
137                    .addComponent(jFontChooser1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
138                .addContainerGap())
139        );
140        jPanel1Layout.setVerticalGroup(
141            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
142            .addGroup(jPanel1Layout.createSequentialGroup()
143                .addContainerGap()
144                .addComponent(jLabel1)
145                .addGap(12, 12, 12)
146                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
147                    .addComponent(jLabel2)
148                    .addComponent(font, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
149                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
150                .addComponent(jFontChooser1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
151                .addContainerGap(13, Short.MAX_VALUE))
152        );
153
154        add(jPanel1, java.awt.BorderLayout.CENTER);
155
156        jPanel6.setBackground(new java.awt.Color(255, 255, 255));
157        jPanel6.setName("jPanel6"); // NOI18N
158        jPanel6.setLayout(new java.awt.FlowLayout(java.awt.FlowLayout.RIGHT));
159
160        jButton2.setText(bundle.getString("ControlPanel_Fonts.jButton2.text")); // NOI18N
161        jButton2.setName("jButton2"); // NOI18N
162        jButton2.addActionListener(new java.awt.event.ActionListener() {
163            public void actionPerformed(java.awt.event.ActionEvent evt) {
164                jButton2ActionPerformed(evt);
165            }
166        });
167        jPanel6.add(jButton2);
168
169        jButton1.setText(bundle.getString("ControlPanel_Fonts.jButton1.text")); // NOI18N
170        jButton1.setName("jButton1"); // NOI18N
171        jButton1.addActionListener(new java.awt.event.ActionListener() {
172            public void actionPerformed(java.awt.event.ActionEvent evt) {
173                jButton1ActionPerformed(evt);
174            }
175        });
176        jPanel6.add(jButton1);
177
178        add(jPanel6, java.awt.BorderLayout.PAGE_END);
179    }// </editor-fold>//GEN-END:initComponents
180
181    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
182
183        if (jFontChooser1.getSelectedFont() != null) {
184            font.setText(getFontString(jFontChooser1.getSelectedFont()));
185            setSettings();
186        }
187
188    }//GEN-LAST:event_jButton2ActionPerformed
189
190    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
191        setSettings();
192        LocalSettings.save();
193    }//GEN-LAST:event_jButton1ActionPerformed
194
195    private void jFontChooser1MouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jFontChooser1MouseClicked
196        font.setText(getFontString(jFontChooser1.getSelectedFont()));
197    }//GEN-LAST:event_jFontChooser1MouseClicked
198
199    public void setValues(PropertyStore values) {
200        oldvalues = values;
201        font.setText(values.getProperty(LocalSettings.DEFAULT_FONT));
202    }
203
204    public String getUname() {
205        return UNAME;
206    }
207
208    public void reset() {
209        setValues(oldvalues);
210    }
211    // Variables declaration - do not modify//GEN-BEGIN:variables
212    private javax.swing.JTextField font;
213    private javax.swing.JButton jButton1;
214    private javax.swing.JButton jButton2;
215    private com.l2fprod.common.swing.JFontChooser jFontChooser1;
216    private javax.swing.JLabel jLabel1;
217    private javax.swing.JLabel jLabel2;
218    private javax.swing.JPanel jPanel1;
219    private javax.swing.JPanel jPanel6;
220    // End of variables declaration//GEN-END:variables
221
222    private void setSettings() {
223
224        if (font.getText().equalsIgnoreCase(getFontString(Font.decode(null)))) {
225            LocalSettings.setProperty(LocalSettings.DEFAULT_FONT, getFontString(jFontChooser1.getSelectedFont()));
226
227        } else if (font.getText() != null && font.getText().length() > 0 &&
228                !(getFontString(font.getText())).equalsIgnoreCase(getFontString(Font.decode(null)))) {
229            LocalSettings.setProperty(LocalSettings.DEFAULT_FONT, getFontString(font.getText()));
230
231        } else {
232            Popup.notice(Messages.VALUE_NOT_VALID + font.getText());
233        }
234
235        jFontChooser1.setSelectedFont(Font.decode(LocalSettings.getProperty(LocalSettings.DEFAULT_FONT)));
236        font.setText(getFontString(jFontChooser1.getSelectedFont()));
237
238        applyFont(Font.decode(getFontString(font.getText())));
239
240    }
241
242
243    public Component getAndRemoveActionPanel() {
244         this.remove(jPanel6);validate();
245        return jPanel6;
246    }
247}