📄 vpanel.java
字号:
/******************************************************************************
* The contents of this file are subject to the Compiere License Version 1.1
* ("License"); You may not use this file except in compliance with the License
* You may obtain a copy of the License at http://www.compiere.org/license.html
* Software distributed under the License is distributed on an "AS IS" basis,
* WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
* the specific language governing rights and limitations under the License.
* The Original Code is Compiere ERP & CRM Smart Business Solution. The Initial
* Developer of the Original Code is Jorg Janke. Portions created by Jorg Janke
* are Copyright (C) 1999-2005 Jorg Janke.
* All parts are Copyright (C) 1999-2005 ComPiere, Inc. All Rights Reserved.
* Contributor(s): ______________________________________.
*****************************************************************************/
package org.compiere.grid;
import java.awt.*;
import java.awt.event.*;
import javax.swing.*;
import java.util.*;
//
import org.compiere.grid.ed.*;
import org.compiere.model.*;
import org.compiere.swing.*;
import org.compiere.util.*;
/**
* Single Row Panel.
* Called from GridController
* <pre>
* Structure
* this (CPanel - Group Bag Layout)
* group
* label - field
*
* Spacing:
* -------------------
* Total Top = 10+2
* Total Right = 0+12
* Total Left = 0+12
* Total Bottom = 3+9
* -------------------
* 2
* 12 Label 0+5 Field 0
* 3+2=5
* 12 Label 0+5 Field 0
* 3
*
* </pre>
* @author Jorg Janke
* @version $Id: VPanel.java,v 1.18 2005/12/09 05:17:53 jjanke Exp $
*/
public final class VPanel extends CPanel
{
/**
* Constructor
*/
public VPanel()
{
super(new GridBagLayout());
setName("VPanel");
setBorder(null);
// Set initial values of constraint
m_gbc.anchor = GridBagConstraints.NORTHWEST;
m_gbc.gridy = 0; // line
m_gbc.gridx = 0;
m_gbc.gridheight = 1;
m_gbc.gridwidth = 1;
m_gbc.insets = m_zeroInset;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
m_gbc.weightx = 0;
m_gbc.weighty = 0;
m_gbc.ipadx = 0;
m_gbc.ipady = 0;
} // VPanel
/** GridBag Constraint */
private GridBagConstraints m_gbc = new GridBagConstraints();
/** Orientation */
private final boolean m_leftToRight = Language.getLoginLanguage().isLeftToRight();
/** Label Inset */
private final Insets m_labelInset =
m_leftToRight ? new Insets(2,12,3,0) : new Insets(2,5,3,0); // top,left,bottom,right
/** Field Inset */
private final Insets m_fieldInset =
m_leftToRight ? new Insets(2,5,3,0) : new Insets(2,12,3,0); // top,left,bottom,right
/** Zero Inset */
private final Insets m_zeroInset = new Insets(0,0,0,0);
//
private int m_line = 0;
private boolean m_hGapAdded = false; // only once
/** Previous Field Group Header */
private String m_oldFieldGroup = null;
/**
* Add Field and Label to Panel
* @param editor editor
* @param mField field model
*/
public void addField (VEditor editor, MField mField)
{
CLabel label = VEditorFactory.getLabel(mField);
if (label == null && editor == null)
return;
boolean sameLine = mField.isSameLine();
if (addGroup(mField.getFieldGroup())) // sets top
sameLine = false;
if (sameLine) // Set line #
m_gbc.gridy = m_line-1;
else
m_gbc.gridy = m_line++;
// *** The Label ***
if (label != null)
{
m_gbc.gridwidth = 1;
m_gbc.insets = m_labelInset;
m_gbc.fill = GridBagConstraints.HORIZONTAL; // required for right justified
// Set column #
if (m_leftToRight)
m_gbc.gridx = sameLine ? 2 : 0;
else
m_gbc.gridx = sameLine | mField.isLongField() ? 3 : 1;
// Weight factor for Label
m_gbc.weightx = 0;
//
if (mField.isCreateMnemonic())
setMnemonic(label);
// Add Label
this.add(label, m_gbc);
}
// *** The Field ***
if (editor != null)
{
Component field = (Component)editor;
// Default Width
m_gbc.gridwidth = mField.isLongField() ? 3 : 1;
m_gbc.insets = m_fieldInset;
// m_gbc.fill = GridBagConstraints.NONE;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
// Set column #
if (m_leftToRight)
m_gbc.gridx = sameLine ? 3 : 1;
else
m_gbc.gridx = sameLine ? 2 : 0;
// Weight factor for Fields
m_gbc.weightx = 1;
// Add Field
this.add(field, m_gbc);
// Link Label to Field
if (label != null)
label.setLabelFor(field);
else if (mField.isCreateMnemonic())
setMnemonic(editor);
}
} // addField
/**
* Add Group
* @param fieldGroup field group
* @return true if group added
*/
private boolean addGroup(String fieldGroup)
{
// First time - add top
if (m_oldFieldGroup == null)
{
addTop();
m_oldFieldGroup = "";
}
if (fieldGroup == null || fieldGroup.length() == 0 || fieldGroup.equals(m_oldFieldGroup))
return false;
m_oldFieldGroup = fieldGroup;
CPanel group = new CPanel();
group.setBorder(new VLine(fieldGroup));
group.add(Box.createVerticalStrut(VLine.SPACE));
m_gbc.gridx = 0;
m_gbc.gridy = m_line++;
m_gbc.gridwidth = 4;
this.add(group, m_gbc);
// reset
m_gbc.gridwidth = 1;
return true;
} // addGroup
/**
* Add Top (10) and right (12) gap
*/
private void addTop()
{
// Top Gap
m_gbc.gridy = m_line++;
this.add(Box.createVerticalStrut(10), m_gbc); // top gap
// Right gap
m_gbc.gridx = 4; // 5th column
m_gbc.gridwidth = 1;
m_gbc.weightx = 0;
m_gbc.insets = m_zeroInset;
m_gbc.fill = GridBagConstraints.NONE;
this.add(Box.createHorizontalStrut(12), m_gbc);
} // addTop
/**
* Add End (9) of Form
*/
public void addEnd()
{
m_gbc.gridx = 0;
m_gbc.gridy = m_line;
m_gbc.gridwidth = 1;
m_gbc.insets = m_zeroInset;
m_gbc.fill = GridBagConstraints.HORIZONTAL;
m_gbc.weightx = 0;
//
this.add(Box.createVerticalStrut(9), m_gbc); // botton gap
} // addEnd
/**
* Set Mnemonic for Label CTRL_x
* @param label label
*/
private void setMnemonic (CLabel label)
{
String text = label.getText();
int pos = text.indexOf("&");
if (pos != -1 && text.length() > pos) // We have a nemonic - creates CTL-_
{
char mnemonic = text.toUpperCase().charAt(pos+1);
if (mnemonic != ' ')
{
m_mnemonics.add(mnemonic);
text = text.substring(0, pos) + text.substring(pos+1);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
label.setText(text);
label.setSavedMnemonic(mnemonic);
}
// label.setDisplayedMnemonic(mnemonic);
}
}
else
{
char mnemonic = getMnemonic(text);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
label.setSavedMnemonic(mnemonic);
}
// label.setDisplayedMnemonic(mnemonic);
}
m_fields.add(label);
} // setMnemonic
/**
* Set Mnemonic for Check Box or Button
* @param editor
*/
private void setMnemonic (VEditor editor)
{
if (editor instanceof VCheckBox)
{
VCheckBox cb = (VCheckBox)editor;
String text = cb.getText();
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
char mnemonic = text.toUpperCase().charAt(pos+1);
text = text.substring(0, pos) + text.substring(pos+1);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
cb.setText(text);
cb.setSavedMnemonic(mnemonic);
}
// cb.setMnemonic(mnemonic);
}
else
{
char mnemonic = getMnemonic(text);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
cb.setSavedMnemonic(mnemonic);
}
// cb.setMnemonic(mnemonic);
}
m_fields.add(cb);
}
// Button
else if (editor instanceof VButton)
{
VButton b = (VButton)editor;
String text = b.getText();
int pos = text.indexOf("&");
if (pos != -1) // We have a nemonic - creates ALT-_
{
char mnemonic = text.toUpperCase().charAt(pos+1);
text = text.substring(0, pos) + text.substring(pos+1);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
b.setText(text);
b.setSavedMnemonic(mnemonic);
}
// b.setMnemonic(mnemonic);
m_fields.add(b);
}
else if (b.getColumnName().equals("DocAction"))
{
b.getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.SHIFT_MASK, false), "pressed");
b.getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, Event.SHIFT_MASK, true), "released");
// Util.printActionInputMap(b);
}
else if (b.getColumnName().equals("Posted"))
{
b.getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, Event.SHIFT_MASK, false), "pressed");
b.getInputMap(WHEN_IN_FOCUSED_WINDOW)
.put(KeyStroke.getKeyStroke(KeyEvent.VK_F5, Event.SHIFT_MASK, true), "released");
// Util.printActionInputMap(b);
}
else
{
char mnemonic = getMnemonic(text);
if(Env.getLanguage(Env.getCtx()).getLanguageCode() != "zh"){
b.setSavedMnemonic(mnemonic);
}
// b.setMnemonic(mnemonic);
m_fields.add(b);
}
}
} // setMnemonic
/**
* Get Mnemonic
* @param text text
* @return Mnemonic
*/
private char getMnemonic (String text)
{
if (text == null || text.length() == 0)
return 0;
text = text.trim();
char mnemonic = text.toUpperCase().charAt(0);
if (m_mnemonics.contains(mnemonic))
{
mnemonic = 0;
// Beginning new word
int index = text.indexOf(' ');
while (index != -1 && text.length() > index)
{
char c = text.toUpperCase().charAt(index+1);
if (Character.isLetterOrDigit(c) && !m_mnemonics.contains(c))
{
mnemonic = c;
break;
}
index = text.indexOf(' ', index+1);
}
// Any character
if (mnemonic == 0)
{
for (int i = 1; i < text.length(); i++)
{
char c = text.toUpperCase().charAt(i);
if (Character.isLetterOrDigit(c) && !m_mnemonics.contains(c))
{
mnemonic = c;
break;
}
}
}
// First character fallback
if (mnemonic == 0)
mnemonic = text.toUpperCase().charAt(0);
}
m_mnemonics.add(mnemonic);
return mnemonic;
} // getMnemonic
/** Used Mnemonics */
private ArrayList<Character> m_mnemonics = new ArrayList<Character>(30);
/** Mnemonic Fields */
private ArrayList<Component> m_fields = new ArrayList<Component>(30);
/**
* Set Window level Mnemonics
* @param set true if set otherwise unregiser
*/
public void setMnemonics (boolean set)
{
int size = m_fields.size();
for (int i = 0; i < size; i++)
{
Component c = m_fields.get(i);
if (c instanceof CLabel)
{
CLabel l = (CLabel)c;
if (set)
l.setDisplayedMnemonic(l.getSavedMnemonic());
else
l.setDisplayedMnemonic(0);
}
else if (c instanceof VCheckBox)
{
VCheckBox cb = (VCheckBox)c;
if (set)
cb.setMnemonic(cb.getSavedMnemonic());
else
cb.setMnemonic(0);
}
else if (c instanceof VButton)
{
VButton b = (VButton)c;
if (set)
b.setMnemonic(b.getSavedMnemonic());
else
b.setMnemonic(0);
}
}
} // setMnemonics
/**************************************************************************
* Set Background to AD_Color_ID (nop)
* @param AD_Color_ID Color
*/
public void setBackground (int AD_Color_ID)
{
} // setBackground
} // VPanel
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -