private void initComponents() { { DefaultTableColumnModel model = new DefaultTableColumnModel(); TableColumn column = new TableColumn(0); column.setResizable(true); model.addColumn(column); column = new TableColumn(1, 120, new ButtonCellRenderer(), null); column.setMaxWidth(120); column.setResizable(false); model.addColumn(column); companionsTable.setAutoResizeMode(JTable.AUTO_RESIZE_ALL_COLUMNS); companionsTable.getTableHeader().setResizingAllowed(false); companionsTable.setAutoCreateColumnsFromModel(false); companionsTable.setColumnModel(model); } companionsTable.setIntercellSpacing(new Dimension(0, 0)); companionsTable.setFocusable(false); companionsTable.setRowHeight(23); companionsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); setLeftComponent(new JScrollPane(companionsTable)); JPanel rightPane = new JPanel(new BorderLayout()); infoPane.setOpaque(false); infoPane.setEditable(false); infoPane.setFocusable(true); infoPane.setContentType("text/html"); // $NON-NLS-1$ rightPane.add(new JScrollPane(infoPane), BorderLayout.CENTER); JPanel buttonPane = new JPanel(new FlowLayout()); buttonPane.add(loadButton); rightPane.add(buttonPane, BorderLayout.SOUTH); setRightComponent(rightPane); }
private void jbInit() throws Exception { border1 = BorderFactory.createEmptyBorder(20, 20, 20, 20); contentPane.setBorder(border1); contentPane.setLayout(borderLayout1); controlsPane.setLayout(gridLayout1); gridLayout1.setColumns(1); gridLayout1.setHgap(10); gridLayout1.setRows(0); gridLayout1.setVgap(10); okButton.setVerifyInputWhenFocusTarget(true); okButton.setMnemonic('O'); okButton.setText("OK"); buttonsPane.setLayout(flowLayout1); flowLayout1.setAlignment(FlowLayout.CENTER); messagePane.setEditable(false); messagePane.setText(""); borderLayout1.setHgap(10); borderLayout1.setVgap(10); this.setTitle("Subscription Authorization"); this.getContentPane().add(contentPane, BorderLayout.CENTER); contentPane.add(controlsPane, BorderLayout.SOUTH); controlsPane.add(responsesComboBox, null); controlsPane.add(buttonsPane, null); buttonsPane.add(okButton, null); contentPane.add(messageScrollPane, BorderLayout.CENTER); messageScrollPane.getViewport().add(messagePane, null); }
TextPanel(String file) { super(new BorderLayout()); JEditorPane text = new JEditorPane(); try { text.setPage(TextPanel.this.getClass().getResource(file)); } catch (Exception e) { text.setText("Error loading '" + file + "'"); e.printStackTrace(); } text.setEditable(false); JScrollPane scrollPane = new JScrollPane(text); Dimension dim = new Dimension(); dim.width = 450; dim.height = 200; scrollPane.setPreferredSize(dim); TextPanel.this.add(BorderLayout.CENTER, scrollPane); }
private void jbInit() throws Exception { //////////////////////////////////////////////////////// // Init LAF //////////////////////////////////////////////////////// ButtonGroup grpLAF = new ButtonGroup(); ActionListener lsnLAF = new ActionListener() { public void actionPerformed(ActionEvent evt) { int iIndex = mvtLAFItem.indexOf(evt.getSource()); if (iIndex >= 0) changeLAF(iIndex); } }; //////////////////////////////////////////////////////// UIManager.LookAndFeelInfo laf = new UIManager.LookAndFeelInfo( "Kunststoff", "com.incors.plaf.kunststoff.KunststoffLookAndFeel"); marrLaf = UIManager.getInstalledLookAndFeels(); int iIndex = 0; while (iIndex < marrLaf.length && !marrLaf[iIndex].getName().equals(laf.getName())) iIndex++; if (iIndex >= marrLaf.length) { UIManager.installLookAndFeel(laf); marrLaf = UIManager.getInstalledLookAndFeels(); } for (iIndex = 0; iIndex < marrLaf.length; iIndex++) { JMenuItem mnu = new JRadioButtonMenuItem(marrLaf[iIndex].getName()); mnu.addActionListener(lsnLAF); mvtLAFItem.addElement(mnu); mnuUI.add(mnu); grpLAF.add(mnu); } mnuUI.addSeparator(); //////////////////////////////////////////////////////// // Init language //////////////////////////////////////////////////////// ButtonGroup grpLanguage = new ButtonGroup(); ActionListener lsnLanguage = new ActionListener() { public void actionPerformed(ActionEvent e) { int iIndex = mvtLanguageItem.indexOf(e.getSource()); if (iIndex >= 0) changeDictionary((String) mvtLanguage.elementAt(iIndex)); } }; //////////////////////////////////////////////////////// String[] str = MonitorDictionary.getSupportedLanguage(); for (iIndex = 0; iIndex < str.length; iIndex++) { JMenuItem mnu = new JRadioButtonMenuItem(MonitorDictionary.getDictionary(str[iIndex]).getLanguage()); mnu.addActionListener(lsnLanguage); mvtLanguage.addElement(str[iIndex]); mvtLanguageItem.addElement(mnu); mnuUI.add(mnu); grpLanguage.add(mnu); } //////////////////////////////////////////////////////// // Add to main menu //////////////////////////////////////////////////////// mnuMain.removeAll(); mnuMain.add(mnuSystem); mnuSystem.add(mnuSystem_Login); mnuSystem.add(mnuSystem_ChangePassword); mnuSystem.addSeparator(); mnuSystem.add(mnuSystem_StopServer); mnuSystem.add(mnuSystem_EnableThreads); mnuMain.add(mnuUI); mnuMain.add(mnuHelp); mnuHelp.add(mnuHelp_About); //////////////////////////////////////////////////////// mnuMain.add(chkVietnamese); mnuMain.add(lblStatus); //////////////////////////////////////////////////////// pnlThread.setTabPlacement(JTabbedPane.LEFT); pnlThread.setTabLayoutPolicy(JTabbedPane.SCROLL_TAB_LAYOUT); //////////////////////////////////////////////////////// tblUser.addColumn("", 1, false); tblUser.addColumn("", 2, false, Global.FORMAT_DATE_TIME); tblUser.addColumn("", 3, false); //////////////////////////////////////////////////////// JPanel pnlMessage = new JPanel(); pnlMessage.setLayout(new GridBagLayout()); pnlMessage.add( new JScrollPane(txtBoard), new GridBagConstraints( 0, 0, 2, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0)); pnlMessage.add( txtMessage, new GridBagConstraints( 0, 1, 1, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0)); pnlMessage.add( btnSend, new GridBagConstraints( 1, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(2, 2, 2, 2), 0, 0)); txtBoard.setEditable(false); txtBoard.setAutoscrolls(true); txtBoard.setContentType("text/html"); clearAll(txtBoard); //////////////////////////////////////////////////////// JPanel pnlUserButton = new JPanel(new GridLayout(1, 2, 4, 4)); pnlUserButton.add(btnKick); pnlUserButton.add(btnRefresh); //////////////////////////////////////////////////////// JPanel pnlManager = new JPanel(new GridBagLayout()); pnlManager.add( new JScrollPane(tblUser), new GridBagConstraints( 0, 0, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 2, 2, 2), 0, 0)); pnlManager.add( pnlUserButton, new GridBagConstraints( 0, 1, 1, 1, 0.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.NONE, new Insets(4, 2, 4, 2), 0, 0)); //////////////////////////////////////////////////////// pnlUser.setDividerLocation(320); pnlUser.setLeftComponent(pnlManager); pnlUser.setRightComponent(pnlMessage); pnlUser.setOneTouchExpandable(true); //////////////////////////////////////////////////////// setOrientation(JSplitPane.VERTICAL_SPLIT); setOneTouchExpandable(true); pnlThread.setVisible(false); pnlUser.setVisible(false); setTopComponent(pnlThread); setBottomComponent(pnlUser); //////////////////////////////////////////////////////// pmn.add(mnuSelectAll); pmn.addSeparator(); pmn.add(mnuClearSelected); pmn.add(mnuClearAll); //////////////////////////////////////////////////////// setBorder(BorderFactory.createEmptyBorder()); pnlUser.setBorder(BorderFactory.createEmptyBorder()); pnlManager.setBorder( BorderFactory.createBevelBorder( javax.swing.border.BevelBorder.RAISED, Color.white, UIManager.getColor("Panel.background"), UIManager.getColor("Panel.background"), UIManager.getColor("Panel.background"))); pnlMessage.setBorder( BorderFactory.createBevelBorder( javax.swing.border.BevelBorder.RAISED, Color.white, UIManager.getColor("Panel.background"), UIManager.getColor("Panel.background"), UIManager.getColor("Panel.background"))); //////////////////////////////////////////////////////// Skin.applySkin(mnuMain); Skin.applySkin(tblUser); Skin.applySkin(pmn); Skin.applySkin(this); //////////////////////////////////////////////////////// // Default setting //////////////////////////////////////////////////////// Hashtable prt = null; try { prt = Global.loadHashtable(Global.FILE_CONFIG); } catch (Exception e) { prt = new Hashtable(); } changeLAF(Integer.parseInt(StringUtil.nvl(prt.get("LAF"), "0"))); changeDictionary(StringUtil.nvl(prt.get("Language"), "VN")); Skin.LANGUAGE_CHANGE_LISTENER = this; MonitorProcessor.setRootObject(this); updateKeyboardUI(); //////////////////////////////////////////////////////// // Event handler //////////////////////////////////////////////////////// tblUser.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getClickCount() > 1) btnKick.doClick(); } }); //////////////////////////////////////////////////////// btnRefresh.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent evt) { try { DDTP request = new DDTP(); request.setRequestID(String.valueOf(System.currentTimeMillis())); DDTP response = channel.sendRequest("ThreadProcessor", "queryUserList", request); if (response != null) { tblUser.setData((Vector) response.getReturn()); if (mstrChannel != null) removeUser(mstrChannel); } } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); } } }); //////////////////////////////////////////////////////// btnKick.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent evt) { int iSelected = tblUser.getSelectedRow(); if (iSelected < 0) return; int iResult = MessageBox.showConfirmDialog( pnlThread, mdic.getString("ConfirmKick"), Global.APP_NAME, MessageBox.YES_NO_OPTION); if (iResult == MessageBox.NO_OPTION) return; try { String strChannel = (String) tblUser.getRow(iSelected).elementAt(0); DDTP request = new DDTP(); request.setRequestID(String.valueOf(System.currentTimeMillis())); request.setString("strChannel", strChannel); DDTP response = channel.sendRequest("ThreadProcessor", "kickUser", request); } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); } } }); //////////////////////////////////////////////////////// txtMessage.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent evt) { btnSend.doClick(); } }); //////////////////////////////////////////////////////// btnSend.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent evt) { if (txtMessage.getText().length() == 0) return; try { DDTP request = new DDTP(); request.setString("strMessage", txtMessage.getText()); channel.sendRequest("ThreadProcessor", "sendMessage", request); txtMessage.setText(""); } catch (Exception e) { e.printStackTrace(); MessageBox.showMessageDialog(pnlThread, e, Global.APP_NAME, MessageBox.ERROR_MESSAGE); } } }); //////////////////////////////////////////////////////// mnuClearAll.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { clearAll(txtBoard); } }); //////////////////////////////////////////////////////// mnuClearSelected.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { txtBoard.setEditable(true); txtBoard.replaceSelection(""); txtBoard.setEditable(false); } }); //////////////////////////////////////////////////////// mnuSelectAll.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { txtBoard.requestFocus(); txtBoard.selectAll(); } }); //////////////////////////////////////////////////////// txtBoard.addMouseListener( new MouseAdapter() { public void mouseClicked(MouseEvent e) { if (e.getButton() == e.BUTTON3) pmn.show(txtBoard, e.getX(), e.getY()); } }); //////////////////////////////////////////////////////// mnuSystem_Login.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { login(); } }); //////////////////////////////////////////////////////// mnuSystem_ChangePassword.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { changePassword(); } }); //////////////////////////////////////////////////////// mnuSystem_StopServer.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { stopServer(); } }); //////////////////////////////////////////////////////// mnuSystem_EnableThreads.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { manageThreads(); } }); //////////////////////////////////////////////////////// mnuHelp_About.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { WindowManager.centeredWindow(new DialogAbout(PanelThreadManager.this)); } }); //////////////////////////////////////////////////////// chkVietnamese.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(ActionEvent e) { switchKeyboard(); } }); }
/** Construct a new "about…" dialog */ public DialogAbout(MDIManager mdimgr) { buttonOk = new JButton(localize("button.OK")); buttonOk.addActionListener(this); JPanel buttonPanel = new JPanel(new FlowLayout(), false); buttonPanel.add(buttonOk); JPanel logoPanel = new JPanel(new FlowLayout(), false); logoPanel.setBorder(new EmptyBorder(10, 10, 10, 10)); logoPanel.add(PEToolKit.createJLabel("Frankenstein")); JPanel infoPanel = new JPanel(new GridLayout(9, 1, 5, 5), true); infoPanel.setBorder(new EmptyBorder(10, 60, 10, 10)); infoPanel.add( new JLabel("jPicEdt " + Version.getVersion() + " Built " + Version.getBuildDate())); infoPanel.add(new JLabel(localize("about.APictureEditorFor"))); final String[] addressLines = { "(c) Sylvain Reynal", "É.N.S.É.A. - Dept. of Physics", "6, avenue du Ponceau", "F-95014 CERGY Cedex", "Fax: +33 (0) 130 736 667", "*****@*****.**", "http://www.jpicedt.org" }; for (String addressLine : addressLines) infoPanel.add(new JLabel(addressLine)); JTabbedPane caveatPanel = new JTabbedPane(); String[] tabKeys = {"license.lines", "license.thirdparty.lines"}; for (String tabKey : tabKeys) { JEditorPane caveatTA = new JEditorPane(); caveatTA.setContentType("text/html; charset=" + localize(tabKey + ".encoding")); caveatTA.setEditable(false); caveatTA.setPreferredSize(new Dimension(485, 300)); JScrollPane scrollCaveat = new JScrollPane(caveatTA); caveatTA.setText(localize(tabKey)); caveatPanel.addTab(localize(tabKey + ".tabname"), null, scrollCaveat, null); } caveatPanel.setBorder(BorderFactory.createEtchedBorder()); JPanel upperPanel = new JPanel(new BorderLayout(), false); upperPanel.add(logoPanel, BorderLayout.WEST); upperPanel.add(infoPanel, BorderLayout.CENTER); upperPanel.add(caveatPanel, BorderLayout.SOUTH); upperPanel.setBorder(BorderFactory.createEtchedBorder()); JPanel contentPane = new JPanel(new BorderLayout(5, 5)); contentPane.add(upperPanel, BorderLayout.NORTH); contentPane.add(buttonPanel, BorderLayout.SOUTH); String title = localize("about.AboutPicEdt") + " " + Version.getVersion(); boolean modal = true; frame = mdimgr.createDialog(title, modal, contentPane); frame.setResizable(true); frame.setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE); Dimension dlgSize = frame.getPreferredSize(); frame.setSize(dlgSize); // this.pack(); frame.setVisible(true); }
private void updateList(final List<WCInfo> infoList) { myPanel.removeAll(); final Insets nullIndent = new Insets(1, 3, 1, 0); final GridBagConstraints gb = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, new Insets(2, 2, 0, 0), 0, 0); gb.insets.left = 4; myPanel.add(myRefreshLabel, gb); gb.insets.left = 1; final LocalFileSystem lfs = LocalFileSystem.getInstance(); final Insets topIndent = new Insets(10, 3, 0, 0); for (final WCInfo wcInfo : infoList) { final VirtualFile vf = lfs.refreshAndFindFileByIoFile(new File(wcInfo.getPath())); final VirtualFile root = (vf == null) ? wcInfo.getVcsRoot() : vf; final JEditorPane editorPane = new JEditorPane(UIUtil.HTML_MIME, ""); editorPane.setEditable(false); editorPane.setFocusable(true); editorPane.setBackground(UIUtil.getPanelBackground()); editorPane.addHyperlinkListener( new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { if (e.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { if (CONFIGURE_BRANCHES.equals(e.getDescription())) { if (!checkRoot(root, wcInfo.getPath(), " invoke Configure Branches")) return; BranchConfigurationDialog.configureBranches(myProject, root, true); } else if (FIX_DEPTH.equals(e.getDescription())) { final int result = Messages.showOkCancelDialog( myVcs.getProject(), "You are going to checkout into '" + wcInfo.getPath() + "' with 'infinity' depth.\n" + "This will update your working copy to HEAD revision as well.", "Set working copy infinity depth", Messages.getWarningIcon()); if (result == 0) { // update of view will be triggered by roots changed event SvnCheckoutProvider.checkout( myVcs.getProject(), new File(wcInfo.getPath()), wcInfo.getRootUrl(), SVNRevision.HEAD, SVNDepth.INFINITY, false, null, wcInfo.getFormat()); } } else if (CHANGE_FORMAT.equals(e.getDescription())) { changeFormat(wcInfo); } else if (MERGE_FROM.equals(e.getDescription())) { if (!checkRoot(root, wcInfo.getPath(), " invoke Merge From")) return; mergeFrom(wcInfo, root, editorPane); } } } private boolean checkRoot( VirtualFile root, final String path, final String actionName) { if (root == null) { Messages.showWarningDialog( myProject, "Invalid working copy root: " + path, "Can not " + actionName); return false; } return true; } }); editorPane.setBorder(null); editorPane.setText(formatWc(wcInfo)); final JPanel copyPanel = new JPanel(new GridBagLayout()); final GridBagConstraints gb1 = new GridBagConstraints( 0, 0, 1, 1, 0, 0, GridBagConstraints.NORTHWEST, GridBagConstraints.NONE, nullIndent, 0, 0); gb1.insets.top = 1; gb1.gridwidth = 3; gb.insets = topIndent; gb.fill = GridBagConstraints.HORIZONTAL; ++gb.gridy; final JPanel contForCopy = new JPanel(new BorderLayout()); contForCopy.add(copyPanel, BorderLayout.WEST); myPanel.add(contForCopy, gb); copyPanel.add(editorPane, gb1); gb1.insets = nullIndent; } myPanel.revalidate(); myPanel.repaint(); }
public EditorPaneFrame() { setSize(DEFAULT_WIDTH, DEFAULT_HEIGHT); final Stack<String> urlStack = new Stack<>(); final JEditorPane editorPane = new JEditorPane(); final JTextField url = new JTextField(30); // set up hyperlink listener editorPane.setEditable(false); editorPane.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); add(new JScrollPane(editorPane), BorderLayout.CENTER); // put all control components in a panel JPanel panel = new JPanel(); panel.add(new JLabel("URL")); panel.add(url); panel.add(loadButton); panel.add(backButton); panel.add(new JLabel("Editable")); panel.add(editable); add(panel, BorderLayout.SOUTH); }
/** * Constructs a X509 certificate panel. * * @param certificates <tt>X509Certificate</tt> objects */ public X509CertificatePanel(Certificate[] certificates) { setLayout(new BorderLayout(5, 5)); // Certificate chain list TransparentPanel topPanel = new TransparentPanel(new BorderLayout()); topPanel.add( new JLabel( "<html><body><b>" + R.getI18NString("service.gui.CERT_INFO_CHAIN") + "</b></body></html>"), BorderLayout.NORTH); DefaultMutableTreeNode top = new DefaultMutableTreeNode(); DefaultMutableTreeNode previous = top; for (int i = certificates.length - 1; i >= 0; i--) { Certificate cert = certificates[i]; DefaultMutableTreeNode next = new DefaultMutableTreeNode(cert); previous.add(next); previous = next; } JTree tree = new JTree(top); tree.setBorder(new BevelBorder(BevelBorder.LOWERED)); tree.setRootVisible(false); tree.setExpandsSelectedPaths(true); tree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION); tree.setCellRenderer( new DefaultTreeCellRenderer() { @Override public Component getTreeCellRendererComponent( JTree tree, Object value, boolean sel, boolean expanded, boolean leaf, int row, boolean hasFocus) { JLabel component = (JLabel) super.getTreeCellRendererComponent( tree, value, sel, expanded, leaf, row, hasFocus); if (value instanceof DefaultMutableTreeNode) { Object o = ((DefaultMutableTreeNode) value).getUserObject(); if (o instanceof X509Certificate) { component.setText(getSimplifiedName((X509Certificate) o)); } else { // We don't know how to represent this certificate type, // let's use the first 20 characters String text = o.toString(); if (text.length() > 20) { text = text.substring(0, 20); } component.setText(text); } } return component; } }); tree.getSelectionModel() .addTreeSelectionListener( new TreeSelectionListener() { @Override public void valueChanged(TreeSelectionEvent e) { valueChangedPerformed(e); } }); tree.setSelectionPath( new TreePath((((DefaultTreeModel) tree.getModel()).getPathToRoot(previous)))); topPanel.add(tree, BorderLayout.CENTER); add(topPanel, BorderLayout.NORTH); // Certificate details pane Caret caret = infoTextPane.getCaret(); if (caret instanceof DefaultCaret) { ((DefaultCaret) caret).setUpdatePolicy(DefaultCaret.NEVER_UPDATE); } /* * Make JEditorPane respect our default font because we will be using it * to just display text. */ infoTextPane.putClientProperty(JEditorPane.HONOR_DISPLAY_PROPERTIES, true); infoTextPane.setOpaque(false); infoTextPane.setEditable(false); infoTextPane.setContentType("text/html"); infoTextPane.setText(toString(certificates[0])); final JScrollPane certScroll = new JScrollPane(infoTextPane); certScroll.setPreferredSize(new Dimension(300, 500)); add(certScroll, BorderLayout.CENTER); }
public OrderTrans2() { super(windowTitle); int i; int currentPanel; // Value to specify which is the current panel in the vector JPanel subPanel = new JPanel(); // value used when adding sliders to the frame Runtime program = Runtime.getRuntime(); Container content = getContentPane(); createSliderVector(); createPanelVector(); getCodeSwapString(); /** Set code-swap strings' value. */ /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Add the radio buttons to the group */ radioGrp.add(firstBox); radioGrp.add(secondBox); /** Set interactive buttons for the user interface */ JButton exeButton = new JButton("Execute"); exeButton.setToolTipText("Re-execute the program"); JButton resetButton = new JButton("Reset"); resetButton.setToolTipText("Reset Value"); JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); // Create the main panel that contains everything. JPanel mainPanel = new JPanel(); // Create the panel that contains the sliders JPanel subPanel1 = new JPanel(); // Create the panel that contains the checkboxes JPanel subPanel2 = new JPanel(); // Create the panel that contains the buttons JPanel subPanel3 = new JPanel(); // JScrollPane scrollPane = new JScrollPane(); // main text pane with scroll bars content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setLayout(new BoxLayout(mainPanel, BoxLayout.Y_AXIS)); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(subPanel1); mainPanel.add(subPanel2); mainPanel.add(subPanel3); subPanel1.setLayout(new GridLayout(0, 1)); /** Add subPanel elements to the subPanel1, each would be a row of sliders */ for (i = 0; i < ROWS; i++) subPanel1.add((JPanel) vSubPanel.elementAt(i)); /** Set the first element in the Panel Vector as the current subPanel. */ currentPanel = 0; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); /** Allocate sliders to the sub-panels. */ for (i = 0; i < COMPONENTS; i++) { PSlider slider = (PSlider) vSlider.elementAt(i); if (slider.getResideValue() == 'n') { currentPanel += 1; subPanel = (JPanel) vSubPanel.elementAt(currentPanel); } subPanel.add((PSlider) vSlider.elementAt(i)); } /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); subPanel2.setLayout(new GridLayout(0, 2)); subPanel2.add(firstBox); subPanel2.add(secondBox); subPanel3.setLayout(new GridLayout(0, 3)); subPanel3.add(exeButton); exeButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExeCommand(); } }); subPanel3.add(resetButton); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doResetCommand(); } }); subPanel3.add(exitButton); exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); if (isWindows == false) { Process pid2 = null; pid2 = program.exec("getpid " + cmd.substring(4)); } } catch (IOException ie) { System.err.println("Couldn't run " + ie); // System.exit(-1);; } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { File fp = new File(dataFile); doResetCommand(); boolean delete = fp.delete(); pid.destroy(); } }); doExeCommand(); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }
public void setEditable(boolean b) { editor.setEditable(b); }
/** * Constructor, initialises the editor components. * * @param initialText The initial text to be displayed in the editor. * @param handler The GUI handler for this component. */ public GUITextModelEditor(String initialText, GUIMultiModelHandler handler) { this.handler = handler; setLayout(new BorderLayout()); // Setup the editor with it's custom editor kits. To switch between // editor kits just use setContentType() for the desired content type. editor = new JEditorPane() { @Override public String getToolTipText(MouseEvent event) { if (parseError != null) { try { int offset = this.viewToModel(new Point(event.getX(), event.getY())); int startOffset = computeDocumentOffset(parseError.getBeginLine(), parseError.getBeginColumn()); int endOffset = computeDocumentOffset(parseError.getEndLine(), parseError.getEndColumn()) + 1; if (offset >= startOffset && offset <= endOffset) return parseError.getMessage(); } catch (BadLocationException e) { } } return null; } }; editor.setToolTipText("dummy"); editor.setEditorKitForContentType("text/prism", new PrismEditorKit(handler)); editor.setEditorKitForContentType("text/pepa", new PepaEditorKit(handler)); // The default editor kit is the Prism one. editor.setContentType("text/prism"); editor.setBackground(Color.white); editor.addMouseListener(editorMouseListener); editor.setEditable(true); editor.setText(initialText); editor.getDocument().addDocumentListener(this); editor.addCaretListener( new CaretListener() { public void caretUpdate(CaretEvent e) { GUITextModelEditor.this .handler .getGUIPlugin() .getSelectionChangeHandler() .notifyListeners(new GUIEvent(1)); } }); editor.getDocument().putProperty(PlainDocument.tabSizeAttribute, new Integer(4)); editor.addMouseListener(this); errorHighlightPainter = new DefaultHighlighter.DefaultHighlightPainter(new Color(255, 192, 192)); undoManager = new GUIUndoManager(GUIPrism.getGUI()); undoManager.setLimit(200); // Setup the scrollpane editorScrollPane = new JScrollPane(editor); add(editorScrollPane, BorderLayout.CENTER); gutter = new GUITextModelEditorGutter(editor); // Get the 'show line numbers' setting to determine // if the line numbers should be shown. showLineNumbersSetting = handler .getGUIPlugin() .getPrism() .getSettings() .getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS); if (showLineNumbersSetting) { editorScrollPane.setRowHeaderView(gutter); } // Add a Prism settings listener to catch changes made to the // 'show line numbers' setting. handler .getGUIPlugin() .getPrism() .getSettings() .addSettingsListener( new PrismSettingsListener() { public void notifySettings(PrismSettings settings) { // Check if the setting has changed. if (settings.getBoolean(PrismSettings.MODEL_SHOW_LINE_NUMBERS) != showLineNumbersSetting) { showLineNumbersSetting = !showLineNumbersSetting; if (showLineNumbersSetting) { editorScrollPane.setRowHeaderView(gutter); } else { editorScrollPane.setRowHeaderView(null); } } } }); // initialize the actions for the context menu initActions(); // method to initialize the context menu popup initContextMenu(); InputMap inputMap = editor.getInputMap(); inputMap.clear(); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_undo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_undo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_Y, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_redo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_selectall"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_D, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_delete"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_cut"); inputMap.put( KeyStroke.getKeyStroke( KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask() | java.awt.event.InputEvent.SHIFT_MASK), "prism_redo"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_paste"); inputMap.put( KeyStroke.getKeyStroke(KeyEvent.VK_E, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()), "prism_jumperr"); ActionMap actionMap = editor.getActionMap(); actionMap.put("prism_undo", GUIPrism.getClipboardPlugin().getUndoAction()); actionMap.put("prism_redo", GUIPrism.getClipboardPlugin().getRedoAction()); actionMap.put("prism_selectall", GUIPrism.getClipboardPlugin().getSelectAllAction()); actionMap.put("prism_cut", GUIPrism.getClipboardPlugin().getCutAction()); actionMap.put("prism_copy", GUIPrism.getClipboardPlugin().getCopyAction()); actionMap.put("prism_paste", GUIPrism.getClipboardPlugin().getPasteAction()); actionMap.put("prism_delete", GUIPrism.getClipboardPlugin().getDeleteAction()); actionMap.put("prism_jumperr", actionJumpToError); // Attempt to programmatically allow all accelerators /*ArrayList plugins = ((GUIMultiModel)handler.getGUIPlugin()).getGUI().getPlugins(); Iterator it = plugins.iterator(); while (it.hasNext()) { GUIPlugin plugin = ((GUIPlugin)it.next()); System.out.println(plugin.getName()); JMenu firstMenu = plugin.getMenu(); Stack<MenuElement> menuStack = new Stack<MenuElement>(); menuStack.add(firstMenu); while (!menuStack.empty()) { MenuElement menu = menuStack.pop(); if (menu instanceof JMenuItem) { JMenuItem menuItem = ((JMenuItem)menu); KeyStroke accelerator = menuItem.getAccelerator(); Action action = menuItem.getAction(); if (action != null && accelerator != null && menuItem.getText() != null) { System.out.println(menuItem.getText() + " " + menuItem.getName()); inputMap.put(accelerator, "prism_" + menuItem.getText()); actionMap.put("prism_" + menuItem.getText(), action); } } MenuElement[] subelements = menu.getSubElements(); if (subelements != null) { for (int i = 0; i < subelements.length; i++) menuStack.push(subelements[i]); } } }*/ editor.getDocument().addUndoableEditListener(undoManager); editor .getDocument() .addUndoableEditListener( new UndoableEditListener() { public void undoableEditHappened(UndoableEditEvent e) { System.out.println("adding undo edit"); } }); }
public EditorPaneHTMLHelp(String htmlFile) { if (GlobalValues.useSystemBrowserForHelp) { Desktop d = GlobalValues.desktop; try { // create a temp file GlobalValues.forHTMLHelptempFile = new File("tempHTMLHelpSynthetic.html"); FileWriter fw = new FileWriter(GlobalValues.forHTMLHelptempFile); java.util.List<String> list = readTextFromJar(htmlFile); Iterator<String> it = list.iterator(); while (it.hasNext()) { fw.write(it.next() + "\n"); } String canonicalPathOfFile = GlobalValues.forHTMLHelptempFile.getCanonicalPath(); URL urlFile = new URL("file://" + canonicalPathOfFile); URI uriOfFile = urlFile.toURI(); fw.close(); d.browse(uriOfFile); } catch (Exception e) { e.printStackTrace(); } } else { URL initialURL = getClass().getResource(htmlFile); font = GlobalValues.htmlfont; String title = "HTML Help"; setTitle(title); final Stack<String> urlStack = new Stack<String>(); final JEditorPane editorPane; editorPane = new JEditorPane(new HTMLEditorKit().getContentType(), " "); editorPane.setOpaque(false); editorPane.setBorder(null); editorPane.setEditable(false); JPanel magPanel = new JPanel(); magnificationFactor = GlobalValues.helpMagnificationFactor; magFactor = new JTextField(Double.toString(magnificationFactor)); JButton magButton = new JButton("Set Magnification: "); magButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { magnificationFactor = Double.parseDouble(magFactor.getText()); GlobalValues.helpMagnificationFactor = magnificationFactor; } }); magPanel.setLayout(new GridLayout(1, 2)); magPanel.add(magButton); magPanel.add(magFactor); final JTextField url = new JTextField(initialURL.toString()); // set up hyperlink listener editorPane.setEditable(false); try { // remember URL for back button urlStack.push(initialURL.toString()); // show URL in text field url.setText(initialURL.toString()); // add a CSS rule to force body tags to use the default label font // instead of the value in javax.swing.text.html.default.csss String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); editorPane.setPage(initialURL); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } editorPane.addPropertyChangeListener( new PropertyChangeListener() { public void propertyChange(PropertyChangeEvent evt) { String bodyRule = "body { font-family: " + font.getFamily() + "; " + "font-size: " + font.getSize() * GlobalValues.helpMagnificationFactor + "pt; }"; ((HTMLDocument) editorPane.getDocument()).getStyleSheet().addRule(bodyRule); } }); editorPane.addHyperlinkListener( new HyperlinkListener() { public void hyperlinkUpdate(HyperlinkEvent event) { if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) { try { // remember URL for back button urlStack.push(event.getURL().toString()); // show URL in text field url.setText(event.getURL().toString()); editorPane.setPage(event.getURL()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } } }); // set up checkbox for toggling edit mode final JCheckBox editable = new JCheckBox(); editable.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { editorPane.setEditable(editable.isSelected()); } }); // set up load button for loading URL ActionListener listener = new ActionListener() { public void actionPerformed(ActionEvent event) { try { // remember URL for back button urlStack.push(url.getText()); editorPane.setPage(url.getText()); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }; JButton loadButton = new JButton("Load/Magnify"); loadButton.addActionListener(listener); url.addActionListener(listener); // set up back button and button action JButton backButton = new JButton("Back"); backButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { if (urlStack.size() <= 1) return; try { // get URL from back button urlStack.pop(); // show URL in text field String urlString = urlStack.peek(); url.setText(urlString); editorPane.setPage(urlString); editorPane.firePropertyChange("dummyProp", true, false); } catch (IOException e) { editorPane.setText("Exception: " + e); } } }); JPanel allPanel = new JPanel(new BorderLayout()); // put all control components in a panel JPanel ctrlPanel = new JPanel(new BorderLayout()); JPanel urlPanel = new JPanel(); urlPanel.add(new JLabel("URL")); urlPanel.add(url); JPanel buttonPanel = new JPanel(); buttonPanel.add(loadButton); buttonPanel.add(backButton); buttonPanel.add(new JLabel("Editable")); buttonPanel.add(magPanel); buttonPanel.add(editable); ctrlPanel.add(buttonPanel, BorderLayout.NORTH); ctrlPanel.add(urlPanel, BorderLayout.CENTER); allPanel.add(ctrlPanel, BorderLayout.NORTH); allPanel.add(new JScrollPane(editorPane), BorderLayout.CENTER); add(allPanel); } }
public BoxOnTable() { super(windowTitle); int i; Runtime program = Runtime.getRuntime(); Container content = getContentPane(); /** Get current OS of the system. */ if (System.getProperty("os.name").startsWith("Windows")) isWindows = true; else isWindows = false; /** Set interactive buttons for the user interface */ JButton exitButton = new JButton("Exit"); exitButton.setToolTipText("Exit the Program"); JPanel mainPanel = new JPanel(); content.add(mainPanel, BorderLayout.SOUTH); mainPanel.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); content.add(scrollPane, BorderLayout.CENTER); scrollPane.setBorder(BorderFactory.createLoweredBevelBorder()); scrollPane.getViewport().add(textPane); mainPanel.add(exitButton, BorderLayout.CENTER); /** Set and view the source code on the frame */ textPane.setEditable(false); textPane.setContentType("text/html; charset=EUC-JP"); try { URL url = new URL("file:" + exampleSource); textPane.setPage(url); } catch (IOException ie) { System.err.println("Error in opening html source file " + ie); System.exit(-1); } exitButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { doExitCommand(); } }); /** Run the illustrated program */ try { pid = program.exec(cmd); } catch (IOException ie) { System.err.println("Couldn't run " + ie); System.exit(-1); } /** Set the initial status for the window */ addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { pid.destroy(); } }); setSize(WIDTH, HEIGHT); setLocation(500, 0); setVisible(true); }