@Override public void actionPerformed(ActionEvent e) { // TODO Auto-generated method stub Object source = e.getSource(); if (source == ok) { response = APPLY_OPTION; this.setVisible(false); } else if (source == cancel) { response = CANCEL_OPTION; this.setVisible(false); } else if (source == sizeCombo) { // get the number from the source JComboBox number = (JComboBox) source; String numberItem = (String) number.getSelectedItem(); Font temp = example.getFont(); // then set the font int newSize = Integer.parseInt(numberItem); example.setFont(new Font(temp.getFamily(), temp.getStyle(), newSize)); } else if (source == fontCombo) { JComboBox font = (JComboBox) source; String s = (String) font.getSelectedItem(); Font tmp = example.getFont(); example.setFont(new Font(s, tmp.getStyle(), tmp.getSize())); } else if (source == foreground) { Color tmp = JColorChooser.showDialog(this, "Choose text color", example.getForeground()); MenuBar.shapeLBG.setBackground(tmp); if (tmp != null) example.setForeground(tmp); } }
private void _applyFontStyleForSelection(Font font) { StyledDocument doc = mTextEditor.getStyledDocument(); MutableAttributeSet attrs = mTextEditor.getInputAttributes(); StyleConstants.setFontFamily(attrs, font.getFamily()); StyleConstants.setFontSize(attrs, font.getSize()); StyleConstants.setBold(attrs, ((font.getStyle() & Font.BOLD) != 0)); StyleConstants.setItalic(attrs, ((font.getStyle() & Font.ITALIC) != 0)); StyleConstants.setUnderline(attrs, ((font.getStyle() & Font.CENTER_BASELINE) != 0)); int start = mTextEditor.getSelectionStart(); int end = mTextEditor.getSelectionEnd(); doc.setCharacterAttributes(start, (end - start), attrs, false); }
public void setSelectedFont(Font font) { selectedFont = font; family = font.getFamily(); style = font.getStyle(); size = font.getSize(); preview.setFont(font); }
public MaritimeTradeView() { this.setLayout(new BoxLayout(this, BoxLayout.X_AXIS)); Font font = new JButton().getFont(); Font newFont = font.deriveFont(font.getStyle(), 20); button = new JButton("Maritime Trade"); button.setFont(newFont); button.addActionListener(buttonListener); this.add(button); }
public void setFont(Font f) { if (f != null) { String str = f.getName(); int style = f.getStyle(); String size = "" + f.getSize(); for (int i = 0; i < fontList.getModel().getSize(); i++) { String listStr = ((String) fontList.getModel().getElementAt(i)).toLowerCase(); if (listStr.equals(str.toLowerCase())) { Object value = fontList.getModel().getElementAt(i); fontList.setSelectedValue(value, true); fontBox.setText((String) value); break; } } switch (style) { case Font.PLAIN: styleList.setSelectedIndex(0); break; case Font.ITALIC: styleList.setSelectedIndex(2); break; case Font.BOLD: styleList.setSelectedIndex(1); break; case Font.BOLD | Font.ITALIC: styleList.setSelectedIndex(3); break; } boolean found = false; for (int i = 0; i < sizeList.getModel().getSize(); i++) { String listStr = ((String) sizeList.getModel().getElementAt(i)).toLowerCase(); if (listStr.equals(size.toLowerCase())) { Object value = sizeList.getModel().getElementAt(i); sizeList.setSelectedValue(value, true); sizeBox.setText((String) value); found = true; break; } } if (!found) { sizeBox.setText(size); } } }
public void startDrop(PieceType pieceType, CatanColor pieceColor, boolean isCancelAllowed) { this.setOpaque(false); this.setLayout(new BorderLayout()); this.setBorder(BorderFactory.createLineBorder(Color.black, BORDER_WIDTH)); label = new JLabel(getLabelText(pieceType), JLabel.CENTER); label.setOpaque(true); label.setBackground(Color.white); Font labelFont = label.getFont(); labelFont = labelFont.deriveFont(labelFont.getStyle(), LABEL_TEXT_SIZE); label.setFont(labelFont); map = mainMap.copy(); map.setController(getController()); int prefWidth = (int) (mainMap.getScale() * mainMap.getPreferredSize().getWidth()); int prefHeight = (int) (mainMap.getScale() * mainMap.getPreferredSize().getHeight()); Dimension prefSize = new Dimension(prefWidth, prefHeight); map.setPreferredSize(prefSize); this.add(label, BorderLayout.NORTH); this.add(map, BorderLayout.CENTER); if (isCancelAllowed) { cancelButton = new JButton("Cancel"); Font buttonFont = cancelButton.getFont(); buttonFont = buttonFont.deriveFont(buttonFont.getStyle(), BUTTON_TEXT_SIZE); cancelButton.setFont(buttonFont); cancelButton.addActionListener(cancelButtonListener); this.add(cancelButton, BorderLayout.SOUTH); } map.startDrop(pieceType, pieceColor); }
@Override public void itemStateChanged(ItemEvent e) { // TODO Auto-generated method stub Object source = e.getSource(); Font tmp = example.getFont(); int style = tmp.getStyle(); if (source == italic) if (italic.isSelected()) style = style | Font.ITALIC; // turn italic on else style = style & ~Font.ITALIC; // turn italic off else if (source == bold) if (bold.isSelected()) style = style | Font.BOLD; // turn bold on else style = style & ~Font.BOLD; // turn bold off example.setFont(new Font(tmp.getFamily(), style, tmp.getSize())); }
public void adjustFont(int w, int h) { if (h <= 0) return; int oldH = rHeight; if (font == null) { font = getFont(); fontH = font.getSize(); rHeight = fontH; } nHeight = h; if (fontH >= h) rHeight = h - 2; else rHeight = fontH; if ((rHeight < 10) && (fontH > 10)) rHeight = 10; if (oldH != rHeight) { // Font curFont = font.deriveFont((float) rHeight); Font curFont = DisplayOptions.getFont(font.getName(), font.getStyle(), rHeight); setFont(curFont); } if (rHeight > h) rHeight = h; }
private void updateText() { Font font = getFont(); String styleString; switch (font.getStyle()) { case Font.PLAIN: styleString = jEdit.getProperty("font-selector.plain"); break; case Font.BOLD: styleString = jEdit.getProperty("font-selector.bold"); break; case Font.ITALIC: styleString = jEdit.getProperty("font-selector.italic"); break; case Font.BOLD | Font.ITALIC: styleString = jEdit.getProperty("font-selector.bolditalic"); break; default: styleString = "UNKNOWN!!!???"; break; } setText(font.getName() + ' ' + font.getSize() + ' ' + styleString); }
public int showCustomDialog(Frame f, Font fontArg, Color foreColorArg, Color backColorArg) { this.setLocationRelativeTo(f); String s = fontArg.getName(); fontCombo.setSelectedItem((Object) s); int style = fontArg.getStyle(); if ((style & Font.ITALIC) == 0) italic.setSelected(false); else italic.setSelected(true); if ((style & Font.BOLD) == 0) bold.setSelected(false); else bold.setSelected(true); int size = fontArg.getSize(); sizeCombo.setSelectedItem((Object) ("" + size)); example.setFont(fontArg); example.setForeground(MenuBar.shapeLBG.getBackground()); // show the dialog this.setVisible(true); return response; }
private void init(Font font) { JPanel content = new JPanel(new BorderLayout()); content.setBorder(new EmptyBorder(12, 12, 12, 12)); setContentPane(content); JPanel listPanel = new JPanel(new GridLayout(1, 3, 6, 6)); String[] fonts; try { fonts = getFontList(); } catch (Exception e) { Log.log(Log.ERROR, this, "Broken Java implementation!"); Log.log(Log.ERROR, this, e); fonts = new String[] {"Broken Java implementation!"}; } JPanel familyPanel = createTextFieldAndListPanel( "font-selector.family", familyField = new JTextField(), familyList = new JList(fonts)); listPanel.add(familyPanel); String[] sizes = {"9", "10", "12", "14", "16", "18", "24"}; JPanel sizePanel = createTextFieldAndListPanel( "font-selector.size", sizeField = new JTextField(), sizeList = new JList(sizes)); listPanel.add(sizePanel); String[] styles = { jEdit.getProperty("font-selector.plain"), jEdit.getProperty("font-selector.bold"), jEdit.getProperty("font-selector.italic"), jEdit.getProperty("font-selector.bolditalic") }; JPanel stylePanel = createTextFieldAndListPanel( "font-selector.style", styleField = new JTextField(), styleList = new JList(styles)); styleField.setEditable(false); listPanel.add(stylePanel); familyList.setSelectedValue(font.getFamily(), true); familyField.setText(font.getFamily()); sizeList.setSelectedValue(String.valueOf(font.getSize()), true); sizeField.setText(String.valueOf(font.getSize())); styleList.setSelectedIndex(font.getStyle()); styleField.setText((String) styleList.getSelectedValue()); ListHandler listHandler = new ListHandler(); familyList.addListSelectionListener(listHandler); sizeList.addListSelectionListener(listHandler); styleList.addListSelectionListener(listHandler); content.add(BorderLayout.NORTH, listPanel); preview = new JLabel(jEdit.getProperty("font-selector.long-text")) { public void paintComponent(Graphics g) { if (fontSelector != null) fontSelector.setAntiAliasEnabled(g); super.paintComponent(g); } }; preview.setBorder(new TitledBorder(jEdit.getProperty("font-selector.preview"))); updatePreview(); Dimension prefSize = preview.getPreferredSize(); prefSize.height = 50; preview.setPreferredSize(prefSize); content.add(BorderLayout.CENTER, preview); JPanel buttons = new JPanel(); buttons.setLayout(new BoxLayout(buttons, BoxLayout.X_AXIS)); buttons.setBorder(new EmptyBorder(12, 0, 0, 0)); buttons.add(Box.createGlue()); ok = new JButton(jEdit.getProperty("common.ok")); ok.addActionListener(new ActionHandler()); getRootPane().setDefaultButton(ok); buttons.add(ok); buttons.add(Box.createHorizontalStrut(6)); cancel = new JButton(jEdit.getProperty("common.cancel")); cancel.addActionListener(new ActionHandler()); buttons.add(cancel); buttons.add(Box.createGlue()); content.add(BorderLayout.SOUTH, buttons); pack(); setLocationRelativeTo(getParent()); setVisible(true); }
private void prepareToShow() { final MouseAdapter mouseAdapter = new MouseAdapter() { public void mousePressed(MouseEvent e) { Point point = (Point) e.getPoint().clone(); SwingUtilities.convertPointToScreen(point, e.getComponent()); final Dimension dimension = myContent.getSize(); dimension.height += myResizable && isToDrawMacCorner() ? ourMacCorner.getHeight(myContent) : 4; dimension.width += 4; Point locationOnScreen = myContent.getLocationOnScreen(); final Rectangle bounds = new Rectangle(new Point(locationOnScreen.x - 2, locationOnScreen.y - 2), dimension); if (!bounds.contains(point)) { cancel(); } } }; myContent.addMouseListener(mouseAdapter); Disposer.register( this, new Disposable() { public void dispose() { myContent.removeMouseListener(mouseAdapter); } }); myContent.registerKeyboardAction( new ActionListener() { public void actionPerformed(ActionEvent e) { if (myCancelKeyEnabled) { cancel(); } } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); mySearchKeyListener = new SpeedSearchKeyListener(); myContent.addKeyListener(mySearchKeyListener); if (myCancelOnMouseOutCallback != null || myCancelOnWindow) { myMouseOutCanceller = new Canceller(); Toolkit.getDefaultToolkit() .addAWTEventListener( myMouseOutCanceller, AWTEvent.MOUSE_EVENT_MASK | WindowEvent.WINDOW_ACTIVATED | AWTEvent.MOUSE_MOTION_EVENT_MASK); } myFocusWatcher = new ChildFocusWatcher(myContent) { protected void onFocusGained(final FocusEvent event) { setWindowActive(true); } protected void onFocusLost(final FocusEvent event) { setWindowActive(false); } }; mySpeedSearchPatternField = new JTextField(); if (SystemInfo.isMac) { Font f = mySpeedSearchPatternField.getFont(); mySpeedSearchPatternField.setFont(f.deriveFont(f.getStyle(), f.getSize() - 2)); } }
/** * Execute applet events. Here is the state transition diagram * * <pre>{@literal * Note: (XXX) is the action * APPLET_XXX is the state * (applet code loaded) --> APPLET_LOAD -- (applet init called)--> APPLET_INIT -- * (applet start called) --> APPLET_START -- (applet stop called) --> APPLET_STOP -- * (applet destroyed called) --> APPLET_DESTROY --> (applet gets disposed) --> * APPLET_DISPOSE --> ... * }</pre> * * In the legacy lifecycle model. The applet gets loaded, inited and started. So it stays in the * APPLET_START state unless the applet goes away(refresh page or leave the page). So the applet * stop method called and the applet enters APPLET_STOP state. Then if the applet is revisited, it * will call applet start method and enter the APPLET_START state and stay there. * * <p>In the modern lifecycle model. When the applet first time visited, it is same as legacy * lifecycle model. However, when the applet page goes away. It calls applet stop method and * enters APPLET_STOP state and then applet destroyed method gets called and enters APPLET_DESTROY * state. * * <p>This code is also called by AppletViewer. In AppletViewer "Restart" menu, the applet is jump * from APPLET_STOP to APPLET_DESTROY and to APPLET_INIT . * * <p>Also, the applet can jump from APPLET_INIT state to APPLET_DESTROY (in Netscape/Mozilla * case). Same as APPLET_LOAD to APPLET_DISPOSE since all of this are triggered by browser. */ @Override public void run() { Thread curThread = Thread.currentThread(); if (curThread == loaderThread) { // if we are in the loader thread, cause // loading to occur. We may exit this with // status being APPLET_DISPOSE, APPLET_ERROR, // or APPLET_LOAD runLoader(); return; } boolean disposed = false; while (!disposed && !curThread.isInterrupted()) { AppletEvent evt; try { evt = getNextEvent(); } catch (InterruptedException e) { showAppletStatus("bail"); return; } // showAppletStatus("EVENT = " + evt.getID()); try { switch (evt.getID()) { case APPLET_LOAD: if (!okToLoad()) { break; } // This complexity allows loading of applets to be // interruptable. The actual thread loading runs // in a separate thread, so it can be interrupted // without harming the applet thread. // So that we don't have to worry about // concurrency issues, the main applet thread waits // until the loader thread terminates. // (one way or another). if (loaderThread == null) { setLoaderThread(new Thread(null, this, "AppletLoader", 0, false)); loaderThread.start(); // we get to go to sleep while this runs loaderThread.join(); setLoaderThread(null); } else { // REMIND: issue an error -- this case should never // occur. } break; case APPLET_INIT: // AppletViewer "Restart" will jump from destroy method to // init, that is why we need to check status w/ APPLET_DESTROY if (status != APPLET_LOAD && status != APPLET_DESTROY) { showAppletStatus("notloaded"); break; } applet.resize(defaultAppletSize); if (PerformanceLogger.loggingEnabled()) { PerformanceLogger.setTime("Applet Init"); PerformanceLogger.outputLog(); } applet.init(); // Need the default(fallback) font to be created in this AppContext Font f = getFont(); if (f == null || "dialog".equals(f.getFamily().toLowerCase(Locale.ENGLISH)) && f.getSize() == 12 && f.getStyle() == Font.PLAIN) { setFont(new Font(Font.DIALOG, Font.PLAIN, 12)); } // Validate the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; Runnable r = new Runnable() { @Override public void run() { p.validate(); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_INIT; showAppletStatus("inited"); break; case APPLET_START: { if (status != APPLET_INIT && status != APPLET_STOP) { showAppletStatus("notinited"); break; } applet.resize(currentAppletSize); applet.start(); // Validate and show the applet in event dispatch thread // to avoid deadlock. try { final AppletPanel p = this; final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { p.validate(); a.setVisible(true); // Fix for BugTraq ID 4041703. // Set the default focus for an applet. if (hasInitialFocus()) { setDefaultFocus(); } } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } status = APPLET_START; showAppletStatus("started"); break; } case APPLET_STOP: if (status != APPLET_START) { showAppletStatus("notstarted"); break; } status = APPLET_STOP; // Hide the applet in event dispatch thread // to avoid deadlock. try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { a.setVisible(false); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } // During Applet.stop(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.stop(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("stopped"); break; case APPLET_DESTROY: if (status != APPLET_STOP && status != APPLET_INIT) { showAppletStatus("notstopped"); break; } status = APPLET_DESTROY; // During Applet.destroy(), any AccessControlException on an involved Class remains in // the "memory" of the AppletClassLoader. If the same instance of the ClassLoader is // reused, the same exception will occur during class loading. Set the // AppletClassLoader's // exceptionStatusSet flag to allow recognition of what had happened // when reusing AppletClassLoader object. try { applet.destroy(); } catch (java.security.AccessControlException e) { setExceptionStatus(e); // rethrow exception to be handled as it normally would be. throw e; } showAppletStatus("destroyed"); break; case APPLET_DISPOSE: if (status != APPLET_DESTROY && status != APPLET_LOAD) { showAppletStatus("notdestroyed"); break; } status = APPLET_DISPOSE; try { final Applet a = applet; Runnable r = new Runnable() { @Override public void run() { remove(a); } }; AWTAccessor.getEventQueueAccessor().invokeAndWait(applet, r); } catch (InterruptedException ie) { } catch (InvocationTargetException ite) { } applet = null; showAppletStatus("disposed"); disposed = true; break; case APPLET_QUIT: return; } } catch (Exception e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("exception2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("exception", e.getClass().getName()); } showAppletException(e); } catch (ThreadDeath e) { showAppletStatus("death"); return; } catch (Error e) { status = APPLET_ERROR; if (e.getMessage() != null) { showAppletStatus("error2", e.getClass().getName(), e.getMessage()); } else { showAppletStatus("error", e.getClass().getName()); } showAppletException(e); } clearLoadAbortRequest(); } }
public void fillPopupMenu() { JMenuItem item; TextImageIcon textIcon; StatementHistory history; int rowCount = 0; int numRows = 0; Insets margin = new Insets(0, 0, 0, 0); // Get the font defined in the displayOptions panel for menus Font ft = DisplayOptions.getFont("Menu1"); // We need a fairly small font, so make it 2 smaller. int size = ft.getSize(); // If larger than 12, subtract 2 if (size > 12) size -= 2; Font font = DisplayOptions.getFont(ft.getName(), ft.getStyle(), size); // This flag is used so that we only fill the menu when needed if (menuAlreadyFilled) return; menuAlreadyFilled = true; history = sshare.statementHistory(); ArrayList list = history.getNamedStatementList(); Color bgColor = Util.getBgColor(); // Only show the Saved Statements section if there are some. if (list != null && list.size() != 0) { item = popup.add("Saved Statements"); rowCount++; // item.setForeground(Color.blue); // item.setBackground(bgColor); item.setFont(font); item.setMargin(margin); popup.add(item); for (int i = 0; i < list.size(); i++) { ArrayList nameNlabel = (ArrayList) list.get(i); // first item in nameNlabel is name and second is label item = popup.add(" " + (String) nameNlabel.get(1)); rowCount++; item.setActionCommand("save:" + (String) nameNlabel.get(0)); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); } } // the rest of menu (return object types, statement types, etc.) ShufflerService shufflerService = sshare.shufflerService(); ArrayList objTypes = shufflerService.getAllMenuObjectTypes(); for (int i = 0; i < objTypes.size(); i++) { String objType = (String) objTypes.get(i); // Do not display menu for DB_AVAIL_SUB_TYPES if (objType.equals(Shuf.DB_AVAIL_SUB_TYPES)) continue; // addSeparator looks bad using GridLayout because it creates rows // and columns which are all equal in size. It cannot have a row // with a separator which is a different height than the other // rectangles it creates. So just use dashes. item = popup.add(separator); item.setFont(font); item.setMargin(margin); rowCount++; item = popup.add(shufflerService.getCategoryLabel(objType)); rowCount++; // item.setForeground(Color.blue); item.setActionCommand("title:" + objType); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); ArrayList menuStrings = shufflerService.getmenuStringsThisObj(objType); // If current rowCount plus the next section size is too big, // specify the numRows to the current value of rowCount -1. // That is, put this next section in a new column. // 47 is emperical number of rows to fit 90% full screen. if (numRows == 0 && rowCount - 1 + menuStrings.size() > 44) { numRows = rowCount - 2; } for (int j = 0; j < menuStrings.size(); j++) { String menuString = (String) menuStrings.get(j); item = popup.add(" " + menuString); rowCount++; item.setActionCommand("command:" + objType + "/" + menuString); // item.setBackground(bgColor); item.addActionListener(popActionListener); item.setFont(font); item.setMargin(margin); } // The spotter menu changes dynamically when // the list of saved statements changes. history.addStatementListener( new StatementAdapter() { public void saveListChanged() { refreshSaveMenu(); } }); } if (numRows == 0) numRows = rowCount; GridLayoutCol lm = new GridLayoutCol(numRows, 0); popup.setLayout(lm); }