// TODO not used private void showNotification() { final WebDialog dialog = new WebDialog(); dialog.setUndecorated(true); dialog.setBackground(Color.BLACK); dialog.setBackground(StyleConstants.transparent); WebNotificationPopup popup = new WebNotificationPopup(PopupStyle.dark); popup.setIcon(Utils.getIcon("kontalk_small.png")); popup.setMargin(View.MARGIN_DEFAULT); popup.setDisplayTime(6000); popup.addNotificationListener( new NotificationListener() { @Override public void optionSelected(NotificationOption option) {} @Override public void accepted() {} @Override public void closed() { dialog.dispose(); } }); // content WebPanel panel = new WebPanel(); panel.setMargin(View.MARGIN_DEFAULT); panel.setOpaque(false); WebLabel title = new WebLabel("A new Message!"); title.setFontSize(View.FONT_SIZE_BIG); title.setForeground(Color.WHITE); panel.add(title, BorderLayout.NORTH); String text = "this is some message, and some longer text was added"; WebLabel message = new WebLabel(text); message.setForeground(Color.WHITE); panel.add(message, BorderLayout.CENTER); popup.setContent(panel); // popup.packPopup(); dialog.setSize(popup.getPreferredSize()); // set position on screen GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); GraphicsDevice gd = ge.getDefaultScreenDevice(); GraphicsConfiguration gc = gd.getDefaultConfiguration(); Rectangle screenBounds = gc.getBounds(); // get height of the task bar // doesn't work on all environments // Insets toolHeight = toolkit.getScreenInsets(popup.getGraphicsConfiguration()); int toolHeight = 40; dialog.setLocation( screenBounds.width - dialog.getWidth() - 10, screenBounds.height - toolHeight - dialog.getHeight()); dialog.setVisible(true); NotificationManager.showNotification(dialog, popup); }
/** * Creates and returns month panel. * * @return created month panel */ protected WebPanel createMonthPanel() { final WebPanel monthDays = new WebPanel(); monthDays.setOpaque(false); monthDays.setMargin( StyleConstants.shadeWidth - 1, StyleConstants.shadeWidth - 1, StyleConstants.shadeWidth - 1, StyleConstants.shadeWidth - 1); final TableLayout layout = new TableLayout( new double[][] { { TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL }, { TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL, TableLayout.FILL } }); layout.setHGap(0); layout.setVGap(0); monthDays.setLayout(layout); return monthDays; }
/** Constructs new directory chooser panel. */ public WebDirectoryChooserPanel() { super(); // Panel settings setOpaque(true); // Controls pane final WebToolBar contolsToolbar = new WebToolBar(WebToolBar.HORIZONTAL); contolsToolbar.setToolbarStyle(ToolbarStyle.attached); contolsToolbar.setFloatable(false); folderUp = new WebButton(FOLDER_UP_ICON); folderUp.setLanguage("weblaf.ex.dirchooser.folderup"); folderUp .addHotkey(WebDirectoryChooserPanel.this, Hotkey.ALT_UP) .setHotkeyDisplayWay(TooltipWay.down); folderUp.setRolloverDecoratedOnly(true); folderUp.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (selectedDirectory != null) { updateSelectedDirectory(selectedDirectory.getParentFile(), true, true); } } }); contolsToolbar.add(folderUp); folderHome = new WebButton(FOLDER_HOME_ICON); folderHome.setLanguage("weblaf.ex.dirchooser.home"); folderHome .addHotkey(WebDirectoryChooserPanel.this, Hotkey.ALT_H) .setHotkeyDisplayWay(TooltipWay.trailing); folderHome.setRolloverDecoratedOnly(true); folderHome.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { updateSelectedDirectory(FileUtils.getUserHome(), true, true); } }); contolsToolbar.add(folderHome); contolsToolbar.addSeparator(); for (final File file : FileTreeRootType.drives.getRoots()) { final WebButton root = new WebButton(FileUtils.getFileIcon(file)); TooltipManager.setTooltip(root, FileUtils.getDisplayFileName(file)); root.setRolloverDecoratedOnly(true); root.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { updateSelectedDirectory(file, true, true); } }); contolsToolbar.add(root); } refresh = new WebButton(REFRESH_ICON); refresh.setLanguage("weblaf.ex.dirchooser.refresh"); refresh .addHotkey(WebDirectoryChooserPanel.this, Hotkey.F5) .setHotkeyDisplayWay(TooltipWay.leading); refresh.setRolloverDecoratedOnly(true); refresh.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (selectedDirectory != null) { fileTree.reloadChilds(selectedDirectory); } else { fileTree.reloadRootNode(); } } }); contolsToolbar.add(refresh, ToolbarLayout.END); folderNew = new WebButton(FOLDER_NEW_ICON); folderNew.setLanguage("weblaf.ex.dirchooser.newfolder"); folderNew .addHotkey(WebDirectoryChooserPanel.this, Hotkey.CTRL_N) .setHotkeyDisplayWay(TooltipWay.down); folderNew.setRolloverDecoratedOnly(true); folderNew.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { if (selectedDirectory != null) { final String defaultName = LanguageManager.get("weblaf.ex.dirchooser.newfolder.name"); final String freeName = FileUtils.getAvailableName(selectedDirectory, defaultName); final File file = new File(selectedDirectory, freeName); if (file.mkdir()) { // Updating filestree fileTree.addFile(selectedDirectory, file); // Editing added folder name fileTree.startEditingFile(file); } else { final String message = LanguageManager.get("weblaf.ex.dirchooser.newfolder.error.text"); final String title = LanguageManager.get("weblaf.ex.dirchooser.newfolder.error.title"); WebOptionPane.showMessageDialog( WebDirectoryChooserPanel.this, message, title, WebOptionPane.ERROR_MESSAGE); } } } }); contolsToolbar.add(folderNew, ToolbarLayout.END); remove = new WebButton(REMOVE_ICON); remove.setLanguage("weblaf.ex.dirchooser.delete"); remove .addHotkey(WebDirectoryChooserPanel.this, Hotkey.DELETE) .setHotkeyDisplayWay(TooltipWay.down); remove.setRolloverDecoratedOnly(true); remove.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { final File file = fileTree.getSelectedFile(); if (file == null) { return; } // Displaying delete confirmation final String message = LanguageManager.get("weblaf.ex.dirchooser.delete.confirm.text"); final String title = LanguageManager.get("weblaf.ex.dirchooser.delete.confirm.title"); final int confirm = WebOptionPane.showConfirmDialog( WebDirectoryChooserPanel.this, message, title, WebOptionPane.YES_NO_OPTION, WebOptionPane.QUESTION_MESSAGE); // Proceed if delete was confirmed if (confirm == WebOptionPane.YES_OPTION) { // Retrieving index of deleted file node in parent node final FileTreeNode parentNode = fileTree.getSelectedNode().getParent(); final int index = parentNode.indexOfFileChild(file); final int count = parentNode.getChildCount(); // Removing file FileUtils.deleteFile(file); fileTree.removeFile(file); // Restoring selection fileTree.setSelectedNode( count == 1 ? parentNode : (index < count - 1 ? parentNode.getChildAt(index) : parentNode.getChildAt(index - 1))); } } }); contolsToolbar.add(remove, ToolbarLayout.END); // Path field webPathField = new WebPathField(selectedDirectory); webPathField.setFileFilter(filter); webPathField.addPathFieldListener( new PathFieldListener() { @Override public void directoryChanged(final File newDirectory) { updateSelectedDirectory(webPathField.getSelectedPath(), false, true); } }); // Files tree fileTree = new WebFileTree(FileTreeRootType.drives); fileTree.setVisibleRowCount(15); fileTree.setFileFilter(filter); fileTree.setSelectedFile(selectedDirectory, true); fileTree.setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); fileTree.setEditable(true); // Selected directory update fileTreeListener = new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent e) { updateSelectedDirectory(fileTree.getSelectedFile(), true, false); } }; fileTree.addTreeSelectionListener(fileTreeListener); // Toolbar update fileTree.addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(final TreeSelectionEvent e) { updateToolbarControlsState(); } }); // Tree scroll final WebScrollPane treeScroll = new WebScrollPane(fileTree); treeScroll.setPreferredWidth(400); // Panel content setLayout(new BorderLayout(0, 3)); add(contolsToolbar, BorderLayout.NORTH); final WebPanel panel = new WebPanel(new BorderLayout(0, 1)); panel.setMargin(0, 3, 2, 3); panel.add(webPathField, BorderLayout.NORTH); panel.add(treeScroll, BorderLayout.CENTER); add(panel, BorderLayout.CENTER); updateSelectedDirectory(null, true, true); updateToolbarControlsState(); }
/** * Constructs new calendar with the specified selected date. * * @param date selected date */ public WebCalendar(final Date date) { super(true); this.date = date != null ? new Date(date.getTime()) : null; this.shownDate = date != null ? new Date(date.getTime()) : new Date(); setDrawFocus(true); setRound(StyleConstants.smallRound); setLayout(new BorderLayout(0, 0)); putClientProperty(SwingUtils.HANDLES_ENABLE_STATE, true); // Main layout final WebPanel centerPanel = new WebPanel(); centerPanel.setOpaque(false); add(centerPanel, BorderLayout.CENTER); // Header panel final WebPanel header = new WebPanel(); header.setOpaque(false); add(header, BorderLayout.NORTH); previousSkip = WebButton.createIconWebButton(previousSkipIcon, StyleConstants.smallRound, true); previousSkip.setDrawFocus(false); previousSkip.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { changeYear(-1); } }); previous = WebButton.createIconWebButton(previousIcon, StyleConstants.smallRound, true); previous.setDrawFocus(false); previous.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { changeMonth(-1); } }); final WebPanel leftHeader = new WebPanel(new BorderLayout()); leftHeader.setOpaque(false); leftHeader.add(previousSkip, BorderLayout.WEST); leftHeader.add(previous, BorderLayout.EAST); header.add(leftHeader, BorderLayout.WEST); titlePanel = new ComponentTransition(createTitleLabel()); titlePanel.setOpaque(false); titlePanel.setTransitionEffect(new FadeTransitionEffect()); titlePanel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(final MouseEvent e) { if (SwingUtilities.isLeftMouseButton(e)) { setShownDate(new Date()); } } }); header.add(titlePanel, BorderLayout.CENTER); next = WebButton.createIconWebButton(nextIcon, StyleConstants.smallRound, true); next.setDrawFocus(false); next.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { changeMonth(1); } }); nextSkip = WebButton.createIconWebButton(nextSkipIcon, StyleConstants.smallRound, true); nextSkip.setDrawFocus(false); nextSkip.addActionListener( new ActionListener() { @Override public void actionPerformed(final ActionEvent e) { changeYear(1); } }); final WebPanel rightHeader = new WebPanel(new BorderLayout()); rightHeader.setOpaque(false); rightHeader.add(next, BorderLayout.WEST); rightHeader.add(nextSkip, BorderLayout.EAST); header.add(rightHeader, BorderLayout.EAST); // Week days weekHeaders = new WebPanel(); weekHeaders.setUndecorated(false); weekHeaders.setDrawSides(true, false, true, false); weekHeaders.setShadeWidth(0); weekHeaders.setOpaque(false); weekHeaders.setMargin( StyleConstants.shadeWidth, StyleConstants.shadeWidth - 1, StyleConstants.shadeWidth + 1, StyleConstants.shadeWidth - 1); weekHeaders.setLayout( new TableLayout( new double[][] { { TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL, TableLayout.PREFERRED, TableLayout.FILL }, {TableLayout.PREFERRED} })); centerPanel.add(weekHeaders, BorderLayout.NORTH); updateWeekHeaders(); // Month days monthDays = createMonthPanel(); updateMonth(monthDays); monthDaysTransition = new ComponentTransition(monthDays); monthDaysTransition.setOpaque(false); monthDaysTransition.addTransitionListener( new TransitionAdapter() { @Override public void transitionFinished() { requestFocusToSelected(); } }); centerPanel.add(monthDaysTransition, BorderLayout.CENTER); }
private WebButton createSettings() { WebButton settings = new WebButton(new ImageIcon(SourceViewer.class.getResource("icons/settings.png"))); settings.setDrawFocus(false); settings.setRolloverDecoratedOnly(true); WebButtonPopup wbp = new WebButtonPopup(settings, PopupWay.downLeft); WebPanel popupContent = new WebPanel(new VerticalFlowLayout(5, 5)); popupContent.setMargin(5); popupContent.setOpaque(false); wbp.setContent(popupContent); theme = new WebComboBox(EditorTheme.values()); theme.registerSettings(SETTINGS_PREFIX + "theme", 0); theme.setRenderer( new WebComboBoxCellRenderer(theme) { @Override public Component getListCellRendererComponent( JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { EditorTheme editorTheme = (EditorTheme) value; WebComboBoxElement renderer = (WebComboBoxElement) super.getListCellRendererComponent( list, value, index, isSelected, cellHasFocus); renderer.setIcon(editorTheme.getIcon()); renderer.setText(editorTheme.getName()); return renderer; } }); theme.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { synchronized (activeEditorsLock) { final String themeName = theme.getSelectedItem().toString().toLowerCase(); for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) { loadTheme(themeName, entry.getValue()); } } } }); popupContent.add(theme); allowCodeFolding = new WebToggleButton(loadEditorIcon("allowCodeFolding")); allowCodeFolding.registerSettings(SETTINGS_PREFIX + "allowCodeFolding", false); allowCodeFolding.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { synchronized (activeEditorsLock) { for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) { entry.getValue().setCodeFoldingEnabled(allowCodeFolding.isSelected()); } } } }); final WebLabel allowCodeFoldingLabel = new WebLabel("Allow code folding"); allowCodeFoldingLabel.setDrawShade(true); allowCodeFoldingLabel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtils.isLeftMouseButton(e)) { allowCodeFolding.requestFocusInWindow(); allowCodeFolding.doClick(); } } }); popupContent.add(new GroupPanel(5, allowCodeFolding, allowCodeFoldingLabel)); paintTabLines = new WebToggleButton(loadEditorIcon("paintTabLines")); paintTabLines.registerSettings(SETTINGS_PREFIX + "paintTabLines", false); paintTabLines.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { synchronized (activeEditorsLock) { for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) { entry.getValue().setPaintTabLines(paintTabLines.isSelected()); } } } }); final WebLabel paintTabLinesLabel = new WebLabel("Paint tab lines"); paintTabLinesLabel.setDrawShade(true); paintTabLinesLabel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtils.isLeftMouseButton(e)) { paintTabLines.requestFocusInWindow(); paintTabLines.doClick(); } } }); popupContent.add(new GroupPanel(5, paintTabLines, paintTabLinesLabel)); showWhitespaces = new WebToggleButton(loadEditorIcon("showWhitespaces")); showWhitespaces.registerSettings(SETTINGS_PREFIX + "showWhitespaces", false); showWhitespaces.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { synchronized (activeEditorsLock) { for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) { entry.getValue().setWhitespaceVisible(showWhitespaces.isSelected()); } } } }); final WebLabel showWhitespacesLabel = new WebLabel("Show whitespaces"); showWhitespacesLabel.setDrawShade(true); showWhitespacesLabel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtils.isLeftMouseButton(e)) { showWhitespaces.requestFocusInWindow(); showWhitespaces.doClick(); } } }); popupContent.add(new GroupPanel(5, showWhitespaces, showWhitespacesLabel)); showEol = new WebToggleButton(loadEditorIcon("showEol")); showEol.registerSettings(SETTINGS_PREFIX + "showEol", false); showEol.addItemListener( new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { synchronized (activeEditorsLock) { for (Map.Entry<JarEntry, RSyntaxTextArea> entry : activeEditors.entrySet()) { entry.getValue().setEOLMarkersVisible(showEol.isSelected()); } } } }); final WebLabel showEolLabel = new WebLabel("Show end of line"); showEolLabel.setDrawShade(true); showEolLabel.addMouseListener( new MouseAdapter() { @Override public void mousePressed(MouseEvent e) { if (SwingUtils.isLeftMouseButton(e)) { showEol.requestFocusInWindow(); showEol.doClick(); } } }); popupContent.add(new GroupPanel(5, showEol, showEolLabel)); return settings; }
/** 初始化组件 */ private void initComponent() { WebLabel netSettingLbl = new WebLabel("Network Setting"); WebLabel typeLbl = new WebLabel("Type:"); WebLabel addressLbl = new WebLabel("Address:"); WebLabel portLbl = new WebLabel("Port:"); WebLabel usernameLbl = new WebLabel("Username:"******"Password:"******"Domain:"); typeCbx = new WebComboBox(); typeCbx.addItem("None"); typeCbx.addItem("Http"); typeCbx.addItem("Socks5"); typeCbx.addItem("Browser"); typeCbx.setDrawFocus(false); // field addressFld = new WebTextField(); portFld = new WebTextField(); usernameFld = new WebTextField(); passwordFld = new WebTextField(); domainFld = new WebTextField(); // label margin netSettingLbl.setMargin(15); Insets insets = new Insets(5, 5, 5, 5); typeLbl.setMargin(5, 37, 5, 5); addressLbl.setMargin(5, 14, 5, 5); portLbl.setMargin(5, 27, 5, 5); usernameLbl.setMargin(insets); passwordLbl.setMargin(insets); domainLbl.setMargin(insets); // size Dimension d1 = new Dimension(80, 30); Dimension d2 = new Dimension(100, 30); Dimension d3 = new Dimension(50, 30); // field properties typeCbx.setPreferredSize(d1); usernameFld.setPreferredSize(d1); addressFld.setPreferredSize(d2); passwordFld.setPreferredSize(d2); portFld.setPreferredSize(d3); domainFld.setPreferredSize(d3); // group panel GroupPanel g1 = new GroupPanel(true, typeLbl, typeCbx, addressLbl, addressFld, portLbl, portFld); GroupPanel g2 = new GroupPanel( true, usernameLbl, usernameFld, passwordLbl, passwordFld, domainLbl, domainFld); g1.setPreferredSize(new Dimension(this.getWidth(), 30)); // test button Dimension dBtn = new Dimension(80, 30); WebButton testBtn = new WebButton("Test"); WebButton okBtn = new WebButton("OK"); WebButton cancelBtn = new WebButton("Cancel"); // size testBtn.setPreferredSize(dBtn); okBtn.setPreferredSize(dBtn); cancelBtn.setPreferredSize(dBtn); // action testBtn.setAction(view.getActionService().getActionMap(this).get("processTestAction")); okBtn.setAction(view.getActionService().getActionMap(this).get("processOKAction")); cancelBtn.setAction(view.getActionService().getActionMap(this).get("processCancelAction")); // reset text testBtn.setText("Test"); okBtn.setText("OK"); cancelBtn.setText("Cancel"); // layout panel WebPanel testPl = new WebPanel(); testPl.add(testBtn, BorderLayout.LINE_END); testPl.setOpaque(false); testPl.setMargin(20, 0, 5, 30); WebPanel confimBtnPl = new WebPanel(); confimBtnPl.add(new GroupPanel(true, okBtn, cancelBtn), BorderLayout.LINE_END); confimBtnPl.setMargin(10, 0, 5, 30); confimBtnPl.setOpaque(false); // add to content add(new GroupPanel(false, netSettingLbl, g1, g2, testPl, confimBtnPl)); }