下面列出了javax.swing.JButton#setMnemonic ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
private void addSubsetAcessory() {
subsetButton = new JButton("Subset...");
subsetButton.setMnemonic('S');
subsetButton.addActionListener(e -> openProductSubsetDialog());
subsetButton.setEnabled(getSelectedFile() != null || productToExport != null);
sizeLabel = new JLabel("0 M");
sizeLabel.setHorizontalAlignment(JLabel.RIGHT);
JPanel panel = GridBagUtils.createPanel();
GridBagConstraints gbc = GridBagUtils.createConstraints(
"fill=HORIZONTAL,weightx=1,anchor=NORTHWEST,insets.left=7,insets.right=7,insets.bottom=4");
GridBagUtils.addToPanel(panel, subsetButton, gbc, "gridy=0");
GridBagUtils.addToPanel(panel, sizeLabel, gbc, "gridy=1");
GridBagUtils.addVerticalFiller(panel, gbc);
setAccessory(panel);
addPropertyChangeListener(e -> updateState());
}
private
JButton
createButton(FormButtonKeys key, String tip, ActionListener listener)
{
JButton button = new JButton();
// Build Button.
buildButton(button, key.getText(), listener, "", tip);
if(IS_MAC == false)
{
button.setMnemonic(key.getText().charAt(0));
}
return button;
}
private static JComponent createImageLegendAccessory(final JFileChooser fileChooser,
final ParamGroup legendParamGroup,
final ImageLegend imageLegend, String helpId) {
final JButton button = new JButton("Properties...");
button.setMnemonic('P');
button.addActionListener(e -> {
final SnapFileFilter fileFilter = (SnapFileFilter) fileChooser.getFileFilter();
final ImageLegendDialog dialog = new ImageLegendDialog(
legendParamGroup,
imageLegend,
isTransparencySupportedByFormat(fileFilter.getFormatName()), helpId);
dialog.show();
});
final JPanel accessory = new JPanel(new BorderLayout());
accessory.setBorder(new EmptyBorder(3, 3, 3, 3));
accessory.add(button, BorderLayout.NORTH);
return accessory;
}
ControlPanel( FormatChartsViewer fcv )
{
this.fcv = fcv;
setLayout( new GridLayout( 0, 1, 0, 0 ) );
JPanel jp = new JPanel( );
jp.setLayout( new FlowLayout( FlowLayout.LEFT, 3, 3 ) );
JLabel choose=new JLabel( "Choose:" );//$NON-NLS-1$
choose.setDisplayedMnemonic( 'c' );
jp.add( choose );
jcbModels = new JComboBox( );
jcbModels.addItem( "Axis Format" );//$NON-NLS-1$
jcbModels.addItem( "Colored By Category" );//$NON-NLS-1$
jcbModels.addItem( "Legend & Title Format" );//$NON-NLS-1$
jcbModels.addItem( "Percentage Values" );//$NON-NLS-1$
jcbModels.addItem( "Plot Format" );//$NON-NLS-1$
jcbModels.addItem( "Series Format" );//$NON-NLS-1$
choose.setLabelFor( jcbModels );
jcbModels.setSelectedIndex( 0 );
jp.add( jcbModels );
jbUpdate = new JButton( "Update" );//$NON-NLS-1$
jbUpdate.setMnemonic( 'u' );
jbUpdate.setToolTipText( "Update" );//$NON-NLS-1$
jbUpdate.addActionListener( this );
jp.add( jbUpdate );
add( jp );
}
public ButtonDemo() {
ImageIcon leftButtonIcon = createImageIcon("images/right.gif");
ImageIcon middleButtonIcon = createImageIcon("images/middle.gif");
ImageIcon rightButtonIcon = createImageIcon("images/left.gif");
b1 = new JButton("Disable middle button", leftButtonIcon);
b1.setVerticalTextPosition(AbstractButton.CENTER);
b1.setHorizontalTextPosition(AbstractButton.LEADING); // aka LEFT, for
// left-to-right
// locales
b1.setMnemonic(KeyEvent.VK_D);
b1.setActionCommand("disable");
b2 = new JButton("Middle button", middleButtonIcon);
b2.setVerticalTextPosition(AbstractButton.BOTTOM);
b2.setHorizontalTextPosition(AbstractButton.CENTER);
b2.setMnemonic(KeyEvent.VK_M);
b3 = new JButton("Enable middle button", rightButtonIcon);
// Use the default text position of CENTER, TRAILING (RIGHT).
b3.setMnemonic(KeyEvent.VK_E);
b3.setActionCommand("enable");
b3.setEnabled(false);
// Listen for actions on buttons 1 and 3.
b1.addActionListener(this);
b3.addActionListener(this);
b1.setToolTipText("Click this button to disable the middle button.");
b2.setToolTipText("This middle button does nothing when you click it.");
b3.setToolTipText("Click this button to enable the middle button.");
// Add Components to this container, using the default FlowLayout.
add(b1);
add(b2);
add(b3);
}
/**
*
* ͼ�갴ť
*
* */
public JButton createButton(int x, int y, ImageIcon[] img, char keyLinstenr) {
JButton add = new JButton("", img[0]);
add.setPressedIcon(img[3]);
add.setRolloverIcon(img[2]);
add.setMnemonic(keyLinstenr);
add.setBounds(x, y, img[0].getIconWidth(), img[0].getIconHeight());
return add;
}
/** @return 0 => cannot close, -1 can close and do not save, 1 can close and save */
private int canCloseImpl() {
String msg = messageSave();
ResourceBundle bundle = NbBundle.getBundle(CloneableEditorSupport.class);
JButton saveOption = new JButton(bundle.getString("CTL_Save")); // NOI18N
saveOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Save")); // NOI18N
saveOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Save")); // NOI18N
JButton discardOption = new JButton(bundle.getString("CTL_Discard")); // NOI18N
discardOption.getAccessibleContext().setAccessibleDescription(bundle.getString("ACSD_CTL_Discard")); // NOI18N
discardOption.getAccessibleContext().setAccessibleName(bundle.getString("ACSN_CTL_Discard")); // NOI18N
discardOption.setMnemonic(bundle.getString("CTL_Discard_Mnemonic").charAt(0)); // NOI18N
NotifyDescriptor nd = new NotifyDescriptor(
msg, bundle.getString("LBL_SaveFile_Title"), NotifyDescriptor.YES_NO_CANCEL_OPTION,
NotifyDescriptor.QUESTION_MESSAGE,
new Object[] { saveOption, discardOption, NotifyDescriptor.CANCEL_OPTION }, saveOption
);
Object ret = DialogDisplayer.getDefault().notify(nd);
if (NotifyDescriptor.CANCEL_OPTION.equals(ret) || NotifyDescriptor.CLOSED_OPTION.equals(ret)) {
return 0;
}
if (saveOption.equals(ret)) {
return 1;
} else {
return -1;
}
}
public void setShortCutTo(int key, JButton b) {
b.setMnemonic(key);
String tt= b.getToolTipText();
if(tt==null)
b.setToolTipText("( Alt+" + KeyEvent.getKeyText(key)+" )");
else
b.setToolTipText(tt + " ( Alt+" + KeyEvent.getKeyText(key)+" )");
mapping.put(keyfor(b),b);
}
/**
* Creates a new "Don't Save" button.
*
* @param escapeKeyIsTrigger
* if true then pressing the escape key will trigger this button.
* (Also on Macs command-period will act like the escape key.)
* This should be <code>false</code> if this button can lead to
* permanent data loss.
*/
public static JButton createDontSaveButton(boolean escapeKeyIsTrigger) {
String text = strings.getString("dialogDontSaveButton");
JButton button = new JButton(text);
button.setMnemonic(strings.getString("dialogDontSaveMnemonic")
.charAt(0));
button.putClientProperty(PROPERTY_OPTION, new Integer(DONT_SAVE_OPTION));
// Don't know if this documented by Apple, but command-D usually
// triggers "Don't Save" buttons:
button.putClientProperty(DialogFooter.PROPERTY_META_SHORTCUT,
new Character(text.charAt(0)));
if (escapeKeyIsTrigger)
makeEscapeKeyActivate(button);
return button;
}
ControlPanel( SwingInteractivityViewer siv )
{
this.siv = siv;
setLayout( new GridLayout( 0, 1, 0, 0 ) );
JPanel jp = new JPanel( );
jp.setLayout( new FlowLayout( FlowLayout.LEFT, 3, 3 ) );
JLabel choose = new JLabel( "Choose:" );//$NON-NLS-1$
choose.setDisplayedMnemonic( 'c' );
jp.add( choose );
jcbModels = new JComboBox( );
choose.setLabelFor( jcbModels );
jcbModels.addItem( "Highlight Series" );//$NON-NLS-1$
jcbModels.addItem( "Show Tooltip" );//$NON-NLS-1$
jcbModels.addItem( "Toggle Visibility" );//$NON-NLS-1$
jcbModels.addItem( "URL Redirect" );//$NON-NLS-1$
jcbModels.addItem( "Multiple URLs Redirect" );//$NON-NLS-1$
jcbModels.addItem( "Call Back" );//$NON-NLS-1$
jcbModels.addItem( "Right Mouse Click" );//$NON-NLS-1$
jcbModels.addItem( "Mouse Cursor" );//$NON-NLS-1$
jcbModels.setSelectedIndex( 0 );
jp.add( jcbModels );
jbUpdate = new JButton( "Update" );//$NON-NLS-1$
jbUpdate.setMnemonic( 'u' );
jbUpdate.addActionListener( this );
jbUpdate.setToolTipText( "Show" );//$NON-NLS-1$
jp.add( jbUpdate );
add( jp );
}
private void initUI(){
indexSurface=0;
currentSurface=surfaceRanksBests[indexSurface].getSurface();
surfaceComponent=new SurfaceComponent (maxJump,stackWidth,currentSurface);
labelScore=new JLabel(AIRanksTool.getUIText("Result_Score")+surfaceRanksBests[indexSurface].getRank());
currentSurfaceMirrored=surfaceRanksBestsMirrored[indexSurface].getSurface();
surfaceComponentMirrored=new SurfaceComponent(maxJump,stackWidth,currentSurfaceMirrored);
labelScoreMirrored=new JLabel(AIRanksTool.getUIText("Result_Score")+surfaceRanksBestsMirrored[indexSurface].getRank());
buttonNext=new JButton(AIRanksTool.getUIText("Result_Next"));
buttonNext.setActionCommand("next");
buttonNext.addActionListener( this);
buttonNext.setMnemonic('N');
buttonPrevious=new JButton(AIRanksTool.getUIText("Result_Previous"));
buttonPrevious.setActionCommand("previous ");
buttonPrevious.setEnabled(false);
buttonPrevious.addActionListener( this);
buttonPrevious.setMnemonic('P');
JPanel pane=new JPanel(new BorderLayout());
JPanel surfacePane=new JPanel(new BorderLayout());
surfacePane.add(surfaceComponent,BorderLayout.CENTER);
surfacePane.add(labelScore,BorderLayout.SOUTH);
JPanel surfacePaneMirrored=new JPanel(new BorderLayout());
surfacePaneMirrored.add(surfaceComponentMirrored,BorderLayout.CENTER);
surfacePaneMirrored.add(labelScoreMirrored,BorderLayout.SOUTH);
JPanel highPane=new JPanel();
highPane.add(surfacePane);
highPane.add(surfacePaneMirrored);
JPanel buttonsPane=new JPanel();
buttonsPane.add(buttonPrevious);
buttonsPane.add(buttonNext);
pane.setBorder(BorderFactory.createEmptyBorder(20, 20, 20, 20));
pane.add(highPane,BorderLayout.CENTER);
pane.add(buttonsPane,BorderLayout.SOUTH);
getContentPane().add(pane);
//getContentPane().add(surfaceComponent);
}
/**
* GUIAInitialization
*/
protected void initUI() {
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
// Tab
tabPane = new JTabbedPane();
tabPane.setAlignmentX(LEFT_ALIGNMENT);
this.add(tabPane);
// Rules
listboxRule = new JList[GameEngine.MAX_GAMESTYLE];
for(int i = 0; i < GameEngine.MAX_GAMESTYLE; i++) {
listboxRule[i] = new JList(extractRuleListFromRuleEntries(i));
JScrollPane scpaneRule = new JScrollPane(listboxRule[i]);
scpaneRule.setPreferredSize(new Dimension(380, 250));
scpaneRule.setAlignmentX(LEFT_ALIGNMENT);
tabPane.addTab(GameEngine.GAMESTYLE_NAMES[i], scpaneRule);
}
// default Back to button
JButton btnUseDefault = new JButton(NullpoMinoSwing.getUIText("RuleSelect_UseDefault"));
btnUseDefault.setMnemonic('D');
btnUseDefault.addActionListener(this);
btnUseDefault.setActionCommand("RuleSelect_UseDefault");
btnUseDefault.setAlignmentX(LEFT_ALIGNMENT);
btnUseDefault.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
btnUseDefault.setVisible(false);
this.add(btnUseDefault);
// buttonKind
JPanel pButtons = new JPanel();
pButtons.setLayout(new BoxLayout(pButtons, BoxLayout.X_AXIS));
pButtons.setAlignmentX(LEFT_ALIGNMENT);
this.add(pButtons);
JButton btnOK = new JButton(NullpoMinoSwing.getUIText("RuleSelect_OK"));
btnOK.setMnemonic('O');
btnOK.addActionListener(this);
btnOK.setActionCommand("RuleSelect_OK");
btnOK.setAlignmentX(LEFT_ALIGNMENT);
btnOK.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
pButtons.add(btnOK);
this.getRootPane().setDefaultButton(btnOK);
JButton btnCancel = new JButton(NullpoMinoSwing.getUIText("RuleSelect_Cancel"));
btnCancel.setMnemonic('C');
btnCancel.addActionListener(this);
btnCancel.setActionCommand("RuleSelect_Cancel");
btnCancel.setAlignmentX(LEFT_ALIGNMENT);
btnCancel.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
pButtons.add(btnCancel);
}
private void setupScreen() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createLineBorder(Color.GRAY));
// add main panel to XSheet
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
// add south panel to XSheet
southPanel = new JPanel();
add(southPanel, BorderLayout.SOUTH);
// create the refresh button
refreshButton = new JButton(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON);
refreshButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON));
refreshButton.setToolTipText(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON_TOOLTIP);
refreshButton.addActionListener(this);
// create the clear button
clearButton = new JButton(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON);
clearButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON));
clearButton.setToolTipText(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON_TOOLTIP);
clearButton.addActionListener(this);
// create the subscribe button
subscribeButton = new JButton(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON);
subscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON));
subscribeButton.setToolTipText(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);
subscribeButton.addActionListener(this);
// create the unsubscribe button
unsubscribeButton = new JButton(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON);
unsubscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON));
unsubscribeButton.setToolTipText(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);
unsubscribeButton.addActionListener(this);
// create XMBeanAttributes container
mbeanAttributes = new XMBeanAttributes(mbeansTab);
// create XMBeanOperations container
mbeanOperations = new XMBeanOperations(mbeansTab);
mbeanOperations.addOperationsListener(this);
// create XMBeanNotifications container
mbeanNotifications = new XMBeanNotifications();
mbeanNotifications.addNotificationsListener(this);
// create XMBeanInfo container
mbeanInfo = new XMBeanInfo();
}
private void setupScreen() {
setLayout(new BorderLayout());
setBorder(BorderFactory.createLineBorder(Color.GRAY));
// add main panel to XSheet
mainPanel = new JPanel();
mainPanel.setLayout(new BorderLayout());
add(mainPanel, BorderLayout.CENTER);
// add south panel to XSheet
southPanel = new JPanel();
add(southPanel, BorderLayout.SOUTH);
// create the refresh button
refreshButton = new JButton(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON);
refreshButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON));
refreshButton.setToolTipText(Messages.MBEANS_TAB_REFRESH_ATTRIBUTES_BUTTON_TOOLTIP);
refreshButton.addActionListener(this);
// create the clear button
clearButton = new JButton(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON);
clearButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON));
clearButton.setToolTipText(Messages.MBEANS_TAB_CLEAR_NOTIFICATIONS_BUTTON_TOOLTIP);
clearButton.addActionListener(this);
// create the subscribe button
subscribeButton = new JButton(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON);
subscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON));
subscribeButton.setToolTipText(Messages.MBEANS_TAB_SUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);
subscribeButton.addActionListener(this);
// create the unsubscribe button
unsubscribeButton = new JButton(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON);
unsubscribeButton.setMnemonic(Resources.getMnemonicInt(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON));
unsubscribeButton.setToolTipText(Messages.MBEANS_TAB_UNSUBSCRIBE_NOTIFICATIONS_BUTTON_TOOLTIP);
unsubscribeButton.addActionListener(this);
// create XMBeanAttributes container
mbeanAttributes = new XMBeanAttributes(mbeansTab);
// create XMBeanOperations container
mbeanOperations = new XMBeanOperations(mbeansTab);
mbeanOperations.addOperationsListener(this);
// create XMBeanNotifications container
mbeanNotifications = new XMBeanNotifications();
mbeanNotifications.addNotificationsListener(this);
// create XMBeanInfo container
mbeanInfo = new XMBeanInfo();
}
/**
* ScreenInitialization
*/
private void initUI() {
this.getContentPane().setLayout(new BoxLayout(this.getContentPane(), BoxLayout.Y_AXIS));
// Main screen
JPanel pMusicSetting = new JPanel();
pMusicSetting.setLayout(new BoxLayout(pMusicSetting, BoxLayout.Y_AXIS));
pMusicSetting.setAlignmentX(LEFT_ALIGNMENT);
this.add(pMusicSetting);
txtfldMusicFileNames = new JTextField[BGMStatus.BGM_COUNT];
chkboxNoLoop = new JCheckBox[BGMStatus.BGM_COUNT];
for(int i = 0; i < BGMStatus.BGM_COUNT; i++) {
JPanel pMusicTemp = new JPanel(new BorderLayout());
pMusicSetting.add(pMusicTemp);
JPanel pMusicTempLabels = new JPanel(new BorderLayout());
pMusicTemp.add(pMusicTempLabels, BorderLayout.WEST);
pMusicTempLabels.add(new JLabel(getUIText("MusicListEditor_LabelMusic" + i)), BorderLayout.WEST);
JPanel pMusicTempTexts = new JPanel(new BorderLayout());
pMusicTemp.add(pMusicTempTexts, BorderLayout.EAST);
txtfldMusicFileNames[i] = new JTextField(45);
txtfldMusicFileNames[i].setComponentPopupMenu(new TextFieldPopupMenu(txtfldMusicFileNames[i]));
txtfldMusicFileNames[i].setText(propMusic.getProperty("music.filename." + i, ""));
pMusicTempTexts.add(txtfldMusicFileNames[i], BorderLayout.CENTER);
JPanel pMusicTempTextsButtons = new JPanel(new BorderLayout());
pMusicTempTexts.add(pMusicTempTextsButtons, BorderLayout.EAST);
chkboxNoLoop[i] = new JCheckBox();
chkboxNoLoop[i].setToolTipText(getUIText("MusicListEditor_NoLoop_Tip"));
chkboxNoLoop[i].setSelected(propMusic.getProperty("music.noloop." + i, false));
pMusicTempTextsButtons.add(chkboxNoLoop[i], BorderLayout.WEST);
JButton btnClear = new JButton(getUIText("MusicListEditor_Clear"));
btnClear.setToolTipText(getUIText("MusicListEditor_Clear_Tip"));
btnClear.setActionCommand("Clear" + i);
btnClear.addActionListener(this);
pMusicTempTextsButtons.add(btnClear, BorderLayout.CENTER);
JButton btnOpen = new JButton(getUIText("MusicListEditor_OpenFileDialog"));
btnOpen.setToolTipText(getUIText("MusicListEditor_OpenFileDialog_Tip"));
btnOpen.setActionCommand("OpenFileDialog" + i);
btnOpen.addActionListener(this);
pMusicTempTextsButtons.add(btnOpen, BorderLayout.EAST);
}
// The bottom of the screen buttonKind
JPanel pButtons = new JPanel();
pButtons.setLayout(new BoxLayout(pButtons, BoxLayout.X_AXIS));
pButtons.setAlignmentX(LEFT_ALIGNMENT);
this.add(pButtons);
JButton btnOK = new JButton(getUIText("MusicListEditor_OK"));
btnOK.addActionListener(this);
btnOK.setActionCommand("OK");
btnOK.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
btnOK.setMnemonic('O');
pButtons.add(btnOK);
JButton btnCancel = new JButton(getUIText("MusicListEditor_Cancel"));
btnCancel.addActionListener(this);
btnCancel.setActionCommand("Cancel");
btnCancel.setMaximumSize(new Dimension(Short.MAX_VALUE, 30));
btnCancel.setMnemonic('C');
pButtons.add(btnCancel);
// File Filter
hashmapFileFilters = new HashMap<String, SimpleFileFilter>();
hashmapFileFilters.put(".wav", new SimpleFileFilter(".wav", getUIText("FileChooser_wav")));
hashmapFileFilters.put(".xm", new SimpleFileFilter(".xm", getUIText("FileChooser_xm")));
hashmapFileFilters.put(".mod", new SimpleFileFilter(".mod", getUIText("FileChooser_mod")));
hashmapFileFilters.put(".aif", new SimpleFileFilter(".aif", getUIText("FileChooser_aif")));
hashmapFileFilters.put(".aiff", new SimpleFileFilter(".aif", getUIText("FileChooser_aiff")));
hashmapFileFilters.put(".ogg", new SimpleFileFilter(".ogg", getUIText("FileChooser_ogg")));
// File selection dialog
fileChooser = new JFileChooser();
Iterator<SimpleFileFilter> it = hashmapFileFilters.values().iterator();
while(it.hasNext()) {
SimpleFileFilter filter = it.next();
fileChooser.addChoosableFileFilter(filter);
}
}
public ConvertPanel(List<ConvertSubPanel> bq)
{
super(new BorderLayout());
statusLabel = new JLabel();
TaskStrategyListener tsl = (source, string) -> statusLabel.setText(string);
TaskStrategyMessage.addTaskStrategyListener(tsl);
properties = new ObjectCache();
Box buttonBox = Box.createHorizontalBox();
prevButton = new JButton("< Previous");
prevButton.setMnemonic('P');
prevButton.addActionListener(new PreviousButtonListener());
prevButton.setEnabled(false); // FUTURE Need to reenable this
buttonBox.add(prevButton);
nextButton = new JButton("Next >");
nextButton.setMnemonic('N');
pl = new ProgressListener()
{
@Override
public void progressAllowed(ProgressEvent pe)
{
if (pe.getID() == ProgressEvent.AUTO_ADVANCE)
{
proceedToNextPanel();
}
else
{
nextButton.setEnabled(true);
}
}
@Override
public void progressNotAllowed(ProgressEvent pe)
{
nextButton.setEnabled(false);
}
};
nextButton.addActionListener(arg0 -> proceedToNextPanel());
buttonBox.add(nextButton);
cancelButton = new JButton("Cancel");
cancelButton.addActionListener(arg0 -> checkExit());
buttonBox.add(cancelButton);
finishButton = new JButton("Finish");
finishButton.addActionListener(arg0 -> {
PCGenDataConvert.savePrefs();
System.exit(0);
});
finishButton.setVisible(false);
buttonBox.add(finishButton);
basePanel.setPreferredSize(new Dimension(800, 500));
JScrollPane jsp = new JScrollPane(basePanel);
jsp.setHorizontalScrollBarPolicy(ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
jsp.setVerticalScrollBarPolicy(ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED);
add(jsp);
JPanel buttonLayout = new JPanel(new GridBagLayout());
GridBagConstraints gbc = new GridBagConstraints();
Utility.buildRelativeConstraints(gbc, 1, 1, 1.0, 0, GridBagConstraints.HORIZONTAL, GridBagConstraints.WEST);
gbc.insets = new Insets(0, 10, 5, 10);
buttonLayout.add(statusLabel, gbc);
Utility.buildRelativeConstraints(gbc, GridBagConstraints.REMAINDER, 1, 0, 0, GridBagConstraints.NONE,
GridBagConstraints.EAST);
buttonLayout.add(buttonBox, gbc);
add(buttonLayout, BorderLayout.SOUTH);
queue = bq;
runNextPanel();
}
private void addButton(JPanel buttons, String rkey, int mnemonic, ActionListener action) {
JButton but = new JButton(getResourceString(rkey));
but.setMnemonic(mnemonic);
buttons.add(but);
but.addActionListener(action);
}
private void initVerticalToolbar(ActionListener outputListener) {
URL url = getClass().getResource(IMG_PREFIX + "row_add.png"); // NOI18N
insert = new JButton(new ImageIcon(url));
insert.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_insert")+" (Alt+I)");
insert.setMnemonic('I');
insert.addActionListener(outputListener);
insert.setEnabled(false);
processButton(insert);
editButtons[0] = insert;
url = getClass().getResource(IMG_PREFIX + "row_delete.png"); // NOI18N
deleteRow = new JButton(new ImageIcon(url));
deleteRow.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_deleterow"));
deleteRow.addActionListener(outputListener);
deleteRow.setEnabled(false);
processButton(deleteRow);
editButtons[1] = deleteRow;
url = getClass().getResource(IMG_PREFIX + "row_commit.png"); // NOI18N
commit = new JButton(new ImageIcon(url));
commit.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_commit_all"));
commit.addActionListener(outputListener);
commit.setEnabled(false);
processButton(commit);
editButtons[2] = commit;
url = getClass().getResource(IMG_PREFIX + "cancel_edits.png"); // NOI18N
cancel = new JButton(new ImageIcon(url));
cancel.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_cancel_edits_all"));
cancel.addActionListener(outputListener);
cancel.setEnabled(false);
processButton(cancel);
editButtons[3] = cancel;
//add truncate button
url = getClass().getResource(IMG_PREFIX + "table_truncate.png"); // NOI18N
truncateButton = new JButton(new ImageIcon(url));
truncateButton.setToolTipText(NbBundle.getMessage(DataViewUI.class, "TOOLTIP_truncate_table")+" (Alt+T)");
truncateButton.setMnemonic('T');
truncateButton.addActionListener(outputListener);
truncateButton.setEnabled(false);
processButton(truncateButton);
editButtons[4] = truncateButton;
}
/**
* Builds a parameters pane.
*/
private void buildSAXParamsPane() {
saxParametersPane = new JPanel();
saxParametersPane.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(BevelBorder.LOWERED), "SAX parameteres", TitledBorder.LEFT,
TitledBorder.CENTER, new Font(TITLE_FONT, Font.PLAIN, 10)));
// insets: T, L, B, R.
MigLayout saxPaneLayout = new MigLayout("insets 3 2 2 2",
"[][]10[][fill,grow]10[][fill,grow]10[][fill,grow]10[][]", "[]");
saxParametersPane.setLayout(saxPaneLayout);
// the sliding window parameter
JLabel slideWindowLabel = new JLabel("Slide the window");
useSlidingWindowCheckBox = new JCheckBox();
useSlidingWindowCheckBox.setSelected(this.controller.getSession().useSlidingWindow);
useSlidingWindowCheckBox.setActionCommand(USE_SLIDING_WINDOW_ACTION_KEY);
useSlidingWindowCheckBox.addActionListener(this);
windowSizeLabel = new JLabel("Window size:");
SAXwindowSizeField = new JTextField(String.valueOf(this.controller.getSession().saxWindow));
paaSizeLabel = new JLabel("PAA size:");
SAXpaaSizeField = new JTextField(String.valueOf(this.controller.getSession().saxPAA));
JLabel alphabetSizeLabel = new JLabel("Alphabet size:");
SAXalphabetSizeField = new JTextField(String.valueOf(this.controller.getSession().saxAlphabet));
saxParametersPane.add(slideWindowLabel);
saxParametersPane.add(useSlidingWindowCheckBox);
saxParametersPane.add(windowSizeLabel);
saxParametersPane.add(SAXwindowSizeField);
saxParametersPane.add(paaSizeLabel);
saxParametersPane.add(SAXpaaSizeField);
saxParametersPane.add(alphabetSizeLabel);
saxParametersPane.add(SAXalphabetSizeField);
guessParametersButton = new JButton("Guess");
guessParametersButton.setMnemonic('G');
guessParametersButton.setActionCommand(GUESS_PARAMETERS);
guessParametersButton.addActionListener(this);
saxParametersPane.add(guessParametersButton, "");
// numerosity reduction pane
//
numerosityReductionPane = new JPanel();
numerosityReductionPane.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(BevelBorder.LOWERED), "Numerosity reduction",
TitledBorder.LEFT, TitledBorder.CENTER, new Font(TITLE_FONT, Font.PLAIN, 10)));
// insets: T, L, B, R.
MigLayout numerosityPaneLayout = new MigLayout("insets 3 2 10 2", "[]5[]5[]", "[]");
numerosityReductionPane.setLayout(numerosityPaneLayout);
numerosityReductionOFFButton.setActionCommand(NumerosityReductionStrategy.NONE.toString());
numerosityButtonsGroup.add(numerosityReductionOFFButton);
numerosityReductionOFFButton.addActionListener(this);
numerosityReductionPane.add(numerosityReductionOFFButton);
numerosityReductionExactButton.setActionCommand(NumerosityReductionStrategy.EXACT.toString());
numerosityButtonsGroup.add(numerosityReductionExactButton);
numerosityReductionExactButton.addActionListener(this);
numerosityReductionPane.add(numerosityReductionExactButton);
numerosityReductionMINDISTButton
.setActionCommand(NumerosityReductionStrategy.MINDIST.toString());
numerosityButtonsGroup.add(numerosityReductionMINDISTButton);
numerosityReductionMINDISTButton.addActionListener(this);
numerosityReductionPane.add(numerosityReductionMINDISTButton);
this.controller.getSession().numerosityReductionStrategy = NumerosityReductionStrategy.EXACT;
numerosityReductionExactButton.setSelected(true);
// PROCESS button
//
discretizeButton = new JButton("Discretize");
discretizeButton.setMnemonic('P');
discretizeButton.setActionCommand(PROCESS_DATA);
discretizeButton.addActionListener(this);
discretizePane = new JPanel();
discretizePane.setBorder(BorderFactory.createTitledBorder(
BorderFactory.createEtchedBorder(BevelBorder.LOWERED), "Hit to run GI", TitledBorder.LEFT,
TitledBorder.CENTER, new Font(TITLE_FONT, Font.PLAIN, 10)));
// insets: T, L, B, R.
MigLayout processPaneLayout = new MigLayout("insets 3 2 4 2", "5[]5", "[]");
discretizePane.setLayout(processPaneLayout);
discretizePane.add(discretizeButton, "");
}
/**
* Create a new page.
*/
Page() {
this.setLayout(new SBoxLayout(SBoxLayout.VERTICAL));
JComponent panels = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
add(panels, SBoxLayout.constraint(SLayout.EXPAND_X,
SLayout.EXPAND_Y));
indexArea = new PrettyEditorPane();
indexArea.addHyperlinkListener(this);
indexScrollPane = new JScrollPane(indexArea);
// Fixed width
indexScrollPane.setMaximumSize(new Dimension(INDEX_WIDTH, Integer.MAX_VALUE));
indexScrollPane.setMinimumSize(new Dimension(INDEX_WIDTH, 0));
// Turn off caret following
Caret caret = indexArea.getCaret();
if (caret instanceof DefaultCaret) {
((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE);
}
panels.add(indexScrollPane, SLayout.EXPAND_Y);
contentArea = new PrettyEditorPane();
// Does not need a listener. There should be no links
contentScrollPane = new JScrollPane(contentArea);
panels.add(contentScrollPane, SBoxLayout.constraint(SLayout.EXPAND_X,
SLayout.EXPAND_Y));
JComponent buttonBox = SBoxLayout.createContainer(SBoxLayout.HORIZONTAL, SBoxLayout.COMMON_PADDING);
buttonBox.setAlignmentX(RIGHT_ALIGNMENT);
buttonBox.setBorder(BorderFactory.createEmptyBorder(SBoxLayout.COMMON_PADDING,
0, SBoxLayout.COMMON_PADDING, SBoxLayout.COMMON_PADDING));
add(buttonBox);
// A button for reloading the page contents
JButton refresh = new JButton("Update");
refresh.setMnemonic(KeyEvent.VK_U);
refresh.setAlignmentX(Component.RIGHT_ALIGNMENT);
refresh.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent event) {
update();
}
});
buttonBox.add(refresh);
JButton closeButton = new JButton("Close");
closeButton.setMnemonic(KeyEvent.VK_C);
closeButton.addActionListener(new ActionListener() {
@Override
public void actionPerformed(ActionEvent e) {
getWindow().dispose();
}
});
buttonBox.add(closeButton);
}