1 14 package org.compiere.apps; 15 16 import java.awt.*; 17 import java.awt.event.*; 18 import javax.swing.*; 19 import javax.swing.event.*; 20 import javax.swing.table.*; 21 import java.util.*; 22 23 import org.compiere.util.*; 24 import org.compiere.grid.ed.*; 25 import org.compiere.plaf.*; 26 import org.compiere.swing.*; 27 import org.compiere.print.*; 28 import org.compiere.minigrid.*; 29 import org.compiere.model.*; 30 31 37 public final class Preference extends JDialog 38 implements ActionListener, ListSelectionListener 39 { 40 46 public Preference(Frame frame, int WindowNo, boolean modal) 47 { 48 super(frame, Msg.getMsg(Env.getCtx(), "Preference"), modal); 49 Log.trace(Log.l2_Sub, "Preference"); 50 setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); 51 try 52 { 53 jbInit(); 54 } 55 catch(Exception ex) 56 { 57 Log.error("Preference - " + ex.getMessage()); 58 } 59 load(); 60 StringBuffer sta = new StringBuffer ("#"); 62 sta.append(Env.getCtx().size()).append(" - ") 63 .append(Msg.translate(Env.getCtx(), "AD_Window_ID")) 64 .append("=").append(WindowNo); 65 statusBar.setStatusLine(sta.toString()); 66 statusBar.setStatusDB(""); 67 AEnv.positionCenterWindow(frame, this); 68 } 70 73 public Preference() 74 { 75 this(null, 0, false); 76 } 78 private CPanel panel = new CPanel(); 79 private BorderLayout panelLayout = new BorderLayout(); 80 private CTabbedPane tabPane = new CTabbedPane(); 81 private CPanel customizePane = new CPanel(); 82 private CPanel contextPane = new CPanel(); 83 private GridBagLayout customizeLayout = new GridBagLayout(); 84 private CCheckBox autoCommit = new CCheckBox(); 85 private CCheckBox printPreview = new CCheckBox(); 86 private CPanel southPanel = new CPanel(); 87 private BorderLayout southLayout = new BorderLayout(); 88 private BorderLayout icontextLayout = new BorderLayout(); 89 private JList infoList = new JList(); 90 private JScrollPane contextListScrollPane = new JScrollPane(infoList); 91 private CPanel contextSouthPanel = new CPanel(); 92 private CText contextHeader = new CText(4,15); 93 private CText contextDetail = new CText(4,35); 94 private CText infoArea = new CText(5, 30); 95 private BorderLayout contextSouthLayout = new BorderLayout(); 96 private StatusBar statusBar = new StatusBar(); 97 private ConfirmPanel confirm = new ConfirmPanel(true); 98 private JSlider debugLevel = new JSlider(); 99 private CLabel traceLabel = new CLabel(); 100 private CCheckBox autoLogin = new CCheckBox(); 101 private CCheckBox compiereSys = new CCheckBox(); 102 private CCheckBox storePassword = new CCheckBox(); 103 private CCheckBox showTrl = new CCheckBox(); 104 private CCheckBox showAcct = new CCheckBox(); 105 private CButton uiTheme = new CButton(); 106 private CLabel lPrinter = new CLabel(); 107 private CPrinter fPrinter = new CPrinter(); 108 private CLabel lDate = new CLabel(); 109 private VDate fDate = new VDate(); 110 private CCheckBox serverObjects = new CCheckBox(); 111 private CPanel errorPane = new CPanel(); 112 private BorderLayout errorLayout = new BorderLayout(); 113 private JScrollPane errorScrollPane = new JScrollPane(); 114 private MiniTable errorTable = new MiniTable(); 115 private CButton bErrorReset = new CButton(Msg.getMsg(Env.getCtx(), "Reset")); 116 private CButton bRoleInfo = new CButton(Msg.translate(Env.getCtx(), "AD_Role_ID")); 117 118 138 void jbInit() throws Exception  139 { 140 CompiereColor.setBackground(this); 141 traceLabel.setRequestFocusEnabled(false); 142 traceLabel.setText("TraceLevel"); 143 debugLevel.setMinorTickSpacing(1); 144 debugLevel.setMajorTickSpacing(2); 145 debugLevel.setPaintLabels(true); 146 debugLevel.setValue(5); 147 debugLevel.setPaintTicks(true); 148 debugLevel.setMaximum(10); 149 debugLevel.setSnapToTicks(true); 150 debugLevel.setOpaque(false); 151 152 uiTheme.setText(Msg.getMsg(Env.getCtx(), "UITheme", true)); 153 uiTheme.setToolTipText(Msg.getMsg(Env.getCtx(), "UITheme", false)); 154 autoCommit.setText(Msg.getMsg(Env.getCtx(), "AutoCommit", true)); 155 autoCommit.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoCommit", false)); 156 compiereSys.setText(Msg.getMsg(Env.getCtx(), "CompiereSys", true)); 157 compiereSys.setToolTipText(Msg.getMsg(Env.getCtx(), "CompiereSys", false)); 158 printPreview.setText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", true)); 159 printPreview.setToolTipText(Msg.getMsg(Env.getCtx(), "AlwaysPrintPreview", false)); 160 autoLogin.setText(Msg.getMsg(Env.getCtx(), "AutoLogin", true)); 161 autoLogin.setToolTipText(Msg.getMsg(Env.getCtx(), "AutoLogin", false)); 162 storePassword.setText(Msg.getMsg(Env.getCtx(), "StorePassword", true)); 163 storePassword.setToolTipText(Msg.getMsg(Env.getCtx(), "StorePassword", false)); 164 showTrl.setText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", true)); 165 showTrl.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowTrlTab", false)); 166 showAcct.setText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", true)); 167 showAcct.setToolTipText(Msg.getMsg(Env.getCtx(), "ShowAcctTab", false)); 168 serverObjects.setText(Msg.getMsg(Env.getCtx(), "ServerObjects", true)); 169 serverObjects.setToolTipText(Msg.getMsg(Env.getCtx(), "ServerObjects", false)); 170 lPrinter.setText(Msg.getMsg(Env.getCtx(), "Printer")); 171 lDate.setText(Msg.getMsg(Env.getCtx(), "Date")); 172 infoArea.setReadWrite(false); 173 getContentPane().add(panel); 174 panel.setLayout(panelLayout); 175 panel.add(tabPane, BorderLayout.CENTER); 176 tabPane.add(customizePane, Msg.getMsg(Env.getCtx(), "Preference")); 179 customizePane.setLayout(customizeLayout); 180 customizePane.add(infoArea, new GridBagConstraints(0, 0, 3, 1, 0.0, 0.0 181 ,GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(5, 5, 5, 5), 0, 0)); 182 customizePane.add(uiTheme, new GridBagConstraints(1, 1, 1, 1, 0.0, 0.0 183 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 184 customizePane.add(bRoleInfo, new GridBagConstraints(2, 1, 1, 1, 0.0, 0.0 185 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 186 187 customizePane.add(autoCommit, new GridBagConstraints(1, 2, 1, 1, 0.0, 0.0 188 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 189 customizePane.add(compiereSys, new GridBagConstraints(2, 2, 1, 1, 0.0, 0.0 190 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 191 customizePane.add(autoLogin, new GridBagConstraints(1, 3, 1, 1, 0.0, 0.0 192 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 193 customizePane.add(storePassword, new GridBagConstraints(2, 3, 1, 1, 0.0, 0.0 194 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 195 customizePane.add(showAcct, new GridBagConstraints(1, 4, 1, 1, 0.0, 0.0 196 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 197 customizePane.add(showTrl, new GridBagConstraints(2, 4, 1, 1, 0.0, 0.0 198 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 199 customizePane.add(serverObjects, new GridBagConstraints(1, 5, 1, 1, 0.0, 0.0 200 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 201 customizePane.add(printPreview, new GridBagConstraints(2, 5, 1, 1, 0.0, 0.0 202 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 203 204 customizePane.add(debugLevel, new GridBagConstraints(1, 6, 2, 1, 0.0, 0.0 205 ,GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(5, 5, 5, 5), 0, 0)); 206 customizePane.add(traceLabel, new GridBagConstraints(0, 6, 1, 1, 0.0, 0.0 207 ,GridBagConstraints.NORTHEAST, GridBagConstraints.NONE, new Insets(0, 0, 5, 5), 0, 0)); 208 customizePane.add(lPrinter, new GridBagConstraints(0, 7, 1, 1, 0.0, 0.0 209 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 210 customizePane.add(fPrinter, new GridBagConstraints(1, 7, 2, 1, 0.0, 0.0 211 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 212 customizePane.add(lDate, new GridBagConstraints(0, 8, 1, 1, 0.0, 0.0 213 ,GridBagConstraints.EAST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 214 customizePane.add(fDate, new GridBagConstraints(1, 8, 2, 1, 0.0, 0.0 215 ,GridBagConstraints.WEST, GridBagConstraints.NONE, new Insets(5, 5, 5, 5), 0, 0)); 216 tabPane.add(contextPane, Msg.getMsg(Env.getCtx(), "Context")); 219 contextPane.setLayout(icontextLayout); 220 contextPane.add(contextListScrollPane, BorderLayout.CENTER); 221 contextListScrollPane.setPreferredSize(new Dimension(200, 300)); 222 infoList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION); 223 infoList.setBackground(CompierePLAF.getFieldBackground_Inactive()); 224 infoList.addListSelectionListener(this); 225 infoList.setFixedCellWidth(30); 226 contextPane.add(contextSouthPanel, BorderLayout.SOUTH); 227 contextSouthPanel.setLayout(contextSouthLayout); 228 contextSouthPanel.add(contextHeader, BorderLayout.WEST); 229 contextHeader.setBackground(SystemColor.info); 230 contextHeader.setReadWrite(false); 231 contextHeader.setLineWrap(true); 232 contextHeader.setWrapStyleWord(true); 233 contextHeader.setBorder(BorderFactory.createLoweredBevelBorder()); 234 contextSouthPanel.add(contextDetail, BorderLayout.CENTER); 235 contextDetail.setBackground(SystemColor.info); 236 contextDetail.setReadWrite(false); 237 contextDetail.setLineWrap(true); 238 contextDetail.setWrapStyleWord(true); 239 contextDetail.setBorder(BorderFactory.createLoweredBevelBorder()); 240 errorPane.setLayout(errorLayout); 242 tabPane.add(errorPane, "Errors"); 244 errorPane.add(errorScrollPane, BorderLayout.CENTER); 245 errorScrollPane.getViewport().add(errorTable, null); 246 errorPane.add(bErrorReset, BorderLayout.SOUTH); 247 panel.add(southPanel, BorderLayout.SOUTH); 249 southPanel.setLayout(southLayout); 250 southPanel.add(statusBar, BorderLayout.SOUTH); 251 southPanel.add(confirm, BorderLayout.CENTER); 252 bRoleInfo.addActionListener(this); 254 confirm.addActionListener(this); 255 } 257 258 262 public void valueChanged(ListSelectionEvent e) 263 { 264 if (e.getValueIsAdjusting()) 265 return; 266 267 String value = (String )infoList.getSelectedValue(); 268 if (value == null) 269 return; 270 int pos = value.indexOf("=="); 271 if (pos == -1) 272 { 273 contextHeader.setText(""); 274 contextDetail.setText(value); 275 } 276 else 277 { 278 contextHeader.setText(value.substring(0, pos).replace('|','\n')); 279 contextDetail.setText(value.substring(pos+3)); 280 } 281 } 283 284 288 public void actionPerformed(ActionEvent e) 289 { 290 if (e.getSource() == uiTheme) 292 new CompierePLAFEditor(this, false); 293 else if (e.getActionCommand().equals(ConfirmPanel.A_CANCEL)) 294 dispose(); 295 else if (e.getActionCommand().equals(ConfirmPanel.A_OK)) 296 cmd_save(); 297 else if (e.getSource() == bErrorReset) 298 cmd_resetErrors(); 299 else if (e.getSource() == bRoleInfo) 300 ADialog.info(0, this, "RoleInfo", MRole.getDefault().toStringX(Env.getCtx())); 301 } 303 304 307 private void load() 308 { 309 Log.trace(Log.l3_Util, "Preference.load"); 310 infoArea.setText(AboutBox.getInfo()); 311 infoArea.setCaretPosition(0); 312 313 uiTheme.addActionListener(this); 316 autoCommit.setSelected(Env.isAutoCommit(Env.getCtx())); 318 compiereSys.setSelected(Ini.getPropertyBool(Ini.P_COMPIERESYS)); 320 if (Env.getAD_Client_ID(Env.getCtx()) > 20) 321 { 322 compiereSys.setSelected(false); 323 compiereSys.setEnabled(false); 324 } 325 autoLogin.setSelected(Ini.getPropertyBool(Ini.P_A_LOGIN)); 327 storePassword.setSelected(Ini.getPropertyBool(Ini.P_STORE_PWD)); 329 if (MRole.getDefault().isShowAcct()) 331 showAcct.setSelected(Ini.getPropertyBool(Ini.P_SHOW_ACCT)); 332 else 333 { 334 showAcct.setSelected(false); 335 showAcct.setReadWrite(false); 336 } 337 showTrl.setSelected(Ini.getPropertyBool(Ini.P_SHOW_TRL)); 339 serverObjects.setSelected(Ini.getPropertyBool(Ini.P_OBJECTS)); 341 printPreview.setSelected(Ini.getPropertyBool(Ini.P_PRINTPREVIEW)); 343 344 debugLevel.setValue(Log.getTraceLevel()); 346 fPrinter.setValue(Env.getContext(Env.getCtx(), "#Printer")); 348 fDate.setValue(Env.getContextAsDate(Env.getCtx(), "#Date")); 350 351 String [] context = Env.getEntireContext(Env.getCtx()); 353 Arrays.sort(context); 354 infoList.setListData(context); 355 356 Vector data = LogBuffer.get().getLogData(); 358 Vector columnNames = LogBuffer.get().getColumnNames(Env.getCtx()); 359 DefaultTableModel model = new DefaultTableModel(data, columnNames); 360 errorTable.setModel(model); 361 errorTable.setCellSelectionEnabled(true); 362 tabPane.setTitleAt(2, Msg.getMsg(Env.getCtx(), "Errors") + " (" + data.size() + ")"); 363 for (int i = 2; i < 6; i++) 364 errorTable.setColumnReadOnly(i, false); 365 errorTable.autoSize(); 366 bErrorReset.addActionListener(this); 367 } 369 372 private void cmd_save() 373 { 374 Log.trace(Log.l3_Util, "Preference.cmd_save"); 375 Ini.setProperty(Ini.P_A_COMMIT, (autoCommit.isSelected())); 378 Env.setAutoCommit(Env.getCtx(), autoCommit.isSelected()); 379 Ini.setProperty(Ini.P_COMPIERESYS, compiereSys.isSelected()); 381 Ini.setProperty(Ini.P_A_LOGIN, (autoLogin.isSelected())); 383 Ini.setProperty(Ini.P_STORE_PWD, (storePassword.isSelected())); 385 Ini.setProperty(Ini.P_SHOW_ACCT, (showAcct.isSelected())); 387 Env.setContext(Env.getCtx(), "#ShowAcct", (showAcct.isSelected())); 388 Ini.setProperty(Ini.P_SHOW_TRL, (showTrl.isSelected())); 390 Env.setContext(Env.getCtx(), "#ShowTrl", (showTrl.isSelected())); 391 Ini.setProperty(Ini.P_OBJECTS, (serverObjects.isSelected())); 393 Ini.setProperty(Ini.P_PRINTPREVIEW, (printPreview.isSelected())); 395 Log.setTraceLevel(debugLevel.getValue()); 397 Ini.setProperty(Ini.P_DEBUGLEVEL, String.valueOf(debugLevel.getValue())); 398 String printer = (String )fPrinter.getSelectedItem(); 400 Env.setContext(Env.getCtx(), "#Printer", printer); 401 Ini.setProperty(Ini.P_PRINTER, printer); 402 java.sql.Timestamp ts = (java.sql.Timestamp )fDate.getValue(); 404 if (ts != null) 405 { 406 java.sql.Date sd = new java.sql.Date (ts.getTime()); 407 Env.setContext(Env.getCtx(), "#Date", sd.toString()); } 409 410 Ini.saveProperties(true); 411 if (!Ini.isClient()) 412 Ini.saveProperties(false); 413 414 dispose(); 415 } 417 420 private void cmd_resetErrors() 421 { 422 LogBuffer.get().resetBuffer(); 423 Vector data = LogBuffer.get().getLogData(); 424 Vector columnNames = LogBuffer.get().getColumnNames(Env.getCtx()); 425 DefaultTableModel model = new DefaultTableModel(data, columnNames); 426 errorTable.setModel(model); 427 tabPane.setTitleAt(2, Msg.getMsg(Env.getCtx(), "Errors") + " (" + data.size() + ")"); 429 errorTable.autoSize(); 430 } 432 } | Popular Tags |