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