public Calculator() { super("Add Two Numbers"); setSize(350, 90); setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); setLookAndFeel(); FlowLayout flow = new FlowLayout(FlowLayout.CENTER); setLayout(flow); // create components value1 = new JTextField("0", 5); plus = new JLabel("+"); value2 = new JTextField("0", 5); equals = new JLabel("="); sum = new JTextField("0", 5); // add listeners value1.addFocusListener(this); value2.addFocusListener(this); // set up sum field sum.setEditable(false); // add components add(value1); add(plus); add(value2); add(equals); add(sum); setVisible(true); }
private JTextField createColorField(boolean hex) { final NumberDocument doc = new NumberDocument(hex); int lafFix = UIUtil.isUnderWindowsLookAndFeel() || UIUtil.isUnderDarcula() ? 1 : 0; UIManager.LookAndFeelInfo info = LafManager.getInstance().getCurrentLookAndFeel(); if (info != null && (info.getName().startsWith("IDEA") || info.getName().equals("Windows Classic"))) lafFix = 1; final JTextField field; if (SystemInfo.isMac && UIUtil.isUnderIntelliJLaF()) { field = new JTextField(""); field.setDocument(doc); field.setPreferredSize(new Dimension(hex ? 60 : 40, 26)); } else { field = new JTextField(doc, "", (hex ? 5 : 2) + lafFix); field.setSize(50, -1); } doc.setSource(field); field.getDocument().addDocumentListener(this); field.addFocusListener( new FocusAdapter() { @Override public void focusGained(final FocusEvent e) { field.selectAll(); } }); return field; }
public LabelField(String name, int max, ChangeListener changeListener) { this.changeListener = changeListener; oldText = ""; this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); this.setAlignmentX(0); label = new JLabel(name); label.setMinimumSize(new Dimension(90, 21)); label.setMaximumSize(new Dimension(90, 21)); label.setPreferredSize(new Dimension(90, 21)); this.add(label); textField = new JTextField(); textField.setMaximumSize(new Dimension(max, 21)); textField.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) {} @Override public void focusLost(FocusEvent e) { if (oldText.equals(getText())) return; oldText = getText(); notifyChanged(); } }); this.add(textField); }
private void setupInputListeners(final JTextField currentInput) { currentInput.addKeyListener( new KeyAdapter() { // Plot the graph. @Override public void keyPressed(KeyEvent e) { if (e.getKeyCode() == KeyEvent.VK_ENTER && currentInput.isFocusOwner()) { try { String[] equations = new String[nInputs]; for (int i = 0; i < nInputs; i++) { equations[i] = input[i].getText(); } addPlot( equations, templateFunc.getColor(), gridOP.getGridBounds(), gridOP.getGridStepSize()); } catch (IllegalExpressionException e1) { signalAll(new ActionEvent(e1, -1, "")); } } } }); currentInput.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent arg0) { setSelected(templateFunc); } }); }
private JTextField createField(final String text) { final JTextField field = new JTextField(text) { public Dimension getPreferredSize() { Dimension preferredSize = super.getPreferredSize(); return new Dimension(preferredSize.width, myTextHeight); } }; field.setBackground(UIUtil.getPanelBackground()); field.setEditable(false); final Border lineBorder = BorderFactory.createLineBorder(UIUtil.getPanelBackground()); final DottedBorder dotted = new DottedBorder(UIUtil.getActiveTextColor()); field.setBorder(lineBorder); // field.setFocusable(false); field.setHorizontalAlignment(JTextField.RIGHT); field.setCaretPosition(0); field.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent e) { field.setBorder(dotted); } public void focusLost(FocusEvent e) { field.setBorder(lineBorder); } }); return field; }
private JTextField initializeGoToTextField() { JTextField textField = new JTextField(); textField.setFont(new Font("Arial", Font.ITALIC, 10)); textField.setEnabled(false); textField.addActionListener(this); textField.addFocusListener(this); return textField; }
public RegistrationForm() { super("Registration Form"); setLayout(new GridLayout(10, 2)); add(new JLabel("Name:")); add(txtName); add(new JLabel("Password:"******"Verify Password:"******"Gender:")); add(pnlGender); pnlGender.add(rbMale); pnlGender.add(rbFemale); add(new JLabel("Phone")); add(pnlPhone); pnlPhone.add(txtPhone); pnlPhone.add(cmbPhoneType); add(new JLabel("Email:")); add(txtEmail); add(new JLabel("Preferred Contact:")); add(pnlContact); pnlContact.add(cbEmail); pnlContact.add(cbPhone); add(new JLabel()); add(new JLabel()); add(lblMouse); add(new JLabel()); add(lblMessage); add(btnSubmit); grpGender.add(rbMale); grpGender.add(rbFemale); mouseHandler h = new mouseHandler(); this.addMouseListener(h); this.addMouseMotionListener(h); txtVerify.addKeyListener(new keyHandler()); txtName.addFocusListener(new focusHandler()); txtPhone.addFocusListener(new focusHandler()); txtEmail.addFocusListener(new focusHandler()); btnSubmit.addActionListener(new butonHandler()); }
public static void selectTextOnFocusGain(JTextField textField) { textField.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent focusEvent) { Object source = focusEvent.getSource(); if (source instanceof JTextField) { ((JTextField) source).selectAll(); } } }); }
private static void insertQuestion(final JTextPane textPane, String str) { Document doc = textPane.getDocument(); try { doc.insertString(doc.getLength(), str, null); final int pos = doc.getLength(); System.out.println(pos); final JTextField field = new JTextField(4) { @Override public Dimension getMaximumSize() { return getPreferredSize(); } }; field.setBorder(BorderFactory.createMatteBorder(0, 0, 1, 0, Color.BLACK)); field.addFocusListener( new FocusListener() { @Override public void focusGained(FocusEvent e) { try { Rectangle rect = textPane.modelToView(pos); rect.grow(0, 4); rect.setSize(field.getSize()); // System.out.println(rect); // System.out.println(field.getLocation()); textPane.scrollRectToVisible(rect); } catch (BadLocationException ex) { ex.printStackTrace(); } } @Override public void focusLost(FocusEvent e) { /* not needed */ } }); Dimension d = field.getPreferredSize(); int baseline = field.getBaseline(d.width, d.height); field.setAlignmentY(baseline / (float) d.height); SimpleAttributeSet a = new SimpleAttributeSet(); StyleConstants.setLineSpacing(a, 1.5f); textPane.setParagraphAttributes(a, true); textPane.insertComponent(field); doc.insertString(doc.getLength(), "\n", null); } catch (BadLocationException e) { e.printStackTrace(); } }
/** initialises the layout */ private void initLayout() { setLayout(new BorderLayout()); populateCompType(); initCompPanel(); JLabel complabel = new JLabel(Env.getString("component")); complabel.setBorder(new EmptyBorder(0, 0, 0, 3)); JPanel typepanel = new JPanel(new BorderLayout()); typepanel.add(comptype, BorderLayout.WEST); JPanel compcont = new JPanel(new BorderLayout()); compcont.add(complabel, BorderLayout.WEST); compcont.add(typepanel, BorderLayout.CENTER); compcont.setBorder(new EmptyBorder(0, 0, 10, 0)); JLabel deflabel = new JLabel(Env.getString("defaultValue")); deflabel.setBorder(new EmptyBorder(0, 0, 0, 3)); JPanel defpanel = new JPanel(new BorderLayout()); defpanel.add(defval, BorderLayout.WEST); defval.addFocusListener(this); JPanel defcont = new JPanel(new BorderLayout()); defcont.add(compcont, BorderLayout.NORTH); defcont.add(deflabel, BorderLayout.WEST); defcont.add(defpanel, BorderLayout.CENTER); defcont.setBorder(new EmptyBorder(0, 0, 3, 0)); JPanel cont = new JPanel(new BorderLayout()); cont.add(defcont, BorderLayout.NORTH); cont.add(comppanel, BorderLayout.CENTER); JPanel maincont = new JPanel(new BorderLayout()); maincont.add(cont, BorderLayout.NORTH); add(maincont, BorderLayout.WEST); }
/** Setup field listeners. */ private void initializeFieldListeners() { checkboxMonitor.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { model.setMonitor(new Boolean(checkboxMonitor.isSelected())); } }); textfieldName.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent event) { model.setName(textfieldName.getText()); } }); textfieldTare.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent event) { try { textfieldTare.commitEdit(); } catch (ParseException e) { logger.warn(e); } model.setTare((Double) textfieldTare.getValue()); } }); comboboxType.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { model.setScaletype((ScaleType) comboboxType.getSelectedItem()); } }); }
private void setupActions() { wordList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { wordEditField.setText((String) wordList.getSelectedValue()); wordEditField.selectAll(); new FocusRequester(wordEditField); } }); newWord.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { newWordAction(); } }); wordEditFieldListener = new ActionListener() { public void actionPerformed(ActionEvent e) { int index = wordList.getSelectedIndex(); String old = (String) wordList.getSelectedValue(), newVal = wordEditField.getText(); if (newVal.equals("") || newVal.equals(old)) { return; // Empty string or no change. } if (wordListModel.contains(newVal)) { // ensure that word already in list is visible index = wordListModel.indexOf(newVal); wordList.ensureIndexIsVisible(index); return; } int newIndex = findPos(wordListModel, newVal); if (index >= 0) { // initiate replacement of selected word wordListModel.remove(index); if (newIndex > index) { // newIndex has to be adjusted after removal of previous entry newIndex--; } } wordListModel.add(newIndex, newVal); wordList.ensureIndexIsVisible(newIndex); wordEditField.selectAll(); } }; wordEditField.addActionListener(wordEditFieldListener); removeWord.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int index = wordList.getSelectedIndex(); if (index == -1) return; wordListModel.remove(index); wordEditField.setText(""); if (wordListModel.size() > 0) wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1)); } }); fieldList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { currentField = (String) fieldList.getSelectedValue(); fieldNameField.setText(""); setupWordSelector(); } }); newField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) { // only add <field name> once fieldListModel.add(0, FIELD_FIRST_LINE); } fieldList.setSelectedIndex(0); fPane.getVerticalScrollBar().setValue(0); fieldNameField.setEnabled(true); fieldNameField.setText(currentField); fieldNameField.selectAll(); new FocusRequester(fieldNameField); } }); fieldNameField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { fieldNameField.transferFocus(); } }); fieldNameField.addFocusListener( new FocusAdapter() { /** Adds the text value to the list */ public void focusLost(FocusEvent e) { String s = fieldNameField.getText(); fieldNameField.setText(""); fieldNameField.setEnabled(false); if (!FIELD_FIRST_LINE.equals(s) && !"".equals(s)) { // user has typed something // remove "<first name>" from list fieldListModel.remove(0); int pos; if (fieldListModel.contains(s)) { // field already exists, scroll to that field (below) pos = fieldListModel.indexOf(s); } else { // Add new field. pos = findPos(fieldListModel, s); fieldListModel.add(Math.max(0, pos), s); } fieldList.setSelectedIndex(pos); fieldList.ensureIndexIsVisible(pos); currentField = s; setupWordSelector(); newWordAction(); // new FocusRequester(wordEditField); } } }); removeField.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { int index = fieldList.getSelectedIndex(); if (index == -1) return; String fieldName = (String) fieldListModel.get(index); removedFields.add(fieldName); fieldListModel.remove(index); wordListModels.remove(fieldName); fieldNameField.setText(""); if (fieldListModel.size() > 0) fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1)); } }); help.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { frame.helpDiag.showPage(GUIGlobals.contentSelectorHelp); } }); ok.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { applyChanges(); dispose(); } }); apply.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // Store if an entry is currently being edited: if (!wordEditField.getText().equals("")) { wordEditFieldListener.actionPerformed(null); } applyChanges(); } }); @SuppressWarnings("serial") Action cancelAction = new AbstractAction() { public void actionPerformed(ActionEvent e) { dispose(); } }; cancelAction.putValue(Action.NAME, Globals.lang("Cancel")); cancel.setAction(cancelAction); }
public void initPanel() { // The panel uses an absolute layout. setLayout(null); // Name nameField = new JFormattedTextField(20); nameField.setEditable(false); addRow("Name", nameField); // Label labelField = new JTextField(20); labelField.addActionListener(this); labelField.addFocusListener(this); addRow("Label", labelField); // Help Text helpTextField = new JTextField(20); helpTextField.addActionListener(this); helpTextField.addFocusListener(this); addRow("Help Text", helpTextField); // Widget widgetBox = new JComboBox(humanizedWidgets); widgetBox.addActionListener(this); addRow("Type", widgetBox); // Value valueField = new JTextField(20); valueField.addActionListener(this); valueField.addFocusListener(this); addRow("Value", valueField); // Enable If enableIfField = new JTextField(20); enableIfField.addActionListener(this); enableIfField.addFocusListener(this); addRow("Enable If", enableIfField); // Bounding Method boundingMethodBox = new JComboBox(new String[] {"none", "soft", "hard"}); boundingMethodBox.addActionListener(this); addRow("Bounding", boundingMethodBox); // Minimum Value minimumValueCheck = new JCheckBox(); minimumValueCheck.addActionListener(this); minimumValueField = new JTextField(10); minimumValueField.addActionListener(this); minimumValueField.addFocusListener(this); JPanel minimumValuePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); minimumValuePanel.add(minimumValueCheck); minimumValuePanel.add(minimumValueField); addRow("Minimum", minimumValuePanel); // Maximum Value maximumValueCheck = new JCheckBox(); maximumValueCheck.addActionListener(this); maximumValueField = new JTextField(10); maximumValueField.addActionListener(this); maximumValueField.addFocusListener(this); JPanel maximumValuePanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 0)); maximumValuePanel.add(maximumValueCheck); maximumValuePanel.add(maximumValueField); addRow("Maximum", maximumValuePanel); // Display Level displayLevelBox = new JComboBox(new String[] {"hud", "detail", "hidden"}); displayLevelBox.addActionListener(this); addRow("Display Level", displayLevelBox); // Menu Items menuItemsTable = new JTable(new MenuItemsModel()); menuItemsTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); JPanel tablePanel = new JPanel(new BorderLayout(5, 5)); JScrollPane tableScroll = new JScrollPane( menuItemsTable, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); tableScroll.setSize(200, 170); tableScroll.setPreferredSize(new Dimension(200, 170)); tableScroll.setMaximumSize(new Dimension(200, 170)); tableScroll.setMinimumSize(new Dimension(200, 170)); tablePanel.add(tableScroll, BorderLayout.CENTER); JPanel buttonPanel = new JPanel(new FlowLayout(FlowLayout.LEADING, 5, 5)); addButton = new JButton(new Icons.PlusIcon()); addButton.addActionListener(this); removeButton = new JButton(new Icons.MinusIcon()); removeButton.addActionListener(this); upButton = new JButton(new Icons.ArrowIcon(Icons.ArrowIcon.NORTH)); upButton.addActionListener(this); downButton = new JButton(new Icons.ArrowIcon(Icons.ArrowIcon.SOUTH)); downButton.addActionListener(this); buttonPanel.add(addButton); buttonPanel.add(removeButton); buttonPanel.add(upButton); buttonPanel.add(downButton); tablePanel.add(buttonPanel, BorderLayout.SOUTH); addRow("Menu Items", tablePanel); }
public patientAdd(String s) { super(s); image = new JLabel() { public void paint(Graphics g) { ImageIcon ic = new ImageIcon(str); Image img = ic.getImage(); g.drawImage(img, 0, 0, 150, 150, this); } }; image.setBounds(670, 270, 300, 300); bu = new JButton("UPLOAD"); bu.setBounds(700, 230, 100, 20); bu.addActionListener(this); // q.add(bu); ldt = new JLabel("Date"); lpid = new JLabel("Patient ID"); lpnm = new JLabel("Patient Name"); lgen = new JLabel("Gender"); lbg = new JLabel("Blood Group"); lage = new JLabel("Age"); lwt = new JLabel("Weight Kg"); ladd = new JLabel("Address"); lcno = new JLabel("Cont. no."); ldnm = new JLabel("Doctor Name Dr."); lsym = new JLabel("Symptoms"); ldig = new JLabel("Diagnosis"); lfee = new JLabel("Fee Rs."); cbg = new CheckboxGroup(); cm = new Checkbox("Male", cbg, false); cm.addItemListener(this); cf = new Checkbox("Female", cbg, false); cf.setState(true); cf.addItemListener(this); tdt = new JTextField(15); tpid = new JTextField(6); tpid.addFocusListener(this); tpfnm = new JTextField("first"); tpmnm = new JTextField("middle"); tplnm = new JTextField("last"); tage = new JTextField(4); tage.addFocusListener(this); tbg = new JTextField(6); twt = new JTextField(5); tadd = new TextArea(patient.addr); tcno = new JTextField(20); tdnm = new JTextField(20); tsym = new TextArea(); tdig = new JTextField(20); tfee = new JTextField(6); tfee.addFocusListener(this); ba = new JButton("ADD"); ba.addActionListener(this); bm = new JButton("CANCEL"); bm.addActionListener(this); bd = new JButton("DELETE"); bd.addActionListener(this); bl = new JButton("DISPLAY"); bl.addActionListener(this); bs = new JButton("SEARCH"); bs.addActionListener(this); JPanel p = new JPanel(); p.add(ba); p.add(bm); // p.add(bd); // p.add(bl); // p.add(bs); add(p, BorderLayout.SOUTH); q = new JPanel(); q.setLayout(null); ldt.setBounds(1015, 20, 60, 20); q.add(ldt); tdt.setBounds(1060, 20, 170, 20); q.add(tdt); lpid.setBounds(70, 60, 80, 20); q.add(lpid); tpid.setBounds(200, 60, 60, 20); q.add(tpid); lpnm.setBounds(70, 100, 80, 20); q.add(lpnm); tpfnm.setBounds(200, 100, 100, 20); q.add(tpfnm); tpmnm.setBounds(320, 100, 100, 20); q.add(tpmnm); tplnm.setBounds(440, 100, 100, 20); q.add(tplnm); lgen.setBounds(70, 140, 60, 20); q.add(lgen); lbg.setBounds(370, 140, 80, 20); q.add(lbg); tbg.setBounds(470, 140, 60, 20); q.add(tbg); cm.setBounds(200, 140, 60, 20); cf.setBounds(280, 140, 60, 20); lage.setBounds(70, 180, 40, 20); q.add(lage); tage.setBounds(200, 180, 50, 20); q.add(tage); lwt.setBounds(370, 180, 200, 20); q.add(lwt); twt.setBounds(470, 180, 60, 20); q.add(twt); ladd.setBounds(70, 220, 60, 20); q.add(ladd); tadd.setBounds(200, 220, 350, 50); q.add(tadd); lcno.setBounds(70, 310, 60, 20); q.add(lcno); tcno.setBounds(200, 310, 120, 20); q.add(tcno); ldnm.setBounds(70, 350, 200, 20); q.add(ldnm); tdnm.setBounds(200, 350, 150, 20); q.add(tdnm); lsym.setBounds(70, 390, 100, 20); q.add(lsym); tsym.setBounds(200, 390, 300, 70); q.add(tsym); ldig.setBounds(70, 480, 60, 20); q.add(ldig); tdig.setBounds(200, 480, 100, 20); q.add(tdig); lfee.setBounds(70, 520, 200, 20); q.add(lfee); tfee.setBounds(200, 520, 40, 20); q.add(tfee); q.add(cm); q.add(cf); q.add(image); q.add(bu); add(q, BorderLayout.CENTER); addWindowListener( new WindowAdapter() { public void windowClosing(WindowEvent e) { try { patient.con.close(); System.exit(0); } catch (Exception e8) { } } }); System.out.println(tadd.getText()); setSize(1330, 740); setVisible(true); }
/** Install the Rotate-Button into the toolbar */ private void installRotateButton() { URL imgURL = ClassLoader.getSystemResource("ch/tbe/pics/rotate.gif"); ImageIcon rotateIcon = new ImageIcon(imgURL); rotate = new JButton(rotateIcon); rotate.setEnabled(false); rotatePanel = new JToolBar(); rotatePanel.setOrientation(1); rotatePanel.setLayout(new BorderLayout(0, 1)); rotateSlider = new JSlider(); rotateSlider.setMaximum(359); rotateSlider.setMinimum(0); rotateSlider.setMaximumSize(new Dimension(100, 100)); rotateSlider.setOrientation(1); Box box = Box.createVerticalBox(); sliderValue.setPreferredSize(new Dimension(30, 20)); rotateSlider.setAlignmentY(Component.TOP_ALIGNMENT); box.add(sliderValue); box.add(rotateSlider); sliderValue.setAlignmentY(Component.TOP_ALIGNMENT); rotatePanel.add(box, BorderLayout.NORTH); sliderValue.addFocusListener( new FocusListener() { private int oldValue = 0; public void focusGained(FocusEvent arg0) { oldValue = Integer.parseInt(sliderValue.getText()); } public void focusLost(FocusEvent arg0) { int newValue = 0; try { newValue = Integer.parseInt(sliderValue.getText()); } catch (Exception ex) { sliderValue.setText(Integer.toString(oldValue)); } if (newValue >= 0 && newValue <= 359) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rotateSlider.setValue(newValue); } else { sliderValue.setText(Integer.toString(oldValue)); } } }); rotateSlider.addChangeListener( new ChangeListener() { public void stateChanged(ChangeEvent arg0) { if (board.getSelectionCount() == 1 && board.getSelectionCells()[0] instanceof ShapeItem) { sliderValue.setText(Integer.toString(rotateSlider.getValue())); ShapeItem s = (ShapeItem) board.getSelectionCells()[0]; board.removeItem(new ItemComponent[] {s}); s.setRotation(rotateSlider.getValue()); board.addItem(s); } } }); rotateSlider.addMouseListener( new MouseAdapter() { private int value; public void mousePressed(MouseEvent e) { value = rotateSlider.getValue(); } public void mouseReleased(MouseEvent e) { if (value != rotateSlider.getValue()) { RotateCommand rc = new RotateCommand(board.getSelectedItems()); ArrayList<Command> actCommands = new ArrayList<Command>(); actCommands.add(rc); TBE.getInstance().addCommands(actCommands); rc.setRotation(value); } } }); rotate.setToolTipText(workingViewLabels.getString("rotate")); rotate.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (board.getSelectionCount() == 1 && board.getSelectedItems()[0] instanceof ShapeItem) { rotateSlider.setValue(((ShapeItem) board.getSelectedItems()[0]).getRotation()); } rotatePanel.setVisible(!rotatePanel.isVisible()); showRotate = !showRotate; } }); rotate.setContentAreaFilled(false); rotate.setBorderPainted(false); toolbar.add(rotate); rotatePanel.setVisible(false); this.add(rotatePanel, BorderLayout.EAST); }
private static JPanel initOptionsPane() { JPanel pane = null; ActionAdapter buttonListener = null; // Create an options pane JPanel optionsPane = new JPanel(new GridLayout(4, 1)); // IP address input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Host IP:")); ipField = new JTextField(10); ipField.setText(hostIP); ipField.setEnabled(false); ipField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { ipField.selectAll(); // Should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { hostIP = ipField.getText(); } } }); pane.add(ipField); optionsPane.add(pane); // Port input pane = new JPanel(new FlowLayout(FlowLayout.RIGHT)); pane.add(new JLabel("Port:")); portField = new JTextField(10); portField.setEditable(true); portField.setText((new Integer(port)).toString()); portField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { // should be editable only when disconnected if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { int temp; try { temp = Integer.parseInt(portField.getText()); port = temp; } catch (NumberFormatException nfe) { portField.setText((new Integer(port)).toString()); mainFrame.repaint(); } } } }); pane.add(portField); optionsPane.add(pane); // Host/guest option buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { if (connectionStatus != DISCONNECTED) { changeStatusNTS(NULL, true); } else { isHost = e.getActionCommand().equals("host"); // Cannot supply host IP if host option is chosen if (isHost) { ipField.setEnabled(false); ipField.setText("localhost"); hostIP = "localhost"; } else { ipField.setEnabled(true); } } } }; ButtonGroup bg = new ButtonGroup(); hostOption = new JRadioButton("Host", true); hostOption.setMnemonic(KeyEvent.VK_H); hostOption.setActionCommand("host"); hostOption.addActionListener(buttonListener); guestOption = new JRadioButton("Guest", false); guestOption.setMnemonic(KeyEvent.VK_G); guestOption.setActionCommand("guest"); guestOption.addActionListener(buttonListener); bg.add(hostOption); bg.add(guestOption); pane = new JPanel(new GridLayout(1, 2)); pane.add(hostOption); pane.add(guestOption); optionsPane.add(pane); // Connect/disconnect buttons JPanel buttonPane = new JPanel(new GridLayout(1, 2)); buttonListener = new ActionAdapter() { public void actionPerformed(ActionEvent e) { // Request a connection initiation if (e.getActionCommand().equals("connect")) { changeStatusNTS(BEGIN_CONNECT, true); } // Disconnect else { changeStatusNTS(DISCONNECTING, true); } } }; connectButton = new JButton("Connect"); connectButton.setMnemonic(KeyEvent.VK_C); connectButton.setActionCommand("connect"); connectButton.addActionListener(buttonListener); connectButton.setEnabled(true); disconnectButton = new JButton("Disconnect"); disconnectButton.setMnemonic(KeyEvent.VK_D); disconnectButton.setActionCommand("disconnect"); disconnectButton.addActionListener(buttonListener); disconnectButton.setEnabled(false); buttonPane.add(connectButton); buttonPane.add(disconnectButton); optionsPane.add(buttonPane); return optionsPane; }
private void addTextChangeListener() { // Edit panel. FocusListener editListener = new FocusAdapter() { @Override public void focusGained(FocusEvent e) { FocusListener[] listeners = getFocusListeners(); for (FocusListener l : listeners) { l.focusGained(e); } updateColor(); } }; exprFieldX.addFocusListener(editListener); exprFieldY.addFocusListener(editListener); exprFieldZ.addFocusListener(editListener); KeyAdapter keyListener = new KeyAdapter() { @Override public void keyReleased(KeyEvent e) { Function currentFunction = getMother(); boolean hasChanged = !exprFieldX.getText().equals(currentFunction.getExpression()[0]) || !exprFieldY.getText().equals(currentFunction.getExpression()[1]) || !exprFieldZ.getText().equals(currentFunction.getExpression()[2]); // They want to update the plot if (e.getKeyCode() == KeyEvent.VK_ENTER) { if (hasChanged) { // Update the plot notifyPlotUpdate(exprFieldX.getText(), exprFieldY.getText(), exprFieldZ.getText()); Function newFunction = getMother(); if (currentFunction.equals(newFunction)) { setState(STATE.FAILED); } else { setState(STATE.SELECTED); } } } // Doing something else than plotting else if (hasChanged) { setState(STATE.CHANGED); } else { setState(STATE.SELECTED); } updateColor(); } }; exprFieldX.addKeyListener(keyListener); exprFieldY.addKeyListener(keyListener); exprFieldZ.addKeyListener(keyListener); }
DeleteCustomer() { // super(Title, Resizable, Closable, Maximizable, Iconifiable) super("Delete Account Holder", false, true, false, true); setSize(350, 235); jpDel.setLayout(null); lbNo = new JLabel("Account No:"); lbNo.setForeground(Color.black); lbNo.setBounds(15, 20, 80, 25); lbName = new JLabel("Person Name:"); lbName.setForeground(Color.black); lbName.setBounds(15, 55, 90, 25); lbDate = new JLabel("Last Transaction:"); lbDate.setForeground(Color.black); lbDate.setBounds(15, 90, 100, 25); lbBal = new JLabel("Balance:"); lbBal.setForeground(Color.black); lbBal.setBounds(15, 125, 80, 25); txtNo = new JTextField(); txtNo.setHorizontalAlignment(JTextField.RIGHT); txtNo.setBounds(125, 20, 200, 25); txtName = new JTextField(); txtName.setEnabled(false); txtName.setBounds(125, 55, 200, 25); txtDate = new JTextField(); txtDate.setEnabled(false); txtDate.setBounds(125, 90, 200, 25); txtBal = new JTextField(); txtBal.setEnabled(false); txtBal.setHorizontalAlignment(JTextField.RIGHT); txtBal.setBounds(125, 125, 200, 25); // Aligning The Buttons. btnDel = new JButton("Delete"); btnDel.setBounds(20, 165, 120, 25); btnDel.addActionListener(this); btnCancel = new JButton("Cancel"); btnCancel.setBounds(200, 165, 120, 25); btnCancel.addActionListener(this); // Adding the All the Controls to Panel. jpDel.add(lbNo); jpDel.add(txtNo); jpDel.add(lbName); jpDel.add(txtName); jpDel.add(lbDate); jpDel.add(txtDate); jpDel.add(lbBal); jpDel.add(txtBal); jpDel.add(btnDel); jpDel.add(btnCancel); // Restricting The User Input to only Numerics in Numeric TextBoxes. txtNo.addKeyListener( new KeyAdapter() { public void keyTyped(KeyEvent ke) { char c = ke.getKeyChar(); if (!((Character.isDigit(c) || (c == KeyEvent.VK_BACK_SPACE)))) { getToolkit().beep(); ke.consume(); } } }); // Checking the Accunt No. Provided By User on Lost Focus of the TextBox. txtNo.addFocusListener( new FocusListener() { public void focusGained(FocusEvent e) {} public void focusLost(FocusEvent fe) { if (txtNo.getText().equals("")) { } else { rows = 0; populateArray(); // Load All Existing Records in Memory. findRec(); // Finding if Account No. Already Exist or Not. } } }); // Adding Panel to Window. getContentPane().add(jpDel); populateArray(); // Load All Existing Records in Memory. // In the End Showing the New Account Window. setVisible(true); }
/** * Initialize the frame. * * @param info true if additional information is desired */ private void init(boolean info) { _buttonPressed = null; addComponentListener( new java.awt.event.ComponentAdapter() { public void componentResized(ComponentEvent e) { validate(); _matchList.ensureIndexIsVisible(_matchList.getSelectedIndex()); } }); // buttons int i = 0; for (final CloseAction<T> a : _actions) { _buttons[i] = new JButton(a.getName()); final String tooltip = a.getToolTipText(); if (tooltip != null) { _buttons[i].setToolTipText(tooltip); } _buttons[i].addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { buttonPressed(a); } }); ++i; } getRootPane().setDefaultButton(_buttons[0]); _strategyBox.setEditable(false); _strategyBox.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { // System.out.println("set strategy!"); selectStrategy(); } }); _strategyBox.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { boolean bf = false; for (JButton b : _buttons) { if (e.getOppositeComponent() == b) { bf = true; break; } } if ((e.getOppositeComponent() != _textField) && (!bf)) { for (JComponent c : _optionalComponents) { if (e.getOppositeComponent() == c) { return; } } _textField.requestFocus(); } } }); // text field _textField.setDragEnabled(false); _textField.setFocusTraversalKeysEnabled(false); addListener(); Keymap ourMap = JTextComponent.addKeymap("PredictiveInputFrame._textField", _textField.getKeymap()); for (final CloseAction<T> a : _actions) { KeyStroke ks = a.getKeyStroke(); if (ks != null) { ourMap.addActionForKeyStroke( ks, new AbstractAction() { public void actionPerformed(ActionEvent e) { buttonPressed(a); } }); } } ourMap.addActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { // System.out.println("tab!"); removeListener(); _pim.extendSharedMask(); updateTextField(); updateExtensionLabel(); updateList(); addListener(); } }); ourMap.addActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { // System.out.println("up!"); if (_matchList.getModel().getSize() > 0) { removeListener(); int i = _matchList.getSelectedIndex(); if (i > 0) { _matchList.setSelectedIndex(i - 1); _matchList.ensureIndexIsVisible(i - 1); _pim.setCurrentItem(_pim.getMatchingItems().get(i - 1)); updateInfo(); } addListener(); } } }); ourMap.addActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { // System.out.println("down!"); if (_matchList.getModel().getSize() > 0) { removeListener(); int i = _matchList.getSelectedIndex(); if (i < _matchList.getModel().getSize() - 1) { _matchList.setSelectedIndex(i + 1); _matchList.ensureIndexIsVisible(i + 1); _pim.setCurrentItem(_pim.getMatchingItems().get(i + 1)); updateInfo(); } addListener(); } } }); ourMap.addActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_UP, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { // System.out.println("page up!"); if (_matchList.getModel().getSize() > 0) { removeListener(); int page = _matchList.getLastVisibleIndex() - _matchList.getFirstVisibleIndex() + 1; int i = _matchList.getSelectedIndex() - page; if (i < 0) i = 0; _matchList.setSelectedIndex(i); _matchList.ensureIndexIsVisible(i); _pim.setCurrentItem(_pim.getMatchingItems().get(i)); updateInfo(); addListener(); } } }); ourMap.addActionForKeyStroke( KeyStroke.getKeyStroke(KeyEvent.VK_PAGE_DOWN, 0), new AbstractAction() { public void actionPerformed(ActionEvent e) { // System.out.println("page down!"); if (_matchList.getModel().getSize() > 0) { removeListener(); int page = _matchList.getLastVisibleIndex() - _matchList.getFirstVisibleIndex() + 1; int i = _matchList.getSelectedIndex() + page; if (i >= _matchList.getModel().getSize()) { i = _matchList.getModel().getSize() - 1; } _matchList.setSelectedIndex(i); _matchList.ensureIndexIsVisible(i); _pim.setCurrentItem(_pim.getMatchingItems().get(i)); updateInfo(); addListener(); } } }); _textField.setKeymap(ourMap); _textField.addFocusListener( new FocusAdapter() { public void focusLost(FocusEvent e) { boolean bf = false; for (JButton b : _buttons) { if (e.getOppositeComponent() == b) { bf = true; break; } } if ((e.getOppositeComponent() != _strategyBox) && (!bf)) { for (JComponent c : _optionalComponents) { if (e.getOppositeComponent() == c) { return; } } _textField.requestFocus(); } } }); _matchList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); _matchList.addListSelectionListener( new ListSelectionListener() { public void valueChanged(ListSelectionEvent e) { // System.out.println("click!"); removeListener(); int i = _matchList.getSelectedIndex(); if (i >= 0) { _pim.setCurrentItem(_pim.getMatchingItems().get(i)); _matchList.ensureIndexIsVisible(i); updateInfo(); } addListener(); } }); // put everything together Container contentPane = getContentPane(); GridBagLayout layout = new GridBagLayout(); contentPane.setLayout(layout); GridBagConstraints c = new GridBagConstraints(); c.anchor = GridBagConstraints.NORTHWEST; c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; // end row c.insets.top = 2; c.insets.left = 2; c.insets.bottom = 2; c.insets.right = 2; if (info) { c.fill = GridBagConstraints.NONE; contentPane.add(_infoLabel, c); } c.fill = GridBagConstraints.BOTH; c.weighty = 1.0; contentPane.add( new JScrollPane( _matchList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED, ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED), c); c.anchor = GridBagConstraints.SOUTHWEST; c.fill = GridBagConstraints.NONE; c.weightx = 0.0; c.weighty = 0.0; c.gridwidth = 1; contentPane.add(_tabCompletesLabel, c); c.fill = GridBagConstraints.HORIZONTAL; c.weightx = 1.0; c.gridwidth = GridBagConstraints.REMAINDER; contentPane.add(_sharedExtLabel, c); contentPane.add(_textField, c); _optionalComponents = makeOptions(); if (_optionalComponents.length > 0) { _optionsPanel = new JPanel(new BorderLayout()); _setupOptionsPanel(_optionalComponents); contentPane.add(_optionsPanel, c); } c.anchor = GridBagConstraints.SOUTHWEST; c.weightx = 1.0; c.weighty = 0.0; c.gridwidth = GridBagConstraints.REMAINDER; // end row c.insets.top = 2; c.insets.left = 2; c.insets.bottom = 2; c.insets.right = 2; JPanel buttonPanel = new JPanel(new GridBagLayout()); GridBagConstraints bc = new GridBagConstraints(); bc.insets.left = 2; bc.insets.right = 2; buttonPanel.add(new JLabel("Matching strategy:"), bc); buttonPanel.add(_strategyBox, bc); for (JButton b : _buttons) { buttonPanel.add(b, bc); } contentPane.add(buttonPanel, c); pack(); // Dimension parentDim = (_owner != null) ? _owner.getSize() : getToolkit().getScreenSize(); //// int xs = (int) parentDim.getWidth()/3; // int ys = (int) parentDim.getHeight()/4; //// in line below, parentDim was _owner.getSize(); changed because former could generate // NullPointerException // setSize(new Dimension((int) getSize().getWidth(), (int)Math.min(parentDim.getHeight(), // Math.max(ys, 300)))); if (_owner != null) { setLocationRelativeTo(_owner); } removeListener(); updateTextField(); addListener(); updateList(); }
private void initComponents() { setPreferredSize(new java.awt.Dimension(420, 65)); this.setLayout(new BoxLayout(this, BoxLayout.Y_AXIS)); JPanel buttonPanel = new JPanel(); buttonPanel.setLayout(new FlowLayout(FlowLayout.LEFT)); JPanel textPanel = new JPanel(); SpringLayout textLayout = new SpringLayout(); textPanel.setLayout(textLayout); this.add(buttonPanel); this.add(textPanel); // button area abortButton_ = new JButton(); abortButton_.setBackground(new java.awt.Color(255, 255, 255)); abortButton_.setIcon( new javax.swing.ImageIcon( getClass().getResource("/org/micromanager/icons/cancel.png"))); // NOI18N abortButton_.setToolTipText("Abort acquisition"); abortButton_.setFocusable(false); abortButton_.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER); abortButton_.setMaximumSize(new java.awt.Dimension(30, 28)); abortButton_.setMinimumSize(new java.awt.Dimension(30, 28)); abortButton_.setPreferredSize(new java.awt.Dimension(30, 28)); abortButton_.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM); abortButton_.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { try { JavaUtils.invokeRestrictedMethod(vad_, VirtualAcquisitionDisplay.class, "abort"); } catch (Exception ex) { ReportingUtils.showError( "Couldn't abort. Try pressing stop on Multi-Dimensional acquisition Window"); } } }); buttonPanel.add(abortButton_); pauseButton_ = new JButton(); pauseButton_.setIcon( new javax.swing.ImageIcon( getClass().getResource("/org/micromanager/icons/control_pause.png"))); // NOI18N pauseButton_.setToolTipText("Pause acquisition"); pauseButton_.setFocusable(false); pauseButton_.setMargin(new java.awt.Insets(0, 0, 0, 0)); pauseButton_.setMaximumSize(new java.awt.Dimension(30, 28)); pauseButton_.setMinimumSize(new java.awt.Dimension(30, 28)); pauseButton_.setPreferredSize(new java.awt.Dimension(30, 28)); pauseButton_.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { try { JavaUtils.invokeRestrictedMethod(vad_, VirtualAcquisitionDisplay.class, "pause"); } catch (Exception ex) { ReportingUtils.showError("Couldn't pause"); } if (eng_.isPaused()) { pauseButton_.setIcon( new javax.swing.ImageIcon( getClass() .getResource("/org/micromanager/icons/resultset_next.png"))); // NOI18N } else { pauseButton_.setIcon( new javax.swing.ImageIcon( getClass() .getResource("/org/micromanager/icons/control_pause.png"))); // NOI18N } } }); buttonPanel.add(pauseButton_); gridXSpinner_ = new JSpinner(); gridXSpinner_.setModel(new SpinnerNumberModel(2, 1, 1000, 1)); gridXSpinner_.setPreferredSize(new Dimension(35, 24)); gridYSpinner_ = new JSpinner(); gridYSpinner_.setModel(new SpinnerNumberModel(2, 1, 1000, 1)); gridYSpinner_.setPreferredSize(new Dimension(35, 24)); gridXSpinner_.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { gridSizeChanged(); } }); gridYSpinner_.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { gridSizeChanged(); } }); final JLabel gridLabel = new JLabel(" grid"); final JLabel byLabel = new JLabel("by"); gridLabel.setEnabled(false); byLabel.setEnabled(false); gridXSpinner_.setEnabled(false); gridYSpinner_.setEnabled(false); final JButton createGridButton = new JButton("Create"); createGridButton.setEnabled(false); createGridButton.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { createGrid(); } }); newGridButton_ = new JToggleButton("New grid"); buttonPanel.add(new JLabel(" ")); buttonPanel.add(newGridButton_); newGridButton_.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (newGridButton_.isSelected()) { makeGridOverlay( vad_.getImagePlus().getWidth() / 2, vad_.getImagePlus().getHeight() / 2); newGridButton_.setText("Cancel"); gridLabel.setEnabled(true); byLabel.setEnabled(true); gridXSpinner_.setEnabled(true); gridYSpinner_.setEnabled(true); createGridButton.setEnabled(true); } else { vad_.getImagePlus().getOverlay().clear(); vad_.getImagePlus().getCanvas().repaint(); newGridButton_.setText("New grid"); gridLabel.setEnabled(false); byLabel.setEnabled(false); gridXSpinner_.setEnabled(false); gridYSpinner_.setEnabled(false); createGridButton.setEnabled(false); } } }); buttonPanel.add(gridXSpinner_); buttonPanel.add(byLabel); buttonPanel.add(gridYSpinner_); buttonPanel.add(gridLabel); buttonPanel.add(createGridButton); // text area zPosLabel_ = new JLabel("Z position: "); textPanel.add(zPosLabel_); timeStampLabel_ = new JLabel("Elapsed time: "); textPanel.add(timeStampLabel_); fpsField_ = new JTextField(); fpsField_.setText("7"); fpsField_.setToolTipText("Set the speed at which the acquisition is played back."); fpsField_.setPreferredSize(new Dimension(25, 18)); fpsField_.addFocusListener( new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { updateFPS(); } }); fpsField_.addKeyListener( new java.awt.event.KeyAdapter() { public void keyReleased(java.awt.event.KeyEvent evt) { updateFPS(); } }); JLabel fpsLabel = new JLabel("Animation playback FPS: "); textPanel.add(fpsLabel); textPanel.add(fpsField_); textLayout.putConstraint(SpringLayout.WEST, textPanel, 0, SpringLayout.WEST, zPosLabel_); textLayout.putConstraint( SpringLayout.EAST, zPosLabel_, 0, SpringLayout.WEST, timeStampLabel_); textLayout.putConstraint(SpringLayout.EAST, timeStampLabel_, 0, SpringLayout.WEST, fpsLabel); textLayout.putConstraint(SpringLayout.EAST, fpsLabel, 0, SpringLayout.WEST, fpsField_); textLayout.putConstraint(SpringLayout.EAST, fpsField_, 0, SpringLayout.EAST, textPanel); textLayout.putConstraint(SpringLayout.NORTH, fpsField_, 0, SpringLayout.NORTH, textPanel); textLayout.putConstraint(SpringLayout.NORTH, zPosLabel_, 3, SpringLayout.NORTH, textPanel); textLayout.putConstraint( SpringLayout.NORTH, timeStampLabel_, 3, SpringLayout.NORTH, textPanel); textLayout.putConstraint(SpringLayout.NORTH, fpsLabel, 3, SpringLayout.NORTH, textPanel); }
public EchoAWT() throws UnknownHostException { super("채팅 프로그램"); // 각종 정의 h = new JPanel(new GridLayout(2, 3)); m = new JPanel(new BorderLayout()); f = new JPanel(new BorderLayout()); s = new JPanel(new BorderLayout()); login = new JPanel(new BorderLayout()); // name = new JLabel(" 사용자 이름 "); name = new JLabel(" 메세지 입력 "); jta = new JTextArea(); // clientList = new JTextArea(0, 10); clientList = new JList(); jsp = new JScrollPane(jta); list = new JScrollPane(clientList); jtf = new JTextField("입력하세요."); hi = new JTextField("HOST IP 입력"); pi = new JTextField("PORT 입력"); localport = new JTextField("원하는 PORT 입력"); lid = new JTextField("ID를 입력하세요."); lpw = new JTextField("PW를 입력하세요."); serveropen = new JButton("서버 오픈"); textin = new JButton("입력"); clientin = new JButton("서버 접속"); conf = new JButton("로그인"); join = new JButton("회원가입"); addr = InetAddress.getLocalHost(); // 사용자 해상도 및 창 크기 설정 및 가져오기. Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screenSize = tk.getScreenSize(); setSize(500, 500); Dimension d = getSize(); // 각종 버튼 및 텍스트 필드 리스너 jtf.addActionListener(this); hi.addActionListener(this); pi.addActionListener(this); localport.addActionListener(this); lid.addActionListener(this); lpw.addActionListener(this); conf.addActionListener(this); join.addActionListener(this); serveropen.addActionListener(this); clientin.addActionListener(this); textin.addActionListener(this); jtf.addFocusListener(this); hi.addFocusListener(this); pi.addFocusListener(this); localport.addFocusListener(this); lid.addFocusListener(this); lpw.addFocusListener(this); // 서버 접속 h.add(hi); h.add(pi); h.add(clientin); // 서버 생성 h.add(new JLabel("IP : " + addr.getHostAddress(), (int) CENTER_ALIGNMENT)); h.add(localport); h.add(serveropen); // 채팅글창 글 작성 막기 jta.setEditable(false); // 접속자 리스트 width 제한 clientList.setFixedCellWidth(d.width / 3); // 입력 창 f.add(name, "West"); f.add(jtf, "Center"); f.add(textin, "East"); // 접속자 확인창 s.add(new JLabel("접속자", (int) CENTER_ALIGNMENT), "North"); s.add(list, "Center"); // clientList.setEditable(false); // 메인 창 m.add(jsp, "Center"); m.add(s, "East"); // 프레임 설정 add(h, "North"); add(m, "Center"); add(f, "South"); // 로그인 다이얼로그 jd = new JDialog(); jd.setTitle("채팅 로그인"); jd.add(login); jd.setSize(200, 200); Dimension dd = jd.getSize(); jd.setLocation(screenSize.width / 2 - (dd.width / 2), screenSize.height / 2 - (dd.height / 2)); jd.setVisible(true); // 로그인창 JPanel lm = new JPanel(new GridLayout(4, 1)); lm.add(lid); lm.add(new Label()); lm.add(lpw); lm.add(new Label()); JPanel bt = new JPanel(); bt.add(conf); bt.add(join); login.add(new Label(), "North"); login.add(new Label(), "West"); login.add(new Label(), "East"); login.add(lm, "Center"); login.add(bt, "South"); // 창의 위치, 보임, EXIT 단추 활성화. setLocation(screenSize.width / 2 - (d.width / 2), screenSize.height / 2 - (d.height / 2)); setVisible(false); setDefaultCloseOperation(EXIT_ON_CLOSE); }
public FileTextFieldImpl( final JTextField field, Finder finder, LookupFilter filter, Map<String, String> macroMap, final Disposable parent) { myPathTextField = field; myMacroMap = new TreeMap<String, String>(); myMacroMap.putAll(macroMap); final InputMap listMap = (InputMap) UIManager.getDefaults().get("List.focusInputMap"); final KeyStroke[] listKeys = listMap.keys(); myDisabledTextActions = new HashSet<Action>(); for (KeyStroke eachListStroke : listKeys) { final String listActionID = (String) listMap.get(eachListStroke); if ("selectNextRow".equals(listActionID) || "selectPreviousRow".equals(listActionID)) { final Object textActionID = field.getInputMap().get(eachListStroke); if (textActionID != null) { final Action textAction = field.getActionMap().get(textActionID); if (textAction != null) { myDisabledTextActions.add(textAction); } } } } final FileTextFieldImpl assigned = (FileTextFieldImpl) myPathTextField.getClientProperty(KEY); if (assigned != null) { assigned.myFinder = finder; assigned.myFilter = filter; return; } myPathTextField.putClientProperty(KEY, this); final boolean headless = ApplicationManager.getApplication().isUnitTestMode(); myUiUpdater = new MergingUpdateQueue("FileTextField.UiUpdater", 200, false, myPathTextField); if (!headless) { new UiNotifyConnector(myPathTextField, myUiUpdater); } myFinder = finder; myFilter = filter; myFileSpitRegExp = myFinder.getSeparator().replaceAll("\\\\", "\\\\\\\\"); myPathTextField .getDocument() .addDocumentListener( new DocumentListener() { public void insertUpdate(final DocumentEvent e) { processTextChanged(); } public void removeUpdate(final DocumentEvent e) { processTextChanged(); } public void changedUpdate(final DocumentEvent e) { processTextChanged(); } }); myPathTextField.addKeyListener( new KeyAdapter() { public void keyPressed(final KeyEvent e) { processListSelection(e); } }); myPathTextField.addFocusListener( new FocusAdapter() { public void focusLost(final FocusEvent e) { closePopup(); } }); myCancelAction = new CancelAction(); new LazyUiDisposable<FileTextFieldImpl>(parent, field, this) { protected void initialize( @NotNull Disposable parent, @NotNull FileTextFieldImpl child, @Nullable Project project) { Disposer.register(child, myUiUpdater); } }; }
/** Creates all of the UI components used by this application. */ private void createComponents() { // the data entry fields need their focus watched... final FocusWatcher focusWatcher = new FocusWatcher(); // create the label and field for the mortgage principal amount fieldPrincipal = new JTextField(); fieldPrincipal.addFocusListener(focusWatcher); fieldPrincipal.setColumns(FIELD_COLUMNS); labelPrincipal = new JLabel(LABEL_PRINCIPAL); labelPrincipal.setLabelFor(fieldPrincipal); // create the label and field for the mortgage terms combo-box/list fieldMortgageChoices = new JComboBox(); fieldMortgageChoices.addActionListener(new FieldActionListener()); labelMortgageChoices = new JLabel(LABEL_MORTGAGE_CHOICES); labelMortgageChoices.setLabelFor(fieldMortgageChoices); // create the label and field for the mortgage term period fieldTerm = new JTextField(); fieldTerm.addFocusListener(focusWatcher); fieldTerm.setColumns(FIELD_COLUMNS); labelTerm = new JLabel(LABEL_TERM); labelTerm.setLabelFor(fieldTerm); // create the label and field for the mortgage annual interest rate fieldRate = new JTextField(); fieldRate.addFocusListener(focusWatcher); fieldRate.setColumns(FIELD_COLUMNS); labelRate = new JLabel(LABEL_RATE); labelRate.setLabelFor(fieldRate); // create the label that will provide the header text for the panel labelHeader = new JLabel(MSG_HEADER); // create the label that will provide any mesages to the user, // including the newly calculated mortgage payment amounts labelMessage = new JLabel(""); // create a chart used to display the mortgage payment detail; a small // pixel size is used so our primary window isn't sized too large paymentsChart = new Chart(320, 240); paymentsChart.setBorder(BorderFactory.createLineBorder(Color.BLACK)); // TODO paymentsModel = new MortgagePaymentsTableModel(); paymentsTable = new JTableHelper(paymentsModel); paymentsTable.setColumnSelectionAllowed(false); paymentsTable.setRowSelectionAllowed(true); paymentsTable.setDefaultRenderer(Double.class, new CurrencyRenderer()); // create the button that will allow the user to calculate a mortgage // payment schedule from the current input final Action calcAction = new CalcAction(); calcButton = new JButton(calcAction); getRootPane().setDefaultButton(calcButton); // set default values for all of the fields to make the user feel cozy fieldPrincipal.setText(FMT_PRINCIPAL.format(DEFAULT_PRINCIPAL)); fieldRate.setText(FMT_RATE.format(DEFAULT_RATE)); fieldTerm.setText(FMT_TERM.format(DEFAULT_TERM)); // watch the documents of our input fields so that we can reset our // current mortgage calculate whenever the user changes anything final DocumentListener docWatcher = new DocumentWatcher(); fieldPrincipal.getDocument().addDocumentListener(docWatcher); fieldRate.getDocument().addDocumentListener(docWatcher); fieldTerm.getDocument().addDocumentListener(docWatcher); }
public FloorEditorWindow() { previewModeBox.addActionListener( new ActionListener() { /** Invoked when an action occurs. */ public void actionPerformed(ActionEvent e) { previewBox.setMode( FloorPreviewPanel.FloorPreviewMode.values()[previewModeBox.getSelectedIndex()]); loadFloor(); } }); final ChangeListener cl = new ChangeListener() { public void stateChanged(ChangeEvent e) { if (currentFloor == null || isLoading) return; isDirty = true; currentFloor.occlude = blendingCheckbox.isSelected(); switch (previewBox.getMode()) { case RT3_GAME: currentFloor.colour2 = gameColour.getColour(); currentFloor.rgb2hls(currentFloor.colour2, true); currentFloor.texture = (Integer) gameTexture.getValue(); currentFloor.name = gameName.getText(); break; case RT3_MAP: currentFloor.minimapColour = gameColour.getColour(); currentFloor.rgb2hls(currentFloor.minimapColour, false); break; case RT4P_OVERLAY: currentFloor.hdColour = gameColour.getColour(); int hslColour = currentFloor.hslColour; currentFloor.rgb2hls(currentFloor.hdColour, false); currentFloor.hdOlHslColour = hslColour; currentFloor.hslColour = hslColour; currentFloor.hdTexture = (Integer) gameTexture.getValue(); // currentFloor.name = gameName.getText(); break; case RT4P_UNDERLAY: currentFloor.hdUlColour = gameColour.getColour(); hslColour = currentFloor.hslColour; currentFloor.rgb2hls(currentFloor.hdUlColour, false); currentFloor.hdHslColour = hslColour; currentFloor.hslColour = hslColour; currentFloor.hdUlTexture = (Integer) gameTexture.getValue(); // currentFloor.name = gameName.getText(); break; } previewBox.repaint(); } }; gameColour.addChangeListener(cl); gameTexture.addChangeListener(cl); blendingCheckbox.addChangeListener(cl); gameName.addFocusListener( new FocusListener() { String text = ""; public void focusGained(FocusEvent e) { text = gameName.getText(); } public void focusLost(FocusEvent e) { if (!gameName.getText().equals(text)) cl.stateChanged(null); } }); resetButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if ((!isDirty) || JOptionPane.showConfirmDialog( mainPane, "Are you sure you want to revert all changes to this floor?", "RuneScape Map Editor", JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) == JOptionPane.YES_OPTION) currentFloor = loadedFloor.cloneFLO(); } }); saveButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { isDirty = false; loadedFloor.replace(currentFloor); Floor.cache[loadedFloor.id] = loadedFloor; for (ChangeListener l : listenerList) l.stateChanged(null); } }); saveAsNewButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { isDirty = false; int i = Floor.addNew(currentFloor); currentFloor.id = i; loadedFloor = Floor.cache[i]; for (ChangeListener l : listenerList) l.stateChanged(null); } }); }
public PanelMore(OSeaMAction dia) { dlg = dia; setLayout(null); panelPat = new PanelPat(dlg, Ent.BODY); panelPat.setBounds(new Rectangle(0, 0, 110, 160)); add(panelPat); add(getRegionButton(regionAButton, 110, 0, 34, 30, "RegionA")); add(getRegionButton(regionBButton, 110, 32, 34, 30, "RegionB")); add(getRegionButton(regionCButton, 110, 64, 34, 30, "RegionC")); elevLabel = new JLabel(Messages.getString("Elevation"), SwingConstants.CENTER); elevLabel.setBounds(new Rectangle(140, 0, 90, 20)); add(elevLabel); elevBox = new JTextField(); elevBox.setBounds(new Rectangle(160, 20, 50, 20)); elevBox.setHorizontalAlignment(SwingConstants.CENTER); add(elevBox); elevBox.addFocusListener(flElev); heightLabel = new JLabel(Messages.getString("Height"), SwingConstants.CENTER); heightLabel.setBounds(new Rectangle(140, 40, 90, 20)); add(heightLabel); heightBox = new JTextField(); heightBox.setBounds(new Rectangle(160, 60, 50, 20)); heightBox.setHorizontalAlignment(SwingConstants.CENTER); add(heightBox); heightBox.addFocusListener(flHeight); sourceLabel = new JLabel(Messages.getString("Source"), SwingConstants.CENTER); sourceLabel.setBounds(new Rectangle(110, 80, 130, 20)); add(sourceLabel); sourceBox = new JTextField(); sourceBox.setBounds(new Rectangle(110, 100, 130, 20)); sourceBox.setHorizontalAlignment(SwingConstants.CENTER); add(sourceBox); sourceBox.addFocusListener(flSource); infoLabel = new JLabel(Messages.getString("Information"), SwingConstants.CENTER); infoLabel.setBounds(new Rectangle(110, 120, 130, 20)); add(infoLabel); infoBox = new JTextField(); infoBox.setBounds(new Rectangle(110, 140, 130, 20)); infoBox.setHorizontalAlignment(SwingConstants.CENTER); add(infoBox); infoBox.addFocusListener(flInfo); statusLabel = new JLabel(Messages.getString("Status"), SwingConstants.CENTER); statusLabel.setBounds(new Rectangle(250, 0, 100, 20)); add(statusLabel); statusBox = new JComboBox(); statusBox.setBounds(new Rectangle(250, 20, 100, 20)); addStsItem("", Sts.UNKSTS); addStsItem(Messages.getString("Permanent"), Sts.PERM); addStsItem(Messages.getString("Occasional"), Sts.OCC); addStsItem(Messages.getString("Recommended"), Sts.REC); addStsItem(Messages.getString("NotInUse"), Sts.NIU); addStsItem(Messages.getString("Intermittent"), Sts.INT); addStsItem(Messages.getString("Reserved"), Sts.RESV); addStsItem(Messages.getString("Temporary"), Sts.TEMP); addStsItem(Messages.getString("Private"), Sts.PRIV); addStsItem(Messages.getString("Mandatory"), Sts.MAND); addStsItem(Messages.getString("Destroyed"), Sts.DEST); addStsItem(Messages.getString("Extinguished"), Sts.EXT); addStsItem(Messages.getString("Illuminated"), Sts.ILLUM); addStsItem(Messages.getString("Historic"), Sts.HIST); addStsItem(Messages.getString("Public"), Sts.PUB); addStsItem(Messages.getString("Synchronized"), Sts.SYNC); addStsItem(Messages.getString("Watched"), Sts.WATCH); addStsItem(Messages.getString("UnWatched"), Sts.UNWAT); addStsItem(Messages.getString("Doubtful"), Sts.DOUBT); add(statusBox); statusBox.addActionListener(alStatus); constrLabel = new JLabel(Messages.getString("Construction"), SwingConstants.CENTER); constrLabel.setBounds(new Rectangle(250, 40, 100, 20)); add(constrLabel); constrBox = new JComboBox(); constrBox.setBounds(new Rectangle(250, 60, 100, 20)); addCnsItem("", Cns.UNKCNS); addCnsItem(Messages.getString("Masonry"), Cns.BRICK); addCnsItem(Messages.getString("Concreted"), Cns.CONC); addCnsItem(Messages.getString("Boulders"), Cns.BOULD); addCnsItem(Messages.getString("HardSurfaced"), Cns.HSURF); addCnsItem(Messages.getString("Unsurfaced"), Cns.USURF); addCnsItem(Messages.getString("Wooden"), Cns.WOOD); addCnsItem(Messages.getString("Metal"), Cns.METAL); addCnsItem(Messages.getString("GRP"), Cns.GLAS); addCnsItem(Messages.getString("Painted"), Cns.PAINT); add(constrBox); constrBox.addActionListener(alConstr); conLabel = new JLabel(Messages.getString("Conspicuity"), SwingConstants.CENTER); conLabel.setBounds(new Rectangle(250, 80, 100, 20)); add(conLabel); conBox = new JComboBox(); conBox.setBounds(new Rectangle(250, 100, 100, 20)); addConItem("", Con.UNKCON); addConItem(Messages.getString("Conspicuous"), Con.CONSP); addConItem(Messages.getString("NotConspicuous"), Con.NCONS); add(conBox); conBox.addActionListener(alCon); reflLabel = new JLabel(Messages.getString("Reflectivity"), SwingConstants.CENTER); reflLabel.setBounds(new Rectangle(250, 120, 100, 20)); add(reflLabel); reflBox = new JComboBox(); reflBox.setBounds(new Rectangle(250, 140, 100, 20)); addReflItem("", Con.UNKCON); addReflItem(Messages.getString("Conspicuous"), Con.CONSP); addReflItem(Messages.getString("NotConspicuous"), Con.NCONS); addReflItem(Messages.getString("Reflector"), Con.REFL); add(reflBox); reflBox.addActionListener(alRefl); }
public SearchManager2(JabRefFrame frame, SidePaneManager manager) { super(manager, GUIGlobals.getIconUrl("search"), Globals.lang("Search")); this.frame = frame; incSearcher = new IncrementalSearcher(Globals.prefs); // setBorder(BorderFactory.createMatteBorder(1,1,1,1,Color.magenta)); searchReq = new JCheckBoxMenuItem( Globals.lang("Search required fields"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_REQ)); searchOpt = new JCheckBoxMenuItem( Globals.lang("Search optional fields"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_OPT)); searchGen = new JCheckBoxMenuItem( Globals.lang("Search general fields"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_GEN)); searchAll = new JCheckBoxMenuItem( Globals.lang("Search all fields"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL)); regExpSearch = new JCheckBoxMenuItem( Globals.lang("Use regular expressions"), Globals.prefs.getBoolean(JabRefPreferences.REG_EXP_SEARCH)); increment = new JRadioButton(Globals.lang("Incremental"), false); floatSearch = new JRadioButton(Globals.lang("Float"), true); hideSearch = new JRadioButton(Globals.lang("Filter"), true); showResultsInDialog = new JRadioButton(Globals.lang("Show results in dialog"), true); searchAllBases = new JRadioButton( Globals.lang("Global search"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL_BASES)); ButtonGroup types = new ButtonGroup(); types.add(increment); types.add(floatSearch); types.add(hideSearch); types.add(showResultsInDialog); types.add(searchAllBases); select = new JCheckBoxMenuItem(Globals.lang("Select matches"), false); increment.setToolTipText(Globals.lang("Incremental search")); floatSearch.setToolTipText(Globals.lang("Gray out non-matching entries")); hideSearch.setToolTipText(Globals.lang("Hide non-matching entries")); showResultsInDialog.setToolTipText(Globals.lang("Show search results in a window")); // Add an item listener that makes sure we only listen for key events // when incremental search is turned on. increment.addItemListener(this); floatSearch.addItemListener(this); hideSearch.addItemListener(this); showResultsInDialog.addItemListener(this); // Add the global focus listener, so a menu item can see if this field was focused when // an action was called. searchField.addFocusListener(Globals.focusListener); if (searchAll.isSelected()) { searchReq.setEnabled(false); searchOpt.setEnabled(false); searchGen.setEnabled(false); } searchAll.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent event) { boolean state = !searchAll.isSelected(); searchReq.setEnabled(state); searchOpt.setEnabled(state); searchGen.setEnabled(state); } }); caseSensitive = new JCheckBoxMenuItem( Globals.lang("Case sensitive"), Globals.prefs.getBoolean(JabRefPreferences.CASE_SENSITIVE_SEARCH)); highLightWords = new JCheckBoxMenuItem( Globals.lang("Highlight Words"), Globals.prefs.getBoolean(JabRefPreferences.HIGH_LIGHT_WORDS)); searchAutoComplete = new JCheckBoxMenuItem( Globals.lang("Autocomplete names"), Globals.prefs.getBoolean(JabRefPreferences.SEARCH_AUTO_COMPLETE)); settings.add(select); // 2005.03.29, trying to remove field category searches, to simplify // search usability. // settings.addSeparator(); // settings.add(searchReq); // settings.add(searchOpt); // settings.add(searchGen); // settings.addSeparator(); // settings.add(searchAll); // --------------------------------------------------------------- settings.addSeparator(); settings.add(caseSensitive); settings.add(regExpSearch); settings.addSeparator(); settings.add(highLightWords); settings.addSeparator(); settings.add(searchAutoComplete); searchField.addActionListener(this); searchField.addCaretListener(this); search.addActionListener(this); searchField.addFocusListener( new FocusAdapter() { @Override public void focusGained(FocusEvent e) { if (increment.isSelected()) { searchField.setText(""); } } @Override public void focusLost(FocusEvent e) { incSearch = false; incSearchPos = -1; // Reset incremental // search. This makes the // incremental search reset // once the user moves focus to // somewhere else. if (increment.isSelected()) { // searchField.setText(""); // System.out.println("focuslistener"); } } }); escape.addActionListener(this); escape.setEnabled(false); // enabled after searching openset.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { if (settings.isVisible()) { // System.out.println("oee"); // settings.setVisible(false); } else { JButton src = (JButton) e.getSource(); settings.show(src, 0, openset.getHeight()); } } }); searchAutoComplete.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent actionEvent) { Globals.prefs.putBoolean( JabRefPreferences.SEARCH_AUTO_COMPLETE, searchAutoComplete.isSelected()); if (SearchManager2.this.frame.basePanel() != null) { SearchManager2.this.frame.basePanel().updateSearchManager(); } } }); Insets margin = new Insets(0, 2, 0, 2); // search.setMargin(margin); escape.setMargin(margin); openset.setMargin(margin); JButton help = new JButton(GUIGlobals.getImage("help")); int butSize = help.getIcon().getIconHeight() + 5; Dimension butDim = new Dimension(butSize, butSize); help.setPreferredSize(butDim); help.setMinimumSize(butDim); help.setMargin(margin); help.addActionListener(new HelpAction(Globals.helpDiag, GUIGlobals.searchHelp, "Help")); // Select the last used mode of search: if (Globals.prefs.getBoolean(JabRefPreferences.INCREMENT_S)) { increment.setSelected(true); } else if (Globals.prefs.getBoolean(JabRefPreferences.FLOAT_SEARCH)) { floatSearch.setSelected(true); } else if (Globals.prefs.getBoolean(JabRefPreferences.SHOW_SEARCH_IN_DIALOG)) { showResultsInDialog.setSelected(true); } else if (Globals.prefs.getBoolean(JabRefPreferences.SEARCH_ALL_BASES)) { searchAllBases.setSelected(true); } else { hideSearch.setSelected(true); } JPanel main = new JPanel(); GridBagLayout gbl = new GridBagLayout(); main.setLayout(gbl); GridBagConstraints con = new GridBagConstraints(); con.gridwidth = GridBagConstraints.REMAINDER; con.fill = GridBagConstraints.BOTH; con.weightx = 1; gbl.setConstraints(searchField, con); main.add(searchField); // con.gridwidth = 1; gbl.setConstraints(search, con); main.add(search); con.gridwidth = GridBagConstraints.REMAINDER; gbl.setConstraints(escape, con); main.add(escape); con.insets = new Insets(0, 2, 0, 0); gbl.setConstraints(increment, con); main.add(increment); gbl.setConstraints(floatSearch, con); main.add(floatSearch); gbl.setConstraints(hideSearch, con); main.add(hideSearch); gbl.setConstraints(showResultsInDialog, con); main.add(showResultsInDialog); gbl.setConstraints(searchAllBases, con); main.add(searchAllBases); con.insets = new Insets(0, 0, 0, 0); JPanel pan = new JPanel(); GridBagLayout gb = new GridBagLayout(); gbl.setConstraints(pan, con); pan.setLayout(gb); con.weightx = 1; con.gridwidth = 1; gb.setConstraints(openset, con); pan.add(openset); con.weightx = 0; gb.setConstraints(help, con); pan.add(help); main.add(pan); main.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); setContentContainer(main); searchField.getInputMap().put(Globals.prefs.getKey("Repeat incremental search"), "repeat"); searchField .getActionMap() .put( "repeat", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { if (increment.isSelected()) { repeatIncremental(); } } }); searchField.getInputMap().put(Globals.prefs.getKey("Clear search"), "escape"); searchField .getActionMap() .put( "escape", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { hideAway(); // SearchManager2.this.actionPerformed(new ActionEvent(escape, 0, "")); } }); setSearchButtonSizes(); updateSearchButtonText(); }
@Override public JComponent createComponent() { myMainPanel = new JPanel(new GridBagLayout()); myNameField = new JTextField(); myExtensionField = new JTextField(); mySplitter = new Splitter(true, 0.4f); myTemplateEditor = createEditor(); myDescriptionComponent = new JEditorPane(UIUtil.HTML_MIME, EMPTY_HTML); myDescriptionComponent.setEditable(false); myAdjustBox = new JCheckBox(IdeBundle.message("checkbox.reformat.according.to.style")); myTopPanel = new JPanel(new GridBagLayout()); myDescriptionPanel = new JPanel(new GridBagLayout()); myDescriptionPanel.add( SeparatorFactory.createSeparator(IdeBundle.message("label.description"), null), new GridBagConstraints( 0, 0, 1, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 2, 0), 0, 0)); myDescriptionPanel.add( ScrollPaneFactory.createScrollPane(myDescriptionComponent), new GridBagConstraints( 0, 1, 1, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 0, 0, 0), 0, 0)); myMainPanel.add( myTopPanel, new GridBagConstraints( 0, 0, 4, 1, 1.0, 0.0, GridBagConstraints.CENTER, GridBagConstraints.HORIZONTAL, new Insets(0, 0, 2, 0), 0, 0)); myMainPanel.add( myAdjustBox, new GridBagConstraints( 0, 1, 4, 1, 0.0, 0.0, GridBagConstraints.WEST, GridBagConstraints.HORIZONTAL, new Insets(2, 0, 2, 0), 0, 0)); myMainPanel.add( mySplitter, new GridBagConstraints( 0, 2, 4, 1, 1.0, 1.0, GridBagConstraints.CENTER, GridBagConstraints.BOTH, new Insets(2, 0, 0, 0), 0, 0)); mySplitter.setSecondComponent(myDescriptionPanel); setShowInternalMessage(null); myNameField.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { onNameChanged(); } }); myExtensionField.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { onNameChanged(); } }); myMainPanel.setPreferredSize(new Dimension(400, 300)); return myMainPanel; }
private void initPanel() { mapButtons = new HashMap<>(); for (Commontags commontags : CommontagsTools.getAll()) { mapAllTags.put(commontags.getText(), commontags); } int tagnum = 1; for (Commontags selectedTags : listSelectedTags) { if (tagnum % MAXLINE == 0) { add(createButton(selectedTags), RiverLayout.LINE_BREAK); } else { add(createButton(selectedTags), RiverLayout.LEFT); } tagnum++; } if (editmode) { txtTags = new JTextField(10); SelectAllUtils.install(txtTags); ac = new AutoCompletion(txtTags, mapAllTags.keySet().toArray(new String[] {})); ac.setStrict(false); ac.setStrictCompletion(false); txtTags.addActionListener(e -> cmbTagsActionPerformed(e)); txtTags.addFocusListener( new FocusAdapter() { @Override public void focusLost(FocusEvent e) { cmbTagsActionPerformed(null); } }); txtTags.addKeyListener( new KeyAdapter() { @Override public void keyTyped(KeyEvent e) { char c = e.getKeyChar(); if (Character.isAlphabetic(c) || Character.isDigit(c)) { super.keyTyped(e); } else { e.consume(); } } }); add(txtTags); btnPickTags = GUITools.getTinyButton("opde.tags.pnlcommontags.allTags", SYSConst.icon22checkbox); btnPickTags.setPressedIcon(SYSConst.icon22Pressed); btnPickTags.addActionListener( e -> { final JidePopup popup = new JidePopup(); JPanel pnl = new JPanel(new BorderLayout()); pnl.add(new JScrollPane(getClickableTagsPanel()), BorderLayout.CENTER); // JButton btnApply = new JButton(SYSConst.icon22apply); // pnl.add(btnApply, BorderLayout.SOUTH); // // btnApply.addActionListener(new ActionListener() { // @Override // public void actionPerformed(ActionEvent ae) { // popup.hidePopup(); // } // }); popup.setMovable(false); popup .getContentPane() .setLayout(new BoxLayout(popup.getContentPane(), BoxLayout.LINE_AXIS)); popup.setOwner(btnPickTags); popup.removeExcludedComponent(btnPickTags); pnl.setPreferredSize(new Dimension(400, 200)); popup.getContentPane().add(pnl); popup.setDefaultFocusComponent(pnl); popup.addPopupMenuListener( new PopupMenuListener() { @Override public void popupMenuWillBecomeVisible(PopupMenuEvent e) { OPDE.debug("popupMenuWillBecomeVisible"); } @Override public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { SwingUtilities.invokeLater( () -> { removeAll(); add(txtTags); if (btnPickTags != null) { add(btnPickTags); } int tagnum1 = 1; for (JButton btn : mapButtons.values()) { if (tagnum1 % MAXLINE == 0) { add(btn, RiverLayout.LINE_BREAK); } else { add(btn, RiverLayout.LEFT); } tagnum1++; } revalidate(); repaint(); }); } @Override public void popupMenuCanceled(PopupMenuEvent e) { OPDE.debug("popupMenuCanceled"); } }); GUITools.showPopup(popup, SwingConstants.WEST); }); add(btnPickTags); } }
/** Create and layout the visual components. */ private void initComponents() { setTitle("Chart Settings"); setSize(new Dimension(450, 375)); setResizable(false); addWindowListener( new java.awt.event.WindowAdapter() { public void windowClosing(java.awt.event.WindowEvent evt) { closeDialog(evt); } }); Box mainView = new Box(VERTICAL); getContentPane().add(mainView); Box row; Box yAxisView = new Box(VERTICAL); yAxisView.setBorder(border); mainView.add(yAxisView); yAutoScaleCheckbox = new JCheckBox("Auto Scale"); yAutoScaleCheckbox.addActionListener( new java.awt.event.ActionListener() { public void actionPerformed(java.awt.event.ActionEvent evt) { yAutoScaleCheckboxActionPerformed(evt); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(yAutoScaleCheckbox); yAxisView.add(row); yAxisMinValueField = new JTextField(10); yAxisMinValueField.setMaximumSize(yAxisMinValueField.getPreferredSize()); yAxisMinValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); yAxisMinValueField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisMinValueField.selectAll(); } public void focusLost(FocusEvent event) { yAxisMinValueField.setCaretPosition(0); yAxisMinValueField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Min:")); row.add(yAxisMinValueField); yAxisView.add(row); yAxisMaxValueField = new JTextField(10); yAxisMaxValueField.setMaximumSize(yAxisMaxValueField.getPreferredSize()); yAxisMaxValueField.setHorizontalAlignment(javax.swing.JTextField.RIGHT); yAxisMaxValueField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisMaxValueField.selectAll(); } public void focusLost(FocusEvent event) { yAxisMaxValueField.setCaretPosition(0); yAxisMaxValueField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Max:")); row.add(yAxisMaxValueField); yAxisView.add(row); yAxisDivisionsField = new JTextField(10); yAxisDivisionsField.setMaximumSize(yAxisDivisionsField.getPreferredSize()); yAxisDivisionsField.setHorizontalAlignment(JTextField.RIGHT); yAxisDivisionsField.addFocusListener( new FocusAdapter() { public void focusGained(FocusEvent event) { yAxisDivisionsField.selectAll(); } public void focusLost(FocusEvent event) { yAxisDivisionsField.setCaretPosition(0); yAxisDivisionsField.moveCaretPosition(0); } }); row = new Box(HORIZONTAL); row.add(Box.createHorizontalGlue()); row.add(new JLabel("Major Divisions:")); row.add(yAxisDivisionsField); yAxisView.add(row); Box buttonView = new Box(HORIZONTAL); mainView.add(buttonView); buttonView.add(Box.createHorizontalGlue()); JButton revertButton = new JButton("Revert"); revertButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { revertButtonActionPerformed(event); } }); buttonView.add(revertButton); JButton applyButton = new JButton("Apply"); applyButton.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent event) { applyButtonActionPerformed(event); } }); buttonView.add(applyButton); pack(); }
public ContextEditor(Context cntxt) { super("Edit User Context: " + localFileName(cntxt)); ctxt = cntxt; windowNum = ctxt.languageName + " Context Editor"; setDefaultCloseOperation(DISPOSE_ON_CLOSE); listener = new CEListener(this); JPanel nameBox = new JPanel(); nameBox.setLayout(new BoxLayout(nameBox, BoxLayout.LINE_AXIS)); name = new JTextField(ctxt.languageName, 28); name.setMaximumSize(new Dimension(225, 22)); name.addFocusListener( new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { nameFocusLost(evt); } }); JLabel nameLabel = new JLabel("Language Name: "); nameBox.add(nameLabel); nameBox.add(name); JPanel folderBox = new JPanel(); folderBox.setLayout(new BoxLayout(folderBox, BoxLayout.LINE_AXIS)); folder = new JTextField(ctxt.editDirectory); folder.setMaximumSize(new Dimension(225, 22)); // folder.addActionListener(listener); // folder.setActionCommand("folder edit"); folder.addFocusListener( new java.awt.event.FocusAdapter() { public void focusLost(java.awt.event.FocusEvent evt) { folderFocusLost(evt); } }); JLabel folderLabel = new JLabel("SILK file folder: "); folderBox.add(folderLabel); folderBox.add(folder); JPanel nameFolderBox = new JPanel(); nameFolderBox.setLayout(new BoxLayout(nameFolderBox, BoxLayout.PAGE_AXIS)); nameBox.setAlignmentX(0.5f); nameFolderBox.add(nameBox); nameFolderBox.add(Box.createRigidArea(new Dimension(0, 4))); nameFolderBox.add(folderBox); nameFolderBox.setAlignmentX(0.5f); buildPopulationBox(); JPanel btnBoxUDPs = new JPanel(), subBoxUDP = new JPanel(); btnBoxUDPs.setLayout(new BoxLayout(btnBoxUDPs, BoxLayout.PAGE_AXIS)); subBoxUDP.setLayout(new BoxLayout(subBoxUDP, BoxLayout.LINE_AXIS)); int numUDPs = 0; if (ctxt.userDefinedProperties != null) { numUDPs = ctxt.userDefinedProperties.size(); } String plur = "ies"; if (numUDPs == 1) { plur = "y"; } JLabel udpLabel = new JLabel("Has " + numUDPs + " User-Defined Propert" + plur); subBoxUDP.add(udpLabel); JButton addUDP = new JButton("Add UDP"); addUDP.setActionCommand("add UDP"); addUDP.addActionListener(listener); subBoxUDP.add(addUDP); btnBoxUDPs.add(subBoxUDP); if (numUDPs > 0) { Dimension sizer = new Dimension(250, 50); String[] udpMenu = genUDPMenu(); UDPick = new JComboBox(udpMenu); UDPick.addActionListener(listener); UDPick.setActionCommand("view/edit UDP"); UDPick.setMinimumSize(sizer); UDPick.setMaximumSize(sizer); UDPick.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "View/Edit UDPs")); btnBoxUDPs.add(UDPick); } // end of if-any-UDPs-exist JPanel domThs = new JPanel(); domThs.setLayout(new BoxLayout(domThs, BoxLayout.PAGE_AXIS)); domThs.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "Kinship System Domain Theories")); domThs.setAlignmentX(0.5f); JPanel dtRefBtnBox = new JPanel(); dtRefBtnBox.setLayout(new BoxLayout(dtRefBtnBox, BoxLayout.LINE_AXIS)); dtRefBtnBox.setAlignmentX(0.0f); JLabel dtRefLabel = new JLabel("Terms of Reference "); dtRefBtnBox.add(dtRefLabel); if (ctxt.domTheoryRefExists()) { JButton dtRefEdit = new JButton("Edit Theory"); dtRefEdit.setActionCommand("edit dtRef"); dtRefEdit.addActionListener(listener); dtRefBtnBox.add(dtRefEdit); // JButton dtRefDelete = new JButton("Delete Theory"); // dtRefDelete.setActionCommand("dtRef delete"); // dtRefDelete.addActionListener(listener); // dtRefBtnBox.add(dtRefDelete); } // end of if-dt-exists else { // if does not exist JLabel dtRefNone = new JLabel("< None >"); dtRefBtnBox.add(dtRefNone); // JButton dtRefAdd = new JButton("Add Theory"); // dtRefAdd.setActionCommand("dtRef add"); // dtRefAdd.addActionListener(listener); // dtRefBtnBox.add(dtRefAdd); } // end of does-not-exist domThs.add(dtRefBtnBox); JPanel dtAddrBtnBox = new JPanel(); dtAddrBtnBox.setLayout(new BoxLayout(dtAddrBtnBox, BoxLayout.LINE_AXIS)); dtAddrBtnBox.setAlignmentX(0.0f); JLabel dtAddrLabel = new JLabel("Terms of Address "); dtAddrBtnBox.add(dtAddrLabel); if (ctxt.domTheoryAdrExists()) { JButton dtAddrEdit = new JButton("Edit Theory"); dtAddrEdit.setActionCommand("edit dtAddr"); dtAddrEdit.addActionListener(listener); dtAddrBtnBox.add(dtAddrEdit); // JButton dtAddrViewList = new JButton("Delete Theory"); // dtAddrViewList.setActionCommand("dtAddr delete"); // dtAddrViewList.addActionListener(listener); // dtAddrBtnBox.add(dtAddrViewList); } // end of if-dt-exists else { // if does not exist JLabel dtAddrNone = new JLabel("< None >"); dtAddrBtnBox.add(dtAddrNone); // JButton dtAddrAdd = new JButton("Add Theory"); // dtAddrAdd.setActionCommand("dtAddr add"); // dtAddrAdd.addActionListener(listener); // dtAddrBtnBox.add(dtAddrAdd); } // end of does-not-exist domThs.add(dtAddrBtnBox); // End of the left hand portion // Right hand portion follows. it is narrower. JPanel polyBox = new JPanel(); polyBox.setLayout(new BoxLayout(polyBox, BoxLayout.PAGE_AXIS)); polyBox.setAlignmentX(0.5f); JLabel polyLabelA = new JLabel("Polygamy"); JLabel polyLabelB = new JLabel("Permitted?"); JRadioButton yesPoly = new JRadioButton("Yes"); yesPoly.setActionCommand("polygamy yes"); yesPoly.addActionListener(listener); JRadioButton noPoly = new JRadioButton("No"); noPoly.setActionCommand("polygamy no"); noPoly.addActionListener(listener); if (cntxt.polygamyPermit) { yesPoly.setSelected(true); } else { noPoly.setSelected(true); } ButtonGroup polyBtns = new ButtonGroup(); polyBtns.add(yesPoly); polyBtns.add(noPoly); polyBox.add(polyLabelA); polyBox.add(polyLabelB); polyBox.add(yesPoly); polyBox.add(noPoly); JPanel matrixBox = new JPanel(); matrixBox.setLayout(new BoxLayout(matrixBox, BoxLayout.PAGE_AXIS)); matrixBox.setAlignmentX(0.5f); JLabel matrixLabelA = new JLabel("Kin Term Matrix"); JLabel matrixLabelC = new JLabel(ctxt.indSerNumGen + " rows"); JLabel matrixLabelD = new JLabel(ctxt.ktm.numberOfKinTerms() + " terms"); matrixLabelA.setAlignmentX(0.5f); matrixLabelC.setAlignmentX(0.5f); matrixLabelD.setAlignmentX(0.5f); JButton matrixEditBtn = new JButton("Edit Matrix"); matrixEditBtn.setEnabled(false); matrixEditBtn.setActionCommand("edit matrix"); matrixEditBtn.addActionListener(listener); matrixEditBtn.setAlignmentX(0.5f); matrixBox.add(matrixLabelA); matrixBox.add(matrixLabelC); matrixBox.add(matrixLabelD); matrixBox.add(matrixEditBtn); JPanel distinctBox = new JPanel(); distinctBox.setLayout(new BoxLayout(distinctBox, BoxLayout.PAGE_AXIS)); distinctBox.setAlignmentX(0.5f); JLabel distinctLabelA = new JLabel("Distinct Terms"); JLabel distinctLabelB = new JLabel("of Address"); distinctLabelA.setAlignmentX(0.5f); distinctLabelB.setAlignmentX(0.5f); JRadioButton yesDistinct = new JRadioButton("Yes"); yesDistinct.setActionCommand("distinct yes"); yesDistinct.addActionListener(listener); JRadioButton noDistinct = new JRadioButton("No"); noDistinct.setActionCommand("distinct no"); noDistinct.addActionListener(listener); yesDistinct.setAlignmentX(0.5f); noDistinct.setAlignmentX(0.5f); if (ctxt.distinctAdrTerms) { yesDistinct.setSelected(true); } else { noDistinct.setSelected(true); } ButtonGroup distinctBtns = new ButtonGroup(); distinctBtns.add(yesDistinct); distinctBtns.add(noDistinct); distinctBox.add(distinctLabelA); distinctBox.add(distinctLabelB); distinctBox.add(yesDistinct); distinctBox.add(noDistinct); /* * NOTE: It should be possible to put all these elements directly into * the ContentPane. But that doesn't work; the layout is truly ugly and * stuff gets stacked on top of other stuff. What works is to put * everything into a JPanel with BoxLayout. Then put the JPanel into * ContentPane. */ JPanel leftCol = new JPanel(); leftCol.setLayout(new BoxLayout(leftCol, BoxLayout.PAGE_AXIS)); leftCol.add(nameFolderBox); leftCol.add(Box.createRigidArea(new Dimension(0, 4))); leftCol.add(populationBox); leftCol.add(Box.createRigidArea(new Dimension(0, 8))); leftCol.add(btnBoxUDPs); leftCol.add(Box.createRigidArea(new Dimension(0, 8))); leftCol.add(domThs); leftCol.add(new JLabel(" ")); JPanel rightCol = new JPanel(); rightCol.setLayout(new BoxLayout(rightCol, BoxLayout.PAGE_AXIS)); rightCol.setBorder( BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.blue), "Options")); rightCol.add(Box.createRigidArea(new Dimension(0, 20))); rightCol.add(polyBox); rightCol.add(Box.createRigidArea(new Dimension(0, 20))); rightCol.add(matrixBox); int high = (numUDPs > 0 ? 120 : 20); rightCol.add(Box.createRigidArea(new Dimension(0, high))); rightCol.add(distinctBox); JPanel commentBox = new JPanel(); commentBox.setLayout(new BoxLayout(commentBox, BoxLayout.PAGE_AXIS)); commentBox.setBorder( BorderFactory.createTitledBorder( BorderFactory.createLineBorder(Color.blue), "Notes on this culture:")); JScrollPane commentsPane = new JScrollPane(); comments = new JTextArea(); comments.setColumns(20); comments.setEditable(true); comments.setRows(3); comments.setText(PersonPanel.restoreLineBreaks(ctxt.comments)); comments.getDocument().addDocumentListener(new CommentListener()); commentsPane.setViewportView(comments); commentBox.add(commentsPane); JPanel guts = new JPanel(); // Holds the guts of this window guts.setLayout(new BoxLayout(guts, BoxLayout.LINE_AXIS)); guts.add(leftCol); guts.add(Box.createRigidArea(new Dimension(10, 4))); guts.add(rightCol); JPanel wholeThing = new JPanel(); wholeThing.setLayout(new BoxLayout(wholeThing, BoxLayout.PAGE_AXIS)); wholeThing.add(Box.createRigidArea(new Dimension(0, 4))); wholeThing.add(guts); wholeThing.add(Box.createRigidArea(new Dimension(0, 8))); wholeThing.add(commentBox); wholeThing.add(Box.createRigidArea(new Dimension(0, 4))); getContentPane().add(wholeThing); addInternalFrameListener(this); setSize(600, 620); setVisible(true); } // end of ContextEditor constructor